本文整理了Java中com.sun.tools.javac.code.Types.isSubtypeNoCapture()
方法的一些代码示例,展示了Types.isSubtypeNoCapture()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isSubtypeNoCapture()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:isSubtypeNoCapture
暂无
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
//todo: test against origin needed? or replace with substitution?
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
return true;
if (t.inst != null)
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
t.hibounds = t.hibounds.prepend(s);
return true;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
//todo: test against origin needed? or replace with substitution?
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
return true;
if (t.inst != null)
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
t.hibounds = t.hibounds.prepend(s);
return true;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
public Boolean visitType(Type t, Type s) {
switch (t.tag) {
case BYTE: case CHAR:
return (t.tag == s.tag ||
t.tag + 2 <= s.tag && s.tag <= DOUBLE);
case SHORT: case INT: case LONG: case FLOAT: case DOUBLE:
return t.tag <= s.tag && s.tag <= DOUBLE;
case BOOLEAN: case VOID:
return t.tag == s.tag;
case TYPEVAR:
return isSubtypeNoCapture(t.getUpperBound(), s);
case BOT:
return
s.tag == BOT || s.tag == CLASS ||
s.tag == ARRAY || s.tag == TYPEVAR;
case NONE:
return false;
default:
throw new AssertionError("isSubtype " + t.tag);
}
}
代码示例来源:origin: sc.fiji/javac
public Boolean visitType(Type t, Type s) {
switch (t.tag) {
case BYTE: case CHAR:
return (t.tag == s.tag ||
t.tag + 2 <= s.tag && s.tag <= DOUBLE);
case SHORT: case INT: case LONG: case FLOAT: case DOUBLE:
return t.tag <= s.tag && s.tag <= DOUBLE;
case BOOLEAN: case VOID:
return t.tag == s.tag;
case TYPEVAR:
return isSubtypeNoCapture(t.getUpperBound(), s);
case BOT:
return
s.tag == BOT || s.tag == CLASS ||
s.tag == ARRAY || s.tag == TYPEVAR;
case NONE:
return false;
default:
throw new AssertionError("isSubtype " + t.tag);
}
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
void debugContainsType(WildcardType t, Type s) {
System.err.println();
System.err.format(" does %s contain %s?%n", t, s);
System.err.format(" %s U(%s) <: U(%s) %s = %s%n",
upperBound(s), s, t, U(t),
t.isSuperBound()
|| isSubtypeNoCapture(upperBound(s), U(t)));
System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
L(t), t, s, lowerBound(s),
t.isExtendsBound()
|| isSubtypeNoCapture(L(t), lowerBound(s)));
System.err.println();
}
代码示例来源:origin: sc.fiji/javac
void debugContainsType(WildcardType t, Type s) {
System.err.println();
System.err.format(" does %s contain %s?%n", t, s);
System.err.format(" %s U(%s) <: U(%s) %s = %s%n",
upperBound(s), s, t, U(t),
t.isSuperBound()
|| isSubtypeNoCapture(upperBound(s), U(t)));
System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
L(t), t, s, lowerBound(s),
t.isExtendsBound()
|| isSubtypeNoCapture(L(t), lowerBound(s)));
System.err.println();
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitClassType(ClassType t, Type s) {
Type sup = asSuper(t, s.tsym);
if (sup == null) return false;
// If t is an intersection, sup might not be a class type
if (!sup.hasTag(CLASS)) return isSubtypeNoCapture(sup, s);
return sup.tsym == s.tsym
// Check type variable containment
&& (!s.isParameterized() || containsTypeRecursive(s, sup))
&& isSubtypeNoCapture(sup.getEnclosingType(),
s.getEnclosingType());
}
代码示例来源:origin: konsoletyper/teavm-javac
public Type glb(Type t, Type s) {
if (s == null)
return t;
else if (t.isPrimitive() || s.isPrimitive())
return syms.errType;
else if (isSubtypeNoCapture(t, s))
return t;
else if (isSubtypeNoCapture(s, t))
return s;
List<Type> closure = union(closure(t), closure(s));
return glbFlattened(closure, t);
}
//where
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
if (s.tag >= firstPartialTag)
return containedBy(s, t);
else {
// debugContainsType(t, s);
return isSameWildcard(t, s)
|| isCaptureOf(s, t)
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) &&
(t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t))));
}
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
if (s.tag >= firstPartialTag)
return containedBy(s, t);
else {
// debugContainsType(t, s);
return isSameWildcard(t, s)
|| isCaptureOf(s, t)
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) &&
(t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t))));
}
}
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (s.tag == ARRAY) {
if (t.elemtype.tag <= lastBaseTag)
return isSameType(t.elemtype, elemtype(s));
else
return isSubtypeNoCapture(t.elemtype, elemtype(s));
}
if (s.tag == CLASS) {
Name sname = s.tsym.getQualifiedName();
return sname == names.java_lang_Object
|| sname == names.java_lang_Cloneable
|| sname == names.java_io_Serializable;
}
return false;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (s.tag == ARRAY) {
if (t.elemtype.tag <= lastBaseTag)
return isSameType(t.elemtype, elemtype(s));
else
return isSubtypeNoCapture(t.elemtype, elemtype(s));
}
if (s.tag == CLASS) {
Name sname = s.tsym.getQualifiedName();
return sname == names.java_lang_Object
|| sname == names.java_lang_Cloneable
|| sname == names.java_io_Serializable;
}
return false;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
if (s.isPartial())
return containedBy(s, t);
else {
// debugContainsType(t, s);
return isSameWildcard(t, s)
|| isCaptureOf(s, t)
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) &&
(t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t))));
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitClassType(ClassType t, Type s) {
Type sup = asSuper(t, s.tsym);
return sup != null
&& sup.tsym == s.tsym
// You're not allowed to write
// Vector<Object> vec = new Vector<String>();
// But with wildcards you can write
// Vector<? extends Object> vec = new Vector<String>();
// which means that subtype checking must be done
// here instead of same-type checking (via containsType).
&& (!s.isParameterized() || containsTypeRecursive(s, sup))
&& isSubtypeNoCapture(sup.getEnclosingType(),
s.getEnclosingType());
}
代码示例来源:origin: konsoletyper/teavm-javac
private List<Type> pruneInterfaces(Type t) {
ListBuffer<Type> result = new ListBuffer<>();
for (Type t1 : types.interfaces(t)) {
boolean shouldAdd = true;
for (Type t2 : types.interfaces(t)) {
if (t1 != t2 && types.isSubtypeNoCapture(t2, t1)) {
shouldAdd = false;
}
}
if (shouldAdd) {
result.append(t1);
}
}
return result.toList();
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private List<Type> pruneInterfaces(Type t) {
ListBuffer<Type> result = new ListBuffer<>();
for (Type t1 : types.interfaces(t)) {
boolean shouldAdd = true;
for (Type t2 : types.interfaces(t)) {
if (t1 != t2 && types.isSubtypeNoCapture(t2, t1)) {
shouldAdd = false;
}
}
if (shouldAdd) {
result.append(t1);
}
}
return result.toList();
}
代码示例来源: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: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (s.hasTag(ARRAY)) {
if (t.elemtype.isPrimitive())
return isSameType(t.elemtype, elemtype(s));
else
return isSubtypeNoCapture(t.elemtype, elemtype(s));
}
if (s.hasTag(CLASS)) {
Name sname = s.tsym.getQualifiedName();
return sname == names.java_lang_Object
|| sname == names.java_lang_Cloneable
|| sname == names.java_io_Serializable;
}
return false;
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (s.hasTag(ARRAY)) {
if (t.elemtype.isPrimitive())
return isSameType(t.elemtype, elemtype(s));
else
return isSubtypeNoCapture(t.elemtype, elemtype(s));
}
if (s.hasTag(CLASS)) {
Name sname = s.tsym.getQualifiedName();
return sname == names.java_lang_Object
|| sname == names.java_lang_Cloneable
|| sname == names.java_io_Serializable;
}
return false;
}
代码示例来源:origin: sc.fiji/javac
/**
* Return the minimum types of a closure, suitable for computing
* compoundMin or glb.
*/
private List<Type> closureMin(List<Type> cl) {
ListBuffer<Type> classes = lb();
ListBuffer<Type> interfaces = lb();
while (!cl.isEmpty()) {
Type current = cl.head;
if (current.isInterface())
interfaces.append(current);
else
classes.append(current);
ListBuffer<Type> candidates = lb();
for (Type t : cl.tail) {
if (!isSubtypeNoCapture(current, t))
candidates.append(t);
}
cl = candidates.toList();
}
return classes.appendList(interfaces).toList();
}
内容来源于网络,如有侵权,请联系作者删除!