| 1 | /* |
|---|---|
| 2 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
| 3 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
| 4 | * |
| 5 | * This file is part of JavaParser. |
| 6 | * |
| 7 | * JavaParser can be used either under the terms of |
| 8 | * a) the GNU Lesser General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * b) the terms of the Apache License |
| 12 | * |
| 13 | * You should have received a copy of both licenses in LICENCE.LGPL and |
| 14 | * LICENCE.APACHE. Please refer to those files for details. |
| 15 | * |
| 16 | * JavaParser is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU Lesser General Public License for more details. |
| 20 | */ |
| 21 | package com.github.javaparser.ast.visitor; |
| 22 | |
| 23 | import com.github.javaparser.ast.*; |
| 24 | import com.github.javaparser.ast.body.*; |
| 25 | import com.github.javaparser.ast.comments.*; |
| 26 | import com.github.javaparser.ast.expr.*; |
| 27 | import com.github.javaparser.ast.modules.*; |
| 28 | import com.github.javaparser.ast.stmt.*; |
| 29 | import com.github.javaparser.ast.type.*; |
| 30 | import java.util.Optional; |
| 31 | |
| 32 | /** |
| 33 | * A visitor that clones (copies) a node and all its children. |
| 34 | */ |
| 35 | public class CloneVisitor implements GenericVisitor<Visitable, Object> { |
| 36 | |
| 37 | @Override |
| 38 | @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") |
| 39 | public Visitable visit(final CompilationUnit n, final Object arg) { |
| 40 | NodeList<ImportDeclaration> imports = cloneList(n.getImports(), arg); |
| 41 | ModuleDeclaration module = cloneNode(n.getModule(), arg); |
| 42 | PackageDeclaration packageDeclaration = cloneNode(n.getPackageDeclaration(), arg); |
| 43 | NodeList<TypeDeclaration<?>> types = cloneList(n.getTypes(), arg); |
| 44 | Comment comment = cloneNode(n.getComment(), arg); |
| 45 | CompilationUnit r = new CompilationUnit(n.getTokenRange().orElse(null), packageDeclaration, imports, types, module); |
| 46 | n.getStorage().ifPresent(s -> r.setStorage(s.getPath(), s.getEncoding())); |
| 47 | r.setComment(comment); |
| 48 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 49 | copyData(n, r); |
| 50 | return r; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") |
| 55 | public Visitable visit(final PackageDeclaration n, final Object arg) { |
| 56 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 57 | Name name = cloneNode(n.getName(), arg); |
| 58 | Comment comment = cloneNode(n.getComment(), arg); |
| 59 | PackageDeclaration r = new PackageDeclaration(n.getTokenRange().orElse(null), annotations, name); |
| 60 | r.setComment(comment); |
| 61 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 62 | copyData(n, r); |
| 63 | return r; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Visitable visit(final TypeParameter n, final Object arg) { |
| 68 | SimpleName name = cloneNode(n.getName(), arg); |
| 69 | NodeList<ClassOrInterfaceType> typeBound = cloneList(n.getTypeBound(), arg); |
| 70 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 71 | Comment comment = cloneNode(n.getComment(), arg); |
| 72 | TypeParameter r = new TypeParameter(n.getTokenRange().orElse(null), name, typeBound, annotations); |
| 73 | r.setComment(comment); |
| 74 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 75 | copyData(n, r); |
| 76 | return r; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public Visitable visit(final LineComment n, final Object arg) { |
| 81 | Comment comment = cloneNode(n.getComment(), arg); |
| 82 | LineComment r = new LineComment(n.getTokenRange().orElse(null), n.getContent()); |
| 83 | r.setComment(comment); |
| 84 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 85 | copyData(n, r); |
| 86 | return r; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public Visitable visit(final BlockComment n, final Object arg) { |
| 91 | Comment comment = cloneNode(n.getComment(), arg); |
| 92 | BlockComment r = new BlockComment(n.getTokenRange().orElse(null), n.getContent()); |
| 93 | r.setComment(comment); |
| 94 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 95 | copyData(n, r); |
| 96 | return r; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Visitable visit(final ClassOrInterfaceDeclaration n, final Object arg) { |
| 101 | NodeList<ClassOrInterfaceType> extendedTypes = cloneList(n.getExtendedTypes(), arg); |
| 102 | NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg); |
| 103 | NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); |
| 104 | NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); |
| 105 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 106 | SimpleName name = cloneNode(n.getName(), arg); |
| 107 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 108 | Comment comment = cloneNode(n.getComment(), arg); |
| 109 | ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, n.isInterface(), name, typeParameters, extendedTypes, implementedTypes, members); |
| 110 | r.setComment(comment); |
| 111 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 112 | copyData(n, r); |
| 113 | return r; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public Visitable visit(final EnumDeclaration n, final Object arg) { |
| 118 | NodeList<EnumConstantDeclaration> entries = cloneList(n.getEntries(), arg); |
| 119 | NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg); |
| 120 | NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); |
| 121 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 122 | SimpleName name = cloneNode(n.getName(), arg); |
| 123 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 124 | Comment comment = cloneNode(n.getComment(), arg); |
| 125 | EnumDeclaration r = new EnumDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, name, implementedTypes, entries, members); |
| 126 | r.setComment(comment); |
| 127 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 128 | copyData(n, r); |
| 129 | return r; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public Visitable visit(final EnumConstantDeclaration n, final Object arg) { |
| 134 | NodeList<Expression> arguments = cloneList(n.getArguments(), arg); |
| 135 | NodeList<BodyDeclaration<?>> classBody = cloneList(n.getClassBody(), arg); |
| 136 | SimpleName name = cloneNode(n.getName(), arg); |
| 137 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 138 | Comment comment = cloneNode(n.getComment(), arg); |
| 139 | EnumConstantDeclaration r = new EnumConstantDeclaration(n.getTokenRange().orElse(null), annotations, name, arguments, classBody); |
| 140 | r.setComment(comment); |
| 141 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 142 | copyData(n, r); |
| 143 | return r; |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public Visitable visit(final AnnotationDeclaration n, final Object arg) { |
| 148 | NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); |
| 149 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 150 | SimpleName name = cloneNode(n.getName(), arg); |
| 151 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 152 | Comment comment = cloneNode(n.getComment(), arg); |
| 153 | AnnotationDeclaration r = new AnnotationDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, name, members); |
| 154 | r.setComment(comment); |
| 155 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 156 | copyData(n, r); |
| 157 | return r; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public Visitable visit(final AnnotationMemberDeclaration n, final Object arg) { |
| 162 | Expression defaultValue = cloneNode(n.getDefaultValue(), arg); |
| 163 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 164 | SimpleName name = cloneNode(n.getName(), arg); |
| 165 | Type type = cloneNode(n.getType(), arg); |
| 166 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 167 | Comment comment = cloneNode(n.getComment(), arg); |
| 168 | AnnotationMemberDeclaration r = new AnnotationMemberDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, type, name, defaultValue); |
| 169 | r.setComment(comment); |
| 170 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 171 | copyData(n, r); |
| 172 | return r; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public Visitable visit(final FieldDeclaration n, final Object arg) { |
| 177 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 178 | NodeList<VariableDeclarator> variables = cloneList(n.getVariables(), arg); |
| 179 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 180 | Comment comment = cloneNode(n.getComment(), arg); |
| 181 | FieldDeclaration r = new FieldDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, variables); |
| 182 | r.setComment(comment); |
| 183 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 184 | copyData(n, r); |
| 185 | return r; |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public Visitable visit(final VariableDeclarator n, final Object arg) { |
| 190 | Expression initializer = cloneNode(n.getInitializer(), arg); |
| 191 | SimpleName name = cloneNode(n.getName(), arg); |
| 192 | Type type = cloneNode(n.getType(), arg); |
| 193 | Comment comment = cloneNode(n.getComment(), arg); |
| 194 | VariableDeclarator r = new VariableDeclarator(n.getTokenRange().orElse(null), type, name, initializer); |
| 195 | r.setComment(comment); |
| 196 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 197 | copyData(n, r); |
| 198 | return r; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public Visitable visit(final ConstructorDeclaration n, final Object arg) { |
| 203 | BlockStmt body = cloneNode(n.getBody(), arg); |
| 204 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 205 | SimpleName name = cloneNode(n.getName(), arg); |
| 206 | NodeList<Parameter> parameters = cloneList(n.getParameters(), arg); |
| 207 | ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); |
| 208 | NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); |
| 209 | NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); |
| 210 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 211 | Comment comment = cloneNode(n.getComment(), arg); |
| 212 | ConstructorDeclaration r = new ConstructorDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter); |
| 213 | r.setComment(comment); |
| 214 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 215 | copyData(n, r); |
| 216 | return r; |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public Visitable visit(final MethodDeclaration n, final Object arg) { |
| 221 | BlockStmt body = cloneNode(n.getBody(), arg); |
| 222 | Type type = cloneNode(n.getType(), arg); |
| 223 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 224 | SimpleName name = cloneNode(n.getName(), arg); |
| 225 | NodeList<Parameter> parameters = cloneList(n.getParameters(), arg); |
| 226 | ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); |
| 227 | NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); |
| 228 | NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); |
| 229 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 230 | Comment comment = cloneNode(n.getComment(), arg); |
| 231 | MethodDeclaration r = new MethodDeclaration(n.getTokenRange().orElse(null), modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, receiverParameter); |
| 232 | r.setComment(comment); |
| 233 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 234 | copyData(n, r); |
| 235 | return r; |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public Visitable visit(final Parameter n, final Object arg) { |
| 240 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 241 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 242 | SimpleName name = cloneNode(n.getName(), arg); |
| 243 | Type type = cloneNode(n.getType(), arg); |
| 244 | NodeList<AnnotationExpr> varArgsAnnotations = cloneList(n.getVarArgsAnnotations(), arg); |
| 245 | Comment comment = cloneNode(n.getComment(), arg); |
| 246 | Parameter r = new Parameter(n.getTokenRange().orElse(null), modifiers, annotations, type, n.isVarArgs(), varArgsAnnotations, name); |
| 247 | r.setComment(comment); |
| 248 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 249 | copyData(n, r); |
| 250 | return r; |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public Visitable visit(final InitializerDeclaration n, final Object arg) { |
| 255 | BlockStmt body = cloneNode(n.getBody(), arg); |
| 256 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 257 | Comment comment = cloneNode(n.getComment(), arg); |
| 258 | InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body); |
| 259 | r.setComment(comment); |
| 260 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 261 | copyData(n, r); |
| 262 | return r; |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public Visitable visit(final JavadocComment n, final Object arg) { |
| 267 | Comment comment = cloneNode(n.getComment(), arg); |
| 268 | JavadocComment r = new JavadocComment(n.getTokenRange().orElse(null), n.getContent()); |
| 269 | r.setComment(comment); |
| 270 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 271 | copyData(n, r); |
| 272 | return r; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public Visitable visit(final ClassOrInterfaceType n, final Object arg) { |
| 277 | SimpleName name = cloneNode(n.getName(), arg); |
| 278 | ClassOrInterfaceType scope = cloneNode(n.getScope(), arg); |
| 279 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 280 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 281 | Comment comment = cloneNode(n.getComment(), arg); |
| 282 | ClassOrInterfaceType r = new ClassOrInterfaceType(n.getTokenRange().orElse(null), scope, name, typeArguments, annotations); |
| 283 | r.setComment(comment); |
| 284 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 285 | copyData(n, r); |
| 286 | return r; |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public Visitable visit(final PrimitiveType n, final Object arg) { |
| 291 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 292 | Comment comment = cloneNode(n.getComment(), arg); |
| 293 | PrimitiveType r = new PrimitiveType(n.getTokenRange().orElse(null), n.getType(), annotations); |
| 294 | r.setComment(comment); |
| 295 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 296 | copyData(n, r); |
| 297 | return r; |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public Visitable visit(final ArrayType n, final Object arg) { |
| 302 | Type componentType = cloneNode(n.getComponentType(), arg); |
| 303 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 304 | Comment comment = cloneNode(n.getComment(), arg); |
| 305 | ArrayType r = new ArrayType(n.getTokenRange().orElse(null), componentType, n.getOrigin(), annotations); |
| 306 | r.setComment(comment); |
| 307 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 308 | copyData(n, r); |
| 309 | return r; |
| 310 | } |
| 311 | |
| 312 | @Override |
| 313 | public Visitable visit(final ArrayCreationLevel n, final Object arg) { |
| 314 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 315 | Expression dimension = cloneNode(n.getDimension(), arg); |
| 316 | Comment comment = cloneNode(n.getComment(), arg); |
| 317 | ArrayCreationLevel r = new ArrayCreationLevel(n.getTokenRange().orElse(null), dimension, annotations); |
| 318 | r.setComment(comment); |
| 319 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 320 | copyData(n, r); |
| 321 | return r; |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public Visitable visit(final IntersectionType n, final Object arg) { |
| 326 | NodeList<ReferenceType> elements = cloneList(n.getElements(), arg); |
| 327 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 328 | Comment comment = cloneNode(n.getComment(), arg); |
| 329 | IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements); |
| 330 | r.setComment(comment); |
| 331 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 332 | copyData(n, r); |
| 333 | return r; |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public Visitable visit(final UnionType n, final Object arg) { |
| 338 | NodeList<ReferenceType> elements = cloneList(n.getElements(), arg); |
| 339 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 340 | Comment comment = cloneNode(n.getComment(), arg); |
| 341 | UnionType r = new UnionType(n.getTokenRange().orElse(null), elements); |
| 342 | r.setComment(comment); |
| 343 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 344 | copyData(n, r); |
| 345 | return r; |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public Visitable visit(final VoidType n, final Object arg) { |
| 350 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 351 | Comment comment = cloneNode(n.getComment(), arg); |
| 352 | VoidType r = new VoidType(n.getTokenRange().orElse(null)); |
| 353 | r.setComment(comment); |
| 354 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 355 | copyData(n, r); |
| 356 | return r; |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public Visitable visit(final WildcardType n, final Object arg) { |
| 361 | ReferenceType extendedType = cloneNode(n.getExtendedType(), arg); |
| 362 | ReferenceType superType = cloneNode(n.getSuperType(), arg); |
| 363 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 364 | Comment comment = cloneNode(n.getComment(), arg); |
| 365 | WildcardType r = new WildcardType(n.getTokenRange().orElse(null), extendedType, superType, annotations); |
| 366 | r.setComment(comment); |
| 367 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 368 | copyData(n, r); |
| 369 | return r; |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public Visitable visit(final UnknownType n, final Object arg) { |
| 374 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 375 | Comment comment = cloneNode(n.getComment(), arg); |
| 376 | UnknownType r = new UnknownType(n.getTokenRange().orElse(null)); |
| 377 | r.setComment(comment); |
| 378 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 379 | copyData(n, r); |
| 380 | return r; |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public Visitable visit(final ArrayAccessExpr n, final Object arg) { |
| 385 | Expression index = cloneNode(n.getIndex(), arg); |
| 386 | Expression name = cloneNode(n.getName(), arg); |
| 387 | Comment comment = cloneNode(n.getComment(), arg); |
| 388 | ArrayAccessExpr r = new ArrayAccessExpr(n.getTokenRange().orElse(null), name, index); |
| 389 | r.setComment(comment); |
| 390 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 391 | copyData(n, r); |
| 392 | return r; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public Visitable visit(final ArrayCreationExpr n, final Object arg) { |
| 397 | Type elementType = cloneNode(n.getElementType(), arg); |
| 398 | ArrayInitializerExpr initializer = cloneNode(n.getInitializer(), arg); |
| 399 | NodeList<ArrayCreationLevel> levels = cloneList(n.getLevels(), arg); |
| 400 | Comment comment = cloneNode(n.getComment(), arg); |
| 401 | ArrayCreationExpr r = new ArrayCreationExpr(n.getTokenRange().orElse(null), elementType, levels, initializer); |
| 402 | r.setComment(comment); |
| 403 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 404 | copyData(n, r); |
| 405 | return r; |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public Visitable visit(final ArrayInitializerExpr n, final Object arg) { |
| 410 | NodeList<Expression> values = cloneList(n.getValues(), arg); |
| 411 | Comment comment = cloneNode(n.getComment(), arg); |
| 412 | ArrayInitializerExpr r = new ArrayInitializerExpr(n.getTokenRange().orElse(null), values); |
| 413 | r.setComment(comment); |
| 414 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 415 | copyData(n, r); |
| 416 | return r; |
| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | public Visitable visit(final AssignExpr n, final Object arg) { |
| 421 | Expression target = cloneNode(n.getTarget(), arg); |
| 422 | Expression value = cloneNode(n.getValue(), arg); |
| 423 | Comment comment = cloneNode(n.getComment(), arg); |
| 424 | AssignExpr r = new AssignExpr(n.getTokenRange().orElse(null), target, value, n.getOperator()); |
| 425 | r.setComment(comment); |
| 426 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 427 | copyData(n, r); |
| 428 | return r; |
| 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public Visitable visit(final BinaryExpr n, final Object arg) { |
| 433 | Expression left = cloneNode(n.getLeft(), arg); |
| 434 | Expression right = cloneNode(n.getRight(), arg); |
| 435 | Comment comment = cloneNode(n.getComment(), arg); |
| 436 | BinaryExpr r = new BinaryExpr(n.getTokenRange().orElse(null), left, right, n.getOperator()); |
| 437 | r.setComment(comment); |
| 438 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 439 | copyData(n, r); |
| 440 | return r; |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public Visitable visit(final CastExpr n, final Object arg) { |
| 445 | Expression expression = cloneNode(n.getExpression(), arg); |
| 446 | Type type = cloneNode(n.getType(), arg); |
| 447 | Comment comment = cloneNode(n.getComment(), arg); |
| 448 | CastExpr r = new CastExpr(n.getTokenRange().orElse(null), type, expression); |
| 449 | r.setComment(comment); |
| 450 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 451 | copyData(n, r); |
| 452 | return r; |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public Visitable visit(final ClassExpr n, final Object arg) { |
| 457 | Type type = cloneNode(n.getType(), arg); |
| 458 | Comment comment = cloneNode(n.getComment(), arg); |
| 459 | ClassExpr r = new ClassExpr(n.getTokenRange().orElse(null), type); |
| 460 | r.setComment(comment); |
| 461 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 462 | copyData(n, r); |
| 463 | return r; |
| 464 | } |
| 465 | |
| 466 | @Override |
| 467 | public Visitable visit(final ConditionalExpr n, final Object arg) { |
| 468 | Expression condition = cloneNode(n.getCondition(), arg); |
| 469 | Expression elseExpr = cloneNode(n.getElseExpr(), arg); |
| 470 | Expression thenExpr = cloneNode(n.getThenExpr(), arg); |
| 471 | Comment comment = cloneNode(n.getComment(), arg); |
| 472 | ConditionalExpr r = new ConditionalExpr(n.getTokenRange().orElse(null), condition, thenExpr, elseExpr); |
| 473 | r.setComment(comment); |
| 474 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 475 | copyData(n, r); |
| 476 | return r; |
| 477 | } |
| 478 | |
| 479 | @Override |
| 480 | public Visitable visit(final EnclosedExpr n, final Object arg) { |
| 481 | Expression inner = cloneNode(n.getInner(), arg); |
| 482 | Comment comment = cloneNode(n.getComment(), arg); |
| 483 | EnclosedExpr r = new EnclosedExpr(n.getTokenRange().orElse(null), inner); |
| 484 | r.setComment(comment); |
| 485 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 486 | copyData(n, r); |
| 487 | return r; |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public Visitable visit(final FieldAccessExpr n, final Object arg) { |
| 492 | SimpleName name = cloneNode(n.getName(), arg); |
| 493 | Expression scope = cloneNode(n.getScope(), arg); |
| 494 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 495 | Comment comment = cloneNode(n.getComment(), arg); |
| 496 | FieldAccessExpr r = new FieldAccessExpr(n.getTokenRange().orElse(null), scope, typeArguments, name); |
| 497 | r.setComment(comment); |
| 498 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 499 | copyData(n, r); |
| 500 | return r; |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public Visitable visit(final InstanceOfExpr n, final Object arg) { |
| 505 | Expression expression = cloneNode(n.getExpression(), arg); |
| 506 | ReferenceType type = cloneNode(n.getType(), arg); |
| 507 | Comment comment = cloneNode(n.getComment(), arg); |
| 508 | InstanceOfExpr r = new InstanceOfExpr(n.getTokenRange().orElse(null), expression, type); |
| 509 | r.setComment(comment); |
| 510 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 511 | copyData(n, r); |
| 512 | return r; |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public Visitable visit(final StringLiteralExpr n, final Object arg) { |
| 517 | Comment comment = cloneNode(n.getComment(), arg); |
| 518 | StringLiteralExpr r = new StringLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 519 | r.setComment(comment); |
| 520 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 521 | copyData(n, r); |
| 522 | return r; |
| 523 | } |
| 524 | |
| 525 | @Override |
| 526 | public Visitable visit(final IntegerLiteralExpr n, final Object arg) { |
| 527 | Comment comment = cloneNode(n.getComment(), arg); |
| 528 | IntegerLiteralExpr r = new IntegerLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 529 | r.setComment(comment); |
| 530 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 531 | copyData(n, r); |
| 532 | return r; |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public Visitable visit(final LongLiteralExpr n, final Object arg) { |
| 537 | Comment comment = cloneNode(n.getComment(), arg); |
| 538 | LongLiteralExpr r = new LongLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 539 | r.setComment(comment); |
| 540 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 541 | copyData(n, r); |
| 542 | return r; |
| 543 | } |
| 544 | |
| 545 | @Override |
| 546 | public Visitable visit(final CharLiteralExpr n, final Object arg) { |
| 547 | Comment comment = cloneNode(n.getComment(), arg); |
| 548 | CharLiteralExpr r = new CharLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 549 | r.setComment(comment); |
| 550 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 551 | copyData(n, r); |
| 552 | return r; |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public Visitable visit(final DoubleLiteralExpr n, final Object arg) { |
| 557 | Comment comment = cloneNode(n.getComment(), arg); |
| 558 | DoubleLiteralExpr r = new DoubleLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 559 | r.setComment(comment); |
| 560 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 561 | copyData(n, r); |
| 562 | return r; |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public Visitable visit(final BooleanLiteralExpr n, final Object arg) { |
| 567 | Comment comment = cloneNode(n.getComment(), arg); |
| 568 | BooleanLiteralExpr r = new BooleanLiteralExpr(n.getTokenRange().orElse(null), n.isValue()); |
| 569 | r.setComment(comment); |
| 570 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 571 | copyData(n, r); |
| 572 | return r; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public Visitable visit(final NullLiteralExpr n, final Object arg) { |
| 577 | Comment comment = cloneNode(n.getComment(), arg); |
| 578 | NullLiteralExpr r = new NullLiteralExpr(n.getTokenRange().orElse(null)); |
| 579 | r.setComment(comment); |
| 580 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 581 | copyData(n, r); |
| 582 | return r; |
| 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public Visitable visit(final MethodCallExpr n, final Object arg) { |
| 587 | NodeList<Expression> arguments = cloneList(n.getArguments(), arg); |
| 588 | SimpleName name = cloneNode(n.getName(), arg); |
| 589 | Expression scope = cloneNode(n.getScope(), arg); |
| 590 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 591 | Comment comment = cloneNode(n.getComment(), arg); |
| 592 | MethodCallExpr r = new MethodCallExpr(n.getTokenRange().orElse(null), scope, typeArguments, name, arguments); |
| 593 | r.setComment(comment); |
| 594 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 595 | copyData(n, r); |
| 596 | return r; |
| 597 | } |
| 598 | |
| 599 | @Override |
| 600 | public Visitable visit(final NameExpr n, final Object arg) { |
| 601 | SimpleName name = cloneNode(n.getName(), arg); |
| 602 | Comment comment = cloneNode(n.getComment(), arg); |
| 603 | NameExpr r = new NameExpr(n.getTokenRange().orElse(null), name); |
| 604 | r.setComment(comment); |
| 605 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 606 | copyData(n, r); |
| 607 | return r; |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public Visitable visit(final ObjectCreationExpr n, final Object arg) { |
| 612 | NodeList<BodyDeclaration<?>> anonymousClassBody = cloneList(n.getAnonymousClassBody().orElse(null), arg); |
| 613 | NodeList<Expression> arguments = cloneList(n.getArguments(), arg); |
| 614 | Expression scope = cloneNode(n.getScope(), arg); |
| 615 | ClassOrInterfaceType type = cloneNode(n.getType(), arg); |
| 616 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 617 | Comment comment = cloneNode(n.getComment(), arg); |
| 618 | ObjectCreationExpr r = new ObjectCreationExpr(n.getTokenRange().orElse(null), scope, type, typeArguments, arguments, anonymousClassBody); |
| 619 | r.setComment(comment); |
| 620 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 621 | copyData(n, r); |
| 622 | return r; |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public Visitable visit(final Name n, final Object arg) { |
| 627 | Name qualifier = cloneNode(n.getQualifier(), arg); |
| 628 | Comment comment = cloneNode(n.getComment(), arg); |
| 629 | Name r = new Name(n.getTokenRange().orElse(null), qualifier, n.getIdentifier()); |
| 630 | r.setComment(comment); |
| 631 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 632 | copyData(n, r); |
| 633 | return r; |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public Visitable visit(final SimpleName n, final Object arg) { |
| 638 | Comment comment = cloneNode(n.getComment(), arg); |
| 639 | SimpleName r = new SimpleName(n.getTokenRange().orElse(null), n.getIdentifier()); |
| 640 | r.setComment(comment); |
| 641 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 642 | copyData(n, r); |
| 643 | return r; |
| 644 | } |
| 645 | |
| 646 | @Override |
| 647 | public Visitable visit(final ThisExpr n, final Object arg) { |
| 648 | Name typeName = cloneNode(n.getTypeName(), arg); |
| 649 | Comment comment = cloneNode(n.getComment(), arg); |
| 650 | ThisExpr r = new ThisExpr(n.getTokenRange().orElse(null), typeName); |
| 651 | r.setComment(comment); |
| 652 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 653 | copyData(n, r); |
| 654 | return r; |
| 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public Visitable visit(final SuperExpr n, final Object arg) { |
| 659 | Name typeName = cloneNode(n.getTypeName(), arg); |
| 660 | Comment comment = cloneNode(n.getComment(), arg); |
| 661 | SuperExpr r = new SuperExpr(n.getTokenRange().orElse(null), typeName); |
| 662 | r.setComment(comment); |
| 663 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 664 | copyData(n, r); |
| 665 | return r; |
| 666 | } |
| 667 | |
| 668 | @Override |
| 669 | public Visitable visit(final UnaryExpr n, final Object arg) { |
| 670 | Expression expression = cloneNode(n.getExpression(), arg); |
| 671 | Comment comment = cloneNode(n.getComment(), arg); |
| 672 | UnaryExpr r = new UnaryExpr(n.getTokenRange().orElse(null), expression, n.getOperator()); |
| 673 | r.setComment(comment); |
| 674 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 675 | copyData(n, r); |
| 676 | return r; |
| 677 | } |
| 678 | |
| 679 | @Override |
| 680 | public Visitable visit(final VariableDeclarationExpr n, final Object arg) { |
| 681 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 682 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 683 | NodeList<VariableDeclarator> variables = cloneList(n.getVariables(), arg); |
| 684 | Comment comment = cloneNode(n.getComment(), arg); |
| 685 | VariableDeclarationExpr r = new VariableDeclarationExpr(n.getTokenRange().orElse(null), modifiers, annotations, variables); |
| 686 | r.setComment(comment); |
| 687 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 688 | copyData(n, r); |
| 689 | return r; |
| 690 | } |
| 691 | |
| 692 | @Override |
| 693 | public Visitable visit(final MarkerAnnotationExpr n, final Object arg) { |
| 694 | Name name = cloneNode(n.getName(), arg); |
| 695 | Comment comment = cloneNode(n.getComment(), arg); |
| 696 | MarkerAnnotationExpr r = new MarkerAnnotationExpr(n.getTokenRange().orElse(null), name); |
| 697 | r.setComment(comment); |
| 698 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 699 | copyData(n, r); |
| 700 | return r; |
| 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public Visitable visit(final SingleMemberAnnotationExpr n, final Object arg) { |
| 705 | Expression memberValue = cloneNode(n.getMemberValue(), arg); |
| 706 | Name name = cloneNode(n.getName(), arg); |
| 707 | Comment comment = cloneNode(n.getComment(), arg); |
| 708 | SingleMemberAnnotationExpr r = new SingleMemberAnnotationExpr(n.getTokenRange().orElse(null), name, memberValue); |
| 709 | r.setComment(comment); |
| 710 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 711 | copyData(n, r); |
| 712 | return r; |
| 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public Visitable visit(final NormalAnnotationExpr n, final Object arg) { |
| 717 | NodeList<MemberValuePair> pairs = cloneList(n.getPairs(), arg); |
| 718 | Name name = cloneNode(n.getName(), arg); |
| 719 | Comment comment = cloneNode(n.getComment(), arg); |
| 720 | NormalAnnotationExpr r = new NormalAnnotationExpr(n.getTokenRange().orElse(null), name, pairs); |
| 721 | r.setComment(comment); |
| 722 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 723 | copyData(n, r); |
| 724 | return r; |
| 725 | } |
| 726 | |
| 727 | @Override |
| 728 | public Visitable visit(final MemberValuePair n, final Object arg) { |
| 729 | SimpleName name = cloneNode(n.getName(), arg); |
| 730 | Expression value = cloneNode(n.getValue(), arg); |
| 731 | Comment comment = cloneNode(n.getComment(), arg); |
| 732 | MemberValuePair r = new MemberValuePair(n.getTokenRange().orElse(null), name, value); |
| 733 | r.setComment(comment); |
| 734 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 735 | copyData(n, r); |
| 736 | return r; |
| 737 | } |
| 738 | |
| 739 | @Override |
| 740 | public Visitable visit(final ExplicitConstructorInvocationStmt n, final Object arg) { |
| 741 | NodeList<Expression> arguments = cloneList(n.getArguments(), arg); |
| 742 | Expression expression = cloneNode(n.getExpression(), arg); |
| 743 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 744 | Comment comment = cloneNode(n.getComment(), arg); |
| 745 | ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt(n.getTokenRange().orElse(null), typeArguments, n.isThis(), expression, arguments); |
| 746 | r.setComment(comment); |
| 747 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 748 | copyData(n, r); |
| 749 | return r; |
| 750 | } |
| 751 | |
| 752 | @Override |
| 753 | public Visitable visit(final LocalClassDeclarationStmt n, final Object arg) { |
| 754 | ClassOrInterfaceDeclaration classDeclaration = cloneNode(n.getClassDeclaration(), arg); |
| 755 | Comment comment = cloneNode(n.getComment(), arg); |
| 756 | LocalClassDeclarationStmt r = new LocalClassDeclarationStmt(n.getTokenRange().orElse(null), classDeclaration); |
| 757 | r.setComment(comment); |
| 758 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 759 | copyData(n, r); |
| 760 | return r; |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public Visitable visit(final AssertStmt n, final Object arg) { |
| 765 | Expression check = cloneNode(n.getCheck(), arg); |
| 766 | Expression message = cloneNode(n.getMessage(), arg); |
| 767 | Comment comment = cloneNode(n.getComment(), arg); |
| 768 | AssertStmt r = new AssertStmt(n.getTokenRange().orElse(null), check, message); |
| 769 | r.setComment(comment); |
| 770 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 771 | copyData(n, r); |
| 772 | return r; |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public Visitable visit(final BlockStmt n, final Object arg) { |
| 777 | NodeList<Statement> statements = cloneList(n.getStatements(), arg); |
| 778 | Comment comment = cloneNode(n.getComment(), arg); |
| 779 | BlockStmt r = new BlockStmt(n.getTokenRange().orElse(null), statements); |
| 780 | r.setComment(comment); |
| 781 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 782 | copyData(n, r); |
| 783 | return r; |
| 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public Visitable visit(final LabeledStmt n, final Object arg) { |
| 788 | SimpleName label = cloneNode(n.getLabel(), arg); |
| 789 | Statement statement = cloneNode(n.getStatement(), arg); |
| 790 | Comment comment = cloneNode(n.getComment(), arg); |
| 791 | LabeledStmt r = new LabeledStmt(n.getTokenRange().orElse(null), label, statement); |
| 792 | r.setComment(comment); |
| 793 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 794 | copyData(n, r); |
| 795 | return r; |
| 796 | } |
| 797 | |
| 798 | @Override |
| 799 | public Visitable visit(final EmptyStmt n, final Object arg) { |
| 800 | Comment comment = cloneNode(n.getComment(), arg); |
| 801 | EmptyStmt r = new EmptyStmt(n.getTokenRange().orElse(null)); |
| 802 | r.setComment(comment); |
| 803 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 804 | copyData(n, r); |
| 805 | return r; |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | public Visitable visit(final ExpressionStmt n, final Object arg) { |
| 810 | Expression expression = cloneNode(n.getExpression(), arg); |
| 811 | Comment comment = cloneNode(n.getComment(), arg); |
| 812 | ExpressionStmt r = new ExpressionStmt(n.getTokenRange().orElse(null), expression); |
| 813 | r.setComment(comment); |
| 814 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 815 | copyData(n, r); |
| 816 | return r; |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public Visitable visit(final SwitchStmt n, final Object arg) { |
| 821 | NodeList<SwitchEntry> entries = cloneList(n.getEntries(), arg); |
| 822 | Expression selector = cloneNode(n.getSelector(), arg); |
| 823 | Comment comment = cloneNode(n.getComment(), arg); |
| 824 | SwitchStmt r = new SwitchStmt(n.getTokenRange().orElse(null), selector, entries); |
| 825 | r.setComment(comment); |
| 826 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 827 | copyData(n, r); |
| 828 | return r; |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public Visitable visit(final SwitchEntry n, final Object arg) { |
| 833 | NodeList<Expression> labels = cloneList(n.getLabels(), arg); |
| 834 | NodeList<Statement> statements = cloneList(n.getStatements(), arg); |
| 835 | Comment comment = cloneNode(n.getComment(), arg); |
| 836 | SwitchEntry r = new SwitchEntry(n.getTokenRange().orElse(null), labels, n.getType(), statements); |
| 837 | r.setComment(comment); |
| 838 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 839 | copyData(n, r); |
| 840 | return r; |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | public Visitable visit(final BreakStmt n, final Object arg) { |
| 845 | SimpleName label = cloneNode(n.getLabel(), arg); |
| 846 | Comment comment = cloneNode(n.getComment(), arg); |
| 847 | BreakStmt r = new BreakStmt(n.getTokenRange().orElse(null), label); |
| 848 | r.setComment(comment); |
| 849 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 850 | copyData(n, r); |
| 851 | return r; |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public Visitable visit(final ReturnStmt n, final Object arg) { |
| 856 | Expression expression = cloneNode(n.getExpression(), arg); |
| 857 | Comment comment = cloneNode(n.getComment(), arg); |
| 858 | ReturnStmt r = new ReturnStmt(n.getTokenRange().orElse(null), expression); |
| 859 | r.setComment(comment); |
| 860 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 861 | copyData(n, r); |
| 862 | return r; |
| 863 | } |
| 864 | |
| 865 | @Override |
| 866 | public Visitable visit(final IfStmt n, final Object arg) { |
| 867 | Expression condition = cloneNode(n.getCondition(), arg); |
| 868 | Statement elseStmt = cloneNode(n.getElseStmt(), arg); |
| 869 | Statement thenStmt = cloneNode(n.getThenStmt(), arg); |
| 870 | Comment comment = cloneNode(n.getComment(), arg); |
| 871 | IfStmt r = new IfStmt(n.getTokenRange().orElse(null), condition, thenStmt, elseStmt); |
| 872 | r.setComment(comment); |
| 873 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 874 | copyData(n, r); |
| 875 | return r; |
| 876 | } |
| 877 | |
| 878 | @Override |
| 879 | public Visitable visit(final WhileStmt n, final Object arg) { |
| 880 | Statement body = cloneNode(n.getBody(), arg); |
| 881 | Expression condition = cloneNode(n.getCondition(), arg); |
| 882 | Comment comment = cloneNode(n.getComment(), arg); |
| 883 | WhileStmt r = new WhileStmt(n.getTokenRange().orElse(null), condition, body); |
| 884 | r.setComment(comment); |
| 885 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 886 | copyData(n, r); |
| 887 | return r; |
| 888 | } |
| 889 | |
| 890 | @Override |
| 891 | public Visitable visit(final ContinueStmt n, final Object arg) { |
| 892 | SimpleName label = cloneNode(n.getLabel(), arg); |
| 893 | Comment comment = cloneNode(n.getComment(), arg); |
| 894 | ContinueStmt r = new ContinueStmt(n.getTokenRange().orElse(null), label); |
| 895 | r.setComment(comment); |
| 896 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 897 | copyData(n, r); |
| 898 | return r; |
| 899 | } |
| 900 | |
| 901 | @Override |
| 902 | public Visitable visit(final DoStmt n, final Object arg) { |
| 903 | Statement body = cloneNode(n.getBody(), arg); |
| 904 | Expression condition = cloneNode(n.getCondition(), arg); |
| 905 | Comment comment = cloneNode(n.getComment(), arg); |
| 906 | DoStmt r = new DoStmt(n.getTokenRange().orElse(null), body, condition); |
| 907 | r.setComment(comment); |
| 908 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 909 | copyData(n, r); |
| 910 | return r; |
| 911 | } |
| 912 | |
| 913 | @Override |
| 914 | public Visitable visit(final ForEachStmt n, final Object arg) { |
| 915 | Statement body = cloneNode(n.getBody(), arg); |
| 916 | Expression iterable = cloneNode(n.getIterable(), arg); |
| 917 | VariableDeclarationExpr variable = cloneNode(n.getVariable(), arg); |
| 918 | Comment comment = cloneNode(n.getComment(), arg); |
| 919 | ForEachStmt r = new ForEachStmt(n.getTokenRange().orElse(null), variable, iterable, body); |
| 920 | r.setComment(comment); |
| 921 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 922 | copyData(n, r); |
| 923 | return r; |
| 924 | } |
| 925 | |
| 926 | @Override |
| 927 | public Visitable visit(final ForStmt n, final Object arg) { |
| 928 | Statement body = cloneNode(n.getBody(), arg); |
| 929 | Expression compare = cloneNode(n.getCompare(), arg); |
| 930 | NodeList<Expression> initialization = cloneList(n.getInitialization(), arg); |
| 931 | NodeList<Expression> update = cloneList(n.getUpdate(), arg); |
| 932 | Comment comment = cloneNode(n.getComment(), arg); |
| 933 | ForStmt r = new ForStmt(n.getTokenRange().orElse(null), initialization, compare, update, body); |
| 934 | r.setComment(comment); |
| 935 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 936 | copyData(n, r); |
| 937 | return r; |
| 938 | } |
| 939 | |
| 940 | @Override |
| 941 | public Visitable visit(final ThrowStmt n, final Object arg) { |
| 942 | Expression expression = cloneNode(n.getExpression(), arg); |
| 943 | Comment comment = cloneNode(n.getComment(), arg); |
| 944 | ThrowStmt r = new ThrowStmt(n.getTokenRange().orElse(null), expression); |
| 945 | r.setComment(comment); |
| 946 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 947 | copyData(n, r); |
| 948 | return r; |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public Visitable visit(final SynchronizedStmt n, final Object arg) { |
| 953 | BlockStmt body = cloneNode(n.getBody(), arg); |
| 954 | Expression expression = cloneNode(n.getExpression(), arg); |
| 955 | Comment comment = cloneNode(n.getComment(), arg); |
| 956 | SynchronizedStmt r = new SynchronizedStmt(n.getTokenRange().orElse(null), expression, body); |
| 957 | r.setComment(comment); |
| 958 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 959 | copyData(n, r); |
| 960 | return r; |
| 961 | } |
| 962 | |
| 963 | @Override |
| 964 | public Visitable visit(final TryStmt n, final Object arg) { |
| 965 | NodeList<CatchClause> catchClauses = cloneList(n.getCatchClauses(), arg); |
| 966 | BlockStmt finallyBlock = cloneNode(n.getFinallyBlock(), arg); |
| 967 | NodeList<Expression> resources = cloneList(n.getResources(), arg); |
| 968 | BlockStmt tryBlock = cloneNode(n.getTryBlock(), arg); |
| 969 | Comment comment = cloneNode(n.getComment(), arg); |
| 970 | TryStmt r = new TryStmt(n.getTokenRange().orElse(null), resources, tryBlock, catchClauses, finallyBlock); |
| 971 | r.setComment(comment); |
| 972 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 973 | copyData(n, r); |
| 974 | return r; |
| 975 | } |
| 976 | |
| 977 | @Override |
| 978 | public Visitable visit(final CatchClause n, final Object arg) { |
| 979 | BlockStmt body = cloneNode(n.getBody(), arg); |
| 980 | Parameter parameter = cloneNode(n.getParameter(), arg); |
| 981 | Comment comment = cloneNode(n.getComment(), arg); |
| 982 | CatchClause r = new CatchClause(n.getTokenRange().orElse(null), parameter, body); |
| 983 | r.setComment(comment); |
| 984 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 985 | copyData(n, r); |
| 986 | return r; |
| 987 | } |
| 988 | |
| 989 | @Override |
| 990 | public Visitable visit(final LambdaExpr n, final Object arg) { |
| 991 | Statement body = cloneNode(n.getBody(), arg); |
| 992 | NodeList<Parameter> parameters = cloneList(n.getParameters(), arg); |
| 993 | Comment comment = cloneNode(n.getComment(), arg); |
| 994 | LambdaExpr r = new LambdaExpr(n.getTokenRange().orElse(null), parameters, body, n.isEnclosingParameters()); |
| 995 | r.setComment(comment); |
| 996 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 997 | copyData(n, r); |
| 998 | return r; |
| 999 | } |
| 1000 | |
| 1001 | @Override |
| 1002 | public Visitable visit(final MethodReferenceExpr n, final Object arg) { |
| 1003 | Expression scope = cloneNode(n.getScope(), arg); |
| 1004 | NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); |
| 1005 | Comment comment = cloneNode(n.getComment(), arg); |
| 1006 | MethodReferenceExpr r = new MethodReferenceExpr(n.getTokenRange().orElse(null), scope, typeArguments, n.getIdentifier()); |
| 1007 | r.setComment(comment); |
| 1008 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1009 | copyData(n, r); |
| 1010 | return r; |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
| 1014 | public Visitable visit(final TypeExpr n, final Object arg) { |
| 1015 | Type type = cloneNode(n.getType(), arg); |
| 1016 | Comment comment = cloneNode(n.getComment(), arg); |
| 1017 | TypeExpr r = new TypeExpr(n.getTokenRange().orElse(null), type); |
| 1018 | r.setComment(comment); |
| 1019 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1020 | copyData(n, r); |
| 1021 | return r; |
| 1022 | } |
| 1023 | |
| 1024 | @Override |
| 1025 | public Visitable visit(NodeList n, Object arg) { |
| 1026 | NodeList<Node> newNodes = new NodeList<>(); |
| 1027 | for (Object node : n) { |
| 1028 | Node resultNode = (Node) ((Node) node).accept(this, arg); |
| 1029 | if (resultNode != null) { |
| 1030 | newNodes.add(resultNode); |
| 1031 | } |
| 1032 | } |
| 1033 | return newNodes; |
| 1034 | } |
| 1035 | |
| 1036 | @Override |
| 1037 | public Node visit(final ImportDeclaration n, final Object arg) { |
| 1038 | Name name = cloneNode(n.getName(), arg); |
| 1039 | Comment comment = cloneNode(n.getComment(), arg); |
| 1040 | ImportDeclaration r = new ImportDeclaration(n.getTokenRange().orElse(null), name, n.isStatic(), n.isAsterisk()); |
| 1041 | r.setComment(comment); |
| 1042 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1043 | copyData(n, r); |
| 1044 | return r; |
| 1045 | } |
| 1046 | |
| 1047 | @Override |
| 1048 | public Visitable visit(final ModuleDeclaration n, final Object arg) { |
| 1049 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 1050 | NodeList<ModuleDirective> directives = cloneList(n.getDirectives(), arg); |
| 1051 | Name name = cloneNode(n.getName(), arg); |
| 1052 | Comment comment = cloneNode(n.getComment(), arg); |
| 1053 | ModuleDeclaration r = new ModuleDeclaration(n.getTokenRange().orElse(null), annotations, name, n.isOpen(), directives); |
| 1054 | r.setComment(comment); |
| 1055 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1056 | copyData(n, r); |
| 1057 | return r; |
| 1058 | } |
| 1059 | |
| 1060 | @Override |
| 1061 | public Visitable visit(final ModuleRequiresDirective n, final Object arg) { |
| 1062 | NodeList<Modifier> modifiers = cloneList(n.getModifiers(), arg); |
| 1063 | Name name = cloneNode(n.getName(), arg); |
| 1064 | Comment comment = cloneNode(n.getComment(), arg); |
| 1065 | ModuleRequiresDirective r = new ModuleRequiresDirective(n.getTokenRange().orElse(null), modifiers, name); |
| 1066 | r.setComment(comment); |
| 1067 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1068 | copyData(n, r); |
| 1069 | return r; |
| 1070 | } |
| 1071 | |
| 1072 | @SuppressWarnings("unchecked") |
| 1073 | protected <T extends Node> T cloneNode(Optional<T> node, Object arg) { |
| 1074 | if (!node.isPresent()) { |
| 1075 | return null; |
| 1076 | } |
| 1077 | Node r = (Node) node.get().accept(this, arg); |
| 1078 | if (r == null) { |
| 1079 | return null; |
| 1080 | } |
| 1081 | return (T) r; |
| 1082 | } |
| 1083 | |
| 1084 | @SuppressWarnings("unchecked") |
| 1085 | protected <T extends Node> T cloneNode(T node, Object arg) { |
| 1086 | if (node == null) { |
| 1087 | return null; |
| 1088 | } |
| 1089 | Node r = (Node) node.accept(this, arg); |
| 1090 | if (r == null) { |
| 1091 | return null; |
| 1092 | } |
| 1093 | return (T) r; |
| 1094 | } |
| 1095 | |
| 1096 | private <N extends Node> NodeList<N> cloneList(NodeList<N> list, Object arg) { |
| 1097 | if (list == null) { |
| 1098 | return null; |
| 1099 | } |
| 1100 | return (NodeList<N>) list.accept(this, arg); |
| 1101 | } |
| 1102 | |
| 1103 | @Override |
| 1104 | public Visitable visit(final ModuleExportsDirective n, final Object arg) { |
| 1105 | NodeList<Name> moduleNames = cloneList(n.getModuleNames(), arg); |
| 1106 | Name name = cloneNode(n.getName(), arg); |
| 1107 | Comment comment = cloneNode(n.getComment(), arg); |
| 1108 | ModuleExportsDirective r = new ModuleExportsDirective(n.getTokenRange().orElse(null), name, moduleNames); |
| 1109 | r.setComment(comment); |
| 1110 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1111 | copyData(n, r); |
| 1112 | return r; |
| 1113 | } |
| 1114 | |
| 1115 | @Override |
| 1116 | public Visitable visit(final ModuleProvidesDirective n, final Object arg) { |
| 1117 | Name name = cloneNode(n.getName(), arg); |
| 1118 | NodeList<Name> with = cloneList(n.getWith(), arg); |
| 1119 | Comment comment = cloneNode(n.getComment(), arg); |
| 1120 | ModuleProvidesDirective r = new ModuleProvidesDirective(n.getTokenRange().orElse(null), name, with); |
| 1121 | r.setComment(comment); |
| 1122 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1123 | copyData(n, r); |
| 1124 | return r; |
| 1125 | } |
| 1126 | |
| 1127 | @Override |
| 1128 | public Visitable visit(final ModuleUsesDirective n, final Object arg) { |
| 1129 | Name name = cloneNode(n.getName(), arg); |
| 1130 | Comment comment = cloneNode(n.getComment(), arg); |
| 1131 | ModuleUsesDirective r = new ModuleUsesDirective(n.getTokenRange().orElse(null), name); |
| 1132 | r.setComment(comment); |
| 1133 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1134 | copyData(n, r); |
| 1135 | return r; |
| 1136 | } |
| 1137 | |
| 1138 | @Override |
| 1139 | public Visitable visit(final ModuleOpensDirective n, final Object arg) { |
| 1140 | NodeList<Name> moduleNames = cloneList(n.getModuleNames(), arg); |
| 1141 | Name name = cloneNode(n.getName(), arg); |
| 1142 | Comment comment = cloneNode(n.getComment(), arg); |
| 1143 | ModuleOpensDirective r = new ModuleOpensDirective(n.getTokenRange().orElse(null), name, moduleNames); |
| 1144 | r.setComment(comment); |
| 1145 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1146 | copyData(n, r); |
| 1147 | return r; |
| 1148 | } |
| 1149 | |
| 1150 | @Override |
| 1151 | public Visitable visit(final UnparsableStmt n, final Object arg) { |
| 1152 | Comment comment = cloneNode(n.getComment(), arg); |
| 1153 | UnparsableStmt r = new UnparsableStmt(n.getTokenRange().orElse(null)); |
| 1154 | r.setComment(comment); |
| 1155 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1156 | copyData(n, r); |
| 1157 | return r; |
| 1158 | } |
| 1159 | |
| 1160 | @Override |
| 1161 | public Visitable visit(final ReceiverParameter n, final Object arg) { |
| 1162 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 1163 | Name name = cloneNode(n.getName(), arg); |
| 1164 | Type type = cloneNode(n.getType(), arg); |
| 1165 | Comment comment = cloneNode(n.getComment(), arg); |
| 1166 | ReceiverParameter r = new ReceiverParameter(n.getTokenRange().orElse(null), annotations, type, name); |
| 1167 | r.setComment(comment); |
| 1168 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1169 | copyData(n, r); |
| 1170 | return r; |
| 1171 | } |
| 1172 | |
| 1173 | @Override |
| 1174 | public Visitable visit(final VarType n, final Object arg) { |
| 1175 | NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); |
| 1176 | Comment comment = cloneNode(n.getComment(), arg); |
| 1177 | VarType r = new VarType(n.getTokenRange().orElse(null)); |
| 1178 | r.setComment(comment); |
| 1179 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1180 | copyData(n, r); |
| 1181 | return r; |
| 1182 | } |
| 1183 | |
| 1184 | @Override |
| 1185 | public Visitable visit(final Modifier n, final Object arg) { |
| 1186 | Comment comment = cloneNode(n.getComment(), arg); |
| 1187 | Modifier r = new Modifier(n.getTokenRange().orElse(null), n.getKeyword()); |
| 1188 | r.setComment(comment); |
| 1189 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1190 | copyData(n, r); |
| 1191 | return r; |
| 1192 | } |
| 1193 | |
| 1194 | @Override |
| 1195 | public Visitable visit(final SwitchExpr n, final Object arg) { |
| 1196 | NodeList<SwitchEntry> entries = cloneList(n.getEntries(), arg); |
| 1197 | Expression selector = cloneNode(n.getSelector(), arg); |
| 1198 | Comment comment = cloneNode(n.getComment(), arg); |
| 1199 | SwitchExpr r = new SwitchExpr(n.getTokenRange().orElse(null), selector, entries); |
| 1200 | r.setComment(comment); |
| 1201 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1202 | copyData(n, r); |
| 1203 | return r; |
| 1204 | } |
| 1205 | |
| 1206 | private void copyData(Node source, Node destination) { |
| 1207 | for (DataKey dataKey : source.getDataKeys()) { |
| 1208 | destination.setData(dataKey, source.getData(dataKey)); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | @Override |
| 1213 | public Visitable visit(final YieldStmt n, final Object arg) { |
| 1214 | Expression expression = cloneNode(n.getExpression(), arg); |
| 1215 | Comment comment = cloneNode(n.getComment(), arg); |
| 1216 | YieldStmt r = new YieldStmt(n.getTokenRange().orElse(null), expression); |
| 1217 | r.setComment(comment); |
| 1218 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1219 | copyData(n, r); |
| 1220 | return r; |
| 1221 | } |
| 1222 | |
| 1223 | @Override |
| 1224 | public Visitable visit(final TextBlockLiteralExpr n, final Object arg) { |
| 1225 | Comment comment = cloneNode(n.getComment(), arg); |
| 1226 | TextBlockLiteralExpr r = new TextBlockLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); |
| 1227 | r.setComment(comment); |
| 1228 | n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); |
| 1229 | copyData(n, r); |
| 1230 | return r; |
| 1231 | } |
| 1232 | } |
| 1233 |
Members