use of org.jboss.forge.roaster.model.source.JavaClassSource in project herd by FINRAOS.
the class RestControllerProcessor method processRestMethodParameter.
/**
* Process a REST method parameter.
*
* @param parameterSource the parameter source information.
* @param operation the Swagger operation.
* @param methodParamDescriptions the method parameter Javadoc descriptions.
*
* @throws MojoExecutionException if any problems were encountered.
*/
private void processRestMethodParameter(ParameterSource<JavaClassSource> parameterSource, Operation operation, Map<String, String> methodParamDescriptions) throws MojoExecutionException {
log.debug("Processing parameter \"" + parameterSource.getName() + "\".");
try {
AnnotationSource<JavaClassSource> requestParamAnnotationSource = parameterSource.getAnnotation(RequestParam.class);
AnnotationSource<JavaClassSource> requestBodyAnnotationSource = parameterSource.getAnnotation(RequestBody.class);
AnnotationSource<JavaClassSource> pathVariableAnnotationSource = parameterSource.getAnnotation(PathVariable.class);
if (requestParamAnnotationSource != null) {
log.debug("Parameter \"" + parameterSource.getName() + "\" is a RequestParam.");
QueryParameter queryParameter = new QueryParameter();
queryParameter.name(requestParamAnnotationSource.getStringValue("value").trim());
queryParameter.setRequired(BooleanUtils.toBoolean(requestParamAnnotationSource.getStringValue("required")));
setParameterType(parameterSource, queryParameter);
operation.parameter(queryParameter);
setParamDescription(parameterSource, methodParamDescriptions, queryParameter);
} else if (requestBodyAnnotationSource != null) {
log.debug("Parameter \"" + parameterSource.getName() + "\" is a RequestBody.");
// Add the class name to the list of classes which we will create an example for.
exampleClassNames.add(parameterSource.getType().getSimpleName());
BodyParameter bodyParameter = new BodyParameter();
XmlType xmlType = getXmlType(Class.forName(parameterSource.getType().getQualifiedName()));
String name = xmlType.name().trim();
bodyParameter.name(name);
bodyParameter.setRequired(true);
bodyParameter.setSchema(new RefModel(name));
operation.parameter(bodyParameter);
setParamDescription(parameterSource, methodParamDescriptions, bodyParameter);
} else if (pathVariableAnnotationSource != null) {
log.debug("Parameter \"" + parameterSource.getName() + "\" is a PathVariable.");
PathParameter pathParameter = new PathParameter();
pathParameter.name(pathVariableAnnotationSource.getStringValue("value").trim());
setParameterType(parameterSource, pathParameter);
operation.parameter(pathParameter);
setParamDescription(parameterSource, methodParamDescriptions, pathParameter);
}
} catch (ClassNotFoundException e) {
throw new MojoExecutionException("Unable to instantiate class \"" + parameterSource.getType().getQualifiedName() + "\". Reason: " + e.getMessage(), e);
}
}
use of org.jboss.forge.roaster.model.source.JavaClassSource in project Entitas-Java by Rubentxu.
the class MatcherGenerator method generateMatchers.
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;
}
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 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;
}
Aggregations