use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.
the class ComponentLookupGenerator method generateIndicesLookup.
private JavaClassSource generateIndicesLookup(String contextName, List<ComponentData> dataList) {
String pkgDestiny = targetPackageConfig.getTargetPackage();
JavaClassSource codeGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", WordUtils.capitalize(contextName) + DEFAULT_COMPONENT_LOOKUP_TAG));
if (dataList.size() > 0 && !pkgDestiny.endsWith(dataList.get(0).getSubDir())) {
// pkgDestiny += "." + dataList.get(0).getSubDir();
}
codeGen.setPackage(pkgDestiny);
addIndices(dataList, codeGen);
addComponentNames(dataList, codeGen);
addComponentTypes(dataList, codeGen);
System.out.println(codeGen);
return codeGen;
}
use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.
the class ComponentMatcherGenerator method generateMatcher.
private void generateMatcher(String contextName, ComponentData data) {
String pkgDestiny = targetPackageConfig.getTargetPackage();
CodeGenFile<JavaClassSource> genFile = getCodeGenFile(contextName, data);
JavaClassSource codeGenerated = genFile.getFileContent();
if (!pkgDestiny.endsWith(data.getSubDir())) {
pkgDestiny += "." + data.getSubDir();
}
codeGenerated.setPackage(pkgDestiny);
codeGenerated.addImport(Matcher.class);
addMatcher(contextName, data, codeGenerated);
addMatcherMethods(contextName, data, codeGenerated);
}
use of org.jboss.forge.roaster.model.source.JavaClassSource in project morphia by mongodb.
the class AnnotationBuilders method emitBuilder.
private void emitBuilder(File sourceFile) throws IOException {
source = Roaster.parse(JavaAnnotationSource.class, sourceFile);
builder = Roaster.create(JavaClassSource.class).setName(source.getName() + "Builder").setPackage(source.getPackage() + ".builders").setFinal(true);
builder.addAnnotation("dev.morphia.annotations.internal.MorphiaInternal");
JavaDocSource<JavaClassSource> javaDoc = builder.getJavaDoc();
javaDoc.addTagValue("@since", "2.3");
javaDoc.addTagValue("@morphia.internal", "");
javaDoc.addTagValue("@morphia.experimental", "");
MethodSource<JavaClassSource> constructor = builder.addMethod().setConstructor(true).setPrivate();
setDefaults(constructor, source);
builder.addMethod().setPublic().setName("build").setReturnType(source.getName()).setBody(format("var anno = annotation; annotation = null; return anno;", builder.getName()));
builder.addMethod().setPublic().setStatic(true).setName(builderMethodName(source.getName())).setReturnType(builder.getName()).setBody(format("return new %s();", builder.getName()));
JavaClassSource morphiaAnnotation = annotationType(source, builder);
List<AnnotationElementSource> elements = source.getAnnotationElements();
if (!elements.isEmpty()) {
copyBuilder(source, elements);
equals(morphiaAnnotation, elements);
hashCode(morphiaAnnotation, elements);
}
for (AnnotationElementSource element : elements) {
String name = element.getName();
morphiaAnnotation.addField().setName(name).setType(element.getType().toString()).setPrivate();
morphiaAnnotation.addMethod().setPublic().setName(name).setReturnType(element.getType()).setBody(format("return %s;", name)).addAnnotation(Override.class);
builder.addMethod().setPublic().setName(name).setReturnType(builder.getName()).setBody(format("annotation.%s = %s; return this;", name, name)).addParameter(parameterType(element), name);
}
for (Import anImport : source.getImports()) {
builder.addImport(anImport);
}
builder.addImport(Objects.class);
output();
}
use of org.jboss.forge.roaster.model.source.JavaClassSource in project morphia by mongodb.
the class AnnotationBuilders method copyBuilder.
private void copyBuilder(JavaAnnotationSource source, List<AnnotationElementSource> elements) {
MethodSource<JavaClassSource> copier = builder.addMethod().setPublic().setStatic(true).setName(builderMethodName(source.getName())).setReturnType(builder.getName()).setBody(format("return new %s();", builder.getName()));
copier.addParameter(source.getName(), "source");
StringJoiner copies = new StringJoiner("\n");
copies.add(format("var builder = new %s();", builder.getName()));
for (AnnotationElementSource element : elements) {
String name = element.getName();
copies.add(format("builder.annotation.%s = source.%s();", name, name));
}
copies.add("return builder;");
copier.setBody(copies.toString());
}
use of org.jboss.forge.roaster.model.source.JavaClassSource in project morphia by mongodb.
the class AnnotationBuilders method annotationType.
private JavaClassSource annotationType(JavaAnnotationSource source, JavaClassSource builder) {
JavaClassSource morphiaAnnotation = builder.addNestedType(JavaClassSource.class).addInterface(source.getQualifiedName()).setName(format("%sAnnotation", source.getName())).setStatic(true).setPrivate();
morphiaAnnotation.addMethod().setPublic().setName("annotationType").setReturnType(format("Class<%s>", source.getName())).setBody(format("return %s.class;", source.getName()));
builder.addField().setPrivate().setName("annotation").setType(format("%sAnnotation", source.getName())).setLiteralInitializer(format("new %sAnnotation()", source.getName()));
return morphiaAnnotation;
}
Aggregations