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