use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processConnectionRules.
private boolean processConnectionRules(final Element element) {
final Messager messager = processingEnv.getMessager();
final boolean isIface = element.getKind() == ElementKind.INTERFACE;
final boolean isClass = element.getKind() == ElementKind.CLASS;
if (isIface || isClass) {
TypeElement classElement = (TypeElement) element;
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
messager.printMessage(Diagnostic.Kind.NOTE, "Discovered connection rule for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_CONNECTION_SUFFIX_CLASSNAME;
generateRuleCode(connectionRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processContainmentRules.
private boolean processContainmentRules(final Element e) {
final Messager messager = processingEnv.getMessager();
final boolean isIface = e.getKind() == ElementKind.INTERFACE;
final boolean isClass = e.getKind() == ElementKind.CLASS;
if (isIface || isClass) {
TypeElement classElement = (TypeElement) e;
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
messager.printMessage(Diagnostic.Kind.NOTE, "Discovered containment rule for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_CONTAINMENT_SUFFIX_CLASSNAME;
generateRuleCode(containmentRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processDefinitions.
private boolean processDefinitions(final Element e) {
final boolean isClass = e.getKind() == ElementKind.CLASS;
if (isClass) {
TypeElement classElement = (TypeElement) e;
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
String defintionClassName = packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName();
Map<String, String> baseTypes = processingContext.getDefinitionAnnotations().getBaseTypes();
TypeElement parentElement = getDefinitionInheritedType(classElement);
if (null != parentElement && !baseTypes.containsKey(defintionClassName)) {
PackageElement basePackageElement = (PackageElement) parentElement.getEnclosingElement();
String baseClassName = basePackageElement.getQualifiedName().toString() + "." + parentElement.getSimpleName();
baseTypes.put(defintionClassName, baseClassName);
}
// Id field.
processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_ID, processingContext.getDefinitionAnnotations().getIdFieldNames(), false);
// Category field.
processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_CATEGORY, processingContext.getDefinitionAnnotations().getCategoryFieldNames(), true);
// Title field.
processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_TITLE, processingContext.getDefinitionAnnotations().getTitleFieldNames(), false);
// Description field.
processFieldName(classElement, defintionClassName, ANNOTATION_DESCRIPTION, processingContext.getDefinitionAnnotations().getDescriptionFieldNames(), false);
// Labels field.
processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_LABELS, processingContext.getDefinitionAnnotations().getLabelsFieldNames(), true);
// Builder class.
processDefinitionModelBuilder(e, defintionClassName, processingContext.getDefinitionAnnotations().getBuilderFieldNames());
// Graph element.
Definition definitionAnn = e.getAnnotation(Definition.class);
TypeMirror mirror = null;
try {
definitionAnn.graphFactory();
} catch (MirroredTypeException mte) {
mirror = mte.getTypeMirror();
}
if (null == mirror) {
throw new RuntimeException("No graph factory class specified for the @Definition.");
}
String fqcn = mirror.toString();
processingContext.getDefinitionAnnotations().getGraphFactory().put(defintionClassName, fqcn);
// Properties fields.
Map<String, VariableElement> propertyFields = visitVariables("", classElement, variableElement -> hasAnnotation(variableElement, ANNOTATION_PROPERTY));
List<String> propertyFieldNames = new ArrayList<>();
List<Boolean> typedPropertyFields = new ArrayList<>();
DefinitionAdapterBindings.PropertyMetaTypes defMetaTypes = new DefinitionAdapterBindings.PropertyMetaTypes();
propertyFields.forEach((field, variable) -> {
TypeMirror type = variable.asType();
TypeElement element = (TypeElement) ((DeclaredType) type).asElement();
String elementClassName = GeneratorUtils.getTypeMirrorDeclaredName(element.asType());
boolean isTypedProperty = processingContext.getPropertyAnnotations().getValueFieldNames().containsKey(elementClassName);
int index = propertyFieldNames.size();
Property propertyAnnotation = variable.getAnnotation(Property.class);
// Populate the context collections.
propertyFieldNames.add(field);
typedPropertyFields.add(isTypedProperty);
org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes propertyMetaType = propertyAnnotation.meta();
if (org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes.NONE.equals(propertyMetaType)) {
propertyMetaType = getDeclaredMetaType(elementClassName);
}
if (null != propertyMetaType) {
defMetaTypes.setIndex(propertyMetaType, index);
}
});
processingContext.getDefinitionAnnotations().getPropertyFieldNames().put(defintionClassName, propertyFieldNames);
processingContext.getDefinitionAnnotations().getTypedPropertyFields().put(defintionClassName, typedPropertyFields);
processingContext.getMetaPropertyTypesFields().put(defintionClassName, defMetaTypes);
// -- Morphing annotations --
MorphBase morphBaseAnn = e.getAnnotation(MorphBase.class);
Morph morphAnn = e.getAnnotation(Morph.class);
if (null != morphBaseAnn && null != morphAnn) {
TypeElement superElement = getAnnotationInTypeInheritance(classElement, MorphBase.class.getName());
final String packageName = packageElement.getQualifiedName().toString();
String morphBaseClassName = packageName + "." + superElement.getSimpleName().toString();
Map<String, String> defaultTypesMap = processingContext.getMorphingAnnotations().getBaseDefaultTypes();
if (null == defaultTypesMap.get(morphBaseClassName)) {
TypeMirror morphDefaultTypeMirror = null;
try {
morphBaseAnn.defaultType();
} catch (MirroredTypeException mte) {
morphDefaultTypeMirror = mte.getTypeMirror();
}
if (null == morphDefaultTypeMirror) {
throw new RuntimeException("No default type class declared for the @MorphBase.");
}
String morphDefaultTypeClassName = morphDefaultTypeMirror.toString();
processingContext.getMorphingAnnotations().getBaseDefaultTypes().put(morphBaseClassName, morphDefaultTypeClassName);
// MorphBase - targets
List<? extends TypeMirror> morphTargetMirrors = null;
try {
morphBaseAnn.targets();
} catch (MirroredTypesException mte) {
morphTargetMirrors = mte.getTypeMirrors();
}
if (null != morphTargetMirrors) {
Set<String> morphTargetMirrorClasses = new LinkedHashSet<>();
for (TypeMirror morphTargetMirror : morphTargetMirrors) {
String morphTargetMirrorClassName = morphTargetMirror.toString();
morphTargetMirrorClasses.add(morphTargetMirrorClassName);
}
processingContext.getMorphingAnnotations().getBaseTargets().put(morphBaseClassName, morphTargetMirrorClasses);
}
// Morph Properties.
processMorphProperties(superElement, morphBaseClassName);
}
TypeMirror morphBaseTypeMirror = null;
try {
morphAnn.base();
} catch (MirroredTypeException mte) {
morphBaseTypeMirror = mte.getTypeMirror();
}
if (null == morphBaseTypeMirror) {
throw new RuntimeException("No base type class declared for the @MorphBase.");
}
String morphBaseTypeClassName = morphBaseTypeMirror.toString();
Set<String> currentTargets = processingContext.getMorphingAnnotations().getBaseTargets().computeIfAbsent(morphBaseTypeClassName, k -> new LinkedHashSet<>());
currentTargets.add(defintionClassName);
}
}
return false;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processEdgeCardinalityRules.
private boolean processEdgeCardinalityRules(final Element e) {
final Messager messager = processingEnv.getMessager();
final boolean isIface = e.getKind() == ElementKind.INTERFACE;
final boolean isClass = e.getKind() == ElementKind.CLASS;
if (isIface || isClass) {
TypeElement classElement = (TypeElement) e;
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
messager.printMessage(Diagnostic.Kind.NOTE, "Discovered edge cardinality rule for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_EDGE_CARDINALITY_SUFFIX_CLASSNAME;
generateRuleCode(edgeCardinalityRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processRuleExtension.
private boolean processRuleExtension(final Element e) {
final Messager messager = processingEnv.getMessager();
final boolean isIface = e.getKind() == ElementKind.INTERFACE;
final boolean isClass = e.getKind() == ElementKind.CLASS;
if (isIface || isClass) {
TypeElement classElement = (TypeElement) e;
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
messager.printMessage(Diagnostic.Kind.NOTE, "Discovered rule extension for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_EXTENSION_SUFFIX_CLASSNAME;
generateRuleCode(extensionRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
Aggregations