Search in sources :

Example 1 with ICodeGenerator

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenerator in project Entitas-Java by Rubentxu.

the class EntitasGradleProject method getCodeGenerator.

@Override
public CodeGenerator getCodeGenerator() {
    Properties properties = loadProperties();
    CodeGeneratorConfig config = new CodeGeneratorConfig();
    config.configure(properties);
    List<Class> types = loadTypesFromPlugins(properties);
    List<ICodeGeneratorDataProvider> dataProviders = getEnabledInstances(types, config.getDataProviders(), ICodeGeneratorDataProvider.class);
    List<ICodeGenerator> codeGenerators = getEnabledInstances(types, config.getCodeGenerators(), ICodeGenerator.class);
    List<ICodeGenFilePostProcessor> postProcessors = getEnabledInstances(types, config.getPostProcessors(), ICodeGenFilePostProcessor.class);
    configure(dataProviders, properties);
    configure(codeGenerators, properties);
    configure(postProcessors, properties);
    return new CodeGenerator(dataProviders, codeGenerators, postProcessors);
}
Also used : CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) ICodeGeneratorDataProvider(ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider) ICodeGenFilePostProcessor(ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor) CodeGenerator(ilargia.entitas.codeGeneration.CodeGenerator) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) Properties(java.util.Properties)

Example 2 with ICodeGenerator

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenerator 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 3 with ICodeGenerator

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenerator in project Entitas-Java by Rubentxu.

the class CodeGeneratorApp 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<>();
            if (componentsGenerator.isSelected())
                codeGenerators.add(new EntityGenerator());
            if (componentIndicesGenerator.isSelected())
                codeGenerators.add(new ComponentIndicesGenerator());
            if (contextsGenerator.isSelected())
                codeGenerators.add(new ContextGenerator());
            codeGenerators.add(new MatcherGenerator());
            codeGenerators.add(new EntitasGenerator());
            TypeReflectionProvider provider = new TypeReflectionProvider(fieldComponentFolder.getText());
            CodeGeneratorOld generator = new CodeGeneratorOld();
            return generator.generate(provider, fieldGeneratedFolder.getText(), codeGenerators);
        }
    };
    Thread loadingThread = new Thread(loader, "generated-loader");
    loadingThread.setDaemon(true);
    loadingThread.start();
}
Also used : Task(javafx.concurrent.Task) ArrayList(java.util.ArrayList) TypeReflectionProvider(com.ilargia.games.entitas.codeGenerator.providers.TypeReflectionProvider) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) FXML(javafx.fxml.FXML)

Example 4 with ICodeGenerator

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenerator 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 5 with ICodeGenerator

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenerator 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

ICodeGenerator (ilargia.entitas.codeGeneration.interfaces.ICodeGenerator)5 CodeGenFile (ilargia.entitas.codeGeneration.data.CodeGenFile)4 ICodeGeneratorDataProvider (ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider)3 ICodeGenFilePostProcessor (ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)2 ArrayList (java.util.ArrayList)2 Task (javafx.concurrent.Task)2 FXML (javafx.fxml.FXML)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 CodeGeneratorConfig (ilargia.entitas.codeGeneration.config.CodeGeneratorConfig)1 CodeGeneratorData (ilargia.entitas.codeGeneration.data.CodeGeneratorData)1 java.io (java.io)1 java.util (java.util)1 Properties (java.util.Properties)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1 JavaDocSource (org.jboss.forge.roaster.model.source.JavaDocSource)1