diff options
Diffstat (limited to 'javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github')
143 files changed, 21279 insertions, 0 deletions
diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/CommentsInserter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/CommentsInserter.java new file mode 100644 index 000000000..eee450d20 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/CommentsInserter.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +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. + * + * @author Sebastian Kuerten + * @author Júlio Vilmar Gesser + */ +class CommentsInserter { + private final ParserConfiguration configuration; + + CommentsInserter(ParserConfiguration configuration) { + this.configuration = configuration; + } + + /** + * Comments are attributed to the thing they comment and are removed from + * the comments. + */ + private void insertComments(CompilationUnit cu, TreeSet<Comment> comments) { + if (comments.isEmpty()) + return; + + /* I should sort all the direct children and the comments, if a comment + is the first thing then it + a comment to the CompilationUnit */ + + // FIXME if there is no package it could be also a comment to the following class... + // so I could use some heuristics in these cases to distinguish the two + // cases + + List<Node> children = cu.getChildrenNodes(); + PositionUtils.sortByBeginPosition(children); + + Comment firstComment = comments.iterator().next(); + if (cu.getPackage() != null + && (children.isEmpty() || PositionUtils.areInOrder( + firstComment, children.get(0)))) { + cu.setComment(firstComment); + comments.remove(firstComment); + } + } + + /** + * This method try to attributes the nodes received to child of the node. It + * returns the node that were not attributed. + */ + void insertComments(Node node, TreeSet<Comment> commentsToAttribute) { + if (commentsToAttribute.isEmpty()) + return; + + if(node instanceof CompilationUnit){ + insertComments((CompilationUnit)node, commentsToAttribute); + } + + // the comments can: + // 1) Inside one of the child, then it is the child that have to + // associate them + // 2) If they are not inside a child they could be preceeding nothing, a + // comment or a child + // if they preceed a child they are assigned to it, otherweise they + // remain "orphans" + + List<Node> children = node.getChildrenNodes(); + PositionUtils.sortByBeginPosition(children); + + for (Node child : children) { + TreeSet<Comment> commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION); + for (Comment c : commentsToAttribute) { + if (PositionUtils.nodeContains(child, c, + configuration.doNotConsiderAnnotationsAsNodeStartForCodeAttribution)) { + commentsInsideChild.add(c); + } + } + commentsToAttribute.removeAll(commentsInsideChild); + insertComments(child, commentsInsideChild); + } + + /* I can attribute in line comments to elements preceeding them, if + there is something contained in their line */ + List<Comment> attributedComments = new LinkedList<>(); + for (Comment comment : commentsToAttribute) { + if (comment.isLineComment()) { + for (Node child : children) { + if (child.getEnd().line == comment.getBegin().line + && attributeLineCommentToNodeOrChild(child, + comment.asLineComment())) { + attributedComments.add(comment); + } + } + } + } + + /* at this point I create an ordered list of all remaining comments and + children */ + Comment previousComment = null; + attributedComments = new LinkedList<>(); + List<Node> childrenAndComments = new LinkedList<>(); + childrenAndComments.addAll(children); + childrenAndComments.addAll(commentsToAttribute); + PositionUtils.sortByBeginPosition(childrenAndComments, + configuration.doNotConsiderAnnotationsAsNodeStartForCodeAttribution); + + for (Node thing : childrenAndComments) { + if (thing instanceof Comment) { + previousComment = (Comment) thing; + if (!previousComment.isOrphan()) { + previousComment = null; + } + } else { + if (previousComment != null && !thing.hasComment()) { + if (!configuration.doNotAssignCommentsPrecedingEmptyLines + || !thereAreLinesBetween(previousComment, thing)) { + thing.setComment(previousComment); + attributedComments.add(previousComment); + previousComment = null; + } + } + } + } + + commentsToAttribute.removeAll(attributedComments); + + // all the remaining are orphan nodes + for (Comment c : commentsToAttribute) { + if (c.isOrphan()) { + node.addOrphanComment(c); + } + } + } + + private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineComment) { + // The node start and end at the same line as the comment, + // let's give to it the comment + if (node.getBegin().line == lineComment.getBegin().line + && !node.hasComment()) { + if(!(node instanceof Comment)) { + node.setComment(lineComment); + } + return true; + } 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>(); + children.addAll(node.getChildrenNodes()); + PositionUtils.sortByBeginPosition(children); + Collections.reverse(children); + + for (Node child : children) { + if (attributeLineCommentToNodeOrChild(child, lineComment)) { + return true; + } + } + + return false; + } + } + + private boolean thereAreLinesBetween(Node a, Node b) { + if (!PositionUtils.areInOrder(a, b)) { + return thereAreLinesBetween(b, a); + } + int endOfA = a.getEnd().line; + return b.getBegin().line > (endOfA + 1); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/JavaParser.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/JavaParser.java new file mode 100644 index 000000000..7fdc77f21 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/JavaParser.java @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +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.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; + +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; + +/** + * Parse Java source code and creates Abstract Syntax Trees. + * + * @author Júlio Vilmar Gesser + */ +public final class JavaParser { + private final CommentsInserter commentsInserter; + + 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. 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; + } + + /** + * 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. + * @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) { + try { + final ASTParser parser = getParserForProvider(provider); + 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 (ParseException e) { + return new ParseResult<>(e); + } catch (TokenMgrException 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 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)); + } + + /** + * 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.<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 + * {@link CompilationUnit} that represents it.<br> + * + * @param reader the reader 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 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 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)); + } + + 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 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 Expression parseExpression(final String expression) { + return 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 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 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)); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/PackageLocalClasses.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/PackageLocalClasses.java new file mode 100644 index 000000000..90a33f5ba --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/PackageLocalClasses.java @@ -0,0 +1,4 @@ +package com.github.javaparser; + +class FooClass {} +class BarClass {}
\ No newline at end of file diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseProblemException.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseProblemException.java new file mode 100644 index 000000000..f6a029886 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseProblemException.java @@ -0,0 +1,40 @@ +package com.github.javaparser; + +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; + +/** + * Thrown when parsing problems occur during parsing with the static methods on JavaParser. + */ +public class ParseProblemException extends RuntimeException { + /** + * The problems that were encountered during parsing + */ + private final List<Problem> problems; + + ParseProblemException(List<Problem> problems) { + super(createMessage(assertNotNull(problems))); + this.problems = problems; + } + + ParseProblemException(Throwable throwable) { + this(singletonList(new Problem(throwable.getMessage(), Optional.empty(), Optional.of(throwable)))); + } + + private static String createMessage(List<Problem> problems) { + StringBuilder message = new StringBuilder(); + for(Problem problem: problems){ + message.append(problem.toString()).append(EOL); + } + return message.toString(); + } + + public List<Problem> getProblems() { + return problems; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseResult.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseResult.java new file mode 100644 index 000000000..88e400525 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseResult.java @@ -0,0 +1,88 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.comments.CommentsCollection; + +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; + +/** + * The results given when parsing with an instance of JavaParser. + */ +public class ParseResult<T> { + private final Optional<T> result; + private final List<Problem> problems; + private final Optional<List<Token>> tokens; + private final Optional<CommentsCollection> commentsCollection; + + /** + * General constructor. + * @param result the AST, or empty if it wasn't created. + * @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); + } + + /** + * Used when parsing failed completely with an exception. + */ + ParseResult(Throwable throwable) { + this(Optional.empty(), singletonList(new Problem(throwable.getMessage(), Optional.empty(), Optional.of(throwable))), Optional.empty(), Optional.empty()); + } + + /** + * @return if parsing was successful, meaning no errors of any kind were encountered. + */ + public boolean isSuccessful() { + return problems.isEmpty() && result.isPresent(); + } + + /** + * @return the list of encountered parsing problems. Empty when no problems were encountered. + */ + public List<Problem> getProblems() { + return problems; + } + + /** + * @return the complete list of tokens that were parsed, or empty if parsing failed completely. + */ + public Optional<List<Token>> getTokens() { + return tokens; + } + + /** + * @return the complete collection of comments encountered while parsing. + */ + public Optional<CommentsCollection> getCommentsCollection() { + return commentsCollection; + } + + /** + * @return the AST of the parsed source code, or empty if parsing failed completely. + */ + public Optional<T> getResult() { + return result; + } + + @Override + public String toString() { + if (isSuccessful()) { + return "Parsing successful"; + } + StringBuilder message = new StringBuilder("Parsing failed:").append(EOL); + for (Problem problem : problems) { + message.append(problem.toString()).append(EOL); + } + return message.toString(); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseStart.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseStart.java new file mode 100644 index 000000000..f94a66282 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParseStart.java @@ -0,0 +1,32 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; + +/** + * The start production for JavaParser. + * Tells JavaParser what piece of Java code it can expect. + * For example, + * COMPILATION_UNIT indicates a complete Java file, + * and CLASS_BODY would indicate the part of a class that is within { and }. + * @see JavaParser#parse(ParseStart, Provider) + */ +@FunctionalInterface +public interface ParseStart<R> { + ParseStart<CompilationUnit> COMPILATION_UNIT = ASTParser::CompilationUnit; + ParseStart<BlockStmt> BLOCK = ASTParser::Block; + ParseStart<Statement> STATEMENT = ASTParser::BlockStatement; + ParseStart<ImportDeclaration> IMPORT_DECLARATION= ASTParser::ImportDeclaration; + ParseStart<Expression> EXPRESSION = ASTParser::Expression; + ParseStart<AnnotationExpr> ANNOTATION = ASTParser::Annotation; + ParseStart<BodyDeclaration<?>> ANNOTATION_BODY = ASTParser::AnnotationBodyDeclaration; + ParseStart<BodyDeclaration<?>> CLASS_BODY = p -> p.ClassOrInterfaceBodyDeclaration(false); + ParseStart<BodyDeclaration<?>> INTERFACE_BODY = p -> p.ClassOrInterfaceBodyDeclaration(true); + + R parse(ASTParser parser) throws ParseException; +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParserConfiguration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParserConfiguration.java new file mode 100644 index 000000000..0b165b6e2 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ParserConfiguration.java @@ -0,0 +1,6 @@ +package com.github.javaparser; + +public class ParserConfiguration { + public boolean doNotAssignCommentsPrecedingEmptyLines = true; + public boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false; +}
\ No newline at end of file diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Position.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Position.java new file mode 100644 index 000000000..312824445 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Position.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.Node; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * A position in a source file. Lines and columns start counting at 1. + */ +public class Position implements Comparable<Position> { + public final int line; + public final int column; + + public static final Position ABSOLUTE_START = new Position(Node.ABSOLUTE_BEGIN_LINE, -1); + public static final Position ABSOLUTE_END = new Position(Node.ABSOLUTE_END_LINE, -1); + + /** + * The first position in the file + */ + public static final Position HOME = new Position(1, 1); + public static final Position UNKNOWN = new Position(0, 0); + + public Position(int line, int column) { + if (line < Node.ABSOLUTE_END_LINE) { + throw new IllegalArgumentException("Can't position at line " + line); + } + if (column < -1) { + throw new IllegalArgumentException("Can't position at column " + column); + } + this.line = line; + this.column = column; + } + + /** + * Convenient factory method. + */ + public static Position pos(int line, int column) { + return new Position(line, column); + } + + public Position withColumn(int column) { + return new Position(this.line, column); + } + + public Position withLine(int line) { + return new Position(line, this.column); + } + + /** + * Check if the position is usable. Does not know what it is pointing at, so it can't check if the position is after the end of the source. + */ + public boolean valid() { + return line > 0 && column > 0; + } + + public boolean invalid() { + return !valid(); + } + + public Position orIfInvalid(Position anotherPosition) { + if (valid()) { + return this; + } + return anotherPosition; + } + + public boolean isAfter(Position position) { + assertNotNull(position); + if (position.line == Node.ABSOLUTE_BEGIN_LINE) return true; + if (line > position.line) { + return true; + } else if (line == position.line) { + return column > position.column; + } + return false; + + } + + public boolean isBefore(Position position) { + assertNotNull(position); + if (position.line == Node.ABSOLUTE_END_LINE) return true; + if (line < position.line) { + return true; + } else if (line == position.line) { + return column < position.column; + } + return false; + } + + @Override + public int compareTo(Position o) { + assertNotNull(o); + if (isBefore(o)) { + return -1; + } + if (isAfter(o)) { + return 1; + } + return 0; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Position position = (Position) o; + + return line == position.line && column == position.column; + } + + @Override + public int hashCode() { + return 31 * line + column; + } + + @Override + public String toString() { + return "(line " + line + ",col " + column + ")"; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Problem.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Problem.java new file mode 100644 index 000000000..7e45cc987 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Problem.java @@ -0,0 +1,39 @@ +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; + + Problem(String message, Optional<Range> range, Optional<Throwable> cause) { + this.message = assertNotNull(message); + this.range = assertNotNull(range); + this.cause = assertNotNull(cause); + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(message); + range.ifPresent(r -> str.append(" ").append(r)); + return str.toString(); + } + + public String getMessage() { + return message; + } + + public Optional<Range> getRange() { + return range; + } + + public Optional<Throwable> getCause() { + return cause; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Providers.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Providers.java new file mode 100644 index 000000000..b5e731c09 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Providers.java @@ -0,0 +1,61 @@ +package com.github.javaparser; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.OpenOption; +import java.nio.file.Path; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Factory for providers of source code for JavaParser. + * Providers that have no parameter for encoding but need it will use UTF-8. + */ +public final class Providers { + public static final Charset UTF8 = Charset.forName("utf-8"); + + private Providers() { + } + + public static Provider provider(Reader reader) { + return new StreamProvider(assertNotNull(reader)); + } + + public static Provider provider(InputStream input, Charset encoding) { + assertNotNull(input); + assertNotNull(encoding); + try { + return new StreamProvider(input, encoding.name()); + } catch (IOException e) { + // The only one that is thrown is UnsupportedCharacterEncodingException, + // and that's a fundamental problem, so runtime exception. + throw new RuntimeException(e); + } + } + + public static Provider provider(InputStream input) { + return provider(input, UTF8); + } + + public static Provider provider(File file, Charset encoding) throws FileNotFoundException { + return provider(new FileInputStream(assertNotNull(file)), assertNotNull(encoding)); + } + + public static Provider provider(File file) throws FileNotFoundException { + return provider(assertNotNull(file), UTF8); + } + + public static Provider provider(Path path, Charset encoding) throws IOException { + return provider(Files.newInputStream(assertNotNull(path)), assertNotNull(encoding)); + } + + public static Provider provider(Path path) throws IOException { + return provider(assertNotNull(path), UTF8); + } + + public static Provider provider(String source) { + return new StringProvider(assertNotNull(source)); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Range.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Range.java new file mode 100644 index 000000000..68e364aed --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/Range.java @@ -0,0 +1,89 @@ +package com.github.javaparser; + +import static com.github.javaparser.Position.pos; + +/** + * A range of characters in a source file, from "begin" to "end", including the characters at "begin" and "end". + */ +public class Range { + public static final Range UNKNOWN = range(Position.UNKNOWN, Position.UNKNOWN); + + public final Position begin; + public final Position end; + + public Range(Position begin, Position end) { + if (begin == null) { + throw new IllegalArgumentException("begin can't be null"); + } + if (end == null) { + throw new IllegalArgumentException("end can't be null"); + } + this.begin = begin; + this.end = end; + } + + public static Range range(Position begin, Position end) { + return new Range(begin, end); + } + + public static Range range(int beginLine, int beginColumn, int endLine, int endColumn) { + return new Range(pos(beginLine, beginColumn), pos(endLine, endColumn)); + } + + public Range withBeginColumn(int column) { + return range(begin.withColumn(column), end); + } + + public Range withBeginLine(int line) { + return range(begin.withLine(line), end); + } + + public Range withEndColumn(int column) { + return range(begin, end.withColumn(column)); + } + + public Range withEndLine(int line) { + return range(begin, end.withLine(line)); + } + + public Range withBegin(Position begin) { + return range(begin, this.end); + } + + public Range withEnd(Position end) { + return range(this.begin, end); + } + + public boolean contains(Range other) { + return begin.isBefore(other.begin) && end.isAfter(other.end); + } + + public boolean isBefore(Position position) { + return end.isBefore(position); + } + + public boolean isAfter(Position position) { + return begin.isAfter(position); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Range range = (Range) o; + + return begin.equals(range.begin) && end.equals(range.end); + + } + + @Override + public int hashCode() { + return 31 * begin.hashCode() + end.hashCode(); + } + + @Override + public String toString() { + return begin+"-"+end; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java new file mode 100644 index 000000000..f23f8631d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +/** + * Access specifier. Represents one of the possible levels of + * access permitted by the language. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public enum AccessSpecifier { + + PUBLIC("public"), + PRIVATE("private"), + PROTECTED("protected"), + DEFAULT(""); + + private String codeRepresenation; + + AccessSpecifier(String codeRepresentation) { + this.codeRepresenation = codeRepresentation; + } + + public String getCodeRepresenation(){ + return this.codeRepresenation; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayBracketPair.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayBracketPair.java new file mode 100644 index 000000000..cca0b8761 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayBracketPair.java @@ -0,0 +1,44 @@ +package com.github.javaparser.ast; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * In, for example, <code>int[] a[];</code> there are two ArrayBracketPair objects, + * one for the [] after int, one for the [] after a. + */ +public class ArrayBracketPair extends Node implements NodeWithAnnotations<ArrayBracketPair> { + private List<AnnotationExpr> annotations; + + public ArrayBracketPair(Range range, List<AnnotationExpr> annotations) { + super(range); + setAnnotations(annotations); + } + + @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 List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + public ArrayBracketPair setAnnotations(List<AnnotationExpr> annotations) { + setAsParentNodeOf(annotations); + this.annotations = annotations; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayCreationLevel.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayCreationLevel.java new file mode 100644 index 000000000..2edc68c2a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ArrayCreationLevel.java @@ -0,0 +1,56 @@ +package com.github.javaparser.ast; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * 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> { + private Expression dimension; + private List<AnnotationExpr> annotations; + + public ArrayCreationLevel(Range range, Expression dimension, List<AnnotationExpr> annotations) { + super(range); + setDimension(dimension); + setAnnotations(annotations); + } + + @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 void setDimension(Expression dimension) { + this.dimension = dimension; + setAsParentNodeOf(dimension); + } + + public Expression getDimension() { + return dimension; + } + + public List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + public ArrayCreationLevel setAnnotations(List<AnnotationExpr> annotations) { + setAsParentNodeOf(annotations); + this.annotations = annotations; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java new file mode 100644 index 000000000..2f30777de --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java @@ -0,0 +1,413 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +import static com.github.javaparser.ast.expr.NameExpr.*; +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.utils.ClassUtils; +import com.github.javaparser.Range; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.NameExpr; +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.ensureNotNull; + +/** + * <p> + * This class represents the entire compilation unit. Each java file denotes a + * compilation unit. + * </p> + * The CompilationUnit is constructed following the syntax:<br> + * + * <pre> + * {@code + * CompilationUnit ::= ( }{@link PackageDeclaration}{@code )? + * ( }{@link ImportDeclaration}{@code )* + * ( }{@link TypeDeclaration}{@code )* + * } + * </pre> + * + * @author Julio Vilmar Gesser + */ +public final class CompilationUnit extends Node { + + private PackageDeclaration pakage; + + private List<ImportDeclaration> imports; + + private List<TypeDeclaration<?>> types; + + public CompilationUnit() { + } + + public CompilationUnit(PackageDeclaration pakage, List<ImportDeclaration> imports, List<TypeDeclaration<?>> types) { + setPackage(pakage); + setImports(imports); + setTypes(types); + } + + public CompilationUnit(Range range, PackageDeclaration pakage, List<ImportDeclaration> imports, + List<TypeDeclaration<?>> types) { + super(range); + setPackage(pakage); + setImports(imports); + setTypes(types); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + /** + * Return a list containing all comments declared in this compilation unit. + * Including javadocs, line comments and block comments of all types, + * inner-classes and other members.<br> + * If there is no comment, <code>null</code> is returned. + * + * @return list with all comments of this compilation unit or + * <code>null</code> + * @see JavadocComment + * @see com.github.javaparser.ast.comments.LineComment + * @see com.github.javaparser.ast.comments.BlockComment + */ + public List<Comment> getComments() { + return this.getAllContainedComments(); + } + + /** + * Retrieves the list of imports declared in this compilation unit or + * <code>null</code> if there is no import. + * + * @return the list of imports or <code>null</code> if there is no import + */ + public List<ImportDeclaration> getImports() { + imports = ensureNotNull(imports); + return imports; + } + + /** + * Retrieves the package declaration of this compilation unit.<br> + * If this compilation unit has no package declaration (default package), + * <code>null</code> is returned. + * + * @return the package declaration or <code>null</code> + */ + public PackageDeclaration getPackage() { + return pakage; + } + + /** + * Return the list of types declared in this compilation unit.<br> + * If there is no types declared, <code>null</code> is returned. + * + * @return the list of types or <code>null</code> null if there is no type + * @see AnnotationDeclaration + * @see ClassOrInterfaceDeclaration + * @see EmptyTypeDeclaration + * @see EnumDeclaration + */ + public List<TypeDeclaration<?>> getTypes() { + types = ensureNotNull(types); + return types; + } + + /** + * Sets the list of comments of this compilation unit. + * + * @param comments + * the list of comments + */ + public CompilationUnit setComments(List<Comment> comments) { + throw new RuntimeException("Not implemented!"); + } + + /** + * Sets the list of imports of this compilation unit. The list is initially + * <code>null</code>. + * + * @param imports + * the list of imports + */ + public CompilationUnit setImports(List<ImportDeclaration> imports) { + this.imports = imports; + setAsParentNodeOf(this.imports); + return this; + } + + /** + * Sets or clear the package declarations of this compilation unit. + * + * @param pakage + * the pakage declaration to set or <code>null</code> to default + * package + */ + public CompilationUnit setPackage(PackageDeclaration pakage) { + this.pakage = pakage; + setAsParentNodeOf(this.pakage); + return this; + } + + /** + * Sets the list of types declared in this compilation unit. + * + * @param types + * the lis of types + */ + public CompilationUnit setTypes(List<TypeDeclaration<?>> types) { + this.types = types; + setAsParentNodeOf(this.types); + return this; + } + + /** + * sets the package declaration of this compilation unit + * + * @param name the name of the package + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit setPackageName(String name) { + setPackage(new PackageDeclaration(name(name))); + return this; + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br> + * shorthand for {@link #addImport(String, boolean, boolean)} with name,false,false + * + * @param name the import name + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit addImport(String name) { + return addImport(name, false, false); + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br> + * shorthand for {@link #addImport(String)} with clazz.getName() + * + * @param clazz the class to import + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit addImport(Class<?> clazz) { + if (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.getName().startsWith("java.lang")) + return this; + else if (clazz.isArray() && !ClassUtils.isPrimitiveOrWrapper(clazz.getComponentType()) + && !clazz.getComponentType().getName().startsWith("java.lang")) + return addImport(clazz.getComponentType().getName()); + return addImport(clazz.getName()); + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br> + * <b>This method check if no import with the same name is already in the list</b> + * + * @param name the import name + * @param isStatic is it an "import static" + * @param isAsterisk does the import end with ".*" + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit addImport(String name, boolean isStatic, boolean isAsterisk) { + if (getImports().stream().anyMatch(i -> i.getName().toString().equals(name))) + return this; + else { + ImportDeclaration importDeclaration = new ImportDeclaration(name(name), isStatic, + isAsterisk); + getImports().add(importDeclaration); + importDeclaration.setParentNode(this); + return this; + } + } + + /** + * Add a public class to the types of this compilation unit + * + * @param name the class name + * @return the newly created class + */ + public ClassOrInterfaceDeclaration addClass(String name) { + return addClass(name, Modifier.PUBLIC); + } + + /** + * Add a class to the types of this compilation unit + * + * @param name the class name + * @param modifiers the modifiers (like Modifier.PUBLIC) + * @return the newly created class + */ + public ClassOrInterfaceDeclaration addClass(String name, Modifier... modifiers) { + ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration( + Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), + false, name); + getTypes().add(classOrInterfaceDeclaration); + classOrInterfaceDeclaration.setParentNode(this); + return classOrInterfaceDeclaration; + } + + /** + * Add a public interface class to the types of this compilation unit + * + * @param name the interface name + * @return the newly created class + */ + public ClassOrInterfaceDeclaration addInterface(String name) { + return addInterface(name, Modifier.PUBLIC); + } + + /** + * Add an interface to the types of this compilation unit + * + * @param name the interface name + * @param modifiers the modifiers (like Modifier.PUBLIC) + * @return the newly created class + */ + public ClassOrInterfaceDeclaration addInterface(String name, Modifier... modifiers) { + ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration( + Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), + true, name); + getTypes().add(classOrInterfaceDeclaration); + classOrInterfaceDeclaration.setParentNode(this); + return classOrInterfaceDeclaration; + } + + /** + * Add a public enum to the types of this compilation unit + * + * @param name the enum name + * @return the newly created class + */ + public EnumDeclaration addEnum(String name) { + return addEnum(name, Modifier.PUBLIC); + } + + /** + * Add an enum to the types of this compilation unit + * + * @param name the enum name + * @param modifiers the modifiers (like Modifier.PUBLIC) + * @return the newly created class + */ + public EnumDeclaration addEnum(String name, Modifier... modifiers) { + EnumDeclaration enumDeclaration = new EnumDeclaration(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), name); + getTypes().add(enumDeclaration); + enumDeclaration.setParentNode(this); + return enumDeclaration; + } + + /** + * Add a public annotation declaration to the types of this compilation unit + * + * @param name the annotation name + * @return the newly created class + */ + public AnnotationDeclaration addAnnotationDeclaration(String name) { + return addAnnotationDeclaration(name, Modifier.PUBLIC); + } + + /** + * Add an annotation declaration to the types of this compilation unit + * + * @param name the annotation name + * @param modifiers the modifiers (like Modifier.PUBLIC) + * @return the newly created class + */ + public AnnotationDeclaration addAnnotationDeclaration(String name, Modifier... modifiers) { + AnnotationDeclaration annotationDeclaration = new AnnotationDeclaration(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), name); + getTypes().add(annotationDeclaration); + annotationDeclaration.setParentNode(this); + return annotationDeclaration; + } + + /** + * Try to get a class by its name + * + * @param className the class name (case-sensitive) + * @return null if not found, the class otherwise + */ + public ClassOrInterfaceDeclaration getClassByName(String className) { + return (ClassOrInterfaceDeclaration) getTypes().stream().filter(type -> type.getName().equals(className) + && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()) + .findFirst().orElse(null); + } + + /** + * Try to get an interface by its name + * + * @param interfaceName the interface name (case-sensitive) + * @return null if not found, the interface otherwise + */ + public ClassOrInterfaceDeclaration getInterfaceByName(String interfaceName) { + return (ClassOrInterfaceDeclaration) getTypes().stream().filter(type -> type.getName().equals(interfaceName) + && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()) + .findFirst().orElse(null); + } + + /** + * Try to get an enum by its name + * + * @param enumName the enum name (case-sensitive) + * @return null if not found, the enum otherwise + */ + public EnumDeclaration getEnumByName(String enumName) { + return (EnumDeclaration) getTypes().stream().filter(type -> type.getName().equals(enumName) + && type instanceof EnumDeclaration) + .findFirst().orElse(null); + } + + /** + * Try to get an annotation by its name + * + * @param annotationName the annotation name (case-sensitive) + * @return null if not found, the annotation otherwise + */ + public AnnotationDeclaration getAnnotationDeclarationByName(String annotationName) { + return (AnnotationDeclaration) getTypes().stream().filter(type -> type.getName().equals(annotationName) + && type instanceof AnnotationDeclaration) + .findFirst().orElse(null); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Example.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Example.java new file mode 100644 index 000000000..70cf2cd91 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Example.java @@ -0,0 +1,31 @@ +package com.github.javaparser.ast; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseException; +import com.github.javaparser.ast.CompilationUnit; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; + +/** + * Created by federico on 07/01/16. + */ +public class Example { + + public static void main(String[] args) throws UnsupportedEncodingException, ParseException { + String code = "interface A {\n" + + " default Comparator<T> thenComparing(Comparator<? super T> other) {\n" + + " Objects.requireNonNull(other);\n" + + " return (Comparator<T> & Serializable) (c1, c2) -> { // this is the defaulting line\n" + + " int res = compare(c1, c2);\n" + + " return (res != 0) ? res : other.compare(c1, c2);\n" + + " };\n" + + " }\n" + + "}"; + InputStream stream = new ByteArrayInputStream(code.getBytes("UTF-8")); + CompilationUnit cu = JavaParser.parse(stream); + + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ImportDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ImportDeclaration.java new file mode 100644 index 000000000..863c8d364 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/ImportDeclaration.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * <p> + * This class represents a import declaration or an empty import declaration. Imports are optional for the + * {@link CompilationUnit}. + * </p> + * The ImportDeclaration is constructed following the syntax:<br> + * <pre> + * {@code + * ImportDeclaration ::= "import" ( "static" )? }{@link NameExpr}{@code ( "." "*" )? ";" + * } + * </pre> + * An enmpty import declaration is simply a semicolon among the import declarations. + * @author Julio Vilmar Gesser + */ +public final class ImportDeclaration extends Node { + + private NameExpr name; + private boolean static_; + private boolean asterisk; + private boolean isEmptyImportDeclaration; + + private ImportDeclaration() { + this.isEmptyImportDeclaration = true; + static_ = false; + asterisk = false; + } + + private ImportDeclaration(Range range) { + super(range); + this.isEmptyImportDeclaration = true; + static_ = false; + asterisk = false; + } + + /** + * Create an empty import declaration without specifying its position. + */ + public static ImportDeclaration createEmptyDeclaration(){ + return new ImportDeclaration(); + } + + /** + * Create an empty import declaration specifying its position. + */ + public static ImportDeclaration createEmptyDeclaration(Range range){ + return new ImportDeclaration(range); + } + + public ImportDeclaration(NameExpr name, boolean isStatic, boolean isAsterisk) { + setAsterisk(isAsterisk); + setName(name); + setStatic(isStatic); + this.isEmptyImportDeclaration = false; + } + + public ImportDeclaration(Range range, NameExpr name, boolean isStatic, boolean isAsterisk) { + super(range); + setAsterisk(isAsterisk); + setName(name); + setStatic(isStatic); + this.isEmptyImportDeclaration = false; + } + + /** + * Is this an empty import declaration or a normal import declaration? + */ + public boolean isEmptyImportDeclaration(){ + return this.isEmptyImportDeclaration; + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + /** + * Retrieves the name of the import. + * + * @return the name of the import + * @throws UnsupportedOperationException when invoked on an empty import declaration + */ + public NameExpr getName() { + if (isEmptyImportDeclaration) { + throw new UnsupportedOperationException("Empty import declarations have no name"); + } + return name; + } + + /** + * Return if the import ends with "*". + * + * @return <code>true</code> if the import ends with "*", <code>false</code> + * otherwise + */ + public boolean isAsterisk() { + return asterisk; + } + + /** + * Return if the import is static. + * + * @return <code>true</code> if the import is static, <code>false</code> + * otherwise + */ + public boolean isStatic() { + return static_; + } + + /** + * Sets if this import is asterisk. + * + * @param asterisk + * <code>true</code> if this import is asterisk + * @throws UnsupportedOperationException when setting true on an empty import declaration + */ + public ImportDeclaration setAsterisk(boolean asterisk) { + if (isEmptyImportDeclaration && asterisk) { + throw new UnsupportedOperationException("Empty import cannot have asterisk"); + } + this.asterisk = asterisk; + return this; + } + + /** + * Sets the name this import. + * + * @param name + * the name to set + * @throws UnsupportedOperationException when invoked on an empty import declaration + */ + public ImportDeclaration setName(NameExpr name) { + if (isEmptyImportDeclaration) { + throw new UnsupportedOperationException("Empty import cannot have name"); + } + this.name = name; + setAsParentNodeOf(this.name); + return this; + } + + /** + * Sets if this import is static. + * + * @param static_ + * <code>true</code> if this import is static + * @throws UnsupportedOperationException when setting true on an empty import declaration + */ + public ImportDeclaration setStatic(boolean static_) { + if (isEmptyImportDeclaration && static_) { + throw new UnsupportedOperationException("Empty import cannot be static"); + } + this.static_ = static_; + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Modifier.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Modifier.java new file mode 100644 index 000000000..3f5a50b45 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Modifier.java @@ -0,0 +1,46 @@ +package com.github.javaparser.ast; + +import java.util.EnumSet; + +public enum Modifier { + PUBLIC("public"), + PROTECTED("protected"), + PRIVATE("private"), + ABSTRACT("abstract"), + STATIC("static"), + FINAL("final"), + TRANSIENT("transient"), + VOLATILE("volatile"), + SYNCHRONIZED("synchronized"), + NATIVE("native"), + STRICTFP("strictfp"); + + String lib; + + private Modifier(String lib) { + this.lib = lib; + } + + /** + * @return the lib + */ + public String getLib() { + return lib; + } + + public EnumSet<Modifier> toEnumSet() { + return EnumSet.of(this); + } + + public static AccessSpecifier getAccessSpecifier(EnumSet<Modifier> modifiers) { + if (modifiers.contains(Modifier.PUBLIC)) { + return AccessSpecifier.PUBLIC; + } else if (modifiers.contains(Modifier.PROTECTED)) { + return AccessSpecifier.PROTECTED; + } else if (modifiers.contains(Modifier.PRIVATE)) { + return AccessSpecifier.PRIVATE; + } else { + return AccessSpecifier.DEFAULT; + } + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Node.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Node.java new file mode 100644 index 000000000..f2bae43b1 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/Node.java @@ -0,0 +1,396 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +import com.github.javaparser.Position; +import com.github.javaparser.Range; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.visitor.*; + +import java.util.*; + +/** + * Abstract class for all nodes of the AST. + * + * Each Node can have one associated comment which describe it and + * a number of "orphan comments" which it contains but are not specifically + * associated to any element. + * + * @author Julio Vilmar Gesser + */ +public abstract class Node implements Cloneable { + /** + * This can be used to sort nodes on position. + */ + public static Comparator<Node> NODE_BY_BEGIN_POSITION = (a, b) -> a.getBegin().compareTo(b.getBegin()); + + private Range range; + + private Node parentNode; + + private List<Node> childrenNodes = new LinkedList<>(); + private List<Comment> orphanComments = new LinkedList<>(); + + private IdentityHashMap<UserDataKey<?>, Object> userData = null; + + private Comment comment; + + public Node() { + this(Range.UNKNOWN); + } + + public Node(Range range) { + this.range = range; + } + + /** + * Accept method for visitor support. + * + * @param <R> + * the type the return value of the visitor + * @param <A> + * the type the argument passed to the visitor + * @param v + * the visitor implementation + * @param arg + * the argument passed to the visitor + * @return the result of the visit + */ + public abstract <R, A> R accept(GenericVisitor<R, A> v, A arg); + + /** + * Accept method for visitor support. + * + * @param <A> + * the type the argument passed for the visitor + * @param v + * the visitor implementation + * @param arg + * any value relevant for the visitor + */ + public abstract <A> void accept(VoidVisitor<A> v, A arg); + + /** + * This is a comment associated with this node. + * + * @return comment property + */ + public final Comment getComment() { + return comment; + } + + /** + * The begin position of this node in the source file. + */ + public Position getBegin() { + return range.begin; + } + + /** + * The end position of this node in the source file. + */ + public Position getEnd() { + return range.end; + } + + /** + * Sets the begin position of this node in the source file. + */ + public Node setBegin(Position begin) { + range = range.withBegin(begin); + return this; + } + + /** + * Sets the end position of this node in the source file. + */ + public Node setEnd(Position end) { + range = range.withEnd(end); + return this; + } + + /** + * @return the range of characters in the source code that this node covers. + */ + public Range getRange() { + return range; + } + + /** + * @param range the range of characters in the source code that this node covers. + */ + public Node setRange(Range range) { + this.range = range; + return this; + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setComment(final Comment comment) { + if (comment != null && (this instanceof Comment)) { + throw new RuntimeException("A comment can not be commented"); + } + if (this.comment != null) { + this.comment.setCommentedNode(null); + } + this.comment = comment; + if (comment != null) { + this.comment.setCommentedNode(this); + } + return this; + } + + + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setLineComment(String comment) { + return setComment(new LineComment(comment)); + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setBlockComment(String comment) { + return setComment(new BlockComment(comment)); + } + + /** + * Return the String representation of this node. + * + * @return the String representation of this node + */ + @Override + public final String toString() { + final DumpVisitor visitor = new DumpVisitor(); + accept(visitor, null); + return visitor.getSource(); + } + + public final String toStringWithoutComments() { + final DumpVisitor visitor = new DumpVisitor(false); + accept(visitor, null); + return visitor.getSource(); + } + + @Override + public final int hashCode() { + return toString().hashCode(); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof Node)) { + return false; + } + return EqualsVisitor.equals(this, (Node) obj); + } + + @Override + public Node clone() { + return this.accept(new CloneVisitor(), null); + } + + public Node getParentNode() { + return parentNode; + } + + @SuppressWarnings("unchecked") + public <T> T getParentNodeOfType(Class<T> classType) { + Node parent = parentNode; + while (parent != null) { + if (classType.isAssignableFrom(parent.getClass())) + return (T) parent; + parent = parent.parentNode; + } + return null; + } + + public List<Node> getChildrenNodes() { + return childrenNodes; + } + + public boolean contains(Node other) { + return range.contains(other.range); + } + + public void addOrphanComment(Comment comment) { + orphanComments.add(comment); + comment.setParentNode(this); + } + + /** + * This is a list of Comment which are inside the node and are not associated + * with any meaningful AST Node. + * + * For example, comments at the end of methods (immediately before the parenthesis) + * or at the end of CompilationUnit are orphan comments. + * + * When more than one comment preceeds a statement, the one immediately preceding it + * it is associated with the statements, while the others are orphans. + * + * @return all comments that cannot be attributed to a concept + */ + public List<Comment> getOrphanComments() { + return orphanComments; + } + + /** + * This is the list of Comment which are contained in the Node either because + * they are properly associated to one of its children or because they are floating + * around inside the Node + * + * @return all Comments within the node as a list + */ + public List<Comment> getAllContainedComments() { + List<Comment> comments = new LinkedList<>(); + comments.addAll(getOrphanComments()); + + for (Node child : getChildrenNodes()) { + if (child.getComment() != null) { + comments.add(child.getComment()); + } + comments.addAll(child.getAllContainedComments()); + } + + return comments; + } + + /** + * Assign a new parent to this node, removing it + * from the list of children of the previous parent, if any. + * + * @param parentNode node to be set as parent + */ + public void setParentNode(Node parentNode) { + // remove from old parent, if any + if (this.parentNode != null) { + this.parentNode.childrenNodes.remove(this); + } + this.parentNode = parentNode; + // add to new parent, if any + if (this.parentNode != null) { + this.parentNode.childrenNodes.add(this); + } + } + + protected void setAsParentNodeOf(List<? extends Node> childNodes) { + if (childNodes != null) { + for (Node current : childNodes) { + current.setParentNode(this); + } + } + } + + protected void setAsParentNodeOf(Node childNode) { + if (childNode != null) { + childNode.setParentNode(this); + } + } + + public static final int ABSOLUTE_BEGIN_LINE = -1; + public static final int ABSOLUTE_END_LINE = -2; + + public boolean isPositionedAfter(Position position) { + return range.isAfter(position); + } + + public boolean isPositionedBefore(Position position) { + return range.isBefore(position); + } + + public boolean hasComment() { + return comment != null; + } + + public void tryAddImportToParentCompilationUnit(Class<?> clazz) { + CompilationUnit parentNode = getParentNodeOfType(CompilationUnit.class); + if (parentNode != null) { + parentNode.addImport(clazz); + } + } + + /** + * Recursively finds all nodes of a certain type. + * + * @param clazz the type of node to find. + */ + public <N extends Node> List<N> getNodesByType(Class<N> clazz) { + List<N> nodes = new ArrayList<>(); + for (Node child : getChildrenNodes()) { + if (clazz.isInstance(child)) { + nodes.add(clazz.cast(child)); + } + nodes.addAll(child.getNodesByType(clazz)); + } + return nodes; + } + + /** + * Gets user data for this component using the given key. + * + * @param <M> + * The type of the user data. + * + * @param key + * The key for the data + * @return The user data or null of no user data was found for the given key + * @see UserDataKey + */ + public <M> M getUserData(final UserDataKey<M> key) { + if (userData == null) { + return null; + } + return (M) userData.get(key); + } + + /** + * Sets user data for this component using the given key. + * For information on creating UserDataKey, see {@link UserDataKey}. + * + * @param <M> + * The type of user data + * + * @param key + * The singleton key for the user data + * @param object + * The user data object + * @throws IllegalArgumentException + * @see UserDataKey + */ + public <M> void setUserData(UserDataKey<M> key, M object) { + if (userData == null) { + userData = new IdentityHashMap<>(); + } + userData.put(key, object); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/PackageDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/PackageDeclaration.java new file mode 100644 index 000000000..4252ad4e9 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/PackageDeclaration.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.utils.Utils; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +/** + * <p> + * This class represents the package declaration. The package declaration is + * optional for the {@link CompilationUnit}. + * </p> + * The PackageDeclaration is constructed following the syntax:<br> + * <pre> + * {@code + * PackageDeclaration ::= ( }{@link AnnotationExpr}{@code )* "package" }{@link NameExpr}{@code ) ";" + * } + * </pre> + * @author Julio Vilmar Gesser + */ +public final class PackageDeclaration extends Node implements NodeWithAnnotations<PackageDeclaration> { + + private List<AnnotationExpr> annotations; + + private NameExpr name; + + public PackageDeclaration() { + } + + public PackageDeclaration(NameExpr name) { + setName(name); + } + + public PackageDeclaration(List<AnnotationExpr> annotations, NameExpr name) { + setAnnotations(annotations); + setName(name); + } + + public PackageDeclaration(Range range, List<AnnotationExpr> annotations, NameExpr name) { + super(range); + setAnnotations(annotations); + setName(name); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + /** + * Retrieves the list of annotations declared before the package + * declaration. Return <code>null</code> if there are no annotations. + * + * @return list of annotations or <code>null</code> + */ + public List<AnnotationExpr> getAnnotations() { + annotations = Utils.ensureNotNull(annotations); + return annotations; + } + + /** + * Return the name expression of the package. + * + * @return the name of the package + */ + public NameExpr getName() { + return name; + } + + /** + * Get full package name. + */ + public String getPackageName() { + return name.toString(); + } + + /** + * @param annotations + * the annotations to set + */ + public PackageDeclaration setAnnotations(List<AnnotationExpr> annotations) { + this.annotations = annotations; + setAsParentNodeOf(this.annotations); + return this; + } + + /** + * Sets the name of this package declaration. + * + * @param name + * the name to set + */ + public PackageDeclaration setName(NameExpr name) { + this.name = name; + setAsParentNodeOf(this.name); + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/UserDataKey.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/UserDataKey.java new file mode 100644 index 000000000..4d7caa2e2 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/UserDataKey.java @@ -0,0 +1,39 @@ +package com.github.javaparser.ast; + +/** + * A key to a piece of user data associated with a {@link Node} at runtime. + * The key contains type information that can be used to check the + * type of any user data value for the key when the value is set. UserDataKey is abstract in order to + * force the creation of a subtype. That subtype is used to test for identity when looking for the + * user data because actual object identity would suffer from problems under serialization. + * So, the correct way to declare a UserDataKey is like this: + * + * <pre> + * <code> + * public static final UserDataKey<Role> ROLE = new UserDataKey<Role>() { }; + * </code> + * </pre> + * + * This code was taken from the <a href="http://wicket.apache.org/">Wicket project</a>. + * + * @param <T> + * The type of the object which is stored + * + * @see Node#getUserData(UserDataKey) + */ +public abstract class UserDataKey<T> { + @Override + public int hashCode() + { + return getClass().hashCode(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + return obj != null && getClass().equals(obj.getClass()); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationDeclaration.java new file mode 100644 index 000000000..74d84e822 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationDeclaration.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import java.util.List; + +import java.util.EnumSet; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> { + + public AnnotationDeclaration() { + } + + public AnnotationDeclaration(EnumSet<Modifier> modifiers, String name) { + super(modifiers, name); + } + + public AnnotationDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, String name, + List<BodyDeclaration<?>> members) { + super(annotations, modifiers, name, members); + } + + public AnnotationDeclaration(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, String name, + List<BodyDeclaration<?>> members) { + super(range, annotations, modifiers, name, members); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java new file mode 100644 index 000000000..66b9dc3a3 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.EnumSet; +import java.util.List; + +/** + * @author Julio Vilmar Gesser + */ +public final class AnnotationMemberDeclaration extends BodyDeclaration<AnnotationMemberDeclaration> + implements NodeWithJavaDoc<AnnotationMemberDeclaration>, NodeWithName<AnnotationMemberDeclaration>, + NodeWithType<AnnotationMemberDeclaration>, NodeWithModifiers<AnnotationMemberDeclaration> { + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private Type type; + + private String name; + + private Expression defaultValue; + + public AnnotationMemberDeclaration() { + } + + public AnnotationMemberDeclaration(EnumSet<Modifier> modifiers, Type type, String name, Expression defaultValue) { + setModifiers(modifiers); + setType(type); + setName(name); + setDefaultValue(defaultValue); + } + + public AnnotationMemberDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type type, String name, + Expression defaultValue) { + super(annotations); + setModifiers(modifiers); + setType(type); + setName(name); + setDefaultValue(defaultValue); + } + + public AnnotationMemberDeclaration(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type type, + String name, Expression defaultValue) { + super(range, annotations); + setModifiers(modifiers); + setType(type); + setName(name); + setDefaultValue(defaultValue); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getDefaultValue() { + return defaultValue; + } + + /** + * Return the modifiers of this member declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public String getName() { + return name; + } + + @Override + public Type getType() { + return type; + } + + public AnnotationMemberDeclaration setDefaultValue(Expression defaultValue) { + this.defaultValue = defaultValue; + setAsParentNodeOf(defaultValue); + return this; + } + + @Override + public AnnotationMemberDeclaration setModifiers(EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public AnnotationMemberDeclaration setName(String name) { + this.name = name; + return this; + } + + @Override + public AnnotationMemberDeclaration setType(Type type) { + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + public JavadocComment getJavaDoc() { + if (getComment() instanceof JavadocComment) { + return (JavadocComment) getComment(); + } + return null; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/BodyDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/BodyDeclaration.java new file mode 100644 index 000000000..9055d96a5 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/BodyDeclaration.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.utils.Utils; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class BodyDeclaration<T> extends Node implements NodeWithAnnotations<T> { + + private List<AnnotationExpr> annotations; + + public BodyDeclaration() { + } + + public BodyDeclaration(List<AnnotationExpr> annotations) { + setAnnotations(annotations); + } + + public BodyDeclaration(Range range, List<AnnotationExpr> annotations) { + super(range); + setAnnotations(annotations); + } + + @Override + public final List<AnnotationExpr> getAnnotations() { + annotations = Utils.ensureNotNull(annotations); + return annotations; + } + + /** + * + * @param annotations a null value is currently treated as an empty list. This behavior could change + * in the future, so please avoid passing null + */ + @SuppressWarnings("unchecked") + @Override + public final T setAnnotations(List<AnnotationExpr> annotations) { + this.annotations = annotations; + setAsParentNodeOf(this.annotations); + return (T) this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java new file mode 100644 index 000000000..4120d4a71 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithExtends; +import com.github.javaparser.ast.nodeTypes.NodeWithImplements; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.EnumSet; +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> + implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration> { + + private boolean interface_; + + private List<TypeParameter> typeParameters; + + // Can contain more than one item if this is an interface + private List<ClassOrInterfaceType> extendsList; + + private List<ClassOrInterfaceType> implementsList; + + public ClassOrInterfaceDeclaration() { + } + + public ClassOrInterfaceDeclaration(final EnumSet<Modifier> modifiers, final boolean isInterface, + final String name) { + super(modifiers, name); + setInterface(isInterface); + } + + public ClassOrInterfaceDeclaration(final EnumSet<Modifier> modifiers, + final List<AnnotationExpr> annotations, final boolean isInterface, + final String name, + final List<TypeParameter> typeParameters, + final List<ClassOrInterfaceType> extendsList, + final List<ClassOrInterfaceType> implementsList, + final List<BodyDeclaration<?>> members) { + super(annotations, modifiers, name, members); + setInterface(isInterface); + setTypeParameters(typeParameters); + setExtends(extendsList); + setImplements(implementsList); + } + + public ClassOrInterfaceDeclaration(Range range, final EnumSet<Modifier> modifiers, + final List<AnnotationExpr> annotations, final boolean isInterface, + final String name, + final List<TypeParameter> typeParameters, + final List<ClassOrInterfaceType> extendsList, + final List<ClassOrInterfaceType> implementsList, + final List<BodyDeclaration<?>> members) { + super(range, annotations, modifiers, name, members); + setInterface(isInterface); + setTypeParameters(typeParameters); + setExtends(extendsList); + setImplements(implementsList); + } + + @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 List<ClassOrInterfaceType> getExtends() { + extendsList = ensureNotNull(extendsList); + return extendsList; + } + + @Override + public List<ClassOrInterfaceType> getImplements() { + implementsList = ensureNotNull(implementsList); + return implementsList; + } + + public List<TypeParameter> getTypeParameters() { + typeParameters = ensureNotNull(typeParameters); + return typeParameters; + } + + public boolean isInterface() { + return interface_; + } + + /** + * + * @param extendsList a null value is currently treated as an empty list. This behavior could change + * in the future, so please avoid passing null + * @return + */ + @Override + public ClassOrInterfaceDeclaration setExtends(final List<ClassOrInterfaceType> extendsList) { + this.extendsList = extendsList; + setAsParentNodeOf(this.extendsList); + return this; + } + + /** + * + * @param implementsList a null value is currently treated as an empty list. This behavior could change + * in the future, so please avoid passing null + */ + @Override + public ClassOrInterfaceDeclaration setImplements(final List<ClassOrInterfaceType> implementsList) { + this.implementsList = implementsList; + setAsParentNodeOf(this.implementsList); + return this; + } + + public ClassOrInterfaceDeclaration setInterface(final boolean interface_) { + this.interface_ = interface_; + return this; + } + + /** + * + * @param typeParameters a null value is currently treated as an empty list. This behavior could change + * in the future, so please avoid passing null + */ + public ClassOrInterfaceDeclaration setTypeParameters(final List<TypeParameter> typeParameters) { + this.typeParameters = typeParameters; + setAsParentNodeOf(this.typeParameters); + return this; + } + + + + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ConstructorDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ConstructorDeclaration.java new file mode 100644 index 000000000..4a9cd2a2a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/ConstructorDeclaration.java @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Modifier; +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.NameExpr; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.EnumSet; +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ConstructorDeclaration extends BodyDeclaration<ConstructorDeclaration> + implements NodeWithJavaDoc<ConstructorDeclaration>, NodeWithDeclaration, + NodeWithName<ConstructorDeclaration>, NodeWithModifiers<ConstructorDeclaration>, + NodeWithParameters<ConstructorDeclaration>, NodeWithThrowable<ConstructorDeclaration>, + NodeWithBlockStmt<ConstructorDeclaration> { + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private List<TypeParameter> typeParameters; + + private NameExpr name; + + private List<Parameter> parameters; + + private List<ReferenceType> throws_; + + private BlockStmt body; + + public ConstructorDeclaration() { + } + + public ConstructorDeclaration(EnumSet<Modifier> modifiers, String name) { + setModifiers(modifiers); + setName(name); + } + + public ConstructorDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, + List<TypeParameter> typeParameters, + String name, List<Parameter> parameters, List<ReferenceType> throws_, + BlockStmt block) { + super(annotations); + setModifiers(modifiers); + setTypeParameters(typeParameters); + setName(name); + setParameters(parameters); + setThrows(throws_); + setBody(block); + } + + public ConstructorDeclaration(Range range, EnumSet<Modifier> modifiers, + List<AnnotationExpr> annotations, List<TypeParameter> typeParameters, String name, + List<Parameter> parameters, List<ReferenceType> throws_, BlockStmt block) { + super(range, annotations); + setModifiers(modifiers); + setTypeParameters(typeParameters); + setName(name); + setParameters(parameters); + setThrows(throws_); + setBody(block); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + /** + * Return the modifiers of this member declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public String getName() { + return name == null ? null : name.getName(); + } + + public NameExpr getNameExpr() { + return name; + } + + @Override + public List<Parameter> getParameters() { + parameters = ensureNotNull(parameters); + return parameters; + } + + @Override + public List<ReferenceType> getThrows() { + throws_ = ensureNotNull(throws_); + return throws_; + } + + public List<TypeParameter> getTypeParameters() { + typeParameters = ensureNotNull(typeParameters); + return typeParameters; + } + + @Override + public ConstructorDeclaration setModifiers(EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public ConstructorDeclaration setName(String name) { + setNameExpr(new NameExpr(name)); + return this; + } + + public ConstructorDeclaration setNameExpr(NameExpr name) { + this.name = name; + setAsParentNodeOf(this.name); + return this; + } + + @Override + public ConstructorDeclaration setParameters(List<Parameter> parameters) { + this.parameters = parameters; + setAsParentNodeOf(this.parameters); + return this; + } + + @Override + public ConstructorDeclaration setThrows(List<ReferenceType> throws_) { + this.throws_ = throws_; + setAsParentNodeOf(this.throws_); + return this; + } + + public ConstructorDeclaration setTypeParameters(List<TypeParameter> typeParameters) { + this.typeParameters = typeParameters; + setAsParentNodeOf(this.typeParameters); + return this; + } + + /** + * The declaration returned has this schema: + * + * [accessSpecifier] className ([paramType [paramName]]) + * [throws exceptionsList] + */ + @Override + public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, + boolean includingParameterName) { + StringBuilder sb = new StringBuilder(); + if (includingModifiers) { + AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers()); + sb.append(accessSpecifier.getCodeRepresenation()); + sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " "); + } + sb.append(getName()); + sb.append("("); + boolean firstParam = true; + for (Parameter param : getParameters()) { + if (firstParam) { + firstParam = false; + } else { + sb.append(", "); + } + if (includingParameterName) { + sb.append(param.toStringWithoutComments()); + } else { + sb.append(param.getElementType().toStringWithoutComments()); + } + } + sb.append(")"); + if (includingThrows) { + boolean firstThrow = true; + for (ReferenceType thr : getThrows()) { + if (firstThrow) { + firstThrow = false; + sb.append(" throws "); + } else { + sb.append(", "); + } + sb.append(thr.toStringWithoutComments()); + } + } + return sb.toString(); + } + + @Override + public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows) { + return getDeclarationAsString(includingModifiers, includingThrows, true); + } + + @Override + public String getDeclarationAsString() { + return getDeclarationAsString(true, true, true); + } + + @Override + public JavadocComment getJavaDoc() { + if (getComment() instanceof JavadocComment) { + return (JavadocComment) getComment(); + } + return null; + } + + @Override + public BlockStmt getBody() { + return body; + } + + @Override + public ConstructorDeclaration setBody(BlockStmt body) { + this.body = body; + setAsParentNodeOf(body); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyMemberDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyMemberDeclaration.java new file mode 100644 index 000000000..102eb7aa4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyMemberDeclaration.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class EmptyMemberDeclaration extends BodyDeclaration<EmptyMemberDeclaration> + implements NodeWithJavaDoc<EmptyMemberDeclaration> { + + public EmptyMemberDeclaration() { + super(null); + } + + public EmptyMemberDeclaration(Range range) { + super(range, null); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public JavadocComment getJavaDoc() { + if(getComment() instanceof JavadocComment){ + return (JavadocComment) getComment(); + } + return null; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyTypeDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyTypeDeclaration.java new file mode 100644 index 000000000..3a774de99 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EmptyTypeDeclaration.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import java.util.EnumSet; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class EmptyTypeDeclaration extends TypeDeclaration<EmptyTypeDeclaration> { + + public EmptyTypeDeclaration() { + super(null, EnumSet.noneOf(Modifier.class), null, null); + } + + public EmptyTypeDeclaration(Range range) { + super(range, null, EnumSet.noneOf(Modifier.class), null, null); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumConstantDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumConstantDeclaration.java new file mode 100644 index 000000000..646f6c287 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumConstantDeclaration.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import static com.github.javaparser.ast.expr.NameExpr.*; +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> + implements NodeWithJavaDoc<EnumConstantDeclaration>, NodeWithName<EnumConstantDeclaration> { + + private String name; + + private List<Expression> args; + + private List<BodyDeclaration<?>> classBody; + + public EnumConstantDeclaration() { + } + + public EnumConstantDeclaration(String name) { + setName(name); + } + + public EnumConstantDeclaration(List<AnnotationExpr> annotations, String name, List<Expression> args, + List<BodyDeclaration<?>> classBody) { + super(annotations); + setName(name); + setArgs(args); + setClassBody(classBody); + } + + public EnumConstantDeclaration(Range range, List<AnnotationExpr> annotations, String name, List<Expression> args, + List<BodyDeclaration<?>> classBody) { + super(range, annotations); + setName(name); + setArgs(args); + setClassBody(classBody); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public List<Expression> getArgs() { + args = ensureNotNull(args); + return args; + } + + public List<BodyDeclaration<?>> getClassBody() { + classBody = ensureNotNull(classBody); + return classBody; + } + + @Override + public String getName() { + return name; + } + + public EnumConstantDeclaration setArgs(List<Expression> args) { + this.args = args; + setAsParentNodeOf(this.args); + return this; + } + + public EnumConstantDeclaration setClassBody(List<BodyDeclaration<?>> classBody) { + this.classBody = classBody; + setAsParentNodeOf(this.classBody); + return this; + } + + @Override + public EnumConstantDeclaration setName(String name) { + this.name = name; + return this; + } + + @Override + public JavadocComment getJavaDoc() { + if(getComment() instanceof JavadocComment){ + return (JavadocComment) getComment(); + } + return null; + } + + public EnumConstantDeclaration addArgument(String valueExpr) { + getArgs().add(name(valueExpr)); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumDeclaration.java new file mode 100644 index 000000000..0ad3089b6 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/EnumDeclaration.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.EnumSet; +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithImplements; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class EnumDeclaration extends TypeDeclaration<EnumDeclaration> + implements NodeWithImplements<EnumDeclaration> { + + private List<ClassOrInterfaceType> implementsList; + + private List<EnumConstantDeclaration> entries; + + public EnumDeclaration() { + } + + public EnumDeclaration(EnumSet<Modifier> modifiers, String name) { + super(modifiers, name); + } + + public EnumDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, String name, + List<ClassOrInterfaceType> implementsList, List<EnumConstantDeclaration> entries, + List<BodyDeclaration<?>> members) { + super(annotations, modifiers, name, members); + setImplements(implementsList); + setEntries(entries); + } + + public EnumDeclaration(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, String name, + List<ClassOrInterfaceType> implementsList, List<EnumConstantDeclaration> entries, + List<BodyDeclaration<?>> members) { + super(range, annotations, modifiers, name, members); + setImplements(implementsList); + setEntries(entries); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public List<EnumConstantDeclaration> getEntries() { + entries = ensureNotNull(entries); + return entries; + } + + @Override + public List<ClassOrInterfaceType> getImplements() { + implementsList = ensureNotNull(implementsList); + return implementsList; + } + + public EnumDeclaration setEntries(List<EnumConstantDeclaration> entries) { + this.entries = entries; + setAsParentNodeOf(this.entries); + return this; + } + + @Override + public EnumDeclaration setImplements(List<ClassOrInterfaceType> implementsList) { + this.implementsList = implementsList; + setAsParentNodeOf(this.implementsList); + return this; + } + + + + public EnumConstantDeclaration addEnumConstant(String name) { + EnumConstantDeclaration enumConstant = new EnumConstantDeclaration(name); + getEntries().add(enumConstant); + enumConstant.setParentNode(this); + return enumConstant; + } + + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/FieldDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/FieldDeclaration.java new file mode 100644 index 000000000..aa04a5230 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/FieldDeclaration.java @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import static com.github.javaparser.ast.expr.NameExpr.*; +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.AssignExpr.Operator; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +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.Modifier.PUBLIC; +import static com.github.javaparser.ast.type.VoidType.VOID_TYPE; + +/** + * @author Julio Vilmar Gesser + */ +public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration> implements + NodeWithJavaDoc<FieldDeclaration>, + NodeWithElementType<FieldDeclaration>, + NodeWithModifiers<FieldDeclaration>, + NodeWithVariables<FieldDeclaration> { + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private Type elementType; + + private List<VariableDeclarator> variables; + + private List<ArrayBracketPair> arrayBracketPairsAfterElementType; + + public FieldDeclaration() { + } + + public FieldDeclaration(EnumSet<Modifier> modifiers, Type elementType, VariableDeclarator variable) { + setModifiers(modifiers); + setElementType(elementType); + List<VariableDeclarator> aux = new ArrayList<>(); + aux.add(variable); + setVariables(aux); + } + + public FieldDeclaration(EnumSet<Modifier> modifiers, Type elementType, List<VariableDeclarator> variables) { + setModifiers(modifiers); + setElementType(elementType); + setVariables(variables); + } + + public FieldDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type elementType, List<ArrayBracketPair> arrayBracketPairsAfterElementType, + List<VariableDeclarator> variables) { + super(annotations); + setModifiers(modifiers); + setElementType(elementType); + setVariables(variables); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType); + } + + public FieldDeclaration(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type elementType, + List<VariableDeclarator> variables, List<ArrayBracketPair> arrayBracketPairsAfterElementType) { + super(range, annotations); + setModifiers(modifiers); + setElementType(elementType); + setVariables(variables); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType); + } + + /** + * Creates a {@link FieldDeclaration}. + * + * @param modifiers + * modifiers + * @param type + * type + * @param variable + * variable declarator + * @return instance of {@link FieldDeclaration} + */ + public static FieldDeclaration create(EnumSet<Modifier> modifiers, Type type, + VariableDeclarator variable) { + List<VariableDeclarator> variables = new ArrayList<>(); + variables.add(variable); + return new FieldDeclaration(modifiers, type, variables); + } + + /** + * Creates a {@link FieldDeclaration}. + * + * @param modifiers + * modifiers + * @param type + * type + * @param name + * field name + * @return instance of {@link FieldDeclaration} + */ + public static FieldDeclaration create(EnumSet<Modifier> modifiers, Type type, String name) { + VariableDeclaratorId id = new VariableDeclaratorId(name); + VariableDeclarator variable = new VariableDeclarator(id); + return create(modifiers, type, variable); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + /** + * Return the modifiers of this member declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public List<VariableDeclarator> getVariables() { + variables = ensureNotNull(variables); + return variables; + } + + @Override + public FieldDeclaration setModifiers(EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public FieldDeclaration setVariables(List<VariableDeclarator> variables) { + this.variables = variables; + setAsParentNodeOf(this.variables); + return this; + } + + @Override + public JavadocComment getJavaDoc() { + if (getComment() instanceof JavadocComment) { + return (JavadocComment) getComment(); + } + return null; + } + + /** + * Create a getter for this field, <b>will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration</b> + * + * @return the {@link MethodDeclaration} created + * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a + * class or enum + */ + public MethodDeclaration createGetter() { + if (getVariables().size() != 1) + throw new IllegalStateException("You can use this only when the field declares only 1 variable name"); + ClassOrInterfaceDeclaration parentClass = getParentNodeOfType(ClassOrInterfaceDeclaration.class); + EnumDeclaration parentEnum = getParentNodeOfType(EnumDeclaration.class); + if ((parentClass == null && parentEnum == null) || (parentClass != null && parentClass.isInterface())) + throw new IllegalStateException( + "You can use this only when the field is attached to a class or an enum"); + + VariableDeclarator variable = getVariables().get(0); + String fieldName = variable.getId().getName(); + String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); + final MethodDeclaration getter; + if (parentClass != null) + getter = parentClass.addMethod("get" + fieldNameUpper, PUBLIC); + else + getter = parentEnum.addMethod("get" + fieldNameUpper, PUBLIC); + getter.setType(variable.getType()); + BlockStmt blockStmt = new BlockStmt(); + getter.setBody(blockStmt); + blockStmt.addStatement(new ReturnStmt(name(fieldName))); + return getter; + } + + /** + * Create a setter for this field, <b>will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration</b> + * + * @return the {@link MethodDeclaration} created + * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a + * class or enum + */ + public MethodDeclaration createSetter() { + if (getVariables().size() != 1) + throw new IllegalStateException("You can use this only when the field declares only 1 variable name"); + ClassOrInterfaceDeclaration parentClass = getParentNodeOfType(ClassOrInterfaceDeclaration.class); + EnumDeclaration parentEnum = getParentNodeOfType(EnumDeclaration.class); + if ((parentClass == null && parentEnum == null) || (parentClass != null && parentClass.isInterface())) + throw new IllegalStateException( + "You can use this only when the field is attached to a class or an enum"); + + VariableDeclarator variable = getVariables().get(0); + String fieldName = variable.getId().getName(); + String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); + + final MethodDeclaration setter; + if (parentClass != null) + setter = parentClass.addMethod("set" + fieldNameUpper, PUBLIC); + else + setter = parentEnum.addMethod("set" + fieldNameUpper, PUBLIC); + setter.setType(VOID_TYPE); + setter.getParameters().add(new Parameter(variable.getType(), new VariableDeclaratorId(fieldName))); + BlockStmt blockStmt2 = new BlockStmt(); + setter.setBody(blockStmt2); + blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.assign)); + return setter; + } + + + @Override + public Type getElementType() { + return elementType; + } + + @Override + public FieldDeclaration setElementType(final Type elementType) { + this.elementType = elementType; + setAsParentNodeOf(this.elementType); + return this; + } + + /** + * @return the array brackets in this position: <code>class C { int[] abc; }</code> + */ + public List<ArrayBracketPair> getArrayBracketPairsAfterElementType() { + arrayBracketPairsAfterElementType = ensureNotNull(arrayBracketPairsAfterElementType); + return arrayBracketPairsAfterElementType; + } + + @Override + public FieldDeclaration setArrayBracketPairsAfterElementType(List<ArrayBracketPair> arrayBracketPairsAfterType) { + this.arrayBracketPairsAfterElementType = arrayBracketPairsAfterType; + setAsParentNodeOf(arrayBracketPairsAfterType); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/InitializerDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/InitializerDeclaration.java new file mode 100644 index 000000000..adb893f03 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/InitializerDeclaration.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class InitializerDeclaration extends BodyDeclaration<InitializerDeclaration> + implements NodeWithJavaDoc<InitializerDeclaration> { + + private boolean isStatic; + + private BlockStmt block; + + public InitializerDeclaration() { + } + + public InitializerDeclaration(boolean isStatic, BlockStmt block) { + super(null); + setStatic(isStatic); + setBlock(block); + } + + public InitializerDeclaration(Range range, boolean isStatic, BlockStmt block) { + super(range, null); + setStatic(isStatic); + setBlock(block); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public BlockStmt getBlock() { + return block; + } + + public boolean isStatic() { + return isStatic; + } + + public InitializerDeclaration setBlock(BlockStmt block) { + this.block = block; + setAsParentNodeOf(this.block); + return this; + } + + public InitializerDeclaration setStatic(boolean isStatic) { + this.isStatic = isStatic; + return this; + } + + @Override + public JavadocComment getJavaDoc() { + if(getComment() instanceof JavadocComment){ + return (JavadocComment) getComment(); + } + return null; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/MethodDeclaration.java new file mode 100644 index 000000000..a89103a3b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/MethodDeclaration.java @@ -0,0 +1,399 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import static com.github.javaparser.ast.type.ArrayType.*; +import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.EnumSet; +import java.util.List; + +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.nodeTypes.*; +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.NameExpr; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +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 java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration> implements + NodeWithJavaDoc<MethodDeclaration>, + NodeWithDeclaration, + NodeWithName<MethodDeclaration>, + NodeWithType<MethodDeclaration>, + NodeWithElementType<MethodDeclaration>, + NodeWithModifiers<MethodDeclaration>, + NodeWithParameters<MethodDeclaration>, + NodeWithThrowable<MethodDeclaration>, + NodeWithBlockStmt<MethodDeclaration> { + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private List<TypeParameter> typeParameters; + + private Type elementType; + + private NameExpr name; + + private List<Parameter> parameters; + + private List<ReferenceType> throws_; + + private BlockStmt body; + + private boolean isDefault = false; + + private List<ArrayBracketPair> arrayBracketPairsAfterType; + + private List<ArrayBracketPair> arrayBracketPairsAfterParameterList; + + public MethodDeclaration() { + } + + public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type elementType, final String name) { + setModifiers(modifiers); + setElementType(elementType); + setName(name); + } + + public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type elementType, final String name, + final List<Parameter> parameters) { + setModifiers(modifiers); + setElementType(elementType); + setName(name); + setParameters(parameters); + } + + public MethodDeclaration(final EnumSet<Modifier> modifiers, + final List<AnnotationExpr> annotations, + final List<TypeParameter> typeParameters, + final Type elementType, + final List<ArrayBracketPair> arrayBracketPairsAfterElementType, + final String name, + final List<Parameter> parameters, + final List<ArrayBracketPair> arrayBracketPairsAfterParameterList, + final List<ReferenceType> throws_, + final BlockStmt body) { + super(annotations); + setModifiers(modifiers); + setTypeParameters(typeParameters); + setElementType(elementType); + setName(name); + setParameters(parameters); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType); + setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList); + setThrows(throws_); + setBody(body); + } + + public MethodDeclaration(Range range, + final EnumSet<Modifier> modifiers, + final List<AnnotationExpr> annotations, + final List<TypeParameter> typeParameters, + final Type elementType, + final List<ArrayBracketPair> arrayBracketPairsAfterElementType, + final NameExpr nameExpr, + final List<Parameter> parameters, + final List<ArrayBracketPair> arrayBracketPairsAfterParameterList, + final List<ReferenceType> throws_, + final BlockStmt body) { + super(range, annotations); + setModifiers(modifiers); + setTypeParameters(typeParameters); + setElementType(elementType); + setNameExpr(nameExpr); + setParameters(parameters); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType); + setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList); + setThrows(throws_); + 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 BlockStmt getBody() { + return body; + } + + /** + * Return the modifiers of this member declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public String getName() { + return name.getName(); + } + + public NameExpr getNameExpr() { + return name; + } + + @Override + public List<Parameter> getParameters() { + parameters = ensureNotNull(parameters); + return parameters; + } + + @Override + public List<ReferenceType> getThrows() { + throws_ = ensureNotNull(throws_); + return throws_; + } + + @Override + public Type getType() { + return wrapInArrayTypes(getElementType(), + getArrayBracketPairsAfterElementType(), + getArrayBracketPairsAfterParameterList()); + } + + @Override + public Type getElementType() { + return elementType; + } + + public List<TypeParameter> getTypeParameters() { + typeParameters = ensureNotNull(typeParameters); + return typeParameters; + } + + @Override + public MethodDeclaration setBody(final BlockStmt body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + @Override + public MethodDeclaration setModifiers(final EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public MethodDeclaration setName(final String name) { + setNameExpr(new NameExpr(name)); + return this; + } + + public MethodDeclaration setNameExpr(final NameExpr name) { + this.name = name; + setAsParentNodeOf(this.name); + return this; + } + + @Override + public MethodDeclaration setParameters(final List<Parameter> parameters) { + this.parameters = parameters; + setAsParentNodeOf(this.parameters); + return this; + } + + @Override + public MethodDeclaration setThrows(final List<ReferenceType> throws_) { + this.throws_ = throws_; + setAsParentNodeOf(this.throws_); + return this; + } + + @Override + public MethodDeclaration setType(final Type type) { + Pair<Type, List<ArrayBracketPair>> typeListPair = unwrapArrayTypes(type); + setElementType(typeListPair.a); + setArrayBracketPairsAfterElementType(typeListPair.b); + setArrayBracketPairsAfterParameterList(null); + return this; + } + + @Override + public MethodDeclaration setElementType(final Type elementType) { + this.elementType = elementType; + setAsParentNodeOf(this.elementType); + return this; + } + + public MethodDeclaration setTypeParameters(final List<TypeParameter> typeParameters) { + this.typeParameters = typeParameters; + setAsParentNodeOf(typeParameters); + return this; + } + + public boolean isDefault() { + return isDefault; + } + + public MethodDeclaration setDefault(boolean isDefault) { + this.isDefault = isDefault; + return this; + } + + @Override + public String getDeclarationAsString() { + return getDeclarationAsString(true, true, true); + } + + @Override + public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows) { + return getDeclarationAsString(includingModifiers, includingThrows, true); + } + + /** + * The declaration returned has this schema: + * + * [accessSpecifier] [static] [abstract] [final] [native] + * [synchronized] returnType methodName ([paramType [paramName]]) + * [throws exceptionsList] + * + * @return method declaration as String + */ + @Override + public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, + boolean includingParameterName) { + StringBuilder sb = new StringBuilder(); + if (includingModifiers) { + AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers()); + sb.append(accessSpecifier.getCodeRepresenation()); + sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " "); + if (getModifiers().contains(Modifier.STATIC)) { + sb.append("static "); + } + if (getModifiers().contains(Modifier.ABSTRACT)) { + sb.append("abstract "); + } + if (getModifiers().contains(Modifier.FINAL)) { + sb.append("final "); + } + if (getModifiers().contains(Modifier.NATIVE)) { + sb.append("native "); + } + if (getModifiers().contains(Modifier.SYNCHRONIZED)) { + sb.append("synchronized "); + } + } + // TODO verify it does not print comments connected to the type + sb.append(getElementType().toStringWithoutComments()); + sb.append(" "); + sb.append(getName()); + sb.append("("); + boolean firstParam = true; + for (Parameter param : getParameters()) { + if (firstParam) { + firstParam = false; + } else { + sb.append(", "); + } + if (includingParameterName) { + sb.append(param.toStringWithoutComments()); + } else { + sb.append(param.getElementType().toStringWithoutComments()); + if (param.isVarArgs()) { + sb.append("..."); + } + } + } + sb.append(")"); + if (includingThrows) { + boolean firstThrow = true; + for (ReferenceType thr : getThrows()) { + if (firstThrow) { + firstThrow = false; + sb.append(" throws "); + } else { + sb.append(", "); + } + sb.append(thr.toStringWithoutComments()); + } + } + return sb.toString(); + } + + @Override + public JavadocComment getJavaDoc() { + if (getComment() instanceof JavadocComment) { + return (JavadocComment) getComment(); + } + return null; + } + + /** + * @return the array brackets in this position: <code>class C { int[] abc; }</code> + */ + public List<ArrayBracketPair> getArrayBracketPairsAfterElementType() { + arrayBracketPairsAfterType = ensureNotNull(arrayBracketPairsAfterType); + return arrayBracketPairsAfterType; + } + + @Override + public MethodDeclaration setArrayBracketPairsAfterElementType(List<ArrayBracketPair> arrayBracketPairsAfterType) { + this.arrayBracketPairsAfterType = arrayBracketPairsAfterType; + setAsParentNodeOf(arrayBracketPairsAfterType); + return this; + } + + /** + * @return the array brackets in this position: <code>int abc()[] {...}</code> + */ + public List<ArrayBracketPair> getArrayBracketPairsAfterParameterList() { + arrayBracketPairsAfterParameterList = ensureNotNull(arrayBracketPairsAfterParameterList); + return arrayBracketPairsAfterParameterList; + } + + public MethodDeclaration setArrayBracketPairsAfterParameterList(List<ArrayBracketPair> arrayBracketPairsAfterParameterList) { + this.arrayBracketPairsAfterParameterList = arrayBracketPairsAfterParameterList; + setAsParentNodeOf(arrayBracketPairsAfterParameterList); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/Parameter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/Parameter.java new file mode 100644 index 000000000..d66b39a00 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/Parameter.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.Type; +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 java.util.EnumSet; +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class Parameter extends Node implements + NodeWithType<Parameter>, + NodeWithElementType<Parameter>, + NodeWithAnnotations<Parameter>, + NodeWithName<Parameter>, + NodeWithModifiers<Parameter> { + + private Type elementType; + + private boolean isVarArgs; + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private List<AnnotationExpr> annotations; + + private VariableDeclaratorId id; + + private List<ArrayBracketPair> arrayBracketPairsAfterType; + + public Parameter() { + } + + public Parameter(Type elementType, VariableDeclaratorId id) { + setId(id); + setElementType(elementType); + } + + /** + * Creates a new {@link Parameter}. + * + * @param elementType + * type of the parameter + * @param name + * name of the parameter + * @return instance of {@link Parameter} + */ + public static Parameter create(Type elementType, String name) { + return new Parameter(elementType, new VariableDeclaratorId(name)); + } + + public Parameter(EnumSet<Modifier> modifiers, Type elementType, VariableDeclaratorId id) { + setModifiers(modifiers); + setId(id); + setElementType(elementType); + } + + public Parameter(final Range range, + EnumSet<Modifier> modifiers, + List<AnnotationExpr> annotations, + Type elementType, + List<ArrayBracketPair> arrayBracketPairsAfterElementType, + boolean isVarArgs, + VariableDeclaratorId id) { + super(range); + setModifiers(modifiers); + setAnnotations(annotations); + setId(id); + setElementType(elementType); + setVarArgs(isVarArgs); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public Type getType() { + return wrapInArrayTypes(elementType, + getArrayBracketPairsAfterElementType(), + getId().getArrayBracketPairsAfterId()); + } + + public boolean isVarArgs() { + return isVarArgs; + } + + @Override + public Parameter setType(Type type) { + Pair<Type, List<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); + setElementType(unwrapped.a); + setArrayBracketPairsAfterElementType(unwrapped.b); + getId().setArrayBracketPairsAfterId(null); + return this; + } + + public Parameter setVarArgs(boolean isVarArgs) { + this.isVarArgs = isVarArgs; + return this; + } + /** + * @return the list returned could be immutable (in that case it will be empty) + */ + @Override + public List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + public VariableDeclaratorId getId() { + return id; + } + + @Override + public String getName() { + return getId().getName(); + } + + @SuppressWarnings("unchecked") + @Override + public Parameter setName(String name) { + if (id != null) + id.setName(name); + else + id = new VariableDeclaratorId(name); + return this; + } + + /** + * Return the modifiers of this parameter declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + /** + * @param annotations a null value is currently treated as an empty list. This behavior could change + * in the future, so please avoid passing null + */ + @Override + @SuppressWarnings("unchecked") + public Parameter setAnnotations(List<AnnotationExpr> annotations) { + this.annotations = annotations; + setAsParentNodeOf(this.annotations); + return this; + } + + public void setId(VariableDeclaratorId id) { + this.id = id; + setAsParentNodeOf(this.id); + } + + @Override + @SuppressWarnings("unchecked") + public Parameter setModifiers(EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public Type getElementType() { + return elementType; + } + + @Override + public Parameter setElementType(final Type elementType) { + this.elementType = elementType; + setAsParentNodeOf(this.elementType); + return this; + } + + public List<ArrayBracketPair> getArrayBracketPairsAfterElementType() { + arrayBracketPairsAfterType = ensureNotNull(arrayBracketPairsAfterType); + return arrayBracketPairsAfterType; + } + + @Override + public Parameter setArrayBracketPairsAfterElementType(List<ArrayBracketPair> arrayBracketPairsAfterType) { + this.arrayBracketPairsAfterType = arrayBracketPairsAfterType; + setAsParentNodeOf(arrayBracketPairsAfterType); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/TypeDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/TypeDeclaration.java new file mode 100644 index 000000000..829d37c26 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/TypeDeclaration.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import static com.github.javaparser.utils.Utils.ensureNotNull; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc; +import com.github.javaparser.ast.nodeTypes.NodeWithMembers; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; +import com.github.javaparser.ast.nodeTypes.NodeWithName; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class TypeDeclaration<T> extends BodyDeclaration<T> + implements NodeWithName<T>, NodeWithJavaDoc<T>, NodeWithModifiers<T>, NodeWithMembers<T> { + + private NameExpr name; + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private List<BodyDeclaration<?>> members; + + public TypeDeclaration() { + } + + public TypeDeclaration(EnumSet<Modifier> modifiers, String name) { + setName(name); + setModifiers(modifiers); + } + + public TypeDeclaration(List<AnnotationExpr> annotations, + EnumSet<Modifier> modifiers, String name, + List<BodyDeclaration<?>> members) { + super(annotations); + setName(name); + setModifiers(modifiers); + setMembers(members); + } + + public TypeDeclaration(Range range, List<AnnotationExpr> annotations, + EnumSet<Modifier> modifiers, String name, + List<BodyDeclaration<?>> members) { + super(range, annotations); + setName(name); + setModifiers(modifiers); + setMembers(members); + } + + /** + * Adds the given declaration to the specified type. The list of members + * will be initialized if it is <code>null</code>. + * + * @param decl + * member declaration + */ + public TypeDeclaration<T> addMember(BodyDeclaration<?> decl) { + List<BodyDeclaration<?>> members = getMembers(); + if (isNullOrEmpty(members)) { + members = new ArrayList<>(); + setMembers(members); + } + members.add(decl); + decl.setParentNode(this); + return this; + } + + @Override + public List<BodyDeclaration<?>> getMembers() { + members = ensureNotNull(members); + return members; + } + + /** + * Return the modifiers of this type declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public final EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public final String getName() { + return name.getName(); + } + + @SuppressWarnings("unchecked") + @Override + public T setMembers(List<BodyDeclaration<?>> members) { + this.members = members; + setAsParentNodeOf(this.members); + return (T) this; + } + + @SuppressWarnings("unchecked") + @Override + public T setModifiers(EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return (T) this; + } + + @Override + @SuppressWarnings("unchecked") + public T setName(String name) { + setNameExpr(new NameExpr(name)); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T setNameExpr(NameExpr nameExpr) { + this.name = nameExpr; + setAsParentNodeOf(this.name); + return (T) this; + } + + public final NameExpr getNameExpr() { + return name; + } + + @Override + public JavadocComment getJavaDoc() { + if(getComment() instanceof JavadocComment){ + return (JavadocComment) getComment(); + } + return null; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclarator.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclarator.java new file mode 100644 index 000000000..ff78d6e68 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclarator.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithElementType; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.utils.Pair; + +import java.util.List; + +import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; + +/** + * @author Julio Vilmar Gesser + */ +public final class VariableDeclarator extends Node implements + NodeWithType<VariableDeclarator> { + + private VariableDeclaratorId id; + + private Expression init; + + public VariableDeclarator() { + } + + public VariableDeclarator(VariableDeclaratorId id) { + setId(id); + } + + public VariableDeclarator(String variableName) { + setId(new VariableDeclaratorId(variableName)); + } + + /** + * Defines the declaration of a variable. + * + * @param id The identifier for this variable. IE. The variables name. + * @param init What this variable should be initialized to. + * An {@link com.github.javaparser.ast.expr.AssignExpr} is unnecessary as the <code>=</code> operator is + * already added. + */ + public VariableDeclarator(VariableDeclaratorId id, Expression init) { + setId(id); + setInit(init); + } + + public VariableDeclarator(String variableName, Expression init) { + setId(new VariableDeclaratorId(variableName)); + setInit(init); + } + + public VariableDeclarator(Range range, VariableDeclaratorId id, Expression init) { + super(range); + setId(id); + setInit(init); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public VariableDeclaratorId getId() { + return id; + } + + public Expression getInit() { + return init; + } + + public VariableDeclarator setId(VariableDeclaratorId id) { + this.id = id; + setAsParentNodeOf(this.id); + return this; + } + + public VariableDeclarator setInit(Expression init) { + this.init = init; + setAsParentNodeOf(this.init); + return this; + } + + /** + * Will create a {@link NameExpr} with the init param + */ + public VariableDeclarator setInit(String init) { + this.init = new NameExpr(init); + setAsParentNodeOf(this.init); + return this; + } + + + @Override + public Type getType() { + NodeWithElementType<?> elementType = getParentNodeOfType(NodeWithElementType.class); + + return wrapInArrayTypes(elementType.getElementType(), + elementType.getArrayBracketPairsAfterElementType(), + getId().getArrayBracketPairsAfterId()); + } + + @Override + public VariableDeclarator setType(Type type) { + Pair<Type, List<ArrayBracketPair>> unwrapped = ArrayType.unwrapArrayTypes(type); + NodeWithElementType<?> nodeWithElementType = getParentNodeOfType(NodeWithElementType.class); + if (nodeWithElementType == null) { + throw new IllegalStateException("Cannot set type without a parent"); + } + nodeWithElementType.setElementType(unwrapped.a); + nodeWithElementType.setArrayBracketPairsAfterElementType(null); + getId().setArrayBracketPairsAfterId(unwrapped.b); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclaratorId.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclaratorId.java new file mode 100644 index 000000000..b6dccc2aa --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/body/VariableDeclaratorId.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.body; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class VariableDeclaratorId extends Node implements NodeWithName<VariableDeclaratorId> { + + private String name; + + private List<ArrayBracketPair> arrayBracketPairsAfterId; + + public VariableDeclaratorId() { + } + + public VariableDeclaratorId(String name) { + setName(name); + } + + public VariableDeclaratorId(Range range, String name, List<ArrayBracketPair> arrayBracketPairsAfterId) { + super(range); + setName(name); + setArrayBracketPairsAfterId(arrayBracketPairsAfterId); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public String getName() { + return name; + } + + @Override + public VariableDeclaratorId setName(String name) { + this.name = name; + return this; + } + + public List<ArrayBracketPair> getArrayBracketPairsAfterId() { + arrayBracketPairsAfterId = ensureNotNull(arrayBracketPairsAfterId); + return arrayBracketPairsAfterId; + } + + public VariableDeclaratorId setArrayBracketPairsAfterId(List<ArrayBracketPair> arrayBracketPairsAfterId) { + this.arrayBracketPairsAfterId = arrayBracketPairsAfterId; + setAsParentNodeOf(arrayBracketPairsAfterId); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/BlockComment.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/BlockComment.java new file mode 100644 index 000000000..77157d595 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/BlockComment.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.comments; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * <p> + * AST node that represent block comments. + * </p> + * Block comments can has multi lines and are delimited by "/*" and + * "*/". + * + * @author Julio Vilmar Gesser + */ +public final class BlockComment extends Comment { + + public BlockComment() { + } + + public BlockComment(String content) { + super(content); + } + + public BlockComment(Range range, String content) { + super(range, content); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/Comment.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/Comment.java new file mode 100644 index 000000000..9da994ec4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/Comment.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.comments; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; + +/** + * Abstract class for all AST nodes that represent comments. + * + * @see BlockComment + * @see LineComment + * @see JavadocComment + * @author Julio Vilmar Gesser + */ +public abstract class Comment extends Node { + + private String content; + private Node commentedNode; + + public Comment() { + } + + public Comment(String content) { + this.content = content; + } + + public Comment(Range range, String content) { + super(range); + this.content = content; + } + + /** + * Return the text of the comment. + * + * @return text of the comment + */ + public final String getContent() { + return content; + } + + /** + * Sets the text of the comment. + * + * @param content + * the text of the comment to set + */ + public Comment setContent(String content) { + this.content = content; + return this; + } + + public boolean isLineComment() + { + return false; + } + + public LineComment asLineComment() { + if (isLineComment()) { + return (LineComment) this; + } else { + throw new UnsupportedOperationException("Not a line comment"); + } + } + + public Node getCommentedNode() + { + return this.commentedNode; + } + + public Comment setCommentedNode(Node commentedNode) + { + if (commentedNode==null) { + this.commentedNode = null; + return this; + } + if (commentedNode==this) { + throw new IllegalArgumentException(); + } + if (commentedNode instanceof Comment) { + throw new IllegalArgumentException(); + } + this.commentedNode = commentedNode; + return this; + } + + public boolean isOrphan() + { + return this.commentedNode == null; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/CommentsCollection.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/CommentsCollection.java new file mode 100644 index 000000000..d02c7a5f0 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/CommentsCollection.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.comments; + +import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; + +/** + * The comments contained in a certain parsed piece of source code. + */ +public class CommentsCollection { + private final TreeSet<Comment> comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); + + public CommentsCollection() { + } + + public CommentsCollection(Collection<Comment> commentsToCopy) { + comments.addAll(commentsToCopy); + } + + public Set<LineComment> getLineComments() { + return comments.stream() + .filter(comment -> comment instanceof LineComment) + .map(comment -> (LineComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set<BlockComment> getBlockComments() { + return comments.stream() + .filter(comment -> comment instanceof BlockComment) + .map(comment -> (BlockComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set<JavadocComment> getJavadocComments() { + return comments.stream() + .filter(comment -> comment instanceof JavadocComment) + .map(comment -> (JavadocComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public void addComment(Comment comment) { + comments.add(comment); + } + + public boolean contains(Comment comment) { + for (Comment c : getComments()) { + // we tolerate a difference of one element in the end column: + // it depends how \r and \n are calculated... + if (c.getBegin().line == comment.getBegin().line && + c.getBegin().column == comment.getBegin().column && + c.getEnd().line == comment.getEnd().line && + Math.abs(c.getEnd().column - comment.getEnd().column) < 2) { + return true; + } + } + return false; + } + + public TreeSet<Comment> getComments() { + return comments; + } + + public int size() { + return comments.size(); + } + + public CommentsCollection minus(CommentsCollection other) { + CommentsCollection result = new CommentsCollection(); + result.comments.addAll( + comments.stream() + .filter(comment -> !other.contains(comment)) + .collect(Collectors.toList())); + return result; + } + + public CommentsCollection copy() { + return new CommentsCollection(comments); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/JavadocComment.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/JavadocComment.java new file mode 100644 index 000000000..18b77af28 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/JavadocComment.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.comments; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class JavadocComment extends Comment { + + public JavadocComment() { + } + + public JavadocComment(String content) { + super(content); + } + + public JavadocComment(Range range, String content) { + super(range, content); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/LineComment.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/LineComment.java new file mode 100644 index 000000000..56b8054d3 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/comments/LineComment.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.comments; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * <p> + * AST node that represent line comments. + * </p> + * Line comments are started with "//" and finish at the end of the line ("\n"). + * + * @author Julio Vilmar Gesser + */ +public final class LineComment extends Comment { + + public LineComment() { + } + + public LineComment(String content) { + super(content); + } + + public LineComment(Range range, String content) { + super(range, content); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public boolean isLineComment() + { + return true; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AnnotationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AnnotationExpr.java new file mode 100644 index 000000000..a1cad1cdb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AnnotationExpr.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class AnnotationExpr extends Expression { + + protected NameExpr name; + + public AnnotationExpr() {} + + public AnnotationExpr(Range range) { + super(range); + } + + public NameExpr getName() { + return name; + } + + public AnnotationExpr setName(NameExpr name) { + this.name = name; + setAsParentNodeOf(name); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayAccessExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayAccessExpr.java new file mode 100644 index 000000000..b461ea87b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayAccessExpr.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ArrayAccessExpr extends Expression { + + private Expression name; + + private Expression index; + + public ArrayAccessExpr() { + } + + public ArrayAccessExpr(Expression name, Expression index) { + setName(name); + setIndex(index); + } + + public ArrayAccessExpr(Range range, Expression name, Expression index) { + super(range); + setName(name); + setIndex(index); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getIndex() { + return index; + } + + public Expression getName() { + return name; + } + + public ArrayAccessExpr setIndex(Expression index) { + this.index = index; + setAsParentNodeOf(this.index); + return this; + } + + public ArrayAccessExpr setName(Expression name) { + this.name = name; + setAsParentNodeOf(this.name); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayCreationExpr.java new file mode 100644 index 000000000..79d55a56c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayCreationExpr.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ArrayCreationExpr extends Expression implements NodeWithType<ArrayCreationExpr> { + + private List<ArrayCreationLevel> levels; + + private Type type; + + private ArrayInitializerExpr initializer; + + public ArrayCreationExpr() { + } + + public ArrayCreationExpr(Type type, List<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) { + setLevels(levels); + setType(type); + setInitializer(initializer); + } + + public ArrayCreationExpr(Range range, Type type, List<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) { + super(range); + setLevels(levels); + setType(type); + setInitializer(initializer); + } + + public ArrayCreationExpr(Type type) { + setType(type); + setInitializer(null); + } + + public ArrayCreationExpr(Range range, Type type) { + super(range); + setType(type); + setInitializer(null); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public ArrayInitializerExpr getInitializer() { + return initializer; + } + + @Override + public Type getType() { + return type; + } + + public ArrayCreationExpr setInitializer(ArrayInitializerExpr initializer) { + this.initializer = initializer; + setAsParentNodeOf(this.initializer); + return this; + } + + @Override + public ArrayCreationExpr setType(Type type) { + this.type = type; + setAsParentNodeOf(this.type); + return this; + } + + public List<ArrayCreationLevel> getLevels() { + levels = ensureNotNull(levels); + return levels; + } + + public ArrayCreationExpr setLevels(List<ArrayCreationLevel> levels) { + this.levels = levels; + setAsParentNodeOf(levels); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayInitializerExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayInitializerExpr.java new file mode 100644 index 000000000..67c10739b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ArrayInitializerExpr.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ArrayInitializerExpr extends Expression { + + private List<Expression> values; + + public ArrayInitializerExpr() { + } + + public ArrayInitializerExpr(List<Expression> values) { + setValues(values); + } + + public ArrayInitializerExpr(Range range, List<Expression> values) { + super(range); + setValues(values); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public List<Expression> getValues() { + values = ensureNotNull(values); + return values; + } + + public ArrayInitializerExpr setValues(List<Expression> values) { + this.values = values; + setAsParentNodeOf(this.values); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AssignExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AssignExpr.java new file mode 100644 index 000000000..cf16c6fff --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/AssignExpr.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class AssignExpr extends Expression { + + public enum Operator { + assign, // = + plus, // += + minus, // -= + star, // *= + slash, // /= + and, // &= + or, // |= + xor, // ^= + rem, // %= + lShift, // <<= + rSignedShift, // >>= + rUnsignedShift, // >>>= + } + + private Expression target; + + private Expression value; + + private Operator op; + + public AssignExpr() { + } + + public AssignExpr(Expression target, Expression value, Operator op) { + setTarget(target); + setValue(value); + setOperator(op); + } + + public AssignExpr(Range range, Expression target, Expression value, Operator op) { + super(range); + setTarget(target); + setValue(value); + setOperator(op); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Operator getOperator() { + return op; + } + + public Expression getTarget() { + return target; + } + + public Expression getValue() { + return value; + } + + public AssignExpr setOperator(Operator op) { + this.op = op; + return this; + } + + public AssignExpr setTarget(Expression target) { + this.target = target; + setAsParentNodeOf(this.target); + return this; + } + + public AssignExpr setValue(Expression value) { + this.value = value; + setAsParentNodeOf(this.value); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BinaryExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BinaryExpr.java new file mode 100644 index 000000000..83675c8c4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BinaryExpr.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class BinaryExpr extends Expression { + + public enum Operator { + or, // || + and, // && + binOr, // | + binAnd, // & + xor, // ^ + equals, // == + notEquals, // != + less, // < + greater, // > + lessEquals, // <= + greaterEquals, // >= + lShift, // << + rSignedShift, // >> + rUnsignedShift, // >>> + plus, // + + minus, // - + times, // * + divide, // / + remainder, // % + } + + private Expression left; + + private Expression right; + + private Operator op; + + public BinaryExpr() { + } + + public BinaryExpr(Expression left, Expression right, Operator op) { + setLeft(left); + setRight(right); + setOperator(op); + } + + public BinaryExpr(Range range, Expression left, Expression right, Operator op) { + super(range); + setLeft(left); + setRight(right); + setOperator(op); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getLeft() { + return left; + } + + public Operator getOperator() { + return op; + } + + public Expression getRight() { + return right; + } + + public BinaryExpr setLeft(Expression left) { + this.left = left; + setAsParentNodeOf(this.left); + return this; + } + + public BinaryExpr setOperator(Operator op) { + this.op = op; + return this; + } + + public BinaryExpr setRight(Expression right) { + this.right = right; + setAsParentNodeOf(this.right); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BooleanLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BooleanLiteralExpr.java new file mode 100644 index 000000000..a42c8c722 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/BooleanLiteralExpr.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class BooleanLiteralExpr extends LiteralExpr { + + private boolean value; + + public BooleanLiteralExpr() { + } + + public BooleanLiteralExpr(boolean value) { + setValue(value); + } + + public BooleanLiteralExpr(Range range, boolean value) { + super(range); + setValue(value); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public boolean getValue() { + return value; + } + + public BooleanLiteralExpr setValue(boolean value) { + this.value = value; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CastExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CastExpr.java new file mode 100644 index 000000000..d2a54bc08 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CastExpr.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class CastExpr extends Expression implements NodeWithType<CastExpr> { + + private Type type; + + private Expression expr; + + public CastExpr() { + } + + public CastExpr(Type type, Expression expr) { + setType(type); + setExpr(expr); + } + + public CastExpr(Range range, Type type, Expression expr) { + super(range); + setType(type); + setExpr(expr); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getExpr() { + return expr; + } + + @Override + public Type getType() { + return type; + } + + public CastExpr setExpr(Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } + + @Override + public CastExpr setType(Type type) { + this.type = type; + setAsParentNodeOf(this.type); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CharLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CharLiteralExpr.java new file mode 100644 index 000000000..e799e887c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/CharLiteralExpr.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.utils.Utils; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class CharLiteralExpr extends StringLiteralExpr { + + public CharLiteralExpr() { + } + + public CharLiteralExpr(String value) { + super(value); + } + + public CharLiteralExpr(Range range, String value) { + super(range, value); + } + + /** + * Utility method that creates a new StringLiteralExpr. Escapes EOL characters. + */ + public static CharLiteralExpr escape(String string) { + return new CharLiteralExpr(Utils.escapeEndOfLines(string)); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ClassExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ClassExpr.java new file mode 100644 index 000000000..a6dc9058d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ClassExpr.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * Defines an expression that accesses the class of a type. + * Example: + * <code> + * Object.class + * </code> + * @author Julio Vilmar Gesser + */ +public final class ClassExpr extends Expression implements NodeWithType<ClassExpr> { + + private Type type; + + public ClassExpr() { + } + + public ClassExpr(Type type) { + setType(type); + } + + public ClassExpr(Range range, Type type) { + super(range); + setType(type); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public Type getType() { + return type; + } + + @Override + public ClassExpr setType(Type type) { + this.type = type; + setAsParentNodeOf(this.type); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ConditionalExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ConditionalExpr.java new file mode 100644 index 000000000..4dd4c4b0f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ConditionalExpr.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ConditionalExpr extends Expression { + + private Expression condition; + + private Expression thenExpr; + + private Expression elseExpr; + + public ConditionalExpr() { + } + + public ConditionalExpr(Expression condition, Expression thenExpr, Expression elseExpr) { + setCondition(condition); + setThenExpr(thenExpr); + setElseExpr(elseExpr); + } + + public ConditionalExpr(Range range, Expression condition, Expression thenExpr, Expression elseExpr) { + super(range); + setCondition(condition); + setThenExpr(thenExpr); + setElseExpr(elseExpr); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getCondition() { + return condition; + } + + public Expression getElseExpr() { + return elseExpr; + } + + public Expression getThenExpr() { + return thenExpr; + } + + public ConditionalExpr setCondition(Expression condition) { + this.condition = condition; + setAsParentNodeOf(this.condition); + return this; + } + + public ConditionalExpr setElseExpr(Expression elseExpr) { + this.elseExpr = elseExpr; + setAsParentNodeOf(this.elseExpr); + return this; + } + + public ConditionalExpr setThenExpr(Expression thenExpr) { + this.thenExpr = thenExpr; + setAsParentNodeOf(this.thenExpr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/DoubleLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/DoubleLiteralExpr.java new file mode 100644 index 000000000..b78923851 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/DoubleLiteralExpr.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class DoubleLiteralExpr extends StringLiteralExpr { + + public DoubleLiteralExpr() { + } + + public DoubleLiteralExpr(final String value) { + super(value); + } + + public DoubleLiteralExpr(final Range range, final String value) { + super(range, value); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/EnclosedExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/EnclosedExpr.java new file mode 100644 index 000000000..a7c40febc --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/EnclosedExpr.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class EnclosedExpr extends Expression { + + private Expression inner; + + public EnclosedExpr() { + } + + public EnclosedExpr(final Expression inner) { + setInner(inner); + } + + public EnclosedExpr(final Range range, final Expression inner) { + super(range); + setInner(inner); + } + + @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 getInner() { + return inner; + } + + public EnclosedExpr setInner(final Expression inner) { + this.inner = inner; + setAsParentNodeOf(this.inner); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/Expression.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/Expression.java new file mode 100644 index 000000000..f9745646f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/Expression.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class Expression extends Node { + + public Expression() { + } + + public Expression(Range range) { + super(range); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/FieldAccessExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/FieldAccessExpr.java new file mode 100644 index 000000000..0a4badf5c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/FieldAccessExpr.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +/** + * @author Julio Vilmar Gesser + */ +public final class FieldAccessExpr extends Expression implements NodeWithTypeArguments<FieldAccessExpr> { + + private Expression scope; + + private List<Type<?>> typeArguments; + + private NameExpr field; + + public FieldAccessExpr() { + } + + public FieldAccessExpr(final Expression scope, final String field) { + setScope(scope); + setField(field); + } + + public FieldAccessExpr(final Range range, final Expression scope, final List<Type<?>> typeArguments, final String 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 String getField() { + return field.getName(); + } + + public NameExpr getFieldExpr() { + return field; + } + + public Expression getScope() { + return scope; + } + + public FieldAccessExpr setField(final String field) { + setFieldExpr(new NameExpr(field)); + return this; + } + + public FieldAccessExpr setFieldExpr(NameExpr field) { + this.field = field; + setAsParentNodeOf(this.field); + return this; + } + + public FieldAccessExpr setScope(final Expression scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public FieldAccessExpr setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/InstanceOfExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/InstanceOfExpr.java new file mode 100644 index 000000000..ffc248ce6 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/InstanceOfExpr.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr> { + + private Expression expr; + + private Type type; + + public InstanceOfExpr() { + } + + public InstanceOfExpr(final Expression expr, final Type type) { + setExpr(expr); + setType(type); + } + + public InstanceOfExpr(final Range range, final Expression expr, final Type type) { + super(range); + setExpr(expr); + setType(type); + } + + @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 getExpr() { + return expr; + } + + @Override + public Type getType() { + return type; + } + + public InstanceOfExpr setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } + + @Override + public InstanceOfExpr setType(final Type type) { + this.type = type; + setAsParentNodeOf(this.type); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralExpr.java new file mode 100644 index 000000000..91f5dec77 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralExpr.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public class IntegerLiteralExpr extends StringLiteralExpr { + + private static final String UNSIGNED_MIN_VALUE = "2147483648"; + + protected static final String MIN_VALUE = "-" + UNSIGNED_MIN_VALUE; + + public IntegerLiteralExpr() { + } + + public IntegerLiteralExpr(final String value) { + super(value); + } + + public IntegerLiteralExpr(final Range range, final String value) { + super(range, value); + } + + @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 final boolean isMinValue() { + return value != null && // + value.length() == 10 && // + value.equals(UNSIGNED_MIN_VALUE); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java new file mode 100644 index 000000000..2665aafe3 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class IntegerLiteralMinValueExpr extends IntegerLiteralExpr { + + public IntegerLiteralMinValueExpr() { + super(MIN_VALUE); + } + + public IntegerLiteralMinValueExpr(final Range range) { + super(range, MIN_VALUE); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LambdaExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LambdaExpr.java new file mode 100644 index 000000000..4db1b0dfb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LambdaExpr.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.*; + +/** + * Lambda expression. + * + * @author Raquel Pau + */ +public class LambdaExpr extends Expression { + + private List<Parameter> parameters; + + private boolean parametersEnclosed; + + private Statement body; + + public LambdaExpr() { + } + + public LambdaExpr(Range range, List<Parameter> parameters, Statement body, + boolean parametersEnclosed) { + + super(range); + setParameters(parameters); + setBody(body); + setParametersEnclosed(parametersEnclosed); + } + + public List<Parameter> getParameters() { + parameters = ensureNotNull(parameters); + return parameters; + } + + public LambdaExpr setParameters(List<Parameter> parameters) { + this.parameters = parameters; + setAsParentNodeOf(this.parameters); + return this; + } + + public Statement getBody() { + return body; + } + + public LambdaExpr setBody(Statement body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public boolean isParametersEnclosed() { + return parametersEnclosed; + } + + public LambdaExpr setParametersEnclosed(boolean parametersEnclosed) { + this.parametersEnclosed = parametersEnclosed; + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LiteralExpr.java new file mode 100644 index 000000000..9cafefdc4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LiteralExpr.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class LiteralExpr extends Expression { + + public LiteralExpr() { + } + + public LiteralExpr(Range range) { + super(range); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralExpr.java new file mode 100644 index 000000000..0e2e8f299 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralExpr.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public class LongLiteralExpr extends StringLiteralExpr { + + private static final String UNSIGNED_MIN_VALUE = "9223372036854775808"; + + protected static final String MIN_VALUE = "-" + UNSIGNED_MIN_VALUE + "L"; + + public LongLiteralExpr() { + } + + public LongLiteralExpr(final String value) { + super(value); + } + + public LongLiteralExpr(final Range range, final String value) { + super(range, value); + } + + @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 final boolean isMinValue() { + return value != null && // + value.length() == 20 && // + value.startsWith(UNSIGNED_MIN_VALUE) && // + (value.charAt(19) == 'L' || value.charAt(19) == 'l'); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java new file mode 100644 index 000000000..d46145a4a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class LongLiteralMinValueExpr extends LongLiteralExpr { + + public LongLiteralMinValueExpr() { + super(MIN_VALUE); + } + + public LongLiteralMinValueExpr(final Range range) { + super(range, MIN_VALUE); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java new file mode 100644 index 000000000..1a117ff97 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class MarkerAnnotationExpr extends AnnotationExpr { + + public MarkerAnnotationExpr() { + } + + public MarkerAnnotationExpr(final NameExpr name) { + setName(name); + } + + public MarkerAnnotationExpr(final Range range, final NameExpr name) { + super(range); + setName(name); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MemberValuePair.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MemberValuePair.java new file mode 100644 index 000000000..f87af5dbb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MemberValuePair.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class MemberValuePair extends Node implements NodeWithName<MemberValuePair> { + + private String name; + + private Expression value; + + public MemberValuePair() { + } + + public MemberValuePair(final String name, final Expression value) { + setName(name); + setValue(value); + } + + public MemberValuePair(final Range range, final String name, final Expression value) { + super(range); + setName(name); + setValue(value); + } + + @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 String getName() { + return name; + } + + public Expression getValue() { + return value; + } + + @Override + public MemberValuePair setName(final String name) { + this.name = name; + return this; + } + + public MemberValuePair setValue(final Expression value) { + this.value = value; + setAsParentNodeOf(this.value); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodCallExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodCallExpr.java new file mode 100644 index 000000000..98a246455 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodCallExpr.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class MethodCallExpr extends Expression implements NodeWithTypeArguments<MethodCallExpr> { + + private Expression scope; + + private List<Type<?>> typeArguments; + + private NameExpr name; + + private List<Expression> args; + + public MethodCallExpr() { + } + + public MethodCallExpr(final Expression scope, final String name) { + setScope(scope); + setName(name); + } + + public MethodCallExpr(final Expression scope, final String name, final List<Expression> args) { + setScope(scope); + setName(name); + setArgs(args); + } + + public MethodCallExpr(final Range range, final Expression scope, final List<Type<?>> typeArguments, final String name, final List<Expression> args) { + super(range); + setScope(scope); + setTypeArguments(typeArguments); + setName(name); + setArgs(args); + } + + /** + * Adds the given argument to the method call. + * + * @param arg + * argument value + */ + public MethodCallExpr addArgument(Expression arg) { + getArgs().add(arg); + arg.setParentNode(this); + return this; + } + + public void addArgument(String arg) { + addArgument(new NameExpr(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); + } + + public List<Expression> getArgs() { + args = ensureNotNull(args); + return args; + } + + public String getName() { + return name.getName(); + } + + public NameExpr getNameExpr() { + return name; + } + + public Expression getScope() { + return scope; + } + + public void setArgs(final List<Expression> args) { + this.args = args; + setAsParentNodeOf(this.args); + } + + public MethodCallExpr setName(final String name) { + setNameExpr(new NameExpr(name)); + return this; + } + + public MethodCallExpr setNameExpr(NameExpr name) { + this.name = name; + setAsParentNodeOf(this.name); + return this; + } + + public MethodCallExpr setScope(final Expression scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public MethodCallExpr setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodReferenceExpr.java new file mode 100644 index 000000000..d048ca16a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/MethodReferenceExpr.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * Method reference expressions introduced in Java 8 specifically designed to simplify lambda Expressions. + * These are some examples: + * + * System.out::println; + * + * (test ? stream.map(String::trim) : stream)::toArray; + * @author Raquel Pau + * + */ +public class MethodReferenceExpr extends Expression implements NodeWithTypeArguments<MethodReferenceExpr> { + + private Expression scope; + + private List<Type<?>> typeArguments; + + private String identifier; + + public MethodReferenceExpr() { + } + + public MethodReferenceExpr(Range range, Expression scope, + List<Type<?>> typeArguments, String identifier) { + super(range); + setIdentifier(identifier); + setScope(scope); + setTypeArguments(typeArguments); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public Expression getScope() { + return scope; + } + + public MethodReferenceExpr setScope(Expression scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public MethodReferenceExpr setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } + + public String getIdentifier() { + return identifier; + } + + public MethodReferenceExpr setIdentifier(String identifier) { + this.identifier = identifier; + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NameExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NameExpr.java new file mode 100644 index 000000000..331fa2af3 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NameExpr.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public class NameExpr extends Expression implements NodeWithName<NameExpr> { + + private String name; + + public NameExpr() { + } + + public NameExpr(final String name) { + this.name = name; + } + + public NameExpr(Range range, final String name) { + super(range); + this.name = name; + } + + @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 final String getName() { + return name; + } + + @Override + public NameExpr setName(final String name) { + this.name = name; + return this; + } + + + /** + * Creates a new {@link NameExpr} from a qualified name.<br> + * The qualified name can contains "." (dot) characters. + * + * @param qualifiedName + * qualified name + * @return instanceof {@link NameExpr} + */ + public static NameExpr name(String qualifiedName) { + String[] split = qualifiedName.split("\\."); + NameExpr ret = new NameExpr(split[0]); + for (int i = 1; i < split.length; i++) { + ret = new QualifiedNameExpr(ret, split[i]); + } + return ret; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NormalAnnotationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NormalAnnotationExpr.java new file mode 100644 index 000000000..502b11dbd --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NormalAnnotationExpr.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.ast.expr.NameExpr.*; +import static com.github.javaparser.utils.Utils.ensureNotNull; + +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class NormalAnnotationExpr extends AnnotationExpr { + + private List<MemberValuePair> pairs; + + public NormalAnnotationExpr() { + } + + public NormalAnnotationExpr(final NameExpr name, final List<MemberValuePair> pairs) { + setName(name); + setPairs(pairs); + } + + public NormalAnnotationExpr(final Range range, final NameExpr name, final List<MemberValuePair> pairs) { + super(range); + setName(name); + setPairs(pairs); + } + + @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 List<MemberValuePair> getPairs() { + pairs = ensureNotNull(pairs); + return pairs; + } + + public NormalAnnotationExpr setPairs(final List<MemberValuePair> pairs) { + this.pairs = pairs; + setAsParentNodeOf(this.pairs); + return this; + } + + /** + * adds a pair to this annotation + * + * @return this, the {@link NormalAnnotationExpr} + */ + public NormalAnnotationExpr addPair(String key, String value) { + return addPair(key, name(value)); + } + + /** + * adds a pair to this annotation + * + * @return this, the {@link NormalAnnotationExpr} + */ + public NormalAnnotationExpr addPair(String key, NameExpr value) { + MemberValuePair memberValuePair = new MemberValuePair(key, value); + getPairs().add(memberValuePair); + memberValuePair.setParentNode(this); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NullLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NullLiteralExpr.java new file mode 100644 index 000000000..cb0a92b83 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/NullLiteralExpr.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class NullLiteralExpr extends LiteralExpr { + + public NullLiteralExpr() { + } + + public NullLiteralExpr(final Range range) { + super(range); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ObjectCreationExpr.java new file mode 100644 index 000000000..4d06ff8db --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ObjectCreationExpr.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +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 java.util.ArrayList; +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * Defines constructor call expression. + * Example: + * <code> + * new Object() + * </code> + * + * @author Julio Vilmar Gesser + */ +public final class ObjectCreationExpr extends Expression implements + NodeWithTypeArguments<ObjectCreationExpr>, + NodeWithType<ObjectCreationExpr> { + + private Expression scope; + + private ClassOrInterfaceType type; + + private List<Type<?>> typeArguments; + + private List<Expression> args; + + // This can be null, to indicate there is no body + private List<BodyDeclaration<?>> anonymousClassBody; + + public ObjectCreationExpr() { + } + + /** + * Defines a call to a constructor. + * + * @param scope may be null + * @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 List<Expression> args) { + setScope(scope); + setType(type); + setArgs(args); + } + + public ObjectCreationExpr(final Range range, + final Expression scope, final ClassOrInterfaceType type, final List<Type<?>> typeArguments, + final List<Expression> args, final List<BodyDeclaration<?>> 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) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + /** + * This can be null, to indicate there is no body + */ + public List<BodyDeclaration<?>> getAnonymousClassBody() { + return anonymousClassBody; + } + + public void addAnonymousClassBody(BodyDeclaration<?> body) { + if (anonymousClassBody == null) + anonymousClassBody = new ArrayList<>(); + anonymousClassBody.add(body); + body.setParentNode(this); + } + + public List<Expression> getArgs() { + args = ensureNotNull(args); + return args; + } + + public Expression getScope() { + return scope; + } + + @Override + public ClassOrInterfaceType getType() { + return type; + } + + public ObjectCreationExpr setAnonymousClassBody(final List<BodyDeclaration<?>> anonymousClassBody) { + this.anonymousClassBody = anonymousClassBody; + setAsParentNodeOf(this.anonymousClassBody); + return this; + } + + public ObjectCreationExpr setArgs(final List<Expression> args) { + this.args = args; + setAsParentNodeOf(this.args); + return this; + } + + public ObjectCreationExpr setScope(final Expression scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + @Override + public ObjectCreationExpr setType(final Type<?> type) { + if (!(type instanceof ClassOrInterfaceType))// needed so we can use NodeWithType + throw new RuntimeException("You can only add ClassOrInterfaceType to an ObjectCreationExpr"); + this.type = (ClassOrInterfaceType) type; + setAsParentNodeOf(this.type); + return this; + } + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public ObjectCreationExpr setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/QualifiedNameExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/QualifiedNameExpr.java new file mode 100644 index 000000000..dd906310d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/QualifiedNameExpr.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class QualifiedNameExpr extends NameExpr { + + private NameExpr qualifier; + + public QualifiedNameExpr() { + } + + public QualifiedNameExpr(final NameExpr scope, final String name) { + super(name); + setQualifier(scope); + } + + public QualifiedNameExpr(final Range range, final NameExpr scope, final String name) { + super(range, name); + setQualifier(scope); + } + + @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 NameExpr getQualifier() { + return qualifier; + } + + public QualifiedNameExpr setQualifier(final NameExpr qualifier) { + this.qualifier = qualifier; + setAsParentNodeOf(this.qualifier); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java new file mode 100644 index 000000000..bd6692c83 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class SingleMemberAnnotationExpr extends AnnotationExpr { + + private Expression memberValue; + + public SingleMemberAnnotationExpr() { + } + + public SingleMemberAnnotationExpr(final NameExpr name, final Expression memberValue) { + setName(name); + setMemberValue(memberValue); + } + + public SingleMemberAnnotationExpr(final Range range, final NameExpr name, final Expression memberValue) { + super(range); + setName(name); + setMemberValue(memberValue); + } + + @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 getMemberValue() { + return memberValue; + } + + public SingleMemberAnnotationExpr setMemberValue(final Expression memberValue) { + this.memberValue = memberValue; + setAsParentNodeOf(this.memberValue); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/StringLiteralExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/StringLiteralExpr.java new file mode 100644 index 000000000..f66a594da --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/StringLiteralExpr.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.utils.Utils; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * Java® Language Specification 3.10.5 String Literals + * @author Julio Vilmar Gesser + */ +public class StringLiteralExpr extends LiteralExpr { + + protected String value; + + public StringLiteralExpr() { + this.value = ""; + } + + public StringLiteralExpr(final String value) { + if (value.contains("\n") || value.contains("\r")) { + throw new IllegalArgumentException("Illegal literal expression: newlines (line feed or carriage return) have to be escaped"); + } + this.value = value; + } + + /** + * Utility method that creates a new StringLiteralExpr. Escapes EOL characters. + */ + public static StringLiteralExpr escape(String string) { + return new StringLiteralExpr(Utils.escapeEndOfLines(string)); + } + + public StringLiteralExpr(final Range range, final String value) { + super(range); + this.value = value; + } + + @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 final String getValue() { + return value; + } + + public final StringLiteralExpr setValue(final String value) { + this.value = value; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SuperExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SuperExpr.java new file mode 100644 index 000000000..3f5e1866c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/SuperExpr.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class SuperExpr extends Expression { + + private Expression classExpr; + + public SuperExpr() { + } + + public SuperExpr(final Expression classExpr) { + setClassExpr(classExpr); + } + + public SuperExpr(final Range range, final Expression classExpr) { + super(range); + setClassExpr(classExpr); + } + + @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 getClassExpr() { + return classExpr; + } + + public SuperExpr setClassExpr(final Expression classExpr) { + this.classExpr = classExpr; + setAsParentNodeOf(this.classExpr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ThisExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ThisExpr.java new file mode 100644 index 000000000..117fed53d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/ThisExpr.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ThisExpr extends Expression { + + private Expression classExpr; + + public ThisExpr() { + } + + public ThisExpr(final Expression classExpr) { + setClassExpr(classExpr); + } + + public ThisExpr(final Range range, final Expression classExpr) { + super(range); + setClassExpr(classExpr); + } + + @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 getClassExpr() { + return classExpr; + } + + public ThisExpr setClassExpr(final Expression classExpr) { + this.classExpr = classExpr; + setAsParentNodeOf(this.classExpr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/TypeExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/TypeExpr.java new file mode 100644 index 000000000..28b14e19f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/TypeExpr.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * This class is just instantiated as scopes for MethodReferenceExpr nodes to encapsulate Types. + * @author Raquel Pau + * + */ +public class TypeExpr extends Expression implements NodeWithType<TypeExpr> { + + private Type<?> type; + + public TypeExpr(){} + + public TypeExpr(Range range, Type<?> type) { + super(range); + setType(type); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + @Override + public Type<?> getType() { + return type; + } + + @Override + public TypeExpr setType(Type<?> type) { + this.type = type; + setAsParentNodeOf(this.type); + return this; + } + + + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/UnaryExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/UnaryExpr.java new file mode 100644 index 000000000..eef9101ee --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/UnaryExpr.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.expr; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class UnaryExpr extends Expression { + + public enum Operator { + positive, // + + negative, // - + preIncrement, // ++ + preDecrement, // -- + not, // ! + inverse, // ~ + posIncrement, // ++ + posDecrement, // -- + } + + private Expression expr; + + private Operator op; + + public UnaryExpr() { + } + + public UnaryExpr(final Expression expr, final Operator op) { + setExpr(expr); + setOperator(op); + } + + public UnaryExpr(final Range range, final Expression expr, final Operator op) { + super(range); + setExpr(expr); + setOperator(op); + } + + @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 getExpr() { + return expr; + } + + public Operator getOperator() { + return op; + } + + public UnaryExpr setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } + + public UnaryExpr setOperator(final Operator op) { + this.op = op; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/VariableDeclarationExpr.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/VariableDeclarationExpr.java new file mode 100644 index 000000000..5bb0f6299 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/expr/VariableDeclarationExpr.java @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.ensureNotNull; +import static java.util.Collections.*; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Collectors; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.body.VariableDeclarator; +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.NodeWithVariables; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class VariableDeclarationExpr extends Expression implements + NodeWithElementType<VariableDeclarationExpr>, + NodeWithModifiers<VariableDeclarationExpr>, + NodeWithAnnotations<VariableDeclarationExpr>, + NodeWithVariables<VariableDeclarationExpr> { + + private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); + + private List<AnnotationExpr> annotations; + + private Type elementType; + + private List<VariableDeclarator> variables; + + private List<ArrayBracketPair> arrayBracketPairsAfterType; + + public VariableDeclarationExpr() { + } + + public VariableDeclarationExpr(final Type elementType, String variableName) { + setElementType(elementType); + setVariables(singletonList(new VariableDeclarator(variableName))); + } + + public VariableDeclarationExpr(final Type elementType, VariableDeclarator var) { + setElementType(elementType); + setVariables(singletonList(var)); + } + + public VariableDeclarationExpr(final Type elementType, String variableName, Modifier... modifiers) { + setElementType(elementType); + setVariables(singletonList(new VariableDeclarator(variableName))); + setModifiers(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class)))); + } + + public VariableDeclarationExpr(final Type elementType, VariableDeclarator var, Modifier... modifiers) { + setElementType(elementType); + setVariables(singletonList(var)); + setModifiers(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class)))); + } + + public VariableDeclarationExpr(final Type elementType, final List<VariableDeclarator> variables) { + setElementType(elementType); + setVariables(variables); + } + + public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final Type elementType, + final List<VariableDeclarator> variables) { + setModifiers(modifiers); + setElementType(elementType); + setVariables(variables); + } + + public VariableDeclarationExpr(final Range range, + final EnumSet<Modifier> modifiers, final List<AnnotationExpr> annotations, + final Type elementType, + final List<VariableDeclarator> variables, + final List<ArrayBracketPair> arrayBracketPairsAfterType) { + super(range); + setModifiers(modifiers); + setAnnotations(annotations); + setElementType(elementType); + setVariables(variables); + setArrayBracketPairsAfterElementType(arrayBracketPairsAfterType); + } + + /** + * Creates a {@link VariableDeclarationExpr}. + * + * @return instance of {@link VariableDeclarationExpr} + */ + public static VariableDeclarationExpr create(Type type, String name) { + return new VariableDeclarationExpr(type, name); + } + + @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 List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + /** + * Return the modifiers of this variable declaration. + * + * @see Modifier + * @return modifiers + */ + @Override + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Override + public Type getElementType() { + return elementType; + } + + @Override + public List<VariableDeclarator> getVariables() { + variables = ensureNotNull(variables); + return variables; + } + + @Override + public VariableDeclarationExpr setAnnotations(final List<AnnotationExpr> annotations) { + this.annotations = annotations; + setAsParentNodeOf(this.annotations); + return this; + } + + @Override + public VariableDeclarationExpr setModifiers(final EnumSet<Modifier> modifiers) { + this.modifiers = modifiers; + return this; + } + + @Override + public VariableDeclarationExpr setElementType(final Type elementType) { + this.elementType = elementType; + setAsParentNodeOf(this.elementType); + return this; + } + + @Override + public VariableDeclarationExpr setVariables(final List<VariableDeclarator> variables) { + this.variables = variables; + setAsParentNodeOf(this.variables); + return this; + } + + public List<ArrayBracketPair> getArrayBracketPairsAfterElementType() { + arrayBracketPairsAfterType = ensureNotNull(arrayBracketPairsAfterType); + return arrayBracketPairsAfterType; + } + + @Override + public VariableDeclarationExpr setArrayBracketPairsAfterElementType(List<ArrayBracketPair> arrayBracketPairsAfterType) { + this.arrayBracketPairsAfterType = arrayBracketPairsAfterType; + setAsParentNodeOf(arrayBracketPairsAfterType); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java new file mode 100644 index 000000000..71ff7179b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import java.lang.annotation.Annotation; +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; + +import static com.github.javaparser.ast.expr.NameExpr.*; + +/** + * An element which can be the target of annotations. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public interface NodeWithAnnotations<T> { + List<AnnotationExpr> getAnnotations(); + + T setAnnotations(List<AnnotationExpr> annotations); + + /** + * Annotates this + * + * @param name the name of the annotation + * @return the {@link NormalAnnotationExpr} added + */ + public default NormalAnnotationExpr addAnnotation(String name) { + NormalAnnotationExpr normalAnnotationExpr = new NormalAnnotationExpr( + name(name), null); + getAnnotations().add(normalAnnotationExpr); + normalAnnotationExpr.setParentNode((Node) this); + return normalAnnotationExpr; + } + + /** + * Annotates this and automatically add the import + * + * @param clazz the class of the annotation + * @return the {@link NormalAnnotationExpr} added + */ + public default NormalAnnotationExpr addAnnotation(Class<? extends Annotation> clazz) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addAnnotation(clazz.getSimpleName()); + } + + /** + * Annotates this with a marker annotation + * + * @param name the name of the annotation + * @return this + */ + @SuppressWarnings("unchecked") + public default T addMarkerAnnotation(String name) { + MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr( + name(name)); + getAnnotations().add(markerAnnotationExpr); + markerAnnotationExpr.setParentNode((Node) this); + return (T) this; + } + + /** + * Annotates this with a marker annotation and automatically add the import + * + * @param clazz the class of the annotation + * @return this + */ + public default T addMarkerAnnotation(Class<? extends Annotation> clazz) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addMarkerAnnotation(clazz.getSimpleName()); + } + + /** + * Annotates this with a single member annotation + * + * @param name the name of the annotation + * @param value the value, don't forget to add \"\" for a string value + * @return this + */ + @SuppressWarnings("unchecked") + public default T addSingleMemberAnnotation(String name, String value) { + SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr( + name(name), name(value)); + getAnnotations().add(singleMemberAnnotationExpr); + singleMemberAnnotationExpr.setParentNode((Node) this); + return (T) this; + } + + /** + * Annotates this with a single member annotation and automatically add the import + * + * @param clazz the class of the annotation + * @param value the value, don't forget to add \"\" for a string value + * @return this + */ + public default T addSingleMemberAnnotation(Class<? extends Annotation> clazz, + String value) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addSingleMemberAnnotation(clazz.getSimpleName(), value); + } + + /** + * Check whether an annotation with this name is present on this element + * + * @param annotationName the name of the annotation + * @return true if found, false if not + */ + public default boolean isAnnotationPresent(String annotationName) { + return getAnnotations().stream().anyMatch(a -> a.getName().getName().equals(annotationName)); + } + + /** + * Check whether an annotation with this class is present on this element + * + * @param annotationClass the class of the annotation + * @return true if found, false if not + */ + public default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { + return isAnnotationPresent(annotationClass.getSimpleName()); + } + + /** + * Try to find an annotation by its name + * + * @param annotationName the name of the annotation + * @return null if not found, the annotation otherwise + */ + public default AnnotationExpr getAnnotationByName(String annotationName) { + return getAnnotations().stream().filter(a -> a.getName().getName().equals(annotationName)).findFirst() + .orElse(null); + } + + /** + * Try to find an annotation by its class + * + * @param annotationClass the class of the annotation + * @return null if not found, the annotation otherwise + */ + public default AnnotationExpr getAnnotationByClass(Class<? extends Annotation> annotationClass) { + return getAnnotationByName(annotationClass.getSimpleName()); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java new file mode 100644 index 000000000..381318b66 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java @@ -0,0 +1,18 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.stmt.BlockStmt; + +public interface NodeWithBlockStmt<T> { + BlockStmt getBody(); + + T setBody(BlockStmt block); + + default BlockStmt createBody() { + BlockStmt block = new BlockStmt(); + setBody(block); + block.setParentNode((Node) this); + + return block; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBody.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBody.java new file mode 100644 index 000000000..2adfe8664 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithBody.java @@ -0,0 +1,18 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; + +public interface NodeWithBody<T> { + public Statement getBody(); + + public T setBody(final Statement body); + + public default BlockStmt createBlockStatementAsBody() { + BlockStmt b = new BlockStmt(); + b.setParentNode((Node) this); + setBody(b); + return b; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java new file mode 100644 index 000000000..875d28de0 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +/** + * Element with a declaration representable as a String. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public interface NodeWithDeclaration { + + /** + * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including + * the modifiers, the throws clause and the parameters with both type and name. + * @return String representation of declaration + */ + String getDeclarationAsString(); + + /** + * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including + * the parameters with both type and name. + * @param includingModifiers flag to include the modifiers (if present) in the string produced + * @param includingThrows flag to include the throws clause (if present) in the string produced + * @return String representation of declaration based on parameter flags + */ + String getDeclarationAsString(boolean includingModifiers, boolean includingThrows); + + /** + * A simple representation of the element declaration. + * It should fit one string. + * @param includingModifiers flag to include the modifiers (if present) in the string produced + * @param includingThrows flag to include the throws clause (if present) in the string produced + * @param includingParameterName flag to include the parameter name (while the parameter type is always included) in the string produced + * @return String representation of declaration based on parameter flags + */ + String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithElementType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithElementType.java new file mode 100644 index 000000000..21a41bad8 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithElementType.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; + +import java.util.List; + +/** + * A node having an element type. + * In most cases, the element type is simply the type. + * In case of arrays, the element type is the type that is inside the deepest nesting: + * for int[][][], the element type is int. + * + * The main reason for this interface is to permit users to manipulate homogeneously all nodes with getElementType/setElementType + * methods + */ +public interface NodeWithElementType<T> { + /** + * @return the element type + */ + Type<?> getElementType(); + + /** + * @param elementType the element elementType + * @return this + */ + T setElementType(Type<?> elementType); + + List<ArrayBracketPair> getArrayBracketPairsAfterElementType(); + + T setArrayBracketPairsAfterElementType(List<ArrayBracketPair> arrayBracketPairsAfterType); + + /** + * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed + * + * @param typeClass the type + * @return this + */ + default T setElementType(Class<?> typeClass) { + ((Node) this).tryAddImportToParentCompilationUnit(typeClass); + return setElementType(new ClassOrInterfaceType(typeClass.getSimpleName())); + } + + default T setElementType(final String type) { + ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(type); + return setElementType(classOrInterfaceType); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java new file mode 100644 index 000000000..083fc01b1 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java @@ -0,0 +1,37 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.ClassOrInterfaceType; + +public interface NodeWithExtends<T> { + public List<ClassOrInterfaceType> getExtends(); + + public T setExtends(final List<ClassOrInterfaceType> extendsList); + + /** + * Add an extends to this and automatically add the import + * + * @param clazz the class to extand from + * @return this + */ + public default T addExtends(Class<?> clazz) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addExtends(clazz.getSimpleName()); + } + + /** + * Add an extends to this + * + * @param name the name of the type to extends from + * @return this + */ + @SuppressWarnings("unchecked") + public default T addExtends(String name) { + ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name); + getExtends().add(classOrInterfaceType); + classOrInterfaceType.setParentNode((Node) this); + return (T) this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java new file mode 100644 index 000000000..3f5192587 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java @@ -0,0 +1,37 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.ClassOrInterfaceType; + +public interface NodeWithImplements<T> { + public List<ClassOrInterfaceType> getImplements(); + + public T setImplements(List<ClassOrInterfaceType> implementsList); + + /** + * Add an implements to this + * + * @param name the name of the type to extends from + * @return this + */ + @SuppressWarnings("unchecked") + public default T addImplements(String name) { + ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name); + getImplements().add(classOrInterfaceType); + classOrInterfaceType.setParentNode((Node) this); + return (T) this; + } + + /** + * Add an implements to this and automatically add the import + * + * @param clazz the type to implements from + * @return this + */ + public default T addImplements(Class<?> clazz) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addImplements(clazz.getSimpleName()); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithJavaDoc.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithJavaDoc.java new file mode 100644 index 000000000..b00cffa5d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithJavaDoc.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.JavadocComment; + +/** + * Node which can be documented through a Javadoc comment. + */ +public interface NodeWithJavaDoc<T> { + /** + * Gets the JavaDoc for this node. You can set the JavaDoc by calling setComment with a JavadocComment. + * + * @return The JavaDoc for this node if it exists, null if it doesn't. + */ + JavadocComment getJavaDoc(); + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + @SuppressWarnings("unchecked") + public default T setJavaDocComment(String comment) { + ((Node) this).setComment(new JavadocComment(comment)); + return (T) this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java new file mode 100644 index 000000000..827e5edee --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java @@ -0,0 +1,284 @@ +package com.github.javaparser.ast.nodeTypes; + +import static com.github.javaparser.ast.type.VoidType.VOID_TYPE; +import static java.util.Collections.unmodifiableList; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Stream; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +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.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.VariableDeclaratorId; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; + +/** + * A node having members. + * + * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getMembers + * method. + * + */ +public interface NodeWithMembers<T> { + List<BodyDeclaration<?>> getMembers(); + + T setMembers(List<BodyDeclaration<?>> members); + + /** + * Add a field to this and automatically add the import of the type if needed + * + * @param typeClass the type of the field + * @param name the name of the field + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addField(Class<?> typeClass, String name, Modifier... modifiers) { + ((Node) this).tryAddImportToParentCompilationUnit(typeClass); + return addField(typeClass.getSimpleName(), name, modifiers); + } + + /** + * Add a field to this + * + * @param type the type of the field + * @param name the name of the field + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addField(String type, String name, Modifier... modifiers) { + return addField(new ClassOrInterfaceType(type), name, modifiers); + } + + /** + * Add a field to this + * + * @param type the type of the field + * @param name the name of the field + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addField(Type<?> type, String name, Modifier... modifiers) { + FieldDeclaration fieldDeclaration = new FieldDeclaration(); + fieldDeclaration.setParentNode((Node) this); + VariableDeclarator variable = new VariableDeclarator(new VariableDeclaratorId(name)); + fieldDeclaration.getVariables().add(variable); + variable.setParentNode(fieldDeclaration); + fieldDeclaration.setModifiers(Arrays.stream(modifiers) + .collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + variable.setType(type); + getMembers().add(fieldDeclaration); + return fieldDeclaration; + } + + /** + * Add a private field to this + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPrivateField(Class<?> typeClass, String name) { + return addField(typeClass, name, Modifier.PRIVATE); + } + + /** + * Add a private field to this and automatically add the import of the type if + * needed + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPrivateField(String type, String name) { + return addField(type, name, Modifier.PRIVATE); + } + + /** + * Add a public field to this + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPublicField(Class<?> typeClass, String name) { + return addField(typeClass, name, Modifier.PUBLIC); + } + + /** + * Add a public field to this and automatically add the import of the type if + * needed + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPublicField(String type, String name) { + return addField(type, name, Modifier.PUBLIC); + } + + /** + * Add a protected field to this + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addProtectedField(Class<?> typeClass, String name) { + return addField(typeClass, name, Modifier.PROTECTED); + } + + /** + * Add a protected field to this and automatically add the import of the type + * if needed + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addProtectedField(String type, String name) { + return addField(type, name, Modifier.PROTECTED); + } + + /** + * Adds a methods with void return by default to this + * + * @param methodName the method name + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link MethodDeclaration} created + */ + default MethodDeclaration addMethod(String methodName, Modifier... modifiers) { + MethodDeclaration methodDeclaration = new MethodDeclaration(); + methodDeclaration.setName(methodName); + methodDeclaration.setType(VOID_TYPE); + methodDeclaration.setModifiers(Arrays.stream(modifiers) + .collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + getMembers().add(methodDeclaration); + methodDeclaration.setParentNode((Node) this); + return methodDeclaration; + } + + /** + * Adds a constructor to this + * + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link MethodDeclaration} created + */ + default ConstructorDeclaration addCtor(Modifier... modifiers) { + ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration(); + constructorDeclaration.setModifiers(Arrays.stream(modifiers) + .collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + constructorDeclaration.setName(((TypeDeclaration<?>) this).getName()); + getMembers().add(constructorDeclaration); + constructorDeclaration.setParentNode((Node) this); + return constructorDeclaration; + } + + default BlockStmt addInitializer() { + BlockStmt block = new BlockStmt(); + InitializerDeclaration initializerDeclaration = new InitializerDeclaration(false, block); + getMembers().add(initializerDeclaration); + initializerDeclaration.setParentNode((Node) this); + return block; + } + + default BlockStmt addStaticInitializer() { + BlockStmt block = new BlockStmt(); + InitializerDeclaration initializerDeclaration = new InitializerDeclaration(true, block); + getMembers().add(initializerDeclaration); + initializerDeclaration.setParentNode((Node) this); + return block; + } + + /** + * Try to find a {@link MethodDeclaration} by its name + * + * @param name the name of the method + * @return the methods found (multiple in case of polymorphism) + */ + default List<MethodDeclaration> getMethodsByName(String name) { + return getMembers().stream() + .filter(m -> m instanceof MethodDeclaration && ((MethodDeclaration) m).getName().equals(name)) + .map(m -> (MethodDeclaration) m).collect(toList()); + } + + /** + * Find all methods in the members of this node. + * + * @return the methods found. This list is immutable. + */ + default List<MethodDeclaration> getMethods() { + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof MethodDeclaration) + .map(m -> (MethodDeclaration) m) + .collect(toList())); + } + + /** + * Try to find a {@link MethodDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match<br> + * void foo(Map<Integer,String> myMap,int number) + * @return the methods found (multiple in case of polymorphism) + */ + default List<MethodDeclaration> getMethodsByParameterTypes(String... paramTypes) { + return getMembers().stream() + .filter(m -> m instanceof MethodDeclaration + && ((MethodDeclaration) m).getParameters().stream().map(p -> p.getType().toString()) + .collect(toSet()).equals(Stream.of(paramTypes).collect(toSet()))) + .map(m -> (MethodDeclaration) m).collect(toList()); + } + + /** + * Try to find a {@link MethodDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match<br> + * void foo(Map<Integer,String> myMap,int number) + * @return the methods found (multiple in case of polymorphism) + */ + default List<MethodDeclaration> getMethodsByParameterTypes(Class<?>... paramTypes) { + return getMembers().stream() + .filter(m -> m instanceof MethodDeclaration + && ((MethodDeclaration) m).getParameters().stream().map(p -> p.getType().toString()) + .collect(toSet()) + .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toSet()))) + .map(m -> (MethodDeclaration) m).collect(toList()); + } + + /** + * Try to find a {@link FieldDeclaration} by its name + * + * @param name the name of the field + * @return null if not found, the FieldDeclaration otherwise + */ + default FieldDeclaration getFieldByName(String name) { + return (FieldDeclaration) getMembers().stream() + .filter(m -> m instanceof FieldDeclaration && ((FieldDeclaration) m).getVariables().stream() + .anyMatch(var -> var.getId().getName().equals(name))) + .findFirst().orElse(null); + } + + /** + * Find all fields in the members of this node. + * + * @return the fields found. This list is immutable. + */ + default List<FieldDeclaration> getFields() { + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof FieldDeclaration ) + .map(m -> (FieldDeclaration) m) + .collect(toList())); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java new file mode 100644 index 000000000..6a1959ecf --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java @@ -0,0 +1,73 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.Modifier; + +/** + * A Node with Modifiers. + */ +public interface NodeWithModifiers<T> { + /** + * Return the modifiers of this variable declaration. + * + * @see Modifier + * @return modifiers + */ + EnumSet<Modifier> getModifiers(); + + T setModifiers(EnumSet<Modifier> modifiers); + + @SuppressWarnings("unchecked") + default T addModifier(Modifier... modifiers) { + getModifiers().addAll(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class)))); + return (T) this; + } + + default boolean isStatic() { + return getModifiers().contains(Modifier.STATIC); + } + + default boolean isAbstract() { + return getModifiers().contains(Modifier.ABSTRACT); + } + + default boolean isFinal() { + return getModifiers().contains(Modifier.FINAL); + } + + default boolean isNative() { + return getModifiers().contains(Modifier.NATIVE); + } + + default boolean isPrivate() { + return getModifiers().contains(Modifier.PRIVATE); + } + + default boolean isProtected() { + return getModifiers().contains(Modifier.PROTECTED); + } + + default boolean isPublic() { + return getModifiers().contains(Modifier.PUBLIC); + } + + default boolean isStrictfp() { + return getModifiers().contains(Modifier.STRICTFP); + } + + default boolean isSynchronized() { + return getModifiers().contains(Modifier.SYNCHRONIZED); + } + + default boolean isTransient() { + return getModifiers().contains(Modifier.TRANSIENT); + } + + default boolean isVolatile() { + return getModifiers().contains(Modifier.VOLATILE); + } +}
\ No newline at end of file diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithName.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithName.java new file mode 100644 index 000000000..edcff5cff --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithName.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +/** + * A node having a name. + * + * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. + * + * @since 2.0.1 + */ +public interface NodeWithName<T> { + String getName(); + + T setName(String name); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java new file mode 100644 index 000000000..fb8697f3c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java @@ -0,0 +1,100 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclaratorId; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; + +public interface NodeWithParameters<T> { + List<Parameter> getParameters(); + + T setParameters(List<Parameter> parameters); + + default T addParameter(Type type, String name) { + return addParameter(new Parameter(type, new VariableDeclaratorId(name))); + } + + default T addParameter(Class<?> paramClass, String name) { + ((Node) this).tryAddImportToParentCompilationUnit(paramClass); + return addParameter(new ClassOrInterfaceType(paramClass.getSimpleName()), name); + } + + /** + * Remember to import the class in the compilation unit yourself + * + * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import + * @param name the name of the parameter + */ + default T addParameter(String className, String name) { + return addParameter(new ClassOrInterfaceType(className), name); + } + + @SuppressWarnings("unchecked") + default T addParameter(Parameter parameter) { + getParameters().add(parameter); + parameter.setParentNode((Node) this); + return (T) this; + } + + default Parameter addAndGetParameter(Type type, String name) { + return addAndGetParameter(new Parameter(type, new VariableDeclaratorId(name))); + } + + default Parameter addAndGetParameter(Class<?> paramClass, String name) { + ((Node) this).tryAddImportToParentCompilationUnit(paramClass); + return addAndGetParameter(new ClassOrInterfaceType(paramClass.getSimpleName()), name); + } + + /** + * Remember to import the class in the compilation unit yourself + * + * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import + * @param name the name of the parameter + * @return the {@link Parameter} created + */ + default Parameter addAndGetParameter(String className, String name) { + return addAndGetParameter(new ClassOrInterfaceType(className), name); + } + + default Parameter addAndGetParameter(Parameter parameter) { + getParameters().add(parameter); + parameter.setParentNode((Node) this); + return parameter; + } + + /** + * Try to find a {@link Parameter} by its name + * + * @param name the name of the param + * @return null if not found, the param found otherwise + */ + default Parameter getParamByName(String name) { + return getParameters().stream() + .filter(p -> p.getName().equals(name)).findFirst().orElse(null); + } + + /** + * Try to find a {@link Parameter} by its type + * + * @param type the type of the param + * @return null if not found, the param found otherwise + */ + default Parameter getParamByType(String type) { + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type)).findFirst().orElse(null); + } + + /** + * Try to find a {@link Parameter} by its type + * + * @param type the type of the param <b>take care about generics, it wont work</b> + * @return null if not found, the param found otherwise + */ + default Parameter getParamByType(Class<?> type) { + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst().orElse(null); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java new file mode 100644 index 000000000..b6c895efb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -0,0 +1,46 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.Statement; + +public interface NodeWithStatements<T> { + public List<Statement> getStmts(); + + public T setStmts(final List<Statement> stmts); + + @SuppressWarnings("unchecked") + public default T addStatement(Statement statement) { + getStmts().add(statement); + statement.setParentNode((Node) this); + return (T) this; + } + + @SuppressWarnings("unchecked") + public default T addStatement(int index, final Statement statement) { + getStmts().add(index, statement); + statement.setParentNode((Node) this); + return (T) this; + } + + public default T addStatement(Expression expr) { + ExpressionStmt statement = new ExpressionStmt(expr); + expr.setParentNode(statement); + return addStatement(statement); + } + + public default T addStatement(String statement) { + return addStatement(new NameExpr(statement)); + } + + public default T addStatement(int index, final Expression expr) { + Statement stmt = new ExpressionStmt(expr); + expr.setParentNode(stmt); + return addStatement(index, stmt); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java new file mode 100644 index 000000000..beee9e727 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java @@ -0,0 +1,57 @@ +package com.github.javaparser.ast.nodeTypes; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.ReferenceType; + +public interface NodeWithThrowable<T> { + T setThrows(List<ReferenceType> throws_); + + List<ReferenceType> getThrows(); + + /** + * Adds this type to the throws clause + * + * @param throwType the exception type + * @return this + */ + @SuppressWarnings("unchecked") + default T addThrows(ReferenceType throwType) { + getThrows().add(throwType); + throwType.setParentNode((Node) this); + return (T) this; + } + + /** + * Adds this class to the throws clause + * + * @param clazz the exception class + * @return this + */ + default T addThrows(Class<? extends Throwable> clazz) { + ((Node) this).tryAddImportToParentCompilationUnit(clazz); + return addThrows(new ClassOrInterfaceType(clazz.getSimpleName())); + } + + /** + * Check whether this elements throws this exception class + * + * @param clazz the class of the exception + * @return true if found in throws clause, false if not + */ + public default boolean isThrows(Class<? extends Throwable> clazz) { + return isThrows(clazz.getSimpleName()); + } + + /** + * Check whether this elements throws this exception class + * + * @param throwableName the class of the exception + * @return true if found in throws clause, false if not + */ + public default boolean isThrows(String throwableName) { + return getThrows().stream().anyMatch(t -> t.toString().equals(throwableName)); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithType.java new file mode 100644 index 000000000..fc183b20b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithType.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; + +/** + * A node having a type. + * + * The main reason for this interface is to permit users to manipulate homogeneously all nodes with getType/setType + * methods + * + * @since 2.3.1 + */ +public interface NodeWithType<T> { + /** + * Gets the type + * + * @return the type + */ + Type<?> getType(); + + /** + * Sets the type + * + * @param type the type + * @return this + */ + T setType(Type<?> type); + + /** + * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed + * + * @param typeClass the type + * @return this + */ + default T setType(Class<?> typeClass) { + ((Node) this).tryAddImportToParentCompilationUnit(typeClass); + return setType(new ClassOrInterfaceType(typeClass.getSimpleName())); + } + + default T setType(final String type) { + ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(type); + return setType(classOrInterfaceType); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java new file mode 100644 index 000000000..3ce27971e --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.type.Type; + +import java.util.*; + +import static com.github.javaparser.utils.Utils.arrayToList; + +/** + * A node that can have type arguments. + * <pre> + * new X(); --> typeArguments == null + * new X<>(); --> typeArguments.types = [], typeArguments.diamondOperator=true + * new X<C,D>(); --> typeArguments.types = [C,D], typeArguments.diamondOperator=false + * </pre> + */ +public interface NodeWithTypeArguments<T> { + /** + * @return the types that can be found in the type arguments: <String, Integer>. + */ + List<Type<?>> getTypeArguments(); + + /** + * Allows you to set the generic arguments + * @param typeArguments The list of types of the generics + */ + T setTypeArguments(List<Type<?>> typeArguments); + + /** + * @return whether the type arguments look like <>. + */ + default boolean isUsingDiamondOperator() { + if(getTypeArguments()==null){ + return false; + } + return getTypeArguments().isEmpty(); + } + + /** + * Sets the type arguments to <>. + */ + default T setDiamondOperator() { + final List<Type<?>> empty = new LinkedList<>(); + setTypeArguments(empty); + return (T) this; + } + + /** + * Removes all type arguments, including the surrounding <>. + */ + default T removeTypeArguments() { + setTypeArguments((List<Type<?>>) null); + return (T) this; + } + + default T setTypeArguments(Type<?>... typeArguments) { + setTypeArguments(arrayToList(typeArguments)); + return (T) this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java new file mode 100644 index 000000000..2c6702ac4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2015 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; + +import java.util.List; + +/** + * A node which has a list of variables. + */ +public interface NodeWithVariables<T> { + List<VariableDeclarator> getVariables(); + + T setVariables(List<VariableDeclarator> variables); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/AssertStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/AssertStmt.java new file mode 100644 index 000000000..85a34a847 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/AssertStmt.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class AssertStmt extends Statement { + + private Expression check; + + private Expression msg; + + public AssertStmt() { + } + + public AssertStmt(final Expression check) { + setCheck(check); + } + + public AssertStmt(final Expression check, final Expression msg) { + setCheck(check); + setMessage(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 = check; + setAsParentNodeOf(this.check); + return this; + } + + public AssertStmt setMessage(final Expression msg) { + this.msg = msg; + setAsParentNodeOf(this.msg); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BlockStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BlockStmt.java new file mode 100644 index 000000000..31cbfa391 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BlockStmt.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.ensureNotNull; + +import java.util.List; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithStatements; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class BlockStmt extends Statement implements NodeWithStatements<BlockStmt> { + + private List<Statement> stmts; + + public BlockStmt() { + } + + public BlockStmt(final List<Statement> stmts) { + setStmts(stmts); + } + + public BlockStmt(final Range range, final List<Statement> stmts) { + super(range); + setStmts(stmts); + } + + @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 List<Statement> getStmts() { + stmts = ensureNotNull(stmts); + return stmts; + } + + @Override + public BlockStmt setStmts(final List<Statement> stmts) { + this.stmts = stmts; + setAsParentNodeOf(this.stmts); + return this; + } + + + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BreakStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BreakStmt.java new file mode 100644 index 000000000..04c39fb9f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/BreakStmt.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class BreakStmt extends Statement { + + private String id; + + public BreakStmt() { + } + + public BreakStmt(final String id) { + 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 <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + public String getId() { + return id; + } + + public BreakStmt setId(final String id) { + this.id = id; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/CatchClause.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/CatchClause.java new file mode 100644 index 000000000..a1f300544 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/CatchClause.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclaratorId; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.EnumSet; +import java.util.List; + +/** + * @author Julio Vilmar Gesser + */ +public final class CatchClause extends Node implements NodeWithBlockStmt<CatchClause> { + + private Parameter param; + + private BlockStmt catchBlock; + + public CatchClause() { + } + + public CatchClause(final Parameter param, final BlockStmt catchBlock) { + setParam(param); + setBody(catchBlock); + } + + public CatchClause(final Range range, + final EnumSet<Modifier> exceptModifier, + final List<AnnotationExpr> exceptAnnotations, + final Type exceptType, + final VariableDeclaratorId exceptId, + final BlockStmt catchBlock) { + super(range); + setParam(new Parameter(range, exceptModifier, exceptAnnotations, exceptType, null, false, exceptId)); + setBody(catchBlock); + } + + @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); + } + + /** + * Use {@link #getBody()} instead + */ + @Deprecated + public BlockStmt getCatchBlock() { + return catchBlock; + } + + /** + * Note that the type of the Parameter can be a UnionType. In this case, any annotations found at the start of the catch(@X A a |...) + * are found directly in the Parameter. Annotations that are on the second or later type - catch(A a | @X B b ...) are found on those types. + */ + public Parameter getParam() { + return param; + } + + /** + * Use {@link #setBody(BlockStmt)} instead + * + * @param catchBlock + */ + @Deprecated + public CatchClause setCatchBlock(final BlockStmt catchBlock) { + this.catchBlock = catchBlock; + setAsParentNodeOf(this.catchBlock); + return this; + } + + public CatchClause setParam(final Parameter param) { + this.param = param; + setAsParentNodeOf(this.param); + return this; + } + + @Override + public BlockStmt getBody() { + return catchBlock; + } + + @Override + public CatchClause setBody(BlockStmt block) { + this.catchBlock = block; + setAsParentNodeOf(this.catchBlock); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ContinueStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ContinueStmt.java new file mode 100644 index 000000000..4ba7faa7b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ContinueStmt.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ContinueStmt extends Statement { + + private String id; + + public ContinueStmt() { + } + + public ContinueStmt(final String id) { + this.id = id; + } + + public ContinueStmt(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 <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + public String getId() { + return id; + } + + public ContinueStmt setId(final String id) { + this.id = id; + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/DoStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/DoStmt.java new file mode 100644 index 000000000..8f293ecab --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/DoStmt.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class DoStmt extends Statement implements NodeWithBody<DoStmt> { + + private Statement body; + + private Expression condition; + + public DoStmt() { + } + + public DoStmt(final Statement body, final Expression condition) { + setBody(body); + setCondition(condition); + } + + public DoStmt(Range range, final Statement body, final Expression condition) { + super(range); + setBody(body); + setCondition(condition); + } + + @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; + } + + public Expression getCondition() { + return condition; + } + + @Override + public DoStmt setBody(final Statement body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + public DoStmt setCondition(final Expression condition) { + this.condition = condition; + setAsParentNodeOf(this.condition); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/EmptyStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/EmptyStmt.java new file mode 100644 index 000000000..00709806d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/EmptyStmt.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class EmptyStmt extends Statement { + + public EmptyStmt() { + } + + public EmptyStmt(Range range) { + super(range); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java new file mode 100644 index 000000000..e29205b84 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ExplicitConstructorInvocationStmt extends Statement implements NodeWithTypeArguments<ExplicitConstructorInvocationStmt> { + + private List<Type<?>> typeArguments; + + private boolean isThis; + + private Expression expr; + + private List<Expression> args; + + public ExplicitConstructorInvocationStmt() { + } + + public ExplicitConstructorInvocationStmt(final boolean isThis, + final Expression expr, final List<Expression> args) { + setThis(isThis); + setExpr(expr); + setArgs(args); + } + + public ExplicitConstructorInvocationStmt(Range range, + final List<Type<?>> typeArguments, final boolean isThis, + final Expression expr, final List<Expression> args) { + super(range); + setTypeArguments(typeArguments); + setThis(isThis); + setExpr(expr); + setArgs(args); + } + + @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 List<Expression> getArgs() { + args = ensureNotNull(args); + return args; + } + + public Expression getExpr() { + return expr; + } + + public boolean isThis() { + return isThis; + } + + public ExplicitConstructorInvocationStmt setArgs(final List<Expression> args) { + this.args = args; + setAsParentNodeOf(this.args); + return this; + } + + public ExplicitConstructorInvocationStmt setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } + + public ExplicitConstructorInvocationStmt setThis(final boolean isThis) { + this.isThis = isThis; + return this; + } + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public ExplicitConstructorInvocationStmt setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExpressionStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExpressionStmt.java new file mode 100644 index 000000000..72d8a2e94 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ExpressionStmt.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ExpressionStmt extends Statement { + + private Expression expr; + + public ExpressionStmt() { + } + + public ExpressionStmt(final Expression expr) { + setExpression(expr); + } + + public ExpressionStmt(Range range, + final Expression expr) { + super(range); + setExpression(expr); + } + + @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 getExpression() { + return expr; + } + + public ExpressionStmt setExpression(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForStmt.java new file mode 100644 index 000000000..52baddb7b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForStmt.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ForStmt extends Statement implements NodeWithBody<ForStmt> { + + private List<Expression> init; + + private Expression compare; + + private List<Expression> update; + + private Statement body; + + public ForStmt() { + } + + public ForStmt(final List<Expression> init, final Expression compare, + final List<Expression> update, final Statement body) { + setCompare(compare); + setInit(init); + setUpdate(update); + setBody(body); + } + + public ForStmt(Range range, + final List<Expression> init, final Expression compare, + final List<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; + } + + public Expression getCompare() { + return compare; + } + + public List<Expression> getInit() { + init = ensureNotNull(init); + return init; + } + + public List<Expression> getUpdate() { + update = ensureNotNull(update); + return update; + } + + @Override + public ForStmt setBody(final Statement body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + public ForStmt setCompare(final Expression compare) { + this.compare = compare; + setAsParentNodeOf(this.compare); + return this; + } + + public ForStmt setInit(final List<Expression> init) { + this.init = init; + setAsParentNodeOf(this.init); + return this; + } + + public ForStmt setUpdate(final List<Expression> update) { + this.update = update; + setAsParentNodeOf(this.update); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForeachStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForeachStmt.java new file mode 100644 index 000000000..3a94572b0 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ForeachStmt.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ForeachStmt extends Statement implements NodeWithBody<ForeachStmt> { + + private VariableDeclarationExpr var; + + private Expression iterable; + + private Statement body; + + public ForeachStmt() { + } + + public ForeachStmt(final VariableDeclarationExpr var, + final Expression iterable, final Statement body) { + setVariable(var); + setIterable(iterable); + setBody(body); + } + + public ForeachStmt(Range range, + final VariableDeclarationExpr var, final Expression iterable, + final Statement body) { + super(range); + setVariable(var); + setIterable(iterable); + setBody(body); + } + + /** + * Will create a {@link NameExpr} with the iterable param + * + * @param var + * @param iterable + * @param body + */ + public ForeachStmt(VariableDeclarationExpr var, String iterable, BlockStmt body) { + setVariable(var); + setIterable(new NameExpr(iterable)); + 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; + } + + public Expression getIterable() { + return iterable; + } + + public VariableDeclarationExpr getVariable() { + return var; + } + + @Override + public ForeachStmt setBody(final Statement body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + public ForeachStmt setIterable(final Expression iterable) { + this.iterable = iterable; + setAsParentNodeOf(this.iterable); + return this; + } + + public ForeachStmt setVariable(final VariableDeclarationExpr var) { + this.var = var; + setAsParentNodeOf(this.var); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/IfStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/IfStmt.java new file mode 100644 index 000000000..ace3ec8a5 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/IfStmt.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class IfStmt extends Statement { + + private Expression condition; + + private Statement thenStmt; + + private Statement elseStmt; + + public IfStmt() { + } + + public IfStmt(final Expression condition, final Statement thenStmt, final Statement elseStmt) { + setCondition(condition); + setThenStmt(thenStmt); + setElseStmt(elseStmt); + } + + public IfStmt(Range range, + final Expression condition, final Statement thenStmt, final Statement elseStmt) { + super(range); + setCondition(condition); + setThenStmt(thenStmt); + setElseStmt(elseStmt); + } + + @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 getCondition() { + return condition; + } + + public Statement getElseStmt() { + return elseStmt; + } + + public Statement getThenStmt() { + return thenStmt; + } + + public IfStmt setCondition(final Expression condition) { + this.condition = condition; + setAsParentNodeOf(this.condition); + return this; + } + + public IfStmt setElseStmt(final Statement elseStmt) { + this.elseStmt = elseStmt; + setAsParentNodeOf(this.elseStmt); + return this; + } + + public IfStmt setThenStmt(final Statement thenStmt) { + this.thenStmt = thenStmt; + setAsParentNodeOf(this.thenStmt); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/LabeledStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/LabeledStmt.java new file mode 100644 index 000000000..ded1ad8d8 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/LabeledStmt.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class LabeledStmt extends Statement { + + private String label; + + private Statement stmt; + + public LabeledStmt() { + } + + public LabeledStmt(final String label, final Statement stmt) { + setLabel(label); + setStmt(stmt); + } + + public LabeledStmt(Range range, final String label, final Statement stmt) { + super(range); + setLabel(label); + setStmt(stmt); + } + + @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 String getLabel() { + return label; + } + + public Statement getStmt() { + return stmt; + } + + public LabeledStmt setLabel(final String label) { + this.label = label; + return this; + } + + public LabeledStmt setStmt(final Statement stmt) { + this.stmt = stmt; + setAsParentNodeOf(this.stmt); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ReturnStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ReturnStmt.java new file mode 100644 index 000000000..6ce31d0bf --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ReturnStmt.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ReturnStmt extends Statement { + + private Expression expr; + + public ReturnStmt() { + } + + public ReturnStmt(final Expression expr) { + setExpr(expr); + } + + public ReturnStmt(Range range, final Expression expr) { + super(range); + setExpr(expr); + } + + /** + * Will create a NameExpr with the string param + * + * @param expr + */ + public ReturnStmt(String expr) { + setExpr(new NameExpr(expr)); + } + + @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 getExpr() { + return expr; + } + + public ReturnStmt setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/Statement.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/Statement.java new file mode 100644 index 000000000..eacfcc416 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/Statement.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class Statement extends Node { + + public Statement() { + } + + public Statement(final Range range) { + super(range); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchEntryStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchEntryStmt.java new file mode 100644 index 000000000..e17e20e94 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchEntryStmt.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +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 java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class SwitchEntryStmt extends Statement implements NodeWithStatements<SwitchEntryStmt> { + + private Expression label; + + private List<Statement> stmts; + + public SwitchEntryStmt() { + } + + public SwitchEntryStmt(final Expression label, final List<Statement> stmts) { + setLabel(label); + setStmts(stmts); + } + + public SwitchEntryStmt(Range range, final Expression label, + final List<Statement> stmts) { + super(range); + setLabel(label); + setStmts(stmts); + } + + @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 getLabel() { + return label; + } + + @Override + public List<Statement> getStmts() { + stmts = ensureNotNull(stmts); + return stmts; + } + + public SwitchEntryStmt setLabel(final Expression label) { + this.label = label; + setAsParentNodeOf(this.label); + return this; + } + + @Override + public SwitchEntryStmt setStmts(final List<Statement> stmts) { + this.stmts = stmts; + setAsParentNodeOf(this.stmts); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchStmt.java new file mode 100644 index 000000000..c909394b2 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SwitchStmt.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.*; + +/** + * @author Julio Vilmar Gesser + */ +public final class SwitchStmt extends Statement { + + private Expression selector; + + private List<SwitchEntryStmt> entries; + + public SwitchStmt() { + } + + public SwitchStmt(final Expression selector, + final List<SwitchEntryStmt> entries) { + setSelector(selector); + setEntries(entries); + } + + public SwitchStmt(Range range, final Expression selector, + final List<SwitchEntryStmt> entries) { + super(range); + setSelector(selector); + setEntries(entries); + } + + @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 List<SwitchEntryStmt> getEntries() { + entries = ensureNotNull(entries); + return entries; + } + + public Expression getSelector() { + return selector; + } + + public SwitchStmt setEntries(final List<SwitchEntryStmt> entries) { + this.entries = entries; + setAsParentNodeOf(this.entries); + return this; + } + + public SwitchStmt setSelector(final Expression selector) { + this.selector = selector; + setAsParentNodeOf(this.selector); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SynchronizedStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SynchronizedStmt.java new file mode 100644 index 000000000..1a9d2db5d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/SynchronizedStmt.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class SynchronizedStmt extends Statement implements NodeWithBlockStmt<SynchronizedStmt> { + + private Expression expr; + + private BlockStmt block; + + public SynchronizedStmt() { + } + + public SynchronizedStmt(final Expression expr, final BlockStmt block) { + setExpr(expr); + setBlock(block); + } + + public SynchronizedStmt(Range range, final Expression expr, + final BlockStmt block) { + super(range); + setExpr(expr); + setBlock(block); + } + + @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); + } + + /** + * @deprecated use {@link #getBody()} + * @return + */ + @Deprecated + public BlockStmt getBlock() { + return block; + } + + public Expression getExpr() { + return expr; + } + + /** + * @deprecated Use {@link #setBody(BlockStmt)} instead + * @param block + */ + @Deprecated + public SynchronizedStmt setBlock(final BlockStmt block) { + this.block = block; + setAsParentNodeOf(this.block); + return this; + } + + public SynchronizedStmt setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } + + @Override + public BlockStmt getBody() { + return block; + } + + @Override + public SynchronizedStmt setBody(BlockStmt block) { + this.block = block; + setAsParentNodeOf(this.block); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ThrowStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ThrowStmt.java new file mode 100644 index 000000000..180fdd04c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/ThrowStmt.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class ThrowStmt extends Statement { + + private Expression expr; + + public ThrowStmt() { + } + + public ThrowStmt(final Expression expr) { + setExpr(expr); + } + + public ThrowStmt(Range range, final Expression expr) { + super(range); + setExpr(expr); + } + + @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 getExpr() { + return expr; + } + + public ThrowStmt setExpr(final Expression expr) { + this.expr = expr; + setAsParentNodeOf(this.expr); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TryStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TryStmt.java new file mode 100644 index 000000000..4688454b4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TryStmt.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.*; + +/** + * @author Julio Vilmar Gesser + */ +public final class TryStmt extends Statement { + + private List<VariableDeclarationExpr> resources; + + private BlockStmt tryBlock; + + private List<CatchClause> catchs; + + private BlockStmt finallyBlock; + + public TryStmt() { + } + + public TryStmt(final BlockStmt tryBlock, final List<CatchClause> catchs, + final BlockStmt finallyBlock) { + setTryBlock(tryBlock); + setCatchs(catchs); + setFinallyBlock(finallyBlock); + } + + public TryStmt(Range range, List<VariableDeclarationExpr> resources, + final BlockStmt tryBlock, final List<CatchClause> catchs, final BlockStmt finallyBlock) { + super(range); + setResources(resources); + setTryBlock(tryBlock); + setCatchs(catchs); + setFinallyBlock(finallyBlock); + } + + @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 List<CatchClause> getCatchs() { + catchs = ensureNotNull(catchs); + return catchs; + } + + public BlockStmt getFinallyBlock() { + return finallyBlock; + } + + public BlockStmt getTryBlock() { + return tryBlock; + } + + public List<VariableDeclarationExpr> getResources() { + resources = ensureNotNull(resources); + return resources; + } + + public TryStmt setCatchs(final List<CatchClause> catchs) { + this.catchs = catchs; + setAsParentNodeOf(this.catchs); + return this; + } + + public TryStmt setFinallyBlock(final BlockStmt finallyBlock) { + this.finallyBlock = finallyBlock; + setAsParentNodeOf(this.finallyBlock); + return this; + } + + public TryStmt setTryBlock(final BlockStmt tryBlock) { + this.tryBlock = tryBlock; + setAsParentNodeOf(this.tryBlock); + return this; + } + + public TryStmt setResources(List<VariableDeclarationExpr> resources) { + this.resources = resources; + setAsParentNodeOf(this.resources); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java new file mode 100644 index 000000000..a9f83bf78 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class TypeDeclarationStmt extends Statement { + + private TypeDeclaration typeDecl; + + public TypeDeclarationStmt() { + } + + public TypeDeclarationStmt(final TypeDeclaration typeDecl) { + setTypeDeclaration(typeDecl); + } + + public TypeDeclarationStmt(Range range, final TypeDeclaration typeDecl) { + super(range); + setTypeDeclaration(typeDecl); + } + + @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 TypeDeclaration getTypeDeclaration() { + return typeDecl; + } + + public TypeDeclarationStmt setTypeDeclaration(final TypeDeclaration typeDecl) { + this.typeDecl = typeDecl; + setAsParentNodeOf(this.typeDecl); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/WhileStmt.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/WhileStmt.java new file mode 100644 index 000000000..b843494a4 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/stmt/WhileStmt.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class WhileStmt extends Statement implements NodeWithBody<WhileStmt> { + + private Expression condition; + + private Statement body; + + public WhileStmt() { + } + + public WhileStmt(final Expression condition, final Statement body) { + setCondition(condition); + setBody(body); + } + + public WhileStmt(Range range, final Expression condition, final Statement body) { + super(range); + setCondition(condition); + 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; + } + + public Expression getCondition() { + return condition; + } + + @Override + public WhileStmt setBody(final Statement body) { + this.body = body; + setAsParentNodeOf(this.body); + return this; + } + + public WhileStmt setCondition(final Expression condition) { + this.condition = condition; + setAsParentNodeOf(this.condition); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ArrayType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ArrayType.java new file mode 100644 index 000000000..babf2a5d7 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ArrayType.java @@ -0,0 +1,86 @@ +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.ArrayBracketPair; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.utils.Pair; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 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)). + */ +public class ArrayType extends ReferenceType<ArrayType> implements NodeWithAnnotations<ArrayType> { + private Type componentType; + + public ArrayType(Type componentType, List<AnnotationExpr> annotations) { + setComponentType(componentType); + setAnnotations(annotations); + } + + public ArrayType(Range range, Type componentType, List<AnnotationExpr> annotations) { + super(range); + setComponentType(componentType); + setAnnotations(annotations); + } + + @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 Type getComponentType() { + return componentType; + } + + public ArrayType setComponentType(final Type type) { + this.componentType = type; + setAsParentNodeOf(this.componentType); + return this; + } + + /** + * Takes lists of arrayBracketPairs, assumes the lists are ordered left to right and the pairs are ordered left to right, mirroring the actual code. + * The type gets wrapped in ArrayTypes so that the outermost ArrayType corresponds to the rightmost ArrayBracketPair. + */ + @SafeVarargs + public static Type wrapInArrayTypes(Type type, List<ArrayBracketPair>... arrayBracketPairLists) { + for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) { + final List<ArrayBracketPair> arrayBracketPairList = arrayBracketPairLists[i]; + if (arrayBracketPairList != null) { + for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) { + type = new ArrayType(type, arrayBracketPairList.get(j).getAnnotations()); + } + } + } + return type; + } + + /** + * Takes a type that may be an ArrayType. Unwraps ArrayTypes until the element type is found. + * + * @return a pair of the element type, and the unwrapped ArrayTypes, if any. + */ + public static Pair<Type, List<ArrayBracketPair>> unwrapArrayTypes(Type type) { + final List<ArrayBracketPair> arrayBracketPairs = new ArrayList<>(); + while (type instanceof ArrayType) { + ArrayType arrayType = (ArrayType) type; + arrayBracketPairs.add(new ArrayBracketPair(Range.UNKNOWN, arrayType.getAnnotations())); + type = arrayType.getComponentType(); + } + return new Pair<>(type, arrayBracketPairs); + } + + public static ArrayType arrayOf(Type type, AnnotationExpr... annotations) { + return new ArrayType(type, Arrays.asList(annotations)); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ClassOrInterfaceType.java new file mode 100644 index 000000000..ac308940d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceType extends ReferenceType<ClassOrInterfaceType> implements + NodeWithName<ClassOrInterfaceType>, + NodeWithAnnotations<ClassOrInterfaceType>, + NodeWithTypeArguments<ClassOrInterfaceType> { + + private ClassOrInterfaceType scope; + + private String name; + + private List<Type<?>> typeArguments; + + public ClassOrInterfaceType() { + } + + public ClassOrInterfaceType(final String name) { + setName(name); + } + + public ClassOrInterfaceType(final ClassOrInterfaceType scope, final String name) { + setScope(scope); + setName(name); + } + + public ClassOrInterfaceType(final Range range, final ClassOrInterfaceType scope, final String name, final List<Type<?>> typeArguments) { + super(range); + setScope(scope); + setName(name); + setTypeArguments(typeArguments); + } + + @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 String getName() { + return name; + } + + public ClassOrInterfaceType getScope() { + return scope; + } + + public boolean isBoxedType() { + return PrimitiveType.unboxMap.containsKey(name); + } + + public PrimitiveType toUnboxedType() throws UnsupportedOperationException { + if (!isBoxedType()) { + throw new UnsupportedOperationException(name + " isn't a boxed type."); + } + return new PrimitiveType(PrimitiveType.unboxMap.get(name)); + } + + @Override + public ClassOrInterfaceType setName(final String name) { + this.name = name; + return this; + } + + public ClassOrInterfaceType setScope(final ClassOrInterfaceType scope) { + this.scope = scope; + setAsParentNodeOf(this.scope); + return this; + } + + @Override + public List<Type<?>> getTypeArguments() { + return typeArguments; + } + + @Override + public ClassOrInterfaceType setTypeArguments(final List<Type<?>> types) { + this.typeArguments = types; + setAsParentNodeOf(this.typeArguments); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/IntersectionType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/IntersectionType.java new file mode 100644 index 000000000..029d46537 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/IntersectionType.java @@ -0,0 +1,60 @@ +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +/** + * Represents a set of types. A given value of this type has to be assignable to at all of the element types. + * As of Java 8 it is used in casts or while expressing bounds for generic types. + * + * For example: + * public class A>T extends Serializable & Cloneable< { } + * + * Or: + * void foo((Serializable & Cloneable)myObject); + * + * @since 3.0.0 + */ +public class IntersectionType extends Type<IntersectionType> implements NodeWithAnnotations<IntersectionType> { + + private List<ReferenceType> elements; + + public IntersectionType(Range range, List<ReferenceType> elements) { + super(range); + setElements(elements); + } + + public IntersectionType(List<ReferenceType> elements) { + super(); + setElements(elements); + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } + + public List<ReferenceType> getElements() { + return elements; + } + + public IntersectionType setElements(List<ReferenceType> elements) { + if (this.elements != null) { + for (ReferenceType element : elements){ + element.setParentNode(null); + } + } + this.elements = elements; + setAsParentNodeOf(this.elements); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/PrimitiveType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/PrimitiveType.java new file mode 100644 index 000000000..29299a425 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/PrimitiveType.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +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.ensureNotNull; + +import java.util.HashMap; + +/** + * @author Julio Vilmar Gesser + */ +public final class PrimitiveType extends Type<PrimitiveType> implements NodeWithAnnotations<PrimitiveType> { + + public static final PrimitiveType BYTE_TYPE = new PrimitiveType(Primitive.Byte); + + public static final PrimitiveType SHORT_TYPE = new PrimitiveType(Primitive.Short); + + public static final PrimitiveType INT_TYPE = new PrimitiveType(Primitive.Int); + + public static final PrimitiveType LONG_TYPE = new PrimitiveType(Primitive.Long); + + public static final PrimitiveType FLOAT_TYPE = new PrimitiveType(Primitive.Float); + + public static final PrimitiveType DOUBLE_TYPE = new PrimitiveType(Primitive.Double); + + public static final PrimitiveType BOOLEAN_TYPE = new PrimitiveType(Primitive.Boolean); + + public static final PrimitiveType CHAR_TYPE = new PrimitiveType(Primitive.Char); + + public enum Primitive { + Boolean ("Boolean"), + Char ("Character"), + Byte ("Byte"), + Short ("Short"), + Int ("Integer"), + Long ("Long"), + Float ("Float"), + Double ("Double"); + + final String nameOfBoxedType; + + public ClassOrInterfaceType toBoxedType() { + return new ClassOrInterfaceType(nameOfBoxedType); + } + + Primitive(String nameOfBoxedType) { + this.nameOfBoxedType = nameOfBoxedType; + } + } + + static final HashMap<String, Primitive> unboxMap = new HashMap<>(); + static { + for(Primitive unboxedType : Primitive.values()) { + unboxMap.put(unboxedType.nameOfBoxedType, unboxedType); + } + } + + private Primitive type; + + public PrimitiveType() { + } + + public PrimitiveType(final Primitive type) { + this.type = type; + } + + public PrimitiveType(Range range, final Primitive type) { + super(range); + setType(type); + } + + @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 Primitive getType() { + return type; + } + + public ClassOrInterfaceType toBoxedType() { + return type.toBoxedType(); + } + + public PrimitiveType setType(final Primitive type) { + this.type = type; + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ReferenceType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ReferenceType.java new file mode 100644 index 000000000..1a4666b4f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/ReferenceType.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class ReferenceType<T extends ReferenceType> extends Type<T> { + + public ReferenceType() { + } + + public ReferenceType(final Range range) { + super(range); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/Type.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/Type.java new file mode 100644 index 000000000..6c043557a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/Type.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.*; + +/** + * @author Julio Vilmar Gesser + */ +public abstract class Type<T extends Type> extends Node { + + private List<AnnotationExpr> annotations; + + public Type() { + } + + public Type(List<AnnotationExpr> annotation){ + this.annotations = annotation; + } + + public Type(Range range) { + super(range); + } + + public Type(Range range, List<AnnotationExpr> annotations) { + super(range); + setAnnotations(annotations); + } + + public List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + public T setAnnotations(List<AnnotationExpr> annotations) { + setAsParentNodeOf(annotations); + this.annotations = annotations; + return (T) this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/TypeParameter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/TypeParameter.java new file mode 100644 index 000000000..bfec9c936 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/TypeParameter.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.ensureNotNull; + +/** + * <p> + * This class represents the declaration of a generics argument. + * </p> + * The TypeParameter is constructed following the syntax:<br> + * <pre> + * {@code + * TypeParameter ::= <IDENTIFIER> ( "extends" }{@link ClassOrInterfaceType}{@code ( "&" }{@link ClassOrInterfaceType}{@code )* )? + * } + * </pre> + * @author Julio Vilmar Gesser + */ +public final class TypeParameter extends ReferenceType<TypeParameter> implements NodeWithName<TypeParameter> { + + private String name; + + private List<AnnotationExpr> annotations; + + private List<ClassOrInterfaceType> typeBound; + + public TypeParameter() { + } + + public TypeParameter(final String name, final List<ClassOrInterfaceType> typeBound) { + setName(name); + setTypeBound(typeBound); + } + + public TypeParameter(Range range, final String name, final List<ClassOrInterfaceType> typeBound) { + super(range); + setName(name); + setTypeBound(typeBound); + } + + public TypeParameter(Range range, String name, List<ClassOrInterfaceType> typeBound, List<AnnotationExpr> annotations) { + this(range, name, typeBound); + setTypeBound(typeBound); + setAnnotations(annotations); + } + + @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); + } + + /** + * Return the name of the paramenter. + * + * @return the name of the paramenter + */ + @Override + public String getName() { + return name; + } + + /** + * Return the list of {@link ClassOrInterfaceType} that this parameter + * extends. Return <code>null</code> null if there are no type. + * + * @return list of types that this paramente extends or <code>null</code> + */ + public List<ClassOrInterfaceType> getTypeBound() { + typeBound = ensureNotNull(typeBound); + return typeBound; + } + + /** + * Sets the name of this type parameter. + * + * @param name + * the name to set + */ + @Override + public TypeParameter setName(final String name) { + this.name = name; + return this; + } + + /** + * Sets the list o types. + * + * @param typeBound + * the typeBound to set + */ + public TypeParameter setTypeBound(final List<ClassOrInterfaceType> typeBound) { + this.typeBound = typeBound; + setAsParentNodeOf(typeBound); + return this; + } + + public List<AnnotationExpr> getAnnotations() { + annotations = ensureNotNull(annotations); + return annotations; + } + + public TypeParameter setAnnotations(List<AnnotationExpr> annotations) { + this.annotations = annotations; + setAsParentNodeOf(this.annotations); + return this; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnionType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnionType.java new file mode 100644 index 000000000..74894af0f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnionType.java @@ -0,0 +1,52 @@ +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +/** + * Represents a set of types. A given value of this type has to be assignable to at least one of the element types. + * As of Java 8 it is only used in catch clauses. + */ +public class UnionType extends Type<UnionType> implements NodeWithAnnotations<UnionType> { + + private List<ReferenceType> elements; + + public UnionType(Range range, List<ReferenceType> elements) { + super(range); + setElements(elements); + } + + public UnionType(List<ReferenceType> elements) { + super(); + setElements(elements); + } + + public List<ReferenceType> getElements() { + return elements; + } + + public UnionType setElements(List<ReferenceType> elements) { + if (this.elements != null) { + for (ReferenceType element : elements){ + element.setParentNode(null); + } + } + this.elements = elements; + setAsParentNodeOf(this.elements); + return this; + } + + @Override + public <R, A> R accept(GenericVisitor<R, A> v, A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(VoidVisitor<A> v, A arg) { + v.visit(this, arg); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnknownType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnknownType.java new file mode 100644 index 000000000..b76c5962c --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/UnknownType.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.List; + +/** + * An unknown parameter type object. It plays the role of a null object for + * lambda parameters that have no explicit type declared. As such, it has no + * lexical representation and hence gets no comment attributed. + * + * @author Didier Villevalois + */ +public final class UnknownType extends Type<UnknownType> { + + public UnknownType() { + } + + @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 List<AnnotationExpr> getAnnotations() { + throw new IllegalStateException("Inferred lambda types cannot be annotated."); + } + + @Override + public UnknownType setAnnotations(List<AnnotationExpr> annotations) { + throw new IllegalStateException("Inferred lambda types cannot be annotated."); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/VoidType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/VoidType.java new file mode 100644 index 000000000..d5f7273cb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/VoidType.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class VoidType extends Type<VoidType> implements NodeWithAnnotations<VoidType> { + + public static final VoidType VOID_TYPE = new VoidType(); + + public VoidType() { + } + + public VoidType(Range range) { + super(range); + } + + @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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/WildcardType.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/WildcardType.java new file mode 100644 index 000000000..d1e49bc0b --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/type/WildcardType.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * @author Julio Vilmar Gesser + */ +public final class WildcardType extends Type<WildcardType> implements NodeWithAnnotations<WildcardType> { + + private ReferenceType ext; + + private ReferenceType sup; + + public WildcardType() { + } + + public WildcardType(final ReferenceType ext) { + setExtends(ext); + } + + public WildcardType(final ReferenceType ext, final ReferenceType sup) { + setExtends(ext); + setSuper(sup); + } + + public WildcardType(final Range range, + final ReferenceType ext, final ReferenceType sup) { + super(range); + setExtends(ext); + setSuper(sup); + } + + @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 ReferenceType getExtends() { + return ext; + } + + public ReferenceType getSuper() { + return sup; + } + + public WildcardType setExtends(final ReferenceType ext) { + this.ext = ext; + setAsParentNodeOf(this.ext); + return this; + } + + public WildcardType setSuper(final ReferenceType sup) { + this.sup = sup; + setAsParentNodeOf(this.sup); + return this; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/CloneVisitor.java new file mode 100644 index 000000000..33ca0e02a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -0,0 +1,1296 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.visitor; + +import java.util.ArrayList; +import java.util.List; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.type.TypeParameter; +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.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.QualifiedNameExpr; +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.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.*; + +public class CloneVisitor implements GenericVisitor<Node, Object> { + + @Override + public Node visit(CompilationUnit _n, Object _arg) { + PackageDeclaration package_ = cloneNodes(_n.getPackage(), _arg); + List<ImportDeclaration> imports = visit(_n.getImports(), _arg); + List<TypeDeclaration<?>> types = visit(_n.getTypes(), _arg); + + return new CompilationUnit( + _n.getRange(), + package_, imports, types + ); + } + + @Override + public Node visit(PackageDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + NameExpr name = cloneNodes(_n.getName(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + PackageDeclaration r = new PackageDeclaration( + _n.getRange(), + annotations, name + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ImportDeclaration _n, Object _arg) { + NameExpr name = cloneNodes(_n.getName(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ImportDeclaration r = new ImportDeclaration( + _n.getRange(), + name, _n.isStatic(), _n.isAsterisk() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(TypeParameter _n, Object _arg) { + List<ClassOrInterfaceType> typeBound = visit(_n.getTypeBound(), _arg); + + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + TypeParameter r = new TypeParameter(_n.getRange(), + _n.getName(), typeBound, annotations); + + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + return r; + } + + @Override + public Node visit(LineComment _n, Object _arg) { + return new LineComment(_n.getRange(), _n.getContent()); + } + + @Override + public Node visit(BlockComment _n, Object _arg) { + return new BlockComment(_n.getRange(), _n.getContent()); + } + + @Override + public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg); + List<ClassOrInterfaceType> extendsList = visit(_n.getExtends(), _arg); + List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg); + List<BodyDeclaration<?>> members = visit(_n.getMembers(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration( + _n.getRange(), + _n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EnumDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg); + List<EnumConstantDeclaration> entries = visit(_n.getEntries(), _arg); + List<BodyDeclaration<?>> members = visit(_n.getMembers(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + EnumDeclaration r = new EnumDeclaration( + _n.getRange(), + _n.getModifiers(), annotations, _n.getName(), implementsList, entries, members + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EmptyTypeDeclaration _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + EmptyTypeDeclaration r = new EmptyTypeDeclaration( + _n.getRange() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EnumConstantDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<Expression> args = visit(_n.getArgs(), _arg); + List<BodyDeclaration<?>> classBody = visit(_n.getClassBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + EnumConstantDeclaration r = new EnumConstantDeclaration( + _n.getRange(), + annotations, _n.getName(), args, classBody + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(AnnotationDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<BodyDeclaration<?>> members = visit(_n.getMembers(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + AnnotationDeclaration r = new AnnotationDeclaration( + _n.getRange(), + _n.getModifiers(), annotations, _n.getName(), members + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(AnnotationMemberDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + Type<?> type_ = cloneNodes(_n.getType(), _arg); + Expression defaultValue = cloneNodes(_n.getDefaultValue(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + AnnotationMemberDeclaration r = new AnnotationMemberDeclaration( + _n.getRange(), + _n.getModifiers(), annotations, type_, _n.getName(), defaultValue + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(FieldDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations_ = visit(_n.getAnnotations(), _arg); + Type<?> elementType_ = cloneNodes(_n.getElementType(), _arg); + List<VariableDeclarator> variables_ = visit(_n.getVariables(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg); + + FieldDeclaration r = new FieldDeclaration( + _n.getRange(), + _n.getModifiers(), + annotations_, + elementType_, + variables_, + arrayBracketPairsAfterType_ + + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(VariableDeclarator _n, Object _arg) { + VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); + Expression init = cloneNodes(_n.getInit(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + VariableDeclarator r = new VariableDeclarator( + _n.getRange(), + id, init + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(VariableDeclaratorId _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterId_ = visit(_n.getArrayBracketPairsAfterId(), _arg); + + VariableDeclaratorId r = new VariableDeclaratorId( + _n.getRange(), + _n.getName(), + arrayBracketPairsAfterId_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ConstructorDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg); + List<Parameter> parameters = visit(_n.getParameters(), _arg); + List<ReferenceType> throws_ = visit(_n.getThrows(), _arg); + BlockStmt block = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ConstructorDeclaration r = new ConstructorDeclaration( + _n.getRange(), + _n.getModifiers(), annotations, typeParameters, _n.getName(), parameters, throws_, block + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(MethodDeclaration _n, Object _arg) { + List<AnnotationExpr> annotations_ = visit(_n.getAnnotations(), _arg); + List<TypeParameter> typeParameters_ = visit(_n.getTypeParameters(), _arg); + Type<?> type_ = cloneNodes(_n.getElementType(), _arg); + NameExpr nameExpr_ = cloneNodes(_n.getNameExpr(), _arg); + List<Parameter> parameters_ = visit(_n.getParameters(), _arg); + List<ReferenceType> throws_ = visit(_n.getThrows(), _arg); + BlockStmt block_ = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterElementType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterParameterList_ = visit(_n.getArrayBracketPairsAfterParameterList(), _arg); + + MethodDeclaration r = new MethodDeclaration( + _n.getRange(), + _n.getModifiers(), + annotations_, + typeParameters_, + type_, + arrayBracketPairsAfterElementType_, + nameExpr_, + parameters_, + arrayBracketPairsAfterParameterList_, + throws_, + block_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(Parameter _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + Type<?> type_ = cloneNodes(_n.getElementType(), _arg); + VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg); + + Parameter r = new Parameter( + _n.getRange(), + _n.getModifiers(), + annotations, + type_, + arrayBracketPairsAfterType_, + _n.isVarArgs(), + id + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EmptyMemberDeclaration _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + EmptyMemberDeclaration r = new EmptyMemberDeclaration( + _n.getRange() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(InitializerDeclaration _n, Object _arg) { + BlockStmt block = cloneNodes(_n.getBlock(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + InitializerDeclaration r = new InitializerDeclaration( + _n.getRange(), + _n.isStatic(), block + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(JavadocComment _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + JavadocComment r = new JavadocComment( + _n.getRange(), + _n.getContent() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ClassOrInterfaceType _n, Object _arg) { + ClassOrInterfaceType scope = cloneNodes(_n.getScope(), _arg); + List<Type<?>> typeArguments_ = visit(_n.getTypeArguments(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ClassOrInterfaceType r = new ClassOrInterfaceType( + _n.getRange(), + scope, + _n.getName(), + _n.getTypeArguments() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(PrimitiveType _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + + PrimitiveType r = new PrimitiveType( + _n.getRange(), + _n.getType() + ); + r.setComment(comment); + r.setAnnotations(annotations); + return r; + } + + @Override + public Node visit(ArrayType _n, Object _arg) { + List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg); + Type<?> type_ = cloneNodes(_n.getComponentType(), _arg); + + ArrayType r = new ArrayType(_n.getRange(), type_, ann); + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ArrayCreationLevel _n, Object _arg) { + List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg); + Expression dimension_ = cloneNodes(_n.getDimension(), _arg); + + ArrayCreationLevel r = new ArrayCreationLevel(_n.getRange(), dimension_, ann); + + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + return r; + } + + @Override + public Node visit(IntersectionType _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<ReferenceType> elements = visit(_n.getElements(), _arg); + + IntersectionType r = new IntersectionType(_n.getRange(), elements); + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + r.setAnnotations(annotations); + return r; + } + + @Override + public Node visit(UnionType _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + List<ReferenceType> elements = visit(_n.getElements(), _arg); + + UnionType r = new UnionType(_n.getRange(), + elements); + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + r.setAnnotations(annotations); + return r; + } + + @Override + public Node visit(VoidType _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + VoidType r = new VoidType(_n.getRange()); + r.setAnnotations(annotations); + r.setComment(comment); + return r; + } + + @Override + public Node visit(WildcardType _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + ReferenceType ext = cloneNodes(_n.getExtends(), _arg); + ReferenceType sup = cloneNodes(_n.getSuper(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + WildcardType r = new WildcardType( + _n.getRange(), + ext, sup + ); + r.setComment(comment); + r.setAnnotations(annotations); + return r; + } + + @Override + public Node visit(UnknownType _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + UnknownType r = new UnknownType(); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ArrayAccessExpr _n, Object _arg) { + Expression name = cloneNodes(_n.getName(), _arg); + Expression index = cloneNodes(_n.getIndex(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ArrayAccessExpr r = new ArrayAccessExpr( + _n.getRange(), + name, index + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ArrayCreationExpr _n, Object _arg) { + Type<?> type_ = cloneNodes(_n.getType(), _arg); + List<ArrayCreationLevel> levels_ = visit(_n.getLevels(), _arg); + ArrayInitializerExpr initializer_ = cloneNodes(_n.getInitializer(), _arg); + + ArrayCreationExpr r = new ArrayCreationExpr(_n.getRange(), type_, levels_, initializer_); + + Comment comment = cloneNodes(_n.getComment(), _arg); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ArrayInitializerExpr _n, Object _arg) { + List<Expression> values = visit(_n.getValues(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ArrayInitializerExpr r = new ArrayInitializerExpr( + _n.getRange(), + values + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(AssignExpr _n, Object _arg) { + Expression target = cloneNodes(_n.getTarget(), _arg); + Expression value = cloneNodes(_n.getValue(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + AssignExpr r = new AssignExpr( + _n.getRange(), + target, value, _n.getOperator()); + r.setComment(comment); + return r; + } + + @Override + public Node visit(BinaryExpr _n, Object _arg) { + Expression left = cloneNodes(_n.getLeft(), _arg); + Expression right = cloneNodes(_n.getRight(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + BinaryExpr r = new BinaryExpr( + _n.getRange(), + left, right, _n.getOperator() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(CastExpr _n, Object _arg) { + Type<?> type_ = cloneNodes(_n.getType(), _arg); + Expression expr = cloneNodes(_n.getExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + CastExpr r = new CastExpr( + _n.getRange(), + type_, expr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ClassExpr _n, Object _arg) { + Type<?> type_ = cloneNodes(_n.getType(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ClassExpr r = new ClassExpr( + _n.getRange(), + type_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ConditionalExpr _n, Object _arg) { + Expression condition = cloneNodes(_n.getCondition(), _arg); + Expression thenExpr = cloneNodes(_n.getThenExpr(), _arg); + Expression elseExpr = cloneNodes(_n.getElseExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ConditionalExpr r = new ConditionalExpr( + _n.getRange(), + condition, thenExpr, elseExpr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EnclosedExpr _n, Object _arg) { + Expression inner = cloneNodes(_n.getInner(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + EnclosedExpr r = new EnclosedExpr( + _n.getRange(), + inner + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(FieldAccessExpr _n, Object _arg) { + Expression scope_ = cloneNodes(_n.getScope(), _arg); + List<Type<?>> typeArguments_ = visit(_n.getTypeArguments(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + FieldAccessExpr r = new FieldAccessExpr( + _n.getRange(), + scope_, + typeArguments_, + _n.getField() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(InstanceOfExpr _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpr(), _arg); + Type<?> type_ = cloneNodes(_n.getType(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + InstanceOfExpr r = new InstanceOfExpr( + _n.getRange(), + expr, type_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(StringLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + StringLiteralExpr r = new StringLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(IntegerLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + IntegerLiteralExpr r = new IntegerLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(LongLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + LongLiteralExpr r = new LongLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(IntegerLiteralMinValueExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + IntegerLiteralMinValueExpr r = new IntegerLiteralMinValueExpr(_n.getRange()); + r.setComment(comment); + return r; + } + + @Override + public Node visit(LongLiteralMinValueExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + LongLiteralMinValueExpr r = new LongLiteralMinValueExpr(_n.getRange()); + r.setComment(comment); + return r; + } + + @Override + public Node visit(CharLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + CharLiteralExpr r = new CharLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(DoubleLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + DoubleLiteralExpr r = new DoubleLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(BooleanLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + BooleanLiteralExpr r = new BooleanLiteralExpr( + _n.getRange(), + _n.getValue() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(NullLiteralExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + NullLiteralExpr r = new NullLiteralExpr(_n.getRange()); + r.setComment(comment); + return r; + } + + @Override + public Node visit(MethodCallExpr _n, Object _arg) { + Expression scope_ = cloneNodes(_n.getScope(), _arg); + List<Type<?>> typeArguments_ = visit(_n.getTypeArguments(), _arg); + List<Expression> args_ = visit(_n.getArgs(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + MethodCallExpr r = new MethodCallExpr( + _n.getRange(), + scope_, + typeArguments_, + _n.getName(), + args_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(NameExpr _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + NameExpr r = new NameExpr( + _n.getRange(), + _n.getName() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ObjectCreationExpr _n, Object _arg) { + Expression scope = cloneNodes(_n.getScope(), _arg); + ClassOrInterfaceType type_ = cloneNodes(_n.getType(), _arg); + List<Type<?>> typeArgs = visit(_n.getTypeArguments(), _arg); + List<Expression> args = visit(_n.getArgs(), _arg); + List<BodyDeclaration<?>> anonymousBody = visit(_n.getAnonymousClassBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ObjectCreationExpr r = new ObjectCreationExpr( + _n.getRange(), + scope, type_, typeArgs, args, anonymousBody + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(QualifiedNameExpr _n, Object _arg) { + NameExpr scope = cloneNodes(_n.getQualifier(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + QualifiedNameExpr r = new QualifiedNameExpr( + _n.getRange(), + scope, _n.getName() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ThisExpr _n, Object _arg) { + Expression classExpr = cloneNodes(_n.getClassExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ThisExpr r = new ThisExpr( + _n.getRange(), + classExpr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(SuperExpr _n, Object _arg) { + Expression classExpr = cloneNodes(_n.getClassExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + SuperExpr r = new SuperExpr( + _n.getRange(), + classExpr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(UnaryExpr _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + UnaryExpr r = new UnaryExpr( + _n.getRange(), + expr, _n.getOperator() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(VariableDeclarationExpr _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + Type<?> type_ = cloneNodes(_n.getElementType(), _arg); + List<VariableDeclarator> vars = visit(_n.getVariables(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + List<ArrayBracketPair> arrayBracketPairsAfterType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg); + + VariableDeclarationExpr r = new VariableDeclarationExpr( + _n.getRange(), + _n.getModifiers(), + annotations, + type_, + vars, + arrayBracketPairsAfterType_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(MarkerAnnotationExpr _n, Object _arg) { + NameExpr name = cloneNodes(_n.getName(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + MarkerAnnotationExpr r = new MarkerAnnotationExpr( + _n.getRange(), + name + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(SingleMemberAnnotationExpr _n, Object _arg) { + NameExpr name = cloneNodes(_n.getName(), _arg); + Expression memberValue = cloneNodes(_n.getMemberValue(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + SingleMemberAnnotationExpr r = new SingleMemberAnnotationExpr( + _n.getRange(), + name, memberValue + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(NormalAnnotationExpr _n, Object _arg) { + NameExpr name = cloneNodes(_n.getName(), _arg); + List<MemberValuePair> pairs = visit(_n.getPairs(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + NormalAnnotationExpr r = new NormalAnnotationExpr( + _n.getRange(), + name, pairs + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(MemberValuePair _n, Object _arg) { + Expression value = cloneNodes(_n.getValue(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + MemberValuePair r = new MemberValuePair( + _n.getRange(), + _n.getName(), value + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ExplicitConstructorInvocationStmt _n, Object _arg) { + List<Type<?>> typeArguments_ = visit(_n.getTypeArguments(), _arg); + Expression expr_ = cloneNodes(_n.getExpr(), _arg); + List<Expression> args_ = visit(_n.getArgs(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt( + _n.getRange(), + typeArguments_, + _n.isThis(), + expr_, + args_ + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(TypeDeclarationStmt _n, Object _arg) { + TypeDeclaration<?> typeDecl = cloneNodes(_n.getTypeDeclaration(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + TypeDeclarationStmt r = new TypeDeclarationStmt( + _n.getRange(), + typeDecl + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(AssertStmt _n, Object _arg) { + Expression check = cloneNodes(_n.getCheck(), _arg); + Expression message = cloneNodes(_n.getMessage(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + AssertStmt r = new AssertStmt( + _n.getRange(), + check, message + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(BlockStmt _n, Object _arg) { + List<Statement> stmts = visit(_n.getStmts(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + BlockStmt r = new BlockStmt( + _n.getRange(), + stmts + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(LabeledStmt _n, Object _arg) { + Statement stmt = cloneNodes(_n.getStmt(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + LabeledStmt r = new LabeledStmt( + _n.getRange(), + _n.getLabel(), stmt + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(EmptyStmt _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + EmptyStmt r = new EmptyStmt(_n.getRange()); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ExpressionStmt _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpression(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ExpressionStmt r = new ExpressionStmt( + _n.getRange(), + expr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(SwitchStmt _n, Object _arg) { + Expression selector = cloneNodes(_n.getSelector(), _arg); + List<SwitchEntryStmt> entries = visit(_n.getEntries(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + SwitchStmt r = new SwitchStmt( + _n.getRange(), + selector, entries + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(SwitchEntryStmt _n, Object _arg) { + Expression label = cloneNodes(_n.getLabel(), _arg); + List<Statement> stmts = visit(_n.getStmts(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + SwitchEntryStmt r = new SwitchEntryStmt( + _n.getRange(), + label, stmts + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(BreakStmt _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + BreakStmt r = new BreakStmt( + _n.getRange(), + _n.getId() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ReturnStmt _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ReturnStmt r = new ReturnStmt( + _n.getRange(), + expr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(IfStmt _n, Object _arg) { + Expression condition = cloneNodes(_n.getCondition(), _arg); + Statement thenStmt = cloneNodes(_n.getThenStmt(), _arg); + Statement elseStmt = cloneNodes(_n.getElseStmt(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + IfStmt r = new IfStmt( + _n.getRange(), + condition, thenStmt, elseStmt + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(WhileStmt _n, Object _arg) { + Expression condition = cloneNodes(_n.getCondition(), _arg); + Statement body = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + WhileStmt r = new WhileStmt( + _n.getRange(), + condition, body + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ContinueStmt _n, Object _arg) { + Comment comment = cloneNodes(_n.getComment(), _arg); + + ContinueStmt r = new ContinueStmt( + _n.getRange(), + _n.getId() + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(DoStmt _n, Object _arg) { + Statement body = cloneNodes(_n.getBody(), _arg); + Expression condition = cloneNodes(_n.getCondition(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + DoStmt r = new DoStmt( + _n.getRange(), + body, condition + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ForeachStmt _n, Object _arg) { + VariableDeclarationExpr var = cloneNodes(_n.getVariable(), _arg); + Expression iterable = cloneNodes(_n.getIterable(), _arg); + Statement body = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ForeachStmt r = new ForeachStmt( + _n.getRange(), + var, iterable, body + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ForStmt _n, Object _arg) { + List<Expression> init = visit(_n.getInit(), _arg); + Expression compare = cloneNodes(_n.getCompare(), _arg); + List<Expression> update = visit(_n.getUpdate(), _arg); + Statement body = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ForStmt r = new ForStmt( + _n.getRange(), + init, compare, update, body + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(ThrowStmt _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpr(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + ThrowStmt r = new ThrowStmt( + _n.getRange(), + expr + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(SynchronizedStmt _n, Object _arg) { + Expression expr = cloneNodes(_n.getExpr(), _arg); + BlockStmt block = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + SynchronizedStmt r = new SynchronizedStmt( + _n.getRange(), + expr, block + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(TryStmt _n, Object _arg) { + List<VariableDeclarationExpr> resources = visit(_n.getResources(),_arg); + BlockStmt tryBlock = cloneNodes(_n.getTryBlock(), _arg); + List<CatchClause> catchs = visit(_n.getCatchs(), _arg); + BlockStmt finallyBlock = cloneNodes(_n.getFinallyBlock(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + TryStmt r = new TryStmt( + _n.getRange(), + resources, tryBlock, catchs, finallyBlock + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(CatchClause _n, Object _arg) { + Parameter param = cloneNodes(_n.getParam(), _arg); + BlockStmt catchBlock = cloneNodes(_n.getBody(), _arg); + Comment comment = cloneNodes(_n.getComment(), _arg); + + CatchClause r = new CatchClause( + _n.getRange(), + param.getModifiers(), param.getAnnotations(), param.getElementType(), param.getId(), catchBlock + ); + r.setComment(comment); + return r; + } + + @Override + public Node visit(LambdaExpr _n, Object _arg) { + + List<Parameter> lambdaParameters = visit(_n.getParameters(), _arg); + + Statement body = cloneNodes(_n.getBody(), _arg); + + return new LambdaExpr(_n.getRange(), lambdaParameters, body, + _n.isParametersEnclosed()); + } + + @Override + public Node visit(MethodReferenceExpr _n, Object arg) { + + Expression scope = cloneNodes(_n.getScope(), arg); + + return new MethodReferenceExpr(_n.getRange(), scope, + _n.getTypeArguments(), _n.getIdentifier()); + } + + @Override + public Node visit(TypeExpr n, Object arg) { + + Type<?> t = cloneNodes(n.getType(), arg); + + return new TypeExpr(n.getRange(), t); + } + + @Override + public Node visit(ArrayBracketPair _n, Object _arg) { + List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); + + return new ArrayBracketPair(_n.getRange(), annotations); + } + + public <T extends Node> List<T> visit(List<T> _nodes, Object _arg) { + if (_nodes == null) + return null; + List<T> r = new ArrayList<>(_nodes.size()); + for (T n : _nodes) { + T rN = cloneNodes(n, _arg); + if (rN != null) + r.add(rN); + } + return r; + } + + @SuppressWarnings("unchecked") + protected <T extends Node> T cloneNodes(T _node, Object _arg) { + if (_node == null) + return null; + Node r = _node.accept(this, _arg); + if (r == null) + return null; + return (T) r; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/DumpVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/DumpVisitor.java new file mode 100644 index 000000000..569f39516 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/DumpVisitor.java @@ -0,0 +1,1644 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.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.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; + +import java.util.EnumSet; +import java.util.Iterator; +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.EOL; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; + +/** + * Dumps the AST to formatted Java source code. + * + * @author Julio Vilmar Gesser + */ +public class DumpVisitor implements VoidVisitor<Object> { + + private boolean printComments; + + public DumpVisitor() { + this(true); + } + + public DumpVisitor(boolean printComments) { + this.printComments = printComments; + } + + public static class SourcePrinter { + + private final String indentation; + + public SourcePrinter(final String indentation) { + this.indentation = indentation; + } + + private int level = 0; + + private boolean indented = false; + + private final StringBuilder buf = new StringBuilder(); + + public void indent() { + level++; + } + + public void unindent() { + level--; + } + + private void makeIndent() { + for (int i = 0; i < level; i++) { + buf.append(indentation); + } + } + + public void print(final String arg) { + if (!indented) { + makeIndent(); + indented = true; + } + buf.append(arg); + } + + public void printLn(final String arg) { + print(arg); + printLn(); + } + + public void printLn() { + buf.append(EOL); + indented = false; + } + + public String getSource() { + return buf.toString(); + } + + @Override + public String toString() { + return getSource(); + } + } + + private final SourcePrinter printer = createSourcePrinter(); + + protected SourcePrinter createSourcePrinter() { + return new SourcePrinter(" "); + } + + public String getSource() { + return printer.getSource(); + } + + private void printModifiers(final EnumSet<Modifier> modifiers) { + if (modifiers.size() > 0) + printer.print(modifiers.stream().map(Modifier::getLib).collect(Collectors.joining(" ")) + " "); + } + + private void printMembers(final List<BodyDeclaration<?>> members, final Object arg) { + for (final BodyDeclaration<?> member : members) { + printer.printLn(); + member.accept(this, arg); + printer.printLn(); + } + } + + private void printMemberAnnotations(final List<AnnotationExpr> annotations, final Object arg) { + if (!isNullOrEmpty(annotations)) { + for (final AnnotationExpr a : annotations) { + a.accept(this, arg); + printer.printLn(); + } + } + } + + private void printAnnotations(final List<AnnotationExpr> annotations, boolean prefixWithASpace, final Object arg) { + if (!isNullOrEmpty(annotations)) { + if(prefixWithASpace){ + printer.print(" "); + } + for (AnnotationExpr annotation : annotations) { + annotation.accept(this, arg); + printer.print(" "); + } + } + } + + private void printTypeArgs(final NodeWithTypeArguments<?> nodeWithTypeArguments, final Object arg) { + List<Type<?>> typeArguments = nodeWithTypeArguments.getTypeArguments(); + if (!isNullOrEmpty(typeArguments)) { + printer.print("<"); + for (final Iterator<Type<?>> i = typeArguments.iterator(); i.hasNext(); ) { + final Type<?> t = i.next(); + t.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(">"); + } + } + + private void printTypeParameters(final List<TypeParameter> args, final Object arg) { + if (!isNullOrEmpty(args)) { + printer.print("<"); + for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) { + final TypeParameter t = i.next(); + t.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(">"); + } + } + + private void printArguments(final List<Expression> args, final Object arg) { + printer.print("("); + if (!isNullOrEmpty(args)) { + for (final Iterator<Expression> i = args.iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + } + + private void printJavaComment(final Comment javacomment, final Object arg) { + if (javacomment != null) { + javacomment.accept(this, arg); + } + } + + @Override + public void visit(final CompilationUnit n, final Object arg) { + printJavaComment(n.getComment(), arg); + + if (n.getPackage() != null) { + n.getPackage().accept(this, arg); + } + + if (!isNullOrEmpty(n.getImports())) { + for (final ImportDeclaration i : n.getImports()) { + i.accept(this, arg); + } + printer.printLn(); + } + + if (!isNullOrEmpty(n.getTypes())) { + for (final Iterator<TypeDeclaration<?>> i = n.getTypes().iterator(); i.hasNext(); ) { + i.next().accept(this, arg); + printer.printLn(); + if (i.hasNext()) { + printer.printLn(); + } + } + } + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final PackageDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("package "); + n.getName().accept(this, arg); + printer.printLn(";"); + printer.printLn(); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final NameExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getName()); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final QualifiedNameExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getQualifier().accept(this, arg); + printer.print("."); + printer.print(n.getName()); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final ImportDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (!n.isEmptyImportDeclaration()) { + printer.print("import "); + if (n.isStatic()) { + printer.print("static "); + } + n.getName().accept(this, arg); + if (n.isAsterisk()) { + printer.print(".*"); + } + } + printer.printLn(";"); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final ClassOrInterfaceDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + if (n.isInterface()) { + printer.print("interface "); + } else { + printer.print("class "); + } + + printer.print(n.getName()); + + printTypeParameters(n.getTypeParameters(), arg); + + if (!isNullOrEmpty(n.getExtends())) { + printer.print(" extends "); + for (final Iterator<ClassOrInterfaceType> i = n.getExtends().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + if (!isNullOrEmpty(n.getImplements())) { + printer.print(" implements "); + for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + printer.printLn(" {"); + printer.indent(); + if (!isNullOrEmpty(n.getMembers())) { + printMembers(n.getMembers(), arg); + } + + printOrphanCommentsEnding(n); + + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final EmptyTypeDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(";"); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final JavadocComment n, final Object arg) { + printer.print("/**"); + printer.print(n.getContent()); + printer.printLn("*/"); + } + + @Override + public void visit(final ClassOrInterfaceType n, final Object arg) { + printJavaComment(n.getComment(), arg); + + if (n.getScope() != null) { + n.getScope().accept(this, arg); + printer.print("."); + } + for (AnnotationExpr ae : n.getAnnotations()) { + ae.accept(this, arg); + printer.print(" "); + } + + printer.print(n.getName()); + + if (n.isUsingDiamondOperator()) { + printer.print("<>"); + } else { + printTypeArgs(n, arg); + } + } + + @Override + public void visit(final TypeParameter n, final Object arg) { + printJavaComment(n.getComment(), arg); + for (AnnotationExpr ann : n.getAnnotations()) { + ann.accept(this, arg); + printer.print(" "); + } + printer.print(n.getName()); + if (!isNullOrEmpty(n.getTypeBound())) { + printer.print(" extends "); + for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(" & "); + } + } + } + } + + @Override + public void visit(final PrimitiveType n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), true, arg); + switch (n.getType()) { + case Boolean: + printer.print("boolean"); + break; + case Byte: + printer.print("byte"); + break; + case Char: + printer.print("char"); + break; + case Double: + printer.print("double"); + break; + case Float: + printer.print("float"); + break; + case Int: + printer.print("int"); + break; + case Long: + printer.print("long"); + break; + case Short: + printer.print("short"); + break; + } + } + + @Override + public void visit(final ArrayType n, final Object arg) { + final List<ArrayType> arrayTypeBuffer = new LinkedList<>(); + Type type = n; + while (type instanceof ArrayType) { + final ArrayType arrayType = (ArrayType) type; + arrayTypeBuffer.add(arrayType); + type = arrayType.getComponentType(); + } + + type.accept(this, arg); + for (ArrayType arrayType : arrayTypeBuffer) { + printAnnotations(arrayType.getAnnotations(), true, arg); + printer.print("[]"); + } + } + + @Override + public void visit(final ArrayCreationLevel n, final Object arg) { + printAnnotations(n.getAnnotations(), true, arg); + printer.print("["); + if (n.getDimension() != null) { + n.getDimension().accept(this, arg); + } + printer.print("]"); + } + + @Override + public void visit(final IntersectionType n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + boolean isFirst = true; + for (ReferenceType element : n.getElements()) { + element.accept(this, arg); + if (isFirst) { + isFirst = false; + } else { + printer.print(" & "); + } + } + } + + @Override public void visit(final UnionType n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), true, arg); + boolean isFirst = true; + for (ReferenceType element : n.getElements()) { + if (isFirst) { + isFirst = false; + } else { + printer.print(" | "); + } + element.accept(this, arg); + } + } + + + @Override + public void visit(final WildcardType n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("?"); + if (n.getExtends() != null) { + printer.print(" extends "); + n.getExtends().accept(this, arg); + } + if (n.getSuper() != null) { + printer.print(" super "); + n.getSuper().accept(this, arg); + } + } + + @Override + public void visit(final UnknownType n, final Object arg) { + // Nothing to dump + } + + @Override + public void visit(final FieldDeclaration n, final Object arg) { + printOrphanCommentsBeforeThisChildNode(n); + + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + n.getElementType().accept(this, arg); + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterElementType()){ + pair.accept(this, arg); + } + + printer.print(" "); + for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) { + final VariableDeclarator var = i.next(); + var.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + + printer.print(";"); + } + + @Override + public void visit(final VariableDeclarator n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getId().accept(this, arg); + if (n.getInit() != null) { + printer.print(" = "); + n.getInit().accept(this, arg); + } + } + + @Override + public void visit(final VariableDeclaratorId n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getName()); + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterId()){ + pair.accept(this, arg); + } + } + + @Override + public void visit(final ArrayInitializerExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("{"); + if (!isNullOrEmpty(n.getValues())) { + printer.print(" "); + for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) { + final Expression expr = i.next(); + expr.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(" "); + } + printer.print("}"); + } + + @Override + public void visit(final VoidType n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("void"); + } + + @Override + public void visit(final ArrayAccessExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getName().accept(this, arg); + printer.print("["); + n.getIndex().accept(this, arg); + printer.print("]"); + } + + @Override + public void visit(final ArrayCreationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("new "); + n.getType().accept(this, arg); + for (ArrayCreationLevel level : n.getLevels()) { + level.accept(this, arg); + } + if (n.getInitializer() != null) { + printer.print(" "); + n.getInitializer().accept(this, arg); + } + } + + @Override + public void visit(final AssignExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getTarget().accept(this, arg); + printer.print(" "); + switch (n.getOperator()) { + case assign: + printer.print("="); + break; + case and: + printer.print("&="); + break; + case or: + printer.print("|="); + break; + case xor: + printer.print("^="); + break; + case plus: + printer.print("+="); + break; + case minus: + printer.print("-="); + break; + case rem: + printer.print("%="); + break; + case slash: + printer.print("/="); + break; + case star: + printer.print("*="); + break; + case lShift: + printer.print("<<="); + break; + case rSignedShift: + printer.print(">>="); + break; + case rUnsignedShift: + printer.print(">>>="); + break; + } + printer.print(" "); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final BinaryExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getLeft().accept(this, arg); + printer.print(" "); + switch (n.getOperator()) { + case or: + printer.print("||"); + break; + case and: + printer.print("&&"); + break; + case binOr: + printer.print("|"); + break; + case binAnd: + printer.print("&"); + break; + case xor: + printer.print("^"); + break; + case equals: + printer.print("=="); + break; + case notEquals: + printer.print("!="); + break; + case less: + printer.print("<"); + break; + case greater: + printer.print(">"); + break; + case lessEquals: + printer.print("<="); + break; + case greaterEquals: + printer.print(">="); + break; + case lShift: + printer.print("<<"); + break; + case rSignedShift: + printer.print(">>"); + break; + case rUnsignedShift: + printer.print(">>>"); + break; + case plus: + printer.print("+"); + break; + case minus: + printer.print("-"); + break; + case times: + printer.print("*"); + break; + case divide: + printer.print("/"); + break; + case remainder: + printer.print("%"); + break; + } + printer.print(" "); + n.getRight().accept(this, arg); + } + + @Override + public void visit(final CastExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("("); + n.getType().accept(this, arg); + printer.print(") "); + n.getExpr().accept(this, arg); + } + + @Override + public void visit(final ClassExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getType().accept(this, arg); + printer.print(".class"); + } + + @Override + public void visit(final ConditionalExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getCondition().accept(this, arg); + printer.print(" ? "); + n.getThenExpr().accept(this, arg); + printer.print(" : "); + n.getElseExpr().accept(this, arg); + } + + @Override + public void visit(final EnclosedExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("("); + if (n.getInner() != null) { + n.getInner().accept(this, arg); + } + printer.print(")"); + } + + @Override + public void visit(final FieldAccessExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getScope().accept(this, arg); + printer.print("."); + printer.print(n.getField()); + } + + @Override + public void visit(final InstanceOfExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getExpr().accept(this, arg); + printer.print(" instanceof "); + n.getType().accept(this, arg); + } + + @Override + public void visit(final CharLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("'"); + printer.print(n.getValue()); + printer.print("'"); + } + + @Override + public void visit(final DoubleLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final IntegerLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final LongLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final IntegerLiteralMinValueExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final LongLiteralMinValueExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final StringLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("\""); + printer.print(n.getValue()); + printer.print("\""); + } + + @Override + public void visit(final BooleanLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(String.valueOf(n.getValue())); + } + + @Override + public void visit(final NullLiteralExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("null"); + } + + @Override + public void visit(final ThisExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getClassExpr() != null) { + n.getClassExpr().accept(this, arg); + printer.print("."); + } + printer.print("this"); + } + + @Override + public void visit(final SuperExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getClassExpr() != null) { + n.getClassExpr().accept(this, arg); + printer.print("."); + } + printer.print("super"); + } + + @Override + public void visit(final MethodCallExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getScope() != null) { + n.getScope().accept(this, arg); + printer.print("."); + } + printTypeArgs(n, arg); + printer.print(n.getName()); + printArguments(n.getArgs(), arg); + } + + @Override + public void visit(final ObjectCreationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getScope() != null) { + n.getScope().accept(this, arg); + printer.print("."); + } + + printer.print("new "); + + printTypeArgs(n, arg); + if (!isNullOrEmpty(n.getTypeArguments())) { + printer.print(" "); + } + + n.getType().accept(this, arg); + + printArguments(n.getArgs(), arg); + + if (n.getAnonymousClassBody() != null) { + printer.printLn(" {"); + printer.indent(); + printMembers(n.getAnonymousClassBody(), arg); + printer.unindent(); + printer.print("}"); + } + } + + @Override + public void visit(final UnaryExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + switch (n.getOperator()) { + case positive: + printer.print("+"); + break; + case negative: + printer.print("-"); + break; + case inverse: + printer.print("~"); + break; + case not: + printer.print("!"); + break; + case preIncrement: + printer.print("++"); + break; + case preDecrement: + printer.print("--"); + break; + default: + } + + n.getExpr().accept(this, arg); + + switch (n.getOperator()) { + case posIncrement: + printer.print("++"); + break; + case posDecrement: + printer.print("--"); + break; + default: + } + } + + @Override + public void visit(final ConstructorDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printTypeParameters(n.getTypeParameters(), arg); + if (!n.getTypeParameters().isEmpty()) { + printer.print(" "); + } + printer.print(n.getName()); + + printer.print("("); + if (!n.getParameters().isEmpty()) { + for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { + final Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + + if (!isNullOrEmpty(n.getThrows())) { + printer.print(" throws "); + for (final Iterator<ReferenceType> i = n.getThrows().iterator(); i.hasNext(); ) { + final ReferenceType name = i.next(); + name.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(" "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final MethodDeclaration n, final Object arg) { + printOrphanCommentsBeforeThisChildNode(n); + + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + if (n.isDefault()) { + printer.print("default "); + } + printTypeParameters(n.getTypeParameters(), arg); + if (!isNullOrEmpty(n.getTypeParameters())) { + printer.print(" "); + } + + n.getElementType().accept(this, arg); + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterElementType()){ + pair.accept(this, arg); + } + printer.print(" "); + printer.print(n.getName()); + + printer.print("("); + if (!isNullOrEmpty(n.getParameters())) { + for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { + final Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterParameterList()){ + pair.accept(this, arg); + } + + if (!isNullOrEmpty(n.getThrows())) { + printer.print(" throws "); + for (final Iterator<ReferenceType> i = n.getThrows().iterator(); i.hasNext(); ) { + final ReferenceType name = i.next(); + name.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + if (n.getBody() == null) { + printer.print(";"); + } else { + printer.print(" "); + n.getBody().accept(this, arg); + } + } + + @Override + public void visit(final Parameter n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printModifiers(n.getModifiers()); + if (n.getElementType() != null) { + n.getElementType().accept(this, arg); + } + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterElementType()){ + pair.accept(this, arg); + } + if (n.isVarArgs()) { + printer.print("..."); + } + printer.print(" "); + n.getId().accept(this, arg); + } + + @Override + public void visit(final ExplicitConstructorInvocationStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.isThis()) { + printTypeArgs(n, arg); + printer.print("this"); + } else { + if (n.getExpr() != null) { + n.getExpr().accept(this, arg); + printer.print("."); + } + printTypeArgs(n, arg); + printer.print("super"); + } + printArguments(n.getArgs(), arg); + printer.print(";"); + } + + @Override + public void visit(final VariableDeclarationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printModifiers(n.getModifiers()); + + n.getElementType().accept(this, arg); + for(ArrayBracketPair pair: n.getArrayBracketPairsAfterElementType()){ + pair.accept(this, arg); + } + printer.print(" "); + + for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) { + final VariableDeclarator v = i.next(); + v.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + @Override + public void visit(final TypeDeclarationStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + n.getTypeDeclaration().accept(this, arg); + } + + @Override + public void visit(final AssertStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("assert "); + n.getCheck().accept(this, arg); + if (n.getMessage() != null) { + printer.print(" : "); + n.getMessage().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final BlockStmt n, final Object arg) { + printOrphanCommentsBeforeThisChildNode(n); + printJavaComment(n.getComment(), arg); + printer.printLn("{"); + if (n.getStmts() != null) { + printer.indent(); + for (final Statement s : n.getStmts()) { + s.accept(this, arg); + printer.printLn(); + } + printer.unindent(); + } + printOrphanCommentsEnding(n); + printer.print("}"); + + } + + @Override + public void visit(final LabeledStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getLabel()); + printer.print(": "); + n.getStmt().accept(this, arg); + } + + @Override + public void visit(final EmptyStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(";"); + } + + @Override + public void visit(final ExpressionStmt n, final Object arg) { + printOrphanCommentsBeforeThisChildNode(n); + printJavaComment(n.getComment(), arg); + n.getExpression().accept(this, arg); + printer.print(";"); + } + + @Override + public void visit(final SwitchStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("switch("); + n.getSelector().accept(this, arg); + printer.printLn(") {"); + if (n.getEntries() != null) { + printer.indent(); + for (final SwitchEntryStmt e : n.getEntries()) { + e.accept(this, arg); + } + printer.unindent(); + } + printer.print("}"); + + } + + @Override + public void visit(final SwitchEntryStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getLabel() != null) { + printer.print("case "); + n.getLabel().accept(this, arg); + printer.print(":"); + } else { + printer.print("default:"); + } + printer.printLn(); + printer.indent(); + if (n.getStmts() != null) { + for (final Statement s : n.getStmts()) { + s.accept(this, arg); + printer.printLn(); + } + } + printer.unindent(); + } + + @Override + public void visit(final BreakStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("break"); + if (n.getId() != null) { + printer.print(" "); + printer.print(n.getId()); + } + printer.print(";"); + } + + @Override + public void visit(final ReturnStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("return"); + if (n.getExpr() != null) { + printer.print(" "); + n.getExpr().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final EnumDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printer.print("enum "); + printer.print(n.getName()); + + if (!n.getImplements().isEmpty()) { + printer.print(" implements "); + for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + printer.printLn(" {"); + printer.indent(); + if (n.getEntries() != null) { + printer.printLn(); + for (final Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext(); ) { + final EnumConstantDeclaration e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + if (!n.getMembers().isEmpty()) { + printer.printLn(";"); + printMembers(n.getMembers(), arg); + } else { + if (!n.getEntries().isEmpty()) { + printer.printLn(); + } + } + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final EnumConstantDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printer.print(n.getName()); + + if (!n.getArgs().isEmpty()) { + printArguments(n.getArgs(), arg); + } + + if (!n.getClassBody().isEmpty()) { + printer.printLn(" {"); + printer.indent(); + printMembers(n.getClassBody(), arg); + printer.unindent(); + printer.printLn("}"); + } + } + + @Override + public void visit(final EmptyMemberDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(";"); + } + + @Override + public void visit(final InitializerDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + if (n.isStatic()) { + printer.print("static "); + } + n.getBlock().accept(this, arg); + } + + @Override + public void visit(final IfStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("if ("); + n.getCondition().accept(this, arg); + final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; + if (thenBlock) // block statement should start on the same line + printer.print(") "); + else { + printer.printLn(")"); + printer.indent(); + } + n.getThenStmt().accept(this, arg); + if (!thenBlock) + printer.unindent(); + if (n.getElseStmt() != null) { + if (thenBlock) + printer.print(" "); + else + printer.printLn(); + final boolean elseIf = n.getElseStmt() instanceof IfStmt; + final boolean elseBlock = n.getElseStmt() 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 (!(elseIf || elseBlock)) + printer.unindent(); + } + } + + @Override + public void visit(final WhileStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("while ("); + n.getCondition().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ContinueStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("continue"); + if (n.getId() != null) { + printer.print(" "); + printer.print(n.getId()); + } + printer.print(";"); + } + + @Override + public void visit(final DoStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("do "); + n.getBody().accept(this, arg); + printer.print(" while ("); + n.getCondition().accept(this, arg); + printer.print(");"); + } + + @Override + public void visit(final ForeachStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("for ("); + n.getVariable().accept(this, arg); + printer.print(" : "); + n.getIterable().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ForStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("for ("); + if (n.getInit() != null) { + for (final Iterator<Expression> i = n.getInit().iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print("; "); + if (n.getCompare() != null) { + n.getCompare().accept(this, arg); + } + printer.print("; "); + if (n.getUpdate() != null) { + for (final Iterator<Expression> i = n.getUpdate().iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ThrowStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("throw "); + n.getExpr().accept(this, arg); + printer.print(";"); + } + + @Override + public void visit(final SynchronizedStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("synchronized ("); + n.getExpr().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final TryStmt n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("try "); + if (!n.getResources().isEmpty()) { + printer.print("("); + Iterator<VariableDeclarationExpr> resources = n.getResources().iterator(); + boolean first = true; + while (resources.hasNext()) { + visit(resources.next(), arg); + if (resources.hasNext()) { + printer.print(";"); + printer.printLn(); + if (first) { + printer.indent(); + } + } + first = false; + } + if (n.getResources().size() > 1) { + printer.unindent(); + } + printer.print(") "); + } + n.getTryBlock().accept(this, arg); + if (n.getCatchs() != null) { + for (final CatchClause c : n.getCatchs()) { + c.accept(this, arg); + } + } + if (n.getFinallyBlock() != null) { + printer.print(" finally "); + n.getFinallyBlock().accept(this, arg); + } + } + + @Override + public void visit(final CatchClause n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(" catch ("); + n.getParam().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + + } + + @Override + public void visit(final AnnotationDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printer.print("@interface "); + printer.print(n.getName()); + printer.printLn(" {"); + printer.indent(); + if (n.getMembers() != null) { + printMembers(n.getMembers(), arg); + } + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final AnnotationMemberDeclaration n, final Object arg) { + printJavaComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + n.getType().accept(this, arg); + printer.print(" "); + printer.print(n.getName()); + printer.print("()"); + if (n.getDefaultValue() != null) { + printer.print(" default "); + n.getDefaultValue().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final MarkerAnnotationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + } + + @Override + public void visit(final SingleMemberAnnotationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + printer.print("("); + n.getMemberValue().accept(this, arg); + printer.print(")"); + } + + @Override + public void visit(final NormalAnnotationExpr n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + printer.print("("); + if (n.getPairs() != null) { + for (final Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) { + final MemberValuePair m = i.next(); + m.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + } + + @Override + public void visit(final MemberValuePair n, final Object arg) { + printJavaComment(n.getComment(), arg); + printer.print(n.getName()); + printer.print(" = "); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final LineComment n, final Object arg) { + if (!this.printComments) { + return; + } + printer.print("//"); + String tmp = n.getContent(); + tmp = tmp.replace('\r', ' '); + tmp = tmp.replace('\n', ' '); + printer.printLn(tmp); + } + + @Override + public void visit(final BlockComment n, final Object arg) { + if (!this.printComments) { + return; + } + printer.print("/*"); + printer.print(n.getContent()); + printer.printLn("*/"); + } + + @Override + public void visit(LambdaExpr n, Object arg) { + printJavaComment(n.getComment(), arg); + + final List<Parameter> parameters = n.getParameters(); + final boolean printPar = n.isParametersEnclosed(); + + if (printPar) { + printer.print("("); + } + if (parameters != null) { + for (Iterator<Parameter> i = parameters.iterator(); i.hasNext(); ) { + Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + if (printPar) { + printer.print(")"); + } + + printer.print(" -> "); + final Statement body = n.getBody(); + if (body instanceof ExpressionStmt) { + // Print the expression directly + ((ExpressionStmt) body).getExpression().accept(this, arg); + } else { + body.accept(this, arg); + } + } + + + @Override + public void visit(MethodReferenceExpr n, Object arg) { + printJavaComment(n.getComment(), arg); + Expression scope = n.getScope(); + String identifier = n.getIdentifier(); + if (scope != null) { + n.getScope().accept(this, arg); + } + + printer.print("::"); + printTypeArgs(n, arg); + if (identifier != null) { + printer.print(identifier); + } + + } + + @Override + public void visit(TypeExpr n, Object arg) { + printJavaComment(n.getComment(), arg); + if (n.getType() != null) { + n.getType().accept(this, arg); + } + } + + @Override + public void visit(ArrayBracketPair arrayBracketPair, Object arg) { + printAnnotations(arrayBracketPair.getAnnotations(), true, arg); + printer.print("[]"); + } + + private void printOrphanCommentsBeforeThisChildNode(final Node node) { + if (node instanceof Comment) return; + + Node parent = node.getParentNode(); + if (parent == null) return; + List<Node> everything = new LinkedList<>(); + everything.addAll(parent.getChildrenNodes()); + sortByBeginPosition(everything); + int positionOfTheChild = -1; + for (int i = 0; i < everything.size(); i++) { + if (everything.get(i) == node) positionOfTheChild = i; + } + if (positionOfTheChild == -1) throw new RuntimeException("My index not found!!! " + node); + int positionOfPreviousChild = -1; + for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { + if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + } + 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); + nodeToPrint.accept(this, null); + } + } + + + private void printOrphanCommentsEnding(final Node node) { + List<Node> everything = new LinkedList<>(); + everything.addAll(node.getChildrenNodes()); + sortByBeginPosition(everything); + if (everything.isEmpty()) { + return; + } + + int commentsAtEnd = 0; + boolean findingComments = true; + while (findingComments && commentsAtEnd < everything.size()) { + Node last = everything.get(everything.size() - 1 - commentsAtEnd); + findingComments = (last instanceof Comment); + if (findingComments) { + commentsAtEnd++; + } + } + for (int i = 0; i < commentsAtEnd; i++) { + everything.get(everything.size() - commentsAtEnd + i).accept(this, null); + } + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/EqualsVisitor.java new file mode 100644 index 000000000..e10184ce9 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/EqualsVisitor.java @@ -0,0 +1,1514 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.visitor; + +import java.util.List; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.type.TypeParameter; +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.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.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.QualifiedNameExpr; +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.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.*; + +/** + * @author Julio Vilmar Gesser + */ +public class EqualsVisitor implements GenericVisitor<Boolean, Node> { + + private static final EqualsVisitor SINGLETON = new EqualsVisitor(); + + public static boolean equals(final Node n1, final Node n2) { + return SINGLETON.nodeEquals(n1, n2); + } + + private EqualsVisitor() { + // hide constructor + } + + /** + * Check for equality that can be applied to each kind of node, + * to not repeat it in every method we store that here. + */ + private boolean commonNodeEquality(Node n1, Node n2) { + if (!nodeEquals(n1.getComment(), n2.getComment())) { + return false; + } + return nodesEquals(n1.getOrphanComments(), n2.getOrphanComments()); + } + + private <T extends Node> boolean nodesEquals(final List<T> nodes1, final List<T> nodes2) { + if (nodes1 == null) { + return nodes2 == null; + } else if (nodes2 == null) { + return false; + } + if (nodes1.size() != nodes2.size()) { + return false; + } + for (int i = 0; i < nodes1.size(); i++) { + if (!nodeEquals(nodes1.get(i), nodes2.get(i))) { + return false; + } + } + return true; + } + + private <T extends Node> boolean nodeEquals(final T n1, final T n2) { + if (n1 == n2) { + return true; + } + if (n1 == null || n2 == null) { + return false; + } + if (n1.getClass() != n2.getClass()) { + return false; + } + if (!commonNodeEquality(n1, n2)){ + return false; + } + return n1.accept(this, n2); + } + + private boolean objEquals(final Object n1, final Object n2) { + if (n1 == n2) { + return true; + } + if (n1 == null || n2 == null) { + return false; + } + return n1.equals(n2); + } + + @Override public Boolean visit(final CompilationUnit n1, final Node arg) { + final CompilationUnit n2 = (CompilationUnit) arg; + + if (!nodeEquals(n1.getPackage(), n2.getPackage())) { + return false; + } + + if (!nodesEquals(n1.getImports(), n2.getImports())) { + return false; + } + + if (!nodesEquals(n1.getTypes(), n2.getTypes())) { + return false; + } + + if (!nodesEquals(n1.getComments(), n2.getComments())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final PackageDeclaration n1, final Node arg) { + final PackageDeclaration n2 = (PackageDeclaration) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ImportDeclaration n1, final Node arg) { + final ImportDeclaration n2 = (ImportDeclaration) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final TypeParameter n1, final Node arg) { + final TypeParameter n2 = (TypeParameter) arg; + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getTypeBound(), n2.getTypeBound())) { + return false; + } + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override public Boolean visit(final LineComment n1, final Node arg) { + final LineComment n2 = (LineComment) arg; + + if (!objEquals(n1.getContent(), n2.getContent())) { + return false; + } + + if (!objEquals(n1.getBegin().line, n2.getBegin().line)) { + return false; + } + + return true; + } + + @Override public Boolean visit(final BlockComment n1, final Node arg) { + final BlockComment n2 = (BlockComment) arg; + + if (!objEquals(n1.getContent(), n2.getContent())) { + return false; + } + + if (!objEquals(n1.getBegin().line, n2.getBegin().line)) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ClassOrInterfaceDeclaration n1, final Node arg) { + final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (n1.isInterface() != n2.isInterface()) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { + return false; + } + + if (!nodesEquals(n1.getExtends(), n2.getExtends())) { + return false; + } + + if (!nodesEquals(n1.getImplements(), n2.getImplements())) { + return false; + } + + if (!nodesEquals(n1.getMembers(), n2.getMembers())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final EnumDeclaration n1, final Node arg) { + final EnumDeclaration n2 = (EnumDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodesEquals(n1.getImplements(), n2.getImplements())) { + return false; + } + + if (!nodesEquals(n1.getEntries(), n2.getEntries())) { + return false; + } + + if (!nodesEquals(n1.getMembers(), n2.getMembers())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final EmptyTypeDeclaration n1, final Node arg) { + return true; + } + + @Override public Boolean visit(final EnumConstantDeclaration n1, final Node arg) { + final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodesEquals(n1.getArgs(), n2.getArgs())) { + return false; + } + + if (!nodesEquals(n1.getClassBody(), n2.getClassBody())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final AnnotationDeclaration n1, final Node arg) { + final AnnotationDeclaration n2 = (AnnotationDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodesEquals(n1.getMembers(), n2.getMembers())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final AnnotationMemberDeclaration n1, final Node arg) { + final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodeEquals(n1.getDefaultValue(), n2.getDefaultValue())) { + return false; + } + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final FieldDeclaration n1, final Node arg) { + final FieldDeclaration n2 = (FieldDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodeEquals(n1.getElementType(), n2.getElementType())) { + return false; + } + + if (!nodesEquals(n1.getVariables(), n2.getVariables())) { + return false; + } + + if(!nodesEquals(n1.getArrayBracketPairsAfterElementType(), n2.getArrayBracketPairsAfterElementType())){ + return false; + } + + return true; + } + + @Override public Boolean visit(final VariableDeclarator n1, final Node arg) { + final VariableDeclarator n2 = (VariableDeclarator) arg; + + if (!nodeEquals(n1.getId(), n2.getId())) { + return false; + } + + if (!nodeEquals(n1.getInit(), n2.getInit())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final VariableDeclaratorId n1, final Node arg) { + final VariableDeclaratorId n2 = (VariableDeclaratorId) arg; + + if(!nodesEquals(n1.getArrayBracketPairsAfterId(), n2.getArrayBracketPairsAfterId())){ + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ConstructorDeclaration n1, final Node arg) { + final ConstructorDeclaration n2 = (ConstructorDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + if (!nodesEquals(n1.getParameters(), n2.getParameters())) { + return false; + } + + if (!nodesEquals(n1.getThrows(), n2.getThrows())) { + return false; + } + + if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final MethodDeclaration n1, final Node arg) { + final MethodDeclaration n2 = (MethodDeclaration) arg; + + // javadoc are checked at CompilationUnit + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if(!nodesEquals(n1.getArrayBracketPairsAfterElementType(), n2.getArrayBracketPairsAfterElementType())){ + return false; + } + + if(!nodesEquals(n1.getArrayBracketPairsAfterParameterList(), n2.getArrayBracketPairsAfterParameterList())){ + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodeEquals(n1.getElementType(), n2.getElementType())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + if (!nodesEquals(n1.getParameters(), n2.getParameters())) { + return false; + } + + if (!nodesEquals(n1.getThrows(), n2.getThrows())) { + return false; + } + + if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { + return false; + } + if(n1.isDefault() != n2.isDefault()){ + return false; + } + return true; + } + + @Override public Boolean visit(final Parameter n1, final Node arg) { + final Parameter n2 = (Parameter) arg; + if (!nodeEquals(n1.getElementType(), n2.getElementType())) { + return false; + } + + if(!nodesEquals(n1.getArrayBracketPairsAfterElementType(), n2.getArrayBracketPairsAfterElementType())){ + return false; + } + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!nodeEquals(n1.getId(), n2.getId())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final EmptyMemberDeclaration n1, final Node arg) { + return true; + } + + @Override public Boolean visit(final InitializerDeclaration n1, final Node arg) { + final InitializerDeclaration n2 = (InitializerDeclaration) arg; + + if (!nodeEquals(n1.getBlock(), n2.getBlock())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final JavadocComment n1, final Node arg) { + final JavadocComment n2 = (JavadocComment) arg; + + if (!objEquals(n1.getContent(), n2.getContent())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ClassOrInterfaceType n1, final Node arg) { + final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg; + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodeEquals(n1.getScope(), n2.getScope())) { + return false; + } + + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final PrimitiveType n1, final Node arg) { + final PrimitiveType n2 = (PrimitiveType) arg; + + if (n1.getType() != n2.getType()) { + return false; + } + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override + public Boolean visit(ArrayType n1, Node arg) { + final ArrayType n2 = (ArrayType) arg; + + if (!nodeEquals(n1.getComponentType(), n2.getComponentType())) { + return false; + } + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override + public Boolean visit(ArrayCreationLevel n1, Node arg) { + final ArrayCreationLevel n2 = (ArrayCreationLevel) arg; + + if (!nodeEquals(n1.getDimension(), n2.getDimension())) { + return false; + } + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override public Boolean visit(final IntersectionType n1, final Node arg) { + final IntersectionType n2 = (IntersectionType) arg; + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + List<ReferenceType> n1Elements = n1.getElements(); + List<ReferenceType> n2Elements = n2.getElements(); + + if (n1Elements !=null && n2Elements != null) { + if(n1Elements.size() != n2Elements.size()){ + return false; + } + else{ + int i = 0; + for(ReferenceType aux: n1Elements){ + if(aux.accept(this, n2Elements.get(i))) { + return false; + } + i++; + } + } + } else if (n1Elements != n2Elements){ + return false; + } + return true; + } + + @Override public Boolean visit(final UnionType n1, final Node arg) { + final UnionType n2 = (UnionType) arg; + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + List<ReferenceType> n1Elements = n1.getElements(); + List<ReferenceType> n2Elements = n2.getElements(); + + if (n1Elements !=null && n2Elements != null) { + if(n1Elements.size() != n2Elements.size()){ + return false; + } + else{ + int i = 0; + for(ReferenceType aux: n1Elements){ + if(aux.accept(this, n2Elements.get(i))) { + return false; + } + i++; + } + } + } else if (n1Elements != n2Elements){ + return false; + } + return true; + } + + @Override + public Boolean visit(VoidType n1, Node arg) { + VoidType n2 = (VoidType) arg; + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override public Boolean visit(final WildcardType n1, final Node arg) { + final WildcardType n2 = (WildcardType) arg; + + if (!nodeEquals(n1.getExtends(), n2.getExtends())) { + return false; + } + + if (!nodeEquals(n1.getSuper(), n2.getSuper())) { + return false; + } + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + return true; + } + + @Override public Boolean visit(final UnknownType n1, final Node arg) { + return true; + } + + @Override public Boolean visit(final ArrayAccessExpr n1, final Node arg) { + final ArrayAccessExpr n2 = (ArrayAccessExpr) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodeEquals(n1.getIndex(), n2.getIndex())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ArrayCreationExpr n1, final Node arg) { + final ArrayCreationExpr n2 = (ArrayCreationExpr) arg; + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + if (!nodesEquals(n1.getLevels(), n2.getLevels())) { + return false; + } + + if (!nodeEquals(n1.getInitializer(), n2.getInitializer())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ArrayInitializerExpr n1, final Node arg) { + final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg; + + if (!nodesEquals(n1.getValues(), n2.getValues())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final AssignExpr n1, final Node arg) { + final AssignExpr n2 = (AssignExpr) arg; + + if (n1.getOperator() != n2.getOperator()) { + return false; + } + + if (!nodeEquals(n1.getTarget(), n2.getTarget())) { + return false; + } + + if (!nodeEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final BinaryExpr n1, final Node arg) { + final BinaryExpr n2 = (BinaryExpr) arg; + + if (n1.getOperator() != n2.getOperator()) { + return false; + } + + if (!nodeEquals(n1.getLeft(), n2.getLeft())) { + return false; + } + + if (!nodeEquals(n1.getRight(), n2.getRight())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final CastExpr n1, final Node arg) { + final CastExpr n2 = (CastExpr) arg; + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ClassExpr n1, final Node arg) { + final ClassExpr n2 = (ClassExpr) arg; + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ConditionalExpr n1, final Node arg) { + final ConditionalExpr n2 = (ConditionalExpr) arg; + + if (!nodeEquals(n1.getCondition(), n2.getCondition())) { + return false; + } + + if (!nodeEquals(n1.getThenExpr(), n2.getThenExpr())) { + return false; + } + + if (!nodeEquals(n1.getElseExpr(), n2.getElseExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final EnclosedExpr n1, final Node arg) { + final EnclosedExpr n2 = (EnclosedExpr) arg; + + if (!nodeEquals(n1.getInner(), n2.getInner())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final FieldAccessExpr n1, final Node arg) { + final FieldAccessExpr n2 = (FieldAccessExpr) arg; + + if (!nodeEquals(n1.getScope(), n2.getScope())) { + return false; + } + + if (!objEquals(n1.getField(), n2.getField())) { + return false; + } + + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final InstanceOfExpr n1, final Node arg) { + final InstanceOfExpr n2 = (InstanceOfExpr) arg; + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final StringLiteralExpr n1, final Node arg) { + final StringLiteralExpr n2 = (StringLiteralExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final IntegerLiteralExpr n1, final Node arg) { + final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final LongLiteralExpr n1, final Node arg) { + final LongLiteralExpr n2 = (LongLiteralExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final IntegerLiteralMinValueExpr n1, final Node arg) { + final IntegerLiteralMinValueExpr n2 = (IntegerLiteralMinValueExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final LongLiteralMinValueExpr n1, final Node arg) { + final LongLiteralMinValueExpr n2 = (LongLiteralMinValueExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final CharLiteralExpr n1, final Node arg) { + final CharLiteralExpr n2 = (CharLiteralExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final DoubleLiteralExpr n1, final Node arg) { + final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg; + + if (!objEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final BooleanLiteralExpr n1, final Node arg) { + final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg; + + if (n1.getValue() != n2.getValue()) { + return false; + } + + return true; + } + + @Override public Boolean visit(final NullLiteralExpr n1, final Node arg) { + return true; + } + + @Override public Boolean visit(final MethodCallExpr n1, final Node arg) { + final MethodCallExpr n2 = (MethodCallExpr) arg; + + if (!nodeEquals(n1.getScope(), n2.getScope())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getArgs(), n2.getArgs())) { + return false; + } + + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final NameExpr n1, final Node arg) { + final NameExpr n2 = (NameExpr) arg; + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ObjectCreationExpr n1, final Node arg) { + final ObjectCreationExpr n2 = (ObjectCreationExpr) arg; + + if (!nodeEquals(n1.getScope(), n2.getScope())) { + return false; + } + + if (!nodeEquals(n1.getType(), n2.getType())) { + return false; + } + + if (!nodesEquals(n1.getAnonymousClassBody(), n2.getAnonymousClassBody())) { + return false; + } + + if (!nodesEquals(n1.getArgs(), n2.getArgs())) { + return false; + } + + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final QualifiedNameExpr n1, final Node arg) { + final QualifiedNameExpr n2 = (QualifiedNameExpr) arg; + + if (!nodeEquals(n1.getQualifier(), n2.getQualifier())) { + return false; + } + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ThisExpr n1, final Node arg) { + final ThisExpr n2 = (ThisExpr) arg; + + if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final SuperExpr n1, final Node arg) { + final SuperExpr n2 = (SuperExpr) arg; + + if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final UnaryExpr n1, final Node arg) { + final UnaryExpr n2 = (UnaryExpr) arg; + + if (n1.getOperator() != n2.getOperator()) { + return false; + } + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final VariableDeclarationExpr n1, final Node arg) { + final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg; + + if (!n1.getModifiers().equals(n2.getModifiers())) { + return false; + } + + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + if (!nodeEquals(n1.getElementType(), n2.getElementType())) { + return false; + } + + if (!nodesEquals(n1.getVariables(), n2.getVariables())) { + return false; + } + + if(!nodesEquals(n1.getArrayBracketPairsAfterElementType(), n2.getArrayBracketPairsAfterElementType())){ + return false; + } + + return true; + } + + @Override public Boolean visit(final MarkerAnnotationExpr n1, final Node arg) { + final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final SingleMemberAnnotationExpr n1, final Node arg) { + final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodeEquals(n1.getMemberValue(), n2.getMemberValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final NormalAnnotationExpr n1, final Node arg) { + final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg; + + if (!nodeEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodesEquals(n1.getPairs(), n2.getPairs())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final MemberValuePair n1, final Node arg) { + final MemberValuePair n2 = (MemberValuePair) arg; + + if (!objEquals(n1.getName(), n2.getName())) { + return false; + } + + if (!nodeEquals(n1.getValue(), n2.getValue())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ExplicitConstructorInvocationStmt n1, final Node arg) { + final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg; + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + if (!nodesEquals(n1.getArgs(), n2.getArgs())) { + return false; + } + + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final TypeDeclarationStmt n1, final Node arg) { + final TypeDeclarationStmt n2 = (TypeDeclarationStmt) arg; + + if (!nodeEquals(n1.getTypeDeclaration(), n2.getTypeDeclaration())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final AssertStmt n1, final Node arg) { + final AssertStmt n2 = (AssertStmt) arg; + + if (!nodeEquals(n1.getCheck(), n2.getCheck())) { + return false; + } + + if (!nodeEquals(n1.getMessage(), n2.getMessage())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final BlockStmt n1, final Node arg) { + final BlockStmt n2 = (BlockStmt) arg; + + if (!nodesEquals(n1.getStmts(), n2.getStmts())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final LabeledStmt n1, final Node arg) { + final LabeledStmt n2 = (LabeledStmt) arg; + + if (!nodeEquals(n1.getStmt(), n2.getStmt())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final EmptyStmt n1, final Node arg) { + return true; + } + + @Override public Boolean visit(final ExpressionStmt n1, final Node arg) { + final ExpressionStmt n2 = (ExpressionStmt) arg; + + if (!nodeEquals(n1.getExpression(), n2.getExpression())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final SwitchStmt n1, final Node arg) { + final SwitchStmt n2 = (SwitchStmt) arg; + + if (!nodeEquals(n1.getSelector(), n2.getSelector())) { + return false; + } + + if (!nodesEquals(n1.getEntries(), n2.getEntries())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final SwitchEntryStmt n1, final Node arg) { + final SwitchEntryStmt n2 = (SwitchEntryStmt) arg; + + if (!nodeEquals(n1.getLabel(), n2.getLabel())) { + return false; + } + + if (!nodesEquals(n1.getStmts(), n2.getStmts())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final BreakStmt n1, final Node arg) { + final BreakStmt n2 = (BreakStmt) arg; + + if (!objEquals(n1.getId(), n2.getId())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ReturnStmt n1, final Node arg) { + final ReturnStmt n2 = (ReturnStmt) arg; + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final IfStmt n1, final Node arg) { + final IfStmt n2 = (IfStmt) arg; + + if (!nodeEquals(n1.getCondition(), n2.getCondition())) { + return false; + } + + if (!nodeEquals(n1.getThenStmt(), n2.getThenStmt())) { + return false; + } + + if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final WhileStmt n1, final Node arg) { + final WhileStmt n2 = (WhileStmt) arg; + + if (!nodeEquals(n1.getCondition(), n2.getCondition())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ContinueStmt n1, final Node arg) { + final ContinueStmt n2 = (ContinueStmt) arg; + + if (!objEquals(n1.getId(), n2.getId())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final DoStmt n1, final Node arg) { + final DoStmt n2 = (DoStmt) arg; + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + if (!nodeEquals(n1.getCondition(), n2.getCondition())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ForeachStmt n1, final Node arg) { + final ForeachStmt n2 = (ForeachStmt) arg; + + if (!nodeEquals(n1.getVariable(), n2.getVariable())) { + return false; + } + + if (!nodeEquals(n1.getIterable(), n2.getIterable())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ForStmt n1, final Node arg) { + final ForStmt n2 = (ForStmt) arg; + + if (!nodesEquals(n1.getInit(), n2.getInit())) { + return false; + } + + if (!nodeEquals(n1.getCompare(), n2.getCompare())) { + return false; + } + + if (!nodesEquals(n1.getUpdate(), n2.getUpdate())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final ThrowStmt n1, final Node arg) { + final ThrowStmt n2 = (ThrowStmt) arg; + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final SynchronizedStmt n1, final Node arg) { + final SynchronizedStmt n2 = (SynchronizedStmt) arg; + + if (!nodeEquals(n1.getExpr(), n2.getExpr())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final TryStmt n1, final Node arg) { + final TryStmt n2 = (TryStmt) arg; + + if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) { + return false; + } + + if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) { + return false; + } + + if(!nodesEquals(n1.getResources(), n2.getResources())) { + return false; + } + + if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) { + return false; + } + + return true; + } + + @Override public Boolean visit(final CatchClause n1, final Node arg) { + final CatchClause n2 = (CatchClause) arg; + + if (!nodeEquals(n1.getParam(), n2.getParam())) { + return false; + } + + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + + return true; + } + + @Override + public Boolean visit(LambdaExpr n1, Node arg) { + LambdaExpr n2 = (LambdaExpr) arg; + if (!nodesEquals(n1.getParameters(), n2.getParameters())) { + return false; + } + if(n1.isParametersEnclosed() != n2.isParametersEnclosed()){ + return false; + } + if (!nodeEquals(n1.getBody(), n2.getBody())) { + return false; + } + return true; + } + + @Override + public Boolean visit(MethodReferenceExpr n1, Node arg) { + MethodReferenceExpr n2 = (MethodReferenceExpr) arg; + if (!nodeEquals(n1.getScope(), n2.getScope())) { + return false; + } + if (!nodesEquals(n1.getTypeArguments(), n2.getTypeArguments())) { + return false; + } + if (!objEquals(n1.getIdentifier(), n2.getIdentifier())) { + return false; + } + return true; + } + + @Override + public Boolean visit(TypeExpr n, Node arg) { + TypeExpr n2 = (TypeExpr) arg; + if (!nodeEquals(n.getType(), n2.getType())) { + return false; + } + return true; + } + + @Override + public Boolean visit(ArrayBracketPair n1, Node arg) { + ArrayBracketPair n2 = (ArrayBracketPair) arg; + if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { + return false; + } + + return true; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitor.java new file mode 100644 index 000000000..9f4e9bc7f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitor.java @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.comments.BlockComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.type.TypeParameter; +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.comments.JavadocComment; +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.expr.*; +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.*; + +/** + * A visitor that has a return value. + * + * @author Julio Vilmar Gesser + */ +public interface GenericVisitor<R, A> { + + //- Compilation Unit ---------------------------------- + + R visit(CompilationUnit n, A arg); + + R visit(PackageDeclaration n, A arg); + + R visit(ImportDeclaration n, A arg); + + R visit(TypeParameter n, A arg); + + R visit(LineComment n, A arg); + + R visit(BlockComment n, A arg); + + //- Body ---------------------------------------------- + + R visit(ClassOrInterfaceDeclaration n, A arg); + + R visit(EnumDeclaration n, A arg); + + R visit(EmptyTypeDeclaration n, A arg); + + R visit(EnumConstantDeclaration n, A arg); + + R visit(AnnotationDeclaration n, A arg); + + R visit(AnnotationMemberDeclaration n, A arg); + + R visit(FieldDeclaration n, A arg); + + R visit(VariableDeclarator n, A arg); + + R visit(VariableDeclaratorId n, A arg); + + R visit(ConstructorDeclaration n, A arg); + + R visit(MethodDeclaration n, A arg); + + R visit(Parameter n, A arg); + + R visit(EmptyMemberDeclaration n, A arg); + + R visit(InitializerDeclaration n, A arg); + + R visit(JavadocComment n, A arg); + + //- Type ---------------------------------------------- + + R visit(ClassOrInterfaceType n, A arg); + + R visit(PrimitiveType n, A arg); + + R visit(ArrayType n, A arg); + + R visit(ArrayCreationLevel n, A arg); + + R visit(IntersectionType n, A arg); + + R visit(UnionType n, A arg); + + R visit(VoidType n, A arg); + + R visit(WildcardType n, A arg); + + R visit(UnknownType n, A arg); + + //- Expression ---------------------------------------- + + R visit(ArrayAccessExpr n, A arg); + + R visit(ArrayCreationExpr n, A arg); + + R visit(ArrayInitializerExpr n, A arg); + + R visit(AssignExpr n, A arg); + + R visit(BinaryExpr n, A arg); + + R visit(CastExpr n, A arg); + + R visit(ClassExpr n, A arg); + + R visit(ConditionalExpr n, A arg); + + R visit(EnclosedExpr n, A arg); + + R visit(FieldAccessExpr n, A arg); + + R visit(InstanceOfExpr n, A arg); + + R visit(StringLiteralExpr n, A arg); + + R visit(IntegerLiteralExpr n, A arg); + + R visit(LongLiteralExpr n, A arg); + + R visit(IntegerLiteralMinValueExpr n, A arg); + + R visit(LongLiteralMinValueExpr n, A arg); + + R visit(CharLiteralExpr n, A arg); + + R visit(DoubleLiteralExpr n, A arg); + + R visit(BooleanLiteralExpr n, A arg); + + R visit(NullLiteralExpr n, A arg); + + R visit(MethodCallExpr n, A arg); + + R visit(NameExpr n, A arg); + + R visit(ObjectCreationExpr n, A arg); + + R visit(QualifiedNameExpr n, A arg); + + R visit(ThisExpr n, A arg); + + R visit(SuperExpr n, A arg); + + R visit(UnaryExpr n, A arg); + + R visit(VariableDeclarationExpr n, A arg); + + R visit(MarkerAnnotationExpr n, A arg); + + R visit(SingleMemberAnnotationExpr n, A arg); + + R visit(NormalAnnotationExpr n, A arg); + + R visit(MemberValuePair n, A arg); + + //- Statements ---------------------------------------- + + R visit(ExplicitConstructorInvocationStmt n, A arg); + + R visit(TypeDeclarationStmt n, A arg); + + R visit(AssertStmt n, A arg); + + R visit(BlockStmt n, A arg); + + R visit(LabeledStmt n, A arg); + + R visit(EmptyStmt n, A arg); + + R visit(ExpressionStmt n, A arg); + + R visit(SwitchStmt n, A arg); + + R visit(SwitchEntryStmt n, A arg); + + R visit(BreakStmt n, A arg); + + R visit(ReturnStmt n, A arg); + + R visit(IfStmt n, A arg); + + R visit(WhileStmt n, A arg); + + R visit(ContinueStmt n, A arg); + + R visit(DoStmt n, A arg); + + R visit(ForeachStmt n, A arg); + + R visit(ForStmt n, A arg); + + R visit(ThrowStmt n, A arg); + + R visit(SynchronizedStmt n, A arg); + + R visit(TryStmt n, A arg); + + R visit(CatchClause n, A arg); + + R visit(LambdaExpr n, A arg); + + R visit(MethodReferenceExpr n, A arg); + + R visit(TypeExpr n, A arg); + + R visit(ArrayBracketPair arrayBracketPair, A arg); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java new file mode 100644 index 000000000..af01fdffb --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java @@ -0,0 +1,1677 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.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.stmt.*; +import com.github.javaparser.ast.type.*; + +import java.util.List; + +/** + * @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) { + 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.getType().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) { + 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) { + 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) { + 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) { + 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 = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + 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 ImportDeclaration 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 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 QualifiedNameExpr n, final A arg) { + visitComment(n, arg); + { + R result = n.getQualifier().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()!=null) { + R result = n.getDimension().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; + } + } + { + for (ReferenceType element : n.getElements()) { + R result = element.accept(this, arg); + if (result != null) { + return result; + } + } + } + return null; + } + + @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; + } + } + { + for (ReferenceType element : n.getElements()) { + R result = element.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() != 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(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; + } + + @Override + public R visit(MethodReferenceExpr n, A arg) { + visitComment(n, arg); + { + if (n.getTypeArguments() != null) { + for (Type<?> type : n.getTypeArguments()) { + R result = type.accept(this, arg); + if (result != null) { + return result; + } + } + } + } + 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(final BlockComment n, final A arg) { + return null; + } + + @Override + public R visit(final LineComment n, final A arg) { + 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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java new file mode 100644 index 000000000..78b0e2931 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java @@ -0,0 +1,1149 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.visitor; + +import java.util.List; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.type.TypeParameter; +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.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.QualifiedNameExpr; +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.nodeTypes.NodeWithAnnotations; +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.type.*; +import com.github.javaparser.ast.stmt.WhileStmt; + +/** + * This visitor adapter can be used to save time when some specific nodes needs + * to be changed. To do that just extend this class and override the methods + * from the nodes who needs to be changed, returning the changed node. + * + * @author Julio Vilmar Gesser + */ +public class ModifierVisitorAdapter<A> implements GenericVisitor<Node, 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 Node visit(final AnnotationDeclaration n, final A arg) { + visitAnnotations(n, arg); + visitComment(n, arg); + final List<BodyDeclaration<?>> members = n.getMembers(); + if (members != null) { + for (int i = 0; i < members.size(); i++) { + members.set(i, (BodyDeclaration<?>) members.get(i).accept(this, arg)); + } + removeNulls(members); + } + return n; + } + + private void visitAnnotations(NodeWithAnnotations<?> n, A arg) { + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + } + + @Override public Node visit(final AnnotationMemberDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + n.setType((Type) n.getType().accept(this, arg)); + if (n.getDefaultValue() != null) { + n.setDefaultValue((Expression) n.getDefaultValue().accept(this, arg)); + } + return n; + } + + @Override public Node 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 Node visit(final ArrayCreationExpr n, final A arg) { + visitComment(n, arg); + n.setType((Type) n.getType().accept(this, arg)); + + final List<ArrayCreationLevel> values = n.getLevels(); + for (int i = 0; i < values.size(); i++) { + values.set(i, (ArrayCreationLevel) values.get(i).accept(this, arg)); + } + removeNulls(values); + + if (n.getInitializer() != null) { + n.setInitializer((ArrayInitializerExpr) n.getInitializer().accept(this, arg)); + } + return n; + } + + @Override public Node visit(final ArrayInitializerExpr n, final A arg) { + visitComment(n, arg); + if (n.getValues() != null) { + final List<Expression> values = n.getValues(); + if (values != null) { + for (int i = 0; i < values.size(); i++) { + values.set(i, (Expression) values.get(i).accept(this, arg)); + } + removeNulls(values); + } + } + return n; + } + + @Override public Node 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 Node 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 Node 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 Node visit(final BlockStmt n, final A arg) { + visitComment(n, arg); + final List<Statement> stmts = n.getStmts(); + if (stmts != null) { + for (int i = 0; i < stmts.size(); i++) { + stmts.set(i, (Statement) stmts.get(i).accept(this, arg)); + } + removeNulls(stmts); + } + return n; + } + + @Override public Node visit(final BooleanLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final BreakStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node 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 Node 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 Node visit(final CharLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final ClassExpr n, final A arg) { + visitComment(n, arg); + n.setType((Type) n.getType().accept(this, arg)); + return n; + } + + @Override public Node visit(final ClassOrInterfaceDeclaration n, final A arg) { + visitAnnotations(n, arg); + visitComment(n, arg); + final List<TypeParameter> typeParameters = n.getTypeParameters(); + if (typeParameters != null) { + for (int i = 0; i < typeParameters.size(); i++) { + typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); + } + removeNulls(typeParameters); + } + final List<ClassOrInterfaceType> extendz = n.getExtends(); + if (extendz != null) { + for (int i = 0; i < extendz.size(); i++) { + extendz.set(i, (ClassOrInterfaceType) extendz.get(i).accept(this, arg)); + } + removeNulls(extendz); + } + final List<ClassOrInterfaceType> implementz = n.getImplements(); + if (implementz != null) { + for (int i = 0; i < implementz.size(); i++) { + implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg)); + } + removeNulls(implementz); + } + final List<BodyDeclaration<?>> members = n.getMembers(); + if (members != null) { + for (int i = 0; i < members.size(); i++) { + members.set(i, (BodyDeclaration<?>) members.get(i).accept(this, arg)); + } + removeNulls(members); + } + return n; + } + + @Override public Node 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)); + } + final List<Type<?>> typeArguments = n.getTypeArguments(); + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + typeArguments.set(i, (Type<?>) typeArguments.get(i).accept(this, arg)); + } + removeNulls(typeArguments); + } + return n; + } + + @Override public Node visit(final CompilationUnit n, final A arg) { + visitComment(n, arg); + if (n.getPackage() != null) { + n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg)); + } + final List<ImportDeclaration> imports = n.getImports(); + if (imports != null) { + for (int i = 0; i < imports.size(); i++) { + imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg)); + } + removeNulls(imports); + } + final List<TypeDeclaration<?>> types = n.getTypes(); + if (types != null) { + for (int i = 0; i < types.size(); i++) { + types.set(i, (TypeDeclaration<?>) types.get(i).accept(this, arg)); + } + removeNulls(types); + } + return n; + } + + @Override public Node 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 Node visit(final ConstructorDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + final List<TypeParameter> typeParameters = n.getTypeParameters(); + if (typeParameters != null) { + for (int i = 0; i < typeParameters.size(); i++) { + typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); + } + removeNulls(typeParameters); + } + final List<Parameter> parameters = n.getParameters(); + if (parameters != null) { + for (int i = 0; i < parameters.size(); i++) { + parameters.set(i, (Parameter) parameters.get(i).accept(this, arg)); + } + removeNulls(parameters); + } + final List<ReferenceType> throwz = n.getThrows(); + if (throwz != null) { + for (int i = 0; i < throwz.size(); i++) { + throwz.set(i, (ReferenceType) throwz.get(i).accept(this, arg)); + } + removeNulls(throwz); + } + n.setBody((BlockStmt) n.getBody().accept(this, arg)); + return n; + } + + @Override public Node visit(final ContinueStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node 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 Node visit(final DoubleLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final EmptyMemberDeclaration n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final EmptyStmt n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final EmptyTypeDeclaration n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final EnclosedExpr n, final A arg) { + visitComment(n, arg); + n.setInner((Expression) n.getInner().accept(this, arg)); + return n; + } + + @Override public Node visit(final EnumConstantDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + final List<Expression> args = n.getArgs(); + if (args != null) { + for (int i = 0; i < args.size(); i++) { + args.set(i, (Expression) args.get(i).accept(this, arg)); + } + removeNulls(args); + } + final List<BodyDeclaration<?>> classBody = n.getClassBody(); + if (classBody != null) { + for (int i = 0; i < classBody.size(); i++) { + classBody.set(i, (BodyDeclaration<?>) classBody.get(i).accept(this, arg)); + } + removeNulls(classBody); + } + return n; + } + + @Override public Node visit(final EnumDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + final List<ClassOrInterfaceType> implementz = n.getImplements(); + if (implementz != null) { + for (int i = 0; i < implementz.size(); i++) { + implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg)); + } + removeNulls(implementz); + } + final List<EnumConstantDeclaration> entries = n.getEntries(); + if (entries != null) { + for (int i = 0; i < entries.size(); i++) { + entries.set(i, (EnumConstantDeclaration) entries.get(i).accept(this, arg)); + } + removeNulls(entries); + } + final List<BodyDeclaration<?>> members = n.getMembers(); + if (members != null) { + for (int i = 0; i < members.size(); i++) { + members.set(i, (BodyDeclaration<?>) members.get(i).accept(this, arg)); + } + removeNulls(members); + } + return n; + } + + @Override public Node visit(final ExplicitConstructorInvocationStmt n, final A arg) { + visitComment(n, arg); + if (!n.isThis() && n.getExpr() != null) { + n.setExpr((Expression) n.getExpr().accept(this, arg)); + } + final List<Type<?>> typeArguments = n.getTypeArguments(); + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + typeArguments.set(i, (Type<?>) typeArguments.get(i).accept(this, arg)); + } + removeNulls(typeArguments); + } + final List<Expression> args = n.getArgs(); + if (args != null) { + for (int i = 0; i < args.size(); i++) { + args.set(i, (Expression) args.get(i).accept(this, arg)); + } + removeNulls(args); + } + return n; + } + + @Override public Node 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 Node 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 Node visit(final FieldDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + n.setElementType((Type) n.getElementType().accept(this, arg)); + final List<VariableDeclarator> variables = n.getVariables(); + for (int i = 0; i < variables.size(); i++) { + variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg)); + } + removeNulls(variables); + return n; + } + + @Override public Node 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 Node visit(final ForStmt n, final A arg) { + visitComment(n, arg); + final List<Expression> init = n.getInit(); + if (init != null) { + for (int i = 0; i < init.size(); i++) { + init.set(i, (Expression) init.get(i).accept(this, arg)); + } + removeNulls(init); + } + if (n.getCompare() != null) { + n.setCompare((Expression) n.getCompare().accept(this, arg)); + } + final List<Expression> update = n.getUpdate(); + if (update != null) { + for (int i = 0; i < update.size(); i++) { + update.set(i, (Expression) update.get(i).accept(this, arg)); + } + removeNulls(update); + } + n.setBody((Statement) n.getBody().accept(this, arg)); + return n; + } + + @Override public Node 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. + // DumpVisitor, 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 Node visit(final ImportDeclaration n, final A arg) { + visitComment(n, arg); + n.setName((NameExpr) n.getName().accept(this, arg)); + return n; + } + + @Override public Node visit(final InitializerDeclaration n, final A arg) { + visitComment(n, arg); + n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); + return n; + } + + @Override public Node visit(final InstanceOfExpr n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + n.setType((Type) n.getType().accept(this, arg)); + return n; + } + + @Override public Node visit(final IntegerLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final IntegerLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final JavadocComment n, final A arg) { + return n; + } + + @Override public Node visit(final LabeledStmt n, final A arg) { + visitComment(n, arg); + n.setStmt((Statement) n.getStmt().accept(this, arg)); + return n; + } + + @Override public Node visit(final LongLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final LongLiteralMinValueExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final MarkerAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((NameExpr) n.getName().accept(this, arg)); + return n; + } + + @Override public Node visit(final MemberValuePair n, final A arg) { + visitComment(n, arg); + n.setValue((Expression) n.getValue().accept(this, arg)); + return n; + } + + @Override public Node visit(final MethodCallExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope() != null) { + n.setScope((Expression) n.getScope().accept(this, arg)); + } + final List<Type<?>> typeArguments = n.getTypeArguments(); + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + typeArguments.set(i, (Type<?>) typeArguments.get(i).accept(this, arg)); + } + removeNulls(typeArguments); + } + final List<Expression> args = n.getArgs(); + if (args != null) { + for (int i = 0; i < args.size(); i++) { + args.set(i, (Expression) args.get(i).accept(this, arg)); + } + removeNulls(args); + } + return n; + } + + @Override public Node visit(final MethodDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + final List<TypeParameter> typeParameters = n.getTypeParameters(); + if (typeParameters != null) { + for (int i = 0; i < typeParameters.size(); i++) { + typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); + } + removeNulls(typeParameters); + } + n.setElementType((Type) n.getElementType().accept(this, arg)); + final List<Parameter> parameters = n.getParameters(); + if (parameters != null) { + for (int i = 0; i < parameters.size(); i++) { + parameters.set(i, (Parameter) parameters.get(i).accept(this, arg)); + } + removeNulls(parameters); + } + final List<ReferenceType> throwz = n.getThrows(); + if (throwz != null) { + for (int i = 0; i < throwz.size(); i++) { + throwz.set(i, (ReferenceType) throwz.get(i).accept(this, arg)); + } + removeNulls(throwz); + } + if (n.getBody() != null) { + n.setBody((BlockStmt) n.getBody().accept(this, arg)); + } + return n; + } + + @Override public Node visit(final NameExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final NormalAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((NameExpr) n.getName().accept(this, arg)); + final List<MemberValuePair> pairs = n.getPairs(); + if (pairs != null) { + for (int i = 0; i < pairs.size(); i++) { + pairs.set(i, (MemberValuePair) pairs.get(i).accept(this, arg)); + } + removeNulls(pairs); + } + return n; + } + + @Override public Node visit(final NullLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final ObjectCreationExpr n, final A arg) { + visitComment(n, arg); + if (n.getScope() != null) { + n.setScope((Expression) n.getScope().accept(this, arg)); + } + final List<Type<?>> typeArguments = n.getTypeArguments(); + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + typeArguments.set(i, (Type<?>) typeArguments.get(i).accept(this, arg)); + } + removeNulls(typeArguments); + } + n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); + final List<Expression> args = n.getArgs(); + if (args != null) { + for (int i = 0; i < args.size(); i++) { + args.set(i, (Expression) args.get(i).accept(this, arg)); + } + removeNulls(args); + } + final List<BodyDeclaration<?>> anonymousClassBody = n.getAnonymousClassBody(); + if (anonymousClassBody != null) { + for (int i = 0; i < anonymousClassBody.size(); i++) { + anonymousClassBody.set(i, (BodyDeclaration<?>) anonymousClassBody.get(i).accept(this, arg)); + } + removeNulls(anonymousClassBody); + } + return n; + } + + @Override public Node visit(final PackageDeclaration n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + n.setName((NameExpr) n.getName().accept(this, arg)); + return n; + } + + @Override public Node 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 Node visit(final PrimitiveType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + return n; + } + + @Override public Node visit(final QualifiedNameExpr n, final A arg) { + visitComment(n, arg); + n.setQualifier((NameExpr) n.getQualifier().accept(this, arg)); + return n; + } + + @Override + public Node visit(ArrayType n, A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + n.setComponentType((Type) n.getComponentType().accept(this, arg)); + return n; + } + + @Override + public Node 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 Node visit(final IntersectionType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + final List<ReferenceType> elements = n.getElements(); + if (elements != null) { + for (int i = 0; i < elements.size(); i++) { + elements.set(i, (ReferenceType) elements.get(i).accept(this, arg)); + } + removeNulls(elements); + } + return n; + } + + @Override + public Node visit(final UnionType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + final List<ReferenceType> elements = n.getElements(); + if (elements != null) { + for (int i = 0; i < elements.size(); i++) { + elements.set(i, (ReferenceType) elements.get(i).accept(this, arg)); + } + removeNulls(elements); + } + return n; + } + + @Override public Node 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 Node visit(final SingleMemberAnnotationExpr n, final A arg) { + visitComment(n, arg); + n.setName((NameExpr) n.getName().accept(this, arg)); + n.setMemberValue((Expression) n.getMemberValue().accept(this, arg)); + return n; + } + + @Override public Node visit(final StringLiteralExpr n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node 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 Node visit(final SwitchEntryStmt n, final A arg) { + visitComment(n, arg); + if (n.getLabel() != null) { + n.setLabel((Expression) n.getLabel().accept(this, arg)); + } + final List<Statement> stmts = n.getStmts(); + if (stmts != null) { + for (int i = 0; i < stmts.size(); i++) { + stmts.set(i, (Statement) stmts.get(i).accept(this, arg)); + } + removeNulls(stmts); + } + return n; + } + + @Override public Node visit(final SwitchStmt n, final A arg) { + visitComment(n, arg); + n.setSelector((Expression) n.getSelector().accept(this, arg)); + final List<SwitchEntryStmt> entries = n.getEntries(); + if (entries != null) { + for (int i = 0; i < entries.size(); i++) { + entries.set(i, (SwitchEntryStmt) entries.get(i).accept(this, arg)); + } + removeNulls(entries); + } + return n; + + } + + @Override public Node 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 Node 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 Node visit(final ThrowStmt n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + return n; + } + + @Override public Node visit(final TryStmt n, final A arg) { + visitComment(n, arg); + final List<VariableDeclarationExpr> types = n.getResources(); + for (int i = 0; i < types.size(); i++) { + n.getResources().set(i, + (VariableDeclarationExpr) n.getResources().get(i).accept(this, arg)); + } + n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg)); + final List<CatchClause> catchs = n.getCatchs(); + if (catchs != null) { + for (int i = 0; i < catchs.size(); i++) { + catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg)); + } + removeNulls(catchs); + } + if (n.getFinallyBlock() != null) { + n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg)); + } + return n; + } + + @Override public Node visit(final TypeDeclarationStmt n, final A arg) { + visitComment(n, arg); + n.setTypeDeclaration((TypeDeclaration<?>) n.getTypeDeclaration().accept(this, arg)); + return n; + } + + @Override public Node visit(final TypeParameter n, final A arg) { + visitComment(n, arg); + final List<ClassOrInterfaceType> typeBound = n.getTypeBound(); + if (typeBound != null) { + for (int i = 0; i < typeBound.size(); i++) { + typeBound.set(i, (ClassOrInterfaceType) typeBound.get(i).accept(this, arg)); + } + removeNulls(typeBound); + } + return n; + } + + @Override public Node visit(final UnaryExpr n, final A arg) { + visitComment(n, arg); + n.setExpr((Expression) n.getExpr().accept(this, arg)); + return n; + } + + @Override public Node visit(final UnknownType n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final VariableDeclarationExpr n, final A arg) { + visitComment(n, arg); + final List<AnnotationExpr> annotations = n.getAnnotations(); + if (annotations != null) { + for (int i = 0; i < annotations.size(); i++) { + annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); + } + removeNulls(annotations); + } + + final Type type = (Type) n.getElementType().accept(this, arg); + if (type == null) { + return null; + } + n.setElementType(type); + + final List<VariableDeclarator> vars = n.getVariables(); + for (int i = 0; i < vars.size();) { + final VariableDeclarator decl = (VariableDeclarator) + vars.get(i).accept(this, arg); + if (decl == null) { + vars.remove(i); + } else { + vars.set(i++, decl); + } + } + if (vars.isEmpty()) { + return null; + } + + return n; + } + + @Override public Node 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 Node visit(final VariableDeclaratorId n, final A arg) { + visitComment(n, arg); + return n; + } + + @Override public Node visit(final VoidType n, final A arg) { + visitComment(n, arg); + visitAnnotations(n, arg); + return n; + } + + @Override public Node 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 Node 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 Node visit(final LambdaExpr n, final A arg) { + visitComment(n, arg); + final List<Parameter> parameters = n.getParameters(); + for (int i = 0; i < parameters.size(); i++) { + parameters.set(i, (Parameter) parameters.get(i).accept(this, arg)); + } + removeNulls(parameters); + if (n.getBody() != null) { + n.setBody((Statement) n.getBody().accept(this, arg)); + } + return n; + } + + @Override + public Node visit(final MethodReferenceExpr n, final A arg) { + visitComment(n, arg); + final List<Type<?>> types = n.getTypeArguments(); + for (int i = 0; i < types.size(); i++) { + n.getTypeArguments().set(i, + (Type<?>) n.getTypeArguments().get(i).accept(this, arg)); + } + if (n.getScope() != null) { + n.setScope((Expression)n.getScope().accept(this, arg)); + } + return n; + } + + @Override + public Node visit(final TypeExpr n, final A arg) { + visitComment(n, arg); + if (n.getType() != null) { + n.setType((Type<?>) n.getType().accept(this, arg)); + } + return n; + } + + @Override + public Node visit(ArrayBracketPair n, A arg) { + visitAnnotations(n, arg); + return n; + } + + @Override + public Node visit(final BlockComment n, final A arg) { + return n; + } + + @Override + public Node 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)); + } + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/TreeVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/TreeVisitor.java new file mode 100644 index 000000000..c1b7eaee6 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/TreeVisitor.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.Node; + +/** + * Iterate over all the nodes in (a part of) the AST. + */ +public abstract class TreeVisitor { + + /** + * https://en.wikipedia.org/wiki/Depth-first_search + * + * @param node the start node, and the first one that is passed to process(node). + */ + public void visitDepthFirst(Node node) { + process(node); + for (Node child : node.getChildrenNodes()) { + visitDepthFirst(child); + } + } + + public abstract void process(Node node); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitor.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitor.java new file mode 100644 index 000000000..ec1d0f6a6 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitor.java @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.comments.BlockComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.type.TypeParameter; +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.comments.JavadocComment; +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.expr.*; +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.*; + +/** + * A visitor that does not return anything. + * + * @author Julio Vilmar Gesser + */ +public interface VoidVisitor<A> { + + //- Compilation Unit ---------------------------------- + + void visit(CompilationUnit n, A arg); + + void visit(PackageDeclaration n, A arg); + + void visit(ImportDeclaration n, A arg); + + void visit(TypeParameter n, A arg); + + void visit(LineComment n, A arg); + + void visit(BlockComment n, A arg); + + //- Body ---------------------------------------------- + + void visit(ClassOrInterfaceDeclaration n, A arg); + + void visit(EnumDeclaration n, A arg); + + void visit(EmptyTypeDeclaration n, A arg); + + void visit(EnumConstantDeclaration n, A arg); + + void visit(AnnotationDeclaration n, A arg); + + void visit(AnnotationMemberDeclaration n, A arg); + + void visit(FieldDeclaration n, A arg); + + void visit(VariableDeclarator n, A arg); + + void visit(VariableDeclaratorId n, A arg); + + void visit(ConstructorDeclaration n, A arg); + + void visit(MethodDeclaration n, A arg); + + void visit(Parameter n, A arg); + + void visit(EmptyMemberDeclaration n, A arg); + + void visit(InitializerDeclaration n, A arg); + + void visit(JavadocComment n, A arg); + + //- Type ---------------------------------------------- + + void visit(ClassOrInterfaceType n, A arg); + + void visit(PrimitiveType n, A arg); + + void visit(ArrayType n, A arg); + + void visit(ArrayCreationLevel n, A arg); + + void visit(IntersectionType n, A arg); + + void visit(UnionType n, A arg); + + void visit(VoidType n, A arg); + + void visit(WildcardType n, A arg); + + void visit(UnknownType n, A arg); + + //- Expression ---------------------------------------- + + void visit(ArrayAccessExpr n, A arg); + + void visit(ArrayCreationExpr n, A arg); + + void visit(ArrayInitializerExpr n, A arg); + + void visit(AssignExpr n, A arg); + + void visit(BinaryExpr n, A arg); + + void visit(CastExpr n, A arg); + + void visit(ClassExpr n, A arg); + + void visit(ConditionalExpr n, A arg); + + void visit(EnclosedExpr n, A arg); + + void visit(FieldAccessExpr n, A arg); + + void visit(InstanceOfExpr n, A arg); + + void visit(StringLiteralExpr n, A arg); + + void visit(IntegerLiteralExpr n, A arg); + + void visit(LongLiteralExpr n, A arg); + + void visit(IntegerLiteralMinValueExpr n, A arg); + + void visit(LongLiteralMinValueExpr n, A arg); + + void visit(CharLiteralExpr n, A arg); + + void visit(DoubleLiteralExpr n, A arg); + + void visit(BooleanLiteralExpr n, A arg); + + void visit(NullLiteralExpr n, A arg); + + void visit(MethodCallExpr n, A arg); + + void visit(NameExpr n, A arg); + + void visit(ObjectCreationExpr n, A arg); + + void visit(QualifiedNameExpr n, A arg); + + void visit(ThisExpr n, A arg); + + void visit(SuperExpr n, A arg); + + void visit(UnaryExpr n, A arg); + + void visit(VariableDeclarationExpr n, A arg); + + void visit(MarkerAnnotationExpr n, A arg); + + void visit(SingleMemberAnnotationExpr n, A arg); + + void visit(NormalAnnotationExpr n, A arg); + + void visit(MemberValuePair n, A arg); + + //- Statements ---------------------------------------- + + void visit(ExplicitConstructorInvocationStmt n, A arg); + + void visit(TypeDeclarationStmt n, A arg); + + void visit(AssertStmt n, A arg); + + void visit(BlockStmt n, A arg); + + void visit(LabeledStmt n, A arg); + + void visit(EmptyStmt n, A arg); + + void visit(ExpressionStmt n, A arg); + + void visit(SwitchStmt n, A arg); + + void visit(SwitchEntryStmt n, A arg); + + void visit(BreakStmt n, A arg); + + void visit(ReturnStmt n, A arg); + + void visit(IfStmt n, A arg); + + void visit(WhileStmt n, A arg); + + void visit(ContinueStmt n, A arg); + + void visit(DoStmt n, A arg); + + void visit(ForeachStmt n, A arg); + + void visit(ForStmt n, A arg); + + void visit(ThrowStmt n, A arg); + + void visit(SynchronizedStmt n, A arg); + + void visit(TryStmt n, A arg); + + void visit(CatchClause n, A arg); + + void visit(LambdaExpr n, A arg); + + void visit(MethodReferenceExpr n, A arg); + + void visit(TypeExpr n, A arg); + + void visit(ArrayBracketPair arrayBracketPair, A arg); +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java new file mode 100644 index 000000000..cab3ef496 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -0,0 +1,806 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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.stmt.*; +import com.github.javaparser.ast.type.TypeParameter; +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.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.QualifiedNameExpr; +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.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.type.*; + +/** + * @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.getNameExpr().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.getType().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.getNameExpr().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) { + 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.getNameExpr().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.getNameExpr().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) { + 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.getNameExpr().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.getFieldExpr().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 ImportDeclaration n, final A arg) { + visitComment(n.getComment(), arg); + n.getName().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.getNameExpr().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.getNameExpr().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 QualifiedNameExpr n, final A arg) { + visitComment(n.getComment(), arg); + n.getQualifier().accept(this, arg); + } + + @Override + 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(final IntersectionType n, final A arg) { + visitComment(n.getComment(), arg); + visitAnnotations(n, arg); + for (ReferenceType element : n.getElements()) { + element.accept(this, arg); + } + } + + @Override public void visit(final UnionType n, final A arg) { + visitComment(n.getComment(), arg); + 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(LambdaExpr n, final A arg) { + visitComment(n.getComment(), arg); + if (n.getParameters() != null) { + for (final Parameter a : n.getParameters()) { + a.accept(this, arg); + } + } + if (n.getBody() != null) { + n.getBody().accept(this, arg); + } + } + + @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); + } + } + if (n.getScope() != null) { + n.getScope().accept(this, arg); + } + } + + @Override + public void visit(TypeExpr n, final A 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); + } + + 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-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/ClassUtils.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/ClassUtils.java new file mode 100644 index 000000000..476986812 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/ClassUtils.java @@ -0,0 +1,69 @@ +package com.github.javaparser.utils; + +import java.util.HashMap; +import java.util.Map; + +public class ClassUtils { + /** + * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. + */ + private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap<Class<?>, Class<?>>(); + static { + primitiveWrapperMap.put(Boolean.TYPE, Boolean.class); + primitiveWrapperMap.put(Byte.TYPE, Byte.class); + primitiveWrapperMap.put(Character.TYPE, Character.class); + primitiveWrapperMap.put(Short.TYPE, Short.class); + primitiveWrapperMap.put(Integer.TYPE, Integer.class); + primitiveWrapperMap.put(Long.TYPE, Long.class); + primitiveWrapperMap.put(Double.TYPE, Double.class); + primitiveWrapperMap.put(Float.TYPE, Float.class); + primitiveWrapperMap.put(Void.TYPE, Void.TYPE); + } + + /** + * Maps wrapper {@code Class}es to their corresponding primitive types. + */ + private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<Class<?>, Class<?>>(); + static { + for (final Class<?> primitiveClass : primitiveWrapperMap.keySet()) { + final Class<?> wrapperClass = primitiveWrapperMap.get(primitiveClass); + if (!primitiveClass.equals(wrapperClass)) { + wrapperPrimitiveMap.put(wrapperClass, primitiveClass); + } + } + } + + /** + * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, + * {@link Character}, + * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * + * @param type + * The class to query or null. + * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, + * {@link Character}, + * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + */ + public static boolean isPrimitiveOrWrapper(final Class<?> type) { + if (type == null) { + return false; + } + return type.isPrimitive() || isPrimitiveWrapper(type); + } + + /** + * Returns whether the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, + * {@link Short}, + * {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * + * @param type + * The class to query or null. + * @return true if the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, + * {@link Short}, + * {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * @since 3.1 + */ + public static boolean isPrimitiveWrapper(final Class<?> type) { + return wrapperPrimitiveMap.containsKey(type); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Pair.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Pair.java new file mode 100644 index 000000000..40ce85d83 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Pair.java @@ -0,0 +1,16 @@ +package com.github.javaparser.utils; + +/** + * Simply a pair of objects. + * @param <A> type of object a. + * @param <B> type of object b. + */ +public class Pair<A, B> { + public final A a; + public final B b; + + public Pair(A a, B b) { + this.a = a; + this.b = b; + } +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/PositionUtils.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/PositionUtils.java new file mode 100644 index 000000000..e1ecf190e --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/PositionUtils.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import static java.lang.Integer.signum; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithElementType; +import com.github.javaparser.ast.nodeTypes.NodeWithType; + +public final class PositionUtils { + + private PositionUtils() { + // prevent instantiation + } + + public static <T extends Node> void sortByBeginPosition(List<T> nodes){ + sortByBeginPosition(nodes, false); + } + + public static <T extends Node> void sortByBeginPosition(List<T> nodes, final boolean ignoringAnnotations){ + Collections.sort(nodes, (o1, o2) -> PositionUtils.compare(o1, o2, ignoringAnnotations)); + } + + public static boolean areInOrder(Node a, Node b){ + return areInOrder(a, b, false); + } + + public static boolean areInOrder(Node a, Node b, boolean ignoringAnnotations){ + return compare(a, b, ignoringAnnotations) <= 0; + } + + private static int compare(Node a, Node b, boolean ignoringAnnotations) { + if (ignoringAnnotations) { + int signLine = signum(beginLineWithoutConsideringAnnotation(a) - beginLineWithoutConsideringAnnotation(b)); + if (signLine == 0) { + return signum(beginColumnWithoutConsideringAnnotation(a) - beginColumnWithoutConsideringAnnotation(b)); + } else { + return signLine; + } + } + + int signLine = signum( a.getBegin().line - b.getBegin().line ); + if (signLine == 0) { + return signum(a.getBegin().column - b.getBegin().column); + } else { + return signLine; + } + } + + public static AnnotationExpr getLastAnnotation(Node node) { + if (node instanceof NodeWithAnnotations){ + List<AnnotationExpr> annotations = new LinkedList<>(); + annotations.addAll(((NodeWithAnnotations<?>) node).getAnnotations()); + if (annotations.isEmpty()){ + return null; + } + sortByBeginPosition(annotations); + return annotations.get(annotations.size()-1); + } else { + return null; + } + } + + private static int beginLineWithoutConsideringAnnotation(Node node) { + return beginNodeWithoutConsideringAnnotations(node).getBegin().line; + } + + + private static int beginColumnWithoutConsideringAnnotation(Node node) { + return beginNodeWithoutConsideringAnnotations(node).getBegin().column; + } + + private static Node beginNodeWithoutConsideringAnnotations(Node node) { + if (node instanceof MethodDeclaration || node instanceof FieldDeclaration) { + NodeWithElementType<?> casted = (NodeWithElementType<?>) node; + return casted.getElementType(); + } else if (node instanceof ClassOrInterfaceDeclaration) { + ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; + return casted.getNameExpr(); + } else { + return node; + } + } + + public static boolean nodeContains(Node container, Node contained, boolean ignoringAnnotations){ + if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container)==null){ + return container.contains(contained); + } + if (!container.contains(contained)){ + return false; + } + // if the node is contained, but it comes immediately after the annotations, + // let's not consider it contained + if (container instanceof NodeWithAnnotations){ + int bl = beginLineWithoutConsideringAnnotation(container); + int bc = beginColumnWithoutConsideringAnnotation(container); + if (bl>contained.getBegin().line) return false; + if (bl==contained.getBegin().line && bc>contained.getBegin().column) return false; + if (container.getEnd().line<contained.getEnd().line) return false; + // TODO < or <= ? + return !(container.getEnd().line == contained.getEnd().line && container.getEnd().column < contained.getEnd().column); + } + return true; + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Utils.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Utils.java new file mode 100644 index 000000000..b9320852d --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/utils/Utils.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import com.github.javaparser.Provider; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.Reader; +import java.util.*; + +/** + * Any kind of utility. + * + * @author Federico Tomassetti + */ +public class Utils { + public static final String EOL = System.getProperty("line.separator"); + public static <T> List<T> ensureNotNull(List<T> list) { + return list == null ? new ArrayList<T>() : list; + } + + public static <E> boolean isNullOrEmpty(Collection<E> collection) { + return collection == null || collection.isEmpty(); + } + + public static <T> T assertNotNull(T o) { + if (o == null) { + throw new NullPointerException("Assertion failed."); + } + return o; + } + + /** + * @return string with ASCII characters 10 and 13 replaced by the text "\n" and "\r". + */ + public static String escapeEndOfLines(String string) { + StringBuilder escapedString = new StringBuilder(); + for (char c : string.toCharArray()) { + switch (c) { + case '\n': + escapedString.append("\\n"); + break; + case '\r': + escapedString.append("\\r"); + break; + default: + escapedString.append(c); + } + } + return escapedString.toString(); + } + + public static String readerToString(Reader reader) throws IOException { + final StringBuilder result = new StringBuilder(); + final char[] buffer = new char[8 * 1024]; + int numChars; + + while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) { + result.append(buffer, 0, numChars); + } + + return result.toString(); + } + + public static String providerToString(Provider provider) throws IOException { + final StringBuilder result = new StringBuilder(); + final char[] buffer = new char[8 * 1024]; + int numChars; + + while ((numChars = provider.read(buffer, 0, buffer.length)) != -1) { + result.append(buffer, 0, numChars); + } + + return result.toString(); + } + + /** + * Puts varargs in a mutable list. + * This does not have the disadvantage of Arrays#asList that it has a static size. + */ + public static <T> List<T> arrayToList(T[] array){ + List<T> list = new LinkedList<>(); + Collections.addAll(list, array); + return list; + } + +} |