author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 30730 | langtools/test/tools/javac/scope/7017664/CompoundScopeTest.java@d3ce7619db2c |
permissions | -rw-r--r-- |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25443
diff
changeset
|
2 |
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
4 |
* |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
8 |
* |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
14 |
* |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
18 |
* |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
23 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
24 |
/* |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
26 |
* @bug 7017664 7036906 |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Basher for CompoundScopes |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25443
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25443
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25443
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.util |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
31 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
32 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
33 |
import java.util.Random; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
34 |
import java.util.Map; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
35 |
import java.util.HashMap; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.util.*; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.*; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.code.Scope.*; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.*; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.file.JavacFileManager; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
41 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
42 |
public class CompoundScopeTest { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
43 |
public static void main(String... args) throws Exception { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
44 |
new CompoundScopeTest().run(args); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
45 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
46 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
47 |
static final int MAX_SYMBOLS_COUNT = 20; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
48 |
static final int PASSES = 10; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
49 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
50 |
void run(String... args) throws Exception { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
51 |
int count = PASSES; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
52 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
53 |
for (int i = 0; i < args.length; i++) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
54 |
String arg = args[i]; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
55 |
if (arg.equals("-seed") && (i + 1 < args.length)) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
56 |
seed = Long.parseLong(args[++i]); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
57 |
else if(arg.equals("-tests") && (i + 1 < args.length)) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
58 |
count = Integer.parseInt(args[++i]); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
59 |
else |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
60 |
throw new Exception("unknown arg: " + arg); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
61 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
62 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
63 |
rgen = new Random(seed); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
64 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
65 |
for (int i = 0; i < count; i++) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
66 |
Test t = new Test(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
67 |
t.run(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
68 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
69 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
70 |
if (errors > 0) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
71 |
throw new Exception(errors + " errors found"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
72 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
73 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
74 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
75 |
* Write a message to stderr. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
76 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
77 |
void log(String msg) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
78 |
System.err.println(msg); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
79 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
80 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
81 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
82 |
* Write an error message to stderr. |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
83 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
84 |
void error(String msg) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
85 |
System.err.println("Error: " + msg); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
86 |
errors++; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
87 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
88 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
89 |
Random rgen; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
90 |
long seed = 0; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
91 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
92 |
int errors; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
93 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
94 |
/** Class to encapsulate a test run. */ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
95 |
class Test { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
96 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
97 |
List<Symbol> elems = List.nil(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
98 |
Map<Name, List<Symbol>> shadowedMap = new HashMap<Name, List<Symbol>>(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
99 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
100 |
/** Run the test. */ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
101 |
void run() throws Exception { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
102 |
log ("starting test"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
103 |
setup(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
104 |
Scope[] scopes = { createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
105 |
createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
106 |
createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)) }; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
107 |
boolean[][] scopeNesting = { {false, true, false, true}, |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
108 |
{false, true, true, true}, |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
109 |
{false, false, true, true} }; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
110 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
111 |
* We want to generate (and check) the following compound scopes: |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
112 |
* C1 = C(S1, S2, S3) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
113 |
* C2 = C((S1, S2), S3) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
114 |
* C3 = C(S1, (S2, S3)) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
115 |
* C3 = C(C(S1, S2, S3)) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
116 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
117 |
for (int i = 0 ; i < 4 ; i ++) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
118 |
CompoundScope root = new CompoundScope(symtab.noSymbol); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
119 |
CompoundScope sub = new CompoundScope(symtab.noSymbol); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
120 |
boolean subAdded = false; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
121 |
for (int sc = 0 ; sc < 3 ; sc ++) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
122 |
if (scopeNesting[sc][i]) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
123 |
sub.prependSubScope(scopes[sc]); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
124 |
if (!subAdded) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
125 |
root.prependSubScope(sub); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
126 |
subAdded = true; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
127 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
128 |
} else { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
129 |
root.prependSubScope(scopes[sc]); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
130 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
131 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
132 |
log("testing scope: " + root); |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
133 |
checkElems(root, null); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
134 |
checkElems(root, new OddFilter()); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
135 |
checkShadowed(root, null); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
136 |
checkShadowed(root, new OddFilter()); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
137 |
} |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
138 |
} |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
139 |
|
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
140 |
class OddFilter implements Filter<Symbol> { |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
141 |
public boolean accepts(Symbol s) { |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
142 |
Name numPart = s.name.subName(1, s.name.length()); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
143 |
return Integer.parseInt(numPart.toString()) % 2 != 0; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
144 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
145 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
146 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
147 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
148 |
* Create a scope containing a given number of synthetic symbols |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
149 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
150 |
Scope createScope(int nelems) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
151 |
WriteableScope s = WriteableScope.create(symtab.noSymbol); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
152 |
for (int i = 0 ; i < nelems ; i++) { |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
9593
diff
changeset
|
153 |
Symbol sym = new TypeVariableSymbol(0, names.fromString("s" + i), null, null); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
154 |
s.enter(sym); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
155 |
elems = elems.prepend(sym); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
156 |
List<Symbol> shadowed = shadowedMap.get(sym.name); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
157 |
if (shadowed == null) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
158 |
shadowed = List.nil(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
159 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
160 |
shadowedMap.put(sym.name, shadowed.prepend(sym)); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
161 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
162 |
return s; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
163 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
164 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
165 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
166 |
* Setup compiler context |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
167 |
*/ |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
168 |
void setup() { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
169 |
log ("setup"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
170 |
context = new Context(); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
171 |
JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
172 |
names = Names.instance(context); // Name.Table impls tied to an instance of Names |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
173 |
symtab = Symtab.instance(context); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
174 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
175 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
176 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
177 |
* Check that CompoundScope.getElements() correctly visits all symbols |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
178 |
* in all subscopes (in the correct order) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
179 |
*/ |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
180 |
void checkElems(CompoundScope cs, Filter<Symbol> sf) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
181 |
int count = 0; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
16967
diff
changeset
|
182 |
ListBuffer<Symbol> found = new ListBuffer<>(); |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
183 |
List<Symbol> allSymbols = sf == null ? |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
184 |
elems : |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
185 |
filter(elems, sf); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
186 |
int expectedCount = allSymbols.length(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
187 |
for (Symbol s : sf == null ? cs.getSymbols() : cs.getSymbols(sf)) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
188 |
checkSameSymbols(s, allSymbols.head); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
189 |
allSymbols = allSymbols.tail; |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
190 |
found.append(s); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
191 |
count++; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
192 |
} |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
193 |
if (count != expectedCount) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
194 |
error("CompoundScope.getElements() did not returned enough symbols"); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
195 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
196 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
197 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
198 |
/** |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
199 |
* Check that CompoundScope.getElements() correctly visits all symbols |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
200 |
* with a given name in all subscopes (in the correct order) |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
201 |
*/ |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
202 |
void checkShadowed(CompoundScope cs, Filter<Symbol> sf) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
203 |
for (Map.Entry<Name, List<Symbol>> shadowedEntry : shadowedMap.entrySet()) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
204 |
int count = 0; |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
205 |
List<Symbol> shadowed = sf == null ? |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
206 |
shadowedEntry.getValue() : |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
207 |
filter(shadowedEntry.getValue(), sf); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
208 |
int expectedCount = shadowed.length(); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
209 |
Name name = shadowedEntry.getKey(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
20249
diff
changeset
|
210 |
for (Symbol s : sf == null ? cs.getSymbolsByName(name) : cs.getSymbolsByName(name, sf)) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
211 |
checkSameSymbols(s, shadowed.head); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
212 |
shadowed = shadowed.tail; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
213 |
count++; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
214 |
} |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
215 |
if (count != expectedCount) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
216 |
error("CompoundScope.lookup() did not returned enough symbols for name " + name); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
217 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
218 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
219 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
220 |
|
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
221 |
List<Symbol> filter(List<Symbol> elems, Filter<Symbol> sf) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
16967
diff
changeset
|
222 |
ListBuffer<Symbol> res = new ListBuffer<>(); |
9593
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
223 |
for (Symbol s : elems) { |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
224 |
if (sf.accepts(s)) { |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
225 |
res.append(s); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
226 |
} |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
227 |
} |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
228 |
return res.toList(); |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
229 |
} |
f917c044e651
7036906: Scope: CompoundScope.getElements() doesn't pass scope filter to subscopes
mcimadamore
parents:
8427
diff
changeset
|
230 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
231 |
void checkSameSymbols(Symbol found, Symbol req) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
232 |
if (found != req) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
233 |
error("Symbol mismatch - found : " + found + ":" + found.hashCode() + "\n" + |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
234 |
" required : " + req + ":" + req.hashCode()); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
235 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
236 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
237 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
238 |
Context context; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
239 |
Symtab symtab; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
240 |
Names names; |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
241 |
} |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
diff
changeset
|
242 |
} |