use of org.jboss.forge.roaster.model.source.AnnotationSource in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method validateValuePair.
@Override
public List<ValidationMessage> validateValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
// Currently we only validate the syntax but additional checks may be added.
List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseResult = modelDriver.parseAnnotationWithValuePair(annotationClassName, target, valuePairName, literalValue);
if (parseResult.getK2() != null && parseResult.getK2().size() > 0) {
ValidationMessage validationMessage;
for (DriverError driverError : parseResult.getK2()) {
validationMessage = new ValidationMessage();
validationMessage.setText(driverError.getMessage());
validationMessage.setColumn(driverError.getColumn());
validationMessage.setLine(driverError.getLine());
validationMessage.setLevel(Level.ERROR);
validationMessages.add(validationMessage);
}
}
return validationMessages;
}
use of org.jboss.forge.roaster.model.source.AnnotationSource in project Entitas-Java by Rubentxu.
the class EntityIndexDataProvider method createCustomEntityIndexData.
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;
}
use of org.jboss.forge.roaster.model.source.AnnotationSource in project camel by apache.
the class SpringBootAutoConfigurationMojo method createLanguageAutoConfigurationSource.
private void createLanguageAutoConfigurationSource(String packageName, LanguageModel model, List<String> languageAliases, boolean hasOptions, String overrideLanguageName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Language", "LanguageAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(Conditional.class).setLiteralValue(name + ".Condition.class");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
String configurationName = name.replace("LanguageAutoConfiguration", "LanguageConfiguration");
if (hasOptions) {
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
}
javaClass.addImport("org.apache.camel.CamelContextAware");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
String body = createLanguageBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType(model.getShortJavaType()).addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
// Determine all the aliases
// adding the '-language' suffix to prevent collision with component names
String[] springBeanAliases = languageAliases.stream().map(alias -> alias + "-language").toArray(size -> new String[size]);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(Scope.class).setStringValue("prototype");
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US));
}
use of org.jboss.forge.roaster.model.source.AnnotationSource in project camel by apache.
the class SpringBootAutoConfigurationMojo method createComponentAutoConfigurationSource.
private void createComponentAutoConfigurationSource(String packageName, ComponentModel model, List<String> componentAliases, boolean hasOptions, String overrideComponentName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Component", "ComponentAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(Conditional.class).setLiteralValue(name + ".Condition.class");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
String configurationName = name.replace("ComponentAutoConfiguration", "ComponentConfiguration");
if (hasOptions) {
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
}
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
// add method for auto configure
String body = createComponentBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType(model.getShortJavaType()).addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
if (hasOptions) {
method.addParameter(configurationName, "configuration");
}
// Determine all the aliases
String[] springBeanAliases = componentAliases.stream().map(alias -> alias + "-component").toArray(size -> new String[size]);
method.addAnnotation(Lazy.class);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.component", (overrideComponentName != null ? overrideComponentName : model.getScheme()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "component", (overrideComponentName != null ? overrideComponentName : model.getScheme()).toLowerCase(Locale.US));
}
use of org.jboss.forge.roaster.model.source.AnnotationSource in project Entitas-Java by Rubentxu.
the class EntityIndexDataProvider method createCustomEntityIndexData.
SourceDataFile createCustomEntityIndexData(SourceDataFile data) {
AnnotationSource annotation = data.getFileContent().getAnnotation(CustomEntityIndex.class);
setEntityIndexType(data, data.getFileContent().getName());
isCustom(data, true);
setEntityIndexName(data, data.getFileContent().getCanonicalName());
setContextNames(data, Arrays.asList(annotation.getStringValue()));
List<MethodData> getMethods = data.getFileContent().getMethods().stream().filter(m -> m.isPublic()).filter(m -> m.hasAnnotation(EntityIndexGetMethod.class)).map(m -> new MethodData(m.getReturnType(), m.getName(), m.getParameters().stream().map(p -> new MemberData(p.getType(), p.getName(), p.getAnnotations().size() > 0 ? p.getAnnotations().get(0) : null)).collect(Collectors.toList()), m.getAnnotation(EntityIndexGetMethod.class))).collect(Collectors.toList());
setCustomMethods(data, getMethods);
return data;
}
Aggregations