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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations