org.jboss.forge.roaster.model.source.AnnotationSource Java Examples

The following examples show how to use org.jboss.forge.roaster.model.source.AnnotationSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
public void addSizeConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message,
         String min, String max) throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Size.class,
            message);

   if (min != null)
   {
      constraintAnnotation.setLiteralValue("min", min);
   }

   if (max != null)
   {
      constraintAnnotation.setLiteralValue("max", max);
   }

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #2
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void addMaxConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message, String max)
         throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Max.class,
            message);
   constraintAnnotation.setLiteralValue(max);

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #3
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void addMinConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message, String min)
         throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Min.class,
            message);
   constraintAnnotation.setLiteralValue(min);

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #4
Source File: CreateTestClassCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void addDefaultDeploymentAnnotation(JavaClassSource test, Project project) throws ClassNotFoundException, IOException {
    test.addImport("org.wildfly.swarm.arquillian.DefaultDeployment");
    final AnnotationSource<JavaClassSource> defaultDeploymentAnnotation = test.addAnnotation("DefaultDeployment");
    if (asClient.hasValue()) {
        defaultDeploymentAnnotation.setLiteralValue("testable", "false");
    }

    if (archiveType.hasValue()) {
        defaultDeploymentAnnotation.setLiteralValue("type", String.format("DefaultDeployment.Type.%s", archiveType.getValue()));
    }
}
 
Example #5
Source File: ComponentDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
List<String> getComponentNames(JavaClassSource type) {
    AnnotationSource<JavaClassSource> annotation = type.getAnnotation(CustomComponentName.class);
    if (annotation != null) {
        return Arrays.asList(annotation.getStringArrayValue("componentNames"));

    } else {
        return new ArrayList<>();
    }

}
 
Example #6
Source File: ContextsComponentDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
private List<String> extractContextNames(JavaClassSource clazz) {
    AnnotationSource<JavaClassSource> annotation =  clazz.getAnnotation(Contexts.class);
    if (annotation != null) {
        return Arrays.asList(annotation.getStringArrayValue("names"));
    }
    return new ArrayList<>();
}
 
Example #7
Source File: CustomPrefixDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
private String getUniqueComponentPrefix(JavaClassSource clazz) {
    AnnotationSource<JavaClassSource> annotation = clazz.getAnnotation(Unique.class);
    if (annotation != null) {
        return annotation.getStringValue("prefix");
    }
    return "is";
}
 
Example #8
Source File: EntityIndexDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
ComponentData createCustomEntityIndexData(ComponentData data) {
    AnnotationSource annotation = data.getSource().getAnnotation(CustomEntityIndex.class);

    setEntityIndexType(data, data.getSource().getName());
    isCustom(data, true);
    setEntityIndexName(data, data.getSource().getCanonicalName());

    setContextNames(data, Arrays.asList(annotation.getStringValue()));
    setCustomMethods(data, data.getSource().getMethods().stream().filter(m-> !m.isConstructor()).collect(Collectors.toList()));
    return data;
}
 
Example #9
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource<JavaClassSource> addAnnotation(String s) {
    return null;
}
 
Example #10
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_set_archivetype_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("archiveType", "WAR");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("type");
   assertThat(testable, is("DefaultDeployment.Type.WAR"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #11
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_asclient_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("asClient", true);

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("testable");
   assertThat(testable, is("false"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #12
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_incontainer_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));
   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   assertThat(defaultDeployment.getValues().size(), is(0));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example #13
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public List<AnnotationSource> getAnnotations() {
    return null;
}
 
Example #14
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource<JavaClassSource> addAnnotation(Class<? extends Annotation> aClass) {
    return null;
}
 
Example #15
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource<JavaClassSource> addAnnotation() {
    return null;
}
 
Example #16
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource<JavaClassSource> getAnnotation(String s) {
    return null;
}
 
Example #17
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource<JavaClassSource> getAnnotation(Class<? extends Annotation> aClass) {
    return null;
}
 
Example #18
Source File: AnonymousMethodSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public List<AnnotationSource<JavaClassSource>> getAnnotations() {
    return null;
}
 
Example #19
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource getAnnotation(Class type) {
    return null;
}
 
Example #20
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource addAnnotation(Class type) {
    return null;
}
 
Example #21
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource addAnnotation(String className) {
    return null;
}
 
Example #22
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource addAnnotation() {
    return null;
}
 
Example #23
Source File: StatementFieldSource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationSource getAnnotation(String type) {
    return null;
}