Exemplo n.º 1
0
 @Test
 public void testJavaDocField() throws Exception {
   String text =
       "public class MyClass {"
           + "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + ""
           + "private String foo;}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   Assert.assertFalse(javaClass.hasJavaDoc());
   Assert.assertEquals(1, javaClass.getFields().size());
   FieldSource<JavaClassSource> field = javaClass.getFields().get(0);
   Assert.assertTrue(field.hasJavaDoc());
   JavaDocSource<FieldSource<JavaClassSource>> javaDoc = field.getJavaDoc();
   String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
   Assert.assertEquals(expected, javaDoc.getFullText());
 }
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);
   }
 }
Exemplo n.º 3
0
 /**
  * processFields (non-Javadoc).
  *
  * @param javaClass the java class
  * @see
  *     io.github.rampantlions.codetools.CommonProcessor#processFields(org.jboss.forge.roaster.model.source.JavaClassSource)
  */
 @Override
 public void processFields(final JavaClassSource javaClass) {
   for (FieldSource<JavaClassSource> field : javaClass.getFields()) {
     for (AnnotationSource<JavaClassSource> annotation : field.getAnnotations()) {
       switch (annotation.getQualifiedName()) {
         case "com.wordnik.swagger.annotations.ApiModel":
         case "com.wordnik.swagger.annotations.ApiModelProperty":
           field.removeAnnotation(annotation);
           changeMade = true;
           break;
         default:
           break;
       }
     }
   }
 }