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

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCWildcard. 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: JavacSingularsRecipes.java    From EasyMPermission with MIT License 6 votes vote down vote up
protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) {
	if (typeArgs == null || typeArgs.size() <= index) {
		return genJavaLangTypeRef(builderType, "Object");
	} else {
		JCExpression originalType = typeArgs.get(index);
		if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) {
			return genJavaLangTypeRef(builderType, "Object");
		} else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) {
			try {
				return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext());
			} catch (Exception e) {
				return genJavaLangTypeRef(builderType, "Object");
			}
		} else {
			return cloneType(maker, originalType, source, builderType.getContext());
		}
	}
}
 
Example #2
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void printBaseElementType(JCArrayTypeTree tree) throws IOException {
	JCTree elem = tree.elemtype;
	while (elem instanceof JCWildcard)
		elem = ((JCWildcard) elem).inner;
	if (elem instanceof JCArrayTypeTree)
		printBaseElementType((JCArrayTypeTree) elem);
	else
		printExpr(elem);
}
 
Example #3
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitWildcard(JCWildcard tree) {
    result = null;
}
 
Example #4
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 visitWildcard(JCWildcard tree) {
    if (tree.inner != null)
        validateTree(tree.inner, true, isOuter);
}
 
Example #5
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCWildcard Wildcard(TypeBoundKind kind, JCTree type) {
	return invoke(Wildcard, kind, type);
}
 
Example #6
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 #7
Source File: TreeFinder.java    From annotation-tools with MIT License 4 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitWildcard(WildcardTree node, Insertion ins) {
  JCWildcard wc = (JCWildcard) node;
  return Pair.of(astRecord(node), wc.getStartPosition());
}