com.sun.tools.javac.tree.JCTree.JCTypeApply Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCTypeApply. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@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);
}
 
Example #3
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
    }
}
 
Example #5
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected JCExpression clearTypeParams(JCExpression superType) {
    switch (superType.getTag()) {
        case TYPEAPPLY:
            return ((JCTypeApply) superType).clazz;
    }

    return superType;
}
 
Example #6
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
JCNewClass map(JCNewClass oldTree, JCNewClass newTree) {
    if (newTree.clazz.hasTag(TYPEAPPLY)) {
        ((JCTypeApply)newTree.clazz).arguments = List.nil();
    }
    return newTree;
}
 
Example #7
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitTypeApply(JCTypeApply tree) {
	try {
		printExpr(tree.clazz);
		print("<");
		printExprs(tree.arguments);
		print(">");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #8
Source File: TreeFinder.java    From annotation-tools with MIT License 5 votes vote down vote up
@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);
}
 
Example #9
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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;
}
 
Example #10
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Visitor method for parameterized types.
 */
public void visitTypeApply(JCTypeApply tree) {
    JCTree clazz = translate(tree.clazz, null);
    result = clazz;
}
 
Example #11
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTypeApply(JCTypeApply tree) {
    scan(tree.clazz);
}
 
Example #12
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) {
	return invoke(TypeApply, clazz, arguments);
}
 
Example #13
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 4 votes vote down vote up
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;
}
 
Example #14
Source File: UTypeApply.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public JCTypeApply inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeApply(
      getType().inline(inliner),
      inliner.<JCExpression, UExpression>inlineList(getTypeArguments()));
}