Search in sources :

Example 31 with JavaClassSource

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);
    }
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) RefModel(io.swagger.models.RefModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) XmlType(javax.xml.bind.annotation.XmlType)

Example 32 with JavaClassSource

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;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(ilargia.entitas.codeGenerator.data.ComponentInfo)

Example 33 with JavaClassSource

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;
}
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(ilargia.entitas.codeGenerator.data.ComponentInfo) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 34 with JavaClassSource

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;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 35 with JavaClassSource

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;
}
Also used : ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)95 File (java.io.File)37 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)26 ParserResult (org.apache.camel.parser.ParserResult)19 List (java.util.List)15 IOException (java.io.IOException)14 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)12 InputStream (java.io.InputStream)10 Collections (java.util.Collections)10 Roaster (org.jboss.forge.roaster.Roaster)10 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 Matcher (java.util.regex.Matcher)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)8 Arrays (java.util.Arrays)7 Map (java.util.Map)7 Import (org.jboss.forge.roaster.model.source.Import)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7