src/share/classes/com/sun/tools/javac/tree/TreeCopier.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javac.tree;
aoqi@0 27
aoqi@0 28 import com.sun.source.tree.*;
aoqi@0 29 import com.sun.tools.javac.tree.JCTree.*;
aoqi@0 30 import com.sun.tools.javac.util.List;
aoqi@0 31 import com.sun.tools.javac.util.ListBuffer;
aoqi@0 32
aoqi@0 33 /**
aoqi@0 34 * Creates a copy of a tree, using a given TreeMaker.
aoqi@0 35 * Names, literal values, etc are shared with the original.
aoqi@0 36 *
aoqi@0 37 * <p><b>This is NOT part of any supported API.
aoqi@0 38 * If you write code that depends on this, you do so at your own risk.
aoqi@0 39 * This code and its internal interfaces are subject to change or
aoqi@0 40 * deletion without notice.</b>
aoqi@0 41 */
aoqi@0 42 public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
aoqi@0 43 private TreeMaker M;
aoqi@0 44
aoqi@0 45 /** Creates a new instance of TreeCopier */
aoqi@0 46 public TreeCopier(TreeMaker M) {
aoqi@0 47 this.M = M;
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 public <T extends JCTree> T copy(T tree) {
aoqi@0 51 return copy(tree, null);
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 @SuppressWarnings("unchecked")
aoqi@0 55 public <T extends JCTree> T copy(T tree, P p) {
aoqi@0 56 if (tree == null)
aoqi@0 57 return null;
aoqi@0 58 return (T) (tree.accept(this, p));
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 public <T extends JCTree> List<T> copy(List<T> trees) {
aoqi@0 62 return copy(trees, null);
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 public <T extends JCTree> List<T> copy(List<T> trees, P p) {
aoqi@0 66 if (trees == null)
aoqi@0 67 return null;
aoqi@0 68 ListBuffer<T> lb = new ListBuffer<T>();
aoqi@0 69 for (T tree: trees)
aoqi@0 70 lb.append(copy(tree, p));
aoqi@0 71 return lb.toList();
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) {
aoqi@0 75 JCAnnotatedType t = (JCAnnotatedType) node;
aoqi@0 76 List<JCAnnotation> annotations = copy(t.annotations, p);
aoqi@0 77 JCExpression underlyingType = copy(t.underlyingType, p);
aoqi@0 78 return M.at(t.pos).AnnotatedType(annotations, underlyingType);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 public JCTree visitAnnotation(AnnotationTree node, P p) {
aoqi@0 82 JCAnnotation t = (JCAnnotation) node;
aoqi@0 83 JCTree annotationType = copy(t.annotationType, p);
aoqi@0 84 List<JCExpression> args = copy(t.args, p);
aoqi@0 85 if (t.getKind() == Tree.Kind.TYPE_ANNOTATION) {
aoqi@0 86 JCAnnotation newTA = M.at(t.pos).TypeAnnotation(annotationType, args);
aoqi@0 87 newTA.attribute = t.attribute;
aoqi@0 88 return newTA;
aoqi@0 89 } else {
aoqi@0 90 JCAnnotation newT = M.at(t.pos).Annotation(annotationType, args);
aoqi@0 91 newT.attribute = t.attribute;
aoqi@0 92 return newT;
aoqi@0 93 }
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 public JCTree visitAssert(AssertTree node, P p) {
aoqi@0 97 JCAssert t = (JCAssert) node;
aoqi@0 98 JCExpression cond = copy(t.cond, p);
aoqi@0 99 JCExpression detail = copy(t.detail, p);
aoqi@0 100 return M.at(t.pos).Assert(cond, detail);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public JCTree visitAssignment(AssignmentTree node, P p) {
aoqi@0 104 JCAssign t = (JCAssign) node;
aoqi@0 105 JCExpression lhs = copy(t.lhs, p);
aoqi@0 106 JCExpression rhs = copy(t.rhs, p);
aoqi@0 107 return M.at(t.pos).Assign(lhs, rhs);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
aoqi@0 111 JCAssignOp t = (JCAssignOp) node;
aoqi@0 112 JCTree lhs = copy(t.lhs, p);
aoqi@0 113 JCTree rhs = copy(t.rhs, p);
aoqi@0 114 return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 public JCTree visitBinary(BinaryTree node, P p) {
aoqi@0 118 JCBinary t = (JCBinary) node;
aoqi@0 119 JCExpression lhs = copy(t.lhs, p);
aoqi@0 120 JCExpression rhs = copy(t.rhs, p);
aoqi@0 121 return M.at(t.pos).Binary(t.getTag(), lhs, rhs);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 public JCTree visitBlock(BlockTree node, P p) {
aoqi@0 125 JCBlock t = (JCBlock) node;
aoqi@0 126 List<JCStatement> stats = copy(t.stats, p);
aoqi@0 127 return M.at(t.pos).Block(t.flags, stats);
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 public JCTree visitBreak(BreakTree node, P p) {
aoqi@0 131 JCBreak t = (JCBreak) node;
aoqi@0 132 return M.at(t.pos).Break(t.label);
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 public JCTree visitCase(CaseTree node, P p) {
aoqi@0 136 JCCase t = (JCCase) node;
aoqi@0 137 JCExpression pat = copy(t.pat, p);
aoqi@0 138 List<JCStatement> stats = copy(t.stats, p);
aoqi@0 139 return M.at(t.pos).Case(pat, stats);
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 public JCTree visitCatch(CatchTree node, P p) {
aoqi@0 143 JCCatch t = (JCCatch) node;
aoqi@0 144 JCVariableDecl param = copy(t.param, p);
aoqi@0 145 JCBlock body = copy(t.body, p);
aoqi@0 146 return M.at(t.pos).Catch(param, body);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 public JCTree visitClass(ClassTree node, P p) {
aoqi@0 150 JCClassDecl t = (JCClassDecl) node;
aoqi@0 151 JCModifiers mods = copy(t.mods, p);
aoqi@0 152 List<JCTypeParameter> typarams = copy(t.typarams, p);
aoqi@0 153 JCExpression extending = copy(t.extending, p);
aoqi@0 154 List<JCExpression> implementing = copy(t.implementing, p);
aoqi@0 155 List<JCTree> defs = copy(t.defs, p);
aoqi@0 156 return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
aoqi@0 160 JCConditional t = (JCConditional) node;
aoqi@0 161 JCExpression cond = copy(t.cond, p);
aoqi@0 162 JCExpression truepart = copy(t.truepart, p);
aoqi@0 163 JCExpression falsepart = copy(t.falsepart, p);
aoqi@0 164 return M.at(t.pos).Conditional(cond, truepart, falsepart);
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 public JCTree visitContinue(ContinueTree node, P p) {
aoqi@0 168 JCContinue t = (JCContinue) node;
aoqi@0 169 return M.at(t.pos).Continue(t.label);
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
aoqi@0 173 JCDoWhileLoop t = (JCDoWhileLoop) node;
aoqi@0 174 JCStatement body = copy(t.body, p);
aoqi@0 175 JCExpression cond = copy(t.cond, p);
aoqi@0 176 return M.at(t.pos).DoLoop(body, cond);
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 public JCTree visitErroneous(ErroneousTree node, P p) {
aoqi@0 180 JCErroneous t = (JCErroneous) node;
aoqi@0 181 List<? extends JCTree> errs = copy(t.errs, p);
aoqi@0 182 return M.at(t.pos).Erroneous(errs);
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
aoqi@0 186 JCExpressionStatement t = (JCExpressionStatement) node;
aoqi@0 187 JCExpression expr = copy(t.expr, p);
aoqi@0 188 return M.at(t.pos).Exec(expr);
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
aoqi@0 192 JCEnhancedForLoop t = (JCEnhancedForLoop) node;
aoqi@0 193 JCVariableDecl var = copy(t.var, p);
aoqi@0 194 JCExpression expr = copy(t.expr, p);
aoqi@0 195 JCStatement body = copy(t.body, p);
aoqi@0 196 return M.at(t.pos).ForeachLoop(var, expr, body);
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 public JCTree visitForLoop(ForLoopTree node, P p) {
aoqi@0 200 JCForLoop t = (JCForLoop) node;
aoqi@0 201 List<JCStatement> init = copy(t.init, p);
aoqi@0 202 JCExpression cond = copy(t.cond, p);
aoqi@0 203 List<JCExpressionStatement> step = copy(t.step, p);
aoqi@0 204 JCStatement body = copy(t.body, p);
aoqi@0 205 return M.at(t.pos).ForLoop(init, cond, step, body);
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 public JCTree visitIdentifier(IdentifierTree node, P p) {
aoqi@0 209 JCIdent t = (JCIdent) node;
aoqi@0 210 return M.at(t.pos).Ident(t.name);
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 public JCTree visitIf(IfTree node, P p) {
aoqi@0 214 JCIf t = (JCIf) node;
aoqi@0 215 JCExpression cond = copy(t.cond, p);
aoqi@0 216 JCStatement thenpart = copy(t.thenpart, p);
aoqi@0 217 JCStatement elsepart = copy(t.elsepart, p);
aoqi@0 218 return M.at(t.pos).If(cond, thenpart, elsepart);
aoqi@0 219 }
aoqi@0 220
aoqi@0 221 public JCTree visitImport(ImportTree node, P p) {
aoqi@0 222 JCImport t = (JCImport) node;
aoqi@0 223 JCTree qualid = copy(t.qualid, p);
aoqi@0 224 return M.at(t.pos).Import(qualid, t.staticImport);
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 public JCTree visitArrayAccess(ArrayAccessTree node, P p) {
aoqi@0 228 JCArrayAccess t = (JCArrayAccess) node;
aoqi@0 229 JCExpression indexed = copy(t.indexed, p);
aoqi@0 230 JCExpression index = copy(t.index, p);
aoqi@0 231 return M.at(t.pos).Indexed(indexed, index);
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 public JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
aoqi@0 235 JCLabeledStatement t = (JCLabeledStatement) node;
aoqi@0 236 JCStatement body = copy(t.body, p);
aoqi@0 237 return M.at(t.pos).Labelled(t.label, body);
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 public JCTree visitLiteral(LiteralTree node, P p) {
aoqi@0 241 JCLiteral t = (JCLiteral) node;
aoqi@0 242 return M.at(t.pos).Literal(t.typetag, t.value);
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 public JCTree visitMethod(MethodTree node, P p) {
aoqi@0 246 JCMethodDecl t = (JCMethodDecl) node;
aoqi@0 247 JCModifiers mods = copy(t.mods, p);
aoqi@0 248 JCExpression restype = copy(t.restype, p);
aoqi@0 249 List<JCTypeParameter> typarams = copy(t.typarams, p);
aoqi@0 250 List<JCVariableDecl> params = copy(t.params, p);
aoqi@0 251 JCVariableDecl recvparam = copy(t.recvparam, p);
aoqi@0 252 List<JCExpression> thrown = copy(t.thrown, p);
aoqi@0 253 JCBlock body = copy(t.body, p);
aoqi@0 254 JCExpression defaultValue = copy(t.defaultValue, p);
aoqi@0 255 return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue);
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
aoqi@0 259 JCMethodInvocation t = (JCMethodInvocation) node;
aoqi@0 260 List<JCExpression> typeargs = copy(t.typeargs, p);
aoqi@0 261 JCExpression meth = copy(t.meth, p);
aoqi@0 262 List<JCExpression> args = copy(t.args, p);
aoqi@0 263 return M.at(t.pos).Apply(typeargs, meth, args);
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 public JCTree visitModifiers(ModifiersTree node, P p) {
aoqi@0 267 JCModifiers t = (JCModifiers) node;
aoqi@0 268 List<JCAnnotation> annotations = copy(t.annotations, p);
aoqi@0 269 return M.at(t.pos).Modifiers(t.flags, annotations);
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 public JCTree visitNewArray(NewArrayTree node, P p) {
aoqi@0 273 JCNewArray t = (JCNewArray) node;
aoqi@0 274 JCExpression elemtype = copy(t.elemtype, p);
aoqi@0 275 List<JCExpression> dims = copy(t.dims, p);
aoqi@0 276 List<JCExpression> elems = copy(t.elems, p);
aoqi@0 277 return M.at(t.pos).NewArray(elemtype, dims, elems);
aoqi@0 278 }
aoqi@0 279
aoqi@0 280 public JCTree visitNewClass(NewClassTree node, P p) {
aoqi@0 281 JCNewClass t = (JCNewClass) node;
aoqi@0 282 JCExpression encl = copy(t.encl, p);
aoqi@0 283 List<JCExpression> typeargs = copy(t.typeargs, p);
aoqi@0 284 JCExpression clazz = copy(t.clazz, p);
aoqi@0 285 List<JCExpression> args = copy(t.args, p);
aoqi@0 286 JCClassDecl def = copy(t.def, p);
aoqi@0 287 return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
aoqi@0 291 JCLambda t = (JCLambda) node;
aoqi@0 292 List<JCVariableDecl> params = copy(t.params, p);
aoqi@0 293 JCTree body = copy(t.body, p);
aoqi@0 294 return M.at(t.pos).Lambda(params, body);
aoqi@0 295 }
aoqi@0 296
aoqi@0 297 public JCTree visitParenthesized(ParenthesizedTree node, P p) {
aoqi@0 298 JCParens t = (JCParens) node;
aoqi@0 299 JCExpression expr = copy(t.expr, p);
aoqi@0 300 return M.at(t.pos).Parens(expr);
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 public JCTree visitReturn(ReturnTree node, P p) {
aoqi@0 304 JCReturn t = (JCReturn) node;
aoqi@0 305 JCExpression expr = copy(t.expr, p);
aoqi@0 306 return M.at(t.pos).Return(expr);
aoqi@0 307 }
aoqi@0 308
aoqi@0 309 public JCTree visitMemberSelect(MemberSelectTree node, P p) {
aoqi@0 310 JCFieldAccess t = (JCFieldAccess) node;
aoqi@0 311 JCExpression selected = copy(t.selected, p);
aoqi@0 312 return M.at(t.pos).Select(selected, t.name);
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 public JCTree visitMemberReference(MemberReferenceTree node, P p) {
aoqi@0 316 JCMemberReference t = (JCMemberReference) node;
aoqi@0 317 JCExpression expr = copy(t.expr, p);
aoqi@0 318 List<JCExpression> typeargs = copy(t.typeargs, p);
aoqi@0 319 return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs);
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 public JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
aoqi@0 323 JCSkip t = (JCSkip) node;
aoqi@0 324 return M.at(t.pos).Skip();
aoqi@0 325 }
aoqi@0 326
aoqi@0 327 public JCTree visitSwitch(SwitchTree node, P p) {
aoqi@0 328 JCSwitch t = (JCSwitch) node;
aoqi@0 329 JCExpression selector = copy(t.selector, p);
aoqi@0 330 List<JCCase> cases = copy(t.cases, p);
aoqi@0 331 return M.at(t.pos).Switch(selector, cases);
aoqi@0 332 }
aoqi@0 333
aoqi@0 334 public JCTree visitSynchronized(SynchronizedTree node, P p) {
aoqi@0 335 JCSynchronized t = (JCSynchronized) node;
aoqi@0 336 JCExpression lock = copy(t.lock, p);
aoqi@0 337 JCBlock body = copy(t.body, p);
aoqi@0 338 return M.at(t.pos).Synchronized(lock, body);
aoqi@0 339 }
aoqi@0 340
aoqi@0 341 public JCTree visitThrow(ThrowTree node, P p) {
aoqi@0 342 JCThrow t = (JCThrow) node;
aoqi@0 343 JCExpression expr = copy(t.expr, p);
aoqi@0 344 return M.at(t.pos).Throw(expr);
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
aoqi@0 348 JCCompilationUnit t = (JCCompilationUnit) node;
aoqi@0 349 List<JCAnnotation> packageAnnotations = copy(t.packageAnnotations, p);
aoqi@0 350 JCExpression pid = copy(t.pid, p);
aoqi@0 351 List<JCTree> defs = copy(t.defs, p);
aoqi@0 352 return M.at(t.pos).TopLevel(packageAnnotations, pid, defs);
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 public JCTree visitTry(TryTree node, P p) {
aoqi@0 356 JCTry t = (JCTry) node;
aoqi@0 357 List<JCTree> resources = copy(t.resources, p);
aoqi@0 358 JCBlock body = copy(t.body, p);
aoqi@0 359 List<JCCatch> catchers = copy(t.catchers, p);
aoqi@0 360 JCBlock finalizer = copy(t.finalizer, p);
aoqi@0 361 return M.at(t.pos).Try(resources, body, catchers, finalizer);
aoqi@0 362 }
aoqi@0 363
aoqi@0 364 public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
aoqi@0 365 JCTypeApply t = (JCTypeApply) node;
aoqi@0 366 JCExpression clazz = copy(t.clazz, p);
aoqi@0 367 List<JCExpression> arguments = copy(t.arguments, p);
aoqi@0 368 return M.at(t.pos).TypeApply(clazz, arguments);
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 public JCTree visitUnionType(UnionTypeTree node, P p) {
aoqi@0 372 JCTypeUnion t = (JCTypeUnion) node;
aoqi@0 373 List<JCExpression> components = copy(t.alternatives, p);
aoqi@0 374 return M.at(t.pos).TypeUnion(components);
aoqi@0 375 }
aoqi@0 376
aoqi@0 377 public JCTree visitIntersectionType(IntersectionTypeTree node, P p) {
aoqi@0 378 JCTypeIntersection t = (JCTypeIntersection) node;
aoqi@0 379 List<JCExpression> bounds = copy(t.bounds, p);
aoqi@0 380 return M.at(t.pos).TypeIntersection(bounds);
aoqi@0 381 }
aoqi@0 382
aoqi@0 383 public JCTree visitArrayType(ArrayTypeTree node, P p) {
aoqi@0 384 JCArrayTypeTree t = (JCArrayTypeTree) node;
aoqi@0 385 JCExpression elemtype = copy(t.elemtype, p);
aoqi@0 386 return M.at(t.pos).TypeArray(elemtype);
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 public JCTree visitTypeCast(TypeCastTree node, P p) {
aoqi@0 390 JCTypeCast t = (JCTypeCast) node;
aoqi@0 391 JCTree clazz = copy(t.clazz, p);
aoqi@0 392 JCExpression expr = copy(t.expr, p);
aoqi@0 393 return M.at(t.pos).TypeCast(clazz, expr);
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
aoqi@0 397 JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
aoqi@0 398 return M.at(t.pos).TypeIdent(t.typetag);
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 public JCTree visitTypeParameter(TypeParameterTree node, P p) {
aoqi@0 402 JCTypeParameter t = (JCTypeParameter) node;
aoqi@0 403 List<JCAnnotation> annos = copy(t.annotations, p);
aoqi@0 404 List<JCExpression> bounds = copy(t.bounds, p);
aoqi@0 405 return M.at(t.pos).TypeParameter(t.name, bounds, annos);
aoqi@0 406 }
aoqi@0 407
aoqi@0 408 public JCTree visitInstanceOf(InstanceOfTree node, P p) {
aoqi@0 409 JCInstanceOf t = (JCInstanceOf) node;
aoqi@0 410 JCExpression expr = copy(t.expr, p);
aoqi@0 411 JCTree clazz = copy(t.clazz, p);
aoqi@0 412 return M.at(t.pos).TypeTest(expr, clazz);
aoqi@0 413 }
aoqi@0 414
aoqi@0 415 public JCTree visitUnary(UnaryTree node, P p) {
aoqi@0 416 JCUnary t = (JCUnary) node;
aoqi@0 417 JCExpression arg = copy(t.arg, p);
aoqi@0 418 return M.at(t.pos).Unary(t.getTag(), arg);
aoqi@0 419 }
aoqi@0 420
aoqi@0 421 public JCTree visitVariable(VariableTree node, P p) {
aoqi@0 422 JCVariableDecl t = (JCVariableDecl) node;
aoqi@0 423 JCModifiers mods = copy(t.mods, p);
aoqi@0 424 JCExpression vartype = copy(t.vartype, p);
aoqi@0 425 if (t.nameexpr == null) {
aoqi@0 426 JCExpression init = copy(t.init, p);
aoqi@0 427 return M.at(t.pos).VarDef(mods, t.name, vartype, init);
aoqi@0 428 } else {
aoqi@0 429 JCExpression nameexpr = copy(t.nameexpr, p);
aoqi@0 430 return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
aoqi@0 431 }
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 public JCTree visitWhileLoop(WhileLoopTree node, P p) {
aoqi@0 435 JCWhileLoop t = (JCWhileLoop) node;
aoqi@0 436 JCStatement body = copy(t.body, p);
aoqi@0 437 JCExpression cond = copy(t.cond, p);
aoqi@0 438 return M.at(t.pos).WhileLoop(cond, body);
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 public JCTree visitWildcard(WildcardTree node, P p) {
aoqi@0 442 JCWildcard t = (JCWildcard) node;
aoqi@0 443 TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
aoqi@0 444 JCTree inner = copy(t.inner, p);
aoqi@0 445 return M.at(t.pos).Wildcard(kind, inner);
aoqi@0 446 }
aoqi@0 447
aoqi@0 448 public JCTree visitOther(Tree node, P p) {
aoqi@0 449 JCTree tree = (JCTree) node;
aoqi@0 450 switch (tree.getTag()) {
aoqi@0 451 case LETEXPR: {
aoqi@0 452 LetExpr t = (LetExpr) node;
aoqi@0 453 List<JCVariableDecl> defs = copy(t.defs, p);
aoqi@0 454 JCTree expr = copy(t.expr, p);
aoqi@0 455 return M.at(t.pos).LetExpr(defs, expr);
aoqi@0 456 }
aoqi@0 457 default:
aoqi@0 458 throw new AssertionError("unknown tree tag: " + tree.getTag());
aoqi@0 459 }
aoqi@0 460 }
aoqi@0 461
aoqi@0 462 }

mercurial