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

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


   }

   @Test
   public void testMultipleFieldDeclarationWithAnnotation() throws Exception
   {
      final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      javaClass.addField("@javax.xml.bind.annotation.XmlElement public String a,b,c[];");
      List<FieldSource<JavaClassSource>> fields = javaClass.getFields();

      Assert.assertEquals(3, fields.size());

      Assert.assertEquals("a", fields.get(0).getName());
      Assert.assertEquals("java.lang.String", fields.get(0).getType().getQualifiedName());
View Full Code Here


   }

   @Test
   public void testMultipleFieldDeclarationWithInitializers() throws Exception
   {
      final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      javaClass.addField("private static final String a = \"A\",b =\"B\",c[] = {\"C\"};");
      List<FieldSource<JavaClassSource>> fields = javaClass.getFields();

      Assert.assertEquals(3, fields.size());

      Assert.assertEquals("a", fields.get(0).getName());
      Assert.assertEquals("java.lang.String", fields.get(0).getType().getQualifiedName());
View Full Code Here

   }

   @Test
   public void testMethodVisibility() throws Exception
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);

      MethodSource<JavaClassSource> method = javaClass.addMethod("public void hello()");
      assertVisibility(Visibility.PUBLIC, method);
      assertVisibility("public", method);

      method = javaClass.addMethod("protected void hello()");
      assertVisibility(Visibility.PROTECTED, method);
      assertVisibility("protected", method);

      method = javaClass.addMethod("private void hello()");
      assertVisibility(Visibility.PRIVATE, method);
      assertVisibility("private", method);

      method = javaClass.addMethod("void hello()");
      assertVisibility(Visibility.PACKAGE_PRIVATE, method);
      assertVisibility("", method);
   }
View Full Code Here

   }

   @Test
   public void testMethodVisibilityWithSetter() throws Exception
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod().setName("hello");
      assertVisibility("", method);

      method.setVisibility(Visibility.PUBLIC);
      assertVisibility("public", method);
View Full Code Here

   }

   @Test
   public void testMethodWithPrimitiveParameters() throws Exception
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = javaClass.addMethod().setPublic().setName("doSomething").setReturnType(Integer.TYPE).setBody("return 0;");
      method.addParameter(Integer.TYPE, "initValue");
      method.addParameter(int.class,"intValueClass");
      method.addParameter(int[].class,"intValueClassArray");
      Assert.assertEquals(1, javaClass.getMethods().size());
      List<ParameterSource<JavaClassSource>> parameters = javaClass.getMethods().get(0).getParameters();
      Assert.assertEquals(3, parameters.size());
      Assert.assertTrue(parameters.get(0).getType().isPrimitive());
      Assert.assertTrue(parameters.get(1).getType().isPrimitive());
      Assert.assertTrue(parameters.get(2).getType().isArray());
   }
View Full Code Here

{
   @Test
   public void testSetMethodBody() throws Exception
   {
      String body = "return null;";
      JavaClassSource source = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = source.addMethod().setName("myMethod").setReturnType(String.class)
               .setBody(body);
      Assert.assertEquals(body, method.getBody());
   }
View Full Code Here

   @Test
   @Ignore("ROASTER-26")
   public void testSetMethodBodyWithComments() throws Exception
   {
      String body = "//TODO comments\n return null;";
      JavaClassSource source = Roaster.create(JavaClassSource.class);
      MethodSource<JavaClassSource> method = source.addMethod().setName("myMethod").setReturnType(String.class)
               .setBody(body);
      Assert.assertEquals(body, method.getBody());
   }
View Full Code Here

{

   @Test
   public void testImportWithWildCard() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      javaClass.setPackage("it.coopservice.test");
      javaClass.setName("SimpleClass");
      javaClass.addImport("org.junit.Assert.*");
      assertTrue(javaClass.getImport("org.junit.Assert") != null);
      assertTrue(javaClass.getImport("org.junit.Assert").isWildcard());
   }
View Full Code Here

   }

   @Test
   public void testImportStaticAndWithWildCard() throws ClassNotFoundException
   {
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
      javaClass.setPackage("it.coopservice.test");
      javaClass.setName("SimpleClass");
      javaClass.addImport("org.junit.Assert.*")
               .setStatic(true);
      assertTrue(javaClass.getImport("org.junit.Assert") != null);
      assertTrue(javaClass.getImport("org.junit.Assert").isStatic());
      assertTrue(javaClass.getImport("org.junit.Assert").isWildcard());
   }
View Full Code Here

{

   @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>"));
   }
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.