com.sun.tools.javac.code.Type.WildcardType Java Examples
The following examples show how to use
com.sun.tools.javac.code.Type.WildcardType.
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: VarTypePrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected Type makeWildcard(Type upper, Type lower) { BoundKind bk; Type bound; if (upper.hasTag(BOT)) { upper = syms.objectType; } boolean isUpperObject = types.isSameType(upper, syms.objectType); if (!lower.hasTag(BOT) && isUpperObject) { bound = lower; bk = SUPER; } else { bound = upper; bk = isUpperObject ? UNBOUND : EXTENDS; } return new WildcardType(bound, bk, syms.boundClass); }
Example #2
Source File: Printer.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public String visitWildcardType(WildcardType t, Locale locale) { StringBuffer s = new StringBuffer(); s.append(t.kind); if (t.kind != UNBOUND) { s.append(visit(t.type, locale)); } return s.toString(); }
Example #3
Source File: TreeFactory.java From netbeans with Apache License 2.0 | 5 votes |
public ExpressionTree Type(TypeMirror type) { Type t = (Type) type; JCExpression tp; switch (type.getKind()) { case WILDCARD: { WildcardType a = ((WildcardType) type); tp = make.at(NOPOS).Wildcard(make.at(NOPOS).TypeBoundKind(a.kind), (JCExpression) Type(a.type)); break; } case ERROR: if (t.hasTag(TypeTag.ERROR)) { tp = make.at(NOPOS).Ident(((ErrorType) type).tsym.name); break; } case DECLARED: JCExpression clazz = (JCExpression) QualIdent(t.tsym); tp = t.getTypeArguments().isEmpty() ? clazz : make.at(NOPOS).TypeApply(clazz, Types(t.getTypeArguments())); break; case ARRAY: tp = make.at(NOPOS).TypeArray((JCExpression) Type(((ArrayType) type).getComponentType())); break; case NULL: tp = make.at(NOPOS).Literal(TypeTag.BOT, null); break; default: return make.at(NOPOS).Type((Type)type); } return tp.setType(t); }
Example #4
Source File: Printer.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public String visitWildcardType(WildcardType t, Locale locale) { StringBuffer s = new StringBuffer(); s.append(t.kind); if (t.kind != UNBOUND) { s.append(visit(t.type, locale)); } return s.toString(); }
Example #5
Source File: VarTypePrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Type visitWildcardType(WildcardType wt, Boolean upward) { if (upward) { return wt.isExtendsBound() ? wt.type.map(this, upward) : syms.objectType; } else { return wt.isSuperBound() ? wt.type.map(this, upward) : syms.botType; } }
Example #6
Source File: Inliner.java From Refaster with Apache License 2.0 | 5 votes |
@Override public JCExpression visitWildcardType(WildcardType type, Inliner inliner) { TreeMaker maker = inliner.maker(); return maker.Wildcard( maker.TypeBoundKind(type.kind), visit(type.baseType(), inliner)); }
Example #7
Source File: UWildcardType.java From Refaster with Apache License 2.0 | 5 votes |
@Override public Type inline(Inliner inliner) throws CouldNotResolveImportException { return new WildcardType( bound().inline(inliner), boundKind(), inliner.symtab().boundClass); }
Example #8
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Type javaTypeToType(java.lang.reflect.Type type){ if(type instanceof Class) return classToType((Class) type); else if(type instanceof java.lang.reflect.WildcardType){ java.lang.reflect.Type[] lowerBounds=((java.lang.reflect.WildcardType) type).getLowerBounds(); java.lang.reflect.Type[] upperBounds=((java.lang.reflect.WildcardType) type).getUpperBounds(); if(lowerBounds.length>0){ if(upperBounds.length>1||lowerBounds.length!=1) {//always have object as its upper bound throw badClassFile("bad.class.file",type.toString()); } return new WildcardType(javaTypeToType(lowerBounds[0]),BoundKind.SUPER,syms.boundClass); }else if(upperBounds.length>0){ if(upperBounds.length!=1) { throw badClassFile("bad.class.file",type.toString()); } return new WildcardType(javaTypeToType(upperBounds[0]),BoundKind.EXTENDS,syms.boundClass); } return new WildcardType(syms.objectType,BoundKind.UNBOUND,syms.boundClass); }else if(type instanceof ParameterizedType){ java.lang.reflect.Type[] args=((ParameterizedType) type).getActualTypeArguments(); List<Type> params=StreamSupport.stream(Arrays.asList(args)).map(this::javaTypeToType).collect(List.collector()); ClassSymbol symbol=syms.enterClass(currentModule,names.fromString(((Class)((ParameterizedType) type).getRawType()).getName())); return new ClassType(Type.noType,params,symbol){ boolean completed; @Override public Type getEnclosingType() { if(!completed){ completed=true; tsym.complete(); super.setEnclosingType(tsym.type.getEnclosingType()); } return super.getEnclosingType(); } @Override public void setEnclosingType(Type outer) { throw new UnsupportedOperationException(); } }; }else if(type instanceof GenericArrayType){ return types.makeArrayType(javaTypeToType(((GenericArrayType) type).getGenericComponentType())); }else if(type instanceof TypeVariable) return findTypeVar(names.fromString(type.toString())); return null; }
Example #9
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Boolean visitWildcardType(WildcardType t, Void s) { return visit(t.type, s); }
Example #10
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Boolean visitWildcardType(WildcardType t, Void s) { return visit(t.type); }
Example #11
Source File: InferenceContext.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Void visitWildcardType(WildcardType t, Void _unused) { return visit(t.type); }
Example #12
Source File: InferenceContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Void visitWildcardType(WildcardType t, Void _unused) { return visit(t.type); }
Example #13
Source File: VarTypePrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Void visitWildcardType(WildcardType t, Set<Type> seen) { visit(t.type, seen); return null; }
Example #14
Source File: JavacResolution.java From EasyMPermission with MIT License | 4 votes |
private static JCExpression typeToJCTree0(Type type, JavacAST ast, boolean allowCompound, boolean allowVoid) throws TypeNotConvertibleException { // NB: There's such a thing as maker.Type(type), but this doesn't work very well; it screws up anonymous classes, captures, and adds an extra prefix dot for some reason too. // -- so we write our own take on that here. JavacTreeMaker maker = ast.getTreeMaker(); if (CTC_BOT.equals(typeTag(type))) return createJavaLangObject(ast); if (CTC_VOID.equals(typeTag(type))) return allowVoid ? primitiveToJCTree(type.getKind(), maker) : createJavaLangObject(ast); if (type.isPrimitive()) return primitiveToJCTree(type.getKind(), maker); if (type.isErroneous()) throw new TypeNotConvertibleException("Type cannot be resolved"); TypeSymbol symbol = type.asElement(); List<Type> generics = type.getTypeArguments(); JCExpression replacement = null; if (symbol == null) throw new TypeNotConvertibleException("Null or compound type"); if (symbol.name.length() == 0) { // Anonymous inner class if (type instanceof ClassType) { List<Type> ifaces = ((ClassType) type).interfaces_field; Type supertype = ((ClassType) type).supertype_field; if (ifaces != null && ifaces.length() == 1) { return typeToJCTree(ifaces.get(0), ast, allowCompound, allowVoid); } if (supertype != null) return typeToJCTree(supertype, ast, allowCompound, allowVoid); } throw new TypeNotConvertibleException("Anonymous inner class"); } if (type instanceof CapturedType || type instanceof WildcardType) { Type lower, upper; if (type instanceof WildcardType) { upper = ((WildcardType)type).getExtendsBound(); lower = ((WildcardType)type).getSuperBound(); } else { lower = type.getLowerBound(); upper = type.getUpperBound(); } if (allowCompound) { if (lower == null || CTC_BOT.equals(typeTag(lower))) { if (upper == null || upper.toString().equals("java.lang.Object")) { return maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); } if (upper.getTypeArguments().contains(type)) { return maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); } return maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), typeToJCTree(upper, ast, false, false)); } else { return maker.Wildcard(maker.TypeBoundKind(BoundKind.SUPER), typeToJCTree(lower, ast, false, false)); } } if (upper != null) { if (upper.getTypeArguments().contains(type)) { return maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); } return typeToJCTree(upper, ast, allowCompound, allowVoid); } return createJavaLangObject(ast); } String qName; if (symbol.isLocal()) { qName = symbol.getSimpleName().toString(); } else if (symbol.type != null && symbol.type.getEnclosingType() != null && typeTag(symbol.type.getEnclosingType()).equals(typeTag("CLASS"))) { replacement = typeToJCTree0(type.getEnclosingType(), ast, false, false); qName = symbol.getSimpleName().toString(); } else { qName = symbol.getQualifiedName().toString(); } if (qName.isEmpty()) throw new TypeNotConvertibleException("unknown type"); if (qName.startsWith("<")) throw new TypeNotConvertibleException(qName); String[] baseNames = qName.split("\\."); int i = 0; if (replacement == null) { replacement = maker.Ident(ast.toName(baseNames[0])); i = 1; } for (; i < baseNames.length; i++) { replacement = maker.Select(replacement, ast.toName(baseNames[i])); } return genericsToJCTreeNodes(generics, ast, replacement); }
Example #15
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UWildcardType visitWildcardType(WildcardType type, Void v) { return UWildcardType.create(type.kind, type.type.accept(this, null)); }
Example #16
Source File: UWildcardType.java From Refaster with Apache License 2.0 | 4 votes |
@Override @Nullable public Unifier visitWildcardType(WildcardType wildcard, @Nullable Unifier unifier) { unifier = boundKind().equals(wildcard.kind) ? unifier : null; return bound().unify(wildcard.type, unifier); }