940 return mark; 941 } 942 943 @Override 944 public String toString() { 945 StringBuilder buf = new StringBuilder(); 946 buf.append("CompoundScope{"); 947 String sep = ""; 948 for (Scope s : subScopes) { 949 buf.append(sep); 950 buf.append(s); 951 sep = ","; 952 } 953 buf.append("}"); 954 return buf.toString(); 955 } 956 957 @Override 958 public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, 959 final LookupKind lookupKind) { 960 return new Iterable<Symbol>() { 961 public Iterator<Symbol> iterator() { 962 return new CompoundScopeIterator(subScopes) { 963 Iterator<Symbol> nextIterator(Scope s) { 964 return s.getSymbols(sf, lookupKind).iterator(); 965 } 966 }; 967 } 968 }; 969 } 970 971 @Override 972 public Iterable<Symbol> getSymbolsByName(final Name name, 973 final Filter<Symbol> sf, 974 final LookupKind lookupKind) { 975 return new Iterable<Symbol>() { 976 public Iterator<Symbol> iterator() { 977 return new CompoundScopeIterator(subScopes) { 978 Iterator<Symbol> nextIterator(Scope s) { 979 return s.getSymbolsByName(name, sf, lookupKind).iterator(); 980 } 981 }; 982 } 983 }; 984 } 985 986 @Override 987 public Scope getOrigin(Symbol sym) { 988 for (Scope delegate : subScopes) { 989 if (delegate.includes(sym)) 990 return delegate.getOrigin(sym); 991 } 992 993 return null; 994 } 995 996 @Override 997 public boolean isStaticallyImported(Symbol sym) { 998 for (Scope delegate : subScopes) { 999 if (delegate.includes(sym)) 1000 return delegate.isStaticallyImported(sym); 1001 } 1002 1003 return false; 1004 } 1005 1006 abstract class CompoundScopeIterator implements Iterator<Symbol> { 1007 1008 private Iterator<Symbol> currentIterator; 1009 private List<Scope> scopesToScan; 1010 1011 public CompoundScopeIterator(List<Scope> scopesToScan) { 1012 this.scopesToScan = scopesToScan; 1013 update(); 1014 } 1015 1016 abstract Iterator<Symbol> nextIterator(Scope s); 1017 1018 public boolean hasNext() { 1019 return currentIterator != null; 1020 } 1021 1022 public Symbol next() { 1023 Symbol sym = currentIterator.next(); 1024 if (!currentIterator.hasNext()) { 1025 update(); 1026 } 1027 return sym; 1028 } 1029 1030 public void remove() { 1031 throw new UnsupportedOperationException(); 1032 } 1033 1034 private void update() { 1035 while (scopesToScan.nonEmpty()) { 1036 currentIterator = nextIterator(scopesToScan.head); 1037 scopesToScan = scopesToScan.tail; 1038 if (currentIterator.hasNext()) return; 1039 } 1040 currentIterator = null; 1041 } 1042 } 1043 } 1044 1045 /** An error scope, for which the owner should be an error symbol. */ 1046 public static class ErrorScope extends ScopeImpl { 1047 ErrorScope(ScopeImpl next, Symbol errSymbol, Entry[] table) { 1048 super(next, /*owner=*/errSymbol, table); 1049 } 1050 public ErrorScope(Symbol errSymbol) { 1051 super(errSymbol); 1052 } 1053 public WriteableScope dup(Symbol newOwner) { 1054 return new ErrorScope(this, newOwner, table); 1055 } 1056 public WriteableScope dupUnshared(Symbol newOwner) { 1057 return new ErrorScope(this, newOwner, table.clone()); 1058 } 1059 public Entry lookup(Name name) { 1060 Entry e = super.lookup(name); 1061 if (e.scope == null) 1062 return new Entry(owner, null, null, null); | 940 return mark; 941 } 942 943 @Override 944 public String toString() { 945 StringBuilder buf = new StringBuilder(); 946 buf.append("CompoundScope{"); 947 String sep = ""; 948 for (Scope s : subScopes) { 949 buf.append(sep); 950 buf.append(s); 951 sep = ","; 952 } 953 buf.append("}"); 954 return buf.toString(); 955 } 956 957 @Override 958 public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, 959 final LookupKind lookupKind) { 960 return () -> Iterators.createCompoundIterator(subScopes, 961 scope -> scope.getSymbols(sf, 962 lookupKind) 963 .iterator()); 964 } 965 966 @Override 967 public Iterable<Symbol> getSymbolsByName(final Name name, 968 final Filter<Symbol> sf, 969 final LookupKind lookupKind) { 970 return () -> Iterators.createCompoundIterator(subScopes, 971 scope -> scope.getSymbolsByName(name, 972 sf, 973 lookupKind) 974 .iterator()); 975 } 976 977 @Override 978 public Scope getOrigin(Symbol sym) { 979 for (Scope delegate : subScopes) { 980 if (delegate.includes(sym)) 981 return delegate.getOrigin(sym); 982 } 983 984 return null; 985 } 986 987 @Override 988 public boolean isStaticallyImported(Symbol sym) { 989 for (Scope delegate : subScopes) { 990 if (delegate.includes(sym)) 991 return delegate.isStaticallyImported(sym); 992 } 993 994 return false; 995 } 996 997 } 998 999 /** An error scope, for which the owner should be an error symbol. */ 1000 public static class ErrorScope extends ScopeImpl { 1001 ErrorScope(ScopeImpl next, Symbol errSymbol, Entry[] table) { 1002 super(next, /*owner=*/errSymbol, table); 1003 } 1004 public ErrorScope(Symbol errSymbol) { 1005 super(errSymbol); 1006 } 1007 public WriteableScope dup(Symbol newOwner) { 1008 return new ErrorScope(this, newOwner, table); 1009 } 1010 public WriteableScope dupUnshared(Symbol newOwner) { 1011 return new ErrorScope(this, newOwner, table.clone()); 1012 } 1013 public Entry lookup(Name name) { 1014 Entry e = super.lookup(name); 1015 if (e.scope == null) 1016 return new Entry(owner, null, null, null); |