Exemplo n.º 1
0
 /**
  * processMainClass (non-Javadoc).
  *
  * @param javaClass the java class
  * @see
  *     io.github.rampantlions.codetools.CommonProcessor#processMainClass(org.jboss.forge.roaster.model.source.JavaClassSource)
  */
 @Override
 public void processMainClass(final JavaClassSource javaClass) {
   for (AnnotationSource<JavaClassSource> annotation : javaClass.getAnnotations()) {
     switch (annotation.getQualifiedName()) {
       case "com.wordnik.swagger.annotations.ApiModel":
       case "com.wordnik.swagger.annotations.ApiModelProperty":
         javaClass.removeAnnotation(annotation);
         changeMade = true;
         break;
       default:
         break;
     }
   }
 }
Exemplo n.º 2
0
 protected void createInitializers(final JavaClassSource entity)
     throws FacetNotFoundException, FileNotFoundException {
   boolean dirtyBit = false;
   for (FieldSource<JavaClassSource> field : entity.getFields()) {
     if (field.hasAnnotation(OneToOne.class)) {
       AnnotationSource<JavaClassSource> oneToOne = field.getAnnotation(OneToOne.class);
       if (oneToOne.getStringValue("mappedBy") == null
           && oneToOne.getStringValue("cascade") == null) {
         oneToOne.setEnumValue("cascade", CascadeType.ALL);
         dirtyBit = true;
       }
       String methodName = "new" + StringUtils.capitalize(field.getName());
       if (!entity.hasMethodSignature(methodName)) {
         entity
             .addMethod()
             .setName(methodName)
             .setReturnTypeVoid()
             .setPublic()
             .setBody("this." + field.getName() + " = new " + field.getType().getName() + "();");
         dirtyBit = true;
       }
     }
   }
   for (MethodSource<JavaClassSource> method : entity.getMethods()) {
     if (method.hasAnnotation(OneToOne.class)) {
       AnnotationSource<JavaClassSource> oneToOne = method.getAnnotation(OneToOne.class);
       if (oneToOne.getStringValue("mappedBy") == null
           && oneToOne.getStringValue("cascade") == null) {
         oneToOne.setEnumValue("cascade", CascadeType.ALL);
         dirtyBit = true;
       }
       String fieldName = StringUtils.camelCase(method.getName().substring(3));
       String methodName = "new" + StringUtils.capitalize(fieldName);
       if (!entity.hasMethodSignature(methodName)) {
         entity
             .addMethod()
             .setName(methodName)
             .setReturnTypeVoid()
             .setPublic()
             .setBody("this." + fieldName + " = new " + method.getReturnType().getName() + "();");
         dirtyBit = true;
       }
     }
   }
   if (dirtyBit) {
     this.project.getFacet(JavaSourceFacet.class).saveJavaSource(entity);
   }
 }