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 (mainClass.hasValue()) { defaultDeploymentAnnotation.setLiteralValue("main", mainClass.getValue() + ".class"); } if (archiveType.hasValue()) { defaultDeploymentAnnotation.setLiteralValue("type", String.format("DefaultDeployment.Type.%s", archiveType.getValue())); } }
protected void addResourceTypeAnnotation(JavaClassSource type, ClassPlan plan) { type.addImport(ResourceType.class); AnnotationSource<JavaClassSource> typeAnno = type.addAnnotation(); typeAnno.setName("ResourceType"); typeAnno.setStringValue(plan.getResourceType()); if (plan.isSingleton()) { type.addImport(Implicit.class); AnnotationSource<JavaClassSource> implicitMeta = type.addAnnotation(); implicitMeta.setName(Implicit.class.getSimpleName()); } }
private JavaClassSource createCommand(JavaClassSource command, String commandName, Iterable<String> categories) { MethodSource<JavaClassSource> commandMethod = command.addMethod().setName(toMethodName(command, commandName)) .setReturnType(String.class) .setBody(String.format("return \"Command %s executed\";", commandName)).setPublic(); AnnotationSource<JavaClassSource> commandAnn = commandMethod.addAnnotation(Command.class); List<String> categoryList = new ArrayList<>(Lists.toList(categories)); commandAnn.setStringValue("value", commandName); if (!categoryList.isEmpty()) { commandAnn.setStringArrayValue("categories", categoryList.toArray(new String[categoryList.size()])); } // build the thing return command; }
private Object parseStringValue( AnnotationSource javaAnnotationToken, AnnotationValuePairDefinition valuePairDefinition ) { Object result = null; if ( valuePairDefinition.isArray() ) { String[] arrayValue = javaAnnotationToken.getStringArrayValue( valuePairDefinition.getName() ); if ( arrayValue != null ) { result = Arrays.asList( arrayValue ); } } else { result = javaAnnotationToken.getStringValue( valuePairDefinition.getName() ); } return result; }
public void visit(AnnotationSource<? extends JavaClassSource> annoSource) { if (annoSource.getQualifiedName().equals(AssetsUsageServiceImplTest.REFERENCED)) { ResourceReference reference = addResourceReference(annoSource.getStringValue("resourceFQN"), ResourceType.JAVA); reference.addPartReference(annoSource.getStringValue("part"), PartType.FIELD); } }
javaClass.setName(name); javaClass.getJavaDoc().setFullText("Generated by camel-package-maven-plugin - do not edit this file!"); javaClass.addAnnotation(Generated.class).setStringValue("value", SpringBootAutoConfigurationMojo.class.getName()); javaClass.addAnnotation(Configuration.class); javaClass.addAnnotation(Conditional.class).setLiteralValue( "{ ConditionalOnCamelContextAndAutoConfigurationBeans.class, " + name + ".GroupConditions.class }"); javaClass.addAnnotation(AutoConfigureAfter.class).setLiteralValue("CamelAutoConfiguration.class"); javaClass.addAnnotation(EnableConfigurationProperties.class).setLiteralValue( "{ LanguageConfigurationProperties.class, " + configurationName + ".class }" ); .setType("List<LanguageCustomizer<" + model.getShortJavaType() + ">>") .addAnnotation(Autowired.class) .setLiteralValue("required", "false"); method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases); method.addAnnotation(Scope.class).setLiteralValue("ConfigurableBeanFactory.SCOPE_PROTOTYPE"); method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
javaClass.getJavaDoc().setFullText(doc); javaClass.addAnnotation(Generated.class).setStringValue("value", SpringBootAutoConfigurationMojo.class.getName()); javaClass.addAnnotation(Configuration.class); javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration"); javaClass.addAnnotation(ConditionalOnProperty.class).setStringValue("name", "camel.rest.enabled").setLiteralValue("matchIfMissing", "true"); javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration"); javaClass.addAnnotation(EnableConfigurationProperties.class).setLiteralValue("value", configType + ".class"); method.setReturnType("org.apache.camel.spi.RestConfiguration"); method.addAnnotation(Lazy.class); method.addAnnotation(Bean.class).setLiteralValue("name", "RestConstants.DEFAULT_REST_CONFIGURATION_ID"); method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class"); method.addAnnotation(ConditionalOnMissingBean.class); method.setBody(""
@Override public void install(Project project) { JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); applicationClass.setSuperType(Application.class); if (applicationClass.hasAnnotation(ApplicationPath.class)) { applicationClass.getAnnotation(ApplicationPath.class).setStringValue(path); } else { applicationClass.addAnnotation(ApplicationPath.class).setStringValue(path); } facet.saveJavaSource(applicationClass); }
@Override public AnnotationSource<O> addAnnotationValue(String name, Class<? extends java.lang.annotation.Annotation> type) { if (!getOrigin().hasImport(type)) { getOrigin().addImport(type); } return addAnnotationValue(name).setName(type.getSimpleName()); }
.setName("RunWith") .setLiteralValue("VertxUnitRunner.class");
private AnnotationSource<O> getAnnotation(final AnnotationTargetSource<O, T> target, final List<?> modifiers, final String type) { List<AnnotationSource<O>> annotations = getAnnotations(target, modifiers); for (AnnotationSource<O> annotation : annotations) { if (Types.areEquivalent(type, annotation.getName())) { return annotation; } } return null; }
private void addAnnotationMemberValue(AnnotationSource annotationSource, AnnotationValuePairDefinition valuePairDefinition, Annotation annotation) { AnnotationSource targetAnnotation = annotationSource.addAnnotationValue(valuePairDefinition.getName()); targetAnnotation.setName(annotation.getClassName()); if (!annotation.getAnnotationDefinition().isMarker()) { for (AnnotationValuePairDefinition memberDefinition : annotation.getAnnotationDefinition().getValuePairs()) { Object value = annotation.getValue(memberDefinition.getName()); if (value != null) { addMemberValue(targetAnnotation, memberDefinition, value); } } } }
public RestApplicationClassConfigurationStrategy(JavaClassSource javaClass) { Assert.notNull(javaClass, "JavaClass cannot be null"); Assert.isTrue(javaClass.hasAnnotation(ApplicationPath.class), "@ApplicationPath should be present in the JavaClass"); this.applicationClass = javaClass; this.path = javaClass.getAnnotation(ApplicationPath.class).getStringValue(); }
if (oneToOne.getStringValue("mappedBy") == null && oneToOne.getStringValue("cascade") == null) oneToOne.setEnumValue("cascade", CascadeType.ALL); dirtyBit = true; if (oneToOne.getStringValue("mappedBy") == null && oneToOne.getStringValue("cascade") == null) oneToOne.setEnumValue("cascade", CascadeType.ALL); dirtyBit = true;
private void createRepositoryConfiguration(JavaClassSource entitySource, Project project) { final String entitySourcePackage = entitySource.getPackage(); // only create repository configuration if we haven't done so already JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); final DirectoryResource entityPackage = facet.getPackage(entitySourcePackage); final Resource<?> configuration = entityPackage.getChild(REPOSITORY_CONFIGURATION + ".java"); if (configuration == null || !configuration.exists()) { final JavaClassSource source = Roaster.create(JavaClassSource.class) .setName(REPOSITORY_CONFIGURATION) .setPackage(entitySourcePackage); source.addImport("org.springframework.context.annotation.Configuration"); source.addImport("org.springframework.boot.autoconfigure.EnableAutoConfiguration"); source.addImport("org.springframework.transaction.annotation.EnableTransactionManagement"); source.addImport("org.springframework.boot.autoconfigure.domain.EntityScan"); source.addImport("org.springframework.data.jpa.repository.config.EnableJpaRepositories"); source.addAnnotation("Configuration"); source.addAnnotation("EnableAutoConfiguration"); source.addAnnotation("EnableTransactionManagement"); source.addAnnotation("EntityScan") .setStringArrayValue("basePackages", new String[]{entitySourcePackage}); source.addAnnotation("EnableJpaRepositories") .setStringArrayValue("basePackages", new String[]{entitySourcePackage}); facet.saveJavaSource(source); } } }
public AnnotationDefinition buildAnnotationDefinition(AnnotationSource annotationSource, ClassTypeResolver classTypeResolver) throws ModelDriverException { return buildAnnotationDefinition(annotationSource.getQualifiedName(), classTypeResolver); }
javaClass.setName(name); javaClass.getJavaDoc().setFullText("Generated by camel-package-maven-plugin - do not edit this file!"); javaClass.addAnnotation(Generated.class).setStringValue("value", SpringBootAutoConfigurationMojo.class.getName()); javaClass.addAnnotation(Configuration.class); javaClass.addAnnotation(Conditional.class).setLiteralValue( "{ ConditionalOnCamelContextAndAutoConfigurationBeans.class, " + name + ".GroupConditions.class }"); javaClass.addAnnotation(AutoConfigureAfter.class).setLiteralValue("CamelAutoConfiguration.class"); javaClass.addAnnotation(EnableConfigurationProperties.class).setLiteralValue( "{ ComponentConfigurationProperties.class, " + configurationName + ".class }" ); .setType("List<ComponentCustomizer<" + model.getShortJavaType() + ">>") .addAnnotation(Autowired.class) .setLiteralValue("required", "false"); method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases); method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue(model.getShortJavaType() + ".class");
greeting.addAnnotation(RequestMapping.class).setStringValue("/greeting"); greeting.addParameter(String.class, "name").addAnnotation(RequestParam.class).setLiteralValue("value", "\"name\"").setLiteralValue("defaultValue", "\"world\""); greeting.setBody("return new Greeting(this.counter.incrementAndGet(), String.format(this.properties.getMessage(), name));"); break;
public static JavaClassSource createGreetingPropertiesClass(JavaClassSource current) { JavaClassSource source = Roaster.create(JavaClassSource.class).setName("GreetingProperties").setPackage(current.getPackage()); source.addAnnotation(Component.class); source.addAnnotation(ConfigurationProperties.class).setStringValue("greeting"); source.addProperty(String.class, "message").getField().setStringInitializer("Hello, %s!"); return source; }
@Override public AnnotationSource<O> addAnnotationValue(Class<? extends java.lang.annotation.Annotation> type) { if (!getOrigin().hasImport(type)) { getOrigin().addImport(type); } return addAnnotationValue().setName(type.getSimpleName()); }