Search in sources :

Example 91 with JavaClassSource

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;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 92 with JavaClassSource

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);
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 93 with JavaClassSource

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();
}
Also used : Import(org.jboss.forge.roaster.model.source.Import) JavaAnnotationSource(org.jboss.forge.roaster.model.source.JavaAnnotationSource) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) AnnotationElementSource(org.jboss.forge.roaster.model.source.AnnotationElementSource)

Example 94 with JavaClassSource

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());
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) StringJoiner(java.util.StringJoiner) AnnotationElementSource(org.jboss.forge.roaster.model.source.AnnotationElementSource)

Example 95 with JavaClassSource

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;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Aggregations

JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)95 File (java.io.File)37 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)26 ParserResult (org.apache.camel.parser.ParserResult)19 List (java.util.List)15 IOException (java.io.IOException)14 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)12 InputStream (java.io.InputStream)10 Collections (java.util.Collections)10 Roaster (org.jboss.forge.roaster.Roaster)10 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 Matcher (java.util.regex.Matcher)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)8 Arrays (java.util.Arrays)7 Map (java.util.Map)7 Import (org.jboss.forge.roaster.model.source.Import)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7