@Test
 public void javaTypeTypeVariableBounds() throws ClassNotFoundException {
   JavaInterface<?> foo =
       Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Foo");
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds(foo);
   Assert.assertTrue(javaClass.toString().contains("<T extends Foo>"));
   JavaInterface<?> bar =
       Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Bar");
   javaClass.getTypeVariable("T").setBounds(foo, bar);
   Assert.assertTrue(javaClass.toString().contains("<T extends Foo & Bar>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
Example #2
0
 public JavaResource createEmptyEnum(Project project, String enumName) throws IOException {
   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   JavaEnumSource enumSource = Roaster.create(JavaEnumSource.class).setName(enumName);
   String packageName =
       project.getFacet(JavaSourceFacet.class).getBasePackage() + "." + DEFAULT_ENTITY_PACKAGE;
   enumSource.setPackage(packageName);
   return javaSourceFacet.saveJavaSource(enumSource);
 }
 @Test
 public void addGenericSuperTypeWithoutPackage() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.setSuperType("Bar<T>");
   Assert.assertTrue(javaClass.toString().contains("Bar<T>"));
   Assert.assertNull(javaClass.getImport("it.coopservice.test.Bar"));
 }
 @Test
 public void addMultipleGenerics() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("I");
   javaClass.addTypeVariable().setName("O");
   Assert.assertTrue(javaClass.toString().contains("<I, O>"));
   javaClass.removeTypeVariable("I");
   Assert.assertTrue(javaClass.toString().contains("<O>"));
 }
 @Test
 public void addAndRemoveGenericType() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T");
   Assert.assertTrue(javaClass.getTypeVariables().get(0).getBounds().isEmpty());
   Assert.assertTrue(javaClass.toString().contains("<T>"));
   javaClass.removeTypeVariable("T");
   Assert.assertFalse(javaClass.toString().contains("<T>"));
 }
 @Test
 public void classTypeVariableBounds() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds(CharSequence.class);
   Assert.assertTrue(javaClass.toString().contains("<T extends CharSequence>"));
   javaClass.getTypeVariable("T").setBounds(CharSequence.class, Serializable.class);
   Assert.assertTrue(javaClass.toString().contains("<T extends CharSequence & Serializable>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
  @Override
  public String generateJavaTemplateSource(SourceGenerationContext context) {
    JavaClassSource viewClass = Roaster.create(JavaClassSource.class);
    String packageName = getPackageName(context);

    addTypeSignature(context, viewClass, packageName);
    addImports(context, viewClass);
    addAnnotations(context, viewClass);
    addAdditional(context, viewClass);

    addBaseViewFieldsAndMethodImpls(context, viewClass);
    return viewClass.toString();
  }
 @Test
 public void addMultipleConcreteGenericSuperTypeWithPackage() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.setSuperType(
       "it.coopservice.test.Bar<com.coopservice.test.MyConcreteSuperClass,com.coopservice.test.MyOtherClass>");
   Assert.assertTrue(
       javaClass.toString().contains("extends Bar<MyConcreteSuperClass, MyOtherClass>"));
   Assert.assertNotNull(javaClass.getImport("it.coopservice.test.Bar"));
   Assert.assertNotNull(javaClass.getImport("com.coopservice.test.MyConcreteSuperClass"));
   Assert.assertNotNull(javaClass.getImport("com.coopservice.test.MyOtherClass"));
 }
 @Test
 public void stringTypeVariableBounds() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds("com.something.Foo");
   Assert.assertTrue(javaClass.toString().contains("<T extends com.something.Foo>"));
   javaClass.getTypeVariable("T").setBounds("com.something.Foo", "com.something.Bar<T>");
   Assert.assertTrue(
       javaClass.toString().contains("<T extends com.something.Foo & com.something.Bar<T>>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
 @Test
 public void getClassGenericsName() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable("I");
   javaClass.addTypeVariable("O");
   List<TypeVariableSource<JavaClassSource>> typeVariables = javaClass.getTypeVariables();
   Assert.assertNotNull(typeVariables);
   Assert.assertEquals(2, typeVariables.size());
   Assert.assertEquals("I", typeVariables.get(0).getName());
   Assert.assertTrue(typeVariables.get(0).getBounds().isEmpty());
   Assert.assertEquals("O", typeVariables.get(1).getName());
   Assert.assertTrue(typeVariables.get(1).getBounds().isEmpty());
 }
Example #11
0
 @Test
 public void testJavaDocSetFullText() throws Exception {
   String expected =
       "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * "
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + "public class MyClass {"
           + LINE_SEPARATOR
           + "}";
   JavaClassSource javaClass =
       Roaster.create(JavaClassSource.class).setPublic().setName("MyClass");
   Assert.assertFalse(javaClass.hasJavaDoc());
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   javaDoc.setFullText("Do Something" + LINE_SEPARATOR + "* @author George Gastaldi");
   Assert.assertEquals(expected, javaClass.toString());
 }