Search in sources :

Example 1 with JavaClassImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method createNestedClassUpdateTestResult.

private DataObject createNestedClassUpdateTestResult() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package5", "NestedClassUpdateTestResult", null);
    JavaClass nestedClass = new JavaClassImpl("", "UpdatedNestedClass");
    nestedClass.addInterface("java.io.Serializable");
    nestedClass.addInterface("ParametrizedInterface<Double>");
    Annotation generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    nestedClass.addAnnotation(generatedAnnotation);
    MethodImpl method = new MethodImpl("updatedMethod", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
    generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    method.addAnnotation(generatedAnnotation);
    nestedClass.addMethod(method);
    dataObject.addNestedClass(nestedClass);
    return dataObject;
}
Also used : JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Generated(javax.annotation.Generated) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)

Example 2 with JavaClassImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method parseDataObject.

private Pair<DataObject, List<ObjectProperty>> parseDataObject(JavaClassSource javaClassSource) throws ModelDriverException {
    String className;
    String packageName;
    String superClass;
    String qualifiedName;
    ClassTypeResolver classTypeResolver;
    className = javaClassSource.getName();
    packageName = javaClassSource.getPackage();
    qualifiedName = NamingUtils.createQualifiedName(packageName, className);
    if (logger.isDebugEnabled()) {
        logger.debug("Building DataObject for, packageName: " + packageName + ", className: " + className);
    }
    classTypeResolver = DriverUtils.createClassTypeResolver(javaClassSource, classLoader);
    Visibility visibility = DriverUtils.buildVisibility(javaClassSource.getVisibility());
    DataObject dataObject = new DataObjectImpl(packageName, className, visibility, javaClassSource.isAbstract(), javaClassSource.isFinal());
    List<ObjectProperty> unmanagedProperties = new ArrayList<ObjectProperty>();
    try {
        if (javaClassSource.getSuperType() != null) {
            superClass = resolveTypeName(classTypeResolver, javaClassSource.getSuperType());
            dataObject.setSuperClassName(superClass);
        }
        List<AnnotationSource<JavaClassSource>> annotations = javaClassSource.getAnnotations();
        if (annotations != null) {
            for (AnnotationSource annotation : annotations) {
                addJavaClassAnnotation(dataObject, annotation, classTypeResolver);
            }
        }
        List<MethodSource<JavaClassSource>> classMethods = javaClassSource.getMethods();
        if (classMethods != null) {
            for (MethodSource<JavaClassSource> classMethod : classMethods) {
                if (isAccepted(classMethod)) {
                    addMethod(dataObject, classMethod, classTypeResolver);
                }
            }
        }
        List<JavaSource<?>> nestedTypes = javaClassSource.getNestedTypes();
        if (nestedTypes != null) {
            for (JavaSource nestedType : nestedTypes) {
                if (isAccepted(nestedType)) {
                    if (nestedType instanceof JavaClassSource) {
                        JavaClassImpl nestedJavaClass = new JavaClassImpl("", nestedType.getName(), DriverUtils.buildVisibility(nestedType.getVisibility()));
                        dataObject.addNestedClass(nestedJavaClass);
                        if (javaClassSource.getInterfaces() != null) {
                            for (String interfaceDefinition : ((JavaClassSource) nestedType).getInterfaces()) {
                                nestedJavaClass.addInterface(interfaceDefinition);
                            }
                        }
                        List<AnnotationSource<JavaClassSource>> nestedClassAnnotations = nestedType.getAnnotations();
                        if (nestedClassAnnotations != null) {
                            for (AnnotationSource annotation : nestedClassAnnotations) {
                                addJavaClassAnnotation(nestedJavaClass, annotation, classTypeResolver);
                            }
                        }
                        List<MethodSource<JavaClassSource>> nestedClassMethods = ((JavaClassSource) nestedType).getMethods();
                        if (nestedClassMethods != null) {
                            for (Method nestedClassMethod : nestedClassMethods) {
                                if (isAccepted(nestedClassMethod)) {
                                    addMethod(nestedJavaClass, nestedClassMethod, classTypeResolver);
                                }
                            }
                        }
                    }
                }
            }
        }
        List<FieldSource<JavaClassSource>> fields = javaClassSource.getFields();
        if (fields != null) {
            for (FieldSource<JavaClassSource> field : fields) {
                if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) {
                    addProperty(dataObject, field, classTypeResolver);
                } else {
                    logger.debug("field: " + field + "with fieldName: " + field.getName() + " won't be loaded by the diver because type: " + field.getType().getName() + " isn't a managed type.");
                    unmanagedProperties.add(new ObjectPropertyImpl(field.getName(), field.getType().toString(), false, DriverUtils.buildVisibility(field.getVisibility()), field.isStatic(), field.isFinal()));
                }
            }
        }
        List<Import> imports = javaClassSource.getImports();
        if (imports != null) {
            for (Import _import : imports) {
                dataObject.addImport(new ImportImpl(_import.getQualifiedName()));
            }
        }
        return new Pair<DataObject, List<ObjectProperty>>(dataObject, unmanagedProperties);
    } catch (ClassNotFoundException e) {
        logger.error(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
        throw new ModelDriverException(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
    } catch (ModelDriverException e) {
        logger.error(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
        throw new ModelDriverException(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
    }
}
Also used : Import(org.jboss.forge.roaster.model.source.Import) ArrayList(java.util.ArrayList) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) JavaSource(org.jboss.forge.roaster.model.source.JavaSource) FieldSource(org.jboss.forge.roaster.model.source.FieldSource) Pair(org.uberfire.commons.data.Pair) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) Method(org.jboss.forge.roaster.model.Method) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) MethodSource(org.jboss.forge.roaster.model.source.MethodSource) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility) ImportImpl(org.kie.workbench.common.services.datamodeller.core.impl.ImportImpl) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)

Example 3 with JavaClassImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method createNestedClassUpdateTest.

private DataObject createNestedClassUpdateTest() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package5", "NestedClassUpdateTest", null);
    JavaClass nestedClass = new JavaClassImpl("", "NestedClass");
    nestedClass.addInterface("java.io.Serializable");
    nestedClass.addInterface("ParametrizedInterface<Integer>");
    Annotation generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    nestedClass.addAnnotation(generatedAnnotation);
    MethodImpl method = new MethodImpl("method", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
    generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    method.addAnnotation(generatedAnnotation);
    nestedClass.addMethod(method);
    dataObject.addNestedClass(nestedClass);
    return dataObject;
}
Also used : JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Generated(javax.annotation.Generated) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)3 JavaClassImpl (org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl)3 Generated (javax.annotation.Generated)2 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)2 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)2 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)2 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)2 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)2 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)2 JavaClass (org.kie.workbench.common.services.datamodeller.core.JavaClass)2 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)2 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)2 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)2 ArrayList (java.util.ArrayList)1 Method (org.jboss.forge.roaster.model.Method)1 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)1 FieldSource (org.jboss.forge.roaster.model.source.FieldSource)1 Import (org.jboss.forge.roaster.model.source.Import)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1 JavaSource (org.jboss.forge.roaster.model.source.JavaSource)1