本文整理了Java中com.sun.tools.javac.code.Types.covariantReturnType()
方法的一些代码示例,展示了Types.covariantReturnType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.covariantReturnType()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:covariantReturnType
[英]Is t an appropriate return type in an overrider for a method that returns s?
[中]对于返回s的方法,t在重写器中是否是合适的返回类型?
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* Return-Type-Substitutable.
* @jls section 8.4.5
*/
public boolean returnTypeSubstitutable(Type r1, Type r2) {
if (hasSameArgs(r1, r2))
return resultSubtype(r1, r2, noWarnings);
else
return covariantReturnType(r1.getReturnType(),
erasure(r2.getReturnType()),
noWarnings);
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Return-Type-Substitutable.
* @see <a href="http://java.sun.com/docs/books/jls/">The Java
* Language Specification, Third Ed. (8.4.5)</a>
*/
public boolean returnTypeSubstitutable(Type r1, Type r2) {
if (hasSameArgs(r1, r2))
return resultSubtype(r1, r2, Warner.noWarnings);
else
return covariantReturnType(r1.getReturnType(),
erasure(r2.getReturnType()),
Warner.noWarnings);
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Return-Type-Substitutable.
* @jls section 8.4.5
*/
public boolean returnTypeSubstitutable(Type r1, Type r2) {
if (hasSameArgs(r1, r2))
return resultSubtype(r1, r2, noWarnings);
else
return covariantReturnType(r1.getReturnType(),
erasure(r2.getReturnType()),
noWarnings);
}
代码示例来源:origin: sc.fiji/javac
/**
* Return-Type-Substitutable.
* @see <a href="http://java.sun.com/docs/books/jls/">The Java
* Language Specification, Third Ed. (8.4.5)</a>
*/
public boolean returnTypeSubstitutable(Type r1, Type r2) {
if (hasSameArgs(r1, r2))
return resultSubtype(r1, r2, Warner.noWarnings);
else
return covariantReturnType(r1.getReturnType(),
erasure(r2.getReturnType()),
Warner.noWarnings);
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* Does t have a result that is a subtype of the result type of s,
* suitable for covariant returns? It is assumed that both types
* are (possibly polymorphic) method types. Monomorphic method
* types are handled in the obvious way. Polymorphic method types
* require renaming all type variables of one to corresponding
* type variables in the other, where correspondence is by
* position in the type parameter list. */
public boolean resultSubtype(Type t, Type s, Warner warner) {
List<Type> tvars = t.getTypeArguments();
List<Type> svars = s.getTypeArguments();
Type tres = t.getReturnType();
Type sres = subst(s.getReturnType(), svars, tvars);
return covariantReturnType(tres, sres, warner);
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Does t have a result that is a subtype of the result type of s,
* suitable for covariant returns? It is assumed that both types
* are (possibly polymorphic) method types. Monomorphic method
* types are handled in the obvious way. Polymorphic method types
* require renaming all type variables of one to corresponding
* type variables in the other, where correspondence is by
* position in the type parameter list. */
public boolean resultSubtype(Type t, Type s, Warner warner) {
List<Type> tvars = t.getTypeArguments();
List<Type> svars = s.getTypeArguments();
Type tres = t.getReturnType();
Type sres = subst(s.getReturnType(), svars, tvars);
return covariantReturnType(tres, sres, warner);
}
代码示例来源:origin: sc.fiji/javac
/**
* Does t have a result that is a subtype of the result type of s,
* suitable for covariant returns? It is assumed that both types
* are (possibly polymorphic) method types. Monomorphic method
* types are handled in the obvious way. Polymorphic method types
* require renaming all type variables of one to corresponding
* type variables in the other, where correspondence is by
* position in the type parameter list. */
public boolean resultSubtype(Type t, Type s, Warner warner) {
List<Type> tvars = t.getTypeArguments();
List<Type> svars = s.getTypeArguments();
Type tres = t.getReturnType();
Type sres = subst(s.getReturnType(), svars, tvars);
return covariantReturnType(tres, sres, warner);
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Does t have a result that is a subtype of the result type of s,
* suitable for covariant returns? It is assumed that both types
* are (possibly polymorphic) method types. Monomorphic method
* types are handled in the obvious way. Polymorphic method types
* require renaming all type variables of one to corresponding
* type variables in the other, where correspondence is by
* position in the type parameter list. */
public boolean resultSubtype(Type t, Type s, Warner warner) {
List<Type> tvars = t.getTypeArguments();
List<Type> svars = s.getTypeArguments();
Type tres = t.getReturnType();
Type sres = subst(s.getReturnType(), svars, tvars);
return covariantReturnType(tres, sres, warner);
}
代码示例来源:origin: sc.fiji/javac
/** Return the first method in t2 that conflicts with a method from t1. */
private Symbol firstDirectIncompatibility(Type t1, Type t2, Type site) {
for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) {
Symbol s1 = e1.sym;
Type st1 = null;
if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types)) continue;
Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false);
if (impl != null && (impl.flags() & ABSTRACT) == 0) continue;
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) {
Symbol s2 = e2.sym;
if (s1 == s2) continue;
if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types)) continue;
if (st1 == null) st1 = types.memberType(t1, s1);
Type st2 = types.memberType(t2, s2);
if (types.overrideEquivalent(st1, st2)) {
List<Type> tvars1 = st1.getTypeArguments();
List<Type> tvars2 = st2.getTypeArguments();
Type rt1 = st1.getReturnType();
Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1);
boolean compat =
types.isSameType(rt1, rt2) ||
rt1.tag >= CLASS && rt2.tag >= CLASS &&
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
types.covariantReturnType(rt2, rt1, Warner.noWarnings));
if (!compat) return s2;
}
}
}
return null;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Return the first method in t2 that conflicts with a method from t1. */
private Symbol firstDirectIncompatibility(Type t1, Type t2, Type site) {
for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) {
Symbol s1 = e1.sym;
Type st1 = null;
if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types)) continue;
Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false);
if (impl != null && (impl.flags() & ABSTRACT) == 0) continue;
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) {
Symbol s2 = e2.sym;
if (s1 == s2) continue;
if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types)) continue;
if (st1 == null) st1 = types.memberType(t1, s1);
Type st2 = types.memberType(t2, s2);
if (types.overrideEquivalent(st1, st2)) {
List<Type> tvars1 = st1.getTypeArguments();
List<Type> tvars2 = st2.getTypeArguments();
Type rt1 = st1.getReturnType();
Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1);
boolean compat =
types.isSameType(rt1, rt2) ||
rt1.tag >= CLASS && rt2.tag >= CLASS &&
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
types.covariantReturnType(rt2, rt1, Warner.noWarnings));
if (!compat) return s2;
}
}
}
return null;
}
代码示例来源:origin: konsoletyper/teavm-javac
public boolean returnTypeSubstitutable(Type r1,
Type r2, Type r2res,
Warner warner) {
if (isSameType(r1.getReturnType(), r2res))
return true;
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
return false;
if (hasSameArgs(r1, r2))
return covariantReturnType(r1.getReturnType(), r2res, warner);
if (!allowCovariantReturns)
return false;
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
return true;
if (!isSubtype(r1.getReturnType(), erasure(r2res)))
return false;
warner.warn(LintCategory.UNCHECKED);
return true;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public boolean returnTypeSubstitutable(Type r1,
Type r2, Type r2res,
Warner warner) {
if (isSameType(r1.getReturnType(), r2res))
return true;
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
return false;
if (hasSameArgs(r1, r2))
return covariantReturnType(r1.getReturnType(), r2res, warner);
if (!allowCovariantReturns)
return false;
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
return true;
if (!isSubtype(r1.getReturnType(), erasure(r2res)))
return false;
warner.warn(LintCategory.UNCHECKED);
return true;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
public boolean returnTypeSubstitutable(Type r1,
Type r2, Type r2res,
Warner warner) {
if (isSameType(r1.getReturnType(), r2res))
return true;
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
return false;
if (hasSameArgs(r1, r2))
return covariantReturnType(r1.getReturnType(), r2res, warner);
if (!source.allowCovariantReturns())
return false;
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
return true;
if (!isSubtype(r1.getReturnType(), erasure(r2res)))
return false;
warner.warnUnchecked();
return true;
}
代码示例来源:origin: sc.fiji/javac
public boolean returnTypeSubstitutable(Type r1,
Type r2, Type r2res,
Warner warner) {
if (isSameType(r1.getReturnType(), r2res))
return true;
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
return false;
if (hasSameArgs(r1, r2))
return covariantReturnType(r1.getReturnType(), r2res, warner);
if (!source.allowCovariantReturns())
return false;
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
return true;
if (!isSubtype(r1.getReturnType(), erasure(r2res)))
return false;
warner.warnUnchecked();
return true;
}
代码示例来源:origin: konsoletyper/teavm-javac
!rt1.isPrimitiveOrVoid() &&
!rt2.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt1, rt2, types.noWarnings) ||
types.covariantReturnType(rt2, rt1, types.noWarnings)) ||
checkCommonOverriderIn(s1,s2,site);
if (!compat) {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
!rt1.isPrimitiveOrVoid() &&
!rt2.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt1, rt2, types.noWarnings) ||
types.covariantReturnType(rt2, rt1, types.noWarnings)) ||
checkCommonOverriderIn(s1,s2,site);
if (!compat) {
内容来源于网络,如有侵权,请联系作者删除!