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