Search in sources :

Example 86 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class EntitasGenerator method generateEntitas.

public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    javaClass.setPackage(pkgDestiny);
    createMethodConstructor(javaClass, contextNames);
    createContextsMethod(javaClass, contextNames);
    createMethodAllContexts(javaClass, contextNames);
    createContextFields(javaClass, contextNames);
    return javaClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 87 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class MatcherGenerator method generateMatchers.

private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(contextName) + "Matcher"));
    if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
        pkgDestiny += "." + componentInfos.get(0).subDir;
    }
    javaClass.setPackage(pkgDestiny);
    // javaClass.addImport("com.ilargia.games.entitas.interfaces.IMatcher");
    javaClass.addImport("Matcher");
    for (ComponentInfo info : componentInfos) {
        addMatcher(contextName, info, javaClass);
        addMatcherMethods(contextName, info, javaClass);
    }
    System.out.println(javaClass);
    return javaClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 88 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class ContextGenerator method generateContext.

private JavaClassSource generateContext(String contextName, List<ComponentInfo> infos, String pkgDestiny) {
    JavaClassSource contextClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$sContext extends Context<%1$sEntity> {}", contextName));
    // }
    if (infos.size() > 0 && !pkgDestiny.endsWith(infos.get(0).subDir)) {
        pkgDestiny += "." + infos.get(0).subDir;
    }
    contextClass.setPackage(pkgDestiny);
    contextClass.addMethod().setName(contextName + "Context").setPublic().setConstructor(true).setParameters(String.format("int totalComponents, int startCreationIndex, ContextInfo contextInfo, EntityBaseFactory<%1$sEntity> factoryMethod", contextName)).setBody("super(totalComponents, startCreationIndex, contextInfo, factoryMethod);");
    contextClass.addImport("ilargia.entitas.api.*");
    for (ComponentInfo info : infos) {
        if (info.isSingleEntity) {
            addContextMethods(contextName, info, contextClass);
        }
    }
    return contextClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(ilargia.entitas.codeGenerator.data.ComponentInfo)

Example 89 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class EntitasGenerator method generateEntitas.

public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    javaClass.setPackage(pkgDestiny);
    createMethodConstructor(javaClass, contextNames);
    createContextsMethod(javaClass, contextNames);
    createMethodAllContexts(javaClass, contextNames);
    createContextFields(javaClass, contextNames);
    return javaClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 90 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.

the class ComponentEntityGenerator method generateEntity.

private void generateEntity(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();
    }
    if (codeGenerated.getPackage() == null) {
        codeGenerated.setPackage(pkgDestiny);
        codeGenerated.addMethod().setName(contextName + "Entity").setPublic().setConstructor(true).setBody("");
        codeGenerated.addImport("ilargia.entitas.Entity");
    }
    if (shouldGenerateMethods(data)) {
        addImporEnums(data, codeGenerated);
        addEntityMethods(contextName, data, codeGenerated);
    }
    if (isSharedContext(data) && codeGenerated.getImport(targetPackageConfig.getTargetPackage()) == null) {
        codeGenerated.addImport(targetPackageConfig.getTargetPackage() + ".SharedComponentsLookup");
    }
}
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