private static TypeQualifierAnnotation getDefaultTypeQualifierAnnotation(AnnotatedObject o,
            TypeQualifierValue<?> typeQualifierValue, boolean stopAtClassScope) {

        if (o.isSynthetic())
        {
            return null; // synthetic objects don't get default annotations
        }

        ElementType elementType = o.getElementType();
        while (true) {
            o = o.getContainingScope();
            if (o == null) {
                return null;
            }
            if (stopAtClassScope && o instanceof XClass) {
                return null;
            }
            TypeQualifierAnnotation result;

            // Check direct applications of the type qualifier
            Set<TypeQualifierAnnotation> applications = new HashSet<>();
            getDirectApplications(applications, o, elementType);
            result = findMatchingTypeQualifierAnnotation(applications, typeQualifierValue);
            if (result != null) {
                // Great - found an outer scope with a relevant annotation
                assert false : "I don't think we should be looking here";
            return result;
            }

            // Check default annotations
            result = getDefaultAnnotation(o, typeQualifierValue, elementType);
            if (result != null) {
                return result;
            }
        }
    }
private static TypeQualifierAnnotation getDefaultTypeQualifierAnnotation ( AnnotatedObject o , TypeQualifierValue < ? > typeQualifierValue , boolean stopAtClassScope ) { if ( o . isSynthetic ( ) ) { return null ; } ElementType elementType = o . getElementType ( ) ; while ( true ) { o = o . getContainingScope ( ) ; if ( o == null ) { return null ; } if ( stopAtClassScope && o instanceof XClass ) { return null ; } TypeQualifierAnnotation result ; Set < TypeQualifierAnnotation > applications = new HashSet < > ( ) ; getDirectApplications ( applications , o , elementType ) ; result = findMatchingTypeQualifierAnnotation ( applications , typeQualifierValue ) ; if ( result != null ) { assert false : "I don't think we should be looking here" ; return result ; } result = getDefaultAnnotation ( o , typeQualifierValue , elementType ) ; if ( result != null ) { return result ; } } }
Get the default (outer scope) annotation applicable to given
AnnotatedObject.

@param o
an AnnotatedObject
@param typeQualifierValue
the kind of TypeQualifierValue we are looking for
@return the applicable default TypeQualifierAnnotation, or null if there
is no default TypeQualifierAnnotation