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

Examples of org.jboss.forge.roaster.model.source.JavaClassSource.addMethod()


   @Test
   public void addAndRemoveGenericType() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
     
      MethodSource<JavaClassSource> method = javaClass.addMethod();
      method.addTypeVariable().setName("T");
     
      Assert.assertTrue(method.toString().contains("<T>"));
      Assert.assertTrue(method.getTypeVariables().get(0).getBounds().isEmpty());
      method.removeTypeVariable("T");
View Full Code Here


   @Test
   public void addMultipleGenerics() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod();

      method.addTypeVariable().setName("I");
      method.addTypeVariable().setName("O");
      Assert.assertTrue(Pattern.compile("<I, *O>").matcher(method.toString()).find());
      method.removeTypeVariable("I");
View Full Code Here

   @Test
   public void getMethodGenerics() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod();

      method.addTypeVariable().setName("I");
      method.addTypeVariable().setName("O");
      List<TypeVariableSource<JavaClassSource>> typeVariables = method.getTypeVariables();
      Assert.assertNotNull(typeVariables);
View Full Code Here

   @Test
   public void classTypeVariableBounds() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod();
      method.addTypeVariable().setName("T").setBounds(CharSequence.class);
      Assert.assertTrue(method.toString().contains("<T extends CharSequence>"));
      method.getTypeVariable("T").
               setBounds(CharSequence.class, Serializable.class);
      Assert.assertTrue(method.toString().contains("<T extends CharSequence & Serializable>"));
View Full Code Here

   @Test
   public void javaTypeTypeVariableBounds() throws ClassNotFoundException
   {
      JavaInterface<?> foo = Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Foo");
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod();
      method.addTypeVariable().setName("T").setBounds(foo);
      Assert.assertTrue(method.toString().contains("<T extends Foo>"));
      JavaInterface<?> bar = Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Bar");
      method.getTypeVariable("T").setBounds(foo, bar);
      Assert.assertTrue(method.toString().contains("<T extends Foo & Bar>"));
View Full Code Here

   @Test
   public void stringTypeVariableBounds() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod();
      method.addTypeVariable().setName("T").setBounds("com.something.Foo");
      Assert.assertTrue(method.toString().contains("<T extends com.something.Foo>"));
      method.getTypeVariable("T").setBounds("com.something.Foo", "com.something.Bar<T>");
      Assert.assertTrue(method.toString().contains("<T extends com.something.Foo & com.something.Bar<T>>"));
      method.getTypeVariable("T").removeBounds();
View Full Code Here

   @Test
   public void testSupportsGenericsSourceFromMethod() throws Exception
   {
      JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
      source.addMethod("public void test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}");
      Assert.assertFalse(source.hasSyntaxErrors());
   }

   @Test
   public void testSupportsGenericsSourceFromAddedConstructor() throws Exception
View Full Code Here

   @Test
   public void testSupportsGenericsSourceFromAddedConstructor() throws Exception
   {
      JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
      // Add a new method to get JDT to recognize the new ASTs
      source.addMethod().setConstructor(true)
               .setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
      // Forces a rewrite to happen via AbstractJavaSource
      source.toString();
      Assert.assertFalse(source.hasSyntaxErrors());
   }
View Full Code Here

   @Test
   public void testSupportsGenericsSourceFromAddedMethod() throws Exception
   {
      JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
      // Add a new method to get JDT to recognize the new ASTs
      source.addMethod().setName("test")
               .setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
      // Forces a rewrite to happen via AbstractJavaSource
      source.toString();
      Assert.assertFalse(source.hasSyntaxErrors());
   }
View Full Code Here

         }
      }
      body.append(")");
      body.append(";");
      body.append("return archive;");
      MethodSource<JavaClassSource> getDeployment = javaClass.addMethod().setName("getDeployment").setPublic()
               .setStatic(true)
               .setBody(body.toString()).setReturnType("ForgeArchive");
      getDeployment.addAnnotation("Deployment");
      String annotationBody = dependenciesAnnotationBody.toString();
      if (annotationBody.length() > 0)
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.