use of com.sun.tools.javac.code.Attribute.Compound in project error-prone by google.
the class UTemplater method annotationMap.
@SuppressWarnings("unchecked")
public static ImmutableClassToInstanceMap<Annotation> annotationMap(Symbol symbol) {
ImmutableClassToInstanceMap.Builder<Annotation> builder = ImmutableClassToInstanceMap.builder();
for (Compound compound : symbol.getAnnotationMirrors()) {
Name qualifiedAnnotationType = ((TypeElement) compound.getAnnotationType().asElement()).getQualifiedName();
try {
Class<? extends Annotation> annotationClazz = Class.forName(qualifiedAnnotationType.toString()).asSubclass(Annotation.class);
builder.put((Class) annotationClazz, AnnotationProxyMaker.generateAnnotation(compound, annotationClazz));
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Unrecognized annotation type", e);
}
}
return builder.build();
}
use of com.sun.tools.javac.code.Attribute.Compound in project lombok by rzwitserloot.
the class HandleDelegate method addMethodBindings.
public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
TypeSymbol tsym = ct.asElement();
if (tsym == null)
return;
for (Symbol member : tsym.getEnclosedElements()) {
for (Compound am : member.getAnnotationMirrors()) {
String name = null;
try {
name = am.type.tsym.flatName().toString();
} catch (Exception ignore) {
}
if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
}
}
if (member.getKind() != ElementKind.METHOD)
continue;
if (member.isStatic())
continue;
if (member.isConstructor())
continue;
ExecutableElement exElem = (ExecutableElement) member;
if (!exElem.getModifiers().contains(Modifier.PUBLIC))
continue;
ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
String sig = printSig(methodType, member.name, types);
//If add returns false, it was already in there
if (!banList.add(sig))
continue;
boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
}
if (ct.supertype_field instanceof ClassType)
addMethodBindings(signatures, (ClassType) ct.supertype_field, types, banList);
if (ct.interfaces_field != null)
for (Type iface : ct.interfaces_field) {
if (iface instanceof ClassType)
addMethodBindings(signatures, (ClassType) iface, types, banList);
}
}
use of com.sun.tools.javac.code.Attribute.Compound in project ceylon-compiler by ceylon.
the class JavacAnnotation method attributeToRefl.
private Object attributeToRefl(Attribute attr) {
if (attr == null)
return null;
if (attr instanceof Attribute.Constant)
return attr.getValue();
if (attr instanceof Attribute.Array) {
Attribute[] values = ((Attribute.Array) attr).values;
List<Object> list = new ArrayList<Object>(values.length);
for (Attribute elem : values) {
list.add(attributeToRefl(elem));
}
return list;
}
if (attr instanceof Attribute.Compound)
return new JavacAnnotation((Compound) attr);
if (attr instanceof Attribute.Enum)
return ((Attribute.Enum) attr).getValue().name.toString();
if (attr instanceof Attribute.Class)
return new JavacType(((Attribute.Class) attr).getValue());
// FIXME: turn into error
throw new RuntimeException("Unknown attribute type: " + attr);
}
Aggregations