Search in sources :

Example 6 with TypeCompound

use of com.sun.tools.javac.code.Attribute.TypeCompound in project checker-framework by typetools.

the class TypeParamElementAnnotationApplier method handleTargeted.

/**
 * @param targeted the list of annotations that were on the lower/upper bounds of the type
 *     parameter
 *     <p>Note: When handling type parameters we NEVER add primary annotations to the type
 *     parameter. Primary annotations are reserved for the use of a type parameter (e.g. @Nullable
 *     T t; )
 *     <p>If an annotation is present on the type parameter itself, it represents the lower-bound
 *     annotation of that type parameter. Any annotation on the extends bound of a type parameter
 *     is placed on that bound.
 */
@Override
protected void handleTargeted(final List<TypeCompound> targeted) throws UnexpectedAnnotationLocationException {
    final int paramIndex = getElementIndex();
    final List<TypeCompound> upperBoundAnnos = new ArrayList<>();
    final List<TypeCompound> lowerBoundAnnos = new ArrayList<>();
    for (final TypeCompound anno : targeted) {
        final AnnotationMirror aliasedAnno = typeFactory.canonicalAnnotation(anno);
        final AnnotationMirror canonicalAnno = (aliasedAnno != null) ? aliasedAnno : anno;
        if (anno.position.parameter_index != paramIndex || !typeFactory.isSupportedQualifier(canonicalAnno)) {
            continue;
        }
        if (ElementAnnotationUtil.isOnComponentType(anno)) {
            applyComponentAnnotation(anno);
        } else if (anno.position.type == upperBoundTarget()) {
            upperBoundAnnos.add(anno);
        } else {
            lowerBoundAnnos.add(anno);
        }
    }
    applyLowerBounds(lowerBoundAnnos);
    applyUpperBounds(upperBoundAnnos);
}
Also used : TypeCompound(com.sun.tools.javac.code.Attribute.TypeCompound) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList)

Aggregations

TypeCompound (com.sun.tools.javac.code.Attribute.TypeCompound)6 ArrayList (java.util.ArrayList)4 Attribute (com.sun.tools.javac.code.Attribute)3 List (java.util.List)3 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)2 BugInCF (org.checkerframework.javacutil.BugInCF)2 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)1 Tree (com.sun.source.tree.Tree)1 VariableTree (com.sun.source.tree.VariableTree)1 TargetType (com.sun.tools.javac.code.TargetType)1 TypeAnnotationPosition (com.sun.tools.javac.code.TypeAnnotationPosition)1 EnumMap (java.util.EnumMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 AnnotatedIntersectionType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedIntersectionType)1