Search in sources :

Example 1 with DefinitionSet

use of org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet in project kie-wb-common by kiegroup.

the class MainProcessor method processDefinitionSetModelBuilder.

private void processDefinitionSetModelBuilder(final Element e, final String className, final Map<String, String> processingContextMap) {
    DefinitionSet definitionAnn = e.getAnnotation(DefinitionSet.class);
    TypeMirror bMirror = null;
    try {
        Class<?> builderClass = definitionAnn.builder();
    } catch (MirroredTypeException mte) {
        bMirror = mte.getTypeMirror();
    }
    if (null != bMirror && !VoidBuilder.class.getName().equals(bMirror.toString())) {
        String fqcn = bMirror.toString();
        processingContextMap.put(className, fqcn);
    }
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) TypeMirror(javax.lang.model.type.TypeMirror) VoidBuilder(org.kie.workbench.common.stunner.core.definition.builder.VoidBuilder) DefinitionSet(org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet)

Example 2 with DefinitionSet

use of org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet in project kie-wb-common by kiegroup.

the class BackendBindableDefinitionUtils method getDefinitions.

public static <T> Set<Class<?>> getDefinitions(final T definitionSet) {
    Set<Class<?>> result = null;
    if (null != definitionSet) {
        DefinitionSet annotation = definitionSet.getClass().getAnnotation(DefinitionSet.class);
        if (null != annotation) {
            Class<?>[] definitions = annotation.definitions();
            if (definitions.length > 0) {
                result = new HashSet<Class<?>>(definitions.length);
                Collections.addAll(result, definitions);
            }
        }
    }
    return result;
}
Also used : DefinitionSet(org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet)

Example 3 with DefinitionSet

use of org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet in project kie-wb-common by kiegroup.

the class MainProcessor method processDefinitionSets.

private boolean processDefinitionSets(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception {
    final Messager messager = processingEnv.getMessager();
    final boolean isClass = e.getKind() == ElementKind.CLASS;
    if (isClass) {
        TypeElement classElement = (TypeElement) e;
        PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
        messager.printMessage(Diagnostic.Kind.NOTE, "Discovered definition set class [" + classElement.getSimpleName() + "]");
        final String packageName = packageElement.getQualifiedName().toString();
        final String className = classElement.getSimpleName().toString();
        processingContext.setDefinitionSet(packageName, className);
        String defSetClassName = packageName + "." + className;
        // Description fields.
        processFieldName(classElement, defSetClassName, ANNOTATION_DESCRIPTION, processingContext.getDefSetAnnotations().getDescriptionFieldNames(), false);
        // Definitions identifiers.
        DefinitionSet definitionSetAnn = e.getAnnotation(DefinitionSet.class);
        List<? extends TypeMirror> mirrors = null;
        try {
            Class<?>[] defsClasses = definitionSetAnn.definitions();
        } catch (MirroredTypesException mte) {
            mirrors = mte.getTypeMirrors();
        }
        if (null == mirrors) {
            throw new RuntimeException("No graph class class specifyed for the @DefinitionSet.");
        }
        Set<String> defIds = new LinkedHashSet<>();
        for (TypeMirror mirror : mirrors) {
            if (mirror.getKind().equals(TypeKind.DECLARED)) {
                final TypeElement t = (TypeElement) ((DeclaredType) mirror).asElement();
                processingContext.getDefinitionElements().add(t);
            }
            String fqcn = mirror.toString();
            defIds.add(fqcn);
        }
        processingContext.getDefSetAnnotations().getDefinitionIds().addAll(defIds);
        // Builder class.
        processDefinitionSetModelBuilder(e, defSetClassName, processingContext.getDefSetAnnotations().getBuilderFieldNames());
        // Graph factory type.
        TypeMirror mirror = null;
        try {
            Class<?> graphClass = definitionSetAnn.graphFactory();
        } catch (MirroredTypeException mte) {
            mirror = mte.getTypeMirror();
        }
        if (null == mirror) {
            throw new RuntimeException("No graph factory class specifyed for the @DefinitionSet.");
        }
        String fqcn = mirror.toString();
        processingContext.getDefSetAnnotations().getGraphFactoryTypes().put(defSetClassName, fqcn);
        // Definition Set's qualifier.
        try {
            Class<?> qualifierClass = definitionSetAnn.qualifier();
        } catch (MirroredTypeException mte) {
            mirror = mte.getTypeMirror();
        }
        if (null == mirror) {
            throw new RuntimeException("No qualifier class specifyed for the @DefinitionSet.");
        }
        processingContext.getDefSetAnnotations().getQualifiers().put(defSetClassName, mirror.toString());
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MirroredTypesException(javax.lang.model.type.MirroredTypesException) Messager(javax.annotation.processing.Messager) TypeElement(javax.lang.model.element.TypeElement) MirroredTypeException(javax.lang.model.type.MirroredTypeException) TypeMirror(javax.lang.model.type.TypeMirror) PackageElement(javax.lang.model.element.PackageElement) DefinitionSet(org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet)

Aggregations

DefinitionSet (org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet)3 MirroredTypeException (javax.lang.model.type.MirroredTypeException)2 TypeMirror (javax.lang.model.type.TypeMirror)2 LinkedHashSet (java.util.LinkedHashSet)1 Messager (javax.annotation.processing.Messager)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeElement (javax.lang.model.element.TypeElement)1 MirroredTypesException (javax.lang.model.type.MirroredTypesException)1 VoidBuilder (org.kie.workbench.common.stunner.core.definition.builder.VoidBuilder)1