コード例 #1
0
 public Descriptor build() {
   Map<String, String> defaults = getPluginDefault(plugin);
   if (sourceClass != null && sourcePackage == null) {
     sourcePackage = StringUtil.substringBeforeLastIndexOf(sourceClass, ".");
   }
   if (targetPackage == null) {
     if (defaults.containsKey(TARGET_PACKAGE)) {
       targetPackage = sourcePackage + "." + defaults.get(TARGET_PACKAGE);
     } else {
       targetPackage = sourcePackage;
     }
   }
   if (targetPostfix == null && defaults.containsKey(TARGET_POSTFIX)) {
     targetPostfix = defaults.get(TARGET_POSTFIX);
   }
   if (targetPrefix == null && defaults.containsKey(TARGET_PREFIX)) {
     targetPrefix = defaults.get(TARGET_PREFIX);
   }
   return new DescriptorImpl(
       sourcePackage,
       sourceClass,
       targetPackage,
       targetPrefix,
       targetPostfix,
       superType,
       interfaces,
       exclusions,
       inclusion,
       plugin,
       compilationSources,
       options,
       immutableImplementation);
 }
コード例 #2
0
  @Override
  public void handle(JavaType sourceType, JavaField javaField) {
    if (!(javaField.getName().charAt(0) == '_' && javaField.getType().equals(boolean.class))) {
      return;
    }

    String fieldName = javaField.getName();
    String methodPrefix = "has";
    String methodName =
        StringUtil.format(CaseFormat.LOWER_CAMEL, methodPrefix, fieldName, CaseFormat.LOWER_CAMEL);
    if (!ownerTypeBuilder.containsMethod(methodName)) {
      JavaMethodBuilder methodBuilder = new JavaMethodBuilder();
      methodBuilder.setName(methodName);
      methodBuilder.setResultType(boolean.class);
      methodBuilder.addModifier("public");
      methodBuilder.addBody(String.format("return this.%s;", fieldName));
      ownerTypeBuilder.addMethod(methodBuilder.build());
    }
  }