本文整理了Java中com.sun.tools.javac.code.Types.overrideEquivalent()
方法的一些代码示例,展示了Types.overrideEquivalent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.overrideEquivalent()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:overrideEquivalent
[英]Returns true iff these signatures are related by override equivalence. This is the natural extension of isSubSignature to an equivalence relation.
[中]如果这些签名与覆盖等价相关,则返回true。这是isSubSignature对等价关系的自然延伸。
代码示例来源:origin: google/error-prone
@Override
public Choice<Unifier> visitForAll(ForAll target, Unifier unifier) {
Types types = unifier.types();
try {
Type myType = inline(new Inliner(unifier.getContext(), Bindings.create()));
return Choice.condition(
types.overrideEquivalent(types.erasure(myType), types.erasure(target)), unifier);
} catch (CouldNotResolveImportException e) {
return Choice.none();
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public boolean accepts(Symbol s) {
return s.kind == Kinds.MTH &&
s.name == msym.name &&
(s.flags() & SYNTHETIC) == 0 &&
s.isInheritedIn(site.tsym, Types.this) &&
overrideEquivalent(memberType(site, s), memberType(site, msym));
}
};
代码示例来源:origin: konsoletyper/teavm-javac
public boolean accepts(Symbol s) {
return s.kind == Kinds.MTH &&
s.name == msym.name &&
(s.flags() & SYNTHETIC) == 0 &&
s.isInheritedIn(site.tsym, Types.this) &&
overrideEquivalent(memberType(site, s), memberType(site, msym));
}
};
代码示例来源:origin: konsoletyper/teavm-javac
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
Map<TypeSymbol,Type> supertypes = new HashMap<TypeSymbol,Type>();
Type st1 = types.memberType(site, s1);
Type st2 = types.memberType(site, s2);
closure(site, supertypes);
for (Type t : supertypes.values()) {
for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
Symbol s3 = e.sym;
if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue;
Type st3 = types.memberType(site,s3);
if (types.overrideEquivalent(st3, st1) &&
types.overrideEquivalent(st3, st2) &&
types.returnTypeSubstitutable(st3, st1) &&
types.returnTypeSubstitutable(st3, st2)) {
return true;
}
}
}
return false;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
Map<TypeSymbol,Type> supertypes = new HashMap<TypeSymbol,Type>();
Type st1 = types.memberType(site, s1);
Type st2 = types.memberType(site, s2);
closure(site, supertypes);
for (Type t : supertypes.values()) {
for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
Symbol s3 = e.sym;
if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue;
Type st3 = types.memberType(site,s3);
if (types.overrideEquivalent(st3, st1) &&
types.overrideEquivalent(st3, st2) &&
types.returnTypeSubstitutable(st3, st1) &&
types.returnTypeSubstitutable(st3, st2)) {
return true;
}
}
}
return false;
}
代码示例来源:origin: sc.fiji/javac
/**
* "It is also a compile-time error if any method declared in an
* annotation type has a signature that is override-equivalent to
* that of any public or protected method declared in class Object
* or in the interface annotation.Annotation."
*
* @jls3 9.6 Annotation Types
*/
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) {
for (Type sup = syms.annotationType; sup.tag == CLASS; sup = types.supertype(sup)) {
Scope s = sup.tsym.members();
for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) {
if (e.sym.kind == MTH &&
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
types.overrideEquivalent(m.type, e.sym.type))
log.error(pos, "intf.annotation.member.clash", e.sym, sup);
}
}
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* "It is also a compile-time error if any method declared in an
* annotation type has a signature that is override-equivalent to
* that of any public or protected method declared in class Object
* or in the interface annotation.Annotation."
*
* @jls3 9.6 Annotation Types
*/
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) {
for (Type sup = syms.annotationType; sup.tag == CLASS; sup = types.supertype(sup)) {
Scope s = sup.tsym.members();
for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) {
if (e.sym.kind == MTH &&
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
types.overrideEquivalent(m.type, e.sym.type))
log.error(pos, "intf.annotation.member.clash", e.sym, sup);
}
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* "It is also a compile-time error if any method declared in an
* annotation type has a signature that is override-equivalent to
* that of any public or protected method declared in class Object
* or in the interface annotation.Annotation."
*
* @jls 9.6 Annotation Types
*/
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) {
for (Type sup = syms.annotationType; sup.hasTag(CLASS); sup = types.supertype(sup)) {
Scope s = sup.tsym.members();
for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) {
if (e.sym.kind == MTH &&
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
types.overrideEquivalent(m.type, e.sym.type))
log.error(pos, "intf.annotation.member.clash", e.sym, sup);
}
}
}
代码示例来源:origin: com.google.errorprone/error_prone_core
@Override
public Choice<Unifier> visitForAll(ForAll target, Unifier unifier) {
Types types = unifier.types();
try {
Type myType = inline(new Inliner(unifier.getContext(), Bindings.create()));
return Choice.condition(
types.overrideEquivalent(types.erasure(myType), types.erasure(target)), unifier);
} catch (CouldNotResolveImportException e) {
return Choice.none();
}
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* "It is also a compile-time error if any method declared in an
* annotation type has a signature that is override-equivalent to
* that of any public or protected method declared in class Object
* or in the interface annotation.Annotation."
*
* @jls 9.6 Annotation Types
*/
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) {
for (Type sup = syms.annotationType; sup.hasTag(CLASS); sup = types.supertype(sup)) {
Scope s = sup.tsym.members();
for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) {
if (e.sym.kind == MTH &&
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
types.overrideEquivalent(m.type, e.sym.type))
log.error(pos, "intf.annotation.member.clash", e.sym, sup);
}
}
}
代码示例来源:origin: sc.fiji/javac
/** Check that symbol is unique in given scope.
* @param pos Position for error reporting.
* @param sym The symbol.
* @param s The scope.
*/
boolean checkUnique(DiagnosticPosition pos, Symbol sym, Scope s) {
if (sym.type.isErroneous())
return true;
if (sym.owner.name == names.any) return false;
for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) {
if (sym != e.sym &&
sym.kind == e.sym.kind &&
sym.name != names.error &&
(sym.kind != MTH || types.overrideEquivalent(sym.type, e.sym.type))) {
if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS))
varargsDuplicateError(pos, sym, e.sym);
else
duplicateError(pos, e.sym);
return false;
}
}
return true;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Check that symbol is unique in given scope.
* @param pos Position for error reporting.
* @param sym The symbol.
* @param s The scope.
*/
boolean checkUnique(DiagnosticPosition pos, Symbol sym, Scope s) {
if (sym.type.isErroneous())
return true;
if (sym.owner.name == names.any) return false;
for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) {
if (sym != e.sym &&
sym.kind == e.sym.kind &&
sym.name != names.error &&
(sym.kind != MTH || types.overrideEquivalent(sym.type, e.sym.type))) {
if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS))
varargsDuplicateError(pos, sym, e.sym);
else
duplicateError(pos, e.sym);
return false;
}
}
return true;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) {
if (allowLambda &&
identifyLambdaCandidate &&
clazztype.hasTag(CLASS) &&
!pt().hasTag(NONE) &&
types.isFunctionalInterface(clazztype.tsym)) {
Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym);
int count = 0;
boolean found = false;
for (Symbol sym : csym.members().getElements()) {
if ((sym.flags() & SYNTHETIC) != 0 ||
sym.isConstructor()) continue;
count++;
if (sym.kind != MTH ||
!sym.name.equals(descriptor.name)) continue;
Type mtype = types.memberType(clazztype, sym);
if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) {
found = true;
}
}
if (found && count == 1) {
log.note(tree.def, "potential.lambda.found");
}
}
}
代码示例来源:origin: konsoletyper/teavm-javac
private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) {
if (allowLambda &&
identifyLambdaCandidate &&
clazztype.hasTag(CLASS) &&
!pt().hasTag(NONE) &&
types.isFunctionalInterface(clazztype.tsym)) {
Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym);
int count = 0;
boolean found = false;
for (Symbol sym : csym.members().getElements()) {
if ((sym.flags() & SYNTHETIC) != 0 ||
sym.isConstructor()) continue;
count++;
if (sym.kind != MTH ||
!sym.name.equals(descriptor.name)) continue;
Type mtype = types.memberType(clazztype, sym);
if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) {
found = true;
}
}
if (found && count == 1) {
log.note(tree.def, "potential.lambda.found");
}
}
}
代码示例来源: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.kohsuke.sorcerer/sorcerer-javac
Type mt2 = types.memberType(site, s2);
if ((s2.flags() & ABSTRACT) == 0 ||
!types.overrideEquivalent(mt, mt2) ||
!types.isSameTypes(s.erasure(types).getParameterTypes(),
s2.erasure(types).getParameterTypes())) {
代码示例来源: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
Type mt2 = types.memberType(site, s2);
if ((s2.flags() & ABSTRACT) == 0 ||
!types.overrideEquivalent(mt, mt2) ||
!types.isSameTypes(s.erasure(types).getParameterTypes(),
s2.erasure(types).getParameterTypes())) {
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
continue;
Type st2 = types.memberType(t2, s2);
if (types.overrideEquivalent(st1, st2))
log.error(pos, "concrete.inheritance.conflict",
s1, t1, s2, t2, sup);
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
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();
内容来源于网络,如有侵权,请联系作者删除!