Search in sources :

Example 6 with CodeGenFile

use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.

the class ComponentEntityGenerator method getCodeGenFile.

private CodeGenFile<JavaClassSource> getCodeGenFile(String contextName, ComponentData data) {
    if (entities.containsKey(contextName)) {
        return entities.get(contextName);
    } else {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$sEntity extends Entity {}", contextName));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Entity", sourceGen, data.getSubDir());
        entities.put(contextName, genFile);
        return genFile;
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 7 with CodeGenFile

use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.

the class ComponentMatcherGenerator method getCodeGenFile.

private CodeGenFile<JavaClassSource> getCodeGenFile(String contextName, ComponentData data) {
    if (contexts.containsKey(contextName)) {
        return contexts.get(contextName);
    } else {
        JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", WordUtils.capitalize(contextName) + "Matcher"));
        CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>(contextName + "Matcher", sourceGen, data.getSubDir());
        contexts.put(contextName, genFile);
        return genFile;
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 8 with CodeGenFile

use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.

the class EntitasGenerator method generateEntitas.

private CodeGenFile<JavaClassSource> generateEntitas(Set<String> contextNames, String pkgDestiny) {
    JavaClassSource sourceGen = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}");
    CodeGenFile<JavaClassSource> genFile = new CodeGenFile<JavaClassSource>("Entitas", sourceGen, "");
    sourceGen.setPackage(pkgDestiny);
    createMethodConstructor(sourceGen, contextNames);
    createContextsMethod(sourceGen, contextNames);
    createMethodAllContexts(sourceGen, contextNames);
    createContextFields(sourceGen, contextNames);
    System.out.println(genFile.getFileContent());
    return genFile;
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 9 with CodeGenFile

use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.

the class CodeGeneratorJFX method handleGenerate.

@FXML
public void handleGenerate(ActionEvent actionEvent) throws IOException {
    result.setText("");
    progress.setVisible(true);
    result.setText("Generating...");
    if (props != null)
        saveProperties();
    // loads the items at another thread, asynchronously
    Task loader = new Task<List<CodeGenFile>>() {

        {
            setOnSucceeded(workerStateEvent -> {
                progress.setVisible(false);
                result.setText("Success");
            });
            setOnFailed(workerStateEvent -> {
                result.setText("Failed");
                getException().printStackTrace();
            });
        }

        @Override
        protected List<CodeGenFile> call() throws Exception {
            List<ICodeGenerator> codeGenerators = new ArrayList<>();
            // return generator.generate(provider, fieldGeneratedFolder.getText(), codeGenerators);
            return null;
        }
    };
    Thread loadingThread = new Thread(loader, "generated-loader");
    loadingThread.setDaemon(true);
    loadingThread.start();
}
Also used : ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) Task(javafx.concurrent.Task) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) FXML(javafx.fxml.FXML)

Example 10 with CodeGenFile

use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.

the class CodeGenerator method generate.

List<CodeGenFile> generate(String messagePrefix, List<ICodeGeneratorDataProvider> dataProviders, List<ICodeGenerator> codeGenerators, List<ICodeGenFilePostProcessor> postProcessors) {
    _cancel = false;
    List<CodeGeneratorData> data = new ArrayList<>();
    int total = dataProviders.size() + codeGenerators.size() + postProcessors.size();
    int progress = 0;
    for (ICodeGeneratorDataProvider dataProvider : dataProviders) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Creating model", dataProvider.getName(), (float) progress / total);
        }
        data.addAll(dataProvider.getData());
    }
    List<CodeGenFile> files = new ArrayList<>();
    for (ICodeGenerator generator : codeGenerators) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Creating files", generator.getName(), (float) progress / total);
        }
        files.addAll(generator.generate(data));
    }
    for (ICodeGenFilePostProcessor postProcessor : postProcessors) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Processing files", postProcessor.getName(), (float) progress / total);
        }
        files = postProcessor.postProcess(files);
    }
    return files;
}
Also used : ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) ICodeGeneratorDataProvider(ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider) CodeGeneratorData(ilargia.entitas.codeGeneration.data.CodeGeneratorData) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) ArrayList(java.util.ArrayList) ICodeGenFilePostProcessor(ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)

Aggregations

CodeGenFile (ilargia.entitas.codeGeneration.data.CodeGenFile)11 ICodeGenerator (ilargia.entitas.codeGeneration.interfaces.ICodeGenerator)7 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)6 ICodeGeneratorDataProvider (ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider)3 ArrayList (java.util.ArrayList)3 Task (javafx.concurrent.Task)3 FXML (javafx.fxml.FXML)3 java.io (java.io)2 java.util (java.util)2 JavaDocSource (org.jboss.forge.roaster.model.source.JavaDocSource)2 ComponentInfo (com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)1 TypeReflectionProvider (com.ilargia.games.entitas.codeGenerator.providers.TypeReflectionProvider)1 CodeGenerator (ilargia.entitas.codeGeneration.CodeGenerator)1 CodeGeneratorData (ilargia.entitas.codeGeneration.data.CodeGeneratorData)1 ICodeGenFilePostProcessor (ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)1 ComponentInfo (ilargia.entitas.codeGenerator.data.ComponentInfo)1 TypeReflectionProvider (ilargia.entitas.codeGenerator.providers.TypeReflectionProvider)1 TaskAction (org.gradle.api.tasks.TaskAction)1