diff options
Diffstat (limited to 'javaparser-core/src/main/java/com/github/javaparser')
43 files changed, 4940 insertions, 3928 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java index 05f41d4c8..b4dc4d177 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java @@ -21,16 +21,19 @@ package com.github.javaparser; +import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeSet; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.LineComment; import com.github.javaparser.utils.PositionUtils; -import java.util.*; - -import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; - /** * Assigns comments to nodes of the AST. * @@ -63,9 +66,9 @@ class CommentsInserter { List<Node> children = cu.getChildNodes(); Comment firstComment = comments.iterator().next(); - if (cu.getPackage() != null + if (cu.getPackage().isPresent() && (children.isEmpty() || PositionUtils.areInOrder( - firstComment, cu.getPackage()))) { + firstComment, cu.getPackage().get()))) { cu.setComment(firstComment); comments.remove(firstComment); } @@ -173,7 +176,7 @@ class CommentsInserter { } else { // try with all the children, sorted by reverse position (so the // first one is the nearest to the comment - List<Node> children = new LinkedList<Node>(); + List<Node> children = new LinkedList<>(); children.addAll(node.getChildNodes()); PositionUtils.sortByBeginPosition(children); Collections.reverse(children); diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java index 117f573c9..56926c821 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -1,19 +1,19 @@ package com.github.javaparser; -import com.github.javaparser.ast.Node; - import java.util.List; +import java.util.Optional; + +import com.github.javaparser.ast.Node; /** * An object that has a parent node. */ public interface HasParentNode<T> { - // TODO nullable /** * Return the parent node or null, if no parent is set. */ - Node getParentNode(); + Optional<Node> getParentNode(); /** * Set the parent node. @@ -32,12 +32,12 @@ public interface HasParentNode<T> { * Get the ancestor of the node having the given type, or null if no ancestor of the given type is found. */ default <N> N getAncestorOfType(Class<N> classType) { - Node parent = getParentNode(); + Node parent = getParentNode().orElse(null); while (parent != null) { if (classType.isAssignableFrom(parent.getClass())) { return classType.cast(parent); } - parent = parent.getParentNode(); + parent = parent.getParentNode().orElse(null); } return null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java index 6716b1146..36a3c517e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java @@ -21,174 +21,188 @@ package com.github.javaparser; +import static com.github.javaparser.ParseStart.ANNOTATION; +import static com.github.javaparser.ParseStart.ANNOTATION_BODY; +import static com.github.javaparser.ParseStart.BLOCK; +import static com.github.javaparser.ParseStart.CLASS_BODY; +import static com.github.javaparser.ParseStart.CLASS_OR_INTERFACE_TYPE; +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.ParseStart.EXPRESSION; +import static com.github.javaparser.ParseStart.IMPORT_DECLARATION; +import static com.github.javaparser.ParseStart.INTERFACE_BODY; +import static com.github.javaparser.ParseStart.STATEMENT; +import static com.github.javaparser.Providers.UTF8; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.nio.charset.Charset; +import java.nio.file.Path; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.imports.ImportDeclaration; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.comments.CommentsCollection; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.imports.ImportDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import java.io.*; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.Optional; - -import static com.github.javaparser.ParseStart.*; -import static com.github.javaparser.Providers.UTF8; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * Parse Java source code and creates Abstract Syntax Trees. * * @author JĂșlio Vilmar Gesser */ public final class JavaParser { - private final CommentsInserter commentsInserter; + private final CommentsInserter commentsInserter; - private ASTParser astParser = null; + private ASTParser astParser = null; - /** - * Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on this class. - * Creating an instance will reduce setup time between parsing files. - */ - public JavaParser() { - this(new ParserConfiguration()); - } + /** + * Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on + * this class. + * Creating an instance will reduce setup time between parsing files. + */ + public JavaParser() { + this(new ParserConfiguration()); + } - /** - * Instantiate the parser. Note that parsing can also be done with the static methods on this class. - * Creating an instance will reduce setup time between parsing files. - */ - public JavaParser(ParserConfiguration configuration) { - commentsInserter = new CommentsInserter(configuration); - } + /** + * Instantiate the parser. Note that parsing can also be done with the static methods on this class. + * Creating an instance will reduce setup time between parsing files. + */ + public JavaParser(ParserConfiguration configuration) { + commentsInserter = new CommentsInserter(configuration); + } - private ASTParser getParserForProvider(Provider provider) { - if (astParser == null) { - astParser = new ASTParser(provider); - } else { - astParser.ReInit(provider); - } - return astParser; - } + private ASTParser getParserForProvider(Provider provider) { + if (astParser == null) { + astParser = new ASTParser(provider); + } else { + astParser.ReInit(provider); + } + return astParser; + } - /** - * Parses source code. - * It takes the source code from a Provider. - * The start indicates what can be found in the source code (compilation unit, block, import...) - * - * @param start refer to the constants in ParseStart to see what can be parsed. + /** + * Parses source code. + * It takes the source code from a Provider. + * The start indicates what can be found in the source code (compilation unit, block, import...) + * + * @param start refer to the constants in ParseStart to see what can be parsed. * @param provider refer to Providers to see how you can read source. - * @param <N> the subclass of Node that is the result of parsing in the start. + * @param <N> the subclass of Node that is the result of parsing in the start. * @return the parse result, a collection of encountered problems, and some extra data. */ - public <N extends Node> ParseResult<N> parse(ParseStart<N> start, Provider provider) { - assertNotNull(start); - assertNotNull(provider); - try { + public <N extends Node> ParseResult<N> parse(ParseStart<N> start, Provider provider) { + assertNotNull(start); + assertNotNull(provider); + try { final ASTParser parser = getParserForProvider(provider); - N resultNode = start.parse(parser); + N resultNode = start.parse(parser); final CommentsCollection comments = astParser.getCommentsCollection(); commentsInserter.insertComments(resultNode, comments.copy().getComments()); - - return new ParseResult<>(Optional.of(resultNode), parser.problems, Optional.of(astParser.getTokens()), Optional.of(astParser.getCommentsCollection())); - } catch (Exception e) { - return new ParseResult<>(e); - } finally { - try { - provider.close(); - } catch (IOException e) { - // Since we're done parsing and have our result, we don't care about any errors. - } - } - } - /** - * Parses the Java code contained in the {@link InputStream} and returns a - * {@link CompilationUnit} that represents it. - * - * @param in {@link InputStream} containing Java source code - * @param encoding encoding of the source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors - */ - public static CompilationUnit parse(final InputStream in, Charset encoding) { - return simplifiedParse(COMPILATION_UNIT, provider(in, encoding)); - } + return new ParseResult<>(resultNode, parser.problems, astParser.getTokens(), + astParser.getCommentsCollection()); + } catch (Exception e) { + return new ParseResult<>(e); + } finally { + try { + provider.close(); + } catch (IOException e) { + // Since we're done parsing and have our result, we don't care about any errors. + } + } + } + + /** + * Parses the Java code contained in the {@link InputStream} and returns a + * {@link CompilationUnit} that represents it. + * + * @param in {@link InputStream} containing Java source code + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final InputStream in, Charset encoding) { + return simplifiedParse(COMPILATION_UNIT, provider(in, encoding)); + } - /** - * Parses the Java code contained in the {@link InputStream} and returns a - * {@link CompilationUnit} that represents it.<br> - * Note: Uses UTF-8 encoding - * - * @param in {@link InputStream} containing Java source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors - */ - public static CompilationUnit parse(final InputStream in) { - return parse(in, UTF8); - } + /** + * Parses the Java code contained in the {@link InputStream} and returns a + * {@link CompilationUnit} that represents it.<br> + * Note: Uses UTF-8 encoding + * + * @param in {@link InputStream} containing Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final InputStream in) { + return parse(in, UTF8); + } - /** - * Parses the Java code contained in a {@link File} and returns a - * {@link CompilationUnit} that represents it. - * - * @param file {@link File} containing Java source code - * @param encoding encoding of the source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors + /** + * Parses the Java code contained in a {@link File} and returns a + * {@link CompilationUnit} that represents it. + * + * @param file {@link File} containing Java source code + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors * @throws FileNotFoundException the file was not found - */ - public static CompilationUnit parse(final File file, final Charset encoding) throws FileNotFoundException { - return simplifiedParse(COMPILATION_UNIT, provider(file, encoding)); - } + */ + public static CompilationUnit parse(final File file, final Charset encoding) throws FileNotFoundException { + return simplifiedParse(COMPILATION_UNIT, provider(file, encoding)); + } - /** - * Parses the Java code contained in a {@link File} and returns a - * {@link CompilationUnit} that represents it.<br> - * Note: Uses UTF-8 encoding - * - * @param file {@link File} containing Java source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors - * @throws FileNotFoundException the file was not found - */ - public static CompilationUnit parse(final File file) throws FileNotFoundException { - return simplifiedParse(COMPILATION_UNIT, provider(file)); - } + /** + * Parses the Java code contained in a {@link File} and returns a + * {@link CompilationUnit} that represents it.<br> + * Note: Uses UTF-8 encoding + * + * @param file {@link File} containing Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws FileNotFoundException the file was not found + */ + public static CompilationUnit parse(final File file) throws FileNotFoundException { + return simplifiedParse(COMPILATION_UNIT, provider(file)); + } - /** - * Parses the Java code contained in a file and returns a - * {@link CompilationUnit} that represents it. - * - * @param path path to a file containing Java source code - * @param encoding encoding of the source code - * @return CompilationUnit representing the Java source code - * @throws IOException the path could not be accessed - * @throws ParseProblemException if the source code has parser errors - */ - public static CompilationUnit parse(final Path path, final Charset encoding) throws IOException { - return simplifiedParse(COMPILATION_UNIT, provider(path, encoding)); - } + /** + * Parses the Java code contained in a file and returns a + * {@link CompilationUnit} that represents it. + * + * @param path path to a file containing Java source code + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws IOException the path could not be accessed + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final Path path, final Charset encoding) throws IOException { + return simplifiedParse(COMPILATION_UNIT, provider(path, encoding)); + } - /** - * Parses the Java code contained in a file and returns a - * {@link CompilationUnit} that represents it.<br> - * Note: Uses UTF-8 encoding - * - * @param path path to a file containing Java source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors - * @throws IOException the path could not be accessed - */ - public static CompilationUnit parse(final Path path) throws IOException { - return simplifiedParse(COMPILATION_UNIT, provider(path)); - } + /** + * Parses the Java code contained in a file and returns a + * {@link CompilationUnit} that represents it.<br> + * Note: Uses UTF-8 encoding + * + * @param path path to a file containing Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws IOException the path could not be accessed + */ + public static CompilationUnit parse(final Path path) throws IOException { + return simplifiedParse(COMPILATION_UNIT, provider(path)); + } /** * Parses Java code from a Reader and returns a @@ -198,125 +212,125 @@ public final class JavaParser { * @return CompilationUnit representing the Java source code * @throws ParseProblemException if the source code has parser errors */ - public static CompilationUnit parse(final Reader reader) { - return simplifiedParse(COMPILATION_UNIT, provider(reader)); - } + public static CompilationUnit parse(final Reader reader) { + return simplifiedParse(COMPILATION_UNIT, provider(reader)); + } - /** - * Parses the Java code contained in code and returns a - * {@link CompilationUnit} that represents it. - * - * @param code Java source code - * @return CompilationUnit representing the Java source code - * @throws ParseProblemException if the source code has parser errors - */ - public static CompilationUnit parse(String code) { - return simplifiedParse(COMPILATION_UNIT, provider(code)); - } + /** + * Parses the Java code contained in code and returns a + * {@link CompilationUnit} that represents it. + * + * @param code Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(String code) { + return simplifiedParse(COMPILATION_UNIT, provider(code)); + } - /** - * Parses the Java block contained in a {@link String} and returns a - * {@link BlockStmt} that represents it. - * - * @param blockStatement {@link String} containing Java block code - * @return BlockStmt representing the Java block - * @throws ParseProblemException if the source code has parser errors - */ - public static BlockStmt parseBlock(final String blockStatement) { - return simplifiedParse(BLOCK, provider(blockStatement)); - } + /** + * Parses the Java block contained in a {@link String} and returns a + * {@link BlockStmt} that represents it. + * + * @param blockStatement {@link String} containing Java block code + * @return BlockStmt representing the Java block + * @throws ParseProblemException if the source code has parser errors + */ + public static BlockStmt parseBlock(final String blockStatement) { + return simplifiedParse(BLOCK, provider(blockStatement)); + } - /** - * Parses the Java statement contained in a {@link String} and returns a - * {@link Statement} that represents it. - * - * @param statement {@link String} containing Java statement code - * @return Statement representing the Java statement - * @throws ParseProblemException if the source code has parser errors - */ - public static Statement parseStatement(final String statement) { - return simplifiedParse(STATEMENT, provider(statement)); - } + /** + * Parses the Java statement contained in a {@link String} and returns a + * {@link Statement} that represents it. + * + * @param statement {@link String} containing Java statement code + * @return Statement representing the Java statement + * @throws ParseProblemException if the source code has parser errors + */ + public static Statement parseStatement(final String statement) { + return simplifiedParse(STATEMENT, provider(statement)); + } - private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) { - ParseResult<T> result = new JavaParser(new ParserConfiguration()).parse(context, provider); - if (result.isSuccessful()) { - return result.getResult().get(); - } - throw new ParseProblemException(result.getProblems()); - } + private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) { + ParseResult<T> result = new JavaParser(new ParserConfiguration()).parse(context, provider); + if (result.isSuccessful()) { + return result.getResult().get(); + } + throw new ParseProblemException(result.getProblems()); + } - /** - * Parses the Java import contained in a {@link String} and returns a - * {@link ImportDeclaration} that represents it. - * - * @param importDeclaration {@link String} containing Java import code - * @return ImportDeclaration representing the Java import declaration - * @throws ParseProblemException if the source code has parser errors - */ - public static ImportDeclaration parseImport(final String importDeclaration) { - return simplifiedParse(IMPORT_DECLARATION, provider(importDeclaration)); - } + /** + * Parses the Java import contained in a {@link String} and returns a + * {@link ImportDeclaration} that represents it. + * + * @param importDeclaration {@link String} containing Java import code + * @return ImportDeclaration representing the Java import declaration + * @throws ParseProblemException if the source code has parser errors + */ + public static ImportDeclaration parseImport(final String importDeclaration) { + return simplifiedParse(IMPORT_DECLARATION, provider(importDeclaration)); + } - /** - * Parses the Java expression contained in a {@link String} and returns a - * {@link Expression} that represents it. - * - * @param expression {@link String} containing Java expression - * @return Expression representing the Java expression - * @throws ParseProblemException if the source code has parser errors - */ - public static <T extends Expression> T parseExpression(final String expression) { - return (T) simplifiedParse(EXPRESSION, provider(expression)); - } + /** + * Parses the Java expression contained in a {@link String} and returns a + * {@link Expression} that represents it. + * + * @param expression {@link String} containing Java expression + * @return Expression representing the Java expression + * @throws ParseProblemException if the source code has parser errors + */ + public static <T extends Expression> T parseExpression(final String expression) { + return (T) simplifiedParse(EXPRESSION, provider(expression)); + } - /** - * Parses the Java annotation contained in a {@link String} and returns a - * {@link AnnotationExpr} that represents it. - * - * @param annotation {@link String} containing Java annotation - * @return AnnotationExpr representing the Java annotation - * @throws ParseProblemException if the source code has parser errors - */ - public static AnnotationExpr parseAnnotation(final String annotation) { - return simplifiedParse(ANNOTATION, provider(annotation)); - } + /** + * Parses the Java annotation contained in a {@link String} and returns a + * {@link AnnotationExpr} that represents it. + * + * @param annotation {@link String} containing Java annotation + * @return AnnotationExpr representing the Java annotation + * @throws ParseProblemException if the source code has parser errors + */ + public static AnnotationExpr parseAnnotation(final String annotation) { + return simplifiedParse(ANNOTATION, provider(annotation)); + } - /** - * Parses the Java annotation body declaration(e.g fields or methods) contained in a - * {@link String} and returns a {@link BodyDeclaration} that represents it. - * - * @param body {@link String} containing Java body declaration - * @return BodyDeclaration representing the Java annotation - * @throws ParseProblemException if the source code has parser errors - */ - public static BodyDeclaration<?> parseAnnotationBodyDeclaration(final String body) { - return simplifiedParse(ANNOTATION_BODY, provider(body)); - } + /** + * Parses the Java annotation body declaration(e.g fields or methods) contained in a + * {@link String} and returns a {@link BodyDeclaration} that represents it. + * + * @param body {@link String} containing Java body declaration + * @return BodyDeclaration representing the Java annotation + * @throws ParseProblemException if the source code has parser errors + */ + public static BodyDeclaration<?> parseAnnotationBodyDeclaration(final String body) { + return simplifiedParse(ANNOTATION_BODY, provider(body)); + } - /** - * Parses a Java class body declaration(e.g fields or methods) and returns a - * {@link BodyDeclaration} that represents it. - * - * @param body the body of a class - * @return BodyDeclaration representing the Java class body - * @throws ParseProblemException if the source code has parser errors - */ - public static BodyDeclaration<?> parseClassBodyDeclaration(String body) { - return simplifiedParse(CLASS_BODY, provider(body)); - } + /** + * Parses a Java class body declaration(e.g fields or methods) and returns a + * {@link BodyDeclaration} that represents it. + * + * @param body the body of a class + * @return BodyDeclaration representing the Java class body + * @throws ParseProblemException if the source code has parser errors + */ + public static BodyDeclaration<?> parseClassBodyDeclaration(String body) { + return simplifiedParse(CLASS_BODY, provider(body)); + } - /** - * Parses a Java interface body declaration(e.g fields or methods) and returns a - * {@link BodyDeclaration} that represents it. - * - * @param body the body of an interface - * @return BodyDeclaration representing the Java interface body - * @throws ParseProblemException if the source code has parser errors - */ - public static BodyDeclaration parseInterfaceBodyDeclaration(String body) { - return simplifiedParse(INTERFACE_BODY, provider(body)); - } + /** + * Parses a Java interface body declaration(e.g fields or methods) and returns a + * {@link BodyDeclaration} that represents it. + * + * @param body the body of an interface + * @return BodyDeclaration representing the Java interface body + * @throws ParseProblemException if the source code has parser errors + */ + public static BodyDeclaration parseInterfaceBodyDeclaration(String body) { + return simplifiedParse(INTERFACE_BODY, provider(body)); + } /** * Parses a Java type name and returns a {@link ClassOrInterfaceType} that represents it. diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java index f6a029886..984ffa41b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java @@ -23,7 +23,7 @@ public class ParseProblemException extends RuntimeException { } ParseProblemException(Throwable throwable) { - this(singletonList(new Problem(throwable.getMessage(), Optional.empty(), Optional.of(throwable)))); + this(singletonList(new Problem(throwable.getMessage(), null, throwable))); } private static String createMessage(List<Problem> problems) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java index 6a375906e..1003ea2b3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java @@ -1,23 +1,21 @@ package com.github.javaparser; -import com.github.javaparser.ast.comments.CommentsCollection; +import static com.github.javaparser.utils.Utils.EOL; +import static java.util.Collections.singletonList; import java.util.List; import java.util.Optional; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.Collections.singletonList; - -import static com.github.javaparser.utils.Utils.EOL; +import com.github.javaparser.ast.comments.CommentsCollection; /** * The results given when parsing with an instance of JavaParser. */ public class ParseResult<T> { - private final Optional<T> result; + private final T result; private final List<Problem> problems; - private final Optional<List<Token>> tokens; - private final Optional<CommentsCollection> commentsCollection; + private final List<Token> tokens; + private final CommentsCollection commentsCollection; /** * General constructor. @@ -25,19 +23,19 @@ public class ParseResult<T> { * @param problems a list of encountered parsing problems. * @param tokens the complete list of tokens that were parsed, or empty if parsing failed completely. */ - ParseResult(Optional<T> result, List<Problem> problems, Optional<List<Token>> tokens, Optional<CommentsCollection> commentsCollection) { - this.commentsCollection = assertNotNull(commentsCollection); - this.result = assertNotNull(result); - this.problems = assertNotNull(problems); - this.tokens = assertNotNull(tokens); + ParseResult(T result, List<Problem> problems, List<Token> tokens, CommentsCollection commentsCollection) { + this.commentsCollection = commentsCollection; + this.result = result; + this.problems = problems; + this.tokens = tokens; } /** * Used when parsing failed completely with an exception. */ ParseResult(Throwable throwable) { - this(Optional.empty(), singletonList( - new Problem(createMessage(throwable), Optional.empty(), Optional.of(throwable))), Optional.empty(), Optional.empty()); + this(null, singletonList( + new Problem(createMessage(throwable), null, throwable)), null, null); } private static String createMessage(Throwable throwable) { @@ -52,7 +50,7 @@ public class ParseResult<T> { * @return if parsing was successful, meaning no errors of any kind were encountered. */ public boolean isSuccessful() { - return problems.isEmpty() && result.isPresent(); + return problems.isEmpty() && result != null; } /** @@ -66,21 +64,21 @@ public class ParseResult<T> { * @return the complete list of tokens that were parsed, or empty if parsing failed completely. */ public Optional<List<Token>> getTokens() { - return tokens; + return Optional.ofNullable(tokens); } /** * @return the complete collection of comments encountered while parsing. */ public Optional<CommentsCollection> getCommentsCollection() { - return commentsCollection; + return Optional.ofNullable(commentsCollection); } /** * @return the AST of the parsed source code, or empty if parsing failed completely. */ public Optional<T> getResult() { - return result; + return Optional.ofNullable(result); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/Problem.java b/javaparser-core/src/main/java/com/github/javaparser/Problem.java index 7e45cc987..f346c6c17 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Problem.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Problem.java @@ -2,26 +2,30 @@ package com.github.javaparser; import java.util.Optional; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * A problem that was encountered during parsing. */ public class Problem { private final String message; - private final Optional<Range> range; - private final Optional<Throwable> cause; + private final Range range; + private final Throwable cause; - Problem(String message, Optional<Range> range, Optional<Throwable> cause) { - this.message = assertNotNull(message); - this.range = assertNotNull(range); - this.cause = assertNotNull(cause); + Problem(String message, Range range, Throwable cause) { + this.message = message; + this.range = range; + this.cause = cause; } @Override public String toString() { StringBuilder str = new StringBuilder(message); - range.ifPresent(r -> str.append(" ").append(r)); + if (range != null) + str.append(" ").append(range); + if (cause != null) { + str.append(" stack : ").append(System.lineSeparator()); + for (StackTraceElement ste : cause.getStackTrace()) + str.append(ste.toString()); + } return str.toString(); } @@ -30,10 +34,10 @@ public class Problem { } public Optional<Range> getRange() { - return range; + return Optional.ofNullable(range); } public Optional<Throwable> getCause() { - return cause; + return Optional.ofNullable(cause); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java index da01da8b7..62fd9f4e1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java @@ -1,5 +1,9 @@ package com.github.javaparser.ast; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.Expression; @@ -8,15 +12,12 @@ import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * In <code>new int[1][2];</code> there are two ArrayCreationLevel objects, * the first one contains the expression "1", * the second the expression "2". */ public class ArrayCreationLevel extends Node implements NodeWithAnnotations<ArrayCreationLevel> { - // TODO nullable private Expression dimension; private NodeList<AnnotationExpr> annotations = new NodeList<>(); @@ -51,20 +52,29 @@ public class ArrayCreationLevel extends Node implements NodeWithAnnotations<Arra public <A> void accept(final VoidVisitor<A> v, final A arg) { v.visit(this, arg); } - - public void setDimension(Expression dimension) { + + /** + * Sets the dimension + * + * @param dimension the dimension, can be null + * @return this, the ArrayCreationLevel + */ + public ArrayCreationLevel setDimension(Expression dimension) { this.dimension = dimension; setAsParentNodeOf(dimension); + return this; } - public Expression getDimension() { - return dimension; + public Optional<Expression> getDimension() { + return Optional.ofNullable(dimension); } + @Override public NodeList<AnnotationExpr> getAnnotations() { return annotations; } + @Override public ArrayCreationLevel setAnnotations(NodeList<AnnotationExpr> annotations) { setAsParentNodeOf(annotations); this.annotations = assertNotNull(annotations); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java index 6d34e02f4..fe1ab3529 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java @@ -21,8 +21,20 @@ package com.github.javaparser.ast; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + import com.github.javaparser.Range; -import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.expr.Name; @@ -31,13 +43,6 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.utils.ClassUtils; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.stream.Collectors; - -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * <p> * This class represents the entire compilation unit. Each java file denotes a @@ -57,7 +62,6 @@ import static com.github.javaparser.utils.Utils.assertNotNull; */ public final class CompilationUnit extends Node { - // TODO nullable private PackageDeclaration pakage; private NodeList<ImportDeclaration> imports; @@ -123,8 +127,8 @@ public final class CompilationUnit extends Node { * * @return the package declaration or <code>null</code> */ - public PackageDeclaration getPackage() { - return pakage; + public Optional<PackageDeclaration> getPackage() { + return Optional.ofNullable(pakage); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java index a11d84696..85407a397 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -21,6 +21,17 @@ package com.github.javaparser.ast; +import static java.util.Collections.unmodifiableList; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.IdentityHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + import com.github.javaparser.HasParentNode; import com.github.javaparser.Position; import com.github.javaparser.Range; @@ -33,11 +44,6 @@ import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.printer.PrettyPrinter; import com.github.javaparser.printer.PrettyPrinterConfiguration; -import java.lang.reflect.Field; -import java.util.*; - -import static java.util.Collections.unmodifiableList; - /** * Abstract class for all nodes of the AST. * @@ -196,8 +202,8 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable } @Override - public Node getParentNode() { - return parentNode; + public Optional<Node> getParentNode() { + return Optional.ofNullable(parentNode); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java index eb1bedf45..319bc750c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java @@ -1,13 +1,19 @@ package com.github.javaparser.ast; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + import com.github.javaparser.HasParentNode; -import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; -import java.util.*; -import java.util.stream.Stream; - /** * A list of nodes. * @@ -123,10 +129,16 @@ public class NodeList<N extends Node> implements Iterable<N>, HasParentNode<Node } @Override - public Node getParentNode() { - return parentNode; + public Optional<Node> getParentNode() { + return Optional.ofNullable(parentNode); } + /** + * Sets the parentNode + * + * @param parentNode the parentNode + * @return this, the NodeList + */ @Override public NodeList<N> setParentNode(Node parentNode) { this.parentNode = parentNode; @@ -139,10 +151,12 @@ public class NodeList<N extends Node> implements Iterable<N>, HasParentNode<Node return parentNode; } + @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { return v.visit(this, arg); } + @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { v.visit(this, arg); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java index 9864cc0a8..3b0bf2685 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java @@ -38,6 +38,7 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import java.util.EnumSet; +import java.util.Optional; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -56,7 +57,6 @@ public final class AnnotationMemberDeclaration extends BodyDeclaration<Annotatio private SimpleName name; - // TODO nullable private Expression defaultValue; public AnnotationMemberDeclaration() { @@ -106,8 +106,8 @@ public final class AnnotationMemberDeclaration extends BodyDeclaration<Annotatio v.visit(this, arg); } - public Expression getDefaultValue() { - return defaultValue; + public Optional<Expression> getDefaultValue() { + return Optional.ofNullable(defaultValue); } /** @@ -131,6 +131,11 @@ public final class AnnotationMemberDeclaration extends BodyDeclaration<Annotatio return type; } + /** + * Sets the default value + * @param defaultValue the default value, can be null + * @return this, the AnnotationMemberDeclaration + */ public AnnotationMemberDeclaration setDefaultValue(Expression defaultValue) { this.defaultValue = defaultValue; setAsParentNodeOf(defaultValue); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java index 9a5e9c453..29cc9c950 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -21,28 +21,36 @@ package com.github.javaparser.ast.body; -import static com.github.javaparser.ast.expr.Name.*; -import static com.github.javaparser.ast.type.ArrayType.*; +import static com.github.javaparser.ast.type.ArrayType.unwrapArrayTypes; import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; import static com.github.javaparser.utils.Utils.assertNotNull; import java.util.EnumSet; +import java.util.Optional; import com.github.javaparser.Range; import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.ArrayBracketPair; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.nodeTypes.*; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithElementType; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; +import com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt; +import com.github.javaparser.ast.nodeTypes.NodeWithParameters; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithThrowable; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.ReferenceType; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.utils.Pair; @@ -59,14 +67,14 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> NodeWithModifiers<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrowable<MethodDeclaration>, - NodeWithBlockStmt<MethodDeclaration>, + NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration> { private EnumSet<Modifier> modifiers; private NodeList<TypeParameter> typeParameters; - private Type elementType; + private Type<?> elementType; private SimpleName name; @@ -74,7 +82,6 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> private NodeList<ReferenceType<?>> throws_; - // TODO nullable private BlockStmt body; private boolean isDefault; @@ -98,7 +105,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> new BlockStmt()); } - public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type elementType, final String name) { + public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type<?> elementType, final String name) { this(Range.UNKNOWN, modifiers, new NodeList<>(), @@ -113,7 +120,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> new BlockStmt()); } - public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type elementType, final String name, + public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type<?> elementType, final String name, final NodeList<Parameter> parameters) { this(Range.UNKNOWN, modifiers, @@ -132,7 +139,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, - final Type elementType, + final Type<?> elementType, final NodeList<ArrayBracketPair> arrayBracketPairsAfterElementType, final SimpleName name, final boolean isDefault, @@ -158,7 +165,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, - final Type elementType, + final Type<?> elementType, final NodeList<ArrayBracketPair> arrayBracketPairsAfterElementType, final SimpleName name, final boolean isDefault, @@ -190,8 +197,8 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> } @Override - public BlockStmt getBody() { - return body; + public Optional<BlockStmt> getBody() { + return Optional.ofNullable(body); } /** @@ -221,14 +228,14 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> } @Override - public Type getType() { + public Type<?> getType() { return wrapInArrayTypes(getElementType(), getArrayBracketPairsAfterElementType(), getArrayBracketPairsAfterParameterList()); } @Override - public Type getElementType() { + public Type<?> getElementType() { return elementType; } @@ -237,6 +244,12 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> return typeParameters; } + /** + * Sets the body + * + * @param body the body, can be null + * @return this, the MethodDeclaration + */ @Override public MethodDeclaration setBody(final BlockStmt body) { this.body = body; @@ -272,8 +285,8 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> } @Override - public MethodDeclaration setType(final Type type) { - Pair<Type, NodeList<ArrayBracketPair>> typeListPair = unwrapArrayTypes(assertNotNull(type)); + public MethodDeclaration setType(final Type<?> type) { + Pair<Type<?>, NodeList<ArrayBracketPair>> typeListPair = unwrapArrayTypes(assertNotNull(type)); setElementType(typeListPair.a); setArrayBracketPairsAfterElementType(typeListPair.b); setArrayBracketPairsAfterParameterList(new NodeList<>()); @@ -281,7 +294,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> } @Override - public MethodDeclaration setElementType(final Type elementType) { + public MethodDeclaration setElementType(final Type<?> elementType) { this.elementType = assertNotNull(elementType); setAsParentNodeOf(this.elementType); return this; @@ -370,7 +383,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> sb.append(")"); if (includingThrows) { boolean firstThrow = true; - for (ReferenceType thr : getThrows()) { + for (ReferenceType<?> thr : getThrows()) { if (firstThrow) { firstThrow = false; sb.append(" throws "); @@ -394,6 +407,7 @@ public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> /** * @return the array brackets in this position: <code>class C { int[] abc; }</code> */ + @Override public NodeList<ArrayBracketPair> getArrayBracketPairsAfterElementType() { return arrayBracketPairsAfterType; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java index 59e32e843..27a42bf4b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java @@ -21,6 +21,11 @@ package com.github.javaparser.ast.body; +import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.EnumSet; + import com.github.javaparser.Range; import com.github.javaparser.ast.ArrayBracketPair; import com.github.javaparser.ast.Modifier; @@ -28,7 +33,11 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithElementType; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; @@ -36,11 +45,6 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.utils.Pair; -import java.util.EnumSet; - -import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ @@ -149,8 +153,8 @@ public final class Parameter extends Node implements } @Override - public Parameter setType(Type type) { - Pair<Type, NodeList<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); + public Parameter setType(Type<?> type) { + Pair<Type<?>, NodeList<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); setElementType(unwrapped.a); setArrayBracketPairsAfterElementType(unwrapped.b); getId().setArrayBracketPairsAfterId(new NodeList<>()); @@ -234,6 +238,7 @@ public final class Parameter extends Node implements return this; } + @Override public NodeList<ArrayBracketPair> getArrayBracketPairsAfterElementType() { return arrayBracketPairsAfterType; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java index ec91cf0f7..16eb1fdeb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java @@ -21,6 +21,11 @@ package com.github.javaparser.ast.body; +import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.ArrayBracketPair; import com.github.javaparser.ast.Node; @@ -35,9 +40,6 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.utils.Pair; -import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ @@ -46,7 +48,6 @@ public final class VariableDeclarator extends Node implements private VariableDeclaratorId id; - // TODO nullable private Expression init; public VariableDeclarator() { @@ -97,8 +98,8 @@ public final class VariableDeclarator extends Node implements return id; } - public Expression getInit() { - return init; + public Optional<Expression> getInit() { + return Optional.ofNullable(init); } public VariableDeclarator setId(VariableDeclaratorId id) { @@ -107,6 +108,12 @@ public final class VariableDeclarator extends Node implements return this; } + /** + * Sets the init expression + * + * @param init the init expression, can be null + * @return this, the VariableDeclarator + */ public VariableDeclarator setInit(Expression init) { this.init = init; setAsParentNodeOf(this.init); @@ -115,6 +122,9 @@ public final class VariableDeclarator extends Node implements /** * Will create a {@link NameExpr} with the init param + * + * @param init the init expression, can be null + * @return this, the VariableDeclarator */ public VariableDeclarator setInit(String init) { this.init = new NameExpr(assertNotNull(init)); @@ -133,8 +143,8 @@ public final class VariableDeclarator extends Node implements } @Override - public VariableDeclarator setType(Type type) { - Pair<Type, NodeList<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); + public VariableDeclarator setType(Type<?> type) { + Pair<Type<?>, NodeList<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); NodeWithElementType<?> nodeWithElementType = getAncestorOfType(NodeWithElementType.class); if (nodeWithElementType == null) { throw new IllegalStateException("Cannot set type without a parent"); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java index 83940ebd9..3783c3c43 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java @@ -21,6 +21,8 @@ package com.github.javaparser.ast.comments; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.Node; @@ -35,7 +37,6 @@ import com.github.javaparser.ast.Node; public abstract class Comment extends Node { private String content; - // TODO nullable private Node commentedNode; public Comment(Range range, String content) { @@ -76,11 +77,17 @@ public abstract class Comment extends Node { } } - public Node getCommentedNode() + public Optional<Node> getCommentedNode() { - return this.commentedNode; + return Optional.ofNullable(this.commentedNode); } + /** + * Sets the commentedNode + * + * @param commentedNode the commentedNode, can be null + * @return this, the Comment + */ public Comment setCommentedNode(Node commentedNode) { if (commentedNode==null) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java index 029ecb63f..2c0574734 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java @@ -21,6 +21,10 @@ package com.github.javaparser.ast.expr; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.ArrayCreationLevel; import com.github.javaparser.ast.CompilationUnit; @@ -31,8 +35,6 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * <code>new int[5][4][][]</code> or <code>new int[][]{{1},{2,3}}</code> * @@ -46,7 +48,6 @@ public final class ArrayCreationExpr extends Expression { private Type<?> elementType; - // TODO nullable private ArrayInitializerExpr initializer; public ArrayCreationExpr() { @@ -94,14 +95,20 @@ public final class ArrayCreationExpr extends Expression { v.visit(this, arg); } - public ArrayInitializerExpr getInitializer() { - return initializer; + public Optional<ArrayInitializerExpr> getInitializer() { + return Optional.ofNullable(initializer); } public Type<?> getElementType() { return elementType; } + /** + * Sets the initializer + * + * @param initializer the initializer, can be null + * @return this, the ArrayCreationExpr + */ public ArrayCreationExpr setInitializer(ArrayInitializerExpr initializer) { this.initializer = initializer; setAsParentNodeOf(this.initializer); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java index c7ad84dce..e54cb8cd9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java @@ -21,6 +21,8 @@ package com.github.javaparser.ast.expr; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; @@ -30,7 +32,6 @@ import com.github.javaparser.ast.visitor.VoidVisitor; */ public final class EnclosedExpr extends Expression { - // TODO nullable private Expression inner; public EnclosedExpr() { @@ -54,10 +55,16 @@ public final class EnclosedExpr extends Expression { v.visit(this, arg); } - public Expression getInner() { - return inner; + public Optional<Expression> getInner() { + return Optional.ofNullable(inner); } + /** + * Sets the inner expression + * + * @param inner the inner expression, can be null + * @return this, the EnclosedExpr + */ public EnclosedExpr setInner(final Expression inner) { this.inner = inner; setAsParentNodeOf(this.inner); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java index a7a9cec2d..be3381b06 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java @@ -18,9 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.expr; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; @@ -28,72 +32,89 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class FieldAccessExpr extends Expression implements NodeWithTypeArguments<FieldAccessExpr> { - private Expression scope; + private Expression scope; - // TODO nullable - private NodeList<Type<?>> typeArguments; + private NodeList<Type<?>> typeArguments; - private SimpleName field; + private SimpleName field; - public FieldAccessExpr() { + public FieldAccessExpr() { this(Range.UNKNOWN, new ThisExpr(), new NodeList<>(), new SimpleName()); - } + } - public FieldAccessExpr(final Expression scope, final String field) { + public FieldAccessExpr(final Expression scope, final String field) { this(Range.UNKNOWN, scope, new NodeList<>(), new SimpleName(field)); - } - - public FieldAccessExpr(final Range range, final Expression scope, final NodeList<Type<?>> typeArguments, final SimpleName field) { - super(range); - setScope(scope); - setTypeArguments(typeArguments); - setField(field); - } - - @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { - return v.visit(this, arg); - } - - @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { - v.visit(this, arg); - } - - public SimpleName getField() { - return field; - } - - public Expression getScope() { - return scope; - } - - public FieldAccessExpr setField(SimpleName field) { - this.field = assertNotNull(field); + } + + public FieldAccessExpr(final Range range, final Expression scope, final NodeList<Type<?>> typeArguments, + final SimpleName field) { + super(range); + setScope(scope); + setTypeArguments(typeArguments); + setFieldExpr(field); + } + + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + public SimpleName getField() { + return field; + } + + public Optional<Expression> getScope() { + return Optional.ofNullable(scope); + } + + public FieldAccessExpr setField(final String field) { + setFieldExpr(new SimpleName(field)); + return this; + } + + public FieldAccessExpr setFieldExpr(SimpleName field) { + this.field = assertNotNull(field); setAsParentNodeOf(this.field); - return this; - } - - public FieldAccessExpr setScope(final Expression scope) { - this.scope = scope; - setAsParentNodeOf(this.scope); - return this; - } - - @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; - } - - @Override - public FieldAccessExpr setTypeArguments(final NodeList<Type<?>> types) { - this.typeArguments = types; - setAsParentNodeOf(this.typeArguments); - return this; - } + return this; + } + + /** + * Sets the scope + * + * @param scope the scope, can be null + * @return this, the FieldAccessExpr + */ + public FieldAccessExpr setScope(final Expression scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + @Override + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the type arguments + * + * @param types the type arguments, can be null + * @return this, the FieldAccessExpr + */ + @Override + public FieldAccessExpr setTypeArguments(final NodeList<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java index dec687cf5..901fee265 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java @@ -21,6 +21,10 @@ package com.github.javaparser.ast.expr; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.nodeTypes.NodeWithArguments; @@ -30,8 +34,6 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ @@ -40,10 +42,8 @@ public final class MethodCallExpr extends Expression implements NodeWithArguments<MethodCallExpr>, NodeWithSimpleName<MethodCallExpr> { - // TODO nullable private Expression scope; - // TODO nullable private NodeList<Type<?>> typeArguments; private SimpleName name; @@ -113,6 +113,7 @@ public final class MethodCallExpr extends Expression implements return this; } + @Override public MethodCallExpr setName(final SimpleName name) { this.name = name; setAsParentNodeOf(this.name); @@ -126,10 +127,16 @@ public final class MethodCallExpr extends Expression implements } @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); } + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the MethodCallExpr + */ @Override public MethodCallExpr setTypeArguments(final NodeList<Type<?>> types) { this.typeArguments = types; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java index 9ffa110f9..422afb489 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java @@ -21,6 +21,8 @@ package com.github.javaparser.ast.expr; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; @@ -42,7 +44,6 @@ public class MethodReferenceExpr extends Expression implements NodeWithTypeArgum private Expression scope; - // TODO nullable private NodeList<Type<?>> typeArguments; private String identifier; @@ -84,10 +85,16 @@ public class MethodReferenceExpr extends Expression implements NodeWithTypeArgum } @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); } + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the MethodReferenceExpr + */ @Override public MethodReferenceExpr setTypeArguments(final NodeList<Type<?>> types) { this.typeArguments = types; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java index 272b662d5..9b8b62adb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java @@ -21,19 +21,21 @@ package com.github.javaparser.ast.expr; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.nodeTypes.NodeWithArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * Defines constructor call expression. * Example: @@ -43,17 +45,15 @@ import static com.github.javaparser.utils.Utils.assertNotNull; * * @author Julio Vilmar Gesser */ -public final class ObjectCreationExpr extends Expression implements +public final class ObjectCreationExpr extends Expression implements NodeWithTypeArguments<ObjectCreationExpr>, NodeWithType<ObjectCreationExpr, ClassOrInterfaceType>, NodeWithArguments<ObjectCreationExpr> { - // TODO nullable private Expression scope; private ClassOrInterfaceType type; - // TODO nullable private NodeList<Type<?>> typeArguments; private NodeList<Expression> args; @@ -62,7 +62,7 @@ public final class ObjectCreationExpr extends Expression implements private NodeList<BodyDeclaration<?>> anonymousClassBody; public ObjectCreationExpr() { - this(Range.UNKNOWN, + this(Range.UNKNOWN, null, new ClassOrInterfaceType(), new NodeList<>(), @@ -77,7 +77,8 @@ public final class ObjectCreationExpr extends Expression implements * @param type this is the class that the constructor is being called for. * @param args Any arguments to pass to the constructor */ - public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList<Expression> args) { + public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, + final NodeList<Expression> args) { this(Range.UNKNOWN, scope, type, @@ -86,16 +87,17 @@ public final class ObjectCreationExpr extends Expression implements new NodeList<>()); } - public ObjectCreationExpr(final Range range, - final Expression scope, final ClassOrInterfaceType type, final NodeList<Type<?>> typeArguments, + public ObjectCreationExpr(final Range range, + final Expression scope, final ClassOrInterfaceType type, + final NodeList<Type<?>> typeArguments, final NodeList<Expression> args, final NodeList<BodyDeclaration<?>> anonymousBody) { - super(range); - setScope(scope); - setType(type); - setTypeArguments(typeArguments); - setArgs(args); - setAnonymousClassBody(anonymousBody); - } + super(range); + setScope(scope); + setType(type); + setTypeArguments(typeArguments); + setArgs(args); + setAnonymousClassBody(anonymousBody); + } @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { @@ -107,11 +109,8 @@ public final class ObjectCreationExpr extends Expression implements v.visit(this, arg); } - /** - * This can be null, to indicate there is no body - */ - public NodeList<BodyDeclaration<?>> getAnonymousClassBody() { - return anonymousClassBody; + public Optional<NodeList<BodyDeclaration<?>>> getAnonymousClassBody() { + return Optional.ofNullable(anonymousClassBody); } public void addAnonymousClassBody(BodyDeclaration<?> body) { @@ -120,12 +119,13 @@ public final class ObjectCreationExpr extends Expression implements anonymousClassBody.add(body); } + @Override public NodeList<Expression> getArgs() { return args; } - public Expression getScope() { - return scope; + public Optional<Expression> getScope() { + return Optional.ofNullable(scope); } @Override @@ -133,6 +133,12 @@ public final class ObjectCreationExpr extends Expression implements return type; } + /** + * Sets the anonymousClassBody + * + * @param anonymousClassBody the anonymousClassBody, can be null + * @return this, the ObjectCreationExpr + */ public ObjectCreationExpr setAnonymousClassBody(final NodeList<BodyDeclaration<?>> anonymousClassBody) { this.anonymousClassBody = anonymousClassBody; setAsParentNodeOf(this.anonymousClassBody); @@ -146,6 +152,12 @@ public final class ObjectCreationExpr extends Expression implements return this; } + /** + * Sets the scope + * + * @param scope the scope, can be null + * @return this, the FieldAccessExpr + */ public ObjectCreationExpr setScope(final Expression scope) { this.scope = scope; setAsParentNodeOf(this.scope); @@ -161,10 +173,16 @@ public final class ObjectCreationExpr extends Expression implements } @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); } + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ObjectCreationExpr + */ @Override public ObjectCreationExpr setTypeArguments(final NodeList<Type<?>> typeArguments) { this.typeArguments = typeArguments; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java index 2f75be16b..d925811b1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java @@ -21,6 +21,8 @@ package com.github.javaparser.ast.expr; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; @@ -30,7 +32,6 @@ import com.github.javaparser.ast.visitor.VoidVisitor; */ public final class SuperExpr extends Expression { - // TODO nullable private Expression classExpr; public SuperExpr() { @@ -54,10 +55,16 @@ public final class SuperExpr extends Expression { v.visit(this, arg); } - public Expression getClassExpr() { - return classExpr; + public Optional<Expression> getClassExpr() { + return Optional.ofNullable(classExpr); } + /** + * Sets the classExpr + * + * @param classExpr the classExpr, can be null + * @return this, the SuperExpr + */ public SuperExpr setClassExpr(final Expression classExpr) { this.classExpr = classExpr; setAsParentNodeOf(this.classExpr); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java new file mode 100644 index 000000000..34ce423d3 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes;
+
+import java.util.Optional;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.stmt.BlockStmt;
+
+public interface NodeWithOptionalBlockStmt<N extends Node> {
+ Optional<BlockStmt> getBody();
+
+ N setBody(BlockStmt block);
+
+ default BlockStmt createBody() {
+ BlockStmt block = new BlockStmt();
+ setBody(block);
+ block.setParentNode((Node) this);
+
+ return block;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java index 9adbe46ec..da9f39ab5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java @@ -33,6 +33,7 @@ public interface NodeWithSimpleName<T> { T setName(SimpleName name); + @SuppressWarnings("unchecked") default T setName(String name){ setName(new SimpleName(name)); return (T) this; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java index 45f0623fd..9e1f40b36 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -1,5 +1,6 @@ package com.github.javaparser.ast.nodeTypes;
+import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.Expression;
@@ -32,8 +33,14 @@ public interface NodeWithStatements<N extends Node> { return addStatement(statement);
}
+ /**
+ * It will use {@link JavaParser#parseStatement(String)} inside, so it should end with a semi column
+ *
+ * @param statement
+ * @return
+ */
default N addStatement(String statement) {
- return addStatement(new NameExpr(statement));
+ return addStatement(JavaParser.parseStatement(statement));
}
default N addStatement(int index, final Expression expr) {
@@ -63,8 +70,20 @@ public interface NodeWithStatements<N extends Node> { default ExpressionStmt addAndGetStatement(String statement) {
return addAndGetStatement(new NameExpr(statement));
}
-
+
default boolean isEmpty() {
return getStmts().isEmpty();
}
+
+ @SuppressWarnings("unchecked")
+ default N copyStatements(NodeList<Statement> nodeList) {
+ for (Statement n : nodeList) {
+ addStatement((Statement) n.clone());
+ }
+ return (N) this;
+ }
+
+ default N copyStatements(NodeWithStatements<?> other) {
+ return copyStatements(other.getStmts());
+ }
}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java index dbcf51588..75681f6d4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -21,42 +21,44 @@ package com.github.javaparser.ast.nodeTypes; +import static com.github.javaparser.ast.NodeList.nodeList; + +import java.util.Optional; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.type.Type; -import static com.github.javaparser.ast.NodeList.nodeList; - /** * A node that can have type arguments. + * * <pre> - * new X(); --> typeArguments == null + * new X(); --> typeArguments == Optional is empty * new X<>(); --> typeArguments = [], diamondOperator = true * new X<C,D>(); --> typeArguments = [C,D], diamondOperator = false * </pre> */ public interface NodeWithTypeArguments<N extends Node> { /** - * @return the types that can be found in the type arguments: <String, Integer>. + * @return the types that can be found in the type arguments: <String, Integer>. */ - // TODO nullable - NodeList<Type<?>> getTypeArguments(); + Optional<NodeList<Type<?>>> getTypeArguments(); /** * Allows you to set the generic arguments - * @param typeArguments The list of types of the generics + * + * @param typeArguments The list of types of the generics, can be null */ - // TODO nullable N setTypeArguments(NodeList<Type<?>> typeArguments); /** * @return whether the type arguments look like <>. */ default boolean isUsingDiamondOperator() { - if(getTypeArguments()==null){ + if (!getTypeArguments().isPresent()) { return false; } - return getTypeArguments().isEmpty(); + return getTypeArguments().get().isEmpty(); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java index c10abda76..d265a1b05 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java @@ -18,70 +18,79 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.expr.BooleanLiteralExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class AssertStmt extends Statement { - private Expression check; + private Expression check; - // TODO nullable - private Expression msg; + private Expression msg; - public AssertStmt() { + public AssertStmt() { this(Range.UNKNOWN, new BooleanLiteralExpr(), null); - } + } - public AssertStmt(final Expression check) { - this(Range.UNKNOWN, check, null); - } + public AssertStmt(final Expression check) { + this(Range.UNKNOWN, check, null); + } - public AssertStmt(final Expression check, final Expression msg) { + public AssertStmt(final Expression check, final Expression msg) { this(Range.UNKNOWN, check, msg); - } - - public AssertStmt(final Range range, final Expression check, final Expression msg) { - super(range); - setCheck(check); - setMessage(msg); - } - - @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { - return v.visit(this, arg); - } - - @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { - v.visit(this, arg); - } - - public Expression getCheck() { - return check; - } - - public Expression getMessage() { - return msg; - } - - public AssertStmt setCheck(final Expression check) { - this.check = assertNotNull(check); - setAsParentNodeOf(this.check); - return this; - } - - public AssertStmt setMessage(final Expression msg) { - this.msg = msg; - setAsParentNodeOf(this.msg); - return this; - } + } + + public AssertStmt(final Range range, final Expression check, final Expression msg) { + super(range); + setCheck(check); + setMessage(msg); + } + + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + public Expression getCheck() { + return check; + } + + public Optional<Expression> getMessage() { + return Optional.ofNullable(msg); + } + + public AssertStmt setCheck(final Expression check) { + this.check = assertNotNull(check); + setAsParentNodeOf(this.check); + return this; + } + + /** + * Sets the message + * + * @param msg the message, can be null + * @return this, the AssertStmt + */ + public AssertStmt setMessage(final Expression msg) { + this.msg = msg; + setAsParentNodeOf(this.msg); + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java index fbb0af26f..8c54f98d8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java @@ -18,50 +18,59 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class BreakStmt extends Statement { - // TODO nullable - private String id; + private String id; - public BreakStmt() { + public BreakStmt() { this(Range.UNKNOWN, "empty"); - } + } - public BreakStmt(final String id) { - this(Range.UNKNOWN, id); - } + public BreakStmt(final String id) { + this(Range.UNKNOWN, id); + } - public BreakStmt(final Range range, final String id) { - super(range); - this.id = id; - } + public BreakStmt(final Range range, final String id) { + super(range); + this.id = id; + } - @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { - return v.visit(this, arg); - } + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } - @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { - v.visit(this, arg); - } + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } - public String getId() { - return id; - } + public Optional<String> getId() { + return Optional.ofNullable(id); + } - public BreakStmt setId(final String id) { - this.id = assertNotNull(id); - return this; - } + /** + * Sets the id + * + * @param id the id, can be null + * @return this, the BreakStmt + */ + public BreakStmt setId(final String id) { + this.id = assertNotNull(id); + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java index 2326a6121..a7e3e09ec 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java @@ -21,6 +21,10 @@ package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; @@ -30,7 +34,6 @@ import com.github.javaparser.ast.visitor.VoidVisitor; */ public final class ContinueStmt extends Statement { - // TODO nullable private String id; public ContinueStmt() { @@ -54,12 +57,18 @@ public final class ContinueStmt extends Statement { v.visit(this, arg); } - public String getId() { - return id; - } + public Optional<String> getId() { + return Optional.ofNullable(id); + } - public ContinueStmt setId(final String id) { - this.id = id; - return this; - } + /** + * Sets the id + * + * @param id the id, can be null + * @return this, the ContinueStmt + */ + public ContinueStmt setId(final String id) { + this.id = assertNotNull(id); + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java index 31f592ee6..60fa6d120 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java @@ -21,6 +21,10 @@ package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; @@ -29,20 +33,15 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.ast.NodeList.*; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class ExplicitConstructorInvocationStmt extends Statement implements NodeWithTypeArguments<ExplicitConstructorInvocationStmt> { - // TODO nullable private NodeList<Type<?>> typeArguments; private boolean isThis; - // TODO nullable private Expression expr; private NodeList<Expression> args; @@ -80,8 +79,8 @@ public final class ExplicitConstructorInvocationStmt extends Statement implement return args; } - public Expression getExpr() { - return expr; + public Optional<Expression> getExpr() { + return Optional.ofNullable(expr); } public boolean isThis() { @@ -94,6 +93,12 @@ public final class ExplicitConstructorInvocationStmt extends Statement implement return this; } + /** + * Sets the expr + * + * @param expr the expression, can be null + * @return this, the ExplicitConstructorInvocationStmt + */ public ExplicitConstructorInvocationStmt setExpr(final Expression expr) { this.expr = expr; setAsParentNodeOf(this.expr); @@ -106,10 +111,16 @@ public final class ExplicitConstructorInvocationStmt extends Statement implement } @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); } + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ExplicitConstructorInvocationStmt + */ @Override public ExplicitConstructorInvocationStmt setTypeArguments(final NodeList<Type<?>> types) { this.typeArguments = types; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java index 9e63a5055..6e70215d3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java @@ -18,9 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.BooleanLiteralExpr; @@ -29,94 +33,97 @@ import com.github.javaparser.ast.nodeTypes.NodeWithBody; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class ForStmt extends Statement implements NodeWithBody<ForStmt> { - private NodeList<Expression> init; + private NodeList<Expression> init; - // TODO nullable - private Expression compare; + private Expression compare; - private NodeList<Expression> update; + private NodeList<Expression> update; - private Statement body; + private Statement body; - public ForStmt() { - this(Range.UNKNOWN, - new NodeList<>(), - new BooleanLiteralExpr(), - new NodeList<>(), - new EmptyStmt()); - } + public ForStmt() { + this(Range.UNKNOWN, + new NodeList<>(), + new BooleanLiteralExpr(), + new NodeList<>(), + new EmptyStmt()); + } - public ForStmt(final NodeList<Expression> init, final Expression compare, - final NodeList<Expression> update, final Statement body) { + public ForStmt(final NodeList<Expression> init, final Expression compare, + final NodeList<Expression> update, final Statement body) { this(Range.UNKNOWN, init, compare, update, body); - } - - public ForStmt(Range range, - final NodeList<Expression> init, final Expression compare, - final NodeList<Expression> update, final Statement body) { - super(range); - setCompare(compare); - setInit(init); - setUpdate(update); - setBody(body); - } - - @Override - public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { - return v.visit(this, arg); - } - - @Override - public <A> void accept(final VoidVisitor<A> v, final A arg) { - v.visit(this, arg); - } - - @Override + } + + public ForStmt(Range range, + final NodeList<Expression> init, final Expression compare, + final NodeList<Expression> update, final Statement body) { + super(range); + setCompare(compare); + setInit(init); + setUpdate(update); + setBody(body); + } + + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Override public Statement getBody() { - return body; - } + return body; + } - public Expression getCompare() { - return compare; - } + public Optional<Expression> getCompare() { + return Optional.ofNullable(compare); + } - public NodeList<Expression> getInit() { + public NodeList<Expression> getInit() { return init; - } + } - public NodeList<Expression> getUpdate() { + public NodeList<Expression> getUpdate() { return update; - } + } - @Override + @Override public ForStmt setBody(final Statement body) { - this.body = body; - setAsParentNodeOf(this.body); + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + /** + * Sets the compare + * + * @param compare the compare, can be null + * @return this, the ForStmt + */ + public ForStmt setCompare(final Expression compare) { + this.compare = compare; + setAsParentNodeOf(this.compare); + return this; + } + + public ForStmt setInit(final NodeList<Expression> init) { + this.init = assertNotNull(init); + setAsParentNodeOf(this.init); + return this; + } + + public ForStmt setUpdate(final NodeList<Expression> update) { + this.update = assertNotNull(update); + setAsParentNodeOf(this.update); return this; - } - - public ForStmt setCompare(final Expression compare) { - this.compare = compare; - setAsParentNodeOf(this.compare); - return this; - } - - public ForStmt setInit(final NodeList<Expression> init) { - this.init = assertNotNull(init); - setAsParentNodeOf(this.init); - return this; - } - - public ForStmt setUpdate(final NodeList<Expression> update) { - this.update = assertNotNull(update); - setAsParentNodeOf(this.update); - return this; - } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java index bcd8ec72b..91e713bf4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java @@ -21,14 +21,16 @@ package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.expr.BooleanLiteralExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ @@ -38,7 +40,6 @@ public final class IfStmt extends Statement { private Statement thenStmt; - // TODO nullable private Statement elseStmt; public IfStmt() { @@ -72,8 +73,8 @@ public final class IfStmt extends Statement { return condition; } - public Statement getElseStmt() { - return elseStmt; + public Optional<Statement> getElseStmt() { + return Optional.ofNullable(elseStmt); } public Statement getThenStmt() { @@ -86,6 +87,12 @@ public final class IfStmt extends Statement { return this; } + /** + * Sets the elseStmt + * + * @param elseStmt the elseStmt, can be null + * @return this, the IfStmt + */ public IfStmt setElseStmt(final Statement elseStmt) { this.elseStmt = elseStmt; setAsParentNodeOf(this.elseStmt); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java index bf5f9ed7e..45b5a6271 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java @@ -18,9 +18,11 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.stmt; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.NameExpr; @@ -32,21 +34,20 @@ import com.github.javaparser.ast.visitor.VoidVisitor; */ public final class ReturnStmt extends Statement { - // TODO nullable - private Expression expr; + private Expression expr; - public ReturnStmt() { + public ReturnStmt() { this(Range.UNKNOWN, null); - } + } - public ReturnStmt(final Expression expr) { - this(Range.UNKNOWN, expr); - } + public ReturnStmt(final Expression expr) { + this(Range.UNKNOWN, expr); + } - public ReturnStmt(Range range, final Expression expr) { - super(range); - setExpr(expr); - } + public ReturnStmt(Range range, final Expression expr) { + super(range); + setExpr(expr); + } /** * Will create a NameExpr with the string param @@ -57,21 +58,26 @@ public final class ReturnStmt extends Statement { @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { - return v.visit(this, arg); - } + return v.visit(this, arg); + } - @Override - public <A> void accept(final VoidVisitor<A> v, final A arg) { - v.visit(this, arg); - } + @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } - public Expression getExpr() { - return expr; - } + public Optional<Expression> getExpr() { + return Optional.ofNullable(expr); + } - public ReturnStmt setExpr(final Expression expr) { - this.expr = expr; - setAsParentNodeOf(this.expr); - return this; - } + /** + * Sets the expr + * + * @param expr the expr, can be null + * @return this, the ReturnStmt + */ + public ReturnStmt setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java index e33918cc7..412e5073b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java @@ -21,22 +21,22 @@ package com.github.javaparser.ast.stmt; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.expr.CharLiteralExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.nodeTypes.NodeWithStatements; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class SwitchEntryStmt extends Statement implements NodeWithStatements<SwitchEntryStmt> { - // TODO nullable private Expression label; private NodeList<Statement> stmts; @@ -66,8 +66,8 @@ public final class SwitchEntryStmt extends Statement implements NodeWithStatemen v.visit(this, arg); } - public Expression getLabel() { - return label; + public Optional<Expression> getLabel() { + return Optional.ofNullable(label); } @Override @@ -75,6 +75,12 @@ public final class SwitchEntryStmt extends Statement implements NodeWithStatemen return stmts; } + /** + * Sets the label + * + * @param label the label, can be null + * @return this, the SwitchEntryStmt + */ public SwitchEntryStmt setLabel(final Expression label) { this.label = label; setAsParentNodeOf(this.label); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java index 5f185aa1e..4142eb1ee 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java @@ -1,5 +1,8 @@ package com.github.javaparser.ast.type; +import static com.github.javaparser.ast.NodeList.nodeList; +import static com.github.javaparser.utils.Utils.assertNotNull; + import com.github.javaparser.Range; import com.github.javaparser.ast.ArrayBracketPair; import com.github.javaparser.ast.NodeList; @@ -9,9 +12,6 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.utils.Pair; -import static com.github.javaparser.ast.NodeList.*; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * To indicate that a type is an array, it gets wrapped in an ArrayType for every array level it has. * So, int[][] becomes ArrayType(ArrayType(int)). @@ -70,7 +70,7 @@ public class ArrayType extends ReferenceType<ArrayType> implements NodeWithAnnot * * @return a pair of the element type, and the unwrapped ArrayTypes, if any. */ - public static Pair<Type, NodeList<ArrayBracketPair>> unwrapArrayTypes(Type type) { + public static Pair<Type<?>, NodeList<ArrayBracketPair>> unwrapArrayTypes(Type<?> type) { final NodeList<ArrayBracketPair> arrayBracketPairs = new NodeList<>(); while (type instanceof ArrayType) { ArrayType arrayType = (ArrayType) type; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java index 41fe1f401..055f82c3f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -21,6 +21,10 @@ package com.github.javaparser.ast.type; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.SimpleName; @@ -29,23 +33,18 @@ import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; - -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * @author Julio Vilmar Gesser */ public final class ClassOrInterfaceType extends ReferenceType<ClassOrInterfaceType> implements - NodeWithSimpleName<ClassOrInterfaceType>, + NodeWithSimpleName<ClassOrInterfaceType>, NodeWithAnnotations<ClassOrInterfaceType>, NodeWithTypeArguments<ClassOrInterfaceType> { - // TODO nullable private ClassOrInterfaceType scope; private SimpleName name; - // TODO nullable private NodeList<Type<?>> typeArguments; public ClassOrInterfaceType() { @@ -69,23 +68,31 @@ public final class ClassOrInterfaceType extends ReferenceType<ClassOrInterfaceTy null); } - public ClassOrInterfaceType(final Range range, final ClassOrInterfaceType scope, final SimpleName name, final NodeList<Type<?>> typeArguments) { + public ClassOrInterfaceType(final Range range, final ClassOrInterfaceType scope, final SimpleName name, + final NodeList<Type<?>> typeArguments) { super(range); setScope(scope); setName(name); setTypeArguments(typeArguments); } - @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { return v.visit(this, arg); } - @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { v.visit(this, arg); } - public ClassOrInterfaceType getScope() { - return scope; + @Override + public SimpleName getName() { + return name; + } + + public Optional<ClassOrInterfaceType> getScope() { + return Optional.ofNullable(scope); } public boolean isBoxedType() { @@ -100,16 +107,17 @@ public final class ClassOrInterfaceType extends ReferenceType<ClassOrInterfaceTy } @Override - public SimpleName getName() { - return name; - } - - @Override public ClassOrInterfaceType setName(final SimpleName name) { - this.name = assertNotNull(name); + this.name = assertNotNull(name); return this; } + /** + * Sets the scope + * + * @param scope the scope, can be null + * @return this, the ClassOrInterfaceType + */ public ClassOrInterfaceType setScope(final ClassOrInterfaceType scope) { this.scope = scope; setAsParentNodeOf(this.scope); @@ -117,10 +125,16 @@ public final class ClassOrInterfaceType extends ReferenceType<ClassOrInterfaceTy } @Override - public NodeList<Type<?>> getTypeArguments() { - return typeArguments; + public Optional<NodeList<Type<?>>> getTypeArguments() { + return Optional.ofNullable(typeArguments); } + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ClassOrInterfaceType + */ @Override public ClassOrInterfaceType setTypeArguments(final NodeList<Type<?>> types) { this.typeArguments = types; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java index 77d5b0661..d0ccbd40a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java @@ -21,6 +21,8 @@ package com.github.javaparser.ast.type; +import java.util.Optional; + import com.github.javaparser.Range; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; @@ -32,11 +34,9 @@ import com.github.javaparser.ast.visitor.VoidVisitor; */ public final class WildcardType extends Type<WildcardType> implements NodeWithAnnotations<WildcardType> { - // TODO nullable - private ReferenceType ext; + private ReferenceType<?> ext; - // TODO nullable - private ReferenceType sup; + private ReferenceType<?> sup; public WildcardType() { this(Range.UNKNOWN, null, null); @@ -65,21 +65,33 @@ public final class WildcardType extends Type<WildcardType> implements NodeWithAn v.visit(this, arg); } - public ReferenceType getExtends() { - return ext; + public Optional<ReferenceType<?>> getExtends() { + return Optional.ofNullable(ext); } - public ReferenceType getSuper() { - return sup; + public Optional<ReferenceType<?>> getSuper() { + return Optional.ofNullable(sup); } - public WildcardType setExtends(final ReferenceType ext) { + /** + * Sets the extends + * + * @param ext the extends, can be null + * @return this, the WildcardType + */ + public WildcardType setExtends(final ReferenceType<?> ext) { this.ext = ext; setAsParentNodeOf(this.ext); return this; } - public WildcardType setSuper(final ReferenceType sup) { + /** + * Sets the super + * + * @param sup the super, can be null + * @return this, the WildcardType + */ + public WildcardType setSuper(final ReferenceType<?> sup) { this.sup = sup; setAsParentNodeOf(this.sup); return this; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java index 5e3742613..b0ab53080 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -21,16 +21,111 @@ package com.github.javaparser.ast.visitor; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import java.util.Optional; + +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EmptyMemberDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.ImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; public class CloneVisitor implements GenericVisitor<Visitable, Object> { @@ -165,7 +260,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { public Visitable visit(AnnotationMemberDeclaration _n, Object _arg) { NodeList<AnnotationExpr> annotations = cloneList(_n.getAnnotations(), _arg); Type<?> type_ = cloneNode(_n.getType(), _arg); - Expression defaultValue = cloneNode(_n.getDefaultValue(), _arg); + Expression defaultValue = cloneNode(_n.getDefaultValue(), _arg); Comment comment = cloneNode(_n.getComment(), _arg); AnnotationMemberDeclaration r = new AnnotationMemberDeclaration( @@ -333,7 +428,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { @Override public Visitable visit(ClassOrInterfaceType _n, Object _arg) { ClassOrInterfaceType scope = cloneNode(_n.getScope(), _arg); - NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments(), _arg); + NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments().orElse(null), _arg); Comment comment = cloneNode(_n.getComment(), _arg); ClassOrInterfaceType r = new ClassOrInterfaceType( @@ -568,7 +663,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { @Override public Visitable visit(FieldAccessExpr _n, Object _arg) { Expression scope_ = cloneNode(_n.getScope(), _arg); - NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments(), _arg); + NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments().orElse(null), _arg); SimpleName fieldExpr_ = cloneNode(_n.getField(), _arg); Comment comment = cloneNode(_n.getComment(), _arg); @@ -697,7 +792,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { @Override public Visitable visit(MethodCallExpr _n, Object _arg) { Expression scope_ = cloneNode(_n.getScope(), _arg); - NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments(), _arg); + NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments().orElse(null), _arg); NodeList<Expression> args = cloneList(_n.getArgs(), _arg); SimpleName nameExpr = cloneNode(_n.getName(), _arg); Comment comment = cloneNode(_n.getComment(), _arg); @@ -729,9 +824,9 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { public Visitable visit(ObjectCreationExpr _n, Object _arg) { Expression scope = cloneNode(_n.getScope(), _arg); ClassOrInterfaceType type_ = cloneNode(_n.getType(), _arg); - NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments(), _arg); + NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments().orElse(null), _arg); NodeList<Expression> args = cloneList(_n.getArgs(), _arg); - NodeList<BodyDeclaration<?>> anonymousBody = cloneList(_n.getAnonymousClassBody(), _arg); + NodeList<BodyDeclaration<?>> anonymousBody = cloneList(_n.getAnonymousClassBody().orElse(null), _arg); Comment comment = cloneNode(_n.getComment(), _arg); ObjectCreationExpr r = new ObjectCreationExpr( @@ -876,7 +971,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { @Override public Visitable visit(ExplicitConstructorInvocationStmt _n, Object _arg) { - NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments(), _arg); + NodeList<Type<?>> typeArguments_ = cloneList(_n.getTypeArguments().orElse(null), _arg); Expression expr_ = cloneNode(_n.getExpr(), _arg); NodeList<Expression> args = cloneList(_n.getArgs(), _arg); Comment comment = cloneNode(_n.getComment(), _arg); @@ -1001,7 +1096,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { BreakStmt r = new BreakStmt( _n.getRange(), - _n.getId() + _n.getId().orElse(null) ); r.setComment(comment); return r; @@ -1055,7 +1150,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { ContinueStmt r = new ContinueStmt( _n.getRange(), - _n.getId() + _n.getId().orElse(null) ); r.setComment(comment); return r; @@ -1174,7 +1269,7 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { public Visitable visit(MethodReferenceExpr _n, Object arg) { Expression scope = cloneNode(_n.getScope(), arg); - NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments(), arg); + NodeList<Type<?>> typeArguments = cloneList(_n.getTypeArguments().orElse(null), arg); return new MethodReferenceExpr(_n.getRange(), scope, typeArguments, _n.getIdentifier()); @@ -1268,6 +1363,18 @@ public class CloneVisitor implements GenericVisitor<Visitable, Object> { } @SuppressWarnings("unchecked") + protected <T extends Node> T cloneNode(Optional<T> _node, Object _arg) { + if (!_node.isPresent()) { + return null; + } + Node r = (Node) _node.get().accept(this, _arg); + if (r == null) { + return null; + } + return (T) r; + } + + @SuppressWarnings("unchecked") protected <T extends Node> T cloneNode(T _node, Object _arg) { if (_node == null) { return null; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java index e29b5faea..5974ac4a5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java @@ -21,17 +21,103 @@ package com.github.javaparser.ast.visitor; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import java.util.List; + +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EmptyMemberDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -import java.util.List; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; /** * @author Julio Vilmar Gesser @@ -123,7 +209,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final CompilationUnit n1, final Visitable arg) { final CompilationUnit n2 = (CompilationUnit) arg; - if (!nodeEquals(n1.getPackage(), n2.getPackage())) { + if (!nodeEquals(n1.getPackage().orElse(null), n2.getPackage().orElse(null))) { return false; } @@ -341,7 +427,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getDefaultValue(), n2.getDefaultValue())) { + if (!nodeEquals(n1.getDefaultValue().orElse(null), n2.getDefaultValue().orElse(null))) { return false; } @@ -387,7 +473,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getInit(), n2.getInit())) { + if (!nodeEquals(n1.getInit().orElse(null), n2.getInit().orElse(null))) { return false; } @@ -473,7 +559,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getBody(), n2.getBody())) { + if (!nodeEquals(n1.getBody().orElse(null), n2.getBody().orElse(null))) { return false; } @@ -554,11 +640,11 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getScope(), n2.getScope())) { + if (!nodeEquals(n1.getScope().orElse(null), n2.getScope().orElse(null))) { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } @@ -598,7 +684,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { public Boolean visit(ArrayCreationLevel n1, Visitable arg) { final ArrayCreationLevel n2 = (ArrayCreationLevel) arg; - if (!nodeEquals(n1.getDimension(), n2.getDimension())) { + if (!nodeEquals(n1.getDimension().orElse(null), n2.getDimension().orElse(null))) { return false; } if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { @@ -677,11 +763,11 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final WildcardType n1, final Visitable arg) { final WildcardType n2 = (WildcardType) arg; - if (!nodeEquals(n1.getExtends(), n2.getExtends())) { + if (!nodeEquals(n1.getExtends().orElse(null), n2.getExtends().orElse(null))) { return false; } - if (!nodeEquals(n1.getSuper(), n2.getSuper())) { + if (!nodeEquals(n1.getSuper().orElse(null), n2.getSuper().orElse(null))) { return false; } if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { @@ -719,7 +805,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getInitializer(), n2.getInitializer())) { + if (!nodeEquals(n1.getInitializer().orElse(null), n2.getInitializer().orElse(null))) { return false; } @@ -817,7 +903,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final EnclosedExpr n1, final Visitable arg) { final EnclosedExpr n2 = (EnclosedExpr) arg; - if (!nodeEquals(n1.getInner(), n2.getInner())) { + if (!nodeEquals(n1.getInner().orElse(null), n2.getInner().orElse(null))) { return false; } @@ -827,7 +913,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final FieldAccessExpr n1, final Visitable arg) { final FieldAccessExpr n2 = (FieldAccessExpr) arg; - if (!nodeEquals(n1.getScope(), n2.getScope())) { + if (!nodeEquals(n1.getScope().orElse(null), n2.getScope().orElse(null))) { return false; } @@ -835,7 +921,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } @@ -955,7 +1041,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } @@ -975,7 +1061,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final ObjectCreationExpr n1, final Visitable arg) { final ObjectCreationExpr n2 = (ObjectCreationExpr) arg; - if (!nodeEquals(n1.getScope(), n2.getScope())) { + if (!nodeEquals(n1.getScope().orElse(null), n2.getScope().orElse(null))) { return false; } @@ -983,7 +1069,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodesEquals(n1.getAnonymousClassBody(), n2.getAnonymousClassBody())) { + if (!nodesEquals(n1.getAnonymousClassBody().orElse(null), n2.getAnonymousClassBody().orElse(null))) { return false; } @@ -991,7 +1077,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } @@ -1032,7 +1118,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final SuperExpr n1, final Visitable arg) { final SuperExpr n2 = (SuperExpr) arg; - if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) { + if (!nodeEquals(n1.getClassExpr().orElse(null), n2.getClassExpr().orElse(null))) { return false; } @@ -1134,7 +1220,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final ExplicitConstructorInvocationStmt n1, final Visitable arg) { final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg; - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + if (!nodeEquals(n1.getExpr().orElse(null), n2.getExpr().orElse(null))) { return false; } @@ -1142,7 +1228,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } @@ -1166,7 +1252,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getMessage(), n2.getMessage())) { + if (!nodeEquals(n1.getMessage().orElse(null), n2.getMessage().orElse(null))) { return false; } @@ -1224,7 +1310,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final SwitchEntryStmt n1, final Visitable arg) { final SwitchEntryStmt n2 = (SwitchEntryStmt) arg; - if (!nodeEquals(n1.getLabel(), n2.getLabel())) { + if (!nodeEquals(n1.getLabel().orElse(null), n2.getLabel().orElse(null))) { return false; } @@ -1248,7 +1334,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { @Override public Boolean visit(final ReturnStmt n1, final Visitable arg) { final ReturnStmt n2 = (ReturnStmt) arg; - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + if (!nodeEquals(n1.getExpr().orElse(null), n2.getExpr().orElse(null))) { return false; } @@ -1266,7 +1352,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) { + if (!nodeEquals(n1.getElseStmt().orElse(null), n2.getElseStmt().orElse(null))) { return false; } @@ -1336,7 +1422,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { return false; } - if (!nodeEquals(n1.getCompare(), n2.getCompare())) { + if (!nodeEquals(n1.getCompare().orElse(null), n2.getCompare().orElse(null))) { return false; } @@ -1432,7 +1518,7 @@ public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> { if (!nodeEquals(n1.getScope(), n2.getScope())) { return false; } - if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + if (!nodesEquals(n1.getTypeArguments().orElse(null), n2.getTypeArguments().orElse(null))) { return false; } if (!objEquals(n1.getIdentifier(), n2.getIdentifier())) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java index 995cc621a..d2d7806d2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java @@ -18,672 +18,769 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.visitor; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EmptyMemberDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.ImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; /** * @author Julio Vilmar Gesser */ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A> { - @Override - public R visit(final AnnotationDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { + @Override + public R visit(final AnnotationDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getMembers() != null) { for (final BodyDeclaration<?> member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final AnnotationMemberDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getDefaultValue() != null) { - { - R result = n.getDefaultValue().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ArrayAccessExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getIndex().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ArrayCreationExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getElementType().accept(this, arg); - if (result != null) { - return result; - } - } - for(ArrayCreationLevel level: n.getLevels()){ - R result = level.accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getInitializer() != null) { - R result = n.getInitializer().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ArrayInitializerExpr n, final A arg) { - visitComment(n, arg); - if (n.getValues() != null) { - for (final Expression expr : n.getValues()) { - { - R result = expr.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final AssertStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getCheck().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getMessage() != null) { - { - R result = n.getMessage().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final AssignExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getTarget().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final BinaryExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getLeft().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getRight().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final BlockStmt n, final A arg) { - visitComment(n, arg); - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - { - R result = s.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - - } - - @Override - public R visit(final BooleanLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final BreakStmt n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final CastExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final CatchClause n, final A arg) { - visitComment(n, arg); - { - R result = n.getParam().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - - } - - @Override - public R visit(final CharLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final ClassExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ClassOrInterfaceDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getExtends() != null) { - for (final ClassOrInterfaceType c : n.getExtends()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { + { + R result = member.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final AnnotationMemberDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getDefaultValue().isPresent()) { + { + R result = n.getDefaultValue().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final ArrayAccessExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getIndex().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ArrayCreationExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getElementType().accept(this, arg); + if (result != null) { + return result; + } + } + for (ArrayCreationLevel level : n.getLevels()) { + R result = level.accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getInitializer().isPresent()) { + R result = n.getInitializer().get().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ArrayInitializerExpr n, final A arg) { + visitComment(n, arg); + if (n.getValues() != null) { + for (final Expression expr : n.getValues()) { + { + R result = expr.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final AssertStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getCheck().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getMessage().isPresent()) { + { + R result = n.getMessage().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final AssignExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getTarget().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getValue().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final BinaryExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getLeft().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getRight().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final BlockStmt n, final A arg) { + visitComment(n, arg); + if (n.getStmts() != null) { + for (final Statement s : n.getStmts()) { + { + R result = s.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + + } + + @Override + public R visit(final BooleanLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final BreakStmt n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final CastExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getExpr().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final CatchClause n, final A arg) { + visitComment(n, arg); + { + R result = n.getParam().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + + } + + @Override + public R visit(final CharLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final ClassExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ClassOrInterfaceDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getTypeParameters() != null) { + for (final TypeParameter t : n.getTypeParameters()) { + { + R result = t.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getExtends() != null) { + for (final ClassOrInterfaceType c : n.getExtends()) { + { + R result = c.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + + if (n.getImplements() != null) { + for (final ClassOrInterfaceType c : n.getImplements()) { + { + R result = c.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getMembers() != null) { for (final BodyDeclaration<?> member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ClassOrInterfaceType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { - R result = type.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final CompilationUnit n, final A arg) { - visitComment(n, arg); - if (n.getPackage() != null) { - { - R result = n.getPackage().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getImports() != null) { - for (final ImportDeclaration i : n.getImports()) { - { - R result = i.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypes() != null) { + { + R result = member.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final ClassOrInterfaceType n, final A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getScope().isPresent()) { + { + R result = n.getScope().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { + R result = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final CompilationUnit n, final A arg) { + visitComment(n, arg); + if (n.getPackage().isPresent()) { + { + R result = n.getPackage().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getImports() != null) { + for (final ImportDeclaration i : n.getImports()) { + { + R result = i.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getTypes() != null) { for (final TypeDeclaration<?> typeDeclaration : n.getTypes()) { - { - R result = typeDeclaration.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ConditionalExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getThenExpr().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getElseExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ConstructorDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - { - R result = p.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getThrows() != null) { - for (final ReferenceType name : n.getThrows()) { - { - R result = name.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ContinueStmt n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final DoStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final DoubleLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final EmptyMemberDeclaration n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final EmptyStmt n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final EmptyTypeDeclaration n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final EnclosedExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getInner().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final EnumConstantDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getClassBody() != null) { + { + R result = typeDeclaration.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final ConditionalExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getCondition().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getThenExpr().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getElseExpr().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ConstructorDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getTypeParameters() != null) { + for (final TypeParameter t : n.getTypeParameters()) { + { + R result = t.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getParameters() != null) { + for (final Parameter p : n.getParameters()) { + { + R result = p.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getThrows() != null) { + for (final ReferenceType name : n.getThrows()) { + { + R result = name.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ContinueStmt n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final DoStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getCondition().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final DoubleLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final EmptyMemberDeclaration n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final EmptyStmt n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final EmptyTypeDeclaration n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final EnclosedExpr n, final A arg) { + visitComment(n, arg); + { + if (n.getInner().isPresent()) { + R result = n.getInner().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final EnumConstantDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getClassBody() != null) { for (final BodyDeclaration<?> member : n.getClassBody()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final EnumDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getEntries() != null) { - for (final EnumConstantDeclaration e : n.getEntries()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { + { + R result = member.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final EnumDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getImplements() != null) { + for (final ClassOrInterfaceType c : n.getImplements()) { + { + R result = c.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getEntries() != null) { + for (final EnumConstantDeclaration e : n.getEntries()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getMembers() != null) { for (final BodyDeclaration<?> member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ExplicitConstructorInvocationStmt n, final A arg) { - visitComment(n, arg); - if (!n.isThis() && n.getExpr() != null) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { - R result = type.accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ExpressionStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getExpression().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final FieldAccessExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - { - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { + { + R result = member.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final ExplicitConstructorInvocationStmt n, final A arg) { + visitComment(n, arg); + if (!n.isThis() && n.getExpr().isPresent()) { + { + R result = n.getExpr().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { + R result = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final ExpressionStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getExpression().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final FieldAccessExpr n, final A arg) { + visitComment(n, arg); + { + if (n.getScope().isPresent()) { + R result = n.getScope().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + { + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { R result = type.accept(this, arg); if (result != null) { return result; @@ -691,472 +788,471 @@ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A } } } - return null; - } - - @Override - public R visit(final FieldDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getElementType().accept(this, arg); - if (result != null) { - return result; - } - } - for (final VariableDeclarator var : n.getVariables()) { - { - R result = var.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ForeachStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getVariable().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getIterable().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ForStmt n, final A arg) { - visitComment(n, arg); - if (n.getInit() != null) { - for (final Expression e : n.getInit()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getCompare() != null) { - { - R result = n.getCompare().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getUpdate() != null) { - for (final Expression e : n.getUpdate()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final IfStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getThenStmt().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getElseStmt() != null) { - { - R result = n.getElseStmt().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final InitializerDeclaration n, final A arg) { - visitComment(n, arg); - { - R result = n.getBlock().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final InstanceOfExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final IntegerLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final IntegerLiteralMinValueExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final JavadocComment n, final A arg) { - return null; - } - - @Override - public R visit(final LabeledStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getStmt().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final LongLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final LongLiteralMinValueExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final MarkerAnnotationExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final MemberValuePair n, final A arg) { - visitComment(n, arg); - { - R result = n.getValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final MethodCallExpr n, final A arg) { - visitComment(n, arg); - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { - R result = type.accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final MethodDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getElementType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - { - R result = p.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getThrows() != null) { - for (final ReferenceType name : n.getThrows()) { - { - R result = name.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getBody() != null) { - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final NameExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final NormalAnnotationExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getPairs() != null) { - for (final MemberValuePair m : n.getPairs()) { - { - R result = m.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final NullLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final ObjectCreationExpr n, final A arg) { - visitComment(n, arg); - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { - R result = type.accept(this, arg); - if (result != null) { - return result; - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getAnonymousClassBody() != null) { - for (final BodyDeclaration<?> member : n.getAnonymousClassBody()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final PackageDeclaration n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final Parameter n, final A arg) { - visitComment(n, arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getElementType().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getId().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final PrimitiveType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final Name n, final A arg) { - visitComment(n, arg); - if(n.getQualifier()!=null) - { - R result = n.getQualifier().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } + return null; + } + + @Override + public R visit(final FieldDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getElementType().accept(this, arg); + if (result != null) { + return result; + } + } + for (final VariableDeclarator var : n.getVariables()) { + { + R result = var.accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final ForeachStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getVariable().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getIterable().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ForStmt n, final A arg) { + visitComment(n, arg); + if (n.getInit() != null) { + for (final Expression e : n.getInit()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getCompare().isPresent()) { + { + R result = n.getCompare().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getUpdate() != null) { + for (final Expression e : n.getUpdate()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final IfStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getCondition().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getThenStmt().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getElseStmt().isPresent()) { + { + R result = n.getElseStmt().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final InitializerDeclaration n, final A arg) { + visitComment(n, arg); + { + R result = n.getBlock().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final InstanceOfExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getExpr().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final IntegerLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final IntegerLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final JavadocComment n, final A arg) { + return null; + } + + @Override + public R visit(final LabeledStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getStmt().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final LongLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final LongLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final MarkerAnnotationExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final MemberValuePair n, final A arg) { + visitComment(n, arg); + { + R result = n.getValue().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final MethodCallExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope() != null) { + { + R result = n.getScope().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { + R result = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final MethodDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getTypeParameters() != null) { + for (final TypeParameter t : n.getTypeParameters()) { + { + R result = t.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getElementType().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getParameters() != null) { + for (final Parameter p : n.getParameters()) { + { + R result = p.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getThrows() != null) { + for (final ReferenceType<?> name : n.getThrows()) { + { + R result = name.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getBody().isPresent()) { + { + R result = n.getBody().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final NameExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final NormalAnnotationExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getPairs() != null) { + for (final MemberValuePair m : n.getPairs()) { + { + R result = m.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final NullLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final ObjectCreationExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope().isPresent()) { + { + R result = n.getScope().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { + R result = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getAnonymousClassBody().isPresent()) { + for (final BodyDeclaration<?> member : n.getAnonymousClassBody().get()) { + { + R result = member.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final PackageDeclaration n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final Parameter n, final A arg) { + visitComment(n, arg); + if (n.getAnnotations() != null) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getElementType().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getId().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final PrimitiveType n, final A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final Name n, final A arg) { + visitComment(n, arg); + if (n.getQualifier() != null) { + R result = n.getQualifier().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } @Override public R visit(SimpleName n, A arg) { @@ -1165,52 +1261,52 @@ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A } @Override - public R visit(ArrayType n, A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getComponentType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(ArrayCreationLevel n, A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - { - if(n.getDimension()!=null) { - R result = n.getDimension().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override + public R visit(ArrayType n, A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getComponentType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(ArrayCreationLevel n, A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + { + if (n.getDimension().isPresent()) { + R result = n.getDimension().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override public R visit(final IntersectionType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } { for (ReferenceType element : n.getElements()) { R result = element.accept(this, arg); @@ -1224,13 +1320,13 @@ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A @Override public R visit(final UnionType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } { for (ReferenceType element : n.getElements()) { R result = element.accept(this, arg); @@ -1242,373 +1338,373 @@ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A return null; } - @Override - public R visit(final ReturnStmt n, final A arg) { - visitComment(n, arg); - if (n.getExpr() != null) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final SingleMemberAnnotationExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getMemberValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final StringLiteralExpr n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final SuperExpr n, final A arg) { - visitComment(n, arg); - if (n.getClassExpr() != null) { - { - R result = n.getClassExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final SwitchEntryStmt n, final A arg) { - visitComment(n, arg); - if (n.getLabel() != null) { - { - R result = n.getLabel().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - { - R result = s.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final SwitchStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getSelector().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getEntries() != null) { - for (final SwitchEntryStmt e : n.getEntries()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - - } - - @Override - public R visit(final SynchronizedStmt n, final A arg) { - visitComment(n, arg); - { - if (n.getExpr() != null) { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ThisExpr n, final A arg) { - visitComment(n, arg); - if (n.getClassExpr() != null) { - { - R result = n.getClassExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ThrowStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final TryStmt n, final A arg) { - visitComment(n, arg); - if (n.getResources() != null) { - for (final VariableDeclarationExpr v : n.getResources()) { - { - R result = v.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getTryBlock().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getCatchs() != null) { - for (final CatchClause c : n.getCatchs()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getFinallyBlock() != null) { - { - R result = n.getFinallyBlock().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final TypeDeclarationStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getTypeDeclaration().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final TypeParameter n, final A arg) { - visitComment(n, arg); - if (n.getTypeBound() != null) { - for (final ClassOrInterfaceType c : n.getTypeBound()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final UnaryExpr n, final A arg) { - visitComment(n, arg); - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final UnknownType n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final VariableDeclarationExpr n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getElementType().accept(this, arg); - if (result != null) { - return result; - } - } - for (final VariableDeclarator v : n.getVariables()) { - { - R result = v.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final VariableDeclarator n, final A arg) { - visitComment(n, arg); - { - R result = n.getId().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getInit() != null) { - { - R result = n.getInit().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final VariableDeclaratorId n, final A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(final VoidType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final WhileStmt n, final A arg) { - visitComment(n, arg); - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final WildcardType n, final A arg) { - visitComment(n, arg); - for (final AnnotationExpr a : n.getAnnotations()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getExtends() != null) { - { - R result = n.getExtends().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getSuper() != null) { - { - R result = n.getSuper().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } + @Override + public R visit(final ReturnStmt n, final A arg) { + visitComment(n, arg); + if (n.getExpr().isPresent()) { + { + R result = n.getExpr().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final SingleMemberAnnotationExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getMemberValue().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final StringLiteralExpr n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final SuperExpr n, final A arg) { + visitComment(n, arg); + if (n.getClassExpr().isPresent()) { + { + R result = n.getClassExpr().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final SwitchEntryStmt n, final A arg) { + visitComment(n, arg); + if (n.getLabel().isPresent()) { + { + R result = n.getLabel().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getStmts() != null) { + for (final Statement s : n.getStmts()) { + { + R result = s.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final SwitchStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getSelector().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getEntries() != null) { + for (final SwitchEntryStmt e : n.getEntries()) { + { + R result = e.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + + } + + @Override + public R visit(final SynchronizedStmt n, final A arg) { + visitComment(n, arg); + { + if (n.getExpr() != null) { + R result = n.getExpr().accept(this, arg); + if (result != null) { + return result; + } + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final ThisExpr n, final A arg) { + visitComment(n, arg); + if (n.getClassExpr() != null) { + { + R result = n.getClassExpr().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final ThrowStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getExpr().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final TryStmt n, final A arg) { + visitComment(n, arg); + if (n.getResources() != null) { + for (final VariableDeclarationExpr v : n.getResources()) { + { + R result = v.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + { + R result = n.getTryBlock().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getCatchs() != null) { + for (final CatchClause c : n.getCatchs()) { + { + R result = c.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + if (n.getFinallyBlock() != null) { + { + R result = n.getFinallyBlock().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final TypeDeclarationStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getTypeDeclaration().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final TypeParameter n, final A arg) { + visitComment(n, arg); + if (n.getTypeBound() != null) { + for (final ClassOrInterfaceType c : n.getTypeBound()) { + { + R result = c.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + return null; + } + + @Override + public R visit(final UnaryExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getExpr().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final UnknownType n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final VariableDeclarationExpr n, final A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getElementType().accept(this, arg); + if (result != null) { + return result; + } + } + for (final VariableDeclarator v : n.getVariables()) { + { + R result = v.accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final VariableDeclarator n, final A arg) { + visitComment(n, arg); + { + R result = n.getId().accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getInit().isPresent()) { + { + R result = n.getInit().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(final VariableDeclaratorId n, final A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(final VoidType n, final A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final WhileStmt n, final A arg) { + visitComment(n, arg); + { + R result = n.getCondition().accept(this, arg); + if (result != null) { + return result; + } + } + { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final WildcardType n, final A arg) { + visitComment(n, arg); + for (final AnnotationExpr a : n.getAnnotations()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + if (n.getExtends().isPresent()) { + { + R result = n.getExtends().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getSuper().isPresent()) { + { + R result = n.getSuper().get().accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } @Override public R visit(LambdaExpr n, A arg) { - visitComment(n, arg); - if (n.getParameters() != null) { - for (final Parameter a : n.getParameters()) { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getBody() != null) { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; + visitComment(n, arg); + if (n.getParameters() != null) { + for (final Parameter a : n.getParameters()) { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + if (n.getBody() != null) { + R result = n.getBody().accept(this, arg); + if (result != null) { + return result; + } + } + return null; } @Override public R visit(MethodReferenceExpr n, A arg) { visitComment(n, arg); { - if (n.getTypeArguments() != null) { - for (Type<?> type : n.getTypeArguments()) { + if (n.getTypeArguments().isPresent()) { + for (Type<?> type : n.getTypeArguments().get()) { R result = type.accept(this, arg); if (result != null) { return result; @@ -1617,120 +1713,120 @@ public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A } } if (n.getScope() != null) { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(TypeExpr n, A arg){ - visitComment(n, arg); - if (n.getType() != null) { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(ArrayBracketPair n, A arg) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(EmptyImportDeclaration n, A arg) { - visitComment(n, arg); - return null; - } - - @Override - public R visit(SingleStaticImportDeclaration n, A arg) { - visitComment(n, arg); - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(SingleTypeImportDeclaration n, A arg) { - visitComment(n, arg); - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(StaticImportOnDemandDeclaration n, A arg) { - visitComment(n, arg); - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(TypeImportOnDemandDeclaration n, A arg) { - visitComment(n, arg); - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final BlockComment n, final A arg) { - return null; - } - - @Override - public R visit(final LineComment n, final A arg) { - return null; - } - - @Override - public R visit(NodeList n, A arg) { - for (final Object v : n) { - R result = ((Node) v).accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - private void visitComment(Node n, A arg) { - if(n.getComment()!=null){ - Comment result = (Comment) n.getComment().accept(this, arg); - if(result!=null){ - n.setComment(result); - } - } - } + R result = n.getScope().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(TypeExpr n, A arg) { + visitComment(n, arg); + if (n.getType() != null) { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(ArrayBracketPair n, A arg) { + for (final AnnotationExpr a : n.getAnnotations()) { + { + R result = a.accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @Override + public R visit(EmptyImportDeclaration n, A arg) { + visitComment(n, arg); + return null; + } + + @Override + public R visit(SingleStaticImportDeclaration n, A arg) { + visitComment(n, arg); + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(SingleTypeImportDeclaration n, A arg) { + visitComment(n, arg); + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(StaticImportOnDemandDeclaration n, A arg) { + visitComment(n, arg); + { + R result = n.getType().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(TypeImportOnDemandDeclaration n, A arg) { + visitComment(n, arg); + { + R result = n.getName().accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + public R visit(final BlockComment n, final A arg) { + return null; + } + + @Override + public R visit(final LineComment n, final A arg) { + return null; + } + + @Override + public R visit(NodeList n, A arg) { + for (final Object v : n) { + R result = ((Node) v).accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + private void visitComment(Node n, A arg) { + if (n.getComment() != null) { + Comment result = (Comment) n.getComment().accept(this, arg); + if (result != null) { + n.setComment(result); + } + } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java index d36737d9d..136d5a3e0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java @@ -18,22 +18,115 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.visitor; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import java.util.List; + +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EmptyMemberDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.ImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -import java.util.List; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; /** * This visitor adapter can be used to save time when some specific nodes needs @@ -44,485 +137,542 @@ import java.util.List; */ public class ModifierVisitorAdapter<A> implements GenericVisitor<Visitable, A> { - private void removeNulls(final List<?> list) { - for (int i = list.size() - 1; i >= 0; i--) { - if (list.get(i) == null) { - list.remove(i); - } - } - } - - @Override public Visitable visit(final AnnotationDeclaration n, final A arg) { - visitAnnotations(n, arg); - visitComment(n, arg); + private void removeNulls(final List<?> list) { + for (int i = list.size() - 1; i >= 0; i--) { + if (list.get(i) == null) { + list.remove(i); + } + } + } + + @Override + public Visitable visit(final AnnotationDeclaration n, final A arg) { + visitAnnotations(n, arg); + visitComment(n, arg); n.setMembers((NodeList<BodyDeclaration<?>>) n.getMembers().accept(this, arg)); - return n; - } - - private void visitAnnotations(NodeWithAnnotations<?> n, A arg) { - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - } - - @Override public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - n.setType((Type) n.getType().accept(this, arg)); - if (n.getDefaultValue() != null) { - n.setDefaultValue((Expression) n.getDefaultValue().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final ArrayAccessExpr n, final A arg) { - visitComment(n, arg); - n.setName((Expression) n.getName().accept(this, arg)); - n.setIndex((Expression) n.getIndex().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ArrayCreationExpr n, final A arg) { - visitComment(n, arg); - n.setElementType((Type) n.getElementType().accept(this, arg)); - - n.setLevels((NodeList<ArrayCreationLevel>)n.getLevels().accept(this, arg)); - - if (n.getInitializer() != null) { - n.setInitializer((ArrayInitializerExpr) n.getInitializer().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final ArrayInitializerExpr n, final A arg) { - visitComment(n, arg); - n.setValues((NodeList<Expression>)n.getValues().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final AssertStmt n, final A arg) { - visitComment(n, arg); - n.setCheck((Expression) n.getCheck().accept(this, arg)); - if (n.getMessage() != null) { - n.setMessage((Expression) n.getMessage().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final AssignExpr n, final A arg) { - visitComment(n, arg); - final Expression target = (Expression) n.getTarget().accept(this, arg); - if (target == null) { - return null; - } + return n; + } + + private void visitAnnotations(NodeWithAnnotations<?> n, A arg) { + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + } + + @Override + public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + n.setType((Type) n.getType().accept(this, arg)); + if (n.getDefaultValue().isPresent()) { + n.setDefaultValue((Expression) n.getDefaultValue().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final ArrayAccessExpr n, final A arg) { + visitComment(n, arg); + n.setName((Expression) n.getName().accept(this, arg)); + n.setIndex((Expression) n.getIndex().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ArrayCreationExpr n, final A arg) { + visitComment(n, arg); + n.setElementType((Type) n.getElementType().accept(this, arg)); + + n.setLevels((NodeList<ArrayCreationLevel>) n.getLevels().accept(this, arg)); + + if (n.getInitializer().isPresent()) { + n.setInitializer((ArrayInitializerExpr) n.getInitializer().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final ArrayInitializerExpr n, final A arg) { + visitComment(n, arg); + n.setValues((NodeList<Expression>) n.getValues().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final AssertStmt n, final A arg) { + visitComment(n, arg); + n.setCheck((Expression) n.getCheck().accept(this, arg)); + if (n.getMessage().isPresent()) { + n.setMessage((Expression) n.getMessage().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final AssignExpr n, final A arg) { + visitComment(n, arg); + final Expression target = (Expression) n.getTarget().accept(this, arg); + if (target == null) { + return null; + } n.setTarget(target); - final Expression value = (Expression) n.getValue().accept(this, arg); - if (value == null) { - return null; - } - n.setValue(value); - - return n; - } - - @Override public Visitable visit(final BinaryExpr n, final A arg) { - visitComment(n, arg); - final Expression left = (Expression) n.getLeft().accept(this, arg); - final Expression right = (Expression) n.getRight().accept(this, arg); - if (left == null) { - return right; - } - if (right == null) { - return left; - } - n.setLeft(left); - n.setRight(right); - return n; - } - - @Override public Visitable visit(final BlockStmt n, final A arg) { - visitComment(n, arg); - n.setStmts((NodeList<Statement>) n.getStmts().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final BooleanLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final BreakStmt n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final CastExpr n, final A arg) { - visitComment(n, arg); - final Type type = (Type) n.getType().accept(this, arg); - final Expression expr = (Expression) n.getExpr().accept(this, arg); - if (type == null) { - return expr; - } - if (expr == null) { - return null; - } - n.setType(type); - n.setExpr(expr); - return n; - } - - @Override public Visitable visit(final CatchClause n, final A arg) { - visitComment(n, arg); - n.setParam((Parameter)n.getParam().accept(this, arg)); - n.setBody((BlockStmt) n.getBody().accept(this, arg)); - return n; - - } - - @Override public Visitable visit(final CharLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final ClassExpr n, final A arg) { - visitComment(n, arg); - n.setType((Type) n.getType().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) { - visitAnnotations(n, arg); - visitComment(n, arg); - n.setTypeParameters(modifyList(n.getTypeParameters(), arg)); - n.setExtends(modifyList(n.getExtends(), arg)); - n.setImplements(modifyList(n.getImplements(), arg)); - n.setMembers((NodeList<BodyDeclaration<?>>) n.getMembers().accept(this, arg)); - return n; - } + final Expression value = (Expression) n.getValue().accept(this, arg); + if (value == null) { + return null; + } + n.setValue(value); + + return n; + } + + @Override + public Visitable visit(final BinaryExpr n, final A arg) { + visitComment(n, arg); + final Expression left = (Expression) n.getLeft().accept(this, arg); + final Expression right = (Expression) n.getRight().accept(this, arg); + if (left == null) { + return right; + } + if (right == null) { + return left; + } + n.setLeft(left); + n.setRight(right); + return n; + } + + @Override + public Visitable visit(final BlockStmt n, final A arg) { + visitComment(n, arg); + n.setStmts((NodeList<Statement>) n.getStmts().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final BooleanLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final BreakStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final CastExpr n, final A arg) { + visitComment(n, arg); + final Type type = (Type) n.getType().accept(this, arg); + final Expression expr = (Expression) n.getExpr().accept(this, arg); + if (type == null) { + return expr; + } + if (expr == null) { + return null; + } + n.setType(type); + n.setExpr(expr); + return n; + } + + @Override + public Visitable visit(final CatchClause n, final A arg) { + visitComment(n, arg); + n.setParam((Parameter) n.getParam().accept(this, arg)); + n.setBody((BlockStmt) n.getBody().accept(this, arg)); + return n; + + } + + @Override + public Visitable visit(final CharLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final ClassExpr n, final A arg) { + visitComment(n, arg); + n.setType((Type) n.getType().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) { + visitAnnotations(n, arg); + visitComment(n, arg); + n.setTypeParameters(modifyList(n.getTypeParameters(), arg)); + n.setExtends(modifyList(n.getExtends(), arg)); + n.setImplements(modifyList(n.getImplements(), arg)); + n.setMembers((NodeList<BodyDeclaration<?>>) n.getMembers().accept(this, arg)); + return n; + } private <N extends Node> NodeList<N> modifyList(NodeList<N> list, A arg) { - if(list==null){ + if (list == null) { return null; } return (NodeList<N>) list.accept(this, arg); } - @Override public Visitable visit(final ClassOrInterfaceType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - if (n.getScope() != null) { - n.setScope((ClassOrInterfaceType) n.getScope().accept(this, arg)); - } - n.setTypeArguments(modifyList(n.getTypeArguments(), arg)); - return n; - } - - @Override public Visitable visit(final CompilationUnit n, final A arg) { - visitComment(n, arg); - if (n.getPackage() != null) { - n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg)); - } - n.setImports((NodeList<ImportDeclaration> )n.getImports().accept(this, arg)); - n.setTypes((NodeList<TypeDeclaration<?>> )n.getTypes().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ConditionalExpr n, final A arg) { - visitComment(n, arg); - n.setCondition((Expression) n.getCondition().accept(this, arg)); - n.setThenExpr((Expression) n.getThenExpr().accept(this, arg)); - n.setElseExpr((Expression) n.getElseExpr().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ConstructorDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); + @Override + public Visitable visit(final ClassOrInterfaceType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + if (n.getScope().isPresent()) { + n.setScope((ClassOrInterfaceType) n.getScope().get().accept(this, arg)); + } + n.setTypeArguments(modifyList(n.getTypeArguments().orElse(null), arg)); + return n; + } + + @Override + public Visitable visit(final CompilationUnit n, final A arg) { + visitComment(n, arg); + if (n.getPackage().isPresent()) { + n.setPackage((PackageDeclaration) n.getPackage().get().accept(this, arg)); + } + n.setImports((NodeList<ImportDeclaration>) n.getImports().accept(this, arg)); + n.setTypes((NodeList<TypeDeclaration<?>>) n.getTypes().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ConditionalExpr n, final A arg) { + visitComment(n, arg); + n.setCondition((Expression) n.getCondition().accept(this, arg)); + n.setThenExpr((Expression) n.getThenExpr().accept(this, arg)); + n.setElseExpr((Expression) n.getElseExpr().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ConstructorDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); n.setTypeParameters(modifyList(n.getTypeParameters(), arg)); - n.setParameters((NodeList<Parameter>)n.getParameters().accept(this, arg)); - n.setThrows((NodeList<ReferenceType<?>>)n.getThrows().accept(this, arg)); - n.setBody((BlockStmt) n.getBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ContinueStmt n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final DoStmt n, final A arg) { - visitComment(n, arg); - final Statement body = (Statement) n.getBody().accept(this, arg); - if (body == null) { - return null; - } - n.setBody(body); - - final Expression condition = (Expression) n.getCondition().accept(this, arg); - if (condition == null) { - return null; - } - n.setCondition(condition); - - return n; - } - - @Override public Visitable visit(final DoubleLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final EmptyMemberDeclaration n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final EmptyStmt n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final EmptyTypeDeclaration n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final EnclosedExpr n, final A arg) { - visitComment(n, arg); - n.setInner((Expression) n.getInner().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final EnumConstantDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - n.setArgs((NodeList<Expression>)n.getArgs().accept(this, arg)); - n.setClassBody((NodeList<BodyDeclaration<?>>)n.getClassBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final EnumDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - n.setImplements((NodeList<ClassOrInterfaceType>) n.getImplements().accept(this, arg)); - n.setEntries((NodeList<EnumConstantDeclaration>)n.getEntries().accept(this, arg)); + n.setParameters((NodeList<Parameter>) n.getParameters().accept(this, arg)); + n.setThrows((NodeList<ReferenceType<?>>) n.getThrows().accept(this, arg)); + n.setBody((BlockStmt) n.getBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ContinueStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final DoStmt n, final A arg) { + visitComment(n, arg); + final Statement body = (Statement) n.getBody().accept(this, arg); + if (body == null) { + return null; + } + n.setBody(body); + + final Expression condition = (Expression) n.getCondition().accept(this, arg); + if (condition == null) { + return null; + } + n.setCondition(condition); + + return n; + } + + @Override + public Visitable visit(final DoubleLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final EmptyMemberDeclaration n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final EmptyStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final EmptyTypeDeclaration n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final EnclosedExpr n, final A arg) { + visitComment(n, arg); + if (n.getInner().isPresent()) + n.setInner((Expression) n.getInner().get().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final EnumConstantDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + n.setArgs((NodeList<Expression>) n.getArgs().accept(this, arg)); + n.setClassBody((NodeList<BodyDeclaration<?>>) n.getClassBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final EnumDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + n.setImplements((NodeList<ClassOrInterfaceType>) n.getImplements().accept(this, arg)); + n.setEntries((NodeList<EnumConstantDeclaration>) n.getEntries().accept(this, arg)); n.setMembers((NodeList<BodyDeclaration<?>>) n.getMembers().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ExplicitConstructorInvocationStmt n, final A arg) { - visitComment(n, arg); - if (!n.isThis() && n.getExpr() != null) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - } - n.setTypeArguments(modifyList(n.getTypeArguments(), arg)); - n.setArgs((NodeList<Expression>)n.getArgs().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ExpressionStmt n, final A arg) { - visitComment(n, arg); - final Expression expr = (Expression) n.getExpression().accept(this, arg); - if (expr == null) { - return null; - } - n.setExpression(expr); - return n; - } - - @Override public Visitable visit(final FieldAccessExpr n, final A arg) { - visitComment(n, arg); - final Expression scope = (Expression) n.getScope().accept(this, arg); - if (scope == null) { - return null; - } - n.setScope(scope); - return n; - } - - @Override public Visitable visit(final FieldDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - n.setElementType((Type) n.getElementType().accept(this, arg)); - n.setVariables((NodeList<VariableDeclarator>)n.getVariables().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ForeachStmt n, final A arg) { - visitComment(n, arg); - n.setVariable((VariableDeclarationExpr) n.getVariable().accept(this, arg)); - n.setIterable((Expression) n.getIterable().accept(this, arg)); - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ForStmt n, final A arg) { - visitComment(n, arg); - n.setInit((NodeList<Expression>)n.getInit().accept(this, arg)); - if (n.getCompare() != null) { - n.setCompare((Expression) n.getCompare().accept(this, arg)); - } - n.setUpdate((NodeList<Expression>)n.getUpdate().accept(this, arg)); - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final IfStmt n, final A arg) { - visitComment(n, arg); - final Expression condition = (Expression) - n.getCondition().accept(this, arg); - if (condition == null) { - return null; - } - n.setCondition(condition); - final Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg); - if (thenStmt == null) { - // Remove the entire statement if the then-clause was removed. - // PrettyPrintVisitor, used for toString, has no null check for the - // then-clause. - return null; - } - n.setThenStmt(thenStmt); - if (n.getElseStmt() != null) { - n.setElseStmt((Statement) n.getElseStmt().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final InitializerDeclaration n, final A arg) { - visitComment(n, arg); - n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final InstanceOfExpr n, final A arg) { - visitComment(n, arg); - n.setExpr((Expression) n.getExpr().accept(this, arg)); - n.setType((ReferenceType<?>) n.getType().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final IntegerLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final IntegerLiteralMinValueExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final JavadocComment n, final A arg) { - return n; - } - - @Override public Visitable visit(final LabeledStmt n, final A arg) { - visitComment(n, arg); - n.setStmt((Statement) n.getStmt().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final LongLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final LongLiteralMinValueExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final MarkerAnnotationExpr n, final A arg) { - visitComment(n, arg); - n.setName((Name) n.getName().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final MemberValuePair n, final A arg) { - visitComment(n, arg); - n.setValue((Expression) n.getValue().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final MethodCallExpr n, final A arg) { - visitComment(n, arg); - if (n.getScope() != null) { - n.setScope((Expression) n.getScope().accept(this, arg)); - } - n.setTypeArguments(modifyList(n.getTypeArguments(), arg)); - n.setArgs((NodeList<Expression>)n.getArgs().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final MethodDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ExplicitConstructorInvocationStmt n, final A arg) { + visitComment(n, arg); + if (!n.isThis() && n.getExpr().isPresent()) { + n.setExpr((Expression) n.getExpr().get().accept(this, arg)); + } + n.setTypeArguments(modifyList(n.getTypeArguments().orElse(null), arg)); + n.setArgs((NodeList<Expression>) n.getArgs().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ExpressionStmt n, final A arg) { + visitComment(n, arg); + final Expression expr = (Expression) n.getExpression().accept(this, arg); + if (expr == null) { + return null; + } + n.setExpression(expr); + return n; + } + + @Override + public Visitable visit(final FieldAccessExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope().isPresent()) { + final Expression scope = (Expression) n.getScope().get().accept(this, arg); + n.setScope(scope); + return n; + } else + return null; + } + + @Override + public Visitable visit(final FieldDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + n.setElementType((Type) n.getElementType().accept(this, arg)); + n.setVariables((NodeList<VariableDeclarator>) n.getVariables().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ForeachStmt n, final A arg) { + visitComment(n, arg); + n.setVariable((VariableDeclarationExpr) n.getVariable().accept(this, arg)); + n.setIterable((Expression) n.getIterable().accept(this, arg)); + n.setBody((Statement) n.getBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ForStmt n, final A arg) { + visitComment(n, arg); + n.setInit((NodeList<Expression>) n.getInit().accept(this, arg)); + if (n.getCompare().isPresent()) { + n.setCompare((Expression) n.getCompare().get().accept(this, arg)); + } + n.setUpdate((NodeList<Expression>) n.getUpdate().accept(this, arg)); + n.setBody((Statement) n.getBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final IfStmt n, final A arg) { + visitComment(n, arg); + final Expression condition = (Expression) n.getCondition().accept(this, arg); + if (condition == null) { + return null; + } + n.setCondition(condition); + final Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg); + if (thenStmt == null) { + // Remove the entire statement if the then-clause was removed. + // PrettyPrintVisitor, used for toString, has no null check for the + // then-clause. + return null; + } + n.setThenStmt(thenStmt); + if (n.getElseStmt().isPresent()) { + n.setElseStmt((Statement) n.getElseStmt().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final InitializerDeclaration n, final A arg) { + visitComment(n, arg); + n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final InstanceOfExpr n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + n.setType((ReferenceType<?>) n.getType().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final IntegerLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final IntegerLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final JavadocComment n, final A arg) { + return n; + } + + @Override + public Visitable visit(final LabeledStmt n, final A arg) { + visitComment(n, arg); + n.setStmt((Statement) n.getStmt().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final LongLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final LongLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final MarkerAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((Name) n.getName().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final MemberValuePair n, final A arg) { + visitComment(n, arg); + n.setValue((Expression) n.getValue().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final MethodCallExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope() != null) { + n.setScope((Expression) n.getScope().accept(this, arg)); + } + n.setTypeArguments(modifyList(n.getTypeArguments().orElse(null), arg)); + n.setArgs((NodeList<Expression>) n.getArgs().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final MethodDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); n.setTypeParameters(modifyList(n.getTypeParameters(), arg)); - n.setElementType((Type) n.getElementType().accept(this, arg)); - n.setParameters((NodeList<Parameter>)n.getParameters().accept(this, arg)); - n.setThrows((NodeList<ReferenceType<?>>)n.getThrows().accept(this, arg)); - if (n.getBody() != null) { - n.setBody((BlockStmt) n.getBody().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final NameExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final NormalAnnotationExpr n, final A arg) { - visitComment(n, arg); - n.setName((Name) n.getName().accept(this, arg)); - n.setPairs((NodeList<MemberValuePair>)n.getPairs().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final NullLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final ObjectCreationExpr n, final A arg) { - visitComment(n, arg); - if (n.getScope() != null) { - n.setScope((Expression) n.getScope().accept(this, arg)); - } - n.setTypeArguments(modifyList(n.getTypeArguments(), arg)); - n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); - n.setArgs((NodeList<Expression>)n.getArgs().accept(this, arg)); - n.setAnonymousClassBody((NodeList<BodyDeclaration<?>>)n.getAnonymousClassBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final PackageDeclaration n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - n.setName((Name) n.getName().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final Parameter n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - n.setId((VariableDeclaratorId) n.getId().accept(this, arg)); - n.setElementType((Type) n.getElementType().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final PrimitiveType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - return n; - } - - @Override public Visitable visit(final Name n, final A arg) { - visitComment(n, arg); - if(n.getQualifier()!=null) { - n.setQualifier((Name) n.getQualifier().accept(this, arg)); - } - return n; - } + n.setElementType((Type) n.getElementType().accept(this, arg)); + n.setParameters((NodeList<Parameter>) n.getParameters().accept(this, arg)); + n.setThrows((NodeList<ReferenceType<?>>) n.getThrows().accept(this, arg)); + if (n.getBody().isPresent()) { + n.setBody((BlockStmt) n.getBody().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final NameExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final NormalAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((Name) n.getName().accept(this, arg)); + n.setPairs((NodeList<MemberValuePair>) n.getPairs().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final NullLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final ObjectCreationExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope().isPresent()) { + n.setScope((Expression) n.getScope().get().accept(this, arg)); + } + n.setTypeArguments(modifyList(n.getTypeArguments().orElse(null), arg)); + n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); + n.setArgs((NodeList<Expression>) n.getArgs().accept(this, arg)); + if (n.getAnonymousClassBody().isPresent()) + n.setAnonymousClassBody((NodeList<BodyDeclaration<?>>) n.getAnonymousClassBody().get().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final PackageDeclaration n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + n.setName((Name) n.getName().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final Parameter n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + n.setId((VariableDeclaratorId) n.getId().accept(this, arg)); + n.setElementType((Type) n.getElementType().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final Name n, final A arg) { + visitComment(n, arg); + if (n.getQualifier() != null) { + n.setQualifier((Name) n.getQualifier().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final PrimitiveType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + return n; + } @Override public Visitable visit(SimpleName n, A arg) { @@ -530,293 +680,312 @@ public class ModifierVisitorAdapter<A> implements GenericVisitor<Visitable, A> { } @Override - public Visitable visit(ArrayType n, A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - n.setComponentType((Type) n.getComponentType().accept(this, arg)); - return n; - } + public Visitable visit(ArrayType n, A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + n.setComponentType((Type) n.getComponentType().accept(this, arg)); + return n; + } - @Override - public Visitable visit(ArrayCreationLevel n, A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - if(n.getDimension()!=null) { - n.setDimension((Expression) n.getDimension().accept(this, arg)); - } - return n; - } + @Override + public Visitable visit(ArrayCreationLevel n, A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + if (n.getDimension().isPresent()) { + n.setDimension((Expression) n.getDimension().get().accept(this, arg)); + } + return n; + } - @Override + @Override public Visitable visit(final IntersectionType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - n.setElements((NodeList<ReferenceType<?>>)n.getElements().accept(this, arg)); + visitComment(n, arg); + visitAnnotations(n, arg); + n.setElements((NodeList<ReferenceType<?>>) n.getElements().accept(this, arg)); return n; } @Override public Visitable visit(final UnionType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - n.setElements((NodeList<ReferenceType<?>>)n.getElements().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ReturnStmt n, final A arg) { - visitComment(n, arg); - if (n.getExpr() != null) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final SingleMemberAnnotationExpr n, final A arg) { - visitComment(n, arg); - n.setName((Name) n.getName().accept(this, arg)); - n.setMemberValue((Expression) n.getMemberValue().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final StringLiteralExpr n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final SuperExpr n, final A arg) { - visitComment(n, arg); - if (n.getClassExpr() != null) { - n.setClassExpr((Expression) n.getClassExpr().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final SwitchEntryStmt n, final A arg) { - visitComment(n, arg); - if (n.getLabel() != null) { - n.setLabel((Expression) n.getLabel().accept(this, arg)); - } - n.setStmts((NodeList<Statement>) n.getStmts().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final SwitchStmt n, final A arg) { - visitComment(n, arg); - n.setSelector((Expression) n.getSelector().accept(this, arg)); - n.setEntries((NodeList<SwitchEntryStmt>)n.getEntries().accept(this, arg)); - return n; - - } - - @Override public Visitable visit(final SynchronizedStmt n, final A arg) { - visitComment(n, arg); - n.setExpr((Expression) n.getExpr().accept(this, arg)); - n.setBody((BlockStmt) n.getBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final ThisExpr n, final A arg) { - visitComment(n, arg); - if (n.getClassExpr() != null) { - n.setClassExpr((Expression) n.getClassExpr().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final ThrowStmt n, final A arg) { - visitComment(n, arg); - n.setExpr((Expression) n.getExpr().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final TryStmt n, final A arg) { - visitComment(n, arg); - n.setResources((NodeList<VariableDeclarationExpr>)n.getResources().accept(this, arg)); - n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg)); - n.setCatchs((NodeList<CatchClause>)n.getCatchs().accept(this, arg)); - if (n.getFinallyBlock() != null) { - n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final TypeDeclarationStmt n, final A arg) { - visitComment(n, arg); - n.setTypeDeclaration((TypeDeclaration<?>) n.getTypeDeclaration().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final TypeParameter n, final A arg) { - visitComment(n, arg); - n.setTypeBound((NodeList<ClassOrInterfaceType>)n.getTypeBound().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final UnaryExpr n, final A arg) { - visitComment(n, arg); - n.setExpr((Expression) n.getExpr().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final UnknownType n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final VariableDeclarationExpr n, final A arg) { - visitComment(n, arg); - n.setAnnotations((NodeList<AnnotationExpr>)n.getAnnotations().accept(this, arg)); - - final Type type = (Type) n.getElementType().accept(this, arg); - if (type == null) { - return null; - } - n.setElementType(type); - - n.setVariables((NodeList<VariableDeclarator>)n.getVariables().accept(this, arg)); - - return n; - } - - @Override public Visitable visit(final VariableDeclarator n, final A arg) { - visitComment(n, arg); - final VariableDeclaratorId id = (VariableDeclaratorId) - n.getId().accept(this, arg); - if (id == null) { - return null; - } - n.setId(id); - if (n.getInit() != null) { - n.setInit((Expression) n.getInit().accept(this, arg)); - } - return n; - } - - @Override public Visitable visit(final VariableDeclaratorId n, final A arg) { - visitComment(n, arg); - return n; - } - - @Override public Visitable visit(final VoidType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - return n; - } - - @Override public Visitable visit(final WhileStmt n, final A arg) { - visitComment(n, arg); - n.setCondition((Expression) n.getCondition().accept(this, arg)); - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Visitable visit(final WildcardType n, final A arg) { - visitComment(n, arg); - visitAnnotations(n, arg); - if (n.getExtends() != null) { - n.setExtends((ReferenceType) n.getExtends().accept(this, arg)); - } - if (n.getSuper() != null) { - n.setSuper((ReferenceType) n.getSuper().accept(this, arg)); - } - return n; - } - - @Override - public Visitable visit(final LambdaExpr n, final A arg) { - visitComment(n, arg); - n.setParameters((NodeList<Parameter>)n.getParameters().accept(this, arg)); - if (n.getBody() != null) { - n.setBody((Statement) n.getBody().accept(this, arg)); - } - return n; - } - - @Override - public Visitable visit(final MethodReferenceExpr n, final A arg) { - visitComment(n, arg); - n.setTypeArguments(modifyList(n.getTypeArguments(), arg)); - if (n.getScope() != null) { - n.setScope((Expression)n.getScope().accept(this, arg)); - } - return n; - } - - @Override - public Visitable visit(final TypeExpr n, final A arg) { - visitComment(n, arg); - if (n.getType() != null) { + visitComment(n, arg); + visitAnnotations(n, arg); + n.setElements((NodeList<ReferenceType<?>>) n.getElements().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ReturnStmt n, final A arg) { + visitComment(n, arg); + if (n.getExpr().isPresent()) { + n.setExpr((Expression) n.getExpr().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final SingleMemberAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((Name) n.getName().accept(this, arg)); + n.setMemberValue((Expression) n.getMemberValue().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final StringLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final SuperExpr n, final A arg) { + visitComment(n, arg); + if (n.getClassExpr().isPresent()) { + n.setClassExpr((Expression) n.getClassExpr().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final SwitchEntryStmt n, final A arg) { + visitComment(n, arg); + if (n.getLabel().isPresent()) { + n.setLabel((Expression) n.getLabel().get().accept(this, arg)); + } + n.setStmts((NodeList<Statement>) n.getStmts().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final SwitchStmt n, final A arg) { + visitComment(n, arg); + n.setSelector((Expression) n.getSelector().accept(this, arg)); + n.setEntries((NodeList<SwitchEntryStmt>) n.getEntries().accept(this, arg)); + return n; + + } + + @Override + public Visitable visit(final SynchronizedStmt n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + n.setBody((BlockStmt) n.getBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final ThisExpr n, final A arg) { + visitComment(n, arg); + if (n.getClassExpr() != null) { + n.setClassExpr((Expression) n.getClassExpr().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final ThrowStmt n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final TryStmt n, final A arg) { + visitComment(n, arg); + n.setResources((NodeList<VariableDeclarationExpr>) n.getResources().accept(this, arg)); + n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg)); + n.setCatchs((NodeList<CatchClause>) n.getCatchs().accept(this, arg)); + if (n.getFinallyBlock() != null) { + n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final TypeDeclarationStmt n, final A arg) { + visitComment(n, arg); + n.setTypeDeclaration((TypeDeclaration<?>) n.getTypeDeclaration().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final TypeParameter n, final A arg) { + visitComment(n, arg); + n.setTypeBound((NodeList<ClassOrInterfaceType>) n.getTypeBound().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final UnaryExpr n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final UnknownType n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final VariableDeclarationExpr n, final A arg) { + visitComment(n, arg); + n.setAnnotations((NodeList<AnnotationExpr>) n.getAnnotations().accept(this, arg)); + + final Type type = (Type) n.getElementType().accept(this, arg); + if (type == null) { + return null; + } + n.setElementType(type); + + n.setVariables((NodeList<VariableDeclarator>) n.getVariables().accept(this, arg)); + + return n; + } + + @Override + public Visitable visit(final VariableDeclarator n, final A arg) { + visitComment(n, arg); + final VariableDeclaratorId id = (VariableDeclaratorId) n.getId().accept(this, arg); + if (id == null) { + return null; + } + n.setId(id); + if (n.getInit().isPresent()) { + n.setInit((Expression) n.getInit().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final VariableDeclaratorId n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override + public Visitable visit(final VoidType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + return n; + } + + @Override + public Visitable visit(final WhileStmt n, final A arg) { + visitComment(n, arg); + n.setCondition((Expression) n.getCondition().accept(this, arg)); + n.setBody((Statement) n.getBody().accept(this, arg)); + return n; + } + + @Override + public Visitable visit(final WildcardType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + if (n.getExtends().isPresent()) { + n.setExtends((ReferenceType) n.getExtends().get().accept(this, arg)); + } + if (n.getSuper().isPresent()) { + n.setSuper((ReferenceType) n.getSuper().get().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final LambdaExpr n, final A arg) { + visitComment(n, arg); + n.setParameters((NodeList<Parameter>) n.getParameters().accept(this, arg)); + if (n.getBody() != null) { + n.setBody((Statement) n.getBody().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final MethodReferenceExpr n, final A arg) { + visitComment(n, arg); + n.setTypeArguments(modifyList(n.getTypeArguments().orElse(null), arg)); + if (n.getScope() != null) { + n.setScope((Expression) n.getScope().accept(this, arg)); + } + return n; + } + + @Override + public Visitable visit(final TypeExpr n, final A arg) { + visitComment(n, arg); + if (n.getType() != null) { n.setType((Type<?>) n.getType().accept(this, arg)); - } - return n; - } + } + return n; + } - @Override - public Visitable visit(ArrayBracketPair n, A arg) { - visitAnnotations(n, arg); - return n; - } + @Override + public Visitable visit(ArrayBracketPair n, A arg) { + visitAnnotations(n, arg); + return n; + } - @Override - public Visitable visit(NodeList n, A arg) { - for (int i = 0; i < n.size(); i++) { - n.set(i, (Node) n.get(i).accept(this, arg)); - } - for (int i = n.size() - 1; i >= 0; i--) { - if (n.get(i) == null) { - n.remove(i); - } - } - return n; - } + @Override + public Visitable visit(NodeList n, A arg) { + for (int i = 0; i < n.size(); i++) { + n.set(i, (Node) n.get(i).accept(this, arg)); + } + for (int i = n.size() - 1; i >= 0; i--) { + if (n.get(i) == null) { + n.remove(i); + } + } + return n; + } @Override - public Visitable visit(EmptyImportDeclaration n, A arg) { + public Visitable visit(EmptyImportDeclaration n, A arg) { visitComment(n, arg); return n; - } + } - @Override - public Visitable visit(SingleStaticImportDeclaration n, A arg) { + @Override + public Visitable visit(SingleStaticImportDeclaration n, A arg) { visitComment(n, arg); n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); return n; - } + } - @Override - public Visitable visit(SingleTypeImportDeclaration n, A arg) { + @Override + public Visitable visit(SingleTypeImportDeclaration n, A arg) { visitComment(n, arg); n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); return n; - } + } - @Override - public Visitable visit(StaticImportOnDemandDeclaration n, A arg) { + @Override + public Visitable visit(StaticImportOnDemandDeclaration n, A arg) { visitComment(n, arg); n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); return n; - } + } - @Override - public Visitable visit(TypeImportOnDemandDeclaration n, A arg) { + @Override + public Visitable visit(TypeImportOnDemandDeclaration n, A arg) { visitComment(n, arg); n.setName((Name) n.getName().accept(this, arg)); return n; - } + } - @Override - public Visitable visit(final BlockComment n, final A arg) { - return n; - } + @Override + public Visitable visit(final BlockComment n, final A arg) { + return n; + } - @Override - public Visitable visit(final LineComment n, final A arg) { - return n; - } + @Override + public Visitable visit(final LineComment n, final A arg) { + return n; + } - private void visitComment(Node n, final A arg) { - if (n != null && n.getComment() != null) { - n.setComment((Comment) n.getComment().accept(this, arg)); - } - } + private void visitComment(Node n, final A arg) { + if (n != null && n.getComment() != null) { + n.setComment((Comment) n.getComment().accept(this, arg)); + } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java index fe963be0c..e911f75af 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -18,14 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - + package com.github.javaparser.ast.visitor; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.body.BodyDeclaration; @@ -46,493 +47,629 @@ import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.ImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; -import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; /** * @author Julio Vilmar Gesser */ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { - @Override public void visit(final AnnotationDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getName().accept(this, arg); - if (n.getMembers() != null) { + @Override + public void visit(final AnnotationDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getName().accept(this, arg); + if (n.getMembers() != null) { for (final BodyDeclaration<?> member : n.getMembers()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final AnnotationMemberDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getType().accept(this, arg); - if (n.getDefaultValue() != null) { - n.getDefaultValue().accept(this, arg); - } - } - - @Override public void visit(final ArrayAccessExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - n.getIndex().accept(this, arg); - } - - @Override public void visit(final ArrayCreationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getElementType().accept(this, arg); - for (ArrayCreationLevel level : n.getLevels()) { - level.accept(this, arg); - } - if (n.getInitializer() != null) { - n.getInitializer().accept(this, arg); - } - } - - @Override public void visit(final ArrayInitializerExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getValues() != null) { - for (final Expression expr : n.getValues()) { - expr.accept(this, arg); - } - } - } - - @Override public void visit(final AssertStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCheck().accept(this, arg); - if (n.getMessage() != null) { - n.getMessage().accept(this, arg); - } - } - - @Override public void visit(final AssignExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getTarget().accept(this, arg); - n.getValue().accept(this, arg); - } - - @Override public void visit(final BinaryExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getLeft().accept(this, arg); - n.getRight().accept(this, arg); - } - - @Override public void visit(final BlockComment n, final A arg) { - } - - @Override public void visit(final BlockStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - } - } - } - - @Override public void visit(final BooleanLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final BreakStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final CastExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final CatchClause n, final A arg) { - visitComment(n.getComment(), arg); - n.getParam().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final CharLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final ClassExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override public void visit(final ClassOrInterfaceDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getName().accept(this, arg); - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - for (final ClassOrInterfaceType c : n.getExtends()) { - c.accept(this, arg); - } - for (final ClassOrInterfaceType c : n.getImplements()) { - c.accept(this, arg); - } + member.accept(this, arg); + } + } + } + + @Override + public void visit(final AnnotationMemberDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getType().accept(this, arg); + if (n.getDefaultValue().isPresent()) { + n.getDefaultValue().get().accept(this, arg); + } + } + + @Override + public void visit(final ArrayAccessExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + n.getIndex().accept(this, arg); + } + + @Override + public void visit(final ArrayCreationExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getElementType().accept(this, arg); + for (ArrayCreationLevel level : n.getLevels()) { + level.accept(this, arg); + } + if (n.getInitializer().isPresent()) { + n.getInitializer().get().accept(this, arg); + } + } + + @Override + public void visit(final ArrayInitializerExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getValues() != null) { + for (final Expression expr : n.getValues()) { + expr.accept(this, arg); + } + } + } + + @Override + public void visit(final AssertStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getCheck().accept(this, arg); + if (n.getMessage().isPresent()) { + n.getMessage().get().accept(this, arg); + } + } + + @Override + public void visit(final AssignExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getTarget().accept(this, arg); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final BinaryExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getLeft().accept(this, arg); + n.getRight().accept(this, arg); + } + + @Override + public void visit(final BlockComment n, final A arg) { + } + + @Override + public void visit(final BlockStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getStmts() != null) { + for (final Statement s : n.getStmts()) { + s.accept(this, arg); + } + } + } + + @Override + public void visit(final BooleanLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final BreakStmt n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final CastExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getType().accept(this, arg); + n.getExpr().accept(this, arg); + } + + @Override + public void visit(final CatchClause n, final A arg) { + visitComment(n.getComment(), arg); + n.getParam().accept(this, arg); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final CharLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final ClassExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getType().accept(this, arg); + } + + @Override + public void visit(final ClassOrInterfaceDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getName().accept(this, arg); + for (final TypeParameter t : n.getTypeParameters()) { + t.accept(this, arg); + } + for (final ClassOrInterfaceType c : n.getExtends()) { + c.accept(this, arg); + } + for (final ClassOrInterfaceType c : n.getImplements()) { + c.accept(this, arg); + } for (final BodyDeclaration<?> member : n.getMembers()) { - member.accept(this, arg); - } - } - - @Override public void visit(final ClassOrInterfaceType n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArguments() != null) { - for (final Type t : n.getTypeArguments()) { - t.accept(this, arg); - } - } - } - - @Override public void visit(final CompilationUnit n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getPackage() != null) { - n.getPackage().accept(this, arg); - } - if (n.getImports() != null) { - for (final ImportDeclaration i : n.getImports()) { - i.accept(this, arg); - } - } - if (n.getTypes() != null) { + member.accept(this, arg); + } + } + + @Override + public void visit(final ClassOrInterfaceType n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); + } + if (n.getTypeArguments().isPresent()) { + for (final Type<?> t : n.getTypeArguments().get()) { + t.accept(this, arg); + } + } + } + + @Override + public void visit(final CompilationUnit n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getPackage().isPresent()) { + n.getPackage().get().accept(this, arg); + } + if (n.getImports() != null) { + for (final ImportDeclaration i : n.getImports()) { + i.accept(this, arg); + } + } + if (n.getTypes() != null) { for (final TypeDeclaration<?> typeDeclaration : n.getTypes()) { - typeDeclaration.accept(this, arg); - } - } - } - - @Override public void visit(final ConditionalExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getThenExpr().accept(this, arg); - n.getElseExpr().accept(this, arg); - } - - @Override public void visit(final ConstructorDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - } - n.getName().accept(this, arg); - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - p.accept(this, arg); - } - } - if (n.getThrows() != null) { - for (final ReferenceType name : n.getThrows()) { - name.accept(this, arg); - } - } - n.getBody().accept(this, arg); - } - - @Override public void visit(final ContinueStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final DoStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getBody().accept(this, arg); - n.getCondition().accept(this, arg); - } - - @Override public void visit(final DoubleLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final EmptyMemberDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final EmptyStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final EmptyTypeDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - } - - @Override public void visit(final EnclosedExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getInner().accept(this, arg); - } - - @Override public void visit(final EnumConstantDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - if (n.getClassBody() != null) { + typeDeclaration.accept(this, arg); + } + } + } + + @Override + public void visit(final ConditionalExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getCondition().accept(this, arg); + n.getThenExpr().accept(this, arg); + n.getElseExpr().accept(this, arg); + } + + @Override + public void visit(final ConstructorDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getTypeParameters() != null) { + for (final TypeParameter t : n.getTypeParameters()) { + t.accept(this, arg); + } + } + n.getName().accept(this, arg); + if (n.getParameters() != null) { + for (final Parameter p : n.getParameters()) { + p.accept(this, arg); + } + } + if (n.getThrows() != null) { + for (final ReferenceType name : n.getThrows()) { + name.accept(this, arg); + } + } + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ContinueStmt n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final DoStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getBody().accept(this, arg); + n.getCondition().accept(this, arg); + } + + @Override + public void visit(final DoubleLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final EmptyMemberDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final EmptyStmt n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final EmptyTypeDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + } + + @Override + public void visit(final EnclosedExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getInner().isPresent()) + n.getInner().get().accept(this, arg); + } + + @Override + public void visit(final EnumConstantDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + e.accept(this, arg); + } + } + if (n.getClassBody() != null) { for (final BodyDeclaration<?> member : n.getClassBody()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final EnumDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getName().accept(this, arg); - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - c.accept(this, arg); - } - } - if (n.getEntries() != null) { - for (final EnumConstantDeclaration e : n.getEntries()) { - e.accept(this, arg); - } - } - if (n.getMembers() != null) { + member.accept(this, arg); + } + } + } + + @Override + public void visit(final EnumDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getName().accept(this, arg); + if (n.getImplements() != null) { + for (final ClassOrInterfaceType c : n.getImplements()) { + c.accept(this, arg); + } + } + if (n.getEntries() != null) { + for (final EnumConstantDeclaration e : n.getEntries()) { + e.accept(this, arg); + } + } + if (n.getMembers() != null) { for (final BodyDeclaration<?> member : n.getMembers()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (!n.isThis() && n.getExpr() != null) { - n.getExpr().accept(this, arg); - } - if (n.getTypeArguments() != null) { - for (final Type t : n.getTypeArguments()) { - t.accept(this, arg); - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final ExpressionStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpression().accept(this, arg); - } - - @Override public void visit(final FieldAccessExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getScope().accept(this, arg); - n.getField().accept(this, arg); - } - - @Override public void visit(final FieldDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getElementType().accept(this, arg); - for (final VariableDeclarator var : n.getVariables()) { - var.accept(this, arg); - } - } - - @Override public void visit(final ForeachStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getVariable().accept(this, arg); - n.getIterable().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ForStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getInit() != null) { - for (final Expression e : n.getInit()) { - e.accept(this, arg); - } - } - if (n.getCompare() != null) { - n.getCompare().accept(this, arg); - } - if (n.getUpdate() != null) { - for (final Expression e : n.getUpdate()) { - e.accept(this, arg); - } - } - n.getBody().accept(this, arg); - } - - @Override public void visit(final IfStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getThenStmt().accept(this, arg); - if (n.getElseStmt() != null) { - n.getElseStmt().accept(this, arg); - } - } - - @Override public void visit(final InitializerDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - n.getBlock().accept(this, arg); - } - - @Override public void visit(final InstanceOfExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - n.getType().accept(this, arg); - } - - @Override public void visit(final IntegerLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final IntegerLiteralMinValueExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final JavadocComment n, final A arg) { - } - - @Override public void visit(final LabeledStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getStmt().accept(this, arg); - } - - @Override public void visit(final LineComment n, final A arg) { - } - - @Override public void visit(final LongLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final LongLiteralMinValueExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final MarkerAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - } - - @Override public void visit(final MemberValuePair n, final A arg) { - visitComment(n.getComment(), arg); - n.getValue().accept(this, arg); - } - - @Override public void visit(final MethodCallExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArguments() != null) { - for (final Type t : n.getTypeArguments()) { - t.accept(this, arg); - } - } - n.getName().accept(this, arg); - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final MethodDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - } - n.getElementType().accept(this, arg); - n.getName().accept(this, arg); - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - p.accept(this, arg); - } - } - if (n.getThrows() != null) { - for (final ReferenceType name : n.getThrows()) { - name.accept(this, arg); - } - } - if (n.getBody() != null) { - n.getBody().accept(this, arg); - } - } - - @Override public void visit(final NameExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final NormalAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - if (n.getPairs() != null) { - for (final MemberValuePair m : n.getPairs()) { - m.accept(this, arg); - } - } - } - - @Override public void visit(final NullLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final ObjectCreationExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArguments() != null) { - for (final Type t : n.getTypeArguments()) { - t.accept(this, arg); - } - } - n.getType().accept(this, arg); - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - if (n.getAnonymousClassBody() != null) { - for (final BodyDeclaration<?> member : n.getAnonymousClassBody()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final PackageDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getName().accept(this, arg); - } - - @Override public void visit(final Parameter n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getElementType().accept(this, arg); - n.getId().accept(this, arg); - } - - @Override public void visit(final PrimitiveType n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - } - - @Override public void visit(final Name n, final A arg) { - visitComment(n.getComment(), arg); - if(n.getQualifier()!=null) { - n.getQualifier().accept(this, arg); - } - } + member.accept(this, arg); + } + } + } + + @Override + public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (!n.isThis() && n.getExpr().isPresent()) { + n.getExpr().get().accept(this, arg); + } + if (n.getTypeArguments().isPresent()) { + for (final Type<?> t : n.getTypeArguments().get()) { + t.accept(this, arg); + } + } + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + e.accept(this, arg); + } + } + } + + @Override + public void visit(final ExpressionStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getExpression().accept(this, arg); + } + + @Override + public void visit(final FieldAccessExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getScope().isPresent()) + n.getScope().get().accept(this, arg); + n.getField().accept(this, arg); + } + + @Override + public void visit(final FieldDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getElementType().accept(this, arg); + for (final VariableDeclarator var : n.getVariables()) { + var.accept(this, arg); + } + } + + @Override + public void visit(final ForeachStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getVariable().accept(this, arg); + n.getIterable().accept(this, arg); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ForStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getInit() != null) { + for (final Expression e : n.getInit()) { + e.accept(this, arg); + } + } + if (n.getCompare().isPresent()) { + n.getCompare().get().accept(this, arg); + } + if (n.getUpdate() != null) { + for (final Expression e : n.getUpdate()) { + e.accept(this, arg); + } + } + n.getBody().accept(this, arg); + } + + @Override + public void visit(final IfStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getCondition().accept(this, arg); + n.getThenStmt().accept(this, arg); + if (n.getElseStmt().isPresent()) { + n.getElseStmt().get().accept(this, arg); + } + } + + @Override + public void visit(final InitializerDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + n.getBlock().accept(this, arg); + } + + @Override + public void visit(final InstanceOfExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getExpr().accept(this, arg); + n.getType().accept(this, arg); + } + + @Override + public void visit(final IntegerLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final IntegerLiteralMinValueExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final JavadocComment n, final A arg) { + } + + @Override + public void visit(final LabeledStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getStmt().accept(this, arg); + } + + @Override + public void visit(final LineComment n, final A arg) { + } + + @Override + public void visit(final LongLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final LongLiteralMinValueExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final MarkerAnnotationExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + } + + @Override + public void visit(final MemberValuePair n, final A arg) { + visitComment(n.getComment(), arg); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final MethodCallExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getScope() != null) { + n.getScope().accept(this, arg); + } + if (n.getTypeArguments().isPresent()) { + for (final Type<?> t : n.getTypeArguments().get()) { + t.accept(this, arg); + } + } + n.getName().accept(this, arg); + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + e.accept(this, arg); + } + } + } + + @Override + public void visit(final MethodDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getTypeParameters() != null) { + for (final TypeParameter t : n.getTypeParameters()) { + t.accept(this, arg); + } + } + n.getElementType().accept(this, arg); + n.getName().accept(this, arg); + if (n.getParameters() != null) { + for (final Parameter p : n.getParameters()) { + p.accept(this, arg); + } + } + if (n.getThrows() != null) { + for (final ReferenceType<?> name : n.getThrows()) { + name.accept(this, arg); + } + } + if (n.getBody().isPresent()) { + n.getBody().get().accept(this, arg); + } + } + + @Override + public void visit(final NameExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final NormalAnnotationExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + if (n.getPairs() != null) { + for (final MemberValuePair m : n.getPairs()) { + m.accept(this, arg); + } + } + } + + @Override + public void visit(final NullLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final ObjectCreationExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); + } + if (n.getTypeArguments().isPresent()) { + for (final Type<?> t : n.getTypeArguments().get()) { + t.accept(this, arg); + } + } + n.getType().accept(this, arg); + if (n.getArgs() != null) { + for (final Expression e : n.getArgs()) { + e.accept(this, arg); + } + } + if (n.getAnonymousClassBody().isPresent()) { + for (final BodyDeclaration<?> member : n.getAnonymousClassBody().get()) { + member.accept(this, arg); + } + } + } + + @Override + public void visit(final PackageDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getName().accept(this, arg); + } + + @Override + public void visit(final Parameter n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getElementType().accept(this, arg); + n.getId().accept(this, arg); + } + + @Override + public void visit(final PrimitiveType n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + } + + @Override + public void visit(final Name n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getQualifier() != null) { + n.getQualifier().accept(this, arg); + } + } @Override public void visit(SimpleName n, A arg) { @@ -540,189 +677,211 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { } @Override - public void visit(ArrayType n, A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getComponentType().accept(this, arg); - } + public void visit(ArrayType n, A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getComponentType().accept(this, arg); + } - @Override - public void visit(ArrayCreationLevel n, A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if(n.getDimension()!=null) { - n.getDimension().accept(this, arg); - } - } + @Override + public void visit(ArrayCreationLevel n, A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getDimension().isPresent()) { + n.getDimension().get().accept(this, arg); + } + } - @Override public void visit(final IntersectionType n, final A arg) { + @Override + public void visit(final IntersectionType n, final A arg) { visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - for (ReferenceType element : n.getElements()) { + visitAnnotations(n, arg); + for (ReferenceType element : n.getElements()) { element.accept(this, arg); } } - @Override public void visit(final UnionType n, final A arg) { + @Override + public void visit(final UnionType n, final A arg) { visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - for (ReferenceType element : n.getElements()) { + visitAnnotations(n, arg); + for (ReferenceType element : n.getElements()) { element.accept(this, arg); } } - @Override public void visit(final ReturnStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getExpr() != null) { - n.getExpr().accept(this, arg); - } - } - - @Override public void visit(final SingleMemberAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - n.getMemberValue().accept(this, arg); - } - - @Override public void visit(final StringLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final SuperExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - } - } - - @Override public void visit(final SwitchEntryStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getLabel() != null) { - n.getLabel().accept(this, arg); - } - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - } - } - } - - @Override public void visit(final SwitchStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getSelector().accept(this, arg); - if (n.getEntries() != null) { - for (final SwitchEntryStmt e : n.getEntries()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final SynchronizedStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ThisExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - } - } - - @Override public void visit(final ThrowStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final TryStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getResources() != null) { - for (final VariableDeclarationExpr v : n.getResources()) { - v.accept(this, arg); - } - } - n.getTryBlock().accept(this, arg); - if (n.getCatchs() != null) { - for (final CatchClause c : n.getCatchs()) { - c.accept(this, arg); - } - } - if (n.getFinallyBlock() != null) { - n.getFinallyBlock().accept(this, arg); - } - } - - @Override public void visit(final TypeDeclarationStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getTypeDeclaration().accept(this, arg); - } - - @Override public void visit(final TypeParameter n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getTypeBound() != null) { - for (final ClassOrInterfaceType c : n.getTypeBound()) { - c.accept(this, arg); - } - } - } - - @Override public void visit(final UnaryExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final UnknownType n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final VariableDeclarationExpr n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - n.getElementType().accept(this, arg); - for (final VariableDeclarator v : n.getVariables()) { - v.accept(this, arg); - } - } - - @Override public void visit(final VariableDeclarator n, final A arg) { - visitComment(n.getComment(), arg); - n.getId().accept(this, arg); - if (n.getInit() != null) { - n.getInit().accept(this, arg); - } - } - - @Override public void visit(final VariableDeclaratorId n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final VoidType n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - - } - - @Override public void visit(final WhileStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final WildcardType n, final A arg) { - visitComment(n.getComment(), arg); - visitAnnotations(n, arg); - if (n.getExtends() != null) { - n.getExtends().accept(this, arg); - } - if (n.getSuper() != null) { - n.getSuper().accept(this, arg); - } - } + @Override + public void visit(final ReturnStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getExpr().isPresent()) { + n.getExpr().get().accept(this, arg); + } + } + + @Override + public void visit(final SingleMemberAnnotationExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + n.getMemberValue().accept(this, arg); + } + + @Override + public void visit(final StringLiteralExpr n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final SuperExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getClassExpr().isPresent()) { + n.getClassExpr().get().accept(this, arg); + } + } + + @Override + public void visit(final SwitchEntryStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getLabel().isPresent()) { + n.getLabel().get().accept(this, arg); + } + if (n.getStmts() != null) { + for (final Statement s : n.getStmts()) { + s.accept(this, arg); + } + } + } + + @Override + public void visit(final SwitchStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getSelector().accept(this, arg); + if (n.getEntries() != null) { + for (final SwitchEntryStmt e : n.getEntries()) { + e.accept(this, arg); + } + } + } + + @Override + public void visit(final SynchronizedStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getExpr().accept(this, arg); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ThisExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getClassExpr() != null) { + n.getClassExpr().accept(this, arg); + } + } + + @Override + public void visit(final ThrowStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getExpr().accept(this, arg); + } + + @Override + public void visit(final TryStmt n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getResources() != null) { + for (final VariableDeclarationExpr v : n.getResources()) { + v.accept(this, arg); + } + } + n.getTryBlock().accept(this, arg); + if (n.getCatchs() != null) { + for (final CatchClause c : n.getCatchs()) { + c.accept(this, arg); + } + } + if (n.getFinallyBlock() != null) { + n.getFinallyBlock().accept(this, arg); + } + } + + @Override + public void visit(final TypeDeclarationStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getTypeDeclaration().accept(this, arg); + } + + @Override + public void visit(final TypeParameter n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getTypeBound() != null) { + for (final ClassOrInterfaceType c : n.getTypeBound()) { + c.accept(this, arg); + } + } + } + + @Override + public void visit(final UnaryExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getExpr().accept(this, arg); + } + + @Override + public void visit(final UnknownType n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final VariableDeclarationExpr n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + n.getElementType().accept(this, arg); + for (final VariableDeclarator v : n.getVariables()) { + v.accept(this, arg); + } + } + + @Override + public void visit(final VariableDeclarator n, final A arg) { + visitComment(n.getComment(), arg); + n.getId().accept(this, arg); + if (n.getInit().isPresent()) { + n.getInit().get().accept(this, arg); + } + } + + @Override + public void visit(final VariableDeclaratorId n, final A arg) { + visitComment(n.getComment(), arg); + } + + @Override + public void visit(final VoidType n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + + } + + @Override + public void visit(final WhileStmt n, final A arg) { + visitComment(n.getComment(), arg); + n.getCondition().accept(this, arg); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final WildcardType n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + if (n.getExtends().isPresent()) { + n.getExtends().get().accept(this, arg); + } + if (n.getSuper().isPresent()) { + n.getSuper().get().accept(this, arg); + } + } @Override public void visit(LambdaExpr n, final A arg) { - visitComment(n.getComment(), arg); + visitComment(n.getComment(), arg); if (n.getParameters() != null) { for (final Parameter a : n.getParameters()) { a.accept(this, arg); @@ -735,12 +894,12 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { @Override public void visit(MethodReferenceExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getTypeArguments() != null) { - for (final Type t : n.getTypeArguments()) { - t.accept(this, arg); - } - } + visitComment(n.getComment(), arg); + if (n.getTypeArguments().isPresent()) { + for (final Type<?> t : n.getTypeArguments().get()) { + t.accept(this, arg); + } + } if (n.getScope() != null) { n.getScope().accept(this, arg); } @@ -748,63 +907,63 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { @Override public void visit(TypeExpr n, final A arg) { - visitComment(n.getComment(), arg); + visitComment(n.getComment(), arg); if (n.getType() != null) { n.getType().accept(this, arg); } } - @Override - public void visit(ArrayBracketPair n, A arg) { - visitAnnotations(n, arg); - } - - @Override - public void visit(NodeList n, A arg) { - for(Object node: n){ - ((Node)node).accept(this, arg); - } - } - - @Override - public void visit(EmptyImportDeclaration n, A arg) { - visitComment(n.getComment(), arg); - - } - - @Override - public void visit(SingleStaticImportDeclaration n, A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override - public void visit(SingleTypeImportDeclaration n, A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override - public void visit(StaticImportOnDemandDeclaration n, A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override - public void visit(TypeImportOnDemandDeclaration n, A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - } - - private void visitComment(final Comment n, final A arg) { - if (n != null) { - n.accept(this, arg); - } - } - - private void visitAnnotations(NodeWithAnnotations<?> n, A arg) { - for (AnnotationExpr annotation : n.getAnnotations()) { - annotation.accept(this, arg); - } - } + @Override + public void visit(ArrayBracketPair n, A arg) { + visitAnnotations(n, arg); + } + + @Override + public void visit(NodeList n, A arg) { + for (Object node : n) { + ((Node) node).accept(this, arg); + } + } + + @Override + public void visit(EmptyImportDeclaration n, A arg) { + visitComment(n.getComment(), arg); + + } + + @Override + public void visit(SingleStaticImportDeclaration n, A arg) { + visitComment(n.getComment(), arg); + n.getType().accept(this, arg); + } + + @Override + public void visit(SingleTypeImportDeclaration n, A arg) { + visitComment(n.getComment(), arg); + n.getType().accept(this, arg); + } + + @Override + public void visit(StaticImportOnDemandDeclaration n, A arg) { + visitComment(n.getComment(), arg); + n.getType().accept(this, arg); + } + + @Override + public void visit(TypeImportOnDemandDeclaration n, A arg) { + visitComment(n.getComment(), arg); + n.getName().accept(this, arg); + } + + private void visitComment(final Comment n, final A arg) { + if (n != null) { + n.accept(this, arg); + } + } + + private void visitAnnotations(NodeWithAnnotations<?> n, A arg) { + for (AnnotationExpr annotation : n.getAnnotations()) { + annotation.accept(this, arg); + } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index acfe8fe79..69923b3f7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -21,18 +21,8 @@ package com.github.javaparser.printer; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.imports.*; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; -import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; import java.util.EnumSet; import java.util.Iterator; @@ -40,8 +30,111 @@ import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.isNullOrEmpty; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EmptyMemberDeclaration; +import com.github.javaparser.ast.body.EmptyTypeDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.imports.EmptyImportDeclaration; +import com.github.javaparser.ast.imports.SingleStaticImportDeclaration; +import com.github.javaparser.ast.imports.SingleTypeImportDeclaration; +import com.github.javaparser.ast.imports.StaticImportOnDemandDeclaration; +import com.github.javaparser.ast.imports.TypeImportOnDemandDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.TypeDeclarationStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.visitor.VoidVisitor; /** * Outputs the AST as formatted Java source code. @@ -55,9 +148,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) { configuration = prettyPrinterConfiguration; - printer=new SourcePrinter(configuration.getIndent()); + printer = new SourcePrinter(configuration.getIndent()); } - + public String getSource() { return printer.getSource(); } @@ -85,7 +178,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } } - private void printAnnotations(final NodeList<AnnotationExpr> annotations, boolean prefixWithASpace, final Void arg) { + private void printAnnotations(final NodeList<AnnotationExpr> annotations, boolean prefixWithASpace, + final Void arg) { if (annotations.isEmpty()) { return; } @@ -99,10 +193,10 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } private void printTypeArgs(final NodeWithTypeArguments<?> nodeWithTypeArguments, final Void arg) { - NodeList<Type<?>> typeArguments = nodeWithTypeArguments.getTypeArguments(); + NodeList<Type<?>> typeArguments = nodeWithTypeArguments.getTypeArguments().orElse(null); if (!isNullOrEmpty(typeArguments)) { printer.print("<"); - for (final Iterator<Type<?>> i = typeArguments.iterator(); i.hasNext(); ) { + for (final Iterator<Type<?>> i = typeArguments.iterator(); i.hasNext();) { final Type<?> t = i.next(); t.accept(this, arg); if (i.hasNext()) { @@ -116,7 +210,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { private void printTypeParameters(final NodeList<TypeParameter> args, final Void arg) { if (!isNullOrEmpty(args)) { printer.print("<"); - for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) { + for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext();) { final TypeParameter t = i.next(); t.accept(this, arg); if (i.hasNext()) { @@ -130,7 +224,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { private void printArguments(final NodeList<Expression> args, final Void arg) { printer.print("("); if (!isNullOrEmpty(args)) { - for (final Iterator<Expression> i = args.iterator(); i.hasNext(); ) { + for (final Iterator<Expression> i = args.iterator(); i.hasNext();) { final Expression e = i.next(); e.accept(this, arg); if (i.hasNext()) { @@ -151,8 +245,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final CompilationUnit n, final Void arg) { printJavaComment(n.getComment(), arg); - if (n.getPackage() != null) { - n.getPackage().accept(this, arg); + if (n.getPackage().isPresent()) { + n.getPackage().get().accept(this, arg); } n.getImports().accept(this, arg); @@ -160,7 +254,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.println(); } - for (final Iterator<TypeDeclaration<?>> i = n.getTypes().iterator(); i.hasNext(); ) { + for (final Iterator<TypeDeclaration<?>> i = n.getTypes().iterator(); i.hasNext();) { i.next().accept(this, arg); printer.println(); if (i.hasNext()) { @@ -226,7 +320,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (!n.getExtends().isEmpty()) { printer.print(" extends "); - for (final Iterator<ClassOrInterfaceType> i = n.getExtends().iterator(); i.hasNext(); ) { + for (final Iterator<ClassOrInterfaceType> i = n.getExtends().iterator(); i.hasNext();) { final ClassOrInterfaceType c = i.next(); c.accept(this, arg); if (i.hasNext()) { @@ -237,7 +331,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (!n.getImplements().isEmpty()) { printer.print(" implements "); - for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) { + for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext();) { final ClassOrInterfaceType c = i.next(); c.accept(this, arg); if (i.hasNext()) { @@ -277,8 +371,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final ClassOrInterfaceType n, final Void arg) { printJavaComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); printer.print("."); } for (AnnotationExpr ae : n.getAnnotations()) { @@ -305,7 +399,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { n.getName().accept(this, arg); if (!isNullOrEmpty(n.getTypeBound())) { printer.print(" extends "); - for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) { + for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext();) { final ClassOrInterfaceType c = i.next(); c.accept(this, arg); if (i.hasNext()) { @@ -368,8 +462,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final ArrayCreationLevel n, final Void arg) { printAnnotations(n.getAnnotations(), true, arg); printer.print("["); - if (n.getDimension() != null) { - n.getDimension().accept(this, arg); + if (n.getDimension().isPresent()) { + n.getDimension().get().accept(this, arg); } printer.print("]"); } @@ -404,19 +498,18 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } } - @Override public void visit(final WildcardType n, final Void arg) { printJavaComment(n.getComment(), arg); printAnnotations(n.getAnnotations(), false, arg); printer.print("?"); - if (n.getExtends() != null) { + if (n.getExtends().isPresent()) { printer.print(" extends "); - n.getExtends().accept(this, arg); + n.getExtends().get().accept(this, arg); } - if (n.getSuper() != null) { + if (n.getSuper().isPresent()) { printer.print(" super "); - n.getSuper().accept(this, arg); + n.getSuper().get().accept(this, arg); } } @@ -438,7 +531,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } printer.print(" "); - for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) { + for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext();) { final VariableDeclarator var = i.next(); var.accept(this, arg); if (i.hasNext()) { @@ -453,9 +546,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final VariableDeclarator n, final Void arg) { printJavaComment(n.getComment(), arg); n.getId().accept(this, arg); - if (n.getInit() != null) { + if (n.getInit().isPresent()) { printer.print(" = "); - n.getInit().accept(this, arg); + n.getInit().get().accept(this, arg); } } @@ -474,7 +567,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.print("{"); if (!isNullOrEmpty(n.getValues())) { printer.print(" "); - for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) { + for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext();) { final Expression expr = i.next(); expr.accept(this, arg); if (i.hasNext()) { @@ -510,9 +603,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { for (ArrayCreationLevel level : n.getLevels()) { level.accept(this, arg); } - if (n.getInitializer() != null) { + if (n.getInitializer().isPresent()) { printer.print(" "); - n.getInitializer().accept(this, arg); + n.getInitializer().get().accept(this, arg); } } @@ -661,8 +754,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final EnclosedExpr n, final Void arg) { printJavaComment(n.getComment(), arg); printer.print("("); - if (n.getInner() != null) { - n.getInner().accept(this, arg); + if (n.getInner().isPresent()) { + n.getInner().get().accept(this, arg); } printer.print(")"); } @@ -670,7 +763,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { @Override public void visit(final FieldAccessExpr n, final Void arg) { printJavaComment(n.getComment(), arg); - n.getScope().accept(this, arg); + if (n.getScope().isPresent()) + n.getScope().get().accept(this, arg); printer.print("."); n.getField().accept(this, arg); } @@ -754,8 +848,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { @Override public void visit(final SuperExpr n, final Void arg) { printJavaComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); + if (n.getClassExpr().isPresent()) { + n.getClassExpr().get().accept(this, arg); printer.print("."); } printer.print("super"); @@ -776,15 +870,15 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { @Override public void visit(final ObjectCreationExpr n, final Void arg) { printJavaComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); printer.print("."); } printer.print("new "); printTypeArgs(n, arg); - if (!isNullOrEmpty(n.getTypeArguments())) { + if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } @@ -792,10 +886,10 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printArguments(n.getArgs(), arg); - if (n.getAnonymousClassBody() != null) { + if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); - printMembers(n.getAnonymousClassBody(), arg); + printMembers(n.getAnonymousClassBody().get(), arg); printer.unindent(); printer.print("}"); } @@ -853,7 +947,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.print("("); if (!n.getParameters().isEmpty()) { - for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { + for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext();) { final Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) { @@ -865,7 +959,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (!isNullOrEmpty(n.getThrows())) { printer.print(" throws "); - for (final Iterator<ReferenceType<?>> i = n.getThrows().iterator(); i.hasNext(); ) { + for (final Iterator<ReferenceType<?>> i = n.getThrows().iterator(); i.hasNext();) { final ReferenceType<?> name = i.next(); name.accept(this, arg); if (i.hasNext()) { @@ -901,7 +995,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.print("("); if (!isNullOrEmpty(n.getParameters())) { - for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { + for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext();) { final Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) { @@ -917,7 +1011,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (!isNullOrEmpty(n.getThrows())) { printer.print(" throws "); - for (final Iterator<ReferenceType<?>> i = n.getThrows().iterator(); i.hasNext(); ) { + for (final Iterator<ReferenceType<?>> i = n.getThrows().iterator(); i.hasNext();) { final ReferenceType name = i.next(); name.accept(this, arg); if (i.hasNext()) { @@ -925,11 +1019,11 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } } } - if (n.getBody() == null) { + if (!n.getBody().isPresent()) { printer.print(";"); } else { printer.print(" "); - n.getBody().accept(this, arg); + n.getBody().get().accept(this, arg); } } @@ -958,8 +1052,8 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printTypeArgs(n, arg); printer.print("this"); } else { - if (n.getExpr() != null) { - n.getExpr().accept(this, arg); + if (n.getExpr().isPresent()) { + n.getExpr().get().accept(this, arg); printer.print("."); } printTypeArgs(n, arg); @@ -981,7 +1075,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } printer.print(" "); - for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) { + for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext();) { final VariableDeclarator v = i.next(); v.accept(this, arg); if (i.hasNext()) { @@ -1001,9 +1095,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printJavaComment(n.getComment(), arg); printer.print("assert "); n.getCheck().accept(this, arg); - if (n.getMessage() != null) { + if (n.getMessage().isPresent()) { printer.print(" : "); - n.getMessage().accept(this, arg); + n.getMessage().get().accept(this, arg); } printer.print(";"); } @@ -1068,9 +1162,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { @Override public void visit(final SwitchEntryStmt n, final Void arg) { printJavaComment(n.getComment(), arg); - if (n.getLabel() != null) { + if (n.getLabel().isPresent()) { printer.print("case "); - n.getLabel().accept(this, arg); + n.getLabel().get().accept(this, arg); printer.print(":"); } else { printer.print("default:"); @@ -1090,9 +1184,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final BreakStmt n, final Void arg) { printJavaComment(n.getComment(), arg); printer.print("break"); - if (n.getId() != null) { + if (n.getId().isPresent()) { printer.print(" "); - printer.print(n.getId()); + printer.print(n.getId().get()); } printer.print(";"); } @@ -1101,9 +1195,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final ReturnStmt n, final Void arg) { printJavaComment(n.getComment(), arg); printer.print("return"); - if (n.getExpr() != null) { + if (n.getExpr().isPresent()) { printer.print(" "); - n.getExpr().accept(this, arg); + n.getExpr().get().accept(this, arg); } printer.print(";"); } @@ -1119,7 +1213,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (!n.getImplements().isEmpty()) { printer.print(" implements "); - for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) { + for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext();) { final ClassOrInterfaceType c = i.next(); c.accept(this, arg); if (i.hasNext()) { @@ -1132,7 +1226,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.indent(); if (n.getEntries() != null) { printer.println(); - for (final Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext(); ) { + for (final Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext();) { final EnumConstantDeclaration e = i.next(); e.accept(this, arg); if (i.hasNext()) { @@ -1201,20 +1295,21 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { n.getThenStmt().accept(this, arg); if (!thenBlock) printer.unindent(); - if (n.getElseStmt() != null) { + if (n.getElseStmt().isPresent()) { if (thenBlock) printer.print(" "); else printer.println(); - final boolean elseIf = n.getElseStmt() instanceof IfStmt; - final boolean elseBlock = n.getElseStmt() instanceof BlockStmt; + final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; + final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; if (elseIf || elseBlock) // put chained if and start of block statement on a same level printer.print("else "); else { printer.println("else"); printer.indent(); } - n.getElseStmt().accept(this, arg); + if (n.getElseStmt().isPresent()) + n.getElseStmt().get().accept(this, arg); if (!(elseIf || elseBlock)) printer.unindent(); } @@ -1233,9 +1328,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { public void visit(final ContinueStmt n, final Void arg) { printJavaComment(n.getComment(), arg); printer.print("continue"); - if (n.getId() != null) { + if (n.getId().isPresent()) { printer.print(" "); - printer.print(n.getId()); + printer.print(n.getId().get()); } printer.print(";"); } @@ -1266,7 +1361,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printJavaComment(n.getComment(), arg); printer.print("for ("); if (n.getInit() != null) { - for (final Iterator<Expression> i = n.getInit().iterator(); i.hasNext(); ) { + for (final Iterator<Expression> i = n.getInit().iterator(); i.hasNext();) { final Expression e = i.next(); e.accept(this, arg); if (i.hasNext()) { @@ -1275,12 +1370,12 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } } printer.print("; "); - if (n.getCompare() != null) { - n.getCompare().accept(this, arg); + if (n.getCompare().isPresent()) { + n.getCompare().get().accept(this, arg); } printer.print("; "); if (n.getUpdate() != null) { - for (final Iterator<Expression> i = n.getUpdate().iterator(); i.hasNext(); ) { + for (final Iterator<Expression> i = n.getUpdate().iterator(); i.hasNext();) { final Expression e = i.next(); e.accept(this, arg); if (i.hasNext()) { @@ -1382,9 +1477,9 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { printer.print(" "); n.getName().accept(this, arg); printer.print("()"); - if (n.getDefaultValue() != null) { + if (n.getDefaultValue().isPresent()) { printer.print(" default "); - n.getDefaultValue().accept(this, arg); + n.getDefaultValue().get().accept(this, arg); } printer.print(";"); } @@ -1413,7 +1508,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { n.getName().accept(this, arg); printer.print("("); if (n.getPairs() != null) { - for (final Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) { + for (final Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext();) { final MemberValuePair m = i.next(); m.accept(this, arg); if (i.hasNext()) { @@ -1462,7 +1557,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { if (printPar) { printer.print("("); } - for (Iterator<Parameter> i = parameters.iterator(); i.hasNext(); ) { + for (Iterator<Parameter> i = parameters.iterator(); i.hasNext();) { Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) { @@ -1483,7 +1578,6 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { } } - @Override public void visit(MethodReferenceExpr n, Void arg) { printJavaComment(n.getComment(), arg); @@ -1568,7 +1662,7 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { private void printOrphanCommentsBeforeThisChildNode(final Node node) { if (node instanceof Comment) return; - Node parent = node.getParentNode(); + Node parent = node.getParentNode().orElse(null); if (parent == null) return; List<Node> everything = new LinkedList<>(); everything.addAll(parent.getChildNodes()); @@ -1587,12 +1681,13 @@ public class PrettyPrintVisitor implements VoidVisitor<Void> { for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException( + "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } - private void printOrphanCommentsEnding(final Node node) { List<Node> everything = new LinkedList<>(); everything.addAll(node.getChildNodes()); |