use of ilargia.entitas.codeGeneration.data.CodeGenFile in project Entitas-Java by Rubentxu.
the class CodeGenerationTask method run.
@TaskAction
public void run() {
CodeGenerationPluginExtension extension = getProject().getExtensions().findByType(CodeGenerationPluginExtension.class);
if (extension == null) {
extension = new CodeGenerationPluginExtension();
}
CodeGenerator codeGenerator = getCodeGenerator(extension, appDomain);
List<CodeGenFile> gen = codeGenerator.generate();
}
use of ilargia.entitas.codeGeneration.data.CodeGenFile 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;
}
use of ilargia.entitas.codeGeneration.data.CodeGenFile 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();
}
use of ilargia.entitas.codeGeneration.data.CodeGenFile 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;
}
use of ilargia.entitas.codeGeneration.data.CodeGenFile 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);
}
}
}
Aggregations