use of com.sun.source.tree.WildcardTree in project checker-framework by typetools.
the class TypeFromTypeTreeVisitor method updateWildcardBounds.
/**
* Work around a bug in javac 9 where sometimes the bound field is set to the transitive
* supertype's type parameter instead of the type parameter which the wildcard directly
* instantiates. See https://github.com/eisop/checker-framework/issues/18
*
* <p>Sets each wildcard type argument's bound from typeArgs to the corresponding type parameter
* from typeParams.
*
* <p>If typeArgs.size() == 0 the method does nothing and returns. Otherwise, typeArgs.size() has
* to be equal to typeParams.size().
*
* <p>For each wildcard type argument and corresponding type parameter, sets the
* WildcardType.bound field to the corresponding type parameter, if and only if the owners of the
* existing bound and the type parameter are different.
*
* <p>In scenarios where the bound's owner is the same, we don't want to replace a
* capture-converted bound in the wildcard type with a non-capture-converted bound given by the
* type parameter declaration.
*
* @param typeArgs the type of the arguments at (e.g., at the call side)
* @param typeParams the type of the formal parameters (e.g., at the method declaration)
*/
// workaround for javac bug
@SuppressWarnings("interning:not.interned")
private void updateWildcardBounds(List<? extends Tree> typeArgs, List<TypeVariableSymbol> typeParams) {
if (typeArgs.isEmpty()) {
// Nothing to do for empty type arguments.
return;
}
assert typeArgs.size() == typeParams.size();
Iterator<? extends Tree> typeArgsItr = typeArgs.iterator();
Iterator<TypeVariableSymbol> typeParamsItr = typeParams.iterator();
while (typeArgsItr.hasNext()) {
Tree typeArg = typeArgsItr.next();
TypeVariableSymbol typeParam = typeParamsItr.next();
if (typeArg instanceof WildcardTree) {
TypeVar typeVar = (TypeVar) typeParam.asType();
WildcardType wcType = (WildcardType) ((JCWildcard) typeArg).type;
if (wcType.bound != null && wcType.bound.tsym != null && typeVar.tsym != null && wcType.bound.tsym.owner != typeVar.tsym.owner) {
wcType.withTypeVar(typeVar);
}
}
}
}
Aggregations