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     @SuppressWarnings("removal")
 147     public JCTree visitYield(YieldTree node, P p) {
 148         JCYield t = (JCYield) node;
 149         JCExpression value = copy(t.value, p);
 150         return M.at(t.pos).Yield(value);
 151     }
 152 
 153     @DefinedBy(Api.COMPILER_TREE)
 154     public JCTree visitCase(CaseTree node, P p) {
 155         JCCase t = (JCCase) node;
 156         List<JCExpression> pats = copy(t.pats, p);
 157         List<JCStatement> stats = copy(t.stats, p);
 158         JCTree body = copy(t.body, p);
 159         return M.at(t.pos).Case(t.caseKind, pats, stats, body);
 160     }
 161 
 162     @DefinedBy(Api.COMPILER_TREE)
 163     public JCTree visitCatch(CatchTree node, P p) {
 164         JCCatch t = (JCCatch) node;
 165         JCVariableDecl param = copy(t.param, p);
 166         JCBlock body = copy(t.body, p);
 167         return M.at(t.pos).Catch(param, body);
 168     }
 169 
 170     @DefinedBy(Api.COMPILER_TREE)
 171     public JCTree visitClass(ClassTree node, P p) {
 172         JCClassDecl t = (JCClassDecl) node;
 173         JCModifiers mods = copy(t.mods, p);
 174         List<JCTypeParameter> typarams = copy(t.typarams, p);
 175         JCExpression extending = copy(t.extending, p);
 176         List<JCExpression> implementing = copy(t.implementing, p);
 177         List<JCTree> defs = copy(t.defs, p);
 178         return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
 179     }
 180 
 181     @DefinedBy(Api.COMPILER_TREE)
 182     public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
 183         JCConditional t = (JCConditional) node;
 184         JCExpression cond = copy(t.cond, p);
 185         JCExpression truepart = copy(t.truepart, p);
 186         JCExpression falsepart = copy(t.falsepart, p);
 187         return M.at(t.pos).Conditional(cond, truepart, falsepart);
 188     }
 189 
 190     @DefinedBy(Api.COMPILER_TREE)
 191     public JCTree visitContinue(ContinueTree node, P p) {
 192         JCContinue t = (JCContinue) node;
 193         return M.at(t.pos).Continue(t.label);
 194     }
 195 
 196     @DefinedBy(Api.COMPILER_TREE)
 197     public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
 198         JCDoWhileLoop t = (JCDoWhileLoop) node;
 199         JCStatement body = copy(t.body, p);
 200         JCExpression cond = copy(t.cond, p);
 201         return M.at(t.pos).DoLoop(body, cond);
 202     }
 203 
 204     @DefinedBy(Api.COMPILER_TREE)
 205     public JCTree visitErroneous(ErroneousTree node, P p) {
 206         JCErroneous t = (JCErroneous) node;
 207         List<? extends JCTree> errs = copy(t.errs, p);
 208         return M.at(t.pos).Erroneous(errs);
 209     }
 210 
 211     @DefinedBy(Api.COMPILER_TREE)
 212     public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
 213         JCExpressionStatement t = (JCExpressionStatement) node;
 214         JCExpression expr = copy(t.expr, p);
 215         return M.at(t.pos).Exec(expr);
 216     }
 217 
 218     @DefinedBy(Api.COMPILER_TREE)
 219     public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
 220         JCEnhancedForLoop t = (JCEnhancedForLoop) node;
 221         JCVariableDecl var = copy(t.var, p);
 222         JCExpression expr = copy(t.expr, p);
 223         JCStatement body = copy(t.body, p);
 224         return M.at(t.pos).ForeachLoop(var, expr, body);
 225     }
 226 
 227     @DefinedBy(Api.COMPILER_TREE)
 228     public JCTree visitForLoop(ForLoopTree node, P p) {
 229         JCForLoop t = (JCForLoop) node;
 230         List<JCStatement> init = copy(t.init, p);
 231         JCExpression cond = copy(t.cond, p);
 232         List<JCExpressionStatement> step = copy(t.step, p);
 233         JCStatement body = copy(t.body, p);
 234         return M.at(t.pos).ForLoop(init, cond, step, body);
 235     }
 236 
 237     @DefinedBy(Api.COMPILER_TREE)
 238     public JCTree visitIdentifier(IdentifierTree node, P p) {
 239         JCIdent t = (JCIdent) node;
 240         return M.at(t.pos).Ident(t.name);
 241     }
 242 
 243     @DefinedBy(Api.COMPILER_TREE)
 244     public JCTree visitIf(IfTree node, P p) {
 245         JCIf t = (JCIf) node;
 246         JCExpression cond = copy(t.cond, p);
 247         JCStatement thenpart = copy(t.thenpart, p);
 248         JCStatement elsepart = copy(t.elsepart, p);
 249         return M.at(t.pos).If(cond, thenpart, elsepart);
 250     }
 251 
 252     @DefinedBy(Api.COMPILER_TREE)
 253     public JCTree visitImport(ImportTree node, P p) {
 254         JCImport t = (JCImport) node;
 255         JCTree qualid = copy(t.qualid, p);
 256         return M.at(t.pos).Import(qualid, t.staticImport);
 257     }
 258 
 259     @DefinedBy(Api.COMPILER_TREE)
 260     public JCTree visitArrayAccess(ArrayAccessTree node, P p) {
 261         JCArrayAccess t = (JCArrayAccess) node;
 262         JCExpression indexed = copy(t.indexed, p);
 263         JCExpression index = copy(t.index, p);
 264         return M.at(t.pos).Indexed(indexed, index);
 265     }
 266 
 267     @DefinedBy(Api.COMPILER_TREE)
 268     public JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
 269         JCLabeledStatement t = (JCLabeledStatement) node;
 270         JCStatement body = copy(t.body, p);
 271         return M.at(t.pos).Labelled(t.label, body);
 272     }
 273 
 274     @DefinedBy(Api.COMPILER_TREE)
 275     public JCTree visitLiteral(LiteralTree node, P p) {
 276         JCLiteral t = (JCLiteral) node;
 277         return M.at(t.pos).Literal(t.typetag, t.value);
 278     }
 279 
 280     @DefinedBy(Api.COMPILER_TREE)
 281     public JCTree visitMethod(MethodTree node, P p) {
 282         JCMethodDecl t  = (JCMethodDecl) node;
 283         JCModifiers mods = copy(t.mods, p);
 284         JCExpression restype = copy(t.restype, p);
 285         List<JCTypeParameter> typarams = copy(t.typarams, p);
 286         List<JCVariableDecl> params = copy(t.params, p);
 287         JCVariableDecl recvparam = copy(t.recvparam, p);
 288         List<JCExpression> thrown = copy(t.thrown, p);
 289         JCBlock body = copy(t.body, p);
 290         JCExpression defaultValue = copy(t.defaultValue, p);
 291         return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue);
 292     }
 293 
 294     @DefinedBy(Api.COMPILER_TREE)
 295     public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
 296         JCMethodInvocation t = (JCMethodInvocation) node;
 297         List<JCExpression> typeargs = copy(t.typeargs, p);
 298         JCExpression meth = copy(t.meth, p);
 299         List<JCExpression> args = copy(t.args, p);
 300         return M.at(t.pos).Apply(typeargs, meth, args);
 301     }
 302 
 303     @DefinedBy(Api.COMPILER_TREE)
 304     public JCTree visitModifiers(ModifiersTree node, P p) {
 305         JCModifiers t = (JCModifiers) node;
 306         List<JCAnnotation> annotations = copy(t.annotations, p);
 307         return M.at(t.pos).Modifiers(t.flags, annotations);
 308     }
 309 
 310     @DefinedBy(Api.COMPILER_TREE)
 311     public JCTree visitNewArray(NewArrayTree node, P p) {
 312         JCNewArray t = (JCNewArray) node;
 313         JCExpression elemtype = copy(t.elemtype, p);
 314         List<JCExpression> dims = copy(t.dims, p);
 315         List<JCExpression> elems = copy(t.elems, p);
 316         return M.at(t.pos).NewArray(elemtype, dims, elems);
 317     }
 318 
 319     @DefinedBy(Api.COMPILER_TREE)
 320     public JCTree visitNewClass(NewClassTree node, P p) {
 321         JCNewClass t = (JCNewClass) node;
 322         JCExpression encl = copy(t.encl, p);
 323         List<JCExpression> typeargs = copy(t.typeargs, p);
 324         JCExpression clazz = copy(t.clazz, p);
 325         List<JCExpression> args = copy(t.args, p);
 326         JCClassDecl def = copy(t.def, p);
 327         return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
 328     }
 329 
 330     @DefinedBy(Api.COMPILER_TREE)
 331     public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
 332         JCLambda t = (JCLambda) node;
 333         List<JCVariableDecl> params = copy(t.params, p);
 334         JCTree body = copy(t.body, p);
 335         return M.at(t.pos).Lambda(params, body);
 336     }
 337 
 338     @DefinedBy(Api.COMPILER_TREE)
 339     public JCTree visitParenthesized(ParenthesizedTree node, P p) {
 340         JCParens t = (JCParens) node;
 341         JCExpression expr = copy(t.expr, p);
 342         return M.at(t.pos).Parens(expr);
 343     }
 344 
 345     @DefinedBy(Api.COMPILER_TREE)
 346     public JCTree visitReturn(ReturnTree node, P p) {
 347         JCReturn t = (JCReturn) node;
 348         JCExpression expr = copy(t.expr, p);
 349         return M.at(t.pos).Return(expr);
 350     }
 351 
 352     @DefinedBy(Api.COMPILER_TREE)
 353     public JCTree visitMemberSelect(MemberSelectTree node, P p) {
 354         JCFieldAccess t = (JCFieldAccess) node;
 355         JCExpression selected = copy(t.selected, p);
 356         return M.at(t.pos).Select(selected, t.name);
 357     }
 358 
 359     @DefinedBy(Api.COMPILER_TREE)
 360     public JCTree visitMemberReference(MemberReferenceTree node, P p) {
 361         JCMemberReference t = (JCMemberReference) node;
 362         JCExpression expr = copy(t.expr, p);
 363         List<JCExpression> typeargs = copy(t.typeargs, p);
 364         return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs);
 365     }
 366 
 367     @DefinedBy(Api.COMPILER_TREE)
 368     public JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
 369         JCSkip t = (JCSkip) node;
 370         return M.at(t.pos).Skip();
 371     }
 372 
 373     @DefinedBy(Api.COMPILER_TREE)
 374     public JCTree visitSwitch(SwitchTree node, P p) {
 375         JCSwitch t = (JCSwitch) node;
 376         JCExpression selector = copy(t.selector, p);
 377         List<JCCase> cases = copy(t.cases, p);
 378         return M.at(t.pos).Switch(selector, cases);
 379     }
 380 
 381     @DefinedBy(Api.COMPILER_TREE)
 382     @SuppressWarnings("removal")
 383     public JCTree visitSwitchExpression(SwitchExpressionTree node, P p) {
 384         JCSwitchExpression t = (JCSwitchExpression) node;
 385         JCExpression selector = copy(t.selector, p);
 386         List<JCCase> cases = copy(t.cases, p);
 387         return M.at(t.pos).SwitchExpression(selector, cases);
 388     }
 389 
 390     @DefinedBy(Api.COMPILER_TREE)
 391     public JCTree visitSynchronized(SynchronizedTree node, P p) {
 392         JCSynchronized t = (JCSynchronized) node;
 393         JCExpression lock = copy(t.lock, p);
 394         JCBlock body = copy(t.body, p);
 395         return M.at(t.pos).Synchronized(lock, body);
 396     }
 397 
 398     @DefinedBy(Api.COMPILER_TREE)
 399     public JCTree visitThrow(ThrowTree node, P p) {
 400         JCThrow t = (JCThrow) node;
 401         JCExpression expr = copy(t.expr, p);
 402         return M.at(t.pos).Throw(expr);
 403     }
 404 
 405     @DefinedBy(Api.COMPILER_TREE)
 406     public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
 407         JCCompilationUnit t = (JCCompilationUnit) node;
 408         List<JCTree> defs = copy(t.defs, p);
 409         return M.at(t.pos).TopLevel(defs);
 410     }
 411 
 412     @DefinedBy(Api.COMPILER_TREE)
 413     public JCTree visitPackage(PackageTree node, P p) {
 414         JCPackageDecl t = (JCPackageDecl) node;
 415         List<JCAnnotation> annotations = copy(t.annotations, p);
 416         JCExpression pid = copy(t.pid, p);
 417         return M.at(t.pos).PackageDecl(annotations, pid);
 418     }
 419 
 420     @DefinedBy(Api.COMPILER_TREE)
 421     public JCTree visitTry(TryTree node, P p) {
 422         JCTry t = (JCTry) node;
 423         List<JCTree> resources = copy(t.resources, p);
 424         JCBlock body = copy(t.body, p);
 425         List<JCCatch> catchers = copy(t.catchers, p);
 426         JCBlock finalizer = copy(t.finalizer, p);
 427         return M.at(t.pos).Try(resources, body, catchers, finalizer);
 428     }
 429 
 430     @DefinedBy(Api.COMPILER_TREE)
 431     public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
 432         JCTypeApply t = (JCTypeApply) node;
 433         JCExpression clazz = copy(t.clazz, p);
 434         List<JCExpression> arguments = copy(t.arguments, p);
 435         return M.at(t.pos).TypeApply(clazz, arguments);
 436     }
 437 
 438     @DefinedBy(Api.COMPILER_TREE)
 439     public JCTree visitUnionType(UnionTypeTree node, P p) {
 440         JCTypeUnion t = (JCTypeUnion) node;
 441         List<JCExpression> components = copy(t.alternatives, p);
 442         return M.at(t.pos).TypeUnion(components);
 443     }
 444 
 445     @DefinedBy(Api.COMPILER_TREE)
 446     public JCTree visitIntersectionType(IntersectionTypeTree node, P p) {
 447         JCTypeIntersection t = (JCTypeIntersection) node;
 448         List<JCExpression> bounds = copy(t.bounds, p);
 449         return M.at(t.pos).TypeIntersection(bounds);
 450     }
 451 
 452     @DefinedBy(Api.COMPILER_TREE)
 453     public JCTree visitArrayType(ArrayTypeTree node, P p) {
 454         JCArrayTypeTree t = (JCArrayTypeTree) node;
 455         JCExpression elemtype = copy(t.elemtype, p);
 456         return M.at(t.pos).TypeArray(elemtype);
 457     }
 458 
 459     @DefinedBy(Api.COMPILER_TREE)
 460     public JCTree visitTypeCast(TypeCastTree node, P p) {
 461         JCTypeCast t = (JCTypeCast) node;
 462         JCTree clazz = copy(t.clazz, p);
 463         JCExpression expr = copy(t.expr, p);
 464         return M.at(t.pos).TypeCast(clazz, expr);
 465     }
 466 
 467     @DefinedBy(Api.COMPILER_TREE)
 468     public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
 469         JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
 470         return M.at(t.pos).TypeIdent(t.typetag);
 471     }
 472 
 473     @DefinedBy(Api.COMPILER_TREE)
 474     public JCTree visitTypeParameter(TypeParameterTree node, P p) {
 475         JCTypeParameter t = (JCTypeParameter) node;
 476         List<JCAnnotation> annos = copy(t.annotations, p);
 477         List<JCExpression> bounds = copy(t.bounds, p);
 478         return M.at(t.pos).TypeParameter(t.name, bounds, annos);
 479     }
 480 
 481     @DefinedBy(Api.COMPILER_TREE)
 482     public JCTree visitInstanceOf(InstanceOfTree node, P p) {
 483         JCInstanceOf t = (JCInstanceOf) node;
 484         JCExpression expr = copy(t.expr, p);
 485         JCTree pattern = copy(t.pattern, p);
 486         return M.at(t.pos).TypeTest(expr, pattern);
 487     }
 488 
 489     @DefinedBy(Api.COMPILER_TREE)
 490     public JCTree visitBindingPattern(BindingPatternTree node, P p) {
 491         JCBindingPattern t = (JCBindingPattern) node;
 492         JCTree vartype = copy(t.vartype, p);
 493         return M.at(t.pos).BindingPattern(t.name, vartype);
 494     }
 495 
 496     @DefinedBy(Api.COMPILER_TREE)
 497     public JCTree visitUnary(UnaryTree node, P p) {
 498         JCUnary t = (JCUnary) node;
 499         JCExpression arg = copy(t.arg, p);
 500         return M.at(t.pos).Unary(t.getTag(), arg);
 501     }
 502 
 503     @DefinedBy(Api.COMPILER_TREE)
 504     public JCTree visitVariable(VariableTree node, P p) {
 505         JCVariableDecl t = (JCVariableDecl) node;
 506         JCModifiers mods = copy(t.mods, p);
 507         JCExpression vartype = copy(t.vartype, p);
 508         if (t.nameexpr == null) {
 509             JCExpression init = copy(t.init, p);
 510             return M.at(t.pos).VarDef(mods, t.name, vartype, init);
 511         } else {
 512             JCExpression nameexpr = copy(t.nameexpr, p);
 513             return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
 514         }
 515     }
 516 
 517     @DefinedBy(Api.COMPILER_TREE)
 518     public JCTree visitWhileLoop(WhileLoopTree node, P p) {
 519         JCWhileLoop t = (JCWhileLoop) node;
 520         JCStatement body = copy(t.body, p);
 521         JCExpression cond = copy(t.cond, p);
 522         return M.at(t.pos).WhileLoop(cond, body);
 523     }
 524 
 525     @DefinedBy(Api.COMPILER_TREE)
 526     public JCTree visitWildcard(WildcardTree node, P p) {
 527         JCWildcard t = (JCWildcard) node;
 528         TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
 529         JCTree inner = copy(t.inner, p);
 530         return M.at(t.pos).Wildcard(kind, inner);
 531     }
 532 
 533     @Override @DefinedBy(Api.COMPILER_TREE)
 534     public JCTree visitModule(ModuleTree node, P p) {
 535         JCModuleDecl t = (JCModuleDecl) node;
 536         JCModifiers mods = copy(t.mods, p);
 537         JCExpression qualId = copy(t.qualId);
 538         List<JCDirective> directives = copy(t.directives);
 539         return M.at(t.pos).ModuleDef(mods, t.getModuleType(), qualId, directives);
 540     }
 541 
 542     @Override @DefinedBy(Api.COMPILER_TREE)
 543     public JCExports visitExports(ExportsTree node, P p) {
 544         JCExports t = (JCExports) node;
 545         JCExpression qualId = copy(t.qualid, p);
 546         List<JCExpression> moduleNames = copy(t.moduleNames, p);
 547         return M.at(t.pos).Exports(qualId, moduleNames);
 548     }
 549 
 550     @Override @DefinedBy(Api.COMPILER_TREE)
 551     public JCOpens visitOpens(OpensTree node, P p) {
 552         JCOpens t = (JCOpens) node;
 553         JCExpression qualId = copy(t.qualid, p);
 554         List<JCExpression> moduleNames = copy(t.moduleNames, p);
 555         return M.at(t.pos).Opens(qualId, moduleNames);
 556     }
 557 
 558     @Override @DefinedBy(Api.COMPILER_TREE)
 559     public JCProvides visitProvides(ProvidesTree node, P p) {
 560         JCProvides t = (JCProvides) node;
 561         JCExpression serviceName = copy(t.serviceName, p);
 562         List<JCExpression> implNames = copy(t.implNames, p);
 563         return M.at(t.pos).Provides(serviceName, implNames);
 564     }
 565 
 566     @Override @DefinedBy(Api.COMPILER_TREE)
 567     public JCRequires visitRequires(RequiresTree node, P p) {
 568         JCRequires t = (JCRequires) node;
 569         JCExpression moduleName = copy(t.moduleName, p);
 570         return M.at(t.pos).Requires(t.isTransitive, t.isStaticPhase, moduleName);
 571     }
 572 
 573     @Override @DefinedBy(Api.COMPILER_TREE)
 574     public JCUses visitUses(UsesTree node, P p) {
 575         JCUses t = (JCUses) node;
 576         JCExpression serviceName = copy(t.qualid, p);
 577         return M.at(t.pos).Uses(serviceName);
 578     }
 579 
 580     @DefinedBy(Api.COMPILER_TREE)
 581     public JCTree visitOther(Tree node, P p) {
 582         JCTree tree = (JCTree) node;
 583         switch (tree.getTag()) {
 584             case LETEXPR: {
 585                 LetExpr t = (LetExpr) node;
 586                 List<JCStatement> defs = copy(t.defs, p);
 587                 JCExpression expr = copy(t.expr, p);
 588                 return M.at(t.pos).LetExpr(defs, expr);
 589             }
 590             default:
 591                 throw new AssertionError("unknown tree tag: " + tree.getTag());
 592         }
 593     }
 594 
 595 }