Search in sources :

Example 36 with JavaClassSource

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

the class CodeGeneratorOld method generate.

public List<CodeGenFile> generate(ICodeGeneratorDataProvider provider, String destinyDirectory, List<ICodeGenerator> codeGenerators) {
    List<String> scrDir = new ArrayList<String>() {

        {
            add("main/java");
            add("test/java");
            add("main\\java");
            add("test\\java");
            add("src");
        }
    };
    Optional<String> sourcePackage = scrDir.stream().filter((base) -> destinyDirectory.lastIndexOf(base) != -1).map((base) -> destinyDirectory.substring(destinyDirectory.lastIndexOf(base) + base.length() + 1)).map((base) -> base.replaceAll("/", ".").replaceAll("\\\\", ".")).findFirst();
    ArrayList<CodeGenFile> generatedFiles = new ArrayList<CodeGenFile>();
    List<JavaClassSource> files = new ArrayList<>();
    // if (sourcePackage.isPresent()) {
    // for (ICodeGenerator generator : generators) {
    // if (generator instanceof IContextCodeGenerator) {
    // for (JavaClassSource javaClassSource : ((IContextCodeGenerator) generator).generate(provider.poolNames(), sourcePackage.get())) {
    // files.add(javaClassSource);
    // generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
    // }
    // 
    // }
    // if (generator instanceof IComponentCodeGenerator) {
    // for (JavaClassSource javaClassSource : ((IComponentCodeGenerator) generator).generate(provider.componentInfos(), sourcePackage.get())) {
    // files.add(javaClassSource);
    // generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
    // }
    // 
    // }
    // if (generator instanceof IBlueprintsCodeGenerator) {
    // for (JavaClassSource javaClassSource : ((IBlueprintsCodeGenerator) generator).generate(provider.blueprintNames(), sourcePackage.get())) {
    // files.add(javaClassSource);
    // generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
    // }
    // 
    // }
    // }
    // }
    CodeGenFile entitas = generatedFiles.get(generatedFiles.size() - 1);
    for (CodeGenFile generatedFile : generatedFiles) {
        if (!generatedFile.fileName.endsWith("Matcher") && !entitas.fileContent.getPackage().equals(generatedFile.fileContent.getPackage())) {
            entitas.fileContent.addImport(generatedFile.fileName);
        }
    }
    writeFiles(destinyDirectory, files);
    return generatedFiles;
}
Also used : ICodeGeneratorDataProvider(ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) java.util(java.util) java.io(java.io) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) JavaDocSource(org.jboss.forge.roaster.model.source.JavaDocSource) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 37 with JavaClassSource

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

the class ComponentIndicesGenerator method generateIndicesLookup.

private JavaClassSource generateIndicesLookup(String poolName, List<ComponentInfo> componentInfos, String pkgDestiny) {
    JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(poolName) + CodeGeneratorOld.DEFAULT_COMPONENT_LOOKUP_TAG));
    // }
    if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
        pkgDestiny += "." + componentInfos.get(0).subDir;
    }
    javaClass.setPackage(pkgDestiny);
    addIndices(componentInfos, javaClass);
    addComponentNames(componentInfos, javaClass);
    addComponentTypes(componentInfos, javaClass);
    System.out.println(javaClass);
    return javaClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 38 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("com.ilargia.games.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(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 39 with JavaClassSource

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

the class EntitasGenerator method generate.

@Override
public List<JavaClassSource> generate(List<ComponentInfo> infos, String pkgDestiny) {
    Map<String, List<ComponentInfo>> mapContextsComponents = CodeGeneratorOld.generateMap(infos);
    List<JavaClassSource> result = new ArrayList<>();
    JavaClassSource source = generateEntitas(mapContextsComponents.keySet(), pkgDestiny);
    mapContextsComponents.forEach((context, lista) -> {
        String fullTypename = lista.get(0).fullTypeName;
    });
    result.add(source);
    return result;
}
Also used : ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) List(java.util.List) ArrayList(java.util.ArrayList)

Example 40 with JavaClassSource

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

the class ComponentContextGenerator method generateContext.

private void generateContext(String contextName, ComponentData data) {
    String pkgDestiny = targetPackageConfig.getTargetPackage();
    if (!contexts.containsKey(contextName)) {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$sContext extends Context<%1$sEntity> {}", contextName));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Context", sourceGen, data.getSubDir());
        contexts.put(contextName, genFile);
        JavaClassSource codeGenerated = genFile.getFileContent();
        if (!pkgDestiny.endsWith(data.getSubDir())) {
            pkgDestiny += "." + data.getSubDir();
        }
        codeGenerated.setPackage(pkgDestiny);
        codeGenerated.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, null);");
        codeGenerated.addImport("ilargia.entitas.Context");
        codeGenerated.addImport("ilargia.entitas.api.*");
        codeGenerated.addImport("ilargia.entitas.api.entitas.EntityBaseFactory");
        if (isUnique(data)) {
            addContextMethods(contextName, data, codeGenerated);
        }
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) 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