Java源码示例:com.sun.tools.javac.tree.JCTree.JCTypeApply
示例1
@Override
public Pair<ASTRecord, Integer> visitVariable(VariableTree node, Insertion ins) {
Name name = node.getName();
JCVariableDecl jn = (JCVariableDecl) node;
JCTree jt = jn.getType();
Criteria criteria = ins.getCriteria();
dbug.debug("TypePositionFinder.visitVariable: %s %s%n", jt, jt.getClass());
if (name != null && criteria.isOnFieldDeclaration()) {
return Pair.of(astRecord(node), jn.getStartPosition());
}
if (jt instanceof JCTypeApply) {
JCExpression type = ((JCTypeApply) jt).clazz;
return pathAndPos(type);
}
return Pair.of(astRecord(node), jn.pos);
}
示例2
@Override
public Pair<ASTRecord, Integer> visitNewClass(NewClassTree node, Insertion ins) {
JCNewClass na = (JCNewClass) node;
JCExpression className = na.clazz;
// System.out.printf("classname %s (%s)%n", className, className.getClass());
while (! (className.getKind() == Tree.Kind.IDENTIFIER)) { // IdentifierTree
if (className instanceof JCAnnotatedType) {
className = ((JCAnnotatedType) className).underlyingType;
} else if (className instanceof JCTypeApply) {
className = ((JCTypeApply) className).clazz;
} else if (className instanceof JCFieldAccess) {
// This occurs for fully qualified names, e.g. "new java.lang.Object()".
// I'm not quite sure why the field "selected" is taken, but "name" would
// be a type mismatch. It seems to work, see NewPackage test case.
className = ((JCFieldAccess) className).selected;
} else {
throw new Error(String.format("unrecognized JCNewClass.clazz (%s): %s%n" +
" surrounding new class tree: %s%n", className.getClass(), className, node));
}
// System.out.printf("classname %s (%s)%n", className, className.getClass());
}
return visitIdentifier((IdentifierTree) className, ins);
}
示例3
@Override
public void visitTypeApply(JCTypeApply tree) {
if (tree.type.hasTag(CLASS)) {
List<JCExpression> args = tree.arguments;
List<Type> forms = tree.type.tsym.type.getTypeArguments();
Type incompatibleArg = firstIncompatibleTypeArg(tree.type);
if (incompatibleArg != null) {
for (JCTree arg : tree.arguments) {
if (arg.type == incompatibleArg) {
log.error(arg, Errors.NotWithinBounds(incompatibleArg, forms.head));
}
forms = forms.tail;
}
}
forms = tree.type.tsym.type.getTypeArguments();
boolean is_java_lang_Class = tree.type.tsym.flatName() == names.java_lang_Class;
// For matching pairs of actual argument types `a' and
// formal type parameters with declared bound `b' ...
while (args.nonEmpty() && forms.nonEmpty()) {
validateTree(args.head,
!(isOuter && is_java_lang_Class),
false);
args = args.tail;
forms = forms.tail;
}
// Check that this type is either fully parameterized, or
// not parameterized at all.
if (tree.type.getEnclosingType().isRaw())
log.error(tree.pos(), Errors.ImproperlyFormedTypeInnerRawParam);
if (tree.clazz.hasTag(SELECT))
visitSelectInternal((JCFieldAccess)tree.clazz);
}
}
示例4
@Override
List<JCNewClass> rewrite(JCNewClass oldTree) {
if (oldTree.clazz.hasTag(TYPEAPPLY)) {
JCNewClass nc = copier.copy(oldTree);
((JCTypeApply)nc.clazz).arguments = List.nil();
return List.of(nc);
} else {
return List.of(oldTree);
}
}
示例5
@Override
protected JCExpression clearTypeParams(JCExpression superType) {
switch (superType.getTag()) {
case TYPEAPPLY:
return ((JCTypeApply) superType).clazz;
}
return superType;
}
示例6
@Override
JCNewClass map(JCNewClass oldTree, JCNewClass newTree) {
if (newTree.clazz.hasTag(TYPEAPPLY)) {
((JCTypeApply)newTree.clazz).arguments = List.nil();
}
return newTree;
}
示例7
public void visitTypeApply(JCTypeApply tree) {
try {
printExpr(tree.clazz);
print("<");
printExprs(tree.arguments);
print(">");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例8
@Override
public Pair<ASTRecord, Integer> visitParameterizedType(ParameterizedTypeTree node, Insertion ins) {
Tree parent = parent(node);
dbug.debug("TypePositionFinder.visitParameterizedType %s parent=%s%n",
node, parent);
Integer pos = getBaseTypePosition(((JCTypeApply) node).getType()).b;
return Pair.of(astRecord(node), pos);
}
示例9
public void visitTypeApply(JCTypeApply tree) {
SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
sr.mergeWith(csp(tree.clazz));
sr.mergeWith(csp(tree.arguments));
result = sr;
}
示例10
/** Visitor method for parameterized types.
*/
public void visitTypeApply(JCTypeApply tree) {
JCTree clazz = translate(tree.clazz, null);
result = clazz;
}
示例11
@Override
public void visitTypeApply(JCTypeApply tree) {
scan(tree.clazz);
}
示例12
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) {
return invoke(TypeApply, clazz, arguments);
}
示例13
private static JCExpression cloneType0(JavacTreeMaker maker, JCTree in) {
if (in == null) return null;
if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
if (in instanceof JCIdent) {
return maker.Ident(((JCIdent) in).name);
}
if (in instanceof JCFieldAccess) {
JCFieldAccess fa = (JCFieldAccess) in;
return maker.Select(cloneType0(maker, fa.selected), fa.name);
}
if (in instanceof JCArrayTypeTree) {
JCArrayTypeTree att = (JCArrayTypeTree) in;
return maker.TypeArray(cloneType0(maker, att.elemtype));
}
if (in instanceof JCTypeApply) {
JCTypeApply ta = (JCTypeApply) in;
ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>();
for (JCExpression typeArg : ta.arguments) {
lb.append(cloneType0(maker, typeArg));
}
return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
}
if (in instanceof JCWildcard) {
JCWildcard w = (JCWildcard) in;
JCExpression newInner = cloneType0(maker, w.inner);
TypeBoundKind newKind;
switch (w.getKind()) {
case SUPER_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.SUPER);
break;
case EXTENDS_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
break;
default:
case UNBOUNDED_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
break;
}
return maker.Wildcard(newKind, newInner);
}
// This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
return (JCExpression) in;
}
示例14
@Override
public JCTypeApply inline(Inliner inliner) throws CouldNotResolveImportException {
return inliner.maker().TypeApply(
getType().inline(inliner),
inliner.<JCExpression, UExpression>inlineList(getTypeArguments()));
}