use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType in project checker-framework by typetools.
the class AnnotatedTypes method containsModifierImpl.
/*
* For type variables we might hit the same type again. We keep a list of visited types.
*/
private static boolean containsModifierImpl(AnnotatedTypeMirror type, AnnotationMirror modifier, List<AnnotatedTypeMirror> visited) {
boolean found = type.hasAnnotation(modifier);
boolean vis = visited.contains(type);
visited.add(type);
if (!found && !vis) {
if (type.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType declaredType = (AnnotatedDeclaredType) type;
for (AnnotatedTypeMirror typeMirror : declaredType.getTypeArguments()) {
found |= containsModifierImpl(typeMirror, modifier, visited);
if (found) {
break;
}
}
} else if (type.getKind() == TypeKind.ARRAY) {
AnnotatedArrayType arrayType = (AnnotatedArrayType) type;
found = containsModifierImpl(arrayType.getComponentType(), modifier, visited);
} else if (type.getKind() == TypeKind.TYPEVAR) {
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) type;
if (atv.getUpperBound() != null) {
found = containsModifierImpl(atv.getUpperBound(), modifier, visited);
}
if (!found && atv.getLowerBound() != null) {
found = containsModifierImpl(atv.getLowerBound(), modifier, visited);
}
} else if (type.getKind() == TypeKind.WILDCARD) {
AnnotatedWildcardType awc = (AnnotatedWildcardType) type;
if (awc.getExtendsBound() != null) {
found = containsModifierImpl(awc.getExtendsBound(), modifier, visited);
}
if (!found && awc.getSuperBound() != null) {
found = containsModifierImpl(awc.getSuperBound(), modifier, visited);
}
}
}
return found;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType in project checker-framework by typetools.
the class AtmLubVisitor method lubTypeArgument.
private void lubTypeArgument(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotatedTypeMirror lub) {
// In lub(), asSuper is called on type1 and type2, but asSuper does not recur into type
// arguments, so call asSuper on the type arguments so that they have the same underlying type.
final AnnotatedTypeMirror type1AsLub = AnnotatedTypes.asSuper(atypeFactory, type1, lub);
final AnnotatedTypeMirror type2AsLub = AnnotatedTypes.asSuper(atypeFactory, type2, lub);
// but Gen<@A ? super @B Object> is returned.)
if (lub.getKind() == TypeKind.WILDCARD) {
if (visited(lub)) {
return;
}
AnnotatedWildcardType type1Wildcard = (AnnotatedWildcardType) type1AsLub;
AnnotatedWildcardType type2Wildcard = (AnnotatedWildcardType) type2AsLub;
AnnotatedWildcardType lubWildcard = (AnnotatedWildcardType) lub;
if (type1Wildcard.isUninferredTypeArgument() || type2Wildcard.isUninferredTypeArgument()) {
lubWildcard.setUninferredTypeArgument();
}
lubWildcard(type1Wildcard.getSuperBound(), type1Wildcard.getExtendsBound(), type2Wildcard.getSuperBound(), type2Wildcard.getExtendsBound(), lubWildcard.getSuperBound(), lubWildcard.getExtendsBound());
} else if (lub.getKind() == TypeKind.TYPEVAR && TypesUtils.isCapturedTypeVariable((TypeVariable) lub.getUnderlyingType())) {
if (visited(lub)) {
return;
}
AnnotatedTypeVariable type1typevar = (AnnotatedTypeVariable) type1AsLub;
AnnotatedTypeVariable type2typevar = (AnnotatedTypeVariable) type2AsLub;
AnnotatedTypeVariable lubTypevar = (AnnotatedTypeVariable) lub;
lubWildcard(type1typevar.getLowerBound(), type1typevar.getUpperBound(), type2typevar.getLowerBound(), type2typevar.getUpperBound(), lubTypevar.getLowerBound(), lubTypevar.getUpperBound());
} else {
// Don't add to visit history because that will happen in visitTypevar_Typevar or
// visitWildcard_Wildcard if needed.
visit(type1AsLub, type2AsLub, lub);
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType in project checker-framework by typetools.
the class AtmLubVisitor method visitWildcard_Wildcard.
@Override
public Void visitWildcard_Wildcard(AnnotatedWildcardType type1, AnnotatedWildcardType type2, AnnotatedTypeMirror lub1) {
if (visited(lub1)) {
return null;
}
AnnotatedWildcardType lub = castLub(type1, lub1);
visit(type1.getExtendsBound(), type2.getExtendsBound(), lub.getExtendsBound());
visit(type1.getSuperBound(), type2.getSuperBound(), lub.getSuperBound());
lubPrimaryOnBoundedType(type1, type2, lub);
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType in project checker-framework by typetools.
the class PropagationTypeAnnotator method visitDeclared.
/**
* Sometimes the underlying type parameters of AnnotatedWildcardTypes are not available on the
* wildcards themselves. Instead, record enclosing class to find the type parameter to use as a
* backup in visitWildcards.
*
* @param declaredType type to record
*/
@Override
public Void visitDeclared(AnnotatedDeclaredType declaredType, Void aVoid) {
if (pause) {
return null;
}
if (declaredType.isUnderlyingTypeRaw()) {
// Copy annotations from the declaration to the wildcards.
AnnotatedDeclaredType declaration = (AnnotatedDeclaredType) typeFactory.fromElement(declaredType.getUnderlyingType().asElement());
List<AnnotatedTypeMirror> typeArgs = declaredType.getTypeArguments();
for (int i = 0; i < typeArgs.size(); i++) {
if (typeArgs.get(i).getKind() != TypeKind.WILDCARD || !((AnnotatedWildcardType) typeArgs.get(i)).isUninferredTypeArgument()) {
// Sometimes the framework infers a more precise type argument, so just use it.
continue;
}
AnnotatedTypeVariable typeParam = (AnnotatedTypeVariable) declaration.getTypeArguments().get(i);
AnnotatedWildcardType wct = (AnnotatedWildcardType) typeArgs.get(i);
wct.getExtendsBound().replaceAnnotations(typeParam.getUpperBound().getAnnotations());
wct.getSuperBound().replaceAnnotations(typeParam.getLowerBound().getAnnotations());
wct.replaceAnnotations(typeParam.getAnnotations());
}
}
parents.addFirst(declaredType);
super.visitDeclared(declaredType, aVoid);
parents.removeFirst();
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType in project checker-framework by typetools.
the class PropagationTypeAnnotator method visitWildcard.
/**
* Rather than defaulting the missing bounds of a wildcard, find the bound annotations on the type
* parameter it replaced. Place those annotations on the wildcard.
*
* @param wildcardAtm type to annotate
*/
@Override
public Void visitWildcard(AnnotatedWildcardType wildcardAtm, Void aVoid) {
if (visitedNodes.containsKey(wildcardAtm) || pause) {
return null;
}
visitedNodes.put(wildcardAtm, null);
final WildcardType wildcard = (WildcardType) wildcardAtm.getUnderlyingType();
Element typeParamElement = TypesUtils.wildcardToTypeParam(wildcard);
if (typeParamElement == null && !parents.isEmpty()) {
typeParamElement = getTypeParameterElement(wildcardAtm, parents.peekFirst());
}
if (typeParamElement != null) {
pause = true;
AnnotatedTypeVariable typeParam = (AnnotatedTypeVariable) typeFactory.getAnnotatedType(typeParamElement);
pause = false;
final Set<? extends AnnotationMirror> tops = typeFactory.getQualifierHierarchy().getTopAnnotations();
if (wildcard.isUnbound()) {
propagateExtendsBound(wildcardAtm, typeParam, tops);
propagateSuperBound(wildcardAtm, typeParam, tops);
} else if (wildcard.isExtendsBound()) {
propagateSuperBound(wildcardAtm, typeParam, tops);
} else {
// is super bound
propagateExtendsBound(wildcardAtm, typeParam, tops);
}
}
scan(wildcardAtm.getExtendsBound(), null);
scan(wildcardAtm.getSuperBound(), null);
return null;
}
Aggregations