Search in sources :

Example 1 with PropertyMetaTypes

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

the class MainProcessor method processProperties.

private boolean processProperties(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception {
    final boolean isClass = e.getKind() == ElementKind.CLASS;
    if (isClass) {
        TypeElement classElement = (TypeElement) e;
        PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
        String propertyClassName = packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName();
        // Meta-properties
        Property metaProperty = e.getAnnotation(Property.class);
        if (null != metaProperty) {
            PropertyMetaTypes type = metaProperty.meta();
            if (!PropertyMetaTypes.NONE.equals(type)) {
                processingContext.getMetaPropertyTypes().put(type, propertyClassName + ".class");
            }
        }
        // Value fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_VALUE, processingContext.getPropertyAnnotations().getValueFieldNames(), true);
        // Allowed Values fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_ALLOWED_VALUES, processingContext.getPropertyAnnotations().getAllowedValuesFieldNames(), false);
        // Caption fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_CAPTION, processingContext.getPropertyAnnotations().getCaptionFieldNames(), false);
        // Description fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_DESCRIPTION, processingContext.getPropertyAnnotations().getDescriptionFieldNames(), false);
        // Property Type field.
        final boolean propTypeAnnFound = processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_TYPE, processingContext.getPropertyAnnotations().getTypeFieldNames(), false);
        // the value object.
        if (!propTypeAnnFound) {
            Map<String, Element> fieldNames = getFieldNames(classElement, ANNOTATION_PROPERTY_VALUE);
            if (!fieldNames.isEmpty()) {
                final TypeElement te = (TypeElement) fieldNames.values().iterator().next();
                final String type = te.getQualifiedName().toString();
                final Class<?> typeClass = Class.forName(type);
                final Class<? extends PropertyType> defaultPropertyType = DefinitionUtils.getDefaultPropertyType(typeClass);
                if (null != defaultPropertyType) {
                    processingContext.getPropertyAnnotations().getTypes().put(propertyClassName, defaultPropertyType.getName());
                } else {
                    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "No property type specified for class " + propertyClassName, classElement);
                }
            }
        }
        // Read only fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_READONLY, processingContext.getPropertyAnnotations().getReadOnlyFieldNames(), false);
        // Optional fields.
        processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_OPTIONAL, processingContext.getPropertyAnnotations().getOptionalFieldNames(), false);
    }
    return false;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) PropertyMetaTypes(org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes) PackageElement(javax.lang.model.element.PackageElement) MorphProperty(org.kie.workbench.common.stunner.core.definition.annotation.morph.MorphProperty) Property(org.kie.workbench.common.stunner.core.definition.annotation.Property)

Aggregations

Element (javax.lang.model.element.Element)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 Property (org.kie.workbench.common.stunner.core.definition.annotation.Property)1 MorphProperty (org.kie.workbench.common.stunner.core.definition.annotation.morph.MorphProperty)1 PropertyMetaTypes (org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes)1