src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 780
1d625fbe6c22
parent 746
a7ea58fa3e9a
child 795
7b99f98b3035
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Dec 09 15:50:10 2010 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Dec 09 15:50:34 2010 +0000
     1.3 @@ -1668,12 +1668,6 @@
     1.4                      checkOverride(tree, m, (MethodSymbol)e.sym, origin);
     1.5                  }
     1.6              }
     1.7 -            else if (!checkNameClash(origin, e.sym, m)) {
     1.8 -                log.error(tree,
     1.9 -                            "name.clash.same.erasure.no.override",
    1.10 -                            m, m.location(),
    1.11 -                            e.sym, e.sym.location());
    1.12 -            }
    1.13              e = e.next();
    1.14          }
    1.15      }
    1.16 @@ -2022,6 +2016,60 @@
    1.17          }
    1.18      }
    1.19  
    1.20 +    /** Check that all non-override equivalent methods accessible from 'site'
    1.21 +     *  are mutually compatible (JLS 8.4.8/9.4.1).
    1.22 +     *
    1.23 +     *  @param pos  Position to be used for error reporting.
    1.24 +     *  @param site The class whose methods are checked.
    1.25 +     *  @param sym  The method symbol to be checked.
    1.26 +     */
    1.27 +    void checkClashes(DiagnosticPosition pos, Type site, Symbol sym) {
    1.28 +        List<Type> supertypes = types.closure(site);
    1.29 +        for (List<Type> l = supertypes; l.nonEmpty(); l = l.tail) {
    1.30 +            for (List<Type> m = supertypes; m.nonEmpty(); m = m.tail) {
    1.31 +                checkClashes(pos, l.head, m.head, site, sym);
    1.32 +            }
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36 +    /** Reports an error whenever 'sym' seen as a member of type 't1' clashes with
    1.37 +     *  some unrelated method defined in 't2'.
    1.38 +     */
    1.39 +    private void checkClashes(DiagnosticPosition pos, Type t1, Type t2, Type site, Symbol s1) {
    1.40 +        ClashFilter cf = new ClashFilter(site);
    1.41 +        s1 = ((MethodSymbol)s1).implementedIn(t1.tsym, types);
    1.42 +        if (s1 == null) return;
    1.43 +        Type st1 = types.memberType(site, s1);
    1.44 +        for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name, cf); e2.scope != null; e2 = e2.next(cf)) {
    1.45 +            Symbol s2 = e2.sym;
    1.46 +            if (s1 == s2) continue;
    1.47 +            Type st2 = types.memberType(site, s2);
    1.48 +            if (!types.overrideEquivalent(st1, st2) &&
    1.49 +                    !checkNameClash((ClassSymbol)site.tsym, s1, s2)) {
    1.50 +                log.error(pos,
    1.51 +                        "name.clash.same.erasure.no.override",
    1.52 +                        s1, s1.location(),
    1.53 +                        s2, s2.location());
    1.54 +            }
    1.55 +        }
    1.56 +    }
    1.57 +    //where
    1.58 +    private class ClashFilter implements Filter<Symbol> {
    1.59 +
    1.60 +        Type site;
    1.61 +
    1.62 +        ClashFilter(Type site) {
    1.63 +            this.site = site;
    1.64 +        }
    1.65 +
    1.66 +        public boolean accepts(Symbol s) {
    1.67 +            return s.kind == MTH &&
    1.68 +                    (s.flags() & SYNTHETIC) == 0 &&
    1.69 +                    s.isInheritedIn(site.tsym, types) &&
    1.70 +                    !s.isConstructor();
    1.71 +        }
    1.72 +    }
    1.73 +
    1.74      /** Report a conflict between a user symbol and a synthetic symbol.
    1.75       */
    1.76      private void syntheticError(DiagnosticPosition pos, Symbol sym) {

mercurial