Search in sources :

Example 1 with Compound

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();
}
Also used : ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) TypeElement(javax.lang.model.element.TypeElement) Compound(com.sun.tools.javac.code.Attribute.Compound) Annotation(java.lang.annotation.Annotation) Name(javax.lang.model.element.Name)

Example 2 with Compound

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);
        }
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) ClassType(com.sun.tools.javac.code.Type.ClassType) Type(com.sun.tools.javac.code.Type) ExecutableType(javax.lang.model.type.ExecutableType) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) ExecutableElement(javax.lang.model.element.ExecutableElement) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Compound(com.sun.tools.javac.code.Attribute.Compound) ClassType(com.sun.tools.javac.code.Type.ClassType) TypeNotConvertibleException(lombok.javac.JavacResolution.TypeNotConvertibleException)

Example 3 with Compound

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);
}
Also used : Attribute(com.sun.tools.javac.code.Attribute) ArrayList(java.util.ArrayList) Compound(com.sun.tools.javac.code.Attribute.Compound)

Aggregations

Compound (com.sun.tools.javac.code.Attribute.Compound)3 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)1 Attribute (com.sun.tools.javac.code.Attribute)1 Symbol (com.sun.tools.javac.code.Symbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 Type (com.sun.tools.javac.code.Type)1 ClassType (com.sun.tools.javac.code.Type.ClassType)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 Name (javax.lang.model.element.Name)1 TypeElement (javax.lang.model.element.TypeElement)1 ExecutableType (javax.lang.model.type.ExecutableType)1 TypeNotConvertibleException (lombok.javac.JavacResolution.TypeNotConvertibleException)1