author | jlahoda |
Wed, 27 Nov 2019 09:00:01 +0100 | |
changeset 59285 | 7799a51dbe30 |
parent 55306 | ea43db53de91 |
permissions | -rw-r--r-- |
49429 | 1 |
/* |
2 |
* Copyright (c) 2018, Google LLC. All rights reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
28 |
import com.sun.tools.javac.code.Symbol; |
|
29 |
import com.sun.tools.javac.tree.JCTree; |
|
30 |
import com.sun.tools.javac.tree.JCTree.JCAnnotatedType; |
|
31 |
import com.sun.tools.javac.tree.JCTree.JCAnnotation; |
|
32 |
import com.sun.tools.javac.tree.JCTree.JCArrayAccess; |
|
33 |
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree; |
|
34 |
import com.sun.tools.javac.tree.JCTree.JCAssert; |
|
35 |
import com.sun.tools.javac.tree.JCTree.JCAssign; |
|
36 |
import com.sun.tools.javac.tree.JCTree.JCAssignOp; |
|
37 |
import com.sun.tools.javac.tree.JCTree.JCBinary; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
38 |
import com.sun.tools.javac.tree.JCTree.JCBindingPattern; |
49429 | 39 |
import com.sun.tools.javac.tree.JCTree.JCBlock; |
40 |
import com.sun.tools.javac.tree.JCTree.JCBreak; |
|
41 |
import com.sun.tools.javac.tree.JCTree.JCCase; |
|
42 |
import com.sun.tools.javac.tree.JCTree.JCCatch; |
|
43 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
|
44 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
|
45 |
import com.sun.tools.javac.tree.JCTree.JCConditional; |
|
46 |
import com.sun.tools.javac.tree.JCTree.JCContinue; |
|
47 |
import com.sun.tools.javac.tree.JCTree.JCDoWhileLoop; |
|
48 |
import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop; |
|
49 |
import com.sun.tools.javac.tree.JCTree.JCErroneous; |
|
50 |
import com.sun.tools.javac.tree.JCTree.JCExports; |
|
51 |
import com.sun.tools.javac.tree.JCTree.JCExpressionStatement; |
|
52 |
import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
|
53 |
import com.sun.tools.javac.tree.JCTree.JCForLoop; |
|
54 |
import com.sun.tools.javac.tree.JCTree.JCIdent; |
|
55 |
import com.sun.tools.javac.tree.JCTree.JCIf; |
|
56 |
import com.sun.tools.javac.tree.JCTree.JCImport; |
|
57 |
import com.sun.tools.javac.tree.JCTree.JCInstanceOf; |
|
58 |
import com.sun.tools.javac.tree.JCTree.JCLabeledStatement; |
|
59 |
import com.sun.tools.javac.tree.JCTree.JCLambda; |
|
60 |
import com.sun.tools.javac.tree.JCTree.JCLiteral; |
|
61 |
import com.sun.tools.javac.tree.JCTree.JCMemberReference; |
|
62 |
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
|
63 |
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; |
|
64 |
import com.sun.tools.javac.tree.JCTree.JCModifiers; |
|
65 |
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; |
|
66 |
import com.sun.tools.javac.tree.JCTree.JCNewArray; |
|
67 |
import com.sun.tools.javac.tree.JCTree.JCNewClass; |
|
68 |
import com.sun.tools.javac.tree.JCTree.JCOpens; |
|
69 |
import com.sun.tools.javac.tree.JCTree.JCPackageDecl; |
|
70 |
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; |
|
71 |
import com.sun.tools.javac.tree.JCTree.JCProvides; |
|
72 |
import com.sun.tools.javac.tree.JCTree.JCRequires; |
|
73 |
import com.sun.tools.javac.tree.JCTree.JCReturn; |
|
74 |
import com.sun.tools.javac.tree.JCTree.JCSwitch; |
|
55306 | 75 |
import com.sun.tools.javac.tree.JCTree.JCSwitchExpression; |
49429 | 76 |
import com.sun.tools.javac.tree.JCTree.JCSynchronized; |
77 |
import com.sun.tools.javac.tree.JCTree.JCThrow; |
|
78 |
import com.sun.tools.javac.tree.JCTree.JCTry; |
|
79 |
import com.sun.tools.javac.tree.JCTree.JCTypeApply; |
|
80 |
import com.sun.tools.javac.tree.JCTree.JCTypeCast; |
|
81 |
import com.sun.tools.javac.tree.JCTree.JCTypeIntersection; |
|
82 |
import com.sun.tools.javac.tree.JCTree.JCTypeParameter; |
|
83 |
import com.sun.tools.javac.tree.JCTree.JCTypeUnion; |
|
84 |
import com.sun.tools.javac.tree.JCTree.JCUnary; |
|
85 |
import com.sun.tools.javac.tree.JCTree.JCUses; |
|
86 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
|
87 |
import com.sun.tools.javac.tree.JCTree.JCWhileLoop; |
|
88 |
import com.sun.tools.javac.tree.JCTree.JCWildcard; |
|
55306 | 89 |
import com.sun.tools.javac.tree.JCTree.JCYield; |
49429 | 90 |
import com.sun.tools.javac.tree.JCTree.LetExpr; |
91 |
import com.sun.tools.javac.tree.JCTree.TypeBoundKind; |
|
92 |
import com.sun.tools.javac.tree.TreeInfo; |
|
93 |
import com.sun.tools.javac.tree.TreeScanner; |
|
94 |
import com.sun.tools.javac.util.List; |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
95 |
import java.util.Collection; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
96 |
import java.util.HashMap; |
49429 | 97 |
import java.util.Iterator; |
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
98 |
import java.util.Map; |
49429 | 99 |
import java.util.Objects; |
100 |
||
101 |
/** A visitor that compares two lambda bodies for structural equality. */ |
|
102 |
public class TreeDiffer extends TreeScanner { |
|
103 |
||
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
104 |
public TreeDiffer( |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
105 |
Collection<? extends Symbol> symbols, Collection<? extends Symbol> otherSymbols) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
106 |
this.equiv = equiv(symbols, otherSymbols); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
107 |
} |
49429 | 108 |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
109 |
private static Map<Symbol, Symbol> equiv( |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
110 |
Collection<? extends Symbol> symbols, Collection<? extends Symbol> otherSymbols) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
111 |
Map<Symbol, Symbol> result = new HashMap<>(); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
112 |
Iterator<? extends Symbol> it = otherSymbols.iterator(); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
113 |
for (Symbol symbol : symbols) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
114 |
if (!it.hasNext()) break; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
115 |
result.put(symbol, it.next()); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
116 |
} |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
117 |
return result; |
49429 | 118 |
} |
119 |
||
120 |
private JCTree parameter; |
|
121 |
private boolean result; |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
122 |
private Map<Symbol, Symbol> equiv = new HashMap<>(); |
49429 | 123 |
|
124 |
public boolean scan(JCTree tree, JCTree parameter) { |
|
125 |
if (tree == null || parameter == null) { |
|
126 |
return tree == null && parameter == null; |
|
127 |
} |
|
128 |
tree = TreeInfo.skipParens(tree); |
|
129 |
parameter = TreeInfo.skipParens(parameter); |
|
130 |
if (tree.type != null |
|
131 |
&& tree.type.constValue() != null |
|
132 |
&& parameter.type != null |
|
133 |
&& parameter.type.constValue() != null) { |
|
134 |
return Objects.equals(tree.type.constValue(), parameter.type.constValue()); |
|
135 |
} |
|
136 |
if (tree.getTag() != parameter.getTag()) { |
|
137 |
return false; |
|
138 |
} |
|
139 |
JCTree prevParameter = this.parameter; |
|
140 |
boolean prevResult = this.result; |
|
141 |
try { |
|
142 |
this.parameter = parameter; |
|
143 |
tree.accept(this); |
|
144 |
return result; |
|
145 |
} finally { |
|
146 |
this.parameter = prevParameter; |
|
147 |
this.result = prevResult; |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
private boolean scan(Iterable<? extends JCTree> xs, Iterable<? extends JCTree> ys) { |
|
152 |
if (xs == null || ys == null) { |
|
153 |
return xs == null && ys == null; |
|
154 |
} |
|
155 |
Iterator<? extends JCTree> x = xs.iterator(); |
|
156 |
Iterator<? extends JCTree> y = ys.iterator(); |
|
157 |
while (x.hasNext() && y.hasNext()) { |
|
158 |
if (!scan(x.next(), y.next())) { |
|
159 |
return false; |
|
160 |
} |
|
161 |
} |
|
162 |
return !x.hasNext() && !y.hasNext(); |
|
163 |
} |
|
164 |
||
165 |
private boolean scanDimAnnotations(List<List<JCAnnotation>> xs, List<List<JCAnnotation>> ys) { |
|
166 |
if (xs == null || ys == null) { |
|
167 |
return xs == null && ys == null; |
|
168 |
} |
|
169 |
Iterator<List<JCAnnotation>> x = xs.iterator(); |
|
170 |
Iterator<List<JCAnnotation>> y = ys.iterator(); |
|
171 |
while (x.hasNext() && y.hasNext()) { |
|
172 |
if (!scan(x.next(), y.next())) { |
|
173 |
return false; |
|
174 |
} |
|
175 |
} |
|
176 |
return !x.hasNext() && !y.hasNext(); |
|
177 |
} |
|
178 |
||
179 |
@Override |
|
180 |
public void visitIdent(JCIdent tree) { |
|
181 |
JCIdent that = (JCIdent) parameter; |
|
182 |
// Identifiers are a special case: we want to ensure the identifiers correspond to the |
|
183 |
// same symbols (rather than just having the same name), but also consider lambdas |
|
184 |
// equal if they differ only in the names of the parameters. |
|
185 |
Symbol symbol = tree.sym; |
|
186 |
Symbol otherSymbol = that.sym; |
|
187 |
if (symbol != null && otherSymbol != null) { |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
188 |
if (Objects.equals(equiv.get(symbol), otherSymbol)) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
189 |
result = true; |
49429 | 190 |
return; |
191 |
} |
|
192 |
} |
|
193 |
result = tree.sym == that.sym; |
|
194 |
} |
|
195 |
||
196 |
@Override |
|
197 |
public void visitSelect(JCFieldAccess tree) { |
|
198 |
JCFieldAccess that = (JCFieldAccess) parameter; |
|
199 |
result = scan(tree.selected, that.selected) && tree.sym == that.sym; |
|
200 |
} |
|
201 |
||
202 |
@Override |
|
203 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
|
204 |
JCAnnotatedType that = (JCAnnotatedType) parameter; |
|
205 |
result = |
|
206 |
scan(tree.annotations, that.annotations) |
|
207 |
&& scan(tree.underlyingType, that.underlyingType); |
|
208 |
} |
|
209 |
||
210 |
@Override |
|
211 |
public void visitAnnotation(JCAnnotation tree) { |
|
212 |
JCAnnotation that = (JCAnnotation) parameter; |
|
213 |
result = scan(tree.annotationType, that.annotationType) && scan(tree.args, that.args); |
|
214 |
} |
|
215 |
||
216 |
@Override |
|
217 |
public void visitApply(JCMethodInvocation tree) { |
|
218 |
JCMethodInvocation that = (JCMethodInvocation) parameter; |
|
219 |
result = |
|
220 |
scan(tree.typeargs, that.typeargs) |
|
221 |
&& scan(tree.meth, that.meth) |
|
222 |
&& scan(tree.args, that.args) |
|
223 |
&& tree.polyKind == that.polyKind; |
|
224 |
} |
|
225 |
||
226 |
@Override |
|
227 |
public void visitAssert(JCAssert tree) { |
|
228 |
JCAssert that = (JCAssert) parameter; |
|
229 |
result = scan(tree.cond, that.cond) && scan(tree.detail, that.detail); |
|
230 |
} |
|
231 |
||
232 |
@Override |
|
233 |
public void visitAssign(JCAssign tree) { |
|
234 |
JCAssign that = (JCAssign) parameter; |
|
235 |
result = scan(tree.lhs, that.lhs) && scan(tree.rhs, that.rhs); |
|
236 |
} |
|
237 |
||
238 |
@Override |
|
239 |
public void visitAssignop(JCAssignOp tree) { |
|
240 |
JCAssignOp that = (JCAssignOp) parameter; |
|
241 |
result = |
|
242 |
scan(tree.lhs, that.lhs) |
|
243 |
&& scan(tree.rhs, that.rhs) |
|
244 |
&& tree.operator == that.operator; |
|
245 |
} |
|
246 |
||
247 |
@Override |
|
248 |
public void visitBinary(JCBinary tree) { |
|
249 |
JCBinary that = (JCBinary) parameter; |
|
250 |
result = |
|
251 |
scan(tree.lhs, that.lhs) |
|
252 |
&& scan(tree.rhs, that.rhs) |
|
253 |
&& tree.operator == that.operator; |
|
254 |
} |
|
255 |
||
256 |
@Override |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
257 |
public void visitBindingPattern(JCBindingPattern tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
258 |
JCBindingPattern that = (JCBindingPattern) parameter; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
259 |
result = |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
260 |
scan(tree.vartype, that.vartype) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
261 |
&& tree.name == that.name; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
262 |
if (!result) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
263 |
return; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
264 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
265 |
equiv.put(tree.symbol, that.symbol); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
266 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
267 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
268 |
@Override |
49429 | 269 |
public void visitBlock(JCBlock tree) { |
270 |
JCBlock that = (JCBlock) parameter; |
|
271 |
result = tree.flags == that.flags && scan(tree.stats, that.stats); |
|
272 |
} |
|
273 |
||
274 |
@Override |
|
275 |
public void visitBreak(JCBreak tree) { |
|
276 |
JCBreak that = (JCBreak) parameter; |
|
55306 | 277 |
result = tree.label == that.label; |
278 |
} |
|
279 |
||
280 |
@Override |
|
281 |
public void visitYield(JCYield tree) { |
|
282 |
JCYield that = (JCYield) parameter; |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
49541
diff
changeset
|
283 |
result = scan(tree.value, that.value); |
49429 | 284 |
} |
285 |
||
286 |
@Override |
|
287 |
public void visitCase(JCCase tree) { |
|
288 |
JCCase that = (JCCase) parameter; |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
49541
diff
changeset
|
289 |
result = scan(tree.pats, that.pats) && scan(tree.stats, that.stats); |
49429 | 290 |
} |
291 |
||
292 |
@Override |
|
293 |
public void visitCatch(JCCatch tree) { |
|
294 |
JCCatch that = (JCCatch) parameter; |
|
295 |
result = scan(tree.param, that.param) && scan(tree.body, that.body); |
|
296 |
} |
|
297 |
||
298 |
@Override |
|
299 |
public void visitClassDef(JCClassDecl tree) { |
|
300 |
JCClassDecl that = (JCClassDecl) parameter; |
|
301 |
result = |
|
302 |
scan(tree.mods, that.mods) |
|
303 |
&& tree.name == that.name |
|
304 |
&& scan(tree.typarams, that.typarams) |
|
305 |
&& scan(tree.extending, that.extending) |
|
306 |
&& scan(tree.implementing, that.implementing) |
|
307 |
&& scan(tree.defs, that.defs); |
|
308 |
} |
|
309 |
||
310 |
@Override |
|
311 |
public void visitConditional(JCConditional tree) { |
|
312 |
JCConditional that = (JCConditional) parameter; |
|
313 |
result = |
|
314 |
scan(tree.cond, that.cond) |
|
315 |
&& scan(tree.truepart, that.truepart) |
|
316 |
&& scan(tree.falsepart, that.falsepart); |
|
317 |
} |
|
318 |
||
319 |
@Override |
|
320 |
public void visitContinue(JCContinue tree) { |
|
321 |
JCContinue that = (JCContinue) parameter; |
|
322 |
result = tree.label == that.label; |
|
323 |
} |
|
324 |
||
325 |
@Override |
|
326 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
327 |
JCDoWhileLoop that = (JCDoWhileLoop) parameter; |
|
328 |
result = scan(tree.body, that.body) && scan(tree.cond, that.cond); |
|
329 |
} |
|
330 |
||
331 |
@Override |
|
332 |
public void visitErroneous(JCErroneous tree) { |
|
333 |
JCErroneous that = (JCErroneous) parameter; |
|
334 |
result = scan(tree.errs, that.errs); |
|
335 |
} |
|
336 |
||
337 |
@Override |
|
338 |
public void visitExec(JCExpressionStatement tree) { |
|
339 |
JCExpressionStatement that = (JCExpressionStatement) parameter; |
|
340 |
result = scan(tree.expr, that.expr); |
|
341 |
} |
|
342 |
||
343 |
@Override |
|
344 |
public void visitExports(JCExports tree) { |
|
345 |
JCExports that = (JCExports) parameter; |
|
346 |
result = scan(tree.qualid, that.qualid) && scan(tree.moduleNames, that.moduleNames); |
|
347 |
} |
|
348 |
||
349 |
@Override |
|
350 |
public void visitForLoop(JCForLoop tree) { |
|
351 |
JCForLoop that = (JCForLoop) parameter; |
|
352 |
result = |
|
353 |
scan(tree.init, that.init) |
|
354 |
&& scan(tree.cond, that.cond) |
|
355 |
&& scan(tree.step, that.step) |
|
356 |
&& scan(tree.body, that.body); |
|
357 |
} |
|
358 |
||
359 |
@Override |
|
360 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
361 |
JCEnhancedForLoop that = (JCEnhancedForLoop) parameter; |
|
362 |
result = |
|
363 |
scan(tree.var, that.var) |
|
364 |
&& scan(tree.expr, that.expr) |
|
365 |
&& scan(tree.body, that.body); |
|
366 |
} |
|
367 |
||
368 |
@Override |
|
369 |
public void visitIf(JCIf tree) { |
|
370 |
JCIf that = (JCIf) parameter; |
|
371 |
result = |
|
372 |
scan(tree.cond, that.cond) |
|
373 |
&& scan(tree.thenpart, that.thenpart) |
|
374 |
&& scan(tree.elsepart, that.elsepart); |
|
375 |
} |
|
376 |
||
377 |
@Override |
|
378 |
public void visitImport(JCImport tree) { |
|
379 |
JCImport that = (JCImport) parameter; |
|
380 |
result = tree.staticImport == that.staticImport && scan(tree.qualid, that.qualid); |
|
381 |
} |
|
382 |
||
383 |
@Override |
|
384 |
public void visitIndexed(JCArrayAccess tree) { |
|
385 |
JCArrayAccess that = (JCArrayAccess) parameter; |
|
386 |
result = scan(tree.indexed, that.indexed) && scan(tree.index, that.index); |
|
387 |
} |
|
388 |
||
389 |
@Override |
|
390 |
public void visitLabelled(JCLabeledStatement tree) { |
|
391 |
JCLabeledStatement that = (JCLabeledStatement) parameter; |
|
392 |
result = tree.label == that.label && scan(tree.body, that.body); |
|
393 |
} |
|
394 |
||
395 |
@Override |
|
396 |
public void visitLambda(JCLambda tree) { |
|
397 |
JCLambda that = (JCLambda) parameter; |
|
398 |
result = |
|
399 |
scan(tree.params, that.params) |
|
400 |
&& scan(tree.body, that.body) |
|
401 |
&& tree.paramKind == that.paramKind; |
|
402 |
} |
|
403 |
||
404 |
@Override |
|
405 |
public void visitLetExpr(LetExpr tree) { |
|
406 |
LetExpr that = (LetExpr) parameter; |
|
407 |
result = scan(tree.defs, that.defs) && scan(tree.expr, that.expr); |
|
408 |
} |
|
409 |
||
410 |
@Override |
|
411 |
public void visitLiteral(JCLiteral tree) { |
|
412 |
JCLiteral that = (JCLiteral) parameter; |
|
413 |
result = tree.typetag == that.typetag && Objects.equals(tree.value, that.value); |
|
414 |
} |
|
415 |
||
416 |
@Override |
|
417 |
public void visitMethodDef(JCMethodDecl tree) { |
|
418 |
JCMethodDecl that = (JCMethodDecl) parameter; |
|
419 |
result = |
|
420 |
scan(tree.mods, that.mods) |
|
421 |
&& tree.name == that.name |
|
422 |
&& scan(tree.restype, that.restype) |
|
423 |
&& scan(tree.typarams, that.typarams) |
|
424 |
&& scan(tree.recvparam, that.recvparam) |
|
425 |
&& scan(tree.params, that.params) |
|
426 |
&& scan(tree.thrown, that.thrown) |
|
427 |
&& scan(tree.body, that.body) |
|
428 |
&& scan(tree.defaultValue, that.defaultValue); |
|
429 |
} |
|
430 |
||
431 |
@Override |
|
432 |
public void visitModifiers(JCModifiers tree) { |
|
433 |
JCModifiers that = (JCModifiers) parameter; |
|
434 |
result = tree.flags == that.flags && scan(tree.annotations, that.annotations); |
|
435 |
} |
|
436 |
||
437 |
@Override |
|
438 |
public void visitModuleDef(JCModuleDecl tree) { |
|
439 |
JCModuleDecl that = (JCModuleDecl) parameter; |
|
440 |
result = |
|
441 |
scan(tree.mods, that.mods) |
|
442 |
&& scan(tree.qualId, that.qualId) |
|
443 |
&& scan(tree.directives, that.directives); |
|
444 |
} |
|
445 |
||
446 |
@Override |
|
447 |
public void visitNewArray(JCNewArray tree) { |
|
448 |
JCNewArray that = (JCNewArray) parameter; |
|
449 |
result = |
|
450 |
scan(tree.elemtype, that.elemtype) |
|
451 |
&& scan(tree.dims, that.dims) |
|
452 |
&& scan(tree.annotations, that.annotations) |
|
453 |
&& scanDimAnnotations(tree.dimAnnotations, that.dimAnnotations) |
|
454 |
&& scan(tree.elems, that.elems); |
|
455 |
} |
|
456 |
||
457 |
@Override |
|
458 |
public void visitNewClass(JCNewClass tree) { |
|
459 |
JCNewClass that = (JCNewClass) parameter; |
|
460 |
result = |
|
461 |
scan(tree.encl, that.encl) |
|
462 |
&& scan(tree.typeargs, that.typeargs) |
|
463 |
&& scan(tree.clazz, that.clazz) |
|
464 |
&& scan(tree.args, that.args) |
|
465 |
&& scan(tree.def, that.def) |
|
466 |
&& tree.constructor == that.constructor; |
|
467 |
} |
|
468 |
||
469 |
@Override |
|
470 |
public void visitOpens(JCOpens tree) { |
|
471 |
JCOpens that = (JCOpens) parameter; |
|
472 |
result = scan(tree.qualid, that.qualid) && scan(tree.moduleNames, that.moduleNames); |
|
473 |
} |
|
474 |
||
475 |
@Override |
|
476 |
public void visitPackageDef(JCPackageDecl tree) { |
|
477 |
JCPackageDecl that = (JCPackageDecl) parameter; |
|
478 |
result = |
|
479 |
scan(tree.annotations, that.annotations) |
|
480 |
&& scan(tree.pid, that.pid) |
|
481 |
&& tree.packge == that.packge; |
|
482 |
} |
|
483 |
||
484 |
@Override |
|
485 |
public void visitProvides(JCProvides tree) { |
|
486 |
JCProvides that = (JCProvides) parameter; |
|
487 |
result = scan(tree.serviceName, that.serviceName) && scan(tree.implNames, that.implNames); |
|
488 |
} |
|
489 |
||
490 |
@Override |
|
491 |
public void visitReference(JCMemberReference tree) { |
|
492 |
JCMemberReference that = (JCMemberReference) parameter; |
|
493 |
result = |
|
494 |
tree.mode == that.mode |
|
495 |
&& tree.kind == that.kind |
|
496 |
&& tree.name == that.name |
|
497 |
&& scan(tree.expr, that.expr) |
|
498 |
&& scan(tree.typeargs, that.typeargs); |
|
499 |
} |
|
500 |
||
501 |
@Override |
|
502 |
public void visitRequires(JCRequires tree) { |
|
503 |
JCRequires that = (JCRequires) parameter; |
|
504 |
result = |
|
505 |
tree.isTransitive == that.isTransitive |
|
506 |
&& tree.isStaticPhase == that.isStaticPhase |
|
507 |
&& scan(tree.moduleName, that.moduleName); |
|
508 |
} |
|
509 |
||
510 |
@Override |
|
511 |
public void visitReturn(JCReturn tree) { |
|
512 |
JCReturn that = (JCReturn) parameter; |
|
513 |
result = scan(tree.expr, that.expr); |
|
514 |
} |
|
515 |
||
516 |
@Override |
|
517 |
public void visitSwitch(JCSwitch tree) { |
|
518 |
JCSwitch that = (JCSwitch) parameter; |
|
519 |
result = scan(tree.selector, that.selector) && scan(tree.cases, that.cases); |
|
520 |
} |
|
521 |
||
522 |
@Override |
|
55306 | 523 |
public void visitSwitchExpression(JCSwitchExpression tree) { |
524 |
JCSwitchExpression that = (JCSwitchExpression) parameter; |
|
525 |
result = scan(tree.selector, that.selector) && scan(tree.cases, that.cases); |
|
526 |
} |
|
527 |
||
528 |
@Override |
|
49429 | 529 |
public void visitSynchronized(JCSynchronized tree) { |
530 |
JCSynchronized that = (JCSynchronized) parameter; |
|
531 |
result = scan(tree.lock, that.lock) && scan(tree.body, that.body); |
|
532 |
} |
|
533 |
||
534 |
@Override |
|
535 |
public void visitThrow(JCThrow tree) { |
|
536 |
JCThrow that = (JCThrow) parameter; |
|
537 |
result = scan(tree.expr, that.expr); |
|
538 |
} |
|
539 |
||
540 |
@Override |
|
541 |
public void visitTopLevel(JCCompilationUnit tree) { |
|
542 |
JCCompilationUnit that = (JCCompilationUnit) parameter; |
|
543 |
result = |
|
544 |
scan(tree.defs, that.defs) |
|
545 |
&& tree.modle == that.modle |
|
546 |
&& tree.packge == that.packge; |
|
547 |
} |
|
548 |
||
549 |
@Override |
|
550 |
public void visitTry(JCTry tree) { |
|
551 |
JCTry that = (JCTry) parameter; |
|
552 |
result = |
|
553 |
scan(tree.body, that.body) |
|
554 |
&& scan(tree.catchers, that.catchers) |
|
555 |
&& scan(tree.finalizer, that.finalizer) |
|
556 |
&& scan(tree.resources, that.resources); |
|
557 |
} |
|
558 |
||
559 |
@Override |
|
560 |
public void visitTypeApply(JCTypeApply tree) { |
|
561 |
JCTypeApply that = (JCTypeApply) parameter; |
|
562 |
result = scan(tree.clazz, that.clazz) && scan(tree.arguments, that.arguments); |
|
563 |
} |
|
564 |
||
565 |
@Override |
|
566 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
567 |
JCArrayTypeTree that = (JCArrayTypeTree) parameter; |
|
568 |
result = scan(tree.elemtype, that.elemtype); |
|
569 |
} |
|
570 |
||
571 |
@Override |
|
572 |
public void visitTypeBoundKind(TypeBoundKind tree) { |
|
573 |
TypeBoundKind that = (TypeBoundKind) parameter; |
|
574 |
result = tree.kind == that.kind; |
|
575 |
} |
|
576 |
||
577 |
@Override |
|
578 |
public void visitTypeCast(JCTypeCast tree) { |
|
579 |
JCTypeCast that = (JCTypeCast) parameter; |
|
580 |
result = scan(tree.clazz, that.clazz) && scan(tree.expr, that.expr); |
|
581 |
} |
|
582 |
||
583 |
@Override |
|
584 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
585 |
JCPrimitiveTypeTree that = (JCPrimitiveTypeTree) parameter; |
|
586 |
result = tree.typetag == that.typetag; |
|
587 |
} |
|
588 |
||
589 |
@Override |
|
590 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
|
591 |
JCTypeIntersection that = (JCTypeIntersection) parameter; |
|
592 |
result = scan(tree.bounds, that.bounds); |
|
593 |
} |
|
594 |
||
595 |
@Override |
|
596 |
public void visitTypeParameter(JCTypeParameter tree) { |
|
597 |
JCTypeParameter that = (JCTypeParameter) parameter; |
|
598 |
result = |
|
599 |
tree.name == that.name |
|
600 |
&& scan(tree.bounds, that.bounds) |
|
601 |
&& scan(tree.annotations, that.annotations); |
|
602 |
} |
|
603 |
||
604 |
@Override |
|
605 |
public void visitTypeTest(JCInstanceOf tree) { |
|
606 |
JCInstanceOf that = (JCInstanceOf) parameter; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
607 |
result = scan(tree.expr, that.expr) && scan(tree.pattern, that.pattern); |
49429 | 608 |
} |
609 |
||
610 |
@Override |
|
611 |
public void visitTypeUnion(JCTypeUnion tree) { |
|
612 |
JCTypeUnion that = (JCTypeUnion) parameter; |
|
613 |
result = scan(tree.alternatives, that.alternatives); |
|
614 |
} |
|
615 |
||
616 |
@Override |
|
617 |
public void visitUnary(JCUnary tree) { |
|
618 |
JCUnary that = (JCUnary) parameter; |
|
619 |
result = scan(tree.arg, that.arg) && tree.operator == that.operator; |
|
620 |
} |
|
621 |
||
622 |
@Override |
|
623 |
public void visitUses(JCUses tree) { |
|
624 |
JCUses that = (JCUses) parameter; |
|
625 |
result = scan(tree.qualid, that.qualid); |
|
626 |
} |
|
627 |
||
628 |
@Override |
|
629 |
public void visitVarDef(JCVariableDecl tree) { |
|
630 |
JCVariableDecl that = (JCVariableDecl) parameter; |
|
631 |
result = |
|
632 |
scan(tree.mods, that.mods) |
|
633 |
&& tree.name == that.name |
|
634 |
&& scan(tree.nameexpr, that.nameexpr) |
|
635 |
&& scan(tree.vartype, that.vartype) |
|
636 |
&& scan(tree.init, that.init); |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
637 |
if (!result) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
638 |
return; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
639 |
} |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
640 |
equiv.put(tree.sym, that.sym); |
49429 | 641 |
} |
642 |
||
643 |
@Override |
|
644 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
645 |
JCWhileLoop that = (JCWhileLoop) parameter; |
|
646 |
result = scan(tree.cond, that.cond) && scan(tree.body, that.body); |
|
647 |
} |
|
648 |
||
649 |
@Override |
|
650 |
public void visitWildcard(JCWildcard tree) { |
|
651 |
JCWildcard that = (JCWildcard) parameter; |
|
652 |
result = scan(tree.kind, that.kind) && scan(tree.inner, that.inner); |
|
653 |
} |
|
654 |
} |