use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable 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) {
typeParamElement = (parents.isEmpty()) ? null : getTypeParamFromEnclosingClass(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;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable in project checker-framework by typetools.
the class AnnotatedTypeComparer method visitTypeVariable.
@Override
public R visitTypeVariable(AnnotatedTypeVariable type, AnnotatedTypeMirror p) {
R r;
if (visitedNodes.containsKey(type)) {
return visitedNodes.get(type);
}
visitedNodes.put(type, null);
if (p instanceof AnnotatedTypeVariable) {
AnnotatedTypeVariable tv = (AnnotatedTypeVariable) p;
r = scan(type.getLowerBound(), tv.getLowerBound());
visitedNodes.put(type, r);
r = scanAndReduce(type.getUpperBound(), tv.getUpperBound(), r);
visitedNodes.put(type, r);
} else {
r = scan(type.getLowerBound(), p.getErased());
visitedNodes.put(type, r);
r = scanAndReduce(type.getUpperBound(), p.getErased(), r);
visitedNodes.put(type, r);
}
return r;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable 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.AnnotatedTypeVariable in project checker-framework by typetools.
the class AtmLubVisitor method visitTypevar_Typevar.
@Override
public Void visitTypevar_Typevar(AnnotatedTypeVariable type1, AnnotatedTypeVariable type2, AnnotatedTypeMirror lub1) {
if (visited(lub1)) {
return null;
}
AnnotatedTypeVariable lub = castLub(type1, lub1);
visit(type1.getUpperBound(), type2.getUpperBound(), lub.getUpperBound());
visit(type1.getLowerBound(), type2.getLowerBound(), lub.getLowerBound());
lubPrimaryOnBoundedType(type1, type2, lub);
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable 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.isCaptured((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);
}
}
Aggregations