data: java sample project

* added javaparser as sample project
* fixed crash in utility::isPrefix when prefix is longer than the actual string
* fixed crash when inserting a meta value that contains a special character
* added "language" to project settings of tutorial
* changed separators in serialized name hierarchy
* added javaparser project to windows installers
* enabled the checkbox for start menu shortcut in installer by default
* removed autorefresh icon
* removed JavaSmallTest project
This commit is contained in:
malte_langkabel
2016-08-25 15:18:00 +02:00
parent 520a1b2d48
commit 0268e924aa
164 changed files with 47237 additions and 403 deletions
@@ -0,0 +1,232 @@
/*
* 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.CommentsCollection;
import com.github.javaparser.ast.comments.CommentsParser;
import com.github.javaparser.ast.comments.LineComment;
import com.github.javaparser.utils.PositionUtils;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Assigns comments to nodes of the AST.
*
* @author Sebastian Kuerten
* @author Júlio Vilmar Gesser
*/
class CommentsInserter {
private boolean doNotAssignCommentsPreceedingEmptyLines = true;
private boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false;
CommentsInserter() {
}
/**
* Adds the comments found in the source code of a compilation unit to that compilation unit.
* @param cu an already created compilation unit
* @param cuSourceCode the source code of the compilation unit. It will be parsed to find comments.
*/
public void insertComments(CompilationUnit cu, String cuSourceCode) throws IOException {
CommentsParser commentsParser = new CommentsParser();
CommentsCollection allComments = commentsParser.parse(cuSourceCode);
insertCommentsInCu(cu, allComments);
}
public boolean getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() {
return doNotConsiderAnnotationsAsNodeStartForCodeAttribution;
}
public void setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean newValue) {
this.doNotConsiderAnnotationsAsNodeStartForCodeAttribution = newValue;
}
public boolean getDoNotAssignCommentsPreceedingEmptyLines() {
return doNotAssignCommentsPreceedingEmptyLines;
}
public void setDoNotAssignCommentsPreceedingEmptyLines(boolean newValue) {
this.doNotAssignCommentsPreceedingEmptyLines = newValue;
}
/**
* Comments are attributed to the thing the comment and are removed from
* allComments.
*/
private void insertCommentsInCu(CompilationUnit cu,
CommentsCollection commentsCollection) {
if (commentsCollection.size() == 0)
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<Comment> comments = commentsCollection.getAll();
PositionUtils.sortByBeginPosition(comments);
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
if (cu.getPackage() != null
&& (children.isEmpty() || PositionUtils.areInOrder(
comments.get(0), children.get(0)))) {
cu.setComment(comments.get(0));
comments.remove(0);
}
insertCommentsInNode(cu, comments);
}
/**
* This method try to attributes the nodes received to child of the node. It
* returns the node that were not attributed.
*/
private void insertCommentsInNode(Node node,
List<Comment> commentsToAttribute) {
if (commentsToAttribute.isEmpty())
return;
// 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) {
List<Comment> commentsInsideChild = new LinkedList<Comment>();
for (Comment c : commentsToAttribute) {
if (PositionUtils.nodeContains(child, c,
doNotConsiderAnnotationsAsNodeStartForCodeAttribution)) {
commentsInsideChild.add(c);
}
}
commentsToAttribute.removeAll(commentsInsideChild);
insertCommentsInNode(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<Comment>();
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<Comment>();
List<Node> childrenAndComments = new LinkedList<Node>();
childrenAndComments.addAll(children);
childrenAndComments.addAll(commentsToAttribute);
PositionUtils.sortByBeginPosition(childrenAndComments,
doNotConsiderAnnotationsAsNodeStartForCodeAttribution);
for (Node thing : childrenAndComments) {
if (thing instanceof Comment) {
previousComment = (Comment) thing;
if (!previousComment.isOrphan()) {
previousComment = null;
}
} else {
if (previousComment != null && !thing.hasComment()) {
if (!doNotAssignCommentsPreceedingEmptyLines
|| !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);
}
}
@@ -0,0 +1,563 @@
/*
* 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 java.io.*;
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;
import java.nio.charset.Charset;
import java.util.List;
import static com.github.javaparser.utils.Utils.readerToString;
/**
* Parse Java source code and creates Abstract Syntax Tree classes.
*
* @author Júlio Vilmar Gesser
*/
public final class JavaParser {
private static final CommentsInserter commentsInserter = new CommentsInserter();
private static final Charset UTF8 = Charset.forName("utf-8");
private ASTParser astParser = null;
private Provider provider = null;
/**
* 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() {
// No specific constructors for this class.
}
public JavaParser setSource(Provider provider) {
this.provider=provider;
if(astParser==null) {
astParser = new ASTParser(provider);
}else{
astParser.ReInit(provider);
}
return this;
}
public JavaParser setSource(Reader reader) {
return setSource(new StreamProvider(reader));
}
public JavaParser setSource(InputStream input) throws IOException {
return setSource(new StreamProvider(input));
}
public JavaParser setSource(InputStream input, Charset encoding) throws IOException {
return setSource(new StreamProvider(input, encoding.name()));
}
public JavaParser setSource(File file) throws IOException {
return setSource(new FileInputStream(file));
}
public JavaParser setSource(File file, Charset encoding) throws IOException {
return setSource(new FileInputStream(file), encoding);
}
public JavaParser setSource(String source) {
return setSource(new StringReader(source));
}
/**
* Return the list of tokens that have been encountered while parsing code
* using this parser.
*
* @return a list of tokens
*/
public List<Token> getTokens() {
checkSourceSet();
return astParser.getTokens();
}
private void checkSourceSet() {
if (astParser == null || provider == null) {
throw new IllegalStateException("Please setSource() before doing any parsing.");
}
}
/**
* Parses the Java code and returns a {@link CompilationUnit} that
* represents it.
*
* @return CompilationUnit representing the Java source code
* @throws ParseException
* if the source code has parser errors
*/
public CompilationUnit parse() throws ParseException {
try {
checkSourceSet();
return astParser.CompilationUnit();
} finally {
closeProvider();
}
}
private void closeProvider() {
try {
checkSourceSet();
provider.close();
} catch (IOException e) {
// Since we're done parsing and have our result, we don't care about any errors.
}
}
/**
* Parses the Java block and returns a {@link BlockStmt} that represents it.
*
* @return BlockStmt representing the Java block
* @throws ParseException
* if the source code has parser errors
*/
public BlockStmt parseBlock() throws ParseException {
try{
checkSourceSet();
return astParser.Block();
} finally {
closeProvider();
}
}
/**
* Parses the Java block and returns a {@link List} of {@link Statement}s
* that represents it.
*
* @return Statement representing the Java statement
* @throws ParseException
* if the source code has parser errors
*/
public List<Statement> parseStatements() throws ParseException {
try {
checkSourceSet();
return astParser.Statements();
} finally {
closeProvider();
}
}
/**
* Parses the Java statement and returns a {@link Statement} that represents
* it.
*
* @return Statement representing the Java statement
* @throws ParseException
* if the source code has parser errors
*/
public Statement parseStatement() throws ParseException {
try {
checkSourceSet();
return astParser.Statement();
} finally {
closeProvider();
}
}
/**
* Parses the Java import and returns a {@link ImportDeclaration} that
* represents it.
*
* @return ImportDeclaration representing the Java import declaration
* @throws ParseException
* if the source code has parser errors
*/
public ImportDeclaration parseImport() throws ParseException {
try {
checkSourceSet();
return astParser.ImportDeclaration();
} finally {
closeProvider();
}
}
/**
* Parses the Java expression and returns a {@link Expression} that
* represents it.
*
* @return Expression representing the Java expression
* @throws ParseException
* if the source code has parser errors
*/
public Expression parseExpression() throws ParseException {
try {
checkSourceSet();
return astParser.Expression();
} finally {
closeProvider();
}
}
/**
* Parses the Java annotation and returns a {@link AnnotationExpr} that
* represents it.
*
* @return AnnotationExpr representing the Java annotation
* @throws ParseException
* if the source code has parser errors
*/
public AnnotationExpr parseAnnotation() throws ParseException {
try {
checkSourceSet();
return astParser.Annotation();
} finally {
closeProvider();
}
}
/**
* Parses the Java body declaration(e.g fields or methods) and returns a
* {@link BodyDeclaration} that represents it.
*
* @return BodyDeclaration representing the Java body
* @throws ParseException
* if the source code has parser errors
*/
public BodyDeclaration<?> parseBodyDeclaration() throws ParseException {
try {
checkSourceSet();
return astParser.AnnotationBodyDeclaration();
} finally {
closeProvider();
}
}
/**
* Parses a Java class body declaration(e.g fields or methods) and returns a
* {@link BodyDeclaration} that represents it.
*
* @return BodyDeclaration representing the Java class body
* @throws ParseException
* if the source code has parser errors
*/
public BodyDeclaration<?> parseClassBodyDeclaration() throws ParseException {
try {
checkSourceSet();
return astParser.ClassOrInterfaceBodyDeclaration(false);
} finally {
closeProvider();
}
}
/**
* Parses a Java interface body declaration(e.g fields or methods) and returns a
* {@link BodyDeclaration} that represents it.
*
* @return BodyDeclaration representing the Java interface body
* @throws ParseException
* if the source code has parser errors
*/
public BodyDeclaration<?> parseInterfaceBodyDeclaration() throws ParseException {
try {
checkSourceSet();
return astParser.ClassOrInterfaceBodyDeclaration(true);
} finally {
closeProvider();
}
}
public static boolean getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() {
return commentsInserter.getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution();
}
public static void setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean newValue) {
commentsInserter.setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(newValue);
}
public static boolean getDoNotAssignCommentsPreceedingEmptyLines() {
return commentsInserter.getDoNotAssignCommentsPreceedingEmptyLines();
}
public static void setDoNotAssignCommentsPreceedingEmptyLines(boolean newValue) {
commentsInserter.setDoNotAssignCommentsPreceedingEmptyLines(newValue);
}
public static CompilationUnit parse(final InputStream in,
final Charset encoding) throws ParseException {
return parse(in,encoding,true);
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static CompilationUnit parse(final InputStream in,
Charset encoding,
boolean considerComments) throws ParseException {
try {
try (InputStreamReader inputStreamReader = new InputStreamReader(in, encoding)) {
return parse(inputStreamReader, considerComments);
}
} catch (IOException ioe) {
throw new ParseException(ioe.getMessage());
}
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static CompilationUnit parse(final InputStream in)
throws ParseException {
return parse(in, UTF8, true);
}
public static CompilationUnit parse(final File file, final Charset encoding)
throws ParseException, IOException {
return parse(file,encoding,true);
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static CompilationUnit parse(final File file, final Charset encoding, boolean considerComments)
throws ParseException {
try {
try (FileInputStream in = new FileInputStream(file)) {
return parse(in, encoding, considerComments);
}
} catch (IOException ioe) {
throw new ParseException(ioe.getMessage());
}
}
/**
* 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 ParseException
* if the source code has parser errors
* @throws IOException
*/
public static CompilationUnit parse(final File file) throws ParseException,
IOException {
return parse(file, UTF8, true);
}
public static CompilationUnit parse(final Reader reader)
throws ParseException {
return parse(reader, true);
}
public static CompilationUnit parse(final Reader reader, boolean considerComments)
throws ParseException {
try {
String comments = readerToString(reader);
CompilationUnit cu = new JavaParser().setSource(comments).parse();
if (considerComments){
commentsInserter.insertComments(cu, comments);
}
return cu;
} catch (IOException ioe){
throw new ParseException(ioe.getMessage());
}
}
/**
* Parses the Java code contained in code and returns a
* {@link CompilationUnit} that represents it.
*
* @param code Java source code
* @param considerComments parse or ignore comments
* @return CompilationUnit representing the Java source code
* @throws ParseException if the source code has parser errors
*/
public static CompilationUnit parse(String code, boolean considerComments) throws ParseException {
return parse(new StringReader(code), considerComments);
}
/**
* 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 ParseException if the source code has parser errors
*/
public static CompilationUnit parse(String code) throws ParseException {
return parse(code, true);
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static BlockStmt parseBlock(final String blockStatement)
throws ParseException {
return new JavaParser().setSource(blockStatement).parseBlock();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static Statement parseStatement(final String statement) throws ParseException {
return new JavaParser().setSource(statement).parseStatement();
}
/**
* Parses the Java statements contained in a {@link String} and returns a
* list of {@link Statement} that represents it.
*
* @param statements
* {@link String} containing Java statements
* @return list of Statement representing the Java statement
* @throws ParseException
* if the source code has parser errors
*/
public static List<Statement> parseStatements(final String statements) throws ParseException {
return new JavaParser().setSource(statements).parseStatements();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static ImportDeclaration parseImport(final String importDeclaration) throws ParseException {
return new JavaParser().setSource(importDeclaration).parseImport();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static Expression parseExpression(final String expression) throws ParseException {
return new JavaParser().setSource(expression).parseExpression();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static AnnotationExpr parseAnnotation(final String annotation) throws ParseException {
return new JavaParser().setSource(annotation).parseAnnotation();
}
/**
* Parses the Java 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 ParseException
* if the source code has parser errors
*/
public static BodyDeclaration<?> parseBodyDeclaration(final String body) throws ParseException {
return new JavaParser().setSource(body).parseBodyDeclaration();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static BodyDeclaration<?> parseClassBodyDeclaration(String body) throws ParseException {
return new JavaParser().setSource(body).parseClassBodyDeclaration();
}
/**
* 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 ParseException
* if the source code has parser errors
*/
public static BodyDeclaration parseInterfaceBodyDeclaration(String body) throws ParseException {
return new JavaParser().setSource(body).parseInterfaceBodyDeclaration();
}
}
@@ -0,0 +1,137 @@
/*
* 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;
/**
* 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) {
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) {
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) {
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 + ")";
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -0,0 +1,404 @@
/*
* 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.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.AnnotationDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.EmptyTypeDeclaration;
import com.github.javaparser.ast.body.EnumDeclaration;
import com.github.javaparser.ast.body.TypeDeclaration;
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* <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 void 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 void setImports(List<ImportDeclaration> imports) {
this.imports = imports;
setAsParentNodeOf(this.imports);
}
/**
* 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 void setPackage(PackageDeclaration pakage) {
this.pakage = pakage;
setAsParentNodeOf(this.pakage);
}
/**
* Sets the list of types declared in this compilation unit.
*
* @param types
* the lis of types
*/
public void setTypes(List<TypeDeclaration<?>> types) {
this.types = types;
setAsParentNodeOf(this.types);
}
/**
* 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(NameExpr.create(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(NameExpr.create(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);
}
}
@@ -0,0 +1,185 @@
/*
* 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 void setAsterisk(boolean asterisk) {
if (isEmptyImportDeclaration && asterisk) {
throw new UnsupportedOperationException("Empty import cannot have asterisk");
}
this.asterisk = asterisk;
}
/**
* Sets the name this import.
*
* @param name
* the name to set
* @throws UnsupportedOperationException when invoked on an empty import declaration
*/
public void setName(NameExpr name) {
if (isEmptyImportDeclaration) {
throw new UnsupportedOperationException("Empty import cannot have name");
}
this.name = name;
setAsParentNodeOf(this.name);
}
/**
* 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 void setStatic(boolean static_) {
if (isEmptyImportDeclaration && static_) {
throw new UnsupportedOperationException("Empty import cannot be static");
}
this.static_ = static_;
}
}
@@ -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;
}
}
}
@@ -0,0 +1,372 @@
/*
* 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.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* 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 {
private Range range;
private Node parentNode;
private List<Node> childrenNodes = new LinkedList<>();
private List<Comment> orphanComments = new LinkedList<>();
/**
* This attribute can store additional information from semantic analysis.
*/
private Object data;
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;
}
/**
* Use this to retrieve additional information associated to this node.
*
* @return data property
*/
public final Object getData() {
return data;
}
/**
* 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 void setBegin(Position begin) {
range = range.withBegin(begin);
}
/**
* Sets the end position of this node in the source file.
*/
public void setEnd(Position end) {
range = range.withEnd(end);
}
/**
* @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 void setRange(Range range) {
this.range = range;
}
/**
* Use this to store additional information to this node.
*
* @param comment to be set
*/
public final void 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);
}
}
/**
* Use this to store additional information to this node.
*
* @param comment to be set
*/
public final void setLineComment(String comment) {
setComment(new LineComment(comment));
}
/**
* Use this to store additional information to this node.
*
* @param comment to be set
*/
public final void setBlockComment(String comment) {
setComment(new BlockComment(comment));
}
/**
* Use this to store additional information to this node.
*
* @param data to be set
*/
public final void setData(final Object data) {
this.data = data;
}
/**
* 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;
}
}
@@ -0,0 +1,127 @@
/*
* 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.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 {
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 void setAnnotations(List<AnnotationExpr> annotations) {
this.annotations = annotations;
setAsParentNodeOf(this.annotations);
}
/**
* Sets the name of this package declaration.
*
* @param name
* the name to set
*/
public void setName(NameExpr name) {
this.name = name;
setAsParentNodeOf(this.name);
}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 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.ast.type.Type;
import java.util.Collections;
import java.util.List;
import static com.github.javaparser.utils.Utils.ensureNotNull;
public class TypeArguments {
public static final TypeArguments EMPTY = withArguments(Collections.<Type>emptyList());
private final List<Type> typeArguments;
private final boolean usesDiamondOperator;
private TypeArguments(List<Type> typeArguments, boolean usesDiamondOperator) {
this.typeArguments = ensureNotNull(typeArguments);
this.usesDiamondOperator = usesDiamondOperator;
}
public List<Type> getTypeArguments() {
return typeArguments;
}
public boolean isUsingDiamondOperator() {
return usesDiamondOperator;
}
public static TypeArguments withDiamondOperator() {
return new TypeArguments(Collections.<Type>emptyList(), true);
}
public static TypeArguments withArguments(List<Type> typeArguments) {
return new TypeArguments(typeArguments, false);
}
}
@@ -0,0 +1,136 @@
/*
* 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.utils.Utils.ensureNotNull;
import java.util.List;
import com.github.javaparser.Range;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.NodeWithName;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* <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 Node 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 void setTypeBound(final List<ClassOrInterfaceType> typeBound) {
this.typeBound = typeBound;
setAsParentNodeOf(typeBound);
}
public List<AnnotationExpr> getAnnotations() {
annotations = ensureNotNull(annotations);
return annotations;
}
public void setAnnotations(List<AnnotationExpr> annotations) {
this.annotations = annotations;
setAsParentNodeOf(this.annotations);
}
}
@@ -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);
}
}
@@ -0,0 +1,149 @@
/*
* 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 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.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;
/**
* @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 void setDefaultValue(Expression defaultValue) {
this.defaultValue = defaultValue;
setAsParentNodeOf(defaultValue);
}
@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;
}
}
@@ -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.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.Node;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
import com.github.javaparser.ast.nodeTypes.NodeWithName;
public abstract class BaseParameter<T>
extends Node
implements NodeWithAnnotations<T>, NodeWithName<T>, NodeWithModifiers<T> {
private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
private List<AnnotationExpr> annotations;
private VariableDeclaratorId id;
public BaseParameter() {
}
public BaseParameter(VariableDeclaratorId id) {
setId(id);
}
public BaseParameter(EnumSet<Modifier> modifiers, VariableDeclaratorId id) {
setModifiers(modifiers);
setId(id);
}
public BaseParameter(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
setModifiers(modifiers);
setAnnotations(annotations);
setId(id);
}
public BaseParameter(final Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
super(range);
setModifiers(modifiers);
setAnnotations(annotations);
setId(id);
}
/**
* @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 T setName(String name) {
if (id != null)
id.setName(name);
else
id = new VariableDeclaratorId(name);
return (T) 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 T setAnnotations(List<AnnotationExpr> annotations) {
this.annotations = annotations;
setAsParentNodeOf(this.annotations);
return (T) this;
}
public void setId(VariableDeclaratorId id) {
this.id = id;
setAsParentNodeOf(this.id);
}
@Override
@SuppressWarnings("unchecked")
public T setModifiers(EnumSet<Modifier> modifiers) {
this.modifiers = modifiers;
return (T) this;
}
}
@@ -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;
}
}
@@ -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.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.TypeParameter;
import com.github.javaparser.ast.expr.AnnotationExpr;
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 ClassOrInterfaceDeclaration extends TypeDeclaration<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;
}
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
*/
public void setExtends(final List<ClassOrInterfaceType> extendsList) {
this.extendsList = extendsList;
setAsParentNodeOf(this.extendsList);
}
/**
*
* @param implementsList a null value is currently treated as an empty list. This behavior could change
* in the future, so please avoid passing null
*/
public void setImplements(final List<ClassOrInterfaceType> implementsList) {
this.implementsList = implementsList;
setAsParentNodeOf(this.implementsList);
}
public void setInterface(final boolean interface_) {
this.interface_ = interface_;
}
/**
*
* @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 void setTypeParameters(final List<TypeParameter> typeParameters) {
this.typeParameters = typeParameters;
setAsParentNodeOf(this.typeParameters);
}
/**
* Add an extends to this class or interface and automatically add the import
*
* @param clazz the class to extand from
* @return this, the {@link ClassOrInterfaceDeclaration}
*/
public ClassOrInterfaceDeclaration addExtends(Class<?> clazz) {
tryAddImportToParentCompilationUnit(clazz);
return addExtends(clazz.getSimpleName());
}
/**
* Add an extends to this class or interface
*
* @param name the name of the type to extends from
* @return this, the {@link ClassOrInterfaceDeclaration}
*/
public ClassOrInterfaceDeclaration addExtends(String name) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
getExtends().add(classOrInterfaceType);
classOrInterfaceType.setParentNode(this);
return this;
}
/**
* Add an implements to this class or interface
*
* @param name the name of the type to extends from
* @return this, the {@link ClassOrInterfaceDeclaration}
*/
public ClassOrInterfaceDeclaration addImplements(String name) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
getImplements().add(classOrInterfaceType);
classOrInterfaceType.setParentNode(this);
return this;
}
/**
* Add an implements to this class or interface and automatically add the import
*
* @param clazz the type to implements from
* @return this, the {@link ClassOrInterfaceDeclaration}
*/
public ClassOrInterfaceDeclaration addImplements(Class<?> clazz) {
tryAddImportToParentCompilationUnit(clazz);
return addImplements(clazz.getSimpleName());
}
}
@@ -0,0 +1,261 @@
/*
* 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.AccessSpecifier;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.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.NodeWithBlockStmt;
import com.github.javaparser.ast.nodeTypes.NodeWithDeclaration;
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.NodeWithParameters;
import com.github.javaparser.ast.nodeTypes.NodeWithThrowable;
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;
/**
* @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 void setTypeParameters(List<TypeParameter> typeParameters) {
this.typeParameters = typeParameters;
setAsParentNodeOf(this.typeParameters);
}
/**
* 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.getType().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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -0,0 +1,126 @@
/*
* 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.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;
/**
* @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 void setArgs(List<Expression> args) {
this.args = args;
setAsParentNodeOf(this.args);
}
public void setClassBody(List<BodyDeclaration<?>> classBody) {
this.classBody = classBody;
setAsParentNodeOf(this.classBody);
}
@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(NameExpr.create(valueExpr));
return this;
}
}
@@ -0,0 +1,132 @@
/*
* 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.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> {
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;
}
public List<ClassOrInterfaceType> getImplements() {
implementsList = ensureNotNull(implementsList);
return implementsList;
}
public EnumDeclaration setEntries(List<EnumConstantDeclaration> entries) {
this.entries = entries;
setAsParentNodeOf(this.entries);
return this;
}
public EnumDeclaration setImplements(List<ClassOrInterfaceType> implementsList) {
this.implementsList = implementsList;
setAsParentNodeOf(this.implementsList);
return this;
}
/**
* Add an implements to this enum
*
* @param name the name of the type to extends from
* @return this, the {@link EnumDeclaration}
*/
public EnumDeclaration addImplements(String name) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
getImplements().add(classOrInterfaceType);
classOrInterfaceType.setParentNode(this);
return this;
}
/**
* Add an implements to this enum and automatically add the import
*
* @param clazz the type to implements from
* @return this, the {@link EnumDeclaration}
*/
public EnumDeclaration addImplements(Class<?> clazz) {
tryAddImportToParentCompilationUnit(clazz);
return addImplements(clazz.getSimpleName());
}
public EnumConstantDeclaration addEnumConstant(String name) {
EnumConstantDeclaration enumConstant = new EnumConstantDeclaration(name);
getEntries().add(enumConstant);
enumConstant.setParentNode(this);
return enumConstant;
}
}
@@ -0,0 +1,251 @@
/*
* 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.Modifier.*;
import static com.github.javaparser.ast.type.VoidType.*;
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.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.NodeWithJavaDoc;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
import com.github.javaparser.ast.nodeTypes.NodeWithType;
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.type.VoidType;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* @author Julio Vilmar Gesser
*/
public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration>
implements NodeWithJavaDoc<FieldDeclaration>, NodeWithType<FieldDeclaration>,
NodeWithModifiers<FieldDeclaration> {
private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
private Type type;
private List<VariableDeclarator> variables;
public FieldDeclaration() {
}
public FieldDeclaration(EnumSet<Modifier> modifiers, Type type, VariableDeclarator variable) {
setModifiers(modifiers);
setType(type);
List<VariableDeclarator> aux = new ArrayList<>();
aux.add(variable);
setVariables(aux);
}
public FieldDeclaration(EnumSet<Modifier> modifiers, Type type, List<VariableDeclarator> variables) {
setModifiers(modifiers);
setType(type);
setVariables(variables);
}
public FieldDeclaration(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type type,
List<VariableDeclarator> variables) {
super(annotations);
setModifiers(modifiers);
setType(type);
setVariables(variables);
}
public FieldDeclaration(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type type,
List<VariableDeclarator> variables) {
super(range, annotations);
setModifiers(modifiers);
setType(type);
setVariables(variables);
}
/**
* 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 Type getType() {
return type;
}
public List<VariableDeclarator> getVariables() {
variables = ensureNotNull(variables);
return variables;
}
@Override
public FieldDeclaration setModifiers(EnumSet<Modifier> modifiers) {
this.modifiers = modifiers;
return this;
}
@Override
public FieldDeclaration setType(Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
public void setVariables(List<VariableDeclarator> variables) {
this.variables = variables;
setAsParentNodeOf(this.variables);
}
@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");
String fieldName = getVariables().get(0).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(getType());
BlockStmt blockStmt = new BlockStmt();
getter.setBody(blockStmt);
blockStmt.addStatement(new ReturnStmt(NameExpr.create(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");
String fieldName = getVariables().get(0).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(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;
}
}
@@ -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.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 void setBlock(BlockStmt block) {
this.block = block;
setAsParentNodeOf(this.block);
}
public void setStatic(boolean isStatic) {
this.isStatic = isStatic;
}
@Override
public JavadocComment getJavaDoc() {
if(getComment() instanceof JavadocComment){
return (JavadocComment) getComment();
}
return null;
}
}
@@ -0,0 +1,338 @@
/*
* 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.AccessSpecifier;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.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.NodeWithBlockStmt;
import com.github.javaparser.ast.nodeTypes.NodeWithDeclaration;
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.NodeWithParameters;
import com.github.javaparser.ast.nodeTypes.NodeWithThrowable;
import com.github.javaparser.ast.nodeTypes.NodeWithType;
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;
/**
* @author Julio Vilmar Gesser
*/
public final class MethodDeclaration extends BodyDeclaration<MethodDeclaration>
implements NodeWithJavaDoc<MethodDeclaration>, NodeWithDeclaration, NodeWithName<MethodDeclaration>,
NodeWithType<MethodDeclaration>,
NodeWithModifiers<MethodDeclaration>, NodeWithParameters<MethodDeclaration>,
NodeWithThrowable<MethodDeclaration>, NodeWithBlockStmt<MethodDeclaration> {
private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
private List<TypeParameter> typeParameters;
private Type type;
private NameExpr name;
private List<Parameter> parameters;
private int arrayCount;
private List<ReferenceType> throws_;
private BlockStmt body;
private boolean isDefault = false;
public MethodDeclaration() {
}
public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type type, final String name) {
setModifiers(modifiers);
setType(type);
setName(name);
}
public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type type, final String name,
final List<Parameter> parameters) {
setModifiers(modifiers);
setType(type);
setName(name);
setParameters(parameters);
}
public MethodDeclaration(final EnumSet<Modifier> modifiers, final List<AnnotationExpr> annotations,
final List<TypeParameter> typeParameters, final Type type, final String name,
final List<Parameter> parameters, final int arrayCount, final List<ReferenceType> throws_,
final BlockStmt body) {
super(annotations);
setModifiers(modifiers);
setTypeParameters(typeParameters);
setType(type);
setName(name);
setParameters(parameters);
setArrayCount(arrayCount);
setThrows(throws_);
setBody(body);
}
public MethodDeclaration(Range range,
final EnumSet<Modifier> modifiers, final List<AnnotationExpr> annotations,
final List<TypeParameter> typeParameters, final Type type, final String name,
final List<Parameter> parameters, final int arrayCount, final List<ReferenceType> throws_,
final BlockStmt body) {
super(range, annotations);
setModifiers(modifiers);
setTypeParameters(typeParameters);
setType(type);
setName(name);
setParameters(parameters);
setArrayCount(arrayCount);
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);
}
public int getArrayCount() {
return arrayCount;
}
@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 type;
}
public List<TypeParameter> getTypeParameters() {
typeParameters = ensureNotNull(typeParameters);
return typeParameters;
}
public void setArrayCount(final int arrayCount) {
this.arrayCount = arrayCount;
}
@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) {
this.type = type;
setAsParentNodeOf(this.type);
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(getType().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.getType().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;
}
}
@@ -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.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.type.UnionType;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
public class MultiTypeParameter extends BaseParameter<MultiTypeParameter> {
private UnionType type;
public MultiTypeParameter() {}
public MultiTypeParameter(EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, UnionType type, VariableDeclaratorId id) {
super(modifiers, annotations, id);
this.type = type;
}
public MultiTypeParameter(Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, UnionType type, VariableDeclaratorId id) {
super(range, modifiers, annotations, id);
this.type = 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);
}
public UnionType getType() {
return type;
}
public void setType(UnionType type) {
this.type = type;
}
}
@@ -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.body;
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.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 Parameter extends BaseParameter<Parameter> implements NodeWithType<Parameter> {
private Type type;
private boolean isVarArgs;
public Parameter() {
}
public Parameter(Type type, VariableDeclaratorId id) {
super(id);
setType(type);
}
/**
* Creates a new {@link Parameter}.
*
* @param type
* type of the parameter
* @param name
* name of the parameter
* @return instance of {@link Parameter}
*/
public static Parameter create(Type type, String name) {
return new Parameter(type, new VariableDeclaratorId(name));
}
public Parameter(EnumSet<Modifier> modifiers, Type type, VariableDeclaratorId id) {
super(modifiers, id);
setType(type);
}
public Parameter(final Range range, EnumSet<Modifier> modifiers, List<AnnotationExpr> annotations, Type type,
boolean isVarArgs, VariableDeclaratorId id) {
super(range, modifiers, annotations, id);
setType(type);
setVarArgs(isVarArgs);
}
@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;
}
public boolean isVarArgs() {
return isVarArgs;
}
@Override
public Parameter setType(Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
public void setVarArgs(boolean isVarArgs) {
this.isVarArgs = isVarArgs;
}
}
@@ -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;
}
}
@@ -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.body;
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;
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 VariableDeclarator extends Node {
private VariableDeclaratorId id;
private Expression init;
public VariableDeclarator() {
}
public VariableDeclarator(VariableDeclaratorId id) {
setId(id);
}
/**
* 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(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 void setId(VariableDeclaratorId id) {
this.id = id;
setAsParentNodeOf(this.id);
}
public void setInit(Expression init) {
this.init = init;
setAsParentNodeOf(this.init);
}
}
@@ -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.body;
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 VariableDeclaratorId extends Node implements NodeWithName<VariableDeclaratorId> {
private String name;
private int arrayCount;
public VariableDeclaratorId() {
}
public VariableDeclaratorId(String name) {
setName(name);
}
public VariableDeclaratorId(Range range, String name, int arrayCount) {
super(range);
setName(name);
setArrayCount(arrayCount);
}
@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 int getArrayCount() {
return arrayCount;
}
@Override
public String getName() {
return name;
}
public void setArrayCount(int arrayCount) {
this.arrayCount = arrayCount;
}
@Override
public VariableDeclaratorId setName(String name) {
this.name = name;
return this;
}
}
@@ -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 "/&#42;" and
* "&#42;/".
*
* @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);
}
}
@@ -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.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 void setContent(String content) {
this.content = content;
}
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 void setCommentedNode(Node commentedNode)
{
if (commentedNode==null) {
this.commentedNode = null;
return;
}
if (commentedNode==this) {
throw new IllegalArgumentException();
}
if (commentedNode instanceof Comment) {
throw new IllegalArgumentException();
}
this.commentedNode = commentedNode;
}
public boolean isOrphan()
{
return this.commentedNode == null;
}
}
@@ -0,0 +1,104 @@
/*
* 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.LinkedList;
import java.util.List;
/**
* Set of comments produced by CommentsParser.
*/
public class CommentsCollection {
private List<LineComment> lineComments = new LinkedList<LineComment>();
private List<BlockComment> blockComments = new LinkedList<BlockComment>();
private List<JavadocComment> javadocComments = new LinkedList<JavadocComment>();
public List<LineComment> getLineComments(){
return lineComments;
}
public List<BlockComment> getBlockComments(){
return blockComments;
}
public List<JavadocComment> getJavadocComments(){
return javadocComments;
}
public void addComment(LineComment lineComment){
this.lineComments.add(lineComment);
}
public void addComment(BlockComment blockComment){
this.blockComments.add(blockComment);
}
public void addComment(JavadocComment javadocComment){
this.javadocComments.add(javadocComment);
}
public boolean contains(Comment comment){
for (Comment c : getAll()){
// 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 List<Comment> getAll(){
List<Comment> comments = new LinkedList<Comment>();
comments.addAll(lineComments);
comments.addAll(blockComments);
comments.addAll(javadocComments);
return comments;
}
public int size(){
return lineComments.size()+blockComments.size()+javadocComments.size();
}
public CommentsCollection minus(CommentsCollection other){
CommentsCollection result = new CommentsCollection();
for (LineComment comment : lineComments){
if (!other.contains(comment)){
result.lineComments.add(comment);
}
}
for (BlockComment comment : blockComments){
if (!other.contains(comment)){
result.blockComments.add(comment);
}
}
for (JavadocComment comment : javadocComments){
if (!other.contains(comment)){
result.javadocComments.add(comment);
}
}
return result;
}
}
@@ -0,0 +1,223 @@
/*
* 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.io.*;
import java.util.*;
import static com.github.javaparser.Position.pos;
import static com.github.javaparser.Range.range;
/**
* This parser cares exclusively about comments.
*/
public class CommentsParser {
private enum State {
CODE,
IN_LINE_COMMENT,
IN_BLOCK_COMMENT,
IN_STRING,
IN_CHAR
}
private static final int COLUMNS_PER_TAB = 4;
public CommentsCollection parse(final String source) throws IOException {
return parse(new StringReader(source));
}
public CommentsCollection parse(final InputStream in, final String charsetName) throws IOException {
return parse(new InputStreamReader(in, charsetName));
}
/**
* Track the internal state of the parser, remembering the last characters observed.
*/
private static class ParserState {
private Deque<Character> prevTwoChars = new LinkedList<Character>();
/**
* Is the last character the one expected?
*/
boolean isLastChar(char expectedChar) {
return !prevTwoChars.isEmpty() && prevTwoChars.peekLast().equals(expectedChar);
}
/**
* Is the character before the last one the same as expectedChar?
*/
public boolean isSecondToLastChar(char expectedChar) {
return !prevTwoChars.isEmpty() && prevTwoChars.peekFirst().equals(expectedChar);
}
/**
* Record a new character. It will be the last one. The character that was the last one will
* become the second to last one.
*/
public void update(char c) {
if (prevTwoChars.size() == 2) {
prevTwoChars.remove();
}
prevTwoChars.add(c);
}
/**
* Remove all the characters observed.
*/
public void reset() {
while (!prevTwoChars.isEmpty()) {
prevTwoChars.removeFirst();
}
}
}
/**
* Collects all comments in a piece of Java source.
*/
public CommentsCollection parse(final Reader in) throws IOException {
boolean lastWasASlashR = false;
BufferedReader br = new BufferedReader(in);
CommentsCollection comments = new CommentsCollection();
int r;
ParserState parserState = new ParserState();
State state = State.CODE;
LineComment currentLineComment = null;
BlockComment currentBlockComment = null;
StringBuilder currentContent = null;
int currLine = 1;
int currCol = 1;
while ((r=br.read()) != -1){
char c = (char)r;
if (c=='\r'){
lastWasASlashR = true;
} else if (c=='\n'&&lastWasASlashR){
lastWasASlashR=false;
continue;
} else {
lastWasASlashR=false;
}
switch (state) {
case CODE:
if (parserState.isLastChar('/') && c == '/') {
currentLineComment = new LineComment();
currentLineComment.setBegin(pos(currLine, currCol - 1));
state = State.IN_LINE_COMMENT;
currentContent = new StringBuilder();
} else if (parserState.isLastChar('/') && c == '*') {
currentBlockComment = new BlockComment();
currentBlockComment.setBegin(pos(currLine, currCol - 1));
state = State.IN_BLOCK_COMMENT;
currentContent = new StringBuilder();
} else if (c == '"') {
state = State.IN_STRING;
} else if (c == '\'') {
state = State.IN_CHAR;
} else {
// nothing to do
}
break;
case IN_LINE_COMMENT:
if (c=='\n' || c=='\r'){
currentLineComment.setContent(currentContent.toString());
currentLineComment.setEnd(pos(currLine, currCol));
comments.addComment(currentLineComment);
state = State.CODE;
} else {
currentContent.append(c);
}
break;
case IN_BLOCK_COMMENT:
// '/*/' is not a valid block comment: it starts the block comment but it does not close it
// However this sequence can be contained inside a comment and in that case it close the comment
// For example:
// /* blah blah /*/
// At the previous line we had a valid block comment
if (parserState.isLastChar('*') && c=='/' && (!parserState.isSecondToLastChar('/') || currentContent.length() > 0)){
// delete last character
String content = currentContent.deleteCharAt(currentContent.toString().length()-1).toString();
if (content.startsWith("*")){
JavadocComment javadocComment = new JavadocComment();
javadocComment.setContent(content.substring(1));
javadocComment.setRange(range(pos(currentBlockComment.getBegin().line, currentBlockComment.getBegin().column), pos(currLine, currCol+1)));
comments.addComment(javadocComment);
} else {
currentBlockComment.setContent(content);
currentBlockComment.setEnd(pos(currLine, currCol+1));
comments.addComment(currentBlockComment);
}
state = State.CODE;
} else {
currentContent.append(c == '\r' ? System.getProperty("line.separator") : c);
}
break;
case IN_STRING:
if (!parserState.isLastChar('\\') && c == '"') {
state = State.CODE;
}
break;
case IN_CHAR:
if (!parserState.isLastChar('\\') && c == '\'') {
state = State.CODE;
}
break;
default:
throw new RuntimeException("Unexpected");
}
switch (c){
case '\n':
case '\r':
currLine+=1;
currCol = 1;
break;
case '\t':
currCol+=COLUMNS_PER_TAB;
break;
default:
currCol+=1;
}
// ok we have two slashes in a row inside a string
// we want to replace them with... anything else, to not confuse
// the parser
if (state==State.IN_STRING && parserState.isLastChar('\\') && c == '\\') {
parserState.reset();
} else {
parserState.update(c);
}
}
if (state==State.IN_LINE_COMMENT){
currentLineComment.setContent(currentContent.toString());
currentLineComment.setEnd(pos(currLine, currCol));
comments.addComment(currentLineComment);
}
return comments;
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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;
/**
* @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 void setName(NameExpr name) {
this.name = name;
setAsParentNodeOf(name);
}
}
@@ -0,0 +1,78 @@
/*
* 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 void setIndex(Expression index) {
this.index = index;
setAsParentNodeOf(this.index);
}
public void setName(Expression name) {
this.name = name;
setAsParentNodeOf(this.name);
}
}
@@ -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.expr;
import java.util.List;
import com.github.javaparser.Range;
import com.github.javaparser.ast.nodeTypes.NodeWithArrays;
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 static com.github.javaparser.utils.Utils.ensureNotNull;
/**
* @author Julio Vilmar Gesser
*/
public final class ArrayCreationExpr extends Expression implements NodeWithType<ArrayCreationExpr>, NodeWithArrays<ArrayCreationExpr> {
private Type type;
private int arrayCount;
private ArrayInitializerExpr initializer;
private List<Expression> dimensions;
private List<List<AnnotationExpr>> arraysAnnotations;
public ArrayCreationExpr() {
}
public ArrayCreationExpr(Type type, int arrayCount, ArrayInitializerExpr initializer) {
setType(type);
setArrayCount(arrayCount);
setInitializer(initializer);
setDimensions(null);
}
public ArrayCreationExpr(Range range, Type type, int arrayCount, ArrayInitializerExpr initializer) {
super(range);
setType(type);
setArrayCount(arrayCount);
setInitializer(initializer);
setDimensions(null);
}
public ArrayCreationExpr(Type type, List<Expression> dimensions, int arrayCount) {
setType(type);
setArrayCount(arrayCount);
setDimensions(dimensions);
setInitializer(null);
}
public ArrayCreationExpr(Range range, Type type, List<Expression> dimensions, int arrayCount) {
super(range);
setType(type);
setArrayCount(arrayCount);
setDimensions(dimensions);
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);
}
@Override
public int getArrayCount() {
return arrayCount;
}
public List<Expression> getDimensions() {
dimensions = ensureNotNull(dimensions);
return dimensions;
}
public ArrayInitializerExpr getInitializer() {
return initializer;
}
@Override
public Type getType() {
return type;
}
@Override
public ArrayCreationExpr setArrayCount(int arrayCount) {
this.arrayCount = arrayCount;
return this;
}
public void setDimensions(List<Expression> dimensions) {
this.dimensions = dimensions;
setAsParentNodeOf(this.dimensions);
}
public void setInitializer(ArrayInitializerExpr initializer) {
this.initializer = initializer;
setAsParentNodeOf(this.initializer);
}
@Override
public ArrayCreationExpr setType(Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
@Override
public List<List<AnnotationExpr>> getArraysAnnotations() {
arraysAnnotations = ensureNotNull(arraysAnnotations);
return arraysAnnotations;
}
@Override
public ArrayCreationExpr setArraysAnnotations(
List<List<AnnotationExpr>> arraysAnnotations) {
this.arraysAnnotations = arraysAnnotations;
return this;
}
}
@@ -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.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 void setValues(List<Expression> values) {
this.values = values;
setAsParentNodeOf(this.values);
}
}
@@ -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.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 void setOperator(Operator op) {
this.op = op;
}
public void setTarget(Expression target) {
this.target = target;
setAsParentNodeOf(this.target);
}
public void setValue(Expression value) {
this.value = value;
setAsParentNodeOf(this.value);
}
}
@@ -0,0 +1,112 @@
/*
* 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 void setLeft(Expression left) {
this.left = left;
setAsParentNodeOf(this.left);
}
public void setOperator(Operator op) {
this.op = op;
}
public void setRight(Expression right) {
this.right = right;
setAsParentNodeOf(this.right);
}
}
@@ -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 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 void setValue(boolean value) {
this.value = value;
}
}
@@ -0,0 +1,83 @@
/*
* 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 void setExpr(Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
@Override
public CastExpr setType(Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -0,0 +1,91 @@
/*
* 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 void setCondition(Expression condition) {
this.condition = condition;
setAsParentNodeOf(this.condition);
}
public void setElseExpr(Expression elseExpr) {
this.elseExpr = elseExpr;
setAsParentNodeOf(this.elseExpr);
}
public void setThenExpr(Expression thenExpr) {
this.thenExpr = thenExpr;
setAsParentNodeOf(this.thenExpr);
}
}
@@ -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);
}
}
@@ -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.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 void setInner(final Expression inner) {
this.inner = inner;
setAsParentNodeOf(this.inner);
}
}
@@ -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);
}
}
@@ -0,0 +1,102 @@
/*
* 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.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.*;
/**
* @author Julio Vilmar Gesser
*/
public final class FieldAccessExpr extends Expression {
private Expression scope;
private List<Type> typeArgs;
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> typeArgs, final String field) {
super(range);
setScope(scope);
setTypeArgs(typeArgs);
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 List<Type> getTypeArgs() {
typeArgs = ensureNotNull(typeArgs);
return typeArgs;
}
public void setField(final String field) {
setFieldExpr(new NameExpr(field));
}
public void setFieldExpr(NameExpr field) {
this.field = field;
setAsParentNodeOf(this.field);
}
public void setScope(final Expression scope) {
this.scope = scope;
setAsParentNodeOf(this.scope);
}
public void setTypeArgs(final List<Type> typeArgs) {
this.typeArgs = typeArgs;
setAsParentNodeOf(this.typeArgs);
}
}
@@ -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.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 void setExpr(final Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
@Override
public InstanceOfExpr setType(final Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -0,0 +1,96 @@
/*
* 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 void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
setAsParentNodeOf(this.parameters);
}
public Statement getBody() {
return body;
}
public void setBody(Statement body) {
this.body = body;
setAsParentNodeOf(this.body);
}
@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 void setParametersEnclosed(boolean parametersEnclosed) {
this.parametersEnclosed = parametersEnclosed;
}
}
@@ -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);
}
}
@@ -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');
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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.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 void setValue(final Expression value) {
this.value = value;
setAsParentNodeOf(this.value);
}
}
@@ -0,0 +1,141 @@
/*
* 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.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.*;
/**
* @author Julio Vilmar Gesser
*/
public final class MethodCallExpr extends Expression {
private Expression scope;
private List<Type> typeArgs;
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> typeArgs, final String name, final List<Expression> args) {
super(range);
setScope(scope);
setTypeArgs(typeArgs);
setName(name);
setArgs(args);
}
/**
* Adds the given argument to the method call. The list of arguments will be
* initialized if it is <code>null</code>.
*
* @param arg
* argument value
*/
public MethodCallExpr addArgument(Expression arg) {
List<Expression> args = getArgs();
if (isNullOrEmpty(args)) {
args = new ArrayList<>();
setArgs(args);
}
args.add(arg);
arg.setParentNode(this);
return this;
}
@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 List<Type> getTypeArgs() {
typeArgs = ensureNotNull(typeArgs);
return typeArgs;
}
public void setArgs(final List<Expression> args) {
this.args = args;
setAsParentNodeOf(this.args);
}
public void setName(final String name) {
setNameExpr(new NameExpr(name));
}
public void setNameExpr(NameExpr name) {
this.name = name;
setAsParentNodeOf(this.name);
}
public void setScope(final Expression scope) {
this.scope = scope;
setAsParentNodeOf(this.scope);
}
public void setTypeArgs(final List<Type> typeArgs) {
this.typeArgs = typeArgs;
setAsParentNodeOf(this.typeArgs);
}
}
@@ -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.TypeArguments;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* 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 {
private Expression scope;
private TypeArguments typeArguments;
private String identifier;
public MethodReferenceExpr() {
}
public MethodReferenceExpr(Range range, Expression scope,
TypeArguments 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 void setScope(Expression scope) {
this.scope = scope;
setAsParentNodeOf(this.scope);
}
public TypeArguments getTypeArguments() {
return typeArguments;
}
public void setTypeArguments(TypeArguments typeArguments) {
this.typeArguments = typeArguments;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
}
@@ -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 create(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;
}
}
@@ -0,0 +1,93 @@
/*
* 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 java.util.List;
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 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 void setPairs(final List<MemberValuePair> pairs) {
this.pairs = pairs;
setAsParentNodeOf(this.pairs);
}
/**
* adds a pair to this annotation
*
* @return this, the {@link NormalAnnotationExpr}
*/
public NormalAnnotationExpr addPair(String key, String value) {
return addPair(key, NameExpr.create(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;
}
}
@@ -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);
}
}
@@ -0,0 +1,140 @@
/*
* 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 java.util.List;
import com.github.javaparser.Range;
import com.github.javaparser.ast.body.BodyDeclaration;
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;
/**
* Defines constructor call expression.
* Example:
* <code>
* new Object()
* </code>
*
* @author Julio Vilmar Gesser
*/
public final class ObjectCreationExpr extends Expression {
private Expression scope;
private ClassOrInterfaceType type;
private List<Type> typeArgs;
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> typeArgs,
final List<Expression> args, final List<BodyDeclaration<?>> anonymousBody) {
super(range);
setScope(scope);
setType(type);
setTypeArgs(typeArgs);
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 List<Expression> getArgs() {
args = ensureNotNull(args);
return args;
}
public Expression getScope() {
return scope;
}
public ClassOrInterfaceType getType() {
return type;
}
public List<Type> getTypeArgs() {
typeArgs = ensureNotNull(typeArgs);
return typeArgs;
}
public void setAnonymousClassBody(final List<BodyDeclaration<?>> anonymousClassBody) {
this.anonymousClassBody = anonymousClassBody;
setAsParentNodeOf(this.anonymousClassBody);
}
public void setArgs(final List<Expression> args) {
this.args = args;
setAsParentNodeOf(this.args);
}
public void setScope(final Expression scope) {
this.scope = scope;
setAsParentNodeOf(this.scope);
}
public void setType(final ClassOrInterfaceType type) {
this.type = type;
setAsParentNodeOf(this.type);
}
public void setTypeArgs(final List<Type> typeArgs) {
this.typeArgs = typeArgs;
setAsParentNodeOf(this.typeArgs);
}
}
@@ -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 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 void setQualifier(final NameExpr qualifier) {
this.qualifier = qualifier;
setAsParentNodeOf(this.qualifier);
}
}
@@ -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 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 void setMemberValue(final Expression memberValue) {
this.memberValue = memberValue;
setAsParentNodeOf(this.memberValue);
}
}
@@ -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.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 void setValue(final String value) {
this.value = value;
}
}
@@ -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.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 void setClassExpr(final Expression classExpr) {
this.classExpr = classExpr;
setAsParentNodeOf(this.classExpr);
}
}
@@ -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.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 void setClassExpr(final Expression classExpr) {
this.classExpr = classExpr;
setAsParentNodeOf(this.classExpr);
}
}
@@ -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;
}
}
@@ -0,0 +1,86 @@
/*
* 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 void setExpr(final Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
public void setOperator(final Operator op) {
this.op = op;
}
}
@@ -0,0 +1,152 @@
/*
* 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 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.body.VariableDeclarator;
import com.github.javaparser.ast.body.VariableDeclaratorId;
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
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 VariableDeclarationExpr extends Expression
implements NodeWithType<VariableDeclarationExpr>, NodeWithModifiers<VariableDeclarationExpr>,
NodeWithAnnotations<VariableDeclarationExpr> {
private EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
private List<AnnotationExpr> annotations;
private Type type;
private List<VariableDeclarator> vars;
public VariableDeclarationExpr() {
}
public VariableDeclarationExpr(final Type type, final List<VariableDeclarator> vars) {
setType(type);
setVars(vars);
}
public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final Type type,
final List<VariableDeclarator> vars) {
setModifiers(modifiers);
setType(type);
setVars(vars);
}
public VariableDeclarationExpr(final Range range,
final EnumSet<Modifier> modifiers, final List<AnnotationExpr> annotations,
final Type type,
final List<VariableDeclarator> vars) {
super(range);
setModifiers(modifiers);
setAnnotations(annotations);
setType(type);
setVars(vars);
}
/**
* Creates a {@link VariableDeclarationExpr}.
*
* @return instance of {@link VariableDeclarationExpr}
*/
public static VariableDeclarationExpr create(Type type, String name) {
List<VariableDeclarator> vars = new ArrayList<>();
vars.add(new VariableDeclarator(new VariableDeclaratorId(name)));
return new VariableDeclarationExpr(type, vars);
}
@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 getType() {
return type;
}
public List<VariableDeclarator> getVars() {
vars = ensureNotNull(vars);
return vars;
}
@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 setType(final Type type) {
this.type = type;
setAsParentNodeOf(this.type);
return this;
}
public void setVars(final List<VariableDeclarator> vars) {
this.vars = vars;
setAsParentNodeOf(this.vars);
}
}
@@ -0,0 +1,159 @@
/*
* 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.*;
/**
* 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(
NameExpr.create(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(
NameExpr.create(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
* @return this
*/
@SuppressWarnings("unchecked")
public default T addSingleMemberAnnotation(String name, String value) {
SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr(
NameExpr.create(name), NameExpr.create(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
* @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());
}
}
@@ -0,0 +1,18 @@
package com.github.javaparser.ast.nodeTypes;
import com.github.javaparser.ast.expr.AnnotationExpr;
import java.util.List;
/**
* A node that has array brackets behind it [][][]
*/
public interface NodeWithArrays<T> {
int getArrayCount();
T setArrayCount(int arrayCount);
List<List<AnnotationExpr>> getArraysAnnotations();
T setArraysAnnotations(List<List<AnnotationExpr>> arraysAnnotations);
}
@@ -0,0 +1,17 @@
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;
}
}
@@ -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);
}
@@ -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;
}
}
@@ -0,0 +1,285 @@
package com.github.javaparser.ast.nodeTypes;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;
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;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.*;
import static com.github.javaparser.ast.type.VoidType.VOID_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.getVariables().add(new VariableDeclarator(new VariableDeclaratorId(name)));
fieldDeclaration.setModifiers(Arrays.stream(modifiers)
.collect(toCollection(() -> EnumSet.noneOf(Modifier.class))));
fieldDeclaration.setType(type);
getMembers().add(fieldDeclaration);
fieldDeclaration.setParentNode((Node) this);
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 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&lt;Integer,String&gt;","int" to match<br>
* void foo(Map&lt;Integer,String&gt; 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&lt;Integer,String&gt;","int" to match<br>
* void foo(Map&lt;Integer,String&gt; 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()));
}
}
@@ -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);
}
}
@@ -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);
}
@@ -0,0 +1,81 @@
package com.github.javaparser.ast.nodeTypes;
import java.util.ArrayList;
import java.util.List;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
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);
}
@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);
}
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);
}
}
@@ -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 ReferenceType(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));
}
}
@@ -0,0 +1,63 @@
/*
* 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()));
}
}
@@ -0,0 +1,83 @@
/*
* 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 void setCheck(final Expression check) {
this.check = check;
setAsParentNodeOf(this.check);
}
public void setMessage(final Expression msg) {
this.msg = msg;
setAsParentNodeOf(this.msg);
}
}
@@ -0,0 +1,89 @@
/*
* 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.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 BlockStmt extends Statement {
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);
}
public List<Statement> getStmts() {
stmts = ensureNotNull(stmts);
return stmts;
}
public void setStmts(final List<Statement> stmts) {
this.stmts = stmts;
setAsParentNodeOf(this.stmts);
}
// TODO move to a nodeType + addAndGetStatement like methods ?
public BlockStmt addStatement(Statement statement) {
getStmts().add(statement);
statement.setParentNode(this);
return this;
}
public BlockStmt addStatement(String statement) {
return addStatement(new ExpressionStmt(new NameExpr(statement)));
}
public BlockStmt addStatement(Expression expr) {
return addStatement(new ExpressionStmt(expr));
}
}
@@ -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.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 void setId(final String id) {
this.id = id;
}
}
@@ -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 java.util.EnumSet;
import java.util.List;
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.type.Type;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* @author Julio Vilmar Gesser
*/
public final class CatchClause extends Node {
private Parameter param;
private BlockStmt catchBlock;
public CatchClause() {
}
public CatchClause(final Parameter param, final BlockStmt catchBlock) {
setParam(param);
setCatchBlock(catchBlock);
}
public CatchClause(final Range range,
final EnumSet<Modifier> exceptModifier, final List<AnnotationExpr> exceptAnnotations,
final Type exceptTypes,
final VariableDeclaratorId exceptId, final BlockStmt catchBlock) {
super(range);
setParam(new Parameter(range, exceptModifier, exceptAnnotations, exceptTypes, false, exceptId));
setCatchBlock(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);
}
public BlockStmt getCatchBlock() {
return catchBlock;
}
public Parameter getParam() {
return param;
}
public void setCatchBlock(final BlockStmt catchBlock) {
this.catchBlock = catchBlock;
setAsParentNodeOf(this.catchBlock);
}
public void setParam(final Parameter param) {
this.param = param;
setAsParentNodeOf(this.param);
}
}
@@ -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.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 void setId(final String id) {
this.id = id;
}
}
@@ -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.expr.Expression;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* @author Julio Vilmar Gesser
*/
public final class DoStmt extends Statement {
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);
}
public Statement getBody() {
return body;
}
public Expression getCondition() {
return condition;
}
public void setBody(final Statement body) {
this.body = body;
setAsParentNodeOf(this.body);
}
public void setCondition(final Expression condition) {
this.condition = condition;
setAsParentNodeOf(this.condition);
}
}
@@ -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);
}
}
@@ -0,0 +1,113 @@
/*
* 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.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.*;
/**
* @author Julio Vilmar Gesser
*/
public final class ExplicitConstructorInvocationStmt extends Statement {
private List<Type> typeArgs;
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> typeArgs, final boolean isThis,
final Expression expr, final List<Expression> args) {
super(range);
setTypeArgs(typeArgs);
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 List<Type> getTypeArgs() {
typeArgs = ensureNotNull(typeArgs);
return typeArgs;
}
public boolean isThis() {
return isThis;
}
public void setArgs(final List<Expression> args) {
this.args = args;
setAsParentNodeOf(this.args);
}
public void setExpr(final Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
public void setThis(final boolean isThis) {
this.isThis = isThis;
}
public void setTypeArgs(final List<Type> typeArgs) {
this.typeArgs = typeArgs;
setAsParentNodeOf(this.typeArgs);
}
}
@@ -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 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 void setExpression(final Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
}
@@ -0,0 +1,114 @@
/*
* 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 ForStmt extends Statement {
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);
}
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;
}
public void setBody(final Statement body) {
this.body = body;
setAsParentNodeOf(this.body);
}
public void setCompare(final Expression compare) {
this.compare = compare;
setAsParentNodeOf(this.compare);
}
public void setInit(final List<Expression> init) {
this.init = init;
setAsParentNodeOf(this.init);
}
public void setUpdate(final List<Expression> update) {
this.update = update;
setAsParentNodeOf(this.update);
}
}
@@ -0,0 +1,96 @@
/*
* 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.VariableDeclarationExpr;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
/**
* @author Julio Vilmar Gesser
*/
public final class ForeachStmt extends Statement {
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);
}
@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 Statement getBody() {
return body;
}
public Expression getIterable() {
return iterable;
}
public VariableDeclarationExpr getVariable() {
return var;
}
public void setBody(final Statement body) {
this.body = body;
setAsParentNodeOf(this.body);
}
public void setIterable(final Expression iterable) {
this.iterable = iterable;
setAsParentNodeOf(this.iterable);
}
public void setVariable(final VariableDeclarationExpr var) {
this.var = var;
setAsParentNodeOf(this.var);
}
}
@@ -0,0 +1,91 @@
/*
* 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 void setCondition(final Expression condition) {
this.condition = condition;
setAsParentNodeOf(this.condition);
}
public void setElseStmt(final Statement elseStmt) {
this.elseStmt = elseStmt;
setAsParentNodeOf(this.elseStmt);
}
public void setThenStmt(final Statement thenStmt) {
this.thenStmt = thenStmt;
setAsParentNodeOf(this.thenStmt);
}
}
@@ -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.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 void setLabel(final String label) {
this.label = label;
}
public void setStmt(final Statement stmt) {
this.stmt = stmt;
setAsParentNodeOf(this.stmt);
}
}
@@ -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.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 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);
}
@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 void setExpr(final Expression expr) {
this.expr = expr;
setAsParentNodeOf(this.expr);
}
}
@@ -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);
}
}

Some files were not shown because too many files have changed in this diff Show More