use of javax.lang.model.type.TypeMirror in project camel by apache.
the class CoreEipAnnotationProcessor method processRefWhenClauses.
/**
* Special for processing an @XmlElementRef when field
*/
private void processRefWhenClauses(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement originalClassType, XmlElementRef elementRef, VariableElement fieldElement, String fieldName, Set<EipOption> eipOptions, String prefix) {
Elements elementUtils = processingEnv.getElementUtils();
if ("whenClauses".equals(fieldName)) {
String kind = "element";
String name = elementRef.name();
if (isNullOrEmpty(name) || "##default".equals(name)) {
name = fieldName;
}
name = prefix + name;
TypeMirror fieldType = fieldElement.asType();
String fieldTypeName = fieldType.toString();
// find javadoc from original class as it will override the setExpression method where we can provide the javadoc for the given EIP
String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, originalClassType, true);
boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
// indicate that this element is one of when
Set<String> oneOfTypes = new HashSet<String>();
oneOfTypes.add("when");
// when is predicate
boolean asPredicate = true;
String displayName = null;
Metadata metadata = fieldElement.getAnnotation(Metadata.class);
if (metadata != null) {
displayName = metadata.displayName();
}
EipOption ep = new EipOption(name, displayName, kind, fieldTypeName, false, "", docComment, deprecated, false, null, true, oneOfTypes, asPredicate);
eipOptions.add(ep);
}
}
use of javax.lang.model.type.TypeMirror in project robolectric by robolectric.
the class RobolectricModel method getImplementedClass.
public TypeMirror getImplementedClass(AnnotationMirror am) {
if (am == null) {
return null;
}
// RobolectricWiringTest prefers className (if provided) to value, so we do the same here.
TypeMirror impType = getImplementedClassName(am);
if (impType != null) {
return impType;
}
AnnotationValue av = getAnnotationValue(am, "value");
if (av == null) {
return null;
}
TypeMirror type = valueVisitor.visit(av);
if (type == null) {
return null;
}
// If the class is Robolectric.Anything, treat as if it wasn't specified at all.
if (ANYTHING_MIRROR != null && types.isSameType(type, ANYTHING_MIRROR)) {
return null;
}
return type;
}
use of javax.lang.model.type.TypeMirror in project robolectric by robolectric.
the class RobolectricModel method appendParameterList.
public void appendParameterList(StringBuilder message, List<? extends TypeParameterElement> tpeList) {
boolean first = true;
for (TypeParameterElement tpe : tpeList) {
if (first) {
first = false;
} else {
message.append(',');
}
message.append(tpe.toString());
boolean iFirst = true;
for (TypeMirror bound : getExplicitBounds(tpe)) {
if (iFirst) {
message.append(" extends ");
iFirst = false;
} else {
message.append(',');
}
message.append(bound);
}
}
}
use of javax.lang.model.type.TypeMirror in project qpid-broker-j by apache.
the class ConfiguredObjectFactoryGenerator method generateAccessCheckedMethods.
private void generateAccessCheckedMethods(final String className, final TypeElement typeElement, final PrintWriter pw, final HashSet<TypeElement> processedClasses, final HashSet<String> processedMethods) throws ClassNotFoundException {
if (processedClasses.add(typeElement)) {
Element superClassElement = processingEnv.getTypeUtils().asElement(typeElement.getSuperclass());
if (superClassElement instanceof TypeElement) {
generateAccessCheckedMethods(className, (TypeElement) superClassElement, pw, processedClasses, processedMethods);
}
for (TypeMirror ifMirror : typeElement.getInterfaces()) {
Element ifElement = processingEnv.getTypeUtils().asElement(ifMirror);
if (ifElement instanceof TypeElement) {
generateAccessCheckedMethods(className, (TypeElement) ifElement, pw, processedClasses, processedMethods);
}
}
for (Element element : typeElement.getEnclosedElements()) {
if (element instanceof ExecutableElement && element.getKind() == ElementKind.METHOD && !processedMethods.contains(element.getSimpleName().toString())) {
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
if (annotationMirror.getAnnotationType().toString().equals("org.apache.qpid.server.model.ManagedOperation")) {
processedMethods.add(element.getSimpleName().toString());
processManagedOperation(pw, className, (ExecutableElement) element, annotationMirror);
break;
} else if (annotationMirror.getAnnotationType().toString().equals("org.apache.qpid.server.model.DoOnConfigThread")) {
processedMethods.add(element.getSimpleName().toString());
processDoOnConfigMethod(pw, className, (ExecutableElement) element, annotationMirror);
break;
}
}
}
}
}
}
use of javax.lang.model.type.TypeMirror 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