use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processProperties.
private boolean processProperties(final Element e) {
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) {
org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes type = metaProperty.meta();
if (!org.kie.workbench.common.stunner.core.definition.property.PropertyMetaTypes.NONE.equals(type)) {
processingContext.getMetaPropertyTypes().put(type, propertyClassName + ".class");
}
}
// Value fields.
processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_VALUE, processingContext.getPropertyAnnotations().getValueFieldNames(), true);
}
return false;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processCardinalityRules.
private boolean processCardinalityRules(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 cardinality rule for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_CARDINALITY_SUFFIX_CLASSNAME;
generateRuleCode(cardinalityRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
use of javax.lang.model.element.PackageElement in project kie-wb-common by kiegroup.
the class MainProcessor method processDockingRules.
private boolean processDockingRules(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 docking rule for class [" + classElement.getSimpleName() + "]");
final String classNameActivity = classElement.getSimpleName() + RULE_DOCKING_SUFFIX_CLASSNAME;
generateRuleCode(dockingRuleGenerator, messager, classElement, packageElement, classNameActivity);
}
return true;
}
use of javax.lang.model.element.PackageElement in project qpid-broker-j by apache.
the class ConfiguredObjectFactoryGenerator method generateAccessControlEnforcingSubclass.
private void generateAccessControlEnforcingSubclass(final Filer filer, final ExecutableElement constructorElement) {
TypeElement classElement = (TypeElement) constructorElement.getEnclosingElement();
String childClassName = classElement.getQualifiedName().toString() + "WithAccessChecking";
String childClassSimpleName = classElement.getSimpleName().toString() + "WithAccessChecking";
String objectSimpleName = classElement.getSimpleName().toString();
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
try {
JavaFileObject factoryFile = filer.createSourceFile(childClassName);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(factoryFile.openOutputStream(), "UTF-8"));
pw.println("/*");
for (String headerLine : License.LICENSE) {
pw.println(" *" + headerLine);
}
pw.println(" */");
pw.println();
pw.print("package ");
pw.print(packageElement.getQualifiedName());
pw.println(";");
pw.println();
pw.println("import static org.apache.qpid.server.security.access.Operation.INVOKE_METHOD;");
pw.println();
pw.println("import java.util.Map;");
pw.println("import java.util.concurrent.ExecutionException;");
pw.println();
pw.println("import com.google.common.util.concurrent.Futures;");
pw.println("import com.google.common.util.concurrent.ListenableFuture;");
pw.println();
pw.println("import org.apache.qpid.server.configuration.updater.Task;");
pw.println("import org.apache.qpid.server.util.FixedKeyMapCreator;");
pw.println();
pw.println("final class " + childClassSimpleName + " extends " + objectSimpleName);
pw.println("{");
pw.print(" " + childClassSimpleName + "(final Map<String, Object> attributes");
boolean first = true;
for (VariableElement param : constructorElement.getParameters()) {
if (first) {
first = false;
} else {
pw.print(", final " + param.asType() + " " + createParamNameFromType(param));
}
}
pw.println(")");
pw.println(" {");
pw.print(" super(attributes");
first = true;
for (VariableElement param : constructorElement.getParameters()) {
if (first) {
first = false;
} else {
pw.print(", " + createParamNameFromType(param));
}
}
pw.println(");");
pw.println(" }");
pw.println();
generateAccessCheckedMethods(childClassSimpleName, classElement, pw, new HashSet<TypeElement>(), new HashSet<String>());
pw.println("}");
pw.close();
} catch (ClassNotFoundException | IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to write file: " + childClassName + " - " + e.getLocalizedMessage());
}
}
use of javax.lang.model.element.PackageElement in project qpid-broker-j by apache.
the class ConfiguredObjectFactoryGenerator method generateObjectFactory.
private String generateObjectFactory(final Filer filer, final ExecutableElement constructorElement) {
TypeElement classElement = (TypeElement) constructorElement.getEnclosingElement();
String objectQualifiedClassName = classElement.getQualifiedName().toString();
String factoryName = objectQualifiedClassName + "Factory";
String factorySimpleName = classElement.getSimpleName().toString() + "Factory";
String objectSimpleName = classElement.getSimpleName().toString();
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generating factory file for " + objectQualifiedClassName);
final ManagedObjectFactoryConstructor annotation = constructorElement.getAnnotation(ManagedObjectFactoryConstructor.class);
PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
try {
JavaFileObject factoryFile = filer.createSourceFile(factoryName);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(factoryFile.openOutputStream(), "UTF-8"));
pw.println("/*");
for (String headerLine : License.LICENSE) {
pw.println(" *" + headerLine);
}
pw.println(" */");
pw.println();
pw.print("package ");
pw.print(packageElement.getQualifiedName());
pw.println(";");
pw.println();
pw.println("import java.util.Map;");
pw.println();
pw.println("import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory;");
pw.println("import org.apache.qpid.server.model.ConfiguredObject;");
pw.println("import org.apache.qpid.server.plugin.PluggableService;");
if (annotation.conditionallyAvailable()) {
pw.println("import org.apache.qpid.server.plugin.ConditionallyAvailable;");
}
pw.println();
pw.println("@PluggableService");
pw.println("public final class " + factorySimpleName + " extends AbstractConfiguredObjectTypeFactory<" + objectSimpleName + ">");
if (annotation.conditionallyAvailable()) {
pw.println(" implements ConditionallyAvailable");
}
pw.println("{");
pw.println(" public " + factorySimpleName + "()");
pw.println(" {");
pw.println(" super(" + objectSimpleName + ".class);");
pw.println(" }");
pw.println();
pw.println(" @Override");
pw.println(" protected " + objectSimpleName + " createInstance(final Map<String, Object> attributes, final ConfiguredObject<?> parent)");
pw.println(" {");
pw.print(" return new " + objectSimpleName + "WithAccessChecking(attributes");
boolean first = true;
for (VariableElement param : constructorElement.getParameters()) {
if (first) {
first = false;
} else {
TypeMirror erasureType = processingEnv.getTypeUtils().erasure(param.asType());
pw.print(String.format(", (%s)parent", erasureType.toString()));
}
}
pw.println(");");
pw.println(" }");
if (annotation.conditionallyAvailable()) {
final String condition = annotation.condition();
pw.println();
pw.println(" @Override");
pw.println(" public boolean isAvailable()");
pw.println(" {");
if ("".equals(condition)) {
pw.println(" return " + objectSimpleName + ".isAvailable();");
} else {
if (condition.matches("([\\w][\\w\\d_]+\\.)+[\\w][\\w\\d_\\$]*#[\\w\\d_]+\\s*\\(\\s*\\)")) {
pw.println(" return " + condition.replace('#', '.') + ";");
} else {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("Invalid condition expression for '%s' : %s", objectQualifiedClassName, condition));
}
}
pw.println(" }");
}
pw.println("}");
pw.close();
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to write factory file: " + factoryName + " - " + e.getLocalizedMessage());
}
return factoryName;
}
Aggregations