本文整理了Java中com.sun.tools.javac.code.Types.wildUpperBound()
方法的一些代码示例,展示了Types.wildUpperBound()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.wildUpperBound()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:wildUpperBound
[英]Get a wildcard's upper bound, returning non-wildcards unchanged.
[中]
代码示例来源:origin: google/error-prone
@Override
public Violation visitWildcardType(WildcardType type, Void s) {
return state.getTypes().wildUpperBound(type).accept(this, null);
}
代码示例来源:origin: google/error-prone
/**
* Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles
* wildcards and capture variables.
*/
public static Type getUpperBound(Type type, Types types) {
if (type.hasTag(TypeTag.WILDCARD)) {
return types.wildUpperBound(type);
}
if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) {
return types.cvarUpperBound(type);
}
if (type.getUpperBound() != null) {
return type.getUpperBound();
}
// concrete type, e.g. java.lang.String, or a case we haven't considered
return type;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Type visitWildcardType(WildcardType t, Boolean recurse) {
return erasure(wildUpperBound(t), recurse);
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
return isCastable(wildUpperBound(t), s, warnStack.head);
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Type visitWildcardType(WildcardType t, Symbol sym) {
return memberType(wildUpperBound(t), sym);
}
代码示例来源:origin: konsoletyper/teavm-javac
public boolean isArray(Type t) {
while (t.hasTag(WILDCARD))
t = wildUpperBound(t);
return t.hasTag(ARRAY);
}
代码示例来源:origin: com.google.errorprone/error_prone_core
@Override
public Violation visitWildcardType(WildcardType type, Void s) {
return state.getTypes().wildUpperBound(type).accept(this, null);
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Void visitWildcardType(WildcardType source, Type target) throws AdaptFailure {
if (source.isExtendsBound())
adaptRecursive(wildUpperBound(source), wildUpperBound(target));
else if (source.isSuperBound())
adaptRecursive(wildLowerBound(source), wildLowerBound(target));
return null;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Type visitWildcardType(WildcardType t, Void ignored) {
Type bound = t.type;
if (t.kind != BoundKind.UNBOUND)
bound = subst(bound);
if (bound == t.type) {
return t;
} else {
if (t.isExtendsBound() && bound.isExtendsBound())
bound = wildUpperBound(bound);
return new WildcardType(bound, t.kind, syms.boundClass, t.bound);
}
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Get a wildcard's upper bound, returning non-wildcards unchanged.
* @param t a type argument, either a wildcard or a type
*/
public Type wildUpperBound(Type t) {
if (t.hasTag(WILDCARD)) {
WildcardType w = (WildcardType) t.unannotatedType();
if (w.isSuperBound())
return w.bound == null ? syms.objectType : w.bound.bound;
else
return wildUpperBound(w.type);
}
else return t.unannotatedType();
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* The element type of an array.
*/
public Type elemtype(Type t) {
switch (t.getTag()) {
case WILDCARD:
return elemtype(wildUpperBound(t));
case ARRAY:
t = t.unannotatedType();
return ((ArrayType)t).elemtype;
case FORALL:
return elemtype(((ForAll)t).qtype);
case ERROR:
return t;
default:
return null;
}
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Void visitTypeVar(TypeVar source, Type target) throws AdaptFailure {
// Check to see if there is
// already a mapping for $source$, in which case
// the old mapping will be merged with the new
Type val = mapping.get(source.tsym);
if (val != null) {
if (val.isSuperBound() && target.isSuperBound()) {
val = isSubtype(wildLowerBound(val), wildLowerBound(target))
? target : val;
} else if (val.isExtendsBound() && target.isExtendsBound()) {
val = isSubtype(wildUpperBound(val), wildUpperBound(target))
? val : target;
} else if (!isSameType(val, target)) {
throw new AdaptFailure();
}
} else {
val = target;
from.append(source);
to.append(target);
}
mapping.put(source.tsym, val);
return null;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
if (s.isPartial())
return containedBy(s, t);
else {
// debugContainsType(t, s);
return isSameWildcard(t, s)
|| t.type == s
|| isCaptureOf(s, t)
|| ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), cvarLowerBound(wildLowerBound(s)))) &&
// TODO: JDK-8039214, cvarUpperBound call here is incorrect
(t.isSuperBound() || isSubtypeNoCapture(cvarUpperBound(wildUpperBound(s)), wildUpperBound(t))));
}
}
代码示例来源:origin: com.google.errorprone/error_prone_check_api
/**
* Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles
* wildcards and capture variables.
*/
public static Type getUpperBound(Type type, Types types) {
if (type.hasTag(TypeTag.WILDCARD)) {
return types.wildUpperBound(type);
}
if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) {
return types.cvarUpperBound(type);
}
if (type.getUpperBound() != null) {
return type.getUpperBound();
}
// concrete type, e.g. java.lang.String, or a case we haven't considered
return type;
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) {
Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext();
if (from.getKind() == TypeKind.TYPEVAR) {
Types types = Types.instance(c);
TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to)));
return info.getTypes().isAssignable(t.getUpperBound(), to)
|| info.getTypes().isAssignable(to, t.getUpperBound());
}
if (from.getKind() == TypeKind.WILDCARD) {
from = Types.instance(c).wildUpperBound((Type)from);
}
return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
if (t.isUnbound())
return false;
if (!s.hasTag(WILDCARD)) {
if (t.isExtendsBound())
return notSoftSubtypeRecursive(s, t.type);
else
return notSoftSubtypeRecursive(t.type, s);
}
if (s.isUnbound())
return false;
if (t.isExtendsBound()) {
if (s.isExtendsBound())
return !isCastableRecursive(t.type, wildUpperBound(s));
else if (s.isSuperBound())
return notSoftSubtypeRecursive(wildLowerBound(s), t.type);
} else if (t.isSuperBound()) {
if (s.isExtendsBound())
return notSoftSubtypeRecursive(t.type, wildUpperBound(s));
}
return false;
}
};
代码示例来源:origin: konsoletyper/teavm-javac
/** Check that a type is within some bounds.
*
* Used in TypeApply to verify that, e.g., X in {@code V<X>} is a valid
* type argument.
* @param a The type that should be bounded by bs.
* @param bound The bound.
*/
private boolean checkExtends(Type a, Type bound) {
if (a.isUnbound()) {
return true;
} else if (!a.hasTag(WILDCARD)) {
a = types.cvarUpperBound(a);
return types.isSubtype(a, bound);
} else if (a.isExtendsBound()) {
return types.isCastable(bound, types.wildUpperBound(a), types.noWarnings);
} else if (a.isSuperBound()) {
return !types.notSoftSubtype(types.wildLowerBound(a), bound);
}
return true;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitClassType(ClassType t, Type s) {
if (t == s)
return true;
if (s.isPartial())
return visit(s, t);
if (s.isSuperBound() && !s.isExtendsBound())
return visit(t, wildUpperBound(s)) && visit(t, wildLowerBound(s));
if (t.isCompound() && s.isCompound()) {
if (!visit(supertype(t), supertype(s)))
return false;
HashSet<UniqueType> set = new HashSet<UniqueType>();
for (Type x : interfaces(t))
set.add(new UniqueType(x.unannotatedType(), Types.this));
for (Type x : interfaces(s)) {
if (!set.remove(new UniqueType(x.unannotatedType(), Types.this)))
return false;
}
return (set.isEmpty());
}
return t.tsym == s.tsym
&& visit(t.getEnclosingType(), s.getEnclosingType())
&& containsTypes(t.getTypeArguments(), s.getTypeArguments());
}
代码示例来源:origin: konsoletyper/teavm-javac
public boolean containedBy(Type t, Type s) {
switch (t.getTag()) {
case UNDETVAR:
if (s.hasTag(WILDCARD)) {
UndetVar undetvar = (UndetVar)t;
WildcardType wt = (WildcardType)s.unannotatedType();
switch(wt.kind) {
case UNBOUND:
break;
case EXTENDS: {
Type bound = wildUpperBound(s);
undetvar.addBound(InferenceBound.UPPER, bound, this);
break;
}
case SUPER: {
Type bound = wildLowerBound(s);
undetvar.addBound(InferenceBound.LOWER, bound, this);
break;
}
}
return true;
} else {
return isSameType(t, s);
}
case ERROR:
return true;
default:
return containsType(s, t);
}
}
代码示例来源:origin: konsoletyper/teavm-javac
public Boolean visitType(Type t, Type s) {
if (t == s)
return true;
if (s.isPartial())
return visit(s, t);
switch (t.getTag()) {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
return t.hasTag(s.getTag());
case TYPEVAR: {
if (s.hasTag(TYPEVAR)) {
//type-substitution does not preserve type-var types
//check that type var symbols and bounds are indeed the same
return sameTypeVars((TypeVar)t.unannotatedType(), (TypeVar)s.unannotatedType());
}
else {
//special case for s == ? super X, where upper(s) = u
//check that u == t, where u has been set by Type.withTypeVar
return s.isSuperBound() &&
!s.isExtendsBound() &&
visit(t, wildUpperBound(s));
}
}
default:
throw new AssertionError("isSameType " + t.getTag());
}
}
内容来源于网络,如有侵权,请联系作者删除!