1 /*
  2  * Copyright (c) 2006, 2019, Oracle and/or its affiliates. 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.tree;
 27 
 28 import com.sun.source.tree.*;
 29 import com.sun.tools.javac.tree.JCTree.*;
 30 import com.sun.tools.javac.util.DefinedBy;
 31 import com.sun.tools.javac.util.DefinedBy.Api;
 32 import com.sun.tools.javac.util.List;
 33 import com.sun.tools.javac.util.ListBuffer;
 34 
 35 /**
 36  * Creates a copy of a tree, using a given TreeMaker.
 37  * Names, literal values, etc are shared with the original.
 38  *
 39  *  <p><b>This is NOT part of any supported API.
 40  *  If you write code that depends on this, you do so at your own risk.
 41  *  This code and its internal interfaces are subject to change or
 42  *  deletion without notice.</b>
 43  */
 44 public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
 45     private TreeMaker M;
 46 
 47     /** Creates a new instance of TreeCopier */
 48     public TreeCopier(TreeMaker M) {
 49         this.M = M;
 50     }
 51 
 52     public <T extends JCTree> T copy(T tree) {
 53         return copy(tree, null);
 54     }
 55 
 56     @SuppressWarnings("unchecked")
 57     public <T extends JCTree> T copy(T tree, P p) {
 58         if (tree == null)
 59             return null;
 60         return (T) (tree.accept(this, p));
 61     }
 62 
 63     public <T extends JCTree> List<T> copy(List<T> trees) {
 64         return copy(trees, null);
 65     }
 66 
 67     public <T extends JCTree> List<T> copy(List<T> trees, P p) {
 68         if (trees == null)
 69             return null;
 70         ListBuffer<T> lb = new ListBuffer<>();
 71         for (T tree: trees)
 72             lb.append(copy(tree, p));
 73         return lb.toList();
 74     }
 75 
 76     @DefinedBy(Api.COMPILER_TREE)
 77     public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) {
 78         JCAnnotatedType t = (JCAnnotatedType) node;
 79         List<JCAnnotation> annotations = copy(t.annotations, p);
 80         JCExpression underlyingType = copy(t.underlyingType, p);
 81         return M.at(t.pos).AnnotatedType(annotations, underlyingType);
 82     }
 83 
 84     @DefinedBy(Api.COMPILER_TREE)
 85     public JCTree visitAnnotation(AnnotationTree node, P p) {
 86         JCAnnotation t = (JCAnnotation) node;
 87         JCTree annotationType = copy(t.annotationType, p);
 88         List<JCExpression> args = copy(t.args, p);
 89         if (t.getKind() == Tree.Kind.TYPE_ANNOTATION) {
 90             JCAnnotation newTA = M.at(t.pos).TypeAnnotation(annotationType, args);
 91             newTA.attribute = t.attribute;
 92             return newTA;
 93         } else {
 94             JCAnnotation newT = M.at(t.pos).Annotation(annotationType, args);
 95             newT.attribute = t.attribute;
 96             return newT;
 97         }
 98     }
 99 
100     @DefinedBy(Api.COMPILER_TREE)
101     public JCTree visitAssert(AssertTree node, P p) {
102         JCAssert t = (JCAssert) node;
103         JCExpression cond = copy(t.cond, p);
104         JCExpression detail = copy(t.detail, p);
105         return M.at(t.pos).Assert(cond, detail);
106     }
107 
108     @DefinedBy(Api.COMPILER_TREE)
109     public JCTree visitAssignment(AssignmentTree node, P p) {
110         JCAssign t = (JCAssign) node;
111         JCExpression lhs = copy(t.lhs, p);
112         JCExpression rhs = copy(t.rhs, p);
113         return M.at(t.pos).Assign(lhs, rhs);
114     }
115 
116     @DefinedBy(Api.COMPILER_TREE)
117     public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
118         JCAssignOp t = (JCAssignOp) node;
119         JCTree lhs = copy(t.lhs, p);
120         JCTree rhs = copy(t.rhs, p);
121         return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
122     }
123 
124     @DefinedBy(Api.COMPILER_TREE)
125     public JCTree visitBinary(BinaryTree node, P p) {
126         JCBinary t = (JCBinary) node;
127         JCExpression lhs = copy(t.lhs, p);
128         JCExpression rhs = copy(t.rhs, p);
129         return M.at(t.pos).Binary(t.getTag(), lhs, rhs);
130     }
131 
132     @DefinedBy(Api.COMPILER_TREE)
133     public JCTree visitBlock(BlockTree node, P p) {
134         JCBlock t = (JCBlock) node;
135         List<JCStatement> stats = copy(t.stats, p);
136         return M.at(t.pos).Block(t.flags, stats);
137     }
138 
139     @DefinedBy(Api.COMPILER_TREE)
140     public JCTree visitBreak(BreakTree node, P p) {
141         JCBreak t = (JCBreak) node;
142         return M.at(t.pos).Break(t.label);
143     }
144 
145     @DefinedBy(Api.COMPILER_TREE)
146     public JCTree visitYield(YieldTree node, P p) {
147         JCYield t = (JCYield) node;
148         JCExpression value = copy(t.value, p);
149         return M.at(t.pos).Yield(value);
150     }
151 
152     @DefinedBy(Api.COMPILER_TREE)
153     public JCTree visitCase(CaseTree node, P p) {
154         JCCase t = (JCCase) node;
155         List<JCCaseLabel> labels = copy(t.labels, p);
156         List<JCStatement> stats = copy(t.stats, p);
157         JCTree body;
158         if (node.getCaseKind() == CaseTree.CaseKind.RULE) {
159             body = t.body instanceof JCExpression && t.stats.head.hasTag(Tag.YIELD)
160                     ? ((JCYield) t.stats.head).value : t.stats.head;
161         } else {
162             body = null;
163         }
164         return M.at(t.pos).Case(t.caseKind, labels, stats, body);
165     }
166 
167     @DefinedBy(Api.COMPILER_TREE)
168     public JCTree visitCatch(CatchTree node, P p) {
169         JCCatch t = (JCCatch) node;
170         JCVariableDecl param = copy(t.param, p);
171         JCBlock body = copy(t.body, p);
172         return M.at(t.pos).Catch(param, body);
173     }
174 
175     @DefinedBy(Api.COMPILER_TREE)
176     public JCTree visitClass(ClassTree node, P p) {
177         JCClassDecl t = (JCClassDecl) node;
178         JCModifiers mods = copy(t.mods, p);
179         List<JCTypeParameter> typarams = copy(t.typarams, p);
180         JCExpression extending = copy(t.extending, p);
181         List<JCExpression> implementing = copy(t.implementing, p);
182         List<JCTree> defs = copy(t.defs, p);
183         return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
184     }
185 
186     @DefinedBy(Api.COMPILER_TREE)
187     public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
188         JCConditional t = (JCConditional) node;
189         JCExpression cond = copy(t.cond, p);
190         JCExpression truepart = copy(t.truepart, p);
191         JCExpression falsepart = copy(t.falsepart, p);
192         return M.at(t.pos).Conditional(cond, truepart, falsepart);
193     }
194 
195     @DefinedBy(Api.COMPILER_TREE)
196     public JCTree visitContinue(ContinueTree node, P p) {
197         JCContinue t = (JCContinue) node;
198         return M.at(t.pos).Continue(t.label);
199     }
200 
201     @DefinedBy(Api.COMPILER_TREE)
202     public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
203         JCDoWhileLoop t = (JCDoWhileLoop) node;
204         JCStatement body = copy(t.body, p);
205         JCExpression cond = copy(t.cond, p);
206         return M.at(t.pos).DoLoop(body, cond);
207     }
208 
209     @DefinedBy(Api.COMPILER_TREE)
210     public JCTree visitErroneous(ErroneousTree node, P p) {
211         JCErroneous t = (JCErroneous) node;
212         List<? extends JCTree> errs = copy(t.errs, p);
213         return M.at(t.pos).Erroneous(errs);
214     }
215 
216     @DefinedBy(Api.COMPILER_TREE)
217     public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
218         JCExpressionStatement t = (JCExpressionStatement) node;
219         JCExpression expr = copy(t.expr, p);
220         return M.at(t.pos).Exec(expr);
221     }
222 
223     @DefinedBy(Api.COMPILER_TREE)
224     public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
225         JCEnhancedForLoop t = (JCEnhancedForLoop) node;
226         JCVariableDecl var = copy(t.var, p);
227         JCExpression expr = copy(t.expr, p);
228         JCStatement body = copy(t.body, p);
229         return M.at(t.pos).ForeachLoop(var, expr, body);
230     }
231 
232     @DefinedBy(Api.COMPILER_TREE)
233     public JCTree visitForLoop(ForLoopTree node, P p) {
234         JCForLoop t = (JCForLoop) node;
235         List<JCStatement> init = copy(t.init, p);
236         JCExpression cond = copy(t.cond, p);
237         List<JCExpressionStatement> step = copy(t.step, p);
238         JCStatement body = copy(t.body, p);
239         return M.at(t.pos).ForLoop(init, cond, step, body);
240     }
241 
242     @DefinedBy(Api.COMPILER_TREE)
243     public JCTree visitIdentifier(IdentifierTree node, P p) {
244         JCIdent t = (JCIdent) node;
245         return M.at(t.pos).Ident(t.name);
246     }
247 
248     @DefinedBy(Api.COMPILER_TREE)
249     public JCTree visitIf(IfTree node, P p) {
250         JCIf t = (JCIf) node;
251         JCExpression cond = copy(t.cond, p);
252         JCStatement thenpart = copy(t.thenpart, p);
253         JCStatement elsepart = copy(t.elsepart, p);
254         return M.at(t.pos).If(cond, thenpart, elsepart);
255     }
256 
257     @DefinedBy(Api.COMPILER_TREE)
258     public JCTree visitImport(ImportTree node, P p) {
259         JCImport t = (JCImport) node;
260         JCTree qualid = copy(t.qualid, p);
261         return M.at(t.pos).Import(qualid, t.staticImport);
262     }
263 
264     @DefinedBy(Api.COMPILER_TREE)
265     public JCTree visitArrayAccess(ArrayAccessTree node, P p) {
266         JCArrayAccess t = (JCArrayAccess) node;
267         JCExpression indexed = copy(t.indexed, p);
268         JCExpression index = copy(t.index, p);
269         return M.at(t.pos).Indexed(indexed, index);
270     }
271 
272     @DefinedBy(Api.COMPILER_TREE)
273     public JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
274         JCLabeledStatement t = (JCLabeledStatement) node;
275         JCStatement body = copy(t.body, p);
276         return M.at(t.pos).Labelled(t.label, body);
277     }
278 
279     @DefinedBy(Api.COMPILER_TREE)
280     public JCTree visitLiteral(LiteralTree node, P p) {
281         JCLiteral t = (JCLiteral) node;
282         return M.at(t.pos).Literal(t.typetag, t.value);
283     }
284 
285     @DefinedBy(Api.COMPILER_TREE)
286     public JCTree visitMethod(MethodTree node, P p) {
287         JCMethodDecl t  = (JCMethodDecl) node;
288         JCModifiers mods = copy(t.mods, p);
289         JCExpression restype = copy(t.restype, p);
290         List<JCTypeParameter> typarams = copy(t.typarams, p);
291         List<JCVariableDecl> params = copy(t.params, p);
292         JCVariableDecl recvparam = copy(t.recvparam, p);
293         List<JCExpression> thrown = copy(t.thrown, p);
294         JCBlock body = copy(t.body, p);
295         JCExpression defaultValue = copy(t.defaultValue, p);
296         return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue);
297     }
298 
299     @DefinedBy(Api.COMPILER_TREE)
300     public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
301         JCMethodInvocation t = (JCMethodInvocation) node;
302         List<JCExpression> typeargs = copy(t.typeargs, p);
303         JCExpression meth = copy(t.meth, p);
304         List<JCExpression> args = copy(t.args, p);
305         return M.at(t.pos).Apply(typeargs, meth, args);
306     }
307 
308     @DefinedBy(Api.COMPILER_TREE)
309     public JCTree visitModifiers(ModifiersTree node, P p) {
310         JCModifiers t = (JCModifiers) node;
311         List<JCAnnotation> annotations = copy(t.annotations, p);
312         return M.at(t.pos).Modifiers(t.flags, annotations);
313     }
314 
315     @DefinedBy(Api.COMPILER_TREE)
316     public JCTree visitNewArray(NewArrayTree node, P p) {
317         JCNewArray t = (JCNewArray) node;
318         JCExpression elemtype = copy(t.elemtype, p);
319         List<JCExpression> dims = copy(t.dims, p);
320         List<JCExpression> elems = copy(t.elems, p);
321         return M.at(t.pos).NewArray(elemtype, dims, elems);
322     }
323 
324     @DefinedBy(Api.COMPILER_TREE)
325     public JCTree visitNewClass(NewClassTree node, P p) {
326         JCNewClass t = (JCNewClass) node;
327         JCExpression encl = copy(t.encl, p);
328         List<JCExpression> typeargs = copy(t.typeargs, p);
329         JCExpression clazz = copy(t.clazz, p);
330         List<JCExpression> args = copy(t.args, p);
331         JCClassDecl def = copy(t.def, p);
332         return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
333     }
334 
335     @DefinedBy(Api.COMPILER_TREE)
336     public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
337         JCLambda t = (JCLambda) node;
338         List<JCVariableDecl> params = copy(t.params, p);
339         JCTree body = copy(t.body, p);
340         return M.at(t.pos).Lambda(params, body);
341     }
342 
343     @DefinedBy(Api.COMPILER_TREE)
344     public JCTree visitParenthesized(ParenthesizedTree node, P p) {
345         JCParens t = (JCParens) node;
346         JCExpression expr = copy(t.expr, p);
347         return M.at(t.pos).Parens(expr);
348     }
349 
350     @DefinedBy(Api.COMPILER_TREE)
351     public JCTree visitReturn(ReturnTree node, P p) {
352         JCReturn t = (JCReturn) node;
353         JCExpression expr = copy(t.expr, p);
354         return M.at(t.pos).Return(expr);
355     }
356 
357     @DefinedBy(Api.COMPILER_TREE)
358     public JCTree visitMemberSelect(MemberSelectTree node, P p) {
359         JCFieldAccess t = (JCFieldAccess) node;
360         JCExpression selected = copy(t.selected, p);
361         return M.at(t.pos).Select(selected, t.name);
362     }
363 
364     @DefinedBy(Api.COMPILER_TREE)
365     public JCTree visitMemberReference(MemberReferenceTree node, P p) {
366         JCMemberReference t = (JCMemberReference) node;
367         JCExpression expr = copy(t.expr, p);
368         List<JCExpression> typeargs = copy(t.typeargs, p);
369         return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs);
370     }
371 
372     @DefinedBy(Api.COMPILER_TREE)
373     public JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
374         JCSkip t = (JCSkip) node;
375         return M.at(t.pos).Skip();
376     }
377 
378     @DefinedBy(Api.COMPILER_TREE)
379     public JCTree visitSwitch(SwitchTree node, P p) {
380         JCSwitch t = (JCSwitch) node;
381         JCExpression selector = copy(t.selector, p);
382         List<JCCase> cases = copy(t.cases, p);
383         return M.at(t.pos).Switch(selector, cases);
384     }
385 
386     @DefinedBy(Api.COMPILER_TREE)
387     public JCTree visitSwitchExpression(SwitchExpressionTree node, P p) {
388         JCSwitchExpression t = (JCSwitchExpression) node;
389         JCExpression selector = copy(t.selector, p);
390         List<JCCase> cases = copy(t.cases, p);
391         return M.at(t.pos).SwitchExpression(selector, cases);
392     }
393 
394     @DefinedBy(Api.COMPILER_TREE)
395     public JCTree visitSynchronized(SynchronizedTree node, P p) {
396         JCSynchronized t = (JCSynchronized) node;
397         JCExpression lock = copy(t.lock, p);
398         JCBlock body = copy(t.body, p);
399         return M.at(t.pos).Synchronized(lock, body);
400     }
401 
402     @DefinedBy(Api.COMPILER_TREE)
403     public JCTree visitThrow(ThrowTree node, P p) {
404         JCThrow t = (JCThrow) node;
405         JCExpression expr = copy(t.expr, p);
406         return M.at(t.pos).Throw(expr);
407     }
408 
409     @DefinedBy(Api.COMPILER_TREE)
410     public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
411         JCCompilationUnit t = (JCCompilationUnit) node;
412         List<JCTree> defs = copy(t.defs, p);
413         return M.at(t.pos).TopLevel(defs);
414     }
415 
416     @DefinedBy(Api.COMPILER_TREE)
417     public JCTree visitPackage(PackageTree node, P p) {
418         JCPackageDecl t = (JCPackageDecl) node;
419         List<JCAnnotation> annotations = copy(t.annotations, p);
420         JCExpression pid = copy(t.pid, p);
421         return M.at(t.pos).PackageDecl(annotations, pid);
422     }
423 
424     @DefinedBy(Api.COMPILER_TREE)
425     public JCTree visitTry(TryTree node, P p) {
426         JCTry t = (JCTry) node;
427         List<JCTree> resources = copy(t.resources, p);
428         JCBlock body = copy(t.body, p);
429         List<JCCatch> catchers = copy(t.catchers, p);
430         JCBlock finalizer = copy(t.finalizer, p);
431         return M.at(t.pos).Try(resources, body, catchers, finalizer);
432     }
433 
434     @DefinedBy(Api.COMPILER_TREE)
435     public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
436         JCTypeApply t = (JCTypeApply) node;
437         JCExpression clazz = copy(t.clazz, p);
438         List<JCExpression> arguments = copy(t.arguments, p);
439         return M.at(t.pos).TypeApply(clazz, arguments);
440     }
441 
442     @DefinedBy(Api.COMPILER_TREE)
443     public JCTree visitUnionType(UnionTypeTree node, P p) {
444         JCTypeUnion t = (JCTypeUnion) node;
445         List<JCExpression> components = copy(t.alternatives, p);
446         return M.at(t.pos).TypeUnion(components);
447     }
448 
449     @DefinedBy(Api.COMPILER_TREE)
450     public JCTree visitIntersectionType(IntersectionTypeTree node, P p) {
451         JCTypeIntersection t = (JCTypeIntersection) node;
452         List<JCExpression> bounds = copy(t.bounds, p);
453         return M.at(t.pos).TypeIntersection(bounds);
454     }
455 
456     @DefinedBy(Api.COMPILER_TREE)
457     public JCTree visitArrayType(ArrayTypeTree node, P p) {
458         JCArrayTypeTree t = (JCArrayTypeTree) node;
459         JCExpression elemtype = copy(t.elemtype, p);
460         return M.at(t.pos).TypeArray(elemtype);
461     }
462 
463     @DefinedBy(Api.COMPILER_TREE)
464     public JCTree visitTypeCast(TypeCastTree node, P p) {
465         JCTypeCast t = (JCTypeCast) node;
466         JCTree clazz = copy(t.clazz, p);
467         JCExpression expr = copy(t.expr, p);
468         return M.at(t.pos).TypeCast(clazz, expr);
469     }
470 
471     @DefinedBy(Api.COMPILER_TREE)
472     public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
473         JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
474         return M.at(t.pos).TypeIdent(t.typetag);
475     }
476 
477     @DefinedBy(Api.COMPILER_TREE)
478     public JCTree visitTypeParameter(TypeParameterTree node, P p) {
479         JCTypeParameter t = (JCTypeParameter) node;
480         List<JCAnnotation> annos = copy(t.annotations, p);
481         List<JCExpression> bounds = copy(t.bounds, p);
482         return M.at(t.pos).TypeParameter(t.name, bounds, annos);
483     }
484 
485     @DefinedBy(Api.COMPILER_TREE)
486     public JCTree visitInstanceOf(InstanceOfTree node, P p) {
487         JCInstanceOf t = (JCInstanceOf) node;
488         JCExpression expr = copy(t.expr, p);
489         JCTree pattern = copy(t.pattern, p);
490         return M.at(t.pos).TypeTest(expr, pattern);
491     }
492 
493     @DefinedBy(Api.COMPILER_TREE)
494     public JCTree visitBindingPattern(BindingPatternTree node, P p) {
495         JCBindingPattern t = (JCBindingPattern) node;
496         JCVariableDecl var = copy(t.var, p);
497         return M.at(t.pos).BindingPattern(var);
498     }
499 
500     @DefinedBy(Api.COMPILER_TREE)
501     public JCTree visitGuardedPattern(GuardedPatternTree node, P p) {
502         JCGuardPattern t = (JCGuardPattern) node;
503         JCPattern patt = copy(t.patt, p);
504         JCExpression expr = copy(t.expr, p);
505         return M.at(t.pos).GuardPattern(patt, expr);
506     }
507 
508     @DefinedBy(Api.COMPILER_TREE)
509     public JCTree visitParenthesizedPattern(ParenthesizedPatternTree node, P p) {
510         JCParenthesizedPattern t = (JCParenthesizedPattern) node;
511         JCPattern pattern = copy(t.pattern, p);
512         return M.at(t.pos).ParenthesizedPattern(pattern);
513     }
514 
515     @DefinedBy(Api.COMPILER_TREE)
516     public JCTree visitDefaultCaseLabel(DefaultCaseLabelTree node, P p) {
517         JCDefaultCaseLabel t = (JCDefaultCaseLabel) node;
518         return M.at(t.pos).DefaultCaseLabel();
519     }
520 
521     @DefinedBy(Api.COMPILER_TREE)
522     public JCTree visitUnary(UnaryTree node, P p) {
523         JCUnary t = (JCUnary) node;
524         JCExpression arg = copy(t.arg, p);
525         return M.at(t.pos).Unary(t.getTag(), arg);
526     }
527 
528     @DefinedBy(Api.COMPILER_TREE)
529     public JCTree visitVariable(VariableTree node, P p) {
530         JCVariableDecl t = (JCVariableDecl) node;
531         JCModifiers mods = copy(t.mods, p);
532         JCExpression vartype = copy(t.vartype, p);
533         if (t.nameexpr == null) {
534             JCExpression init = copy(t.init, p);
535             return M.at(t.pos).VarDef(mods, t.name, vartype, init);
536         } else {
537             JCExpression nameexpr = copy(t.nameexpr, p);
538             return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
539         }
540     }
541 
542     @DefinedBy(Api.COMPILER_TREE)
543     public JCTree visitWhileLoop(WhileLoopTree node, P p) {
544         JCWhileLoop t = (JCWhileLoop) node;
545         JCStatement body = copy(t.body, p);
546         JCExpression cond = copy(t.cond, p);
547         return M.at(t.pos).WhileLoop(cond, body);
548     }
549 
550     @DefinedBy(Api.COMPILER_TREE)
551     public JCTree visitWildcard(WildcardTree node, P p) {
552         JCWildcard t = (JCWildcard) node;
553         TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
554         JCTree inner = copy(t.inner, p);
555         return M.at(t.pos).Wildcard(kind, inner);
556     }
557 
558     @Override @DefinedBy(Api.COMPILER_TREE)
559     public JCTree visitModule(ModuleTree node, P p) {
560         JCModuleDecl t = (JCModuleDecl) node;
561         JCModifiers mods = copy(t.mods, p);
562         JCExpression qualId = copy(t.qualId);
563         List<JCDirective> directives = copy(t.directives);
564         return M.at(t.pos).ModuleDef(mods, t.getModuleType(), qualId, directives);
565     }
566 
567     @Override @DefinedBy(Api.COMPILER_TREE)
568     public JCExports visitExports(ExportsTree node, P p) {
569         JCExports t = (JCExports) node;
570         JCExpression qualId = copy(t.qualid, p);
571         List<JCExpression> moduleNames = copy(t.moduleNames, p);
572         return M.at(t.pos).Exports(qualId, moduleNames);
573     }
574 
575     @Override @DefinedBy(Api.COMPILER_TREE)
576     public JCOpens visitOpens(OpensTree node, P p) {
577         JCOpens t = (JCOpens) node;
578         JCExpression qualId = copy(t.qualid, p);
579         List<JCExpression> moduleNames = copy(t.moduleNames, p);
580         return M.at(t.pos).Opens(qualId, moduleNames);
581     }
582 
583     @Override @DefinedBy(Api.COMPILER_TREE)
584     public JCProvides visitProvides(ProvidesTree node, P p) {
585         JCProvides t = (JCProvides) node;
586         JCExpression serviceName = copy(t.serviceName, p);
587         List<JCExpression> implNames = copy(t.implNames, p);
588         return M.at(t.pos).Provides(serviceName, implNames);
589     }
590 
591     @Override @DefinedBy(Api.COMPILER_TREE)
592     public JCRequires visitRequires(RequiresTree node, P p) {
593         JCRequires t = (JCRequires) node;
594         JCExpression moduleName = copy(t.moduleName, p);
595         return M.at(t.pos).Requires(t.isTransitive, t.isStaticPhase, moduleName);
596     }
597 
598     @Override @DefinedBy(Api.COMPILER_TREE)
599     public JCUses visitUses(UsesTree node, P p) {
600         JCUses t = (JCUses) node;
601         JCExpression serviceName = copy(t.qualid, p);
602         return M.at(t.pos).Uses(serviceName);
603     }
604 
605     @DefinedBy(Api.COMPILER_TREE)
606     public JCTree visitOther(Tree node, P p) {
607         JCTree tree = (JCTree) node;
608         switch (tree.getTag()) {
609             case LETEXPR: {
610                 LetExpr t = (LetExpr) node;
611                 List<JCStatement> defs = copy(t.defs, p);
612                 JCExpression expr = copy(t.expr, p);
613                 return M.at(t.pos).LetExpr(defs, expr);
614             }
615             default:
616                 throw new AssertionError("unknown tree tag: " + tree.getTag());
617         }
618     }
619 
620 }