src/share/classes/com/sun/tools/javac/code/Types.java

changeset 1393
d7d932236fee
parent 1374
c002fdee76fd
child 1415
01c9d4161882
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Sat Nov 03 21:09:57 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Sun Nov 04 10:59:42 2012 +0000
     1.3 @@ -75,6 +75,7 @@
     1.4      final boolean allowBoxing;
     1.5      final boolean allowCovariantReturns;
     1.6      final boolean allowObjectToPrimitiveCast;
     1.7 +    final boolean allowDefaultMethods;
     1.8      final ClassReader reader;
     1.9      final Check chk;
    1.10      JCDiagnostic.Factory diags;
    1.11 @@ -98,6 +99,7 @@
    1.12          allowBoxing = source.allowBoxing();
    1.13          allowCovariantReturns = source.allowCovariantReturns();
    1.14          allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast();
    1.15 +        allowDefaultMethods = source.allowDefaultMethods();
    1.16          reader = ClassReader.instance(context);
    1.17          chk = Check.instance(context);
    1.18          capturedName = names.fromString("<captured wildcard>");
    1.19 @@ -2146,6 +2148,13 @@
    1.20                  return List.nil();
    1.21              }
    1.22          };
    1.23 +
    1.24 +    public boolean isDirectSuperInterface(Type t, TypeSymbol tsym) {
    1.25 +        for (Type t2 : interfaces(tsym.type)) {
    1.26 +            if (isSameType(t, t2)) return true;
    1.27 +        }
    1.28 +        return false;
    1.29 +    }
    1.30      // </editor-fold>
    1.31  
    1.32      // <editor-fold defaultstate="collapsed" desc="isDerivedRaw">
    1.33 @@ -2310,6 +2319,10 @@
    1.34          return false;
    1.35      }
    1.36  
    1.37 +    public boolean overridesObjectMethod(Symbol msym) {
    1.38 +        return ((MethodSymbol)msym).implementation(syms.objectType.tsym, this, true) != null;
    1.39 +    }
    1.40 +
    1.41      // <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site">
    1.42      class ImplementationCache {
    1.43  
    1.44 @@ -2455,6 +2468,70 @@
    1.45      }
    1.46      // </editor-fold>
    1.47  
    1.48 +
    1.49 +    //where
    1.50 +    public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) {
    1.51 +        return interfaceCandidates(site, ms, false);
    1.52 +    }
    1.53 +
    1.54 +    public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms, boolean intfOnly) {
    1.55 +        Filter<Symbol> filter = new MethodFilter(ms, site, intfOnly);
    1.56 +        List<MethodSymbol> candidates = List.nil();
    1.57 +        for (Symbol s : membersClosure(site, false).getElements(filter)) {
    1.58 +            if (!site.tsym.isInterface() && !s.owner.isInterface()) {
    1.59 +                return List.of((MethodSymbol)s);
    1.60 +            } else if (!candidates.contains(s)) {
    1.61 +                candidates = candidates.prepend((MethodSymbol)s);
    1.62 +            }
    1.63 +        }
    1.64 +        return prune(candidates, ownerComparator);
    1.65 +    }
    1.66 +
    1.67 +    public List<MethodSymbol> prune(List<MethodSymbol> methods, Comparator<MethodSymbol> cmp) {
    1.68 +        ListBuffer<MethodSymbol> methodsMin = ListBuffer.lb();
    1.69 +        for (MethodSymbol m1 : methods) {
    1.70 +            boolean isMin_m1 = true;
    1.71 +            for (MethodSymbol m2 : methods) {
    1.72 +                if (m1 == m2) continue;
    1.73 +                if (cmp.compare(m2, m1) < 0) {
    1.74 +                    isMin_m1 = false;
    1.75 +                    break;
    1.76 +                }
    1.77 +            }
    1.78 +            if (isMin_m1)
    1.79 +                methodsMin.append(m1);
    1.80 +        }
    1.81 +        return methodsMin.toList();
    1.82 +    }
    1.83 +
    1.84 +    Comparator<MethodSymbol> ownerComparator = new Comparator<MethodSymbol>() {
    1.85 +        public int compare(MethodSymbol s1, MethodSymbol s2) {
    1.86 +            return s1.owner.isSubClass(s2.owner, Types.this) ? -1 : 1;
    1.87 +        }
    1.88 +    };
    1.89 +    // where
    1.90 +            private class MethodFilter implements Filter<Symbol> {
    1.91 +
    1.92 +                Symbol msym;
    1.93 +                Type site;
    1.94 +                boolean intfOnly;
    1.95 +
    1.96 +                MethodFilter(Symbol msym, Type site, boolean intfOnly) {
    1.97 +                    this.msym = msym;
    1.98 +                    this.site = site;
    1.99 +                    this.intfOnly = intfOnly;
   1.100 +                }
   1.101 +
   1.102 +                public boolean accepts(Symbol s) {
   1.103 +                    return s.kind == Kinds.MTH &&
   1.104 +                            (!intfOnly || s.owner.isInterface()) &&
   1.105 +                            s.name == msym.name &&
   1.106 +                            s.isInheritedIn(site.tsym, Types.this) &&
   1.107 +                            overrideEquivalent(memberType(site, s), memberType(site, msym));
   1.108 +                }
   1.109 +            };
   1.110 +    // </editor-fold>
   1.111 +
   1.112      /**
   1.113       * Does t have the same arguments as s?  It is assumed that both
   1.114       * types are (possibly polymorphic) method types.  Monomorphic

mercurial