Java Code Examples for org.jboss.forge.roaster.model.source.JavaClassSource#setPackage()
The following examples show how to use
org.jboss.forge.roaster.model.source.JavaClassSource#setPackage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentIndicesGenerator.java From Entitas-Java with MIT License | 6 votes |
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 && componentInfos.get(0).directory !=null) { // pkgDestiny+= "."+componentInfos.get(0).directory; // // } 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; }
Example 2
Source File: MatcherGenerator.java From Entitas-Java with MIT License | 6 votes |
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) { JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(contextName) + "Matcher")); if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) { pkgDestiny += "." + componentInfos.get(0).subDir; } javaClass.setPackage(pkgDestiny); //javaClass.addImport("com.ilargia.games.entitas.interfaces.IMatcher"); javaClass.addImport("Matcher"); for (ComponentInfo info : componentInfos) { addMatcher(contextName, info, javaClass); addMatcherMethods(contextName, info, javaClass); } System.out.println(javaClass); return javaClass; }
Example 3
Source File: WriteToDiskPostProcessor.java From Entitas-Java with MIT License | 6 votes |
public File createFile(String className, String subDir, JavaClassSource content) { String targetPackage = targetPackageConfig.getTargetPackage(); String finalPackage = subDir.equals("") || className.contains("Shared")? String.format("%s", targetPackage) : String.format("%s.%s", targetPackage, subDir); content.setPackage(finalPackage); String pathPackage = targetPackage.replace(".", "/"); String pathFile = subDir.equals("") || className.contains("Shared")? String.format("%s/%s/%s.java", projectConfig.getSrcDirs().get(0), pathPackage, className) : String.format("%s/%s/%s/%s.java", projectConfig.getSrcDirs().get(0), pathPackage, subDir, className); File file = new File(pathFile); CodeGeneratorUtil.writeFile(file, content.toString()); return file; }
Example 4
Source File: ComponentLookupGenerator.java From Entitas-Java with MIT License | 6 votes |
private JavaClassSource generateIndicesLookup(String contextName, List<ComponentData> dataList) { String pkgDestiny = targetPackageConfig.getTargetPackage(); JavaClassSource codeGen = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", WordUtils.capitalize(contextName) + DEFAULT_COMPONENT_LOOKUP_TAG)); if (dataList.size() > 0 && !pkgDestiny.endsWith(dataList.get(0).getSubDir()) ) { // pkgDestiny += "." + dataList.get(0).getSubDir(); } codeGen.setPackage(pkgDestiny); addIndices(dataList, codeGen); addComponentNames(dataList, codeGen); addComponentTypes(dataList, codeGen); System.out.println(codeGen); return codeGen; }
Example 5
Source File: ComponentMatcherGenerator.java From Entitas-Java with MIT License | 6 votes |
private void generateMatcher(String contextName, ComponentData data) { String pkgDestiny = targetPackageConfig.getTargetPackage(); CodeGenFile<JavaClassSource> genFile = getCodeGenFile(contextName, data); JavaClassSource codeGenerated = genFile.getFileContent(); if (!pkgDestiny.endsWith(data.getSubDir())) { pkgDestiny += "." + data.getSubDir(); } codeGenerated.setPackage(pkgDestiny); codeGenerated.addImport(Matcher.class); addMatcher(contextName, data, codeGenerated); addMatcherMethods(contextName, data, codeGenerated); }
Example 6
Source File: ComponentIndicesGenerator.java From Entitas-Java with MIT License | 6 votes |
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 && componentInfos.get(0).directory !=null) { // pkgDestiny+= "."+componentInfos.get(0).directory; // // } 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; }
Example 7
Source File: MatcherGenerator.java From Entitas-Java with MIT License | 6 votes |
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) { JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(contextName) + "Matcher")); if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) { pkgDestiny += "." + componentInfos.get(0).subDir; } javaClass.setPackage(pkgDestiny); //javaClass.addImport("ilargia.entitas.interfaces.IMatcher"); javaClass.addImport("Matcher"); for (ComponentInfo info : componentInfos) { addMatcher(contextName, info, javaClass); addMatcherMethods(contextName, info, javaClass); } System.out.println(javaClass); return javaClass; }
Example 8
Source File: EntitasGenerator.java From Entitas-Java with MIT License | 5 votes |
public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) { JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}"); javaClass.setPackage(pkgDestiny); createMethodConstructor(javaClass, contextNames); createContextsMethod(javaClass, contextNames); createMethodAllContexts(javaClass, contextNames); createContextFields(javaClass, contextNames); return javaClass; }
Example 9
Source File: ContextGenerator.java From Entitas-Java with MIT License | 5 votes |
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 && infos.get(0).directory !=null) { // pkgDestiny+= "."+infos.get(0).directory; // // } 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; }
Example 10
Source File: ComponentContextGenerator.java From Entitas-Java with MIT License | 5 votes |
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); } } }
Example 11
Source File: EntitasGenerator.java From Entitas-Java with MIT License | 5 votes |
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; }
Example 12
Source File: ComponentEntityGenerator.java From Entitas-Java with MIT License | 5 votes |
private void generateEntity(String contextName, ComponentData data) { String pkgDestiny = targetPackageConfig.getTargetPackage(); CodeGenFile<JavaClassSource> genFile = getCodeGenFile(contextName, data); JavaClassSource codeGenerated = genFile.getFileContent(); if (!pkgDestiny.endsWith(data.getSubDir())) { pkgDestiny += "." + data.getSubDir(); } if (codeGenerated.getPackage() == null) { codeGenerated.setPackage(pkgDestiny); codeGenerated.addMethod() .setName(contextName + "Entity") .setPublic() .setConstructor(true) .setBody(""); codeGenerated.addImport("ilargia.entitas.Entity"); } if (shouldGenerateMethods(data)) { addImporEnums(data, codeGenerated); addEntityMethods(contextName, data, codeGenerated); } if (isSharedContext(data) && codeGenerated.getImport(targetPackageConfig.getTargetPackage()) == null) { codeGenerated.addImport(targetPackageConfig.getTargetPackage() + ".SharedComponentsLookup"); } }
Example 13
Source File: EntitasGenerator.java From Entitas-Java with MIT License | 5 votes |
public JavaClassSource generateEntitas(Set<String> contextNames, String pkgDestiny) { JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, "public class Entitas implements IContexts{}"); javaClass.setPackage(pkgDestiny); createMethodConstructor(javaClass, contextNames); createContextsMethod(javaClass, contextNames); createMethodAllContexts(javaClass, contextNames); createContextFields(javaClass, contextNames); return javaClass; }
Example 14
Source File: ContextGenerator.java From Entitas-Java with MIT License | 5 votes |
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 && infos.get(0).directory !=null) { // pkgDestiny+= "."+infos.get(0).directory; // // } 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("ilargia.entitas.api.*"); for (ComponentInfo info : infos) { if (info.isSingleEntity) { addContextMethods(contextName, info, contextClass); } } return contextClass; }
Example 15
Source File: CamelNewRouteBuilderCommand.java From fabric8-forge with Apache License 2.0 | 4 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { Project project = getSelectedProject(context); JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); // does the project already have camel? Dependency core = findCamelCoreDependency(project); if (core == null) { return Results.fail("The project does not include camel-core"); } // do we already have a class with the name String fqn = targetPackage.getValue() != null ? targetPackage.getValue() + "." + name.getValue() : name.getValue(); JavaResource existing = facet.getJavaResource(fqn); if (existing != null && existing.exists()) { return Results.fail("A class with name " + fqn + " already exists"); } // need to parse to be able to extends another class final JavaClassSource javaClass = Roaster.create(JavaClassSource.class); javaClass.setName(name.getValue()); if (targetPackage.getValue() != null) { javaClass.setPackage(targetPackage.getValue()); } javaClass.setSuperType("RouteBuilder"); javaClass.addImport("org.apache.camel.builder.RouteBuilder"); boolean cdi = CamelCommandsHelper.isCdiProject(getSelectedProject(context)); boolean spring = CamelCommandsHelper.isSpringProject(getSelectedProject(context)); if (cdi) { javaClass.addAnnotation("javax.inject.Singleton"); } else if (spring) { javaClass.addAnnotation("org.springframework.stereotype.Component"); } javaClass.addMethod() .setPublic() .setReturnTypeVoid() .setName("configure") .addThrows(Exception.class).setBody(""); JavaResource javaResource = facet.saveJavaSource(javaClass); // if we are in an GUI editor then open the file if (isRunningInGui(context.getUIContext())) { context.getUIContext().setSelection(javaResource); } return Results.success("Created new RouteBuilder class " + name.getValue()); }