Package org.jboss.forge.roaster.model.source

Examples of org.jboss.forge.roaster.model.source.JavaClassSource


         lookupGetters(properties, (MethodHolder<?>) clazz);
         lookupSetters(properties, (MethodHolder<?>) clazz);

         if (clazz instanceof JavaClass)
         {
            JavaClassSource source = Roaster.parse(JavaClassSource.class,
                     clazz.toString());
            if (!source.getSuperType().equals("java.lang.Object"))
            {
               inspectClassProperties(source.getSuperType(), properties);
            }
         }
      }
   }
View Full Code Here


         lookupGetters(properties, (MethodHolder<?>) clazz);
         lookupSetters(properties, (MethodHolder<?>) clazz);

         if (clazz instanceof JavaClass)
         {
            JavaClassSource source = Roaster.parse(JavaClassSource.class,
                     clazz.toString());
            if (!source.getSuperType().equals("java.lang.Object"))
            {
               inspectClassProperties(source.getSuperType(), properties);
            }
         }
      }
   }
View Full Code Here

   }

   @Test
   public void testCreateHashCodeAndEqualsForObjects() throws Exception
   {
      JavaClassSource aClass = Roaster
               .parse(JavaClassSource.class,
                        "import java.util.Date; public class Foo { private Object object; private Date date;}");
      FieldSource<JavaClassSource> identityBasedField = aClass.getField("object");
      FieldSource<JavaClassSource> nonIdentityBasedField = aClass.getField("date");
      Refactory.createHashCodeAndEquals(aClass, identityBasedField, nonIdentityBasedField);

      List<MethodSource<JavaClassSource>> methods = aClass.getMethods();
      assertTrue(aClass.getMethods().size() == 2);
      MethodSource<JavaClassSource> equals = methods.get(0);
      MethodSource<JavaClassSource> hashcode = methods.get(1);
      assertHashCodeForObjects(hashcode);
      assertEqualsForObjects(equals);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(equals);
      aClass.removeMethod(hashcode);
      assertTrue(aClass.getMethods().size() == 0);

      Refactory.createHashCode(aClass, identityBasedField, nonIdentityBasedField);
      assertTrue(aClass.getMethods().size() == 1);
      methods = aClass.getMethods();
      hashcode = methods.get(0);
      assertHashCodeForObjects(hashcode);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(hashcode);
      assertTrue(aClass.getMethods().size() == 0);
     
      Refactory.createEquals(aClass, identityBasedField, nonIdentityBasedField);
      assertTrue(aClass.getMethods().size() == 1);
      methods = aClass.getMethods();
      equals = methods.get(0);
      assertEqualsForObjects(equals);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(equals);
      assertTrue(aClass.getMethods().size() == 0);

   }
View Full Code Here

   }

   @Test
   public void testCreateHashCodeAndEqualsSubclass() throws Exception
   {
      JavaClassSource subClass = Roaster
               .parse(JavaClassSource.class,
                        "import java.util.Set;import java.util.Date; public class Foo extends Date { private int foo; private String firstName; private Set<String> names; private final int bar; }");
      FieldSource<JavaClassSource> intField = subClass.getField("foo");
      FieldSource<JavaClassSource> stringField = subClass.getField("firstName");
      Refactory.createHashCodeAndEquals(subClass, intField, stringField);

      List<MethodSource<JavaClassSource>> methods = subClass.getMethods();
      assertTrue(subClass.getMethods().size() == 2);
      MethodSource<JavaClassSource> equals = methods.get(0);
      MethodSource<JavaClassSource> hashcode = methods.get(1);
      assertHashCodeForSubclass(hashcode);
      assertEqualsForSubclass(equals);
      assertFalse(subClass.hasSyntaxErrors());
      subClass.removeMethod(equals);
      subClass.removeMethod(hashcode);
      assertTrue(subClass.getMethods().size() == 0);
     
      Refactory.createEquals(subClass, intField, stringField);
      methods = subClass.getMethods();
      assertTrue(subClass.getMethods().size() == 1);
      equals = methods.get(0);
      assertEqualsForSubclass(equals);
      assertFalse(subClass.hasSyntaxErrors());
      subClass.removeMethod(equals);
      assertTrue(subClass.getMethods().size() == 0);
     
      Refactory.createHashCode(subClass, intField, stringField);
      methods = subClass.getMethods();
      assertTrue(subClass.getMethods().size() == 1);
      hashcode = methods.get(0);
      assertEqualsForSubclass(equals);
      assertFalse(subClass.hasSyntaxErrors());
      subClass.removeMethod(hashcode);
      assertTrue(subClass.getMethods().size() == 0);
   }
View Full Code Here

   }

   @Test
   public void testCreateHashCodeAndEqualsOuterClass() throws Exception
   {
      JavaClassSource outerClass = Roaster
               .parse(JavaClassSource.class,
                        "public class Foo { private Foo.Bar bar; class Bar{ private Boolean flag; } }");
      FieldSource<JavaClassSource> outerField = outerClass.getField("bar");
     
      Refactory.createHashCodeAndEquals(outerClass, outerField);
      assertTrue(outerClass.getMethods().size() == 2);
      List<MethodSource<JavaClassSource>> methods = outerClass.getMethods();
      MethodSource<JavaClassSource> equals = methods.get(0);
      MethodSource<JavaClassSource> hashcode = methods.get(1);
      assertHashCodeForOuterClass(hashcode);
      assertEqualsForOuterClass(equals);
      assertFalse(outerClass.hasSyntaxErrors());
      outerClass.removeMethod(equals);
      outerClass.removeMethod(hashcode);
      assertTrue(outerClass.getMethods().size() == 0);
     
      Refactory.createEquals(outerClass, outerField);
      assertTrue(outerClass.getMethods().size() == 1);
      methods = outerClass.getMethods();
      equals = methods.get(0);
      assertEqualsForOuterClass(equals);
      assertFalse(outerClass.hasSyntaxErrors());
      outerClass.removeMethod(equals);
      assertTrue(outerClass.getMethods().size() == 0);
     
      Refactory.createHashCode(outerClass, outerField);
      assertTrue(outerClass.getMethods().size() == 1);
      methods = outerClass.getMethods();
      hashcode = methods.get(0);
      assertHashCodeForOuterClass(hashcode);
      assertFalse(outerClass.hasSyntaxErrors());
      outerClass.removeMethod(hashcode);
      assertTrue(outerClass.getMethods().size() == 0);
 
   }
View Full Code Here

   @Test
   @Ignore
   // This is not supported for now
   public void testCreateHashCodeAndEqualsInnerClass() throws Exception
   {
      JavaClassSource outerClass = Roaster
               .parse(JavaClassSource.class,
                        "public class Foo { private Foo.Bar bar; class Bar{ private Boolean flag; } }");
      JavaClassSource innerClass = (JavaClassSource) outerClass.getNestedTypes().get(0);
      FieldSource<JavaClassSource> innerField = innerClass.getField("flag");
      Refactory.createHashCodeAndEquals(innerClass, innerField);

      List<MethodSource<JavaClassSource>> methods = innerClass.getMethods();
      assertTrue(innerClass.getMethods().size() == 2);
      MethodSource<JavaClassSource> equals = methods.get(0);
      MethodSource<JavaClassSource> hashcode = methods.get(1);
      MethodSource<JavaClassSource> outerTypeAccessor = methods.get(2);
      assertEqualsForInnerClass(equals);
      assertHashCodeForInnerClass(hashcode);
      assertEquals("getOuterType", outerTypeAccessor.getName());
      assertFalse(outerClass.hasSyntaxErrors());
      innerClass.removeMethod(equals);
      innerClass.removeMethod(hashcode);
     
      Refactory.createEquals(innerClass, innerField);
      methods = innerClass.getMethods();
      assertTrue(innerClass.getMethods().size() == 1);
      equals = methods.get(0);
      assertEqualsForInnerClass(equals);
      assertFalse(outerClass.hasSyntaxErrors());
      innerClass.removeMethod(equals);
      assertTrue(innerClass.getMethods().size() == 0);
     
      Refactory.createHashCode(innerClass, innerField);
      methods = innerClass.getMethods();
      assertTrue(innerClass.getMethods().size() == 1);
      hashcode = methods.get(0);
      assertHashCodeForInnerClass(hashcode);
      assertFalse(outerClass.hasSyntaxErrors());
      innerClass.removeMethod(hashcode);
      assertTrue(innerClass.getMethods().size() == 0);
   }
View Full Code Here

   }

   @Test
   public void testCreateHashCodeAndEqualsMultipleLongFields() throws Exception
   {
      JavaClassSource aClass = Roaster
               .parse(JavaClassSource.class,
                        "public class Foo { private double firstDouble; private double secondDouble;}");
      FieldSource<JavaClassSource> firstLongField = aClass.getField("firstDouble");
      FieldSource<JavaClassSource> secondLongField = aClass.getField("secondDouble");
     
      Refactory.createHashCodeAndEquals(aClass, firstLongField, secondLongField);
      List<MethodSource<JavaClassSource>> methods = aClass.getMethods();
      assertTrue(aClass.getMethods().size() == 2);
      MethodSource<JavaClassSource> equals = methods.get(0);
      MethodSource<JavaClassSource> hashcode = methods.get(1);
      assertHashCodeForMultipleLongFields(hashcode);
      assertEqualsForMultipleLongFields(equals);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(equals);
      aClass.removeMethod(hashcode);
      assertTrue(aClass.getMethods().size() == 0);
     
      Refactory.createEquals(aClass, firstLongField, secondLongField);
      methods = aClass.getMethods();
      assertTrue(aClass.getMethods().size() == 1);
      equals = methods.get(0);
      assertEqualsForMultipleLongFields(equals);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(equals);
      assertTrue(aClass.getMethods().size() == 0);
     
      Refactory.createHashCode(aClass, firstLongField, secondLongField);
      methods = aClass.getMethods();
      assertTrue(aClass.getMethods().size() == 1);
      hashcode = methods.get(0);
      assertHashCodeForMultipleLongFields(hashcode);
      assertFalse(aClass.hasSyntaxErrors());
      aClass.removeMethod(hashcode);
      assertTrue(aClass.getMethods().size() == 0);
    
   }
View Full Code Here

         else
         {
            continue;
         }

         JavaClassSource entity = (JavaClassSource) javaSource;
         String targetDir = generationContext.getTargetDirectory();
         targetDir = (targetDir == null) ? "" : targetDir;
         config.setProperty(FacesScaffoldProvider.class.getName() + "_targetDir", targetDir);
         Resource<?> template = (Resource<?>) generationContext.getAttribute("pageTemplate");
         List<Resource<?>> generatedResourcesForEntity = this.generateFromEntity(targetDir, template, entity);
View Full Code Here

         // Prepare JPA Persistence Unit
         context.put("persistenceUnitName", jpa.getConfig().getOrCreatePersistenceUnit().getName());

         // Create the Backing Bean for this entity
         JavaClassSource viewBean = Roaster.parse(JavaClassSource.class,
                  this.templateProcessor.processTemplate(context, this.backingBeanTemplate));
         viewBean.setPackage(java.getBasePackage() + ".view");
         result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewBean), viewBean.toString()));

         // Set new context for view generation
         context = getTemplateContext(targetDir, template);
         String beanName = StringUtils.decapitalize(viewBean.getName());
         context.put("beanName", beanName);
         context.put("ccEntity", ccEntity);
         context.put("entityName", StringUtils.uncamelCase(entity.getName()));
         setPrimaryKeyMetaData(context, entity);

         // Prepare entityMetawidget
         this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity));
         this.entityMetawidget.setPath(entity.getQualifiedName());
         this.entityMetawidget.setReadOnly(false);
         this.entityMetawidget.setStyle(null);

         // Generate create
         writeEntityMetawidget(context, this.createTemplateEntityMetawidgetIndent, this.createTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/create.xhtml"),
                  this.templateProcessor.processTemplate(context, this.createTemplate)));

         // Generate view
         this.entityMetawidget.setReadOnly(true);
         writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/view.xhtml"),
                  this.templateProcessor.processTemplate(context, this.viewTemplate)));

         // Generate search
         this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example"));
         this.searchMetawidget.setPath(entity.getQualifiedName());
         this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems"));
         this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems");
         writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent,
                  this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/search.xhtml"),
                  this.templateProcessor.processTemplate(context, this.searchTemplate)));

         // Generate navigation
         result.add(generateNavigation(targetDir));

         // Need ViewUtils and forge.taglib.xml for forgeview:asList
         JavaClassSource viewUtils = Roaster.parse(JavaClassSource.class,
                  this.templateProcessor.processTemplate(context, this.viewUtilsTemplate));
         viewUtils.setPackage(viewBean.getPackage());
         result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewUtils), viewUtils.toString()));

         context.put("viewPackage", viewBean.getPackage());
         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource("WEB-INF/classes/META-INF/forge.taglib.xml"),
                  this.templateProcessor.processTemplate(context, this.taglibTemplate)));
View Full Code Here

   }

   @Test(expected = IllegalArgumentException.class)
   public void testCreateHashCodeAndEqualsForStatics() throws Exception
   {
      JavaClassSource aClass = Roaster
               .parse(JavaClassSource.class,
                        "public class Foo { private static boolean flag;}");
      FieldSource<JavaClassSource> booleanField = aClass.getField("flag");
      Refactory.createHashCodeAndEquals(aClass, booleanField);
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.roaster.model.source.JavaClassSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.