author | jlahoda |
Mon, 08 Aug 2016 17:22:44 +0200 | |
changeset 40235 | fe6c00618434 |
parent 32454 | b0ac04e0fefe |
child 41991 | cc8a2784dd4c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30999
f1bb0191a5a7
8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
29149
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
27857 | 28 |
import com.sun.tools.javac.code.Kinds.Kind; |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
29 |
import java.lang.ref.WeakReference; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
30 |
import java.util.*; |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
31 |
import java.util.function.BiConsumer; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
32 |
import java.util.stream.Stream; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
33 |
import java.util.stream.StreamSupport; |
14258 | 34 |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
35 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
27857 | 36 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
37 |
import com.sun.tools.javac.tree.JCTree.JCImport; |
|
10 | 38 |
import com.sun.tools.javac.util.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
39 |
import com.sun.tools.javac.util.List; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
40 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
41 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
42 |
import static com.sun.tools.javac.code.Scope.LookupKind.RECURSIVE; |
10 | 43 |
|
44 |
/** A scope represents an area of visibility in a Java program. The |
|
45 |
* Scope class is a container for symbols which provides |
|
46 |
* efficient access to symbols given their names. Scopes are implemented |
|
7206
02edd110358f
6998063: new Scope impl to fix Scope performance issues
jjg
parents:
7079
diff
changeset
|
47 |
* as hash tables with "open addressing" and "double hashing". |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
48 |
* Scopes can be nested. Nested scopes can share their hash tables. |
10 | 49 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
50 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
51 |
* If you write code that depends on this, you do so at your own risk. |
10 | 52 |
* This code and its internal interfaces are subject to change or |
53 |
* deletion without notice.</b> |
|
54 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
55 |
public abstract class Scope { |
10 | 56 |
|
57 |
/** The scope's owner. |
|
58 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
59 |
public final Symbol owner; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
60 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
61 |
protected Scope(Symbol owner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
62 |
this.owner = owner; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
63 |
} |
10 | 64 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
65 |
/**Returns all Symbols in this Scope. Symbols from outward Scopes are included. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
66 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
67 |
public final Iterable<Symbol> getSymbols() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
68 |
return getSymbols(noFilter); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
69 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
70 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
71 |
/**Returns Symbols that match the given filter. Symbols from outward Scopes are included. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
72 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
73 |
public final Iterable<Symbol> getSymbols(Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
74 |
return getSymbols(sf, RECURSIVE); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
75 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
76 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
77 |
/**Returns all Symbols in this Scope. Symbols from outward Scopes are included |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
78 |
* iff lookupKind == RECURSIVE. |
10 | 79 |
*/ |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
80 |
public final Iterable<Symbol> getSymbols(LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
81 |
return getSymbols(noFilter, lookupKind); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
82 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
83 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
84 |
/**Returns Symbols that match the given filter. Symbols from outward Scopes are included |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
85 |
* iff lookupKind == RECURSIVE. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
86 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
87 |
public abstract Iterable<Symbol> getSymbols(Filter<Symbol> sf, LookupKind lookupKind); |
10 | 88 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
89 |
/**Returns Symbols with the given name. Symbols from outward Scopes are included. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
90 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
91 |
public final Iterable<Symbol> getSymbolsByName(Name name) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
92 |
return getSymbolsByName(name, RECURSIVE); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
93 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
94 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
95 |
/**Returns Symbols with the given name that match the given filter. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
96 |
* Symbols from outward Scopes are included. |
10 | 97 |
*/ |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
98 |
public final Iterable<Symbol> getSymbolsByName(final Name name, final Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
99 |
return getSymbolsByName(name, sf, RECURSIVE); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
100 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
101 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
102 |
/**Returns Symbols with the given name. Symbols from outward Scopes are included |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
103 |
* iff lookupKind == RECURSIVE. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
104 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
105 |
public final Iterable<Symbol> getSymbolsByName(Name name, LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
106 |
return getSymbolsByName(name, noFilter, lookupKind); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
107 |
} |
10 | 108 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
109 |
/**Returns Symbols with the given name that match the given filter. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
110 |
* Symbols from outward Scopes are included iff lookupKind == RECURSIVE. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
111 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
112 |
public abstract Iterable<Symbol> getSymbolsByName(final Name name, final Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
113 |
final LookupKind lookupKind); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
114 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
115 |
/** Return the first Symbol from this or outward scopes with the given name. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
116 |
* Returns null if none. |
10 | 117 |
*/ |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
118 |
public final Symbol findFirst(Name name) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
119 |
return findFirst(name, noFilter); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
120 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
121 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
122 |
/** Return the first Symbol from this or outward scopes with the given name that matches the |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
123 |
* given filter. Returns null if none. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
124 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
125 |
public Symbol findFirst(Name name, Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
126 |
Iterator<Symbol> it = getSymbolsByName(name, sf).iterator(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
127 |
return it.hasNext() ? it.next() : null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
128 |
} |
10 | 129 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
130 |
/** Returns true iff there are is at least one Symbol in this scope matching the given filter. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
131 |
* Does not inspect outward scopes. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
132 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
133 |
public boolean anyMatch(Filter<Symbol> filter) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
134 |
return getSymbols(filter, NON_RECURSIVE).iterator().hasNext(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
135 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
136 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
137 |
/** Returns true iff the given Symbol is in this scope or any outward scope. |
10 | 138 |
*/ |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
139 |
public boolean includes(final Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
140 |
return getSymbolsByName(sym.name, new Filter<Symbol>() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
141 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
142 |
public boolean accepts(Symbol t) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
143 |
return t == sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
144 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
145 |
}).iterator().hasNext(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
146 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
147 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
148 |
/** Returns true iff this scope does not contain any Symbol. Does not inspect outward scopes. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
149 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
150 |
public boolean isEmpty() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
151 |
return !getSymbols(NON_RECURSIVE).iterator().hasNext(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
152 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
153 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
154 |
/** Returns the Scope from which the givins Symbol originates in this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
155 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
156 |
public abstract Scope getOrigin(Symbol byName); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
157 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
158 |
/** Returns true iff the given Symbol is part of this scope due to a static import. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
159 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
160 |
public abstract boolean isStaticallyImported(Symbol byName); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
161 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
162 |
private static final Filter<Symbol> noFilter = null; |
10 | 163 |
|
7615 | 164 |
/** A list of scopes to be notified if items are to be removed from this scope. |
165 |
*/ |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
166 |
ScopeListenerList listeners = new ScopeListenerList(); |
7615 | 167 |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
168 |
public interface ScopeListener { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
169 |
void symbolAdded(Symbol sym, Scope s); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
170 |
void symbolRemoved(Symbol sym, Scope s); |
10 | 171 |
} |
172 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
173 |
/** |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
174 |
* A list of scope listeners; listeners are stored in weak references, to avoid memory leaks. |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
175 |
* When the listener list is scanned (upon notification), elements corresponding to GC-ed |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
176 |
* listeners are removed so that the listener list size is kept in check. |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
177 |
*/ |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
178 |
public static class ScopeListenerList { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
179 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
180 |
List<WeakReference<ScopeListener>> listeners = List.nil(); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
181 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
182 |
void add(ScopeListener sl) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
183 |
listeners = listeners.prepend(new WeakReference<>(sl)); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
184 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
185 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
186 |
void symbolAdded(Symbol sym, Scope scope) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
187 |
walkReferences(sym, scope, false); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
188 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
189 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
190 |
void symbolRemoved(Symbol sym, Scope scope) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
191 |
walkReferences(sym, scope, true); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
192 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
193 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
194 |
private void walkReferences(Symbol sym, Scope scope, boolean isRemove) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
195 |
ListBuffer<WeakReference<ScopeListener>> newListeners = new ListBuffer<>(); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
196 |
for (WeakReference<ScopeListener> wsl : listeners) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
197 |
ScopeListener sl = wsl.get(); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
198 |
if (sl != null) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
199 |
if (isRemove) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
200 |
sl.symbolRemoved(sym, scope); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
201 |
} else { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
202 |
sl.symbolAdded(sym, scope); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
203 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
204 |
newListeners.add(wsl); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
205 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
206 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
207 |
listeners = newListeners.toList(); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
208 |
} |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
209 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
210 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
211 |
public enum LookupKind { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
212 |
RECURSIVE, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
213 |
NON_RECURSIVE; |
10 | 214 |
} |
215 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
216 |
/**A scope into which Symbols can be added.*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
217 |
public abstract static class WriteableScope extends Scope { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
218 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
219 |
public WriteableScope(Symbol owner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
220 |
super(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
221 |
} |
10 | 222 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
223 |
/** Enter the given Symbol into this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
224 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
225 |
public abstract void enter(Symbol c); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
226 |
/** Enter symbol sym in this scope if not already there. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
227 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
228 |
public abstract void enterIfAbsent(Symbol c); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
229 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
230 |
public abstract void remove(Symbol c); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
231 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
232 |
/** Construct a fresh scope within this scope, with same owner. The new scope may |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
233 |
* shares internal structures with the this scope. Used in connection with |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
234 |
* method leave if scope access is stack-like in order to avoid allocation |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
235 |
* of fresh tables. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
236 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
237 |
public final WriteableScope dup() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
238 |
return dup(this.owner); |
10 | 239 |
} |
240 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
241 |
/** Construct a fresh scope within this scope, with new owner. The new scope may |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
242 |
* shares internal structures with the this scope. Used in connection with |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
243 |
* method leave if scope access is stack-like in order to avoid allocation |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
244 |
* of fresh tables. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
245 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
246 |
public abstract WriteableScope dup(Symbol newOwner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
247 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
248 |
/** Must be called on dup-ed scopes to be able to work with the outward scope again. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
249 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
250 |
public abstract WriteableScope leave(); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
5847
diff
changeset
|
251 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
252 |
/** Construct a fresh scope within this scope, with same owner. The new scope |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
253 |
* will not share internal structures with this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
254 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
255 |
public final WriteableScope dupUnshared() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
256 |
return dupUnshared(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
257 |
} |
18899
2557b27d1f1c
6356530: -Xlint:serial does not flag abstract classes with concrete methods/members
vromero
parents:
14258
diff
changeset
|
258 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
259 |
/** Construct a fresh scope within this scope, with new owner. The new scope |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
260 |
* will not share internal structures with this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
261 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
262 |
public abstract WriteableScope dupUnshared(Symbol newOwner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
263 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
264 |
/** Create a new WriteableScope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
265 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
266 |
public static WriteableScope create(Symbol owner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
267 |
return new ScopeImpl(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
268 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
269 |
|
10 | 270 |
} |
271 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
272 |
private static class ScopeImpl extends WriteableScope { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
273 |
/** The number of scopes that share this scope's hash table. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
274 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
275 |
private int shared; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
276 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
277 |
/** Next enclosing scope (with whom this scope may share a hashtable) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
278 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
279 |
public ScopeImpl next; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
280 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
281 |
/** A hash table for the scope's entries. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
282 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
283 |
Entry[] table; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
284 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
285 |
/** Mask for hash codes, always equal to (table.length - 1). |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
286 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
287 |
int hashMask; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
288 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
289 |
/** A linear list that also contains all entries in |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
290 |
* reverse order of appearance (i.e later entries are pushed on top). |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
291 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
292 |
public Entry elems; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
293 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
294 |
/** The number of elements in this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
295 |
* This includes deleted elements, whose value is the sentinel. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
296 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
297 |
int nelems = 0; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
298 |
|
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
299 |
int removeCount = 0; |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
300 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
301 |
/** Use as a "not-found" result for lookup. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
302 |
* Also used to mark deleted entries in the table. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
303 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
304 |
private static final Entry sentinel = new Entry(null, null, null, null); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
305 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
306 |
/** The hash table's initial size. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
307 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
308 |
private static final int INITIAL_SIZE = 0x10; |
7206
02edd110358f
6998063: new Scope impl to fix Scope performance issues
jjg
parents:
7079
diff
changeset
|
309 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
310 |
/** Construct a new scope, within scope next, with given owner, using |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
311 |
* given table. The table's length must be an exponent of 2. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
312 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
313 |
private ScopeImpl(ScopeImpl next, Symbol owner, Entry[] table) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
314 |
super(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
315 |
this.next = next; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
316 |
Assert.check(owner != null); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
317 |
this.table = table; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
318 |
this.hashMask = table.length - 1; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
319 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
320 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
321 |
/** Convenience constructor used for dup and dupUnshared. */ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
322 |
private ScopeImpl(ScopeImpl next, Symbol owner, Entry[] table, int nelems) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
323 |
this(next, owner, table); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
324 |
this.nelems = nelems; |
7206
02edd110358f
6998063: new Scope impl to fix Scope performance issues
jjg
parents:
7079
diff
changeset
|
325 |
} |
02edd110358f
6998063: new Scope impl to fix Scope performance issues
jjg
parents:
7079
diff
changeset
|
326 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
327 |
/** Construct a new scope, within scope next, with given owner, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
328 |
* using a fresh table of length INITIAL_SIZE. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
329 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
330 |
public ScopeImpl(Symbol owner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
331 |
this(null, owner, new Entry[INITIAL_SIZE]); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
332 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
5847
diff
changeset
|
333 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
334 |
/** Construct a fresh scope within this scope, with new owner, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
335 |
* which shares its table with the outer scope. Used in connection with |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
336 |
* method leave if scope access is stack-like in order to avoid allocation |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
337 |
* of fresh tables. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
338 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
339 |
public WriteableScope dup(Symbol newOwner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
340 |
ScopeImpl result = new ScopeImpl(this, newOwner, this.table, this.nelems); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
341 |
shared++; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
342 |
// System.out.println("====> duping scope " + this.hashCode() + " owned by " + newOwner + " to " + result.hashCode()); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
343 |
// new Error().printStackTrace(System.out); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
344 |
return result; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
345 |
} |
10 | 346 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
347 |
/** Construct a fresh scope within this scope, with new owner, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
348 |
* with a new hash table, whose contents initially are those of |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
349 |
* the table of its outer scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
350 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
351 |
public WriteableScope dupUnshared(Symbol newOwner) { |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
352 |
if (shared > 0) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
353 |
//The nested Scopes might have already added something to the table, so all items |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
354 |
//that don't originate in this Scope or any of its outer Scopes need to be cleared: |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
355 |
Set<Scope> acceptScopes = Collections.newSetFromMap(new IdentityHashMap<>()); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
356 |
ScopeImpl c = this; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
357 |
while (c != null) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
358 |
acceptScopes.add(c); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
359 |
c = c.next; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
360 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
361 |
int n = 0; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
362 |
Entry[] oldTable = this.table; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
363 |
Entry[] newTable = new Entry[this.table.length]; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
364 |
for (int i = 0; i < oldTable.length; i++) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
365 |
Entry e = oldTable[i]; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
366 |
while (e != null && e != sentinel && !acceptScopes.contains(e.scope)) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
367 |
e = e.shadowed; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
368 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
369 |
if (e != null) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
370 |
n++; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
371 |
newTable[i] = e; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
372 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
373 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
374 |
return new ScopeImpl(this, newOwner, newTable, n); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
375 |
} else { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
376 |
return new ScopeImpl(this, newOwner, this.table.clone(), this.nelems); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
25874
diff
changeset
|
377 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
378 |
} |
10 | 379 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
380 |
/** Remove all entries of this scope from its table, if shared |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
381 |
* with next. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
382 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
383 |
public WriteableScope leave() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
384 |
Assert.check(shared == 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
385 |
if (table != next.table) return next; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
386 |
while (elems != null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
387 |
int hash = getIndex(elems.sym.name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
388 |
Entry e = table[hash]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
389 |
Assert.check(e == elems, elems.sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
390 |
table[hash] = elems.shadowed; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
391 |
elems = elems.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
392 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
393 |
Assert.check(next.shared > 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
394 |
next.shared--; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
395 |
next.nelems = nelems; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
396 |
// System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode()); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
397 |
// new Error().printStackTrace(System.out); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
398 |
return next; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
399 |
} |
10 | 400 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
401 |
/** Double size of hash table. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
402 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
403 |
private void dble() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
404 |
Assert.check(shared == 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
405 |
Entry[] oldtable = table; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
406 |
Entry[] newtable = new Entry[oldtable.length * 2]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
407 |
for (ScopeImpl s = this; s != null; s = s.next) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
408 |
if (s.table == oldtable) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
409 |
Assert.check(s == this || s.shared != 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
410 |
s.table = newtable; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
411 |
s.hashMask = newtable.length - 1; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
412 |
} |
10 | 413 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
414 |
int n = 0; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
415 |
for (int i = oldtable.length; --i >= 0; ) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
416 |
Entry e = oldtable[i]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
417 |
if (e != null && e != sentinel) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
418 |
table[getIndex(e.sym.name)] = e; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
419 |
n++; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
420 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
421 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
422 |
// We don't need to update nelems for shared inherited scopes, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
423 |
// since that gets handled by leave(). |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
424 |
nelems = n; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
425 |
} |
10 | 426 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
427 |
/** Enter symbol sym in this scope. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
428 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
429 |
public void enter(Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
430 |
Assert.check(shared == 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
431 |
if (nelems * 3 >= hashMask * 2) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
432 |
dble(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
433 |
int hash = getIndex(sym.name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
434 |
Entry old = table[hash]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
435 |
if (old == null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
436 |
old = sentinel; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
437 |
nelems++; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
438 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
439 |
Entry e = new Entry(sym, old, elems, this); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
440 |
table[hash] = e; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
441 |
elems = e; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
442 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
443 |
//notify listeners |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
444 |
listeners.symbolAdded(sym, this); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
445 |
} |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
446 |
|
30999
f1bb0191a5a7
8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
29149
diff
changeset
|
447 |
/** Remove symbol from this scope. |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
448 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
449 |
public void remove(Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
450 |
Assert.check(shared == 0); |
30999
f1bb0191a5a7
8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
29149
diff
changeset
|
451 |
Entry e = lookup(sym.name, candidate -> candidate == sym); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
452 |
if (e.scope == null) return; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
453 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
454 |
// remove e from table and shadowed list; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
455 |
int i = getIndex(sym.name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
456 |
Entry te = table[i]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
457 |
if (te == e) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
458 |
table[i] = e.shadowed; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
459 |
else while (true) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
460 |
if (te.shadowed == e) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
461 |
te.shadowed = e.shadowed; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
462 |
break; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
463 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
464 |
te = te.shadowed; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
465 |
} |
10 | 466 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
467 |
// remove e from elems and sibling list |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
468 |
te = elems; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
469 |
if (te == e) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
470 |
elems = e.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
471 |
else while (true) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
472 |
if (te.sibling == e) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
473 |
te.sibling = e.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
474 |
break; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
475 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
476 |
te = te.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
477 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
478 |
|
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
479 |
removeCount++; |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
480 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
481 |
//notify listeners |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
482 |
listeners.symbolRemoved(sym, this); |
10 | 483 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
484 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
485 |
/** Enter symbol sym in this scope if not already there. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
486 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
487 |
public void enterIfAbsent(Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
488 |
Assert.check(shared == 0); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
489 |
Entry e = lookup(sym.name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
490 |
while (e.scope == this && e.sym.kind != sym.kind) e = e.next(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
491 |
if (e.scope != this) enter(sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
492 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
493 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
494 |
/** Given a class, is there already a class with same fully |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
495 |
* qualified name in this (import) scope? |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
496 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
497 |
public boolean includes(Symbol c) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
498 |
for (Scope.Entry e = lookup(c.name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
499 |
e.scope == this; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
500 |
e = e.next()) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
501 |
if (e.sym == c) return true; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
502 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
503 |
return false; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
504 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
505 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
506 |
/** Return the entry associated with given name, starting in |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
507 |
* this scope and proceeding outwards. If no entry was found, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
508 |
* return the sentinel, which is characterized by having a null in |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
509 |
* both its scope and sym fields, whereas both fields are non-null |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
510 |
* for regular entries. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
511 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
512 |
protected Entry lookup(Name name) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
513 |
return lookup(name, noFilter); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
514 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
515 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
516 |
protected Entry lookup(Name name, Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
517 |
Entry e = table[getIndex(name)]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
518 |
if (e == null || e == sentinel) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
519 |
return sentinel; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
520 |
while (e.scope != null && (e.sym.name != name || (sf != null && !sf.accepts(e.sym)))) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
521 |
e = e.shadowed; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
522 |
return e; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
523 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
524 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
525 |
public Symbol findFirst(Name name, Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
526 |
return lookup(name, sf).sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
527 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
528 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
529 |
/*void dump (java.io.PrintStream out) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
530 |
out.println(this); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
531 |
for (int l=0; l < table.length; l++) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
532 |
Entry le = table[l]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
533 |
out.print("#"+l+": "); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
534 |
if (le==sentinel) out.println("sentinel"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
535 |
else if(le == null) out.println("null"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
536 |
else out.println(""+le+" s:"+le.sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
537 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
538 |
}*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
539 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
540 |
/** Look for slot in the table. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
541 |
* We use open addressing with double hashing. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
542 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
543 |
int getIndex (Name name) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
544 |
int h = name.hashCode(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
545 |
int i = h & hashMask; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
546 |
// The expression below is always odd, so it is guaranteed |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
547 |
// to be mutually prime with table.length, a power of 2. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
548 |
int x = hashMask - ((h + (h >> 16)) << 1); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
549 |
int d = -1; // Index of a deleted item. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
550 |
for (;;) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
551 |
Entry e = table[i]; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
552 |
if (e == null) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
553 |
return d >= 0 ? d : i; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
554 |
if (e == sentinel) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
555 |
// We have to keep searching even if we see a deleted item. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
556 |
// However, remember the index in case we fail to find the name. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
557 |
if (d < 0) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
558 |
d = i; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
559 |
} else if (e.sym.name == name) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
560 |
return i; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
561 |
i = (i + x) & hashMask; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
562 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
563 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
564 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
565 |
public boolean anyMatch(Filter<Symbol> sf) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
566 |
return getSymbols(sf, NON_RECURSIVE).iterator().hasNext(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
567 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
568 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
569 |
public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
570 |
final LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
571 |
return new Iterable<Symbol>() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
572 |
public Iterator<Symbol> iterator() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
573 |
return new Iterator<Symbol>() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
574 |
private ScopeImpl currScope = ScopeImpl.this; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
575 |
private Scope.Entry currEntry = elems; |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
576 |
private int seenRemoveCount = currScope.removeCount; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
577 |
{ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
578 |
update(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
579 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
580 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
581 |
public boolean hasNext() { |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
582 |
if (seenRemoveCount != currScope.removeCount && |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
583 |
currEntry != null && |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
584 |
!currEntry.scope.includes(currEntry.sym)) { |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
585 |
doNext(); //skip entry that is no longer in the Scope |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
586 |
seenRemoveCount = currScope.removeCount; |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
587 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
588 |
return currEntry != null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
589 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
590 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
591 |
public Symbol next() { |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
592 |
if (!hasNext()) { |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
593 |
throw new NoSuchElementException(); |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
594 |
} |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
595 |
|
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
596 |
return doNext(); |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
597 |
} |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
598 |
private Symbol doNext() { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
599 |
Symbol sym = (currEntry == null ? null : currEntry.sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
600 |
if (currEntry != null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
601 |
currEntry = currEntry.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
602 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
603 |
update(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
604 |
return sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
605 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
606 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
607 |
public void remove() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
608 |
throw new UnsupportedOperationException(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
609 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
610 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
611 |
private void update() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
612 |
skipToNextMatchingEntry(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
613 |
if (lookupKind == RECURSIVE) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
614 |
while (currEntry == null && currScope.next != null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
615 |
currScope = currScope.next; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
616 |
currEntry = currScope.elems; |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
617 |
seenRemoveCount = currScope.removeCount; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
618 |
skipToNextMatchingEntry(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
619 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
620 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
621 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
622 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
623 |
void skipToNextMatchingEntry() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
624 |
while (currEntry != null && sf != null && !sf.accepts(currEntry.sym)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
625 |
currEntry = currEntry.sibling; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
626 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
627 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
628 |
}; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
629 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
630 |
}; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
631 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
632 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
633 |
public Iterable<Symbol> getSymbolsByName(final Name name, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
634 |
final Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
635 |
final LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
636 |
return new Iterable<Symbol>() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
637 |
public Iterator<Symbol> iterator() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
638 |
return new Iterator<Symbol>() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
639 |
Scope.Entry currentEntry = lookup(name, sf); |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
640 |
int seenRemoveCount = currentEntry.scope != null ? |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
641 |
currentEntry.scope.removeCount : -1; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
642 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
643 |
public boolean hasNext() { |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
644 |
if (currentEntry.scope != null && |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
645 |
seenRemoveCount != currentEntry.scope.removeCount && |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
646 |
!currentEntry.scope.includes(currentEntry.sym)) { |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
647 |
doNext(); //skip entry that is no longer in the Scope |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
648 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
649 |
return currentEntry.scope != null && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
650 |
(lookupKind == RECURSIVE || |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
651 |
currentEntry.scope == ScopeImpl.this); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
652 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
653 |
public Symbol next() { |
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
654 |
if (!hasNext()) { |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
655 |
throw new NoSuchElementException(); |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
656 |
} |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
657 |
return doNext(); |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
658 |
} |
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
659 |
private Symbol doNext() { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
660 |
Scope.Entry prevEntry = currentEntry; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
661 |
currentEntry = currentEntry.next(sf); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
662 |
return prevEntry.sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
663 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
664 |
public void remove() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
665 |
throw new UnsupportedOperationException(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
666 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
667 |
}; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
668 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
669 |
}; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
670 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
671 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
672 |
public Scope getOrigin(Symbol s) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
673 |
for (Scope.Entry e = lookup(s.name); e.scope != null ; e = e.next()) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
674 |
if (e.sym == s) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
675 |
return this; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
676 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
677 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
678 |
return null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
679 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
680 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
681 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
682 |
public boolean isStaticallyImported(Symbol s) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
683 |
return false; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
684 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
685 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
686 |
public String toString() { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
687 |
StringBuilder result = new StringBuilder(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
688 |
result.append("Scope["); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
689 |
for (ScopeImpl s = this; s != null ; s = s.next) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
690 |
if (s != this) result.append(" | "); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
691 |
for (Entry e = s.elems; e != null; e = e.sibling) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
692 |
if (e != s.elems) result.append(", "); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
693 |
result.append(e.sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
694 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
695 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
696 |
result.append("]"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
697 |
return result.toString(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
698 |
} |
10 | 699 |
} |
700 |
||
701 |
/** A class for scope entries. |
|
702 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
703 |
private static class Entry { |
10 | 704 |
|
705 |
/** The referenced symbol. |
|
706 |
* sym == null iff this == sentinel |
|
707 |
*/ |
|
708 |
public Symbol sym; |
|
709 |
||
710 |
/** An entry with the same hash code, or sentinel. |
|
711 |
*/ |
|
712 |
private Entry shadowed; |
|
713 |
||
714 |
/** Next entry in same scope. |
|
715 |
*/ |
|
716 |
public Entry sibling; |
|
717 |
||
718 |
/** The entry's scope. |
|
719 |
* scope == null iff this == sentinel |
|
720 |
*/ |
|
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
721 |
public ScopeImpl scope; |
10 | 722 |
|
40235
fe6c00618434
8144733: Iterating over elements of a Scope can return spurious inner class elements
jlahoda
parents:
32454
diff
changeset
|
723 |
public Entry(Symbol sym, Entry shadowed, Entry sibling, ScopeImpl scope) { |
10 | 724 |
this.sym = sym; |
725 |
this.shadowed = shadowed; |
|
726 |
this.sibling = sibling; |
|
727 |
this.scope = scope; |
|
728 |
} |
|
729 |
||
730 |
/** Return next entry with the same name as this entry, proceeding |
|
731 |
* outwards if not found in this scope. |
|
732 |
*/ |
|
733 |
public Entry next() { |
|
7206
02edd110358f
6998063: new Scope impl to fix Scope performance issues
jjg
parents:
7079
diff
changeset
|
734 |
return shadowed; |
10 | 735 |
} |
736 |
||
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7615
diff
changeset
|
737 |
public Entry next(Filter<Symbol> sf) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
738 |
if (shadowed.sym == null || sf == null || sf.accepts(shadowed.sym)) return shadowed; |
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7615
diff
changeset
|
739 |
else return shadowed.next(sf); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7615
diff
changeset
|
740 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7615
diff
changeset
|
741 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
742 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
743 |
|
27857 | 744 |
public static class ImportScope extends CompoundScope { |
745 |
||
746 |
public ImportScope(Symbol owner) { |
|
747 |
super(owner); |
|
748 |
} |
|
749 |
||
750 |
/**Finalize the content of the ImportScope to speed-up future lookups. |
|
751 |
* No further changes to class hierarchy or class content will be reflected. |
|
752 |
*/ |
|
753 |
public void finalizeScope() { |
|
754 |
for (List<Scope> scopes = this.subScopes; scopes.nonEmpty(); scopes = scopes.tail) { |
|
755 |
Scope impScope = scopes.head; |
|
756 |
||
757 |
if (impScope instanceof FilterImportScope && impScope.owner.kind == Kind.TYP) { |
|
758 |
WriteableScope finalized = WriteableScope.create(impScope.owner); |
|
759 |
||
760 |
for (Symbol sym : impScope.getSymbols()) { |
|
761 |
finalized.enter(sym); |
|
762 |
} |
|
763 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
764 |
finalized.listeners.add(new ScopeListener() { |
27857 | 765 |
@Override |
766 |
public void symbolAdded(Symbol sym, Scope s) { |
|
767 |
Assert.error("The scope is sealed."); |
|
768 |
} |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
769 |
|
27857 | 770 |
@Override |
771 |
public void symbolRemoved(Symbol sym, Scope s) { |
|
772 |
Assert.error("The scope is sealed."); |
|
773 |
} |
|
774 |
}); |
|
775 |
||
776 |
scopes.head = finalized; |
|
777 |
} |
|
778 |
} |
|
779 |
} |
|
780 |
||
781 |
} |
|
782 |
||
783 |
public static class NamedImportScope extends ImportScope { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
784 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
785 |
public NamedImportScope(Symbol owner, Scope currentFileScope) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
786 |
super(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
787 |
prependSubScope(currentFileScope); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
788 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
789 |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
790 |
public Scope importByName(Types types, Scope origin, Name name, ImportFilter filter, JCImport imp, BiConsumer<JCImport, CompletionFailure> cfHandler) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
791 |
return appendScope(new FilterImportScope(types, origin, name, filter, imp, cfHandler)); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
792 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
793 |
|
27857 | 794 |
public Scope importType(Scope delegate, Scope origin, Symbol sym) { |
795 |
return appendScope(new SingleEntryScope(delegate.owner, sym, origin)); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
796 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
797 |
|
27857 | 798 |
private Scope appendScope(Scope newScope) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
799 |
List<Scope> existingScopes = this.subScopes.reverse(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
800 |
subScopes = List.of(existingScopes.head); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
801 |
subScopes = subScopes.prepend(newScope); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
802 |
for (Scope s : existingScopes.tail) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
803 |
subScopes = subScopes.prepend(s); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
804 |
} |
27857 | 805 |
return newScope; |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18899
diff
changeset
|
806 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18899
diff
changeset
|
807 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
808 |
private static class SingleEntryScope extends Scope { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
809 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
810 |
private final Symbol sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
811 |
private final List<Symbol> content; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
812 |
private final Scope origin; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
813 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
814 |
public SingleEntryScope(Symbol owner, Symbol sym, Scope origin) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
815 |
super(owner); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
816 |
this.sym = sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
817 |
this.content = List.of(sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
818 |
this.origin = origin; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
819 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
820 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
821 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
822 |
public Iterable<Symbol> getSymbols(Filter<Symbol> sf, LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
823 |
return sf == null || sf.accepts(sym) ? content : Collections.<Symbol>emptyList(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
824 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
825 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
826 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
827 |
public Iterable<Symbol> getSymbolsByName(Name name, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
828 |
Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
829 |
LookupKind lookupKind) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
830 |
return sym.name == name && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
831 |
(sf == null || sf.accepts(sym)) ? content : Collections.<Symbol>emptyList(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
832 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
833 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
834 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
835 |
public Scope getOrigin(Symbol byName) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
836 |
return sym == byName ? origin : null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
837 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
838 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
839 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
840 |
public boolean isStaticallyImported(Symbol byName) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
841 |
return false; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
842 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
843 |
|
10 | 844 |
} |
845 |
} |
|
846 |
||
27857 | 847 |
public static class StarImportScope extends ImportScope { |
7615 | 848 |
|
849 |
public StarImportScope(Symbol owner) { |
|
850 |
super(owner); |
|
851 |
} |
|
852 |
||
27857 | 853 |
public void importAll(Types types, Scope origin, |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
854 |
ImportFilter filter, |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
855 |
JCImport imp, |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
856 |
BiConsumer<JCImport, CompletionFailure> cfHandler) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
857 |
for (Scope existing : subScopes) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
858 |
Assert.check(existing instanceof FilterImportScope); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
859 |
FilterImportScope fis = (FilterImportScope) existing; |
27857 | 860 |
if (fis.origin == origin && fis.filter == filter && |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
861 |
fis.imp.staticImport == imp.staticImport) |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
862 |
return ; //avoid entering the same scope twice |
7615 | 863 |
} |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
864 |
prependSubScope(new FilterImportScope(types, origin, null, filter, imp, cfHandler)); |
10 | 865 |
} |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
866 |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
867 |
public boolean isFilled() { |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
868 |
return subScopes.nonEmpty(); |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
869 |
} |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
870 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
871 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
872 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
873 |
public interface ImportFilter { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
874 |
public boolean accepts(Scope origin, Symbol sym); |
10 | 875 |
} |
876 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
877 |
private static class FilterImportScope extends Scope { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
878 |
|
27857 | 879 |
private final Types types; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
880 |
private final Scope origin; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
881 |
private final Name filterName; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
882 |
private final ImportFilter filter; |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
883 |
private final JCImport imp; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
884 |
private final BiConsumer<JCImport, CompletionFailure> cfHandler; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
885 |
|
27857 | 886 |
public FilterImportScope(Types types, |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
887 |
Scope origin, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
888 |
Name filterName, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
889 |
ImportFilter filter, |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
890 |
JCImport imp, |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
891 |
BiConsumer<JCImport, CompletionFailure> cfHandler) { |
27857 | 892 |
super(origin.owner); |
893 |
this.types = types; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
894 |
this.origin = origin; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
895 |
this.filterName = filterName; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
896 |
this.filter = filter; |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
897 |
this.imp = imp; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
898 |
this.cfHandler = cfHandler; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
899 |
} |
10 | 900 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
901 |
@Override |
27857 | 902 |
public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, final LookupKind lookupKind) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
903 |
if (filterName != null) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
904 |
return getSymbolsByName(filterName, sf, lookupKind); |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
905 |
try { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
906 |
SymbolImporter si = new SymbolImporter(imp.staticImport) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
907 |
@Override |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
908 |
Iterable<Symbol> doLookup(TypeSymbol tsym) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
909 |
return tsym.members().getSymbols(sf, lookupKind); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
910 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
911 |
}; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
912 |
return si.importFrom((TypeSymbol) origin.owner) :: iterator; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
913 |
} catch (CompletionFailure cf) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
914 |
cfHandler.accept(imp, cf); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
915 |
return Collections.emptyList(); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
916 |
} |
10 | 917 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
918 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
919 |
@Override |
27857 | 920 |
public Iterable<Symbol> getSymbolsByName(final Name name, |
921 |
final Filter<Symbol> sf, |
|
922 |
final LookupKind lookupKind) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
923 |
if (filterName != null && filterName != name) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
924 |
return Collections.emptyList(); |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
925 |
try { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
926 |
SymbolImporter si = new SymbolImporter(imp.staticImport) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
927 |
@Override |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
928 |
Iterable<Symbol> doLookup(TypeSymbol tsym) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
929 |
return tsym.members().getSymbolsByName(name, sf, lookupKind); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
930 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
931 |
}; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
932 |
return si.importFrom((TypeSymbol) origin.owner) :: iterator; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
933 |
} catch (CompletionFailure cf) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
934 |
cfHandler.accept(imp, cf); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
935 |
return Collections.emptyList(); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
936 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
937 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
938 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
939 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
940 |
public Scope getOrigin(Symbol byName) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
941 |
return origin; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
942 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
943 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
944 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
945 |
public boolean isStaticallyImported(Symbol byName) { |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31506
diff
changeset
|
946 |
return imp.staticImport; |
10 | 947 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
948 |
|
27857 | 949 |
abstract class SymbolImporter { |
950 |
Set<Symbol> processed = new HashSet<>(); |
|
951 |
List<Iterable<Symbol>> delegates = List.nil(); |
|
952 |
final boolean inspectSuperTypes; |
|
953 |
public SymbolImporter(boolean inspectSuperTypes) { |
|
954 |
this.inspectSuperTypes = inspectSuperTypes; |
|
955 |
} |
|
956 |
Stream<Symbol> importFrom(TypeSymbol tsym) { |
|
957 |
if (tsym == null || !processed.add(tsym)) |
|
958 |
return Stream.empty(); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
959 |
|
27857 | 960 |
Stream<Symbol> result = Stream.empty(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
961 |
|
27857 | 962 |
if (inspectSuperTypes) { |
963 |
// also import inherited names |
|
964 |
result = importFrom(types.supertype(tsym.type).tsym); |
|
965 |
for (Type t : types.interfaces(tsym.type)) |
|
966 |
result = Stream.concat(importFrom(t.tsym), result); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
967 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
968 |
|
27857 | 969 |
return Stream.concat(StreamSupport.stream(doLookup(tsym).spliterator(), false) |
970 |
.filter(s -> filter.accepts(origin, s)), |
|
971 |
result); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
972 |
} |
27857 | 973 |
abstract Iterable<Symbol> doLookup(TypeSymbol tsym); |
10 | 974 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
975 |
|
10 | 976 |
} |
977 |
||
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
978 |
/** A class scope adds capabilities to keep track of changes in related |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
979 |
* class scopes - this allows client to realize whether a class scope |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
980 |
* has changed, either directly (because a new member has been added/removed |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
981 |
* to this scope) or indirectly (i.e. because a new member has been |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
982 |
* added/removed into a supertype scope) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
983 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
984 |
public static class CompoundScope extends Scope implements ScopeListener { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
985 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
986 |
List<Scope> subScopes = List.nil(); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
987 |
private int mark = 0; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
988 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
989 |
public CompoundScope(Symbol owner) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
990 |
super(owner); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
991 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
992 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
993 |
public void prependSubScope(Scope that) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
994 |
if (that != null) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
995 |
subScopes = subScopes.prepend(that); |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
996 |
that.listeners.add(this); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
997 |
mark++; |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
998 |
listeners.symbolAdded(null, this); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
999 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1000 |
} |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1001 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1002 |
public void symbolAdded(Symbol sym, Scope s) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1003 |
mark++; |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
1004 |
listeners.symbolAdded(sym, s); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1005 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1006 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1007 |
public void symbolRemoved(Symbol sym, Scope s) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1008 |
mark++; |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
32059
diff
changeset
|
1009 |
listeners.symbolRemoved(sym, s); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1010 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1011 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1012 |
public int getMark() { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1013 |
return mark; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1014 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1015 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1016 |
@Override |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1017 |
public String toString() { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1018 |
StringBuilder buf = new StringBuilder(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1019 |
buf.append("CompoundScope{"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1020 |
String sep = ""; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1021 |
for (Scope s : subScopes) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1022 |
buf.append(sep); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1023 |
buf.append(s); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1024 |
sep = ","; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1025 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1026 |
buf.append("}"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1027 |
return buf.toString(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1028 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1029 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1030 |
@Override |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1031 |
public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1032 |
final LookupKind lookupKind) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1033 |
return () -> Iterators.createCompoundIterator(subScopes, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1034 |
scope -> scope.getSymbols(sf, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1035 |
lookupKind) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1036 |
.iterator()); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1037 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1038 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1039 |
@Override |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1040 |
public Iterable<Symbol> getSymbolsByName(final Name name, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1041 |
final Filter<Symbol> sf, |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1042 |
final LookupKind lookupKind) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1043 |
return () -> Iterators.createCompoundIterator(subScopes, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1044 |
scope -> scope.getSymbolsByName(name, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1045 |
sf, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1046 |
lookupKind) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30999
diff
changeset
|
1047 |
.iterator()); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1048 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1049 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1050 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1051 |
public Scope getOrigin(Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1052 |
for (Scope delegate : subScopes) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1053 |
if (delegate.includes(sym)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1054 |
return delegate.getOrigin(sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1055 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1056 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1057 |
return null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1058 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1059 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1060 |
@Override |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1061 |
public boolean isStaticallyImported(Symbol sym) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1062 |
for (Scope delegate : subScopes) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1063 |
if (delegate.includes(sym)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1064 |
return delegate.isStaticallyImported(sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1065 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1066 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1067 |
return false; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1068 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1069 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1070 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
1071 |
|
10 | 1072 |
/** An error scope, for which the owner should be an error symbol. */ |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1073 |
public static class ErrorScope extends ScopeImpl { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1074 |
ErrorScope(ScopeImpl next, Symbol errSymbol, Entry[] table) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8032
diff
changeset
|
1075 |
super(next, /*owner=*/errSymbol, table); |
10 | 1076 |
} |
1077 |
public ErrorScope(Symbol errSymbol) { |
|
1078 |
super(errSymbol); |
|
1079 |
} |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1080 |
public WriteableScope dup(Symbol newOwner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1081 |
return new ErrorScope(this, newOwner, table); |
10 | 1082 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1083 |
public WriteableScope dupUnshared(Symbol newOwner) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
19492
diff
changeset
|
1084 |
return new ErrorScope(this, newOwner, table.clone()); |
10 | 1085 |
} |
1086 |
public Entry lookup(Name name) { |
|
1087 |
Entry e = super.lookup(name); |
|
1088 |
if (e.scope == null) |
|
1089 |
return new Entry(owner, null, null, null); |
|
1090 |
else |
|
1091 |
return e; |
|
1092 |
} |
|
1093 |
} |
|
1094 |
} |