Search in sources :

Example 1 with MorphProperty

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

the class MainProcessor method processMorphProperties.

private void processMorphProperties(final TypeElement classElement, final String definitionClassName) {
    final Messager messager = processingEnv.getMessager();
    final Elements elementUtils = processingEnv.getElementUtils();
    List<VariableElement> variableElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
    for (VariableElement variableElement : variableElements) {
        if (GeneratorUtils.getAnnotation(elementUtils, variableElement, ANNOTATION_MORPH_PROPERTY) != null) {
            final TypeMirror fieldReturnType = variableElement.asType();
            final String fieldReturnTypeName = GeneratorUtils.getTypeMirrorDeclaredName(fieldReturnType);
            final String fieldName = variableElement.getSimpleName().toString();
            messager.printMessage(Diagnostic.Kind.NOTE, "Discovered Morph Property " + "for class [" + classElement.getSimpleName() + "] " + "at field [" + fieldName + "] " + "of return type [" + fieldReturnTypeName + "]");
            // MorphBase - defaultType
            MorphProperty morphBaseAnn = variableElement.getAnnotation(MorphProperty.class);
            TypeMirror morphDefaultTypeMirror = null;
            try {
                morphBaseAnn.binder();
            } catch (MirroredTypeException mte) {
                morphDefaultTypeMirror = mte.getTypeMirror();
            }
            if (null == morphDefaultTypeMirror) {
                throw new RuntimeException("No binder class declared for the @MorphProperty.");
            }
            String binderClassName = morphDefaultTypeMirror.toString();
            ProcessingMorphProperty morphProperty = new ProcessingMorphProperty(fieldReturnTypeName, StringUtils.capitalize(fieldName), binderClassName);
            List<ProcessingMorphProperty> morphProperties = processingContext.getMorphingAnnotations().getBaseMorphProperties().computeIfAbsent(definitionClassName, k -> new LinkedList<>());
            morphProperties.add(morphProperty);
        }
    }
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) MorphProperty(org.kie.workbench.common.stunner.core.definition.annotation.morph.MorphProperty) Messager(javax.annotation.processing.Messager) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) Elements(javax.lang.model.util.Elements)

Aggregations

Messager (javax.annotation.processing.Messager)1 VariableElement (javax.lang.model.element.VariableElement)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Elements (javax.lang.model.util.Elements)1 MorphProperty (org.kie.workbench.common.stunner.core.definition.annotation.morph.MorphProperty)1