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

changeset 858
96d4226bdd60
parent 846
17bafae67e9d
child 877
351027202f60
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Feb 07 18:09:46 2011 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Feb 07 18:10:13 2011 +0000
     1.3 @@ -36,6 +36,7 @@
     1.4  import com.sun.tools.javac.code.Lint.LintCategory;
     1.5  import com.sun.tools.javac.comp.Check;
     1.6  
     1.7 +import static com.sun.tools.javac.code.Scope.*;
     1.8  import static com.sun.tools.javac.code.Type.*;
     1.9  import static com.sun.tools.javac.code.TypeTags.*;
    1.10  import static com.sun.tools.javac.code.Symbol.*;
    1.11 @@ -70,7 +71,6 @@
    1.12          new Context.Key<Types>();
    1.13  
    1.14      final Symtab syms;
    1.15 -    final Scope.ScopeCounter scopeCounter;
    1.16      final JavacMessages messages;
    1.17      final Names names;
    1.18      final boolean allowBoxing;
    1.19 @@ -91,7 +91,6 @@
    1.20      protected Types(Context context) {
    1.21          context.put(typesKey, this);
    1.22          syms = Symtab.instance(context);
    1.23 -        scopeCounter = Scope.ScopeCounter.instance(context);
    1.24          names = Names.instance(context);
    1.25          allowBoxing = Source.instance(context).allowBoxing();
    1.26          reader = ClassReader.instance(context);
    1.27 @@ -2024,26 +2023,22 @@
    1.28              final MethodSymbol cachedImpl;
    1.29              final Filter<Symbol> implFilter;
    1.30              final boolean checkResult;
    1.31 -            final Scope.ScopeCounter scopeCounter;
    1.32  
    1.33              public Entry(MethodSymbol cachedImpl,
    1.34                      Filter<Symbol> scopeFilter,
    1.35 -                    boolean checkResult,
    1.36 -                    Scope.ScopeCounter scopeCounter) {
    1.37 +                    boolean checkResult) {
    1.38                  this.cachedImpl = cachedImpl;
    1.39                  this.implFilter = scopeFilter;
    1.40                  this.checkResult = checkResult;
    1.41 -                this.scopeCounter = scopeCounter;
    1.42              }
    1.43  
    1.44 -            boolean matches(Filter<Symbol> scopeFilter, boolean checkResult, Scope.ScopeCounter scopeCounter) {
    1.45 +            boolean matches(Filter<Symbol> scopeFilter, boolean checkResult) {
    1.46                  return this.implFilter == scopeFilter &&
    1.47 -                        this.checkResult == checkResult &&
    1.48 -                        this.scopeCounter.val() >= scopeCounter.val();
    1.49 +                        this.checkResult == checkResult;
    1.50              }
    1.51          }
    1.52  
    1.53 -        MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter, Scope.ScopeCounter scopeCounter) {
    1.54 +        MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) {
    1.55              SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms);
    1.56              Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null;
    1.57              if (cache == null) {
    1.58 @@ -2052,9 +2047,9 @@
    1.59              }
    1.60              Entry e = cache.get(origin);
    1.61              if (e == null ||
    1.62 -                    !e.matches(implFilter, checkResult, scopeCounter)) {
    1.63 +                    !e.matches(implFilter, checkResult)) {
    1.64                  MethodSymbol impl = implementationInternal(ms, origin, Types.this, checkResult, implFilter);
    1.65 -                cache.put(origin, new Entry(impl, implFilter, checkResult, scopeCounter));
    1.66 +                cache.put(origin, new Entry(impl, implFilter, checkResult));
    1.67                  return impl;
    1.68              }
    1.69              else {
    1.70 @@ -2081,11 +2076,55 @@
    1.71  
    1.72      private ImplementationCache implCache = new ImplementationCache();
    1.73  
    1.74 -    public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
    1.75 -        return implCache.get(ms, origin, checkResult, implFilter, scopeCounter);
    1.76 +    public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) {
    1.77 +        return implCache.get(ms, origin, checkResult, implFilter);
    1.78      }
    1.79      // </editor-fold>
    1.80  
    1.81 +    // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site">
    1.82 +    public Scope membersClosure(Type site) {
    1.83 +        return membersClosure.visit(site);
    1.84 +    }
    1.85 +
    1.86 +    UnaryVisitor<Scope> membersClosure = new UnaryVisitor<Scope>() {
    1.87 +
    1.88 +        public Scope visitType(Type t, Void s) {
    1.89 +            return null;
    1.90 +        }
    1.91 +
    1.92 +        @Override
    1.93 +        public Scope visitClassType(ClassType t, Void s) {
    1.94 +            ClassSymbol csym = (ClassSymbol)t.tsym;
    1.95 +            if (csym.membersClosure == null) {
    1.96 +                Scope membersClosure = new Scope(csym);
    1.97 +                for (Type i : interfaces(t)) {
    1.98 +                    enterAll(visit(i), membersClosure);
    1.99 +                }
   1.100 +                enterAll(visit(supertype(t)), membersClosure);
   1.101 +                enterAll(csym.members(), membersClosure);
   1.102 +                csym.membersClosure = membersClosure;
   1.103 +            }
   1.104 +            return csym.membersClosure;
   1.105 +        }
   1.106 +
   1.107 +        @Override
   1.108 +        public Scope visitTypeVar(TypeVar t, Void s) {
   1.109 +            return visit(t.getUpperBound());
   1.110 +        }
   1.111 +
   1.112 +        public void enterAll(Scope s, Scope to) {
   1.113 +            if (s == null) return;
   1.114 +            List<Symbol> syms = List.nil();
   1.115 +            for (Scope.Entry e = s.elems ; e != null ; e = e.sibling) {
   1.116 +                syms = syms.prepend(e.sym);
   1.117 +            }
   1.118 +            for (Symbol sym : syms) {
   1.119 +                to.enter(sym);
   1.120 +            }
   1.121 +        }
   1.122 +    };
   1.123 +    // </editor-fold>
   1.124 +
   1.125      /**
   1.126       * Does t have the same arguments as s?  It is assumed that both
   1.127       * types are (possibly polymorphic) method types.  Monomorphic

mercurial