use of com.sun.source.tree.ParameterizedTypeTree in project checker-framework by typetools.
the class TypeFromTypeTreeVisitor method visitParameterizedType.
@Override
public AnnotatedTypeMirror visitParameterizedType(ParameterizedTypeTree node, AnnotatedTypeFactory f) {
ClassSymbol baseType = (ClassSymbol) TreeUtils.elementFromTree(node.getType());
updateWildcardBounds(node.getTypeArguments(), baseType.getTypeParameters());
List<AnnotatedTypeMirror> args = CollectionsPlume.mapList((Tree t) -> visit(t, f), node.getTypeArguments());
// use creator?
AnnotatedTypeMirror result = f.type(node);
AnnotatedTypeMirror atype = visit(node.getType(), f);
result.addAnnotations(atype.getAnnotations());
// diamond which should be inferred.
if (result instanceof AnnotatedDeclaredType && !args.isEmpty()) {
assert result instanceof AnnotatedDeclaredType : node + " --> " + result;
((AnnotatedDeclaredType) result).setTypeArguments(args);
}
return result;
}
use of com.sun.source.tree.ParameterizedTypeTree in project error-prone by google.
the class JdkObsolete method linkedListFix.
// rewrite e.g. `List<Object> xs = new LinkedList<>()` -> `... = new ArrayList<>()`
private static Optional<Fix> linkedListFix(Tree tree, VisitorState state) {
Type type = getTargetType(state);
if (type == null) {
return Optional.empty();
}
Types types = state.getTypes();
for (String replacement : ImmutableList.of("java.util.ArrayList", "java.util.ArrayDeque")) {
Symbol sym = state.getSymbolFromString(replacement);
if (sym == null) {
continue;
}
if (types.isAssignable(types.erasure(sym.asType()), types.erasure(type))) {
SuggestedFix.Builder fix = SuggestedFix.builder();
while (tree instanceof ParameterizedTypeTree) {
tree = ((ParameterizedTypeTree) tree).getType();
}
fix.replace(tree, SuggestedFixes.qualifyType(state, fix, sym));
return Optional.of(fix.build());
}
}
return Optional.empty();
}
Aggregations