public AnnotationType annotationType(Attribute.Compound a, Symbol s) {
        Attribute.Compound atTarget =
            a.type.tsym.attribute(syms.annotationTargetType.tsym);
        if (atTarget == null) {
            return inferTargetMetaInfo(a, s);
        }
        Attribute atValue = atTarget.member(names.value);
        if (!(atValue instanceof Attribute.Array)) {
            Assert.error("annotationType(): bad @Target argument " + atValue +
                    " (" + atValue.getClass() + ")");
            return AnnotationType.DECLARATION; // error recovery
        }
        Attribute.Array arr = (Attribute.Array) atValue;
        boolean isDecl = false, isType = false;
        for (Attribute app : arr.values) {
            if (!(app instanceof Attribute.Enum)) {
                Assert.error("annotationType(): unrecognized Attribute kind " + app +
                        " (" + app.getClass() + ")");
                isDecl = true;
                continue;
            }
            Attribute.Enum e = (Attribute.Enum) app;
            if (e.value.name == names.TYPE) {
                if (s.kind == Kinds.TYP)
                    isDecl = true;
            } else if (e.value.name == names.FIELD) {
                if (s.kind == Kinds.VAR &&
                        s.owner.kind != Kinds.MTH)
                    isDecl = true;
            } else if (e.value.name == names.METHOD) {
                if (s.kind == Kinds.MTH &&
                        !s.isConstructor())
                    isDecl = true;
            } else if (e.value.name == names.PARAMETER) {
                if (s.kind == Kinds.VAR &&
                        s.owner.kind == Kinds.MTH &&
                        (s.flags() & Flags.PARAMETER) != 0)
                    isDecl = true;
            } else if (e.value.name == names.CONSTRUCTOR) {
                if (s.kind == Kinds.MTH &&
                        s.isConstructor())
                    isDecl = true;
            } else if (e.value.name == names.LOCAL_VARIABLE) {
                if (s.kind == Kinds.VAR &&
                        s.owner.kind == Kinds.MTH &&
                        (s.flags() & Flags.PARAMETER) == 0)
                    isDecl = true;
            } else if (e.value.name == names.ANNOTATION_TYPE) {
                if (s.kind == Kinds.TYP &&
                        (s.flags() & Flags.ANNOTATION) != 0)
                    isDecl = true;
            } else if (e.value.name == names.PACKAGE) {
                if (s.kind == Kinds.PCK)
                    isDecl = true;
            } else if (e.value.name == names.TYPE_USE) {
                if (s.kind == Kinds.TYP ||
                        s.kind == Kinds.VAR ||
                        (s.kind == Kinds.MTH && !s.isConstructor() &&
                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
                        (s.kind == Kinds.MTH && s.isConstructor()))
                    isType = true;
            } else if (e.value.name == names.TYPE_PARAMETER) {
                /* Irrelevant in this case */
                // TYPE_PARAMETER doesn't aid in distinguishing between
                // Type annotations and declaration annotations on an
                // Element
            } else {
                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
                        " (" + e.value.name.getClass() + ")");
                isDecl = true;
            }
        }
        if (isDecl && isType) {
            return AnnotationType.BOTH;
        } else if (isType) {
            return AnnotationType.TYPE;
        } else {
            return AnnotationType.DECLARATION;
        }
    }
public AnnotationType annotationType ( Attribute . Compound a , Symbol s ) { Attribute . Compound atTarget = a . type . tsym . attribute ( syms . annotationTargetType . tsym ) ; if ( atTarget == null ) { return inferTargetMetaInfo ( a , s ) ; } Attribute atValue = atTarget . member ( names . value ) ; if ( ! ( atValue instanceof Attribute . Array ) ) { Assert . error ( "annotationType(): bad @Target argument " + atValue + " (" + atValue . getClass ( ) + ")" ) ; return AnnotationType . DECLARATION ; } Attribute . Array arr = ( Attribute . Array ) atValue ; boolean isDecl = false , isType = false ; for ( Attribute app : arr . values ) { if ( ! ( app instanceof Attribute . Enum ) ) { Assert . error ( "annotationType(): unrecognized Attribute kind " + app + " (" + app . getClass ( ) + ")" ) ; isDecl = true ; continue ; } Attribute . Enum e = ( Attribute . Enum ) app ; if ( e . value . name == names . TYPE ) { if ( s . kind == Kinds . TYP ) isDecl = true ; } else if ( e . value . name == names . FIELD ) { if ( s . kind == Kinds . VAR && s . owner . kind != Kinds . MTH ) isDecl = true ; } else if ( e . value . name == names . METHOD ) { if ( s . kind == Kinds . MTH && ! s . isConstructor ( ) ) isDecl = true ; } else if ( e . value . name == names . PARAMETER ) { if ( s . kind == Kinds . VAR && s . owner . kind == Kinds . MTH && ( s . flags ( ) & Flags . PARAMETER ) != 0 ) isDecl = true ; } else if ( e . value . name == names . CONSTRUCTOR ) { if ( s . kind == Kinds . MTH && s . isConstructor ( ) ) isDecl = true ; } else if ( e . value . name == names . LOCAL_VARIABLE ) { if ( s . kind == Kinds . VAR && s . owner . kind == Kinds . MTH && ( s . flags ( ) & Flags . PARAMETER ) == 0 ) isDecl = true ; } else if ( e . value . name == names . ANNOTATION_TYPE ) { if ( s . kind == Kinds . TYP && ( s . flags ( ) & Flags . ANNOTATION ) != 0 ) isDecl = true ; } else if ( e . value . name == names . PACKAGE ) { if ( s . kind == Kinds . PCK ) isDecl = true ; } else if ( e . value . name == names . TYPE_USE ) { if ( s . kind == Kinds . TYP || s . kind == Kinds . VAR || ( s . kind == Kinds . MTH && ! s . isConstructor ( ) && ! s . type . getReturnType ( ) . hasTag ( TypeTag . VOID ) ) || ( s . kind == Kinds . MTH && s . isConstructor ( ) ) ) isType = true ; } else if ( e . value . name == names . TYPE_PARAMETER ) { } else { Assert . error ( "annotationType(): unrecognized Attribute name " + e . value . name + " (" + e . value . name . getClass ( ) + ")" ) ; isDecl = true ; } } if ( isDecl && isType ) { return AnnotationType . BOTH ; } else if ( isType ) { return AnnotationType . TYPE ; } else { return AnnotationType . DECLARATION ; } }
Determine whether an annotation is a declaration annotation,
a type annotation, or both.