@Test public void testJavaDocMethod() throws Exception { String text = "public class MyClass {" + "/**" + LINE_SEPARATOR + " * Do Something" + LINE_SEPARATOR + " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + "" + "private void foo(){};}"; JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text); Assert.assertFalse(javaClass.hasJavaDoc()); Assert.assertEquals(1, javaClass.getMethods().size()); MethodSource<JavaClassSource> method = javaClass.getMethods().get(0); Assert.assertTrue(method.hasJavaDoc()); JavaDocSource<MethodSource<JavaClassSource>> javaDoc = method.getJavaDoc(); String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi"; Assert.assertEquals(expected, javaDoc.getFullText()); }
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); } }