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