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

changeset 1342
1a65d6565b45
parent 1341
db36841709e4
child 1346
20e4a54b1629
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Sep 26 14:22:41 2012 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Sep 28 16:56:53 2012 +0100
     1.3 @@ -27,8 +27,8 @@
     1.4  
     1.5  import com.sun.tools.javac.api.Formattable.LocalizedString;
     1.6  import com.sun.tools.javac.code.*;
     1.7 +import com.sun.tools.javac.code.Symbol.*;
     1.8  import com.sun.tools.javac.code.Type.*;
     1.9 -import com.sun.tools.javac.code.Symbol.*;
    1.10  import com.sun.tools.javac.comp.Attr.ResultInfo;
    1.11  import com.sun.tools.javac.comp.Check.CheckContext;
    1.12  import com.sun.tools.javac.comp.Infer.InferenceContext;
    1.13 @@ -48,6 +48,7 @@
    1.14  import java.util.EnumMap;
    1.15  import java.util.EnumSet;
    1.16  import java.util.HashSet;
    1.17 +import java.util.Iterator;
    1.18  import java.util.Map;
    1.19  import java.util.Set;
    1.20  
    1.21 @@ -60,7 +61,6 @@
    1.22  import static com.sun.tools.javac.code.TypeTags.*;
    1.23  import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
    1.24  import static com.sun.tools.javac.tree.JCTree.Tag.*;
    1.25 -import java.util.Iterator;
    1.26  
    1.27  /** Helper class for name resolution, used mostly by the attribution phase.
    1.28   *
    1.29 @@ -1200,7 +1200,10 @@
    1.30          for (TypeSymbol s : superclasses(intype)) {
    1.31              bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes,
    1.32                      s.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
    1.33 -            abstractOk &= excludeAbstractsFilter.accepts(s);
    1.34 +            //We should not look for abstract methods if receiver is a concrete class
    1.35 +            //(as concrete classes are expected to implement all abstracts coming
    1.36 +            //from superinterfaces)
    1.37 +            abstractOk &= (s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0;
    1.38              if (abstractOk) {
    1.39                  for (Type itype : types.interfaces(s.type)) {
    1.40                      itypes = types.union(types.closure(itype), itypes);
    1.41 @@ -1247,36 +1250,41 @@
    1.42                  return new Iterator<TypeSymbol>() {
    1.43  
    1.44                      List<TypeSymbol> seen = List.nil();
    1.45 -                    TypeSymbol currentSym = getSymbol(intype);
    1.46 +                    TypeSymbol currentSym = symbolFor(intype);
    1.47 +                    TypeSymbol prevSym = null;
    1.48  
    1.49                      public boolean hasNext() {
    1.50 +                        if (currentSym == syms.noSymbol) {
    1.51 +                            currentSym = symbolFor(types.supertype(prevSym.type));
    1.52 +                        }
    1.53                          return currentSym != null;
    1.54                      }
    1.55  
    1.56                      public TypeSymbol next() {
    1.57 -                        TypeSymbol prevSym = currentSym;
    1.58 -                        currentSym = getSymbol(types.supertype(currentSym.type));
    1.59 +                        prevSym = currentSym;
    1.60 +                        currentSym = syms.noSymbol;
    1.61 +                        Assert.check(prevSym != null || prevSym != syms.noSymbol);
    1.62                          return prevSym;
    1.63                      }
    1.64  
    1.65                      public void remove() {
    1.66 -                        throw new UnsupportedOperationException("Not supported yet.");
    1.67 +                        throw new UnsupportedOperationException();
    1.68                      }
    1.69  
    1.70 -                    TypeSymbol getSymbol(Type intype) {
    1.71 -                        if (intype.tag != CLASS &&
    1.72 -                                intype.tag != TYPEVAR) {
    1.73 +                    TypeSymbol symbolFor(Type t) {
    1.74 +                        if (t.tag != CLASS &&
    1.75 +                                t.tag != TYPEVAR) {
    1.76                              return null;
    1.77                          }
    1.78 -                        while (intype.tag == TYPEVAR)
    1.79 -                            intype = intype.getUpperBound();
    1.80 -                        if (seen.contains(intype.tsym)) {
    1.81 +                        while (t.tag == TYPEVAR)
    1.82 +                            t = t.getUpperBound();
    1.83 +                        if (seen.contains(t.tsym)) {
    1.84                              //degenerate case in which we have a circular
    1.85                              //class hierarchy - because of ill-formed classfiles
    1.86                              return null;
    1.87                          }
    1.88 -                        seen = seen.prepend(intype.tsym);
    1.89 -                        return intype.tsym;
    1.90 +                        seen = seen.prepend(t.tsym);
    1.91 +                        return t.tsym;
    1.92                      }
    1.93                  };
    1.94              }
    1.95 @@ -1284,17 +1292,6 @@
    1.96      }
    1.97  
    1.98      /**
    1.99 -     * We should not look for abstract methods if receiver is a concrete class
   1.100 -     * (as concrete classes are expected to implement all abstracts coming
   1.101 -     * from superinterfaces)
   1.102 -     */
   1.103 -    Filter<Symbol> excludeAbstractsFilter = new Filter<Symbol>() {
   1.104 -        public boolean accepts(Symbol s) {
   1.105 -            return (s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0;
   1.106 -        }
   1.107 -    };
   1.108 -
   1.109 -    /**
   1.110       * Lookup a method with given name and argument types in a given scope
   1.111       */
   1.112      Symbol lookupMethod(Env<AttrContext> env,

mercurial