Search in sources :

Example 16 with AnnotationSource

use of org.jboss.forge.roaster.model.source.AnnotationSource in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method addMethod.

private void addMethod(org.kie.workbench.common.services.datamodeller.core.JavaClass javaClass, Method method, ClassTypeResolver classTypeResolver) throws ClassNotFoundException, ModelDriverException {
    List<Parameter> parameters = method.getParameters();
    List<org.kie.workbench.common.services.datamodeller.core.Parameter> modelParameters = new ArrayList<>();
    if (parameters != null) {
        for (Parameter parameter : parameters) {
            modelParameters.add(new org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl(new org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl(resolveTypeName(classTypeResolver, parameter.getType().getName()), resolveTypeArguments(parameter.getType().getTypeArguments())), parameter.getName()));
        }
    }
    org.kie.workbench.common.services.datamodeller.core.Type returnType = null;
    if (method.getReturnType() != null) {
        returnType = new org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl(resolveTypeName(classTypeResolver, method.getReturnType().getName()), resolveTypeArguments(method.getReturnType().getTypeArguments()));
    }
    Visibility visibility = Visibility.PACKAGE_PRIVATE;
    if (method.getVisibility() != null) {
        visibility = DriverUtils.buildVisibility(method.getVisibility());
    }
    MethodImpl dataObjectMethod = new MethodImpl(method.getName(), modelParameters, method.getBody(), returnType, visibility);
    List<AnnotationSource<JavaClassSource>> annotations = method.getAnnotations();
    if (annotations != null) {
        for (AnnotationSource annotation : annotations) {
            dataObjectMethod.addAnnotation(createAnnotation(annotation, classTypeResolver));
        }
    }
    javaClass.addMethod(dataObjectMethod);
}
Also used : ArrayList(java.util.ArrayList) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) Parameter(org.jboss.forge.roaster.model.Parameter) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility)

Example 17 with AnnotationSource

use of org.jboss.forge.roaster.model.source.AnnotationSource in project kie-wb-common by kiegroup.

the class JavaSourceVisitor method visit.

public void visit(FieldSource<? extends JavaSource> fieldSource) {
    Type fieldType = fieldSource.getType();
    String fieldClassName;
    // the javadoc for Named.getName() is misleading:
    // the FieldSource.getName() (which is implemented by FieldImpl.getName())
    // returns the (fully-qualified!) name of the field
    String fieldName = fieldSource.getName();
    resParts.addPart(fieldName, PartType.FIELD);
    try {
        if (DriverUtils.isManagedType(fieldType, classTypeResolver)) {
            if (fieldType.isPrimitive()) {
                fieldClassName = fieldType.getName();
            } else if (DriverUtils.isSimpleClass(fieldType)) {
                fieldClassName = classTypeResolver.getFullTypeName(fieldType.getName());
            } else {
                // if this point was reached, we know it's a Collection.
                // Managed type check was done previously.
                Type elementsType = ((List<Type>) fieldType.getTypeArguments()).get(0);
                fieldClassName = classTypeResolver.getFullTypeName(elementsType.getName());
            }
        } else {
            // mriet: not complete sure why we don't just do this instead of using DriverUtils?
            fieldClassName = fieldType.getQualifiedName();
        }
        addJavaResourceReference(fieldClassName);
    } catch (Exception e) {
        logger.error("Unable to index java class field for class: " + javaSource.getQualifiedName() + ", fieldName: " + fieldName + " fieldType: " + fieldType);
    }
    // Field annotations
    for (AnnotationSource annoSource : fieldSource.getAnnotations()) {
        visit(annoSource);
    }
}
Also used : Type(org.jboss.forge.roaster.model.Type) PartType(org.kie.workbench.common.services.refactoring.service.PartType) ResourceType(org.kie.workbench.common.services.refactoring.service.ResourceType) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) JavaAnnotationSource(org.jboss.forge.roaster.model.source.JavaAnnotationSource)

Aggregations

AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)17 ArrayList (java.util.ArrayList)11 List (java.util.List)8 Type (org.jboss.forge.roaster.model.Type)6 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)4 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3 Modifier (java.lang.reflect.Modifier)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 URLClassLoader (java.net.URLClassLoader)3