diff --git a/.gitignore b/.gitignore index 3f9413e..4c4883c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ /UMLProjectType/build/ /easyUML/build/ /UMLCodeGenerator/build/ -/UMLReverseEngineering/build/ \ No newline at end of file +/UMLReverseEngineering/build/ +/dist/ diff --git a/JavaParser/nbproject/build-impl.xml b/JavaParser/nbproject/build-impl.xml index 1a5a98d..3ded5d6 100644 --- a/JavaParser/nbproject/build-impl.xml +++ b/JavaParser/nbproject/build-impl.xml @@ -1,45 +1,45 @@ - - - - - - - - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JavaParser/nbproject/genfiles.properties b/JavaParser/nbproject/genfiles.properties index 3a71be0..ae8412f 100644 --- a/JavaParser/nbproject/genfiles.properties +++ b/JavaParser/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=9f450998 -build.xml.script.CRC32=55ec2430 -build.xml.stylesheet.CRC32=a56c6a5b@2.67.1 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=a25d480a -nbproject/build-impl.xml.script.CRC32=fcd88647 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.67.1 +build.xml.data.CRC32=9f450998 +build.xml.script.CRC32=55ec2430 +build.xml.stylesheet.CRC32=a56c6a5b@2.67.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=abada830 +nbproject/build-impl.xml.script.CRC32=fcd88647 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/JavaParser/nbproject/project.properties b/JavaParser/nbproject/project.properties index 75d0c54..e9843e8 100644 --- a/JavaParser/nbproject/project.properties +++ b/JavaParser/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=COPYING.LESSER diff --git a/JavaParser/nbproject/project.xml b/JavaParser/nbproject/project.xml index c0947a4..c3b54d3 100644 --- a/JavaParser/nbproject/project.xml +++ b/JavaParser/nbproject/project.xml @@ -1,22 +1,40 @@ - - - org.netbeans.modules.apisupport.project - - - com.github.javaparser - - - - com.github.javaparser - com.github.javaparser.ast - com.github.javaparser.ast.body - com.github.javaparser.ast.comments - com.github.javaparser.ast.expr - com.github.javaparser.ast.internal - com.github.javaparser.ast.stmt - com.github.javaparser.ast.type - com.github.javaparser.ast.visitor - - - - + + + org.netbeans.modules.apisupport.project + + + com.github.javaparser + + + + com.github.javaparser + com.github.javaparser.ast + com.github.javaparser.ast.body + com.github.javaparser.ast.comments + com.github.javaparser.ast.expr + com.github.javaparser.ast.modules + com.github.javaparser.ast.nodeTypes + com.github.javaparser.ast.nodeTypes.modifiers + com.github.javaparser.ast.observer + com.github.javaparser.ast.stmt + com.github.javaparser.ast.type + com.github.javaparser.ast.validator + com.github.javaparser.ast.validator.chunks + com.github.javaparser.ast.visitor + com.github.javaparser.javadoc + com.github.javaparser.javadoc.description + com.github.javaparser.metamodel + com.github.javaparser.printer + com.github.javaparser.printer.concretesyntaxmodel + com.github.javaparser.printer.lexicalpreservation + com.github.javaparser.printer.lexicalpreservation.changes + com.github.javaparser.resolution + com.github.javaparser.resolution.declarations + com.github.javaparser.resolution.types + com.github.javaparser.resolution.types.parametrization + com.github.javaparser.utils + com.github.javaparser.version + + + + diff --git a/JavaParser/src/com/github/javaparser/ASTHelper.java b/JavaParser/src/com/github/javaparser/ASTHelper.java deleted file mode 100644 index 7952998..0000000 --- a/JavaParser/src/com/github/javaparser/ASTHelper.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser; - -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.QualifiedNameExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.ReferenceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.ast.type.PrimitiveType.Primitive; - -import java.util.ArrayList; -import java.util.List; - -/** - * This class helps to construct new nodes. - * - * @author Júlio Vilmar Gesser - */ -public final class ASTHelper { - - public static final PrimitiveType BYTE_TYPE = new PrimitiveType(Primitive.Byte); - - public static final PrimitiveType SHORT_TYPE = new PrimitiveType(Primitive.Short); - - public static final PrimitiveType INT_TYPE = new PrimitiveType(Primitive.Int); - - public static final PrimitiveType LONG_TYPE = new PrimitiveType(Primitive.Long); - - public static final PrimitiveType FLOAT_TYPE = new PrimitiveType(Primitive.Float); - - public static final PrimitiveType DOUBLE_TYPE = new PrimitiveType(Primitive.Double); - - public static final PrimitiveType BOOLEAN_TYPE = new PrimitiveType(Primitive.Boolean); - - public static final PrimitiveType CHAR_TYPE = new PrimitiveType(Primitive.Char); - - public static final VoidType VOID_TYPE = new VoidType(); - - private ASTHelper() { - // nop - } - - /** - * Creates a new {@link NameExpr} from a qualified name.
- * The qualified name can contains "." (dot) characters. - * - * @param qualifiedName - * qualified name - * @return instanceof {@link NameExpr} - */ - public static NameExpr createNameExpr(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; - } - - /** - * 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 createParameter(Type type, String name) { - return new Parameter(type, new VariableDeclaratorId(name)); - } - - /** - * Creates a {@link FieldDeclaration}. - * - * @param modifiers - * modifiers - * @param type - * type - * @param variable - * variable declarator - * @return instance of {@link FieldDeclaration} - */ - public static FieldDeclaration createFieldDeclaration(int modifiers, Type type, VariableDeclarator variable) { - List variables = new ArrayList(); - variables.add(variable); - FieldDeclaration ret = new FieldDeclaration(modifiers, type, variables); - return ret; - } - - /** - * Creates a {@link FieldDeclaration}. - * - * @param modifiers - * modifiers - * @param type - * type - * @param name - * field name - * @return instance of {@link FieldDeclaration} - */ - public static FieldDeclaration createFieldDeclaration(int modifiers, Type type, String name) { - VariableDeclaratorId id = new VariableDeclaratorId(name); - VariableDeclarator variable = new VariableDeclarator(id); - return createFieldDeclaration(modifiers, type, variable); - } - - /** - * Creates a {@link VariableDeclarationExpr}. - * - * @param type - * type - * @param name - * name - * @return instance of {@link VariableDeclarationExpr} - */ - public static VariableDeclarationExpr createVariableDeclarationExpr(Type type, String name) { - List vars = new ArrayList(); - vars.add(new VariableDeclarator(new VariableDeclaratorId(name))); - return new VariableDeclarationExpr(type, vars); - } - - /** - * Adds the given parameter to the method. The list of parameters will be - * initialized if it is null. - * - * @param method - * method - * @param parameter - * parameter - */ - public static void addParameter(MethodDeclaration method, Parameter parameter) { - List parameters = method.getParameters(); - if (parameters == null) { - parameters = new ArrayList(); - method.setParameters(parameters); - } - parameters.add(parameter); - } - - /** - * Adds the given argument to the method call. The list of arguments will be - * initialized if it is null. - * - * @param call - * method call - * @param arg - * argument value - */ - public static void addArgument(MethodCallExpr call, Expression arg) { - List args = call.getArgs(); - if (args == null) { - args = new ArrayList(); - call.setArgs(args); - } - args.add(arg); - } - - /** - * Adds the given type declaration to the compilation unit. The list of - * types will be initialized if it is null. - * - * @param cu - * compilation unit - * @param type - * type declaration - */ - public static void addTypeDeclaration(CompilationUnit cu, TypeDeclaration type) { - List types = cu.getTypes(); - if (types == null) { - types = new ArrayList(); - cu.setTypes(types); - } - types.add(type); - - } - - /** - * Creates a new {@link ReferenceType} for a class or interface. - * - * @param name - * name of the class or interface - * @param arrayCount - * number of arrays or 0 if is not a array. - * @return instanceof {@link ReferenceType} - */ - public static ReferenceType createReferenceType(String name, int arrayCount) { - return new ReferenceType(new ClassOrInterfaceType(name), arrayCount); - } - - /** - * Creates a new {@link ReferenceType} for the given primitive type. - * - * @param type - * primitive type - * @param arrayCount - * number of arrays or 0 if is not a array. - * @return instanceof {@link ReferenceType} - */ - public static ReferenceType createReferenceType(PrimitiveType type, int arrayCount) { - return new ReferenceType(type, arrayCount); - } - - /** - * Adds the given statement to the specified block. The list of statements - * will be initialized if it is null. - * - * @param block to have expression added to - * @param stmt to be added - */ - public static void addStmt(BlockStmt block, Statement stmt) { - List stmts = block.getStmts(); - if (stmts == null) { - stmts = new ArrayList(); - block.setStmts(stmts); - } - stmts.add(stmt); - } - - /** - * Adds the given expression to the specified block. The list of statements - * will be initialized if it is null. - * - * @param block to have expression added to - * @param expr to be added - */ - public static void addStmt(BlockStmt block, Expression expr) { - addStmt(block, new ExpressionStmt(expr)); - } - - /** - * Adds the given declaration to the specified type. The list of members - * will be initialized if it is null. - * - * @param type - * type declaration - * @param decl - * member declaration - */ - public static void addMember(TypeDeclaration type, BodyDeclaration decl) { - List members = type.getMembers(); - if (members == null) { - members = new ArrayList(); - type.setMembers(members); - } - members.add(decl); - } - -} diff --git a/JavaParser/src/com/github/javaparser/ASTParser.java b/JavaParser/src/com/github/javaparser/ASTParser.java deleted file mode 100644 index 5247896..0000000 --- a/JavaParser/src/com/github/javaparser/ASTParser.java +++ /dev/null @@ -1,9141 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ASTParser.java */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - -import java.io.*; -import java.util.*; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.comments.*; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -/** - *

This class was generated automatically by javacc, do not edit.

- */ -final class ASTParser implements ASTParserConstants { - - void reset(InputStream in, String encoding) { - ReInit(in, encoding); - } - - private List add(List list, Object obj) { - if (list == null) { - list = new LinkedList(); - } - list.add(obj); - return list; - } - - private List add(int pos, List list, Object obj) { - if (list == null) { - list = new LinkedList(); - } - list.add(pos, obj); - return list; - } - - private class Modifier { - - final int modifiers; - final List annotations; - final int beginLine; - final int beginColumn; - - public Modifier(int beginLine, int beginColumn, int modifiers, List annotations) { - this.beginLine = beginLine; - this.beginColumn = beginColumn; - this.modifiers = modifiers; - this.annotations = annotations; - } - } - - public int addModifier(int modifiers, int mod, Token token) throws ParseException { - if ((ModifierSet.hasModifier(modifiers, mod))) { - throwParseException(token, "Duplicated modifier"); - } - return ModifierSet.addModifier(modifiers, mod); - } - - private void throwParseException(Token token, String message) throws ParseException { - StringBuilder buf = new StringBuilder(); - buf.append(message); - buf.append(": \u005c""); - buf.append(token.image); - buf.append("\u005c" at line "); - buf.append(token.beginLine); - buf.append(", column "); - buf.append(token.beginColumn); - ParseException e = new ParseException(buf.toString()); - e.currentToken = token; - throw e; - } - - private Expression generateLambda(Expression ret, Statement lambdaBody) throws ParseException { - if (ret instanceof EnclosedExpr) { - Expression inner = ((EnclosedExpr) ret).getInner(); - if (inner != null && inner instanceof NameExpr) { - VariableDeclaratorId id = new VariableDeclaratorId(inner.getBeginLine(), inner.getBeginColumn(), inner.getEndLine(), inner.getEndColumn(), ((NameExpr)inner).getName(), 0); - List params = add(null, new Parameter(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), 0, null, new UnknownType(), false, id)); - ret = new LambdaExpr(ret.getBeginLine(), ret.getBeginColumn(), lambdaBody.getEndLine(), lambdaBody.getEndColumn(), params, lambdaBody, true); - } else { - ret = new LambdaExpr(ret.getBeginLine(), ret.getBeginColumn(), lambdaBody.getEndLine(), lambdaBody.getEndColumn(), null, lambdaBody, true); - } - } else if (ret instanceof NameExpr) { - VariableDeclaratorId id = new VariableDeclaratorId(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), ((NameExpr)ret).getName(), 0); - List params = add(null, new Parameter(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), 0, null, new UnknownType(), false, id)); - ret = new LambdaExpr(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), params, lambdaBody, false); - } else if (ret instanceof LambdaExpr) { - ((LambdaExpr) ret).setBody(lambdaBody); - ret.setEndLine(lambdaBody.getEndLine()); - ret.setEndColumn(lambdaBody.getEndColumn()); - } else { - throw new ParseException("Failed to parse lambda expression! Please create an issue at https://github.com/javaparser/javaparser/issues"); - } - return ret; - } - - static final class GTToken extends Token { - - int realKind = ASTParserConstants.GT; - - GTToken(int kind, String image) { - this.kind = kind; - this.image = image; - } - - public static Token newToken(int kind, String image) { - return new GTToken(kind, image); - } - } - - private Token last_special_token = null; - -/***************************************** - * THE JAVA LANGUAGE GRAMMAR STARTS HERE * - *****************************************/ - -/* - * Program structuring syntax follows. - */ - final public CompilationUnit CompilationUnit() throws ParseException { - PackageDeclaration pakage = null; - List imports = null; - ImportDeclaration in = null; - List types = null; - TypeDeclaration tn = null; - int line = -1; - int column = 0; - if (jj_2_1(2147483647)) { - pakage = PackageDeclaration(); - line = pakage.getBeginLine(); column = pakage.getBeginColumn(); - } else { - ; - } - label_1: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IMPORT: - ; - break; - default: - jj_la1[0] = jj_gen; - break label_1; - } - in = ImportDeclaration(); - if(line==-1){line = in.getBeginLine(); column = in.getBeginColumn();} imports = add(imports, in); - } - label_2: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case CLASS: - case ENUM: - case FINAL: - case INTERFACE: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOLATILE: - case SEMICOLON: - case AT: - ; - break; - default: - jj_la1[1] = jj_gen; - break label_2; - } - tn = TypeDeclaration(); - if(line==-1){line = tn.getBeginLine(); column = tn.getBeginColumn();} types = add(types, tn); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 0: - jj_consume_token(0); - break; - case 131: - jj_consume_token(131); - break; - default: - jj_la1[2] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return new CompilationUnit(line == -1 ? 0 : line, column, token.endLine, token.endColumn,pakage, imports, types);} - throw new Error("Missing return statement in function"); - } - - final public PackageDeclaration PackageDeclaration() throws ParseException { - List annotations = null; - AnnotationExpr ann; - NameExpr name; - int line; - int column; - label_3: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[3] = jj_gen; - break label_3; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - jj_consume_token(PACKAGE); - line=token.beginLine; column=token.beginColumn; - name = Name(); - jj_consume_token(SEMICOLON); - {if (true) return new PackageDeclaration(line, column, token.endLine, token.endColumn,annotations, name);} - throw new Error("Missing return statement in function"); - } - - final public ImportDeclaration ImportDeclaration() throws ParseException { - NameExpr name; - boolean isStatic = false; - boolean isAsterisk = false; - int line; - int column; - jj_consume_token(IMPORT); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STATIC: - jj_consume_token(STATIC); - isStatic = true; - break; - default: - jj_la1[4] = jj_gen; - ; - } - name = Name(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOT: - jj_consume_token(DOT); - jj_consume_token(STAR); - isAsterisk = true; - break; - default: - jj_la1[5] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - {if (true) return new ImportDeclaration(line, column, token.endLine, token.endColumn,name, isStatic, isAsterisk);} - throw new Error("Missing return statement in function"); - } - -/* - * Modifiers. We match all modifiers in a single rule to reduce the chances of - * syntax errors for simple modifier mistakes. It will also enable us to give - * better error messages. - */ - final public Modifier Modifiers() throws ParseException { - int beginLine = -1; - int beginColumn = -1; - int modifiers = 0; - List annotations = null; - AnnotationExpr ann; - label_4: - while (true) { - if (jj_2_2(2)) { - ; - } else { - break label_4; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PUBLIC: - jj_consume_token(PUBLIC); - modifiers = addModifier(modifiers, ModifierSet.PUBLIC, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case STATIC: - jj_consume_token(STATIC); - modifiers = addModifier(modifiers, ModifierSet.STATIC, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case PROTECTED: - jj_consume_token(PROTECTED); - modifiers = addModifier(modifiers, ModifierSet.PROTECTED, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case PRIVATE: - jj_consume_token(PRIVATE); - modifiers = addModifier(modifiers, ModifierSet.PRIVATE, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case FINAL: - jj_consume_token(FINAL); - modifiers = addModifier(modifiers, ModifierSet.FINAL, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case ABSTRACT: - jj_consume_token(ABSTRACT); - modifiers = addModifier(modifiers, ModifierSet.ABSTRACT, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case SYNCHRONIZED: - jj_consume_token(SYNCHRONIZED); - modifiers = addModifier(modifiers, ModifierSet.SYNCHRONIZED, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case NATIVE: - jj_consume_token(NATIVE); - modifiers = addModifier(modifiers, ModifierSet.NATIVE, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case TRANSIENT: - jj_consume_token(TRANSIENT); - modifiers = addModifier(modifiers, ModifierSet.TRANSIENT, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case VOLATILE: - jj_consume_token(VOLATILE); - modifiers = addModifier(modifiers, ModifierSet.VOLATILE, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case STRICTFP: - jj_consume_token(STRICTFP); - modifiers = addModifier(modifiers, ModifierSet.STRICTFP, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} - break; - case AT: - ann = Annotation(); - annotations = add(annotations, ann); if(beginLine==-1) {beginLine=ann.getBeginLine(); beginColumn=ann.getBeginColumn();} - break; - default: - jj_la1[6] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return new Modifier(beginLine, beginColumn, modifiers, annotations);} - throw new Error("Missing return statement in function"); - } - -/* - * Declaration syntax follows. - */ - final public TypeDeclaration TypeDeclaration() throws ParseException { - Modifier modifier; - TypeDeclaration ret; - - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn); - break; - case ABSTRACT: - case CLASS: - case ENUM: - case FINAL: - case INTERFACE: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOLATILE: - case AT: - modifier = Modifiers(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASS: - case INTERFACE: - ret = ClassOrInterfaceDeclaration(modifier); - break; - case ENUM: - ret = EnumDeclaration(modifier); - break; - case AT: - ret = AnnotationTypeDeclaration(modifier); - break; - default: - jj_la1[7] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - default: - jj_la1[8] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public ClassOrInterfaceDeclaration ClassOrInterfaceDeclaration(Modifier modifier) throws ParseException { - boolean isInterface = false; - NameExpr name; - List typePar = null; - List extList = null; - List impList = null; - List members; - int line = modifier.beginLine; - int column = modifier.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASS: - jj_consume_token(CLASS); - break; - case INTERFACE: - jj_consume_token(INTERFACE); - isInterface = true; - break; - default: - jj_la1[9] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - if (line == -1) {line=token.beginLine; column=token.beginColumn;} - name = Name(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typePar = TypeParameters(); - typePar.remove(0); - break; - default: - jj_la1[10] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXTENDS: - extList = ExtendsList(isInterface); - break; - default: - jj_la1[11] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IMPLEMENTS: - impList = ImplementsList(isInterface); - break; - default: - jj_la1[12] = jj_gen; - ; - } - members = ClassOrInterfaceBody(isInterface); - ClassOrInterfaceDeclaration tmp = new ClassOrInterfaceDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, isInterface, null, typePar, extList, impList, members); - tmp.setNameExpr(name); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public List ExtendsList(boolean isInterface) throws ParseException { - boolean extendsMoreThanOne = false; - List ret = new LinkedList(); - ClassOrInterfaceType cit; - AnnotationExpr ann; - List annotations = null; - jj_consume_token(EXTENDS); - label_5: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[13] = jj_gen; - break label_5; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - cit = ClassOrInterfaceType(); - cit.setAnnotations(annotations); ret.add(cit); - label_6: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[14] = jj_gen; - break label_6; - } - jj_consume_token(COMMA); - cit = ClassOrInterfaceType(); - ret.add(cit); extendsMoreThanOne = true; - } - if (extendsMoreThanOne && !isInterface) - throwParseException(token, "A class cannot extend more than one other class"); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ImplementsList(boolean isInterface) throws ParseException { - List ret = new LinkedList(); - ClassOrInterfaceType cit; - AnnotationExpr ann; - List annotations = null; - jj_consume_token(IMPLEMENTS); - label_7: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[15] = jj_gen; - break label_7; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - cit = ClassOrInterfaceType(); - cit.setAnnotations(annotations); ret.add(cit); - label_8: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[16] = jj_gen; - break label_8; - } - jj_consume_token(COMMA); - cit = ClassOrInterfaceType(); - ret.add(cit); - } - if (isInterface) - throwParseException(token, "An interface cannot implement other interfaces"); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public EnumDeclaration EnumDeclaration(Modifier modifier) throws ParseException { - NameExpr name; - List impList = null; - EnumConstantDeclaration entry; - List entries = null; - BodyDeclaration member; - List members = null; - int line = modifier.beginLine; - int column = modifier.beginColumn; - jj_consume_token(ENUM); - if (line == -1) {line=token.beginLine; column=token.beginColumn;} - name = Name(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IMPLEMENTS: - impList = ImplementsList(false); - break; - default: - jj_la1[17] = jj_gen; - ; - } - jj_consume_token(LBRACE); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - case AT: - entries = new LinkedList(); - entry = EnumConstantDeclaration(); - entries.add(entry); - label_9: - while (true) { - if (jj_2_3(2)) { - ; - } else { - break label_9; - } - jj_consume_token(COMMA); - entry = EnumConstantDeclaration(); - entries.add(entry); - } - break; - default: - jj_la1[18] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - jj_consume_token(COMMA); - break; - default: - jj_la1[19] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - label_10: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case CLASS: - case _DEFAULT: - case DOUBLE: - case ENUM: - case FINAL: - case FLOAT: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOID: - case VOLATILE: - case IDENTIFIER: - case LBRACE: - case SEMICOLON: - case AT: - case LT: - ; - break; - default: - jj_la1[20] = jj_gen; - break label_10; - } - member = ClassOrInterfaceBodyDeclaration(false); - members = add(members, member); - } - break; - default: - jj_la1[21] = jj_gen; - ; - } - jj_consume_token(RBRACE); - EnumDeclaration tmp = new EnumDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, null, impList, entries, members); - tmp.setNameExpr(name); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public EnumConstantDeclaration EnumConstantDeclaration() throws ParseException { - List annotations = null; - AnnotationExpr ann; - String name; - List args = null; - List classBody = null; - int line = -1; - int column = -1; - - label_11: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[22] = jj_gen; - break label_11; - } - ann = Annotation(); - annotations = add(annotations, ann); if(line==-1){line=ann.getBeginLine(); column=ann.getBeginColumn();} - } - jj_consume_token(IDENTIFIER); - name = token.image; if(line==-1){line=token.beginLine; column=token.beginColumn;} - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - args = Arguments(); - break; - default: - jj_la1[23] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACE: - classBody = ClassOrInterfaceBody(false); - break; - default: - jj_la1[24] = jj_gen; - ; - } - EnumConstantDeclaration tmp = new EnumConstantDeclaration(line, column, token.endLine, token.endColumn, annotations, name, args, classBody); - - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public List TypeParameters() throws ParseException { - List ret = new LinkedList(); - TypeParameter tp; - List annotations = null; - AnnotationExpr ann; - jj_consume_token(LT); - ret.add(new int[]{token.beginLine, token.beginColumn}); - label_12: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[25] = jj_gen; - break label_12; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - tp = TypeParameter(); - ret.add(tp); tp.setAnnotations(annotations); annotations = null; - label_13: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[26] = jj_gen; - break label_13; - } - jj_consume_token(COMMA); - label_14: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[27] = jj_gen; - break label_14; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - tp = TypeParameter(); - ret.add(tp); tp.setAnnotations(annotations); annotations = null; - } - jj_consume_token(GT); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public TypeParameter TypeParameter() throws ParseException { - String name; - List typeBound = null; - int line; - int column; - jj_consume_token(IDENTIFIER); - name = token.image; line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXTENDS: - typeBound = TypeBound(); - break; - default: - jj_la1[28] = jj_gen; - ; - } - {if (true) return new TypeParameter(line, column, token.endLine, token.endColumn,name, typeBound);} - throw new Error("Missing return statement in function"); - } - - final public List TypeBound() throws ParseException { - List ret = new LinkedList(); - ClassOrInterfaceType cit; - AnnotationExpr ann; - List annotations = null; - jj_consume_token(EXTENDS); - label_15: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[29] = jj_gen; - break label_15; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - cit = ClassOrInterfaceType(); - cit.setAnnotations(annotations); ret.add(cit); annotations=null; - label_16: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_AND: - ; - break; - default: - jj_la1[30] = jj_gen; - break label_16; - } - jj_consume_token(BIT_AND); - label_17: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[31] = jj_gen; - break label_17; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - cit = ClassOrInterfaceType(); - cit.setAnnotations(annotations); ret.add(cit); annotations=null; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ClassOrInterfaceBody(boolean isInterface) throws ParseException { - List ret = new LinkedList(); - BodyDeclaration member; - jj_consume_token(LBRACE); - label_18: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case CLASS: - case _DEFAULT: - case DOUBLE: - case ENUM: - case FINAL: - case FLOAT: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOID: - case VOLATILE: - case IDENTIFIER: - case LBRACE: - case SEMICOLON: - case AT: - case LT: - ; - break; - default: - jj_la1[32] = jj_gen; - break label_18; - } - member = ClassOrInterfaceBodyDeclaration(isInterface); - ret.add(member); - } - jj_consume_token(RBRACE); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public BodyDeclaration ClassOrInterfaceBodyDeclaration(boolean isInterface) throws ParseException { - boolean isNestedInterface = false; - Modifier modifier; - Modifier modifier2 = null; - int aux = 0; - BodyDeclaration ret; - boolean isDefault = false; - - if (jj_2_6(2)) { - ret = InitializerDeclaration(); - if (isInterface) - throwParseException(token, "An interface cannot have initializers"); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case CLASS: - case _DEFAULT: - case DOUBLE: - case ENUM: - case FINAL: - case FLOAT: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOID: - case VOLATILE: - case IDENTIFIER: - case AT: - case LT: - modifier = Modifiers(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case _DEFAULT: - jj_consume_token(_DEFAULT); - modifier2 = Modifiers(); - if(!isInterface) - { - throwParseException(token, "An interface cannot have default members"); - } - isDefault = true; - break; - default: - jj_la1[33] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASS: - case INTERFACE: - ret = ClassOrInterfaceDeclaration(modifier); - break; - case ENUM: - ret = EnumDeclaration(modifier); - break; - case AT: - ret = AnnotationTypeDeclaration(modifier); - break; - default: - jj_la1[34] = jj_gen; - if (jj_2_4(2147483647)) { - ret = ConstructorDeclaration(modifier); - } else if (jj_2_5(2147483647)) { - ret = FieldDeclaration(modifier); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - case VOID: - case IDENTIFIER: - case LT: - ret = MethodDeclaration(modifier); - if(isDefault && ret!= null && ((MethodDeclaration)ret).getBody() == null) - { - throwParseException(token, "\u005c"default\u005c" methods must have a body"); - } - ((MethodDeclaration)ret).setDefault(isDefault); - if(modifier2!= null) - { - aux = modifier2.modifiers; - } - ((MethodDeclaration)ret).setModifiers(addModifier(modifier.modifiers, aux, token)); - break; - default: - jj_la1[35] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - } - if(isDefault && ! (ret instanceof MethodDeclaration)) - { - throwParseException(token, "Just methods can have the keyword \u005c"default\u005c"."); - } - break; - case SEMICOLON: - jj_consume_token(SEMICOLON); - ret = new EmptyMemberDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn); - break; - default: - jj_la1[36] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public FieldDeclaration FieldDeclaration(Modifier modifier) throws ParseException { - Type type; - List variables = new LinkedList(); - VariableDeclarator val; - // Modifiers are already matched in the caller - type = Type(); - val = VariableDeclarator(); - variables.add(val); - label_19: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[37] = jj_gen; - break label_19; - } - jj_consume_token(COMMA); - val = VariableDeclarator(); - variables.add(val); - } - jj_consume_token(SEMICOLON); - int line = modifier.beginLine; - int column = modifier.beginColumn; - if (line == -1) { line=type.getBeginLine(); column=type.getBeginColumn(); } - {if (true) return new FieldDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, type, variables);} - throw new Error("Missing return statement in function"); - } - - final public VariableDeclarator VariableDeclarator() throws ParseException { - VariableDeclaratorId id; - Expression init = null; - id = VariableDeclaratorId(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSIGN: - jj_consume_token(ASSIGN); - init = VariableInitializer(); - break; - default: - jj_la1[38] = jj_gen; - ; - } - {if (true) return new VariableDeclarator(id.getBeginLine(), id.getBeginColumn(), token.endLine, token.endColumn, id, init);} - throw new Error("Missing return statement in function"); - } - - final public VariableDeclaratorId VariableDeclaratorId() throws ParseException { - String name; - int arrayCount = 0; - int line; - int column; - jj_consume_token(IDENTIFIER); - name = token.image; line=token.beginLine; column=token.beginColumn; - label_20: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACKET: - ; - break; - default: - jj_la1[39] = jj_gen; - break label_20; - } - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - arrayCount++; - } - {if (true) return new VariableDeclaratorId(line, column, token.endLine, token.endColumn,name, arrayCount);} - throw new Error("Missing return statement in function"); - } - - final public Expression VariableInitializer() throws ParseException { - Expression ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACE: - ret = ArrayInitializer(); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - ret = Expression(); - break; - default: - jj_la1[40] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public ArrayInitializerExpr ArrayInitializer() throws ParseException { - List values = null; - Expression val; - int line; - int column; - jj_consume_token(LBRACE); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case LBRACE: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - val = VariableInitializer(); - values = add(values, val); - label_21: - while (true) { - if (jj_2_7(2)) { - ; - } else { - break label_21; - } - jj_consume_token(COMMA); - val = VariableInitializer(); - values = add(values, val); - } - break; - default: - jj_la1[41] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - jj_consume_token(COMMA); - break; - default: - jj_la1[42] = jj_gen; - ; - } - jj_consume_token(RBRACE); - {if (true) return new ArrayInitializerExpr(line, column, token.endLine, token.endColumn,values);} - throw new Error("Missing return statement in function"); - } - - final public MethodDeclaration MethodDeclaration(Modifier modifier) throws ParseException { - List typeParameters = null; - Type type; - NameExpr name; - List parameters; - int arrayCount = 0; - List throws_ = null; - BlockStmt block = null; - int line = modifier.beginLine; - int column = modifier.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeParameters = TypeParameters(); - int[] lineCol=(int[])typeParameters.remove(0); if(line==-1){ line=lineCol[0]; column=lineCol[1];} - break; - default: - jj_la1[43] = jj_gen; - ; - } - type = ResultType(); - if(line==-1){line=type.getBeginLine(); column=type.getBeginColumn();} - name = Name(); - parameters = FormalParameters(); - label_22: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACKET: - ; - break; - default: - jj_la1[44] = jj_gen; - break label_22; - } - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - arrayCount++; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case THROWS: - jj_consume_token(THROWS); - throws_ = NameList(); - break; - default: - jj_la1[45] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACE: - block = Block(); - break; - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - default: - jj_la1[46] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - MethodDeclaration tmp = new MethodDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, typeParameters, type, null, parameters, arrayCount, throws_, block); - tmp.setNameExpr(name); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public List FormalParameters() throws ParseException { - List ret = null; - Parameter par; - jj_consume_token(LPAREN); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FINAL: - case FLOAT: - case INT: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOLATILE: - case IDENTIFIER: - case AT: - par = FormalParameter(); - ret = add(ret, par); - label_23: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[47] = jj_gen; - break label_23; - } - jj_consume_token(COMMA); - par = FormalParameter(); - ret = add(ret, par); - } - break; - default: - jj_la1[48] = jj_gen; - ; - } - jj_consume_token(RPAREN); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List FormalLambdaParameters() throws ParseException { - List ret = null; - Parameter par; - jj_consume_token(COMMA); - par = FormalParameter(); - ret = add(ret, par); - label_24: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[49] = jj_gen; - break label_24; - } - jj_consume_token(COMMA); - par = FormalParameter(); - ret = add(ret, par); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List InferredLambdaParameters() throws ParseException { - List ret = null; - VariableDeclaratorId id; - jj_consume_token(COMMA); - id = VariableDeclaratorId(); - ret = add(ret, new Parameter(id.getBeginLine(), id.getBeginColumn(), id.getEndLine(), id.getEndColumn(), 0, null, new UnknownType(), false, id)); - label_25: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[50] = jj_gen; - break label_25; - } - jj_consume_token(COMMA); - id = VariableDeclaratorId(); - ret = add(ret, new Parameter(id.getBeginLine(), id.getBeginColumn(), id.getEndLine(), id.getEndColumn(), 0, null, new UnknownType(), false, id)); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Parameter FormalParameter() throws ParseException { - Modifier modifier; - Type type; - boolean isVarArg = false; - VariableDeclaratorId id; - modifier = Modifiers(); - type = Type(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ELLIPSIS: - jj_consume_token(ELLIPSIS); - isVarArg = true; - break; - default: - jj_la1[51] = jj_gen; - ; - } - id = VariableDeclaratorId(); - int line = modifier.beginLine; - int column = modifier.beginColumn; - if(line==-1){ line=type.getBeginLine(); column=type.getBeginColumn(); } - {if (true) return new Parameter(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, type, isVarArg, id);} - throw new Error("Missing return statement in function"); - } - - final public ConstructorDeclaration ConstructorDeclaration(Modifier modifier) throws ParseException { - List typeParameters = null; - NameExpr name; - List parameters; - List throws_ = null; - ExplicitConstructorInvocationStmt exConsInv = null; - List stmts; - int line = modifier.beginLine; - int column = modifier.beginColumn; - int bbLine = 0; - int bbColumn = 0; - int beLine = 0; - int beColumn = 0; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeParameters = TypeParameters(); - int[] lineCol=(int[])typeParameters.remove(0); if(line==-1){ line=lineCol[0]; column=lineCol[1];} - break; - default: - jj_la1[52] = jj_gen; - ; - } - // Modifiers matched in the caller - name = SimpleName(); - if(line==-1){line=token.beginLine; column=token.beginColumn;} - parameters = FormalParameters(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case THROWS: - jj_consume_token(THROWS); - throws_ = NameList(); - break; - default: - jj_la1[53] = jj_gen; - ; - } - jj_consume_token(LBRACE); - bbLine=token.beginLine; bbColumn=token.beginColumn; - if (jj_2_8(2147483647)) { - exConsInv = ExplicitConstructorInvocation(); - } else { - ; - } - stmts = Statements(); - jj_consume_token(RBRACE); - if (exConsInv != null) { - stmts = add(0, stmts, exConsInv); - } - ConstructorDeclaration tmp = new ConstructorDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, typeParameters, null, parameters, throws_, new BlockStmt(bbLine, bbColumn, token.endLine, token.endColumn, stmts)); - tmp.setNameExpr(name); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public ExplicitConstructorInvocationStmt ExplicitConstructorInvocation() throws ParseException { - boolean isThis = false; - List args; - Expression expr = null; - List typeArgs = null; - int line = -1; - int column = 0; - if (jj_2_10(2147483647)) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case 132: - typeArgs = TypeArguments(); - int[] lineCol=(int[])typeArgs.remove(0); line=lineCol[0]; column=lineCol[1]; - break; - default: - jj_la1[54] = jj_gen; - ; - } - jj_consume_token(THIS); - if (line == -1) {line=token.beginLine; column=token.beginColumn;} isThis = true; - args = Arguments(); - jj_consume_token(SEMICOLON); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case LT: - case 132: - if (jj_2_9(2147483647)) { - expr = PrimaryExpressionWithoutSuperSuffix(); - jj_consume_token(DOT); - line=expr.getBeginLine(); column=expr.getBeginColumn(); - } else { - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case 132: - typeArgs = TypeArguments(); - int[] lineCol=(int[])typeArgs.remove(0); if (line == -1) {line=lineCol[0]; column=lineCol[1];} - break; - default: - jj_la1[55] = jj_gen; - ; - } - jj_consume_token(SUPER); - if (line == -1) {line=token.beginLine; column=token.beginColumn;} - args = Arguments(); - jj_consume_token(SEMICOLON); - break; - default: - jj_la1[56] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return new ExplicitConstructorInvocationStmt(line, column, token.endLine, token.endColumn,typeArgs, isThis, expr, args);} - throw new Error("Missing return statement in function"); - } - - final public List Statements() throws ParseException { - List ret = null; - Statement stmt; - label_26: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case ASSERT: - case BOOLEAN: - case BREAK: - case BYTE: - case CHAR: - case CLASS: - case CONTINUE: - case DO: - case DOUBLE: - case FALSE: - case FINAL: - case FLOAT: - case FOR: - case IF: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case NEW: - case NULL: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case RETURN: - case SHORT: - case STATIC: - case STRICTFP: - case SUPER: - case SWITCH: - case SYNCHRONIZED: - case THIS: - case THROW: - case TRANSIENT: - case TRUE: - case TRY: - case VOID: - case VOLATILE: - case WHILE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case LBRACE: - case SEMICOLON: - case AT: - case INCR: - case DECR: - ; - break; - default: - jj_la1[57] = jj_gen; - break label_26; - } - stmt = BlockStatement(); - ret = add(ret, stmt); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public InitializerDeclaration InitializerDeclaration() throws ParseException { - BlockStmt block; - int line = -1; - int column = 0; - boolean isStatic = false; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STATIC: - jj_consume_token(STATIC); - isStatic = true; line=token.beginLine; column=token.beginColumn; - break; - default: - jj_la1[58] = jj_gen; - ; - } - block = Block(); - if(line==-1){line=block.getBeginLine(); column=block.getBeginColumn();} - {if (true) return new InitializerDeclaration(line, column, token.endLine, token.endColumn, isStatic, block);} - throw new Error("Missing return statement in function"); - } - -/* - * Type, name and expression syntax follows. - */ - final public Type Type() throws ParseException { - Type ret; - if (jj_2_11(2)) { - ret = ReferenceType(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - ret = PrimitiveType(); - break; - default: - jj_la1[59] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public ReferenceType ReferenceType() throws ParseException { - Type type; - int arrayCount = 0; - List annotations = null; - List accum= null; - AnnotationExpr ann; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - type = PrimitiveType(); - label_27: - while (true) { - label_28: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[60] = jj_gen; - break label_28; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - arrayCount++; accum = add(accum, annotations); annotations= null; - if (jj_2_12(2)) { - ; - } else { - break label_27; - } - } - break; - case IDENTIFIER: - type = ClassOrInterfaceType(); - label_29: - while (true) { - if (jj_2_13(2)) { - ; - } else { - break label_29; - } - label_30: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[61] = jj_gen; - break label_30; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - arrayCount++; accum = add(accum, annotations); annotations= null; - } - break; - default: - jj_la1[62] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return new ReferenceType(type.getBeginLine(), type.getBeginColumn(), token.endLine, token.endColumn, type, arrayCount, null, accum);} - throw new Error("Missing return statement in function"); - } - - final public ClassOrInterfaceType ClassOrInterfaceType() throws ParseException { - ClassOrInterfaceType ret; - String name; - List typeArgs = null; - int line; - int column; - List annotations = null; - AnnotationExpr ann; - jj_consume_token(IDENTIFIER); - line=token.beginLine; column=token.beginColumn; - name = token.image; - if (jj_2_14(2)) { - typeArgs = TypeArguments(); - typeArgs.remove(0); - } else { - ; - } - ret = new ClassOrInterfaceType(line, column, token.endLine, token.endColumn,null, name, typeArgs); - label_31: - while (true) { - if (jj_2_15(2)) { - ; - } else { - break label_31; - } - jj_consume_token(DOT); - label_32: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[63] = jj_gen; - break label_32; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - jj_consume_token(IDENTIFIER); - name = token.image; - if (jj_2_16(2)) { - typeArgs = TypeArguments(); - typeArgs.remove(0); - } else { - ; - } - ret = new ClassOrInterfaceType(line, column, token.endLine, token.endColumn,ret, name, typeArgs); ret.setAnnotations(annotations); annotations = null; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List TypeArguments() throws ParseException { - List ret = new LinkedList(); - Type type; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - jj_consume_token(LT); - ret.add(new int[]{token.beginLine, token.beginColumn}); - type = TypeArgument(); - ret.add(type); - label_33: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[64] = jj_gen; - break label_33; - } - jj_consume_token(COMMA); - type = TypeArgument(); - ret.add(type); - } - jj_consume_token(GT); - {if (true) return ret;} - break; - case 132: - jj_consume_token(132); - ret.add(null); - {if (true) return ret;} - break; - default: - jj_la1[65] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - final public Type TypeArgument() throws ParseException { - Type ret; - List annotations = null; - AnnotationExpr ann; - label_34: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[66] = jj_gen; - break label_34; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - case IDENTIFIER: - ret = ReferenceType(); - break; - case HOOK: - ret = Wildcard(); - break; - default: - jj_la1[67] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret.setAnnotations(annotations); {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public WildcardType Wildcard() throws ParseException { - ReferenceType ext = null; - ReferenceType sup = null; - int line; - int column; - AnnotationExpr ann; - List annotations = null; - jj_consume_token(HOOK); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXTENDS: - case SUPER: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXTENDS: - jj_consume_token(EXTENDS); - label_35: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[68] = jj_gen; - break label_35; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - ext = ReferenceType(); - ext.setAnnotations(annotations); - break; - case SUPER: - jj_consume_token(SUPER); - label_36: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[69] = jj_gen; - break label_36; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - sup = ReferenceType(); - sup.setAnnotations(annotations); - break; - default: - jj_la1[70] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - default: - jj_la1[71] = jj_gen; - ; - } - {if (true) return new WildcardType(line, column, token.endLine, token.endColumn,ext, sup);} - throw new Error("Missing return statement in function"); - } - - final public PrimitiveType PrimitiveType() throws ParseException { - PrimitiveType ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - jj_consume_token(BOOLEAN); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Boolean); - break; - case CHAR: - jj_consume_token(CHAR); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Char); - break; - case BYTE: - jj_consume_token(BYTE); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Byte); - break; - case SHORT: - jj_consume_token(SHORT); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Short); - break; - case INT: - jj_consume_token(INT); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Int); - break; - case LONG: - jj_consume_token(LONG); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Long); - break; - case FLOAT: - jj_consume_token(FLOAT); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Float); - break; - case DOUBLE: - jj_consume_token(DOUBLE); - ret = new PrimitiveType(token.beginLine, token.beginColumn, token.endLine, token.endColumn, PrimitiveType.Primitive.Double); - break; - default: - jj_la1[72] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Type ResultType() throws ParseException { - Type ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case VOID: - jj_consume_token(VOID); - ret = new VoidType(token.beginLine, token.beginColumn, token.endLine, token.endColumn); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - case IDENTIFIER: - ret = Type(); - break; - default: - jj_la1[73] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public NameExpr Name() throws ParseException { - NameExpr ret; - jj_consume_token(IDENTIFIER); - ret = new NameExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); - label_37: - while (true) { - if (jj_2_17(2)) { - ; - } else { - break label_37; - } - jj_consume_token(DOT); - jj_consume_token(IDENTIFIER); - ret = new QualifiedNameExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, token.image); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ClassOrInterfaceTypeList() throws ParseException { - List ret = new LinkedList(); - ClassOrInterfaceType type; - List annotations= null; - AnnotationExpr ann; - label_38: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[74] = jj_gen; - break label_38; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - type = ClassOrInterfaceType(); - type.setAnnotations(annotations); ret.add(type); annotations=null; - label_39: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[75] = jj_gen; - break label_39; - } - jj_consume_token(COMMA); - label_40: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[76] = jj_gen; - break label_40; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - type = ClassOrInterfaceType(); - type.setAnnotations(annotations); ret.add(type); annotations=null; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public NameExpr SimpleName() throws ParseException { - NameExpr ret; - jj_consume_token(IDENTIFIER); - ret = new NameExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List NameList() throws ParseException { - List ret = new LinkedList(); - NameExpr name; - name = Name(); - ret.add(name); - label_41: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[77] = jj_gen; - break label_41; - } - jj_consume_token(COMMA); - name = Name(); - ret.add(name); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - -/* - * Expression syntax follows. - */ - final public Expression Expression() throws ParseException { - Expression ret; - AssignExpr.Operator op; - Expression value; - Statement lambdaBody = null; - List params = null; - List typeArgs = null; - VariableDeclaratorId id = null; - Expression inner = null; - ret = ConditionalExpression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSIGN: - case PLUSASSIGN: - case MINUSASSIGN: - case STARASSIGN: - case SLASHASSIGN: - case ANDASSIGN: - case ORASSIGN: - case XORASSIGN: - case REMASSIGN: - case LSHIFTASSIGN: - case RSIGNEDSHIFTASSIGN: - case RUNSIGNEDSHIFTASSIGN: - case ARROW: - case DOUBLECOLON: - if (jj_2_18(2)) { - op = AssignmentOperator(); - value = Expression(); - ret = new AssignExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, value, op); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ARROW: - jj_consume_token(ARROW); - lambdaBody = LambdaBody(); - if (ret instanceof CastExpr) - { - inner = generateLambda(((CastExpr)ret).getExpr(), lambdaBody); - ((CastExpr)ret).setExpr(inner); - } - else - { - ret = generateLambda(ret, lambdaBody); - } - break; - case DOUBLECOLON: - jj_consume_token(DOUBLECOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeArgs = TypeParameters(); - typeArgs.remove(0); - break; - default: - jj_la1[78] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - break; - case NEW: - jj_consume_token(NEW); - break; - default: - jj_la1[79] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = new MethodReferenceExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, typeArgs, token.image); - break; - default: - jj_la1[80] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - default: - jj_la1[81] = jj_gen; - ; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public AssignExpr.Operator AssignmentOperator() throws ParseException { - AssignExpr.Operator ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSIGN: - jj_consume_token(ASSIGN); - ret = AssignExpr.Operator.assign; - break; - case STARASSIGN: - jj_consume_token(STARASSIGN); - ret = AssignExpr.Operator.star; - break; - case SLASHASSIGN: - jj_consume_token(SLASHASSIGN); - ret = AssignExpr.Operator.slash; - break; - case REMASSIGN: - jj_consume_token(REMASSIGN); - ret = AssignExpr.Operator.rem; - break; - case PLUSASSIGN: - jj_consume_token(PLUSASSIGN); - ret = AssignExpr.Operator.plus; - break; - case MINUSASSIGN: - jj_consume_token(MINUSASSIGN); - ret = AssignExpr.Operator.minus; - break; - case LSHIFTASSIGN: - jj_consume_token(LSHIFTASSIGN); - ret = AssignExpr.Operator.lShift; - break; - case RSIGNEDSHIFTASSIGN: - jj_consume_token(RSIGNEDSHIFTASSIGN); - ret = AssignExpr.Operator.rSignedShift; - break; - case RUNSIGNEDSHIFTASSIGN: - jj_consume_token(RUNSIGNEDSHIFTASSIGN); - ret = AssignExpr.Operator.rUnsignedShift; - break; - case ANDASSIGN: - jj_consume_token(ANDASSIGN); - ret = AssignExpr.Operator.and; - break; - case XORASSIGN: - jj_consume_token(XORASSIGN); - ret = AssignExpr.Operator.xor; - break; - case ORASSIGN: - jj_consume_token(ORASSIGN); - ret = AssignExpr.Operator.or; - break; - default: - jj_la1[82] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression ConditionalExpression() throws ParseException { - Expression ret; - Expression left; - Expression right; - ret = ConditionalOrExpression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case HOOK: - jj_consume_token(HOOK); - left = Expression(); - jj_consume_token(COLON); - right = ConditionalExpression(); - ret = new ConditionalExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, left, right); - break; - default: - jj_la1[83] = jj_gen; - ; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression ConditionalOrExpression() throws ParseException { - Expression ret; - Expression right; - ret = ConditionalAndExpression(); - label_42: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SC_OR: - ; - break; - default: - jj_la1[84] = jj_gen; - break label_42; - } - jj_consume_token(SC_OR); - right = ConditionalAndExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.or); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression ConditionalAndExpression() throws ParseException { - Expression ret; - Expression right; - ret = InclusiveOrExpression(); - label_43: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SC_AND: - ; - break; - default: - jj_la1[85] = jj_gen; - break label_43; - } - jj_consume_token(SC_AND); - right = InclusiveOrExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.and); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression InclusiveOrExpression() throws ParseException { - Expression ret; - Expression right; - ret = ExclusiveOrExpression(); - label_44: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_OR: - ; - break; - default: - jj_la1[86] = jj_gen; - break label_44; - } - jj_consume_token(BIT_OR); - right = ExclusiveOrExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.binOr); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression ExclusiveOrExpression() throws ParseException { - Expression ret; - Expression right; - ret = AndExpression(); - label_45: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case XOR: - ; - break; - default: - jj_la1[87] = jj_gen; - break label_45; - } - jj_consume_token(XOR); - right = AndExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.xor); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression AndExpression() throws ParseException { - Expression ret; - Expression right; - ret = EqualityExpression(); - label_46: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_AND: - ; - break; - default: - jj_la1[88] = jj_gen; - break label_46; - } - jj_consume_token(BIT_AND); - right = EqualityExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.binAnd); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression EqualityExpression() throws ParseException { - Expression ret; - Expression right; - BinaryExpr.Operator op; - ret = InstanceOfExpression(); - label_47: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EQ: - case NE: - ; - break; - default: - jj_la1[89] = jj_gen; - break label_47; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EQ: - jj_consume_token(EQ); - op = BinaryExpr.Operator.equals; - break; - case NE: - jj_consume_token(NE); - op = BinaryExpr.Operator.notEquals; - break; - default: - jj_la1[90] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - right = InstanceOfExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression InstanceOfExpression() throws ParseException { - Expression ret; - Type type; - ret = RelationalExpression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INSTANCEOF: - jj_consume_token(INSTANCEOF); - type = Type(); - ret = new InstanceOfExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, type); - break; - default: - jj_la1[91] = jj_gen; - ; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression RelationalExpression() throws ParseException { - Expression ret; - Expression right; - BinaryExpr.Operator op; - ret = ShiftExpression(); - label_48: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case LE: - case GE: - case GT: - ; - break; - default: - jj_la1[92] = jj_gen; - break label_48; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - jj_consume_token(LT); - op = BinaryExpr.Operator.less; - break; - case GT: - jj_consume_token(GT); - op = BinaryExpr.Operator.greater; - break; - case LE: - jj_consume_token(LE); - op = BinaryExpr.Operator.lessEquals; - break; - case GE: - jj_consume_token(GE); - op = BinaryExpr.Operator.greaterEquals; - break; - default: - jj_la1[93] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - right = ShiftExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression ShiftExpression() throws ParseException { - Expression ret; - Expression right; - BinaryExpr.Operator op; - ret = AdditiveExpression(); - label_49: - while (true) { - if (jj_2_19(1)) { - ; - } else { - break label_49; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LSHIFT: - jj_consume_token(LSHIFT); - op = BinaryExpr.Operator.lShift; - break; - default: - jj_la1[94] = jj_gen; - if (jj_2_20(1)) { - RSIGNEDSHIFT(); - op = BinaryExpr.Operator.rSignedShift; - } else if (jj_2_21(1)) { - RUNSIGNEDSHIFT(); - op = BinaryExpr.Operator.rUnsignedShift; - } else { - jj_consume_token(-1); - throw new ParseException(); - } - } - right = AdditiveExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression AdditiveExpression() throws ParseException { - Expression ret; - Expression right; - BinaryExpr.Operator op; - ret = MultiplicativeExpression(); - label_50: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PLUS: - case MINUS: - ; - break; - default: - jj_la1[95] = jj_gen; - break label_50; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PLUS: - jj_consume_token(PLUS); - op = BinaryExpr.Operator.plus; - break; - case MINUS: - jj_consume_token(MINUS); - op = BinaryExpr.Operator.minus; - break; - default: - jj_la1[96] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - right = MultiplicativeExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression MultiplicativeExpression() throws ParseException { - Expression ret; - Expression right; - BinaryExpr.Operator op; - ret = UnaryExpression(); - label_51: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STAR: - case SLASH: - case REM: - ; - break; - default: - jj_la1[97] = jj_gen; - break label_51; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STAR: - jj_consume_token(STAR); - op = BinaryExpr.Operator.times; - break; - case SLASH: - jj_consume_token(SLASH); - op = BinaryExpr.Operator.divide; - break; - case REM: - jj_consume_token(REM); - op = BinaryExpr.Operator.remainder; - break; - default: - jj_la1[98] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - right = UnaryExpression(); - ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression UnaryExpression() throws ParseException { - Expression ret; - UnaryExpr.Operator op; - int line = 0; - int column = 0; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INCR: - ret = PreIncrementExpression(); - break; - case DECR: - ret = PreDecrementExpression(); - break; - case PLUS: - case MINUS: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PLUS: - jj_consume_token(PLUS); - op = UnaryExpr.Operator.positive; line=token.beginLine; column=token.beginColumn; - break; - case MINUS: - jj_consume_token(MINUS); - op = UnaryExpr.Operator.negative; line=token.beginLine; column=token.beginColumn; - break; - default: - jj_la1[99] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = UnaryExpression(); - if(op == UnaryExpr.Operator.negative) { - if (ret instanceof IntegerLiteralExpr && ((IntegerLiteralExpr)ret).isMinValue()) { - ret = new IntegerLiteralMinValueExpr(line, column, token.endLine, token.endColumn); - } else if (ret instanceof LongLiteralExpr && ((LongLiteralExpr)ret).isMinValue()) { - ret = new LongLiteralMinValueExpr(line, column, token.endLine, token.endColumn); - } else { - ret = new UnaryExpr(line, column, token.endLine, token.endColumn,ret, op); - } - } else { - ret = new UnaryExpr(line, column, token.endLine, token.endColumn,ret, op); - } - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - ret = UnaryExpressionNotPlusMinus(); - break; - default: - jj_la1[100] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PreIncrementExpression() throws ParseException { - Expression ret; - int line; - int column; - jj_consume_token(INCR); - line=token.beginLine; column=token.beginColumn; - ret = UnaryExpression(); - ret = new UnaryExpr(line, column, token.endLine, token.endColumn,ret, UnaryExpr.Operator.preIncrement); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PreDecrementExpression() throws ParseException { - Expression ret; - int line; - int column; - jj_consume_token(DECR); - line=token.beginLine; column=token.beginColumn; - ret = UnaryExpression(); - ret = new UnaryExpr(line, column, token.endLine, token.endColumn,ret, UnaryExpr.Operator.preDecrement); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression UnaryExpressionNotPlusMinus() throws ParseException { - Expression ret; - UnaryExpr.Operator op; - int line = 0; - int column = 0; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BANG: - case TILDE: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TILDE: - jj_consume_token(TILDE); - op = UnaryExpr.Operator.inverse; line=token.beginLine; column=token.beginColumn; - break; - case BANG: - jj_consume_token(BANG); - op = UnaryExpr.Operator.not; line=token.beginLine; column=token.beginColumn; - break; - default: - jj_la1[101] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = UnaryExpression(); - ret = new UnaryExpr(line, column, token.endLine, token.endColumn,ret, op); - break; - default: - jj_la1[102] = jj_gen; - if (jj_2_22(2147483647)) { - ret = CastExpression(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - ret = PostfixExpression(); - break; - default: - jj_la1[103] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PostfixExpression() throws ParseException { - Expression ret; - UnaryExpr.Operator op; - ret = PrimaryExpression(); - if (jj_2_23(2)) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INCR: - jj_consume_token(INCR); - op = UnaryExpr.Operator.posIncrement; - break; - case DECR: - jj_consume_token(DECR); - op = UnaryExpr.Operator.posDecrement; - break; - default: - jj_la1[104] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = new UnaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, op); - } else { - ; - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression CastExpression() throws ParseException { - Expression ret; - Type type; - int line; - int column; - AnnotationExpr ann; - List annotations = null; - jj_consume_token(LPAREN); - line=token.beginLine; column=token.beginColumn; - label_52: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[105] = jj_gen; - break label_52; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - if (jj_2_24(2)) { - type = PrimitiveType(); - jj_consume_token(RPAREN); - ret = UnaryExpression(); - type.setAnnotations(annotations); ret = new CastExpr(line, column, token.endLine, token.endColumn,type, ret); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - case IDENTIFIER: - type = ReferenceType(); - jj_consume_token(RPAREN); - ret = UnaryExpressionNotPlusMinus(); - type.setAnnotations(annotations); ret = new CastExpr(line, column, token.endLine, token.endColumn,type, ret); - break; - default: - jj_la1[106] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PrimaryExpression() throws ParseException { - Expression ret; - Expression inner; - ret = PrimaryPrefix(); - label_53: - while (true) { - if (jj_2_25(2)) { - ; - } else { - break label_53; - } - ret = PrimarySuffix(ret); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PrimaryExpressionWithoutSuperSuffix() throws ParseException { - Expression ret; - Expression inner; - ret = PrimaryPrefix(); - label_54: - while (true) { - if (jj_2_26(2147483647)) { - ; - } else { - break label_54; - } - ret = PrimarySuffixWithoutSuper(ret); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PrimaryPrefix() throws ParseException { - Expression ret = null; - NameExpr name; - List typeArgs = null; - List args = null; - boolean hasArgs = false; - boolean isLambda = false; - Type type; - int line; - int column; - Parameter p = null; - VariableDeclaratorId id = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case FALSE: - case NULL: - case TRUE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - ret = Literal(); - break; - case THIS: - jj_consume_token(THIS); - ret = new ThisExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, null); - break; - case SUPER: - jj_consume_token(SUPER); - ret = new SuperExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, null); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOT: - jj_consume_token(DOT); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case 132: - typeArgs = TypeArguments(); - typeArgs.remove(0); - break; - default: - jj_la1[107] = jj_gen; - ; - } - name = SimpleName(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - args = Arguments(); - hasArgs=true; - break; - default: - jj_la1[108] = jj_gen; - ; - } - if (hasArgs) { - MethodCallExpr m = new MethodCallExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, typeArgs, null, args); - m.setNameExpr(name); - ret = m; - } else { - FieldAccessExpr f = new FieldAccessExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, null, null); - f.setFieldExpr(name); - ret = f; - } - break; - case DOUBLECOLON: - jj_consume_token(DOUBLECOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeArgs = TypeParameters(); - typeArgs.remove(0); - break; - default: - jj_la1[109] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - break; - case NEW: - jj_consume_token(NEW); - break; - default: - jj_la1[110] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = new MethodReferenceExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, typeArgs, token.image); - break; - case LPAREN: - args = Arguments(); - new MethodCallExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, typeArgs, null, args); - break; - default: - jj_la1[111] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - case LPAREN: - jj_consume_token(LPAREN); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FINAL: - case FLOAT: - case INT: - case LONG: - case NATIVE: - case NEW: - case NULL: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SUPER: - case SYNCHRONIZED: - case THIS: - case TRANSIENT: - case TRUE: - case VOID: - case VOLATILE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case AT: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - if (jj_2_27(2147483647)) { - p = FormalParameter(); - isLambda = true; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - args = FormalLambdaParameters(); - break; - default: - jj_la1[112] = jj_gen; - ; - } - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - ret = Expression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - args = InferredLambdaParameters(); - isLambda = true; - break; - default: - jj_la1[113] = jj_gen; - ; - } - break; - default: - jj_la1[114] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - default: - jj_la1[115] = jj_gen; - ; - } - jj_consume_token(RPAREN); - if(!isLambda) { ret = new EnclosedExpr(line, column, token.endLine, token.endColumn,ret);} - else{ - if(ret != null){ - if(ret instanceof NameExpr) - { - id = new VariableDeclaratorId(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), ((NameExpr)ret).getName(), 0); - p = new Parameter(ret.getBeginLine(), ret.getBeginColumn(), ret.getEndLine(), ret.getEndColumn(), 0, null, new UnknownType(), false, id); - } - - } - args = add(0, args, p); - ret = new LambdaExpr(p.getBeginLine(), p.getBeginColumn(), token.endLine, token.endColumn, args, null, true); - } - break; - case NEW: - ret = AllocationExpression(null); - break; - default: - jj_la1[119] = jj_gen; - if (jj_2_28(2147483647)) { - type = ResultType(); - jj_consume_token(DOT); - jj_consume_token(CLASS); - ret = new ClassExpr(type.getBeginLine(), type.getBeginColumn(), token.endLine, token.endColumn, type); - } else if (jj_2_29(2147483647)) { - type = ResultType(); - jj_consume_token(DOUBLECOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeArgs = TypeParameters(); - typeArgs.remove(0); - break; - default: - jj_la1[116] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - break; - case NEW: - jj_consume_token(NEW); - break; - default: - jj_la1[117] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ret = new TypeExpr(type.getBeginLine(), type.getBeginColumn(), type.getEndLine(), type.getEndColumn(), type); - ret = new MethodReferenceExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, typeArgs, token.image); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - name = SimpleName(); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - args = Arguments(); - hasArgs=true; - break; - default: - jj_la1[118] = jj_gen; - ; - } - if (hasArgs) { - MethodCallExpr m = new MethodCallExpr(line, column, token.endLine, token.endColumn, null, null, null, args); - m.setNameExpr(name); - ret = m; - } else { - ret = name; - } - break; - default: - jj_la1[120] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PrimarySuffix(Expression scope) throws ParseException { - Expression ret; - if (jj_2_30(2)) { - ret = PrimarySuffixWithoutSuper(scope); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOT: - jj_consume_token(DOT); - jj_consume_token(SUPER); - ret = new SuperExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope); - break; - default: - jj_la1[121] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression PrimarySuffixWithoutSuper(Expression scope) throws ParseException { - Expression ret; - List typeArgs = null; - List args = null; - boolean hasArgs = false; - NameExpr name; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOT: - jj_consume_token(DOT); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case THIS: - jj_consume_token(THIS); - ret = new ThisExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope); - break; - case NEW: - ret = AllocationExpression(scope); - break; - default: - jj_la1[124] = jj_gen; - if (jj_2_31(2147483647)) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case 132: - typeArgs = TypeArguments(); - typeArgs.remove(0); - break; - default: - jj_la1[122] = jj_gen; - ; - } - name = SimpleName(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - args = Arguments(); - hasArgs=true; - break; - default: - jj_la1[123] = jj_gen; - ; - } - if (hasArgs) { - MethodCallExpr m = new MethodCallExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope, typeArgs, null, args); - m.setNameExpr(name); - ret = m; - } else { - FieldAccessExpr f = new FieldAccessExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope, typeArgs, null); - f.setFieldExpr(name); - ret = f; - } - } else { - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - case LBRACKET: - jj_consume_token(LBRACKET); - ret = Expression(); - jj_consume_token(RBRACKET); - ret = new ArrayAccessExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope, ret); - break; - default: - jj_la1[125] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression Literal() throws ParseException { - Expression ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INTEGER_LITERAL: - jj_consume_token(INTEGER_LITERAL); - ret = new IntegerLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); - break; - case LONG_LITERAL: - jj_consume_token(LONG_LITERAL); - ret = new LongLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); - break; - case FLOATING_POINT_LITERAL: - jj_consume_token(FLOATING_POINT_LITERAL); - ret = new DoubleLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); - break; - case CHARACTER_LITERAL: - jj_consume_token(CHARACTER_LITERAL); - ret = new CharLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image.substring(1, token.image.length()-1)); - break; - case STRING_LITERAL: - jj_consume_token(STRING_LITERAL); - ret = new StringLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image.substring(1, token.image.length()-1)); - break; - case FALSE: - case TRUE: - ret = BooleanLiteral(); - break; - case NULL: - ret = NullLiteral(); - break; - default: - jj_la1[126] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression BooleanLiteral() throws ParseException { - Expression ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TRUE: - jj_consume_token(TRUE); - ret = new BooleanLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, true); - break; - case FALSE: - jj_consume_token(FALSE); - ret = new BooleanLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, false); - break; - default: - jj_la1[127] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression NullLiteral() throws ParseException { - jj_consume_token(NULL); - {if (true) return new NullLiteralExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn);} - throw new Error("Missing return statement in function"); - } - - final public List Arguments() throws ParseException { - List ret = null; - jj_consume_token(LPAREN); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - ret = ArgumentList(); - break; - default: - jj_la1[128] = jj_gen; - ; - } - jj_consume_token(RPAREN); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ArgumentList() throws ParseException { - List ret = new LinkedList(); - Expression expr; - expr = Expression(); - ret.add(expr); - label_55: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[129] = jj_gen; - break label_55; - } - jj_consume_token(COMMA); - expr = Expression(); - ret.add(expr); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression AllocationExpression(Expression scope) throws ParseException { - Expression ret; - ArrayCreationExpr arrayExpr; - Type type; - Object[] arr = null; - List typeArgs = null; - List anonymousBody = null; - List args; - int line; - int column; - List annotations = null; - AnnotationExpr ann; - jj_consume_token(NEW); - if(scope==null) {line=token.beginLine; column=token.beginColumn;} else {line=scope.getBeginLine(); column=scope.getBeginColumn();} - label_56: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[130] = jj_gen; - break label_56; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - type = PrimitiveType(); - type.setAnnotations(annotations); arrayExpr = new ArrayCreationExpr(line, column, token.endLine, token.endColumn, type, null, 0); - arr = ArrayDimsAndInits(); - arrayExpr.setArraysAnnotations((List)arr[2]); - if (arr[0] instanceof Integer) { - arrayExpr.setArrayCount(((Integer)arr[0]).intValue()); - arrayExpr.setInitializer((ArrayInitializerExpr)arr[1]); - } else { - arrayExpr.setArrayCount(((Integer)arr[1]).intValue()); - arrayExpr.setDimensions((List)arr[0]); - } - ret = arrayExpr; - break; - case IDENTIFIER: - case LT: - case 132: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - case 132: - typeArgs = TypeArguments(); - label_57: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[131] = jj_gen; - break label_57; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - typeArgs.remove(0); - break; - default: - jj_la1[132] = jj_gen; - ; - } - type = ClassOrInterfaceType(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACKET: - case AT: - arr = ArrayDimsAndInits(); - type.setAnnotations(annotations); arrayExpr = new ArrayCreationExpr(line, column, token.endLine, token.endColumn, type, null, 0); - arrayExpr.setArraysAnnotations((List)arr[2]); - if (arr[0] instanceof Integer) { - arrayExpr.setArrayCount(((Integer)arr[0]).intValue()); - arrayExpr.setInitializer((ArrayInitializerExpr)arr[1]); - } else { - arrayExpr.setArrayCount(((Integer)arr[1]).intValue()); - arrayExpr.setDimensions((List)arr[0]); - } - ret = arrayExpr; - break; - case LPAREN: - args = Arguments(); - if (jj_2_32(2)) { - anonymousBody = ClassOrInterfaceBody(false); - } else { - ; - } - type.setAnnotations(annotations); ret = new ObjectCreationExpr(line, column, token.endLine, token.endColumn, scope, (ClassOrInterfaceType) type, typeArgs, args, anonymousBody); - break; - default: - jj_la1[133] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - default: - jj_la1[134] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - -/* - * The third LOOKAHEAD specification below is to parse to PrimarySuffix - * if there is an expression between the "[...]". - */ - final public Object[] ArrayDimsAndInits() throws ParseException { - Object[] ret = new Object[3]; - Expression expr; - List inits = null; - int i = 0; - List accum = null; - List annotations = null; - AnnotationExpr ann; - label_58: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[135] = jj_gen; - break label_58; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - if (jj_2_35(2)) { - label_59: - while (true) { - jj_consume_token(LBRACKET); - expr = Expression(); - accum = add(accum, annotations); annotations=null; inits = add(inits, expr); - jj_consume_token(RBRACKET); - if (jj_2_33(2)) { - ; - } else { - break label_59; - } - } - label_60: - while (true) { - if (jj_2_34(2)) { - ; - } else { - break label_60; - } - label_61: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ; - break; - default: - jj_la1[136] = jj_gen; - break label_61; - } - ann = Annotation(); - annotations = add(annotations, ann); - } - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - i++; - } - accum = add(accum, annotations); annotations=null; ret[0] = inits; ret[1] = new Integer(i); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACKET: - label_62: - while (true) { - jj_consume_token(LBRACKET); - jj_consume_token(RBRACKET); - i++; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACKET: - ; - break; - default: - jj_la1[137] = jj_gen; - break label_62; - } - } - expr = ArrayInitializer(); - accum = add(accum, annotations);annotations=null; ret[0] = new Integer(i); ret[1] = expr; - break; - default: - jj_la1[138] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - ret[2]=accum; {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - -/* - * Statement syntax follows. - */ - final public Statement Statement() throws ParseException { - Statement ret; - if (jj_2_36(2)) { - ret = LabeledStatement(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSERT: - ret = AssertStatement(); - break; - case LBRACE: - ret = Block(); - break; - case SEMICOLON: - ret = EmptyStatement(); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case INCR: - case DECR: - ret = StatementExpression(); - break; - case SWITCH: - ret = SwitchStatement(); - break; - case IF: - ret = IfStatement(); - break; - case WHILE: - ret = WhileStatement(); - break; - case DO: - ret = DoStatement(); - break; - case FOR: - ret = ForStatement(); - break; - case BREAK: - ret = BreakStatement(); - break; - case CONTINUE: - ret = ContinueStatement(); - break; - case RETURN: - ret = ReturnStatement(); - break; - case THROW: - ret = ThrowStatement(); - break; - case SYNCHRONIZED: - ret = SynchronizedStatement(); - break; - case TRY: - ret = TryStatement(); - break; - default: - jj_la1[139] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public AssertStmt AssertStatement() throws ParseException { - Expression check; - Expression msg = null; - int line; - int column; - jj_consume_token(ASSERT); - line=token.beginLine; column=token.beginColumn; - check = Expression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COLON: - jj_consume_token(COLON); - msg = Expression(); - break; - default: - jj_la1[140] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - {if (true) return new AssertStmt(line, column, token.endLine, token.endColumn,check, msg);} - throw new Error("Missing return statement in function"); - } - - final public LabeledStmt LabeledStatement() throws ParseException { - String label; - Statement stmt; - int line; - int column; - jj_consume_token(IDENTIFIER); - line=token.beginLine; column=token.beginColumn; - label = token.image; - jj_consume_token(COLON); - stmt = Statement(); - {if (true) return new LabeledStmt(line, column, token.endLine, token.endColumn,label, stmt);} - throw new Error("Missing return statement in function"); - } - - final public BlockStmt Block() throws ParseException { - List stmts; - int beginLine; - int beginColumn; - jj_consume_token(LBRACE); - beginLine=token.beginLine; beginColumn=token.beginColumn; - stmts = Statements(); - jj_consume_token(RBRACE); - {if (true) return new BlockStmt(beginLine, beginColumn, token.endLine, token.endColumn, stmts);} - throw new Error("Missing return statement in function"); - } - -/* - * Classes inside block stametents can only be abstract or final. The semantic must check it. - */ - final public Statement BlockStatement() throws ParseException { - Statement ret; - Expression expr; - ClassOrInterfaceDeclaration typeDecl; - Modifier modifier; - if (jj_2_37(2147483647)) { - - modifier = Modifiers(); - typeDecl = ClassOrInterfaceDeclaration(modifier); - ret = new TypeDeclarationStmt(typeDecl.getBeginLine(), typeDecl.getBeginColumn(), token.endLine, token.endColumn, typeDecl); - } else if (jj_2_38(2147483647)) { - expr = VariableDeclarationExpression(); - jj_consume_token(SEMICOLON); - ret = new ExpressionStmt(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSERT: - case BOOLEAN: - case BREAK: - case BYTE: - case CHAR: - case CONTINUE: - case DO: - case DOUBLE: - case FALSE: - case FLOAT: - case FOR: - case IF: - case INT: - case LONG: - case NEW: - case NULL: - case RETURN: - case SHORT: - case SUPER: - case SWITCH: - case SYNCHRONIZED: - case THIS: - case THROW: - case TRUE: - case TRY: - case VOID: - case WHILE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case LBRACE: - case SEMICOLON: - case INCR: - case DECR: - ret = Statement(); - break; - default: - jj_la1[141] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public VariableDeclarationExpr VariableDeclarationExpression() throws ParseException { - Modifier modifier; - Type type; - List vars = new LinkedList(); - VariableDeclarator var; - modifier = Modifiers(); - type = Type(); - var = VariableDeclarator(); - vars.add(var); - label_63: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[142] = jj_gen; - break label_63; - } - jj_consume_token(COMMA); - var = VariableDeclarator(); - vars.add(var); - } - int line = modifier.beginLine; - int column = modifier.beginColumn; - if(line==-1) {line=type.getBeginLine(); column=type.getBeginColumn(); } - {if (true) return new VariableDeclarationExpr(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, type, vars);} - throw new Error("Missing return statement in function"); - } - - final public EmptyStmt EmptyStatement() throws ParseException { - jj_consume_token(SEMICOLON); - {if (true) return new EmptyStmt(token.beginLine, token.beginColumn, token.endLine, token.endColumn);} - throw new Error("Missing return statement in function"); - } - - final public Statement LambdaBody() throws ParseException { - Expression expr; - Statement n = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - expr = Expression(); - n = new ExpressionStmt(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr); - break; - case LBRACE: - n = Block(); - break; - default: - jj_la1[143] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return n;} - throw new Error("Missing return statement in function"); - } - - final public ExpressionStmt StatementExpression() throws ParseException { - Expression expr; - AssignExpr.Operator op; - Expression value; - Type type; - List typeArgs = null; - Statement lambdaBody = null; - VariableDeclaratorId id = null; - List params = null; - Expression inner = null; - if (jj_2_39(2)) { - expr = PreIncrementExpression(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DECR: - expr = PreDecrementExpression(); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - expr = PrimaryExpression(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSIGN: - case INCR: - case DECR: - case PLUSASSIGN: - case MINUSASSIGN: - case STARASSIGN: - case SLASHASSIGN: - case ANDASSIGN: - case ORASSIGN: - case XORASSIGN: - case REMASSIGN: - case LSHIFTASSIGN: - case RSIGNEDSHIFTASSIGN: - case RUNSIGNEDSHIFTASSIGN: - case ARROW: - case DOUBLECOLON: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INCR: - jj_consume_token(INCR); - expr = new UnaryExpr(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr, UnaryExpr.Operator.posIncrement); - break; - case DECR: - jj_consume_token(DECR); - expr = new UnaryExpr(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr, UnaryExpr.Operator.posDecrement); - break; - case ASSIGN: - case PLUSASSIGN: - case MINUSASSIGN: - case STARASSIGN: - case SLASHASSIGN: - case ANDASSIGN: - case ORASSIGN: - case XORASSIGN: - case REMASSIGN: - case LSHIFTASSIGN: - case RSIGNEDSHIFTASSIGN: - case RUNSIGNEDSHIFTASSIGN: - op = AssignmentOperator(); - value = Expression(); - expr = new AssignExpr(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr, value, op); - break; - case DOUBLECOLON: - jj_consume_token(DOUBLECOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LT: - typeArgs = TypeParameters(); - typeArgs.remove(0); - break; - default: - jj_la1[144] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - break; - case NEW: - jj_consume_token(NEW); - break; - default: - jj_la1[145] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - expr = new MethodReferenceExpr(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr, typeArgs, token.image); - break; - case ARROW: - jj_consume_token(ARROW); - lambdaBody = LambdaBody(); - if (expr instanceof CastExpr) - { - inner = generateLambda(((CastExpr)expr).getExpr(), lambdaBody); - ((CastExpr)expr).setExpr(inner); - } - else - { - expr = generateLambda(expr, lambdaBody); - } - break; - default: - jj_la1[146] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - default: - jj_la1[147] = jj_gen; - ; - } - break; - default: - jj_la1[148] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - jj_consume_token(SEMICOLON); - {if (true) return new ExpressionStmt(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr);} - throw new Error("Missing return statement in function"); - } - - final public SwitchStmt SwitchStatement() throws ParseException { - Expression selector; - SwitchEntryStmt entry; - List entries = null; - int line; - int column; - jj_consume_token(SWITCH); - line=token.beginLine; column=token.beginColumn; - jj_consume_token(LPAREN); - selector = Expression(); - jj_consume_token(RPAREN); - jj_consume_token(LBRACE); - label_64: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CASE: - case _DEFAULT: - ; - break; - default: - jj_la1[149] = jj_gen; - break label_64; - } - entry = SwitchEntry(); - entries = add(entries, entry); - } - jj_consume_token(RBRACE); - {if (true) return new SwitchStmt(line, column, token.endLine, token.endColumn,selector, entries);} - throw new Error("Missing return statement in function"); - } - - final public SwitchEntryStmt SwitchEntry() throws ParseException { - Expression label = null; - List stmts; - int line; - int column; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CASE: - jj_consume_token(CASE); - line=token.beginLine; column=token.beginColumn; - label = Expression(); - break; - case _DEFAULT: - jj_consume_token(_DEFAULT); - line=token.beginLine; column=token.beginColumn; - break; - default: - jj_la1[150] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - jj_consume_token(COLON); - stmts = Statements(); - {if (true) return new SwitchEntryStmt(line, column, token.endLine, token.endColumn,label, stmts);} - throw new Error("Missing return statement in function"); - } - - final public IfStmt IfStatement() throws ParseException { - Expression condition; - Statement thenStmt; - Statement elseStmt = null; - int line; - int column; - Comment thenCmmt = null; - Comment elseCmmt = null; - jj_consume_token(IF); - line=token.beginLine; column=token.beginColumn; - jj_consume_token(LPAREN); - condition = Expression(); - jj_consume_token(RPAREN); - - thenStmt = Statement(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ELSE: - jj_consume_token(ELSE); - - elseStmt = Statement(); - break; - default: - jj_la1[151] = jj_gen; - ; - } - IfStmt tmp = new IfStmt(line, column, token.endLine, token.endColumn,condition, thenStmt, elseStmt); - - thenStmt.setComment(thenCmmt); - if (elseStmt != null) - elseStmt.setComment(elseCmmt); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public WhileStmt WhileStatement() throws ParseException { - Expression condition; - Statement body; - int line; - int column; - jj_consume_token(WHILE); - line=token.beginLine; column=token.beginColumn; - jj_consume_token(LPAREN); - condition = Expression(); - jj_consume_token(RPAREN); - body = Statement(); - {if (true) return new WhileStmt(line, column, token.endLine, token.endColumn,condition, body);} - throw new Error("Missing return statement in function"); - } - - final public DoStmt DoStatement() throws ParseException { - Expression condition; - Statement body; - int line; - int column; - jj_consume_token(DO); - line=token.beginLine; column=token.beginColumn; - body = Statement(); - jj_consume_token(WHILE); - jj_consume_token(LPAREN); - condition = Expression(); - jj_consume_token(RPAREN); - jj_consume_token(SEMICOLON); - {if (true) return new DoStmt(line, column, token.endLine, token.endColumn,body, condition);} - throw new Error("Missing return statement in function"); - } - - final public Statement ForStatement() throws ParseException { - String id = null; - VariableDeclarationExpr varExpr = null; - Expression expr = null; - List init = null; - List update = null; - Statement body; - int line; - int column; - jj_consume_token(FOR); - line=token.beginLine; column=token.beginColumn; - jj_consume_token(LPAREN); - if (jj_2_40(2147483647)) { - varExpr = VariableDeclarationExpression(); - jj_consume_token(COLON); - expr = Expression(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FINAL: - case FLOAT: - case INT: - case LONG: - case NATIVE: - case NEW: - case NULL: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SUPER: - case SYNCHRONIZED: - case THIS: - case TRANSIENT: - case TRUE: - case VOID: - case VOLATILE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case SEMICOLON: - case AT: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FINAL: - case FLOAT: - case INT: - case LONG: - case NATIVE: - case NEW: - case NULL: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SUPER: - case SYNCHRONIZED: - case THIS: - case TRANSIENT: - case TRUE: - case VOID: - case VOLATILE: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case AT: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - init = ForInit(); - break; - default: - jj_la1[152] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - expr = Expression(); - break; - default: - jj_la1[153] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - update = ForUpdate(); - break; - default: - jj_la1[154] = jj_gen; - ; - } - break; - default: - jj_la1[155] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - jj_consume_token(RPAREN); - body = Statement(); - if (varExpr != null) { - {if (true) return new ForeachStmt(line, column, token.endLine, token.endColumn,varExpr, expr, body);} - } - {if (true) return new ForStmt(line, column, token.endLine, token.endColumn,init, expr, update, body);} - throw new Error("Missing return statement in function"); - } - - final public List ForInit() throws ParseException { - List ret; - Expression expr; - if (jj_2_41(2147483647)) { - expr = VariableDeclarationExpression(); - ret = new LinkedList(); ret.add(expr); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - ret = ExpressionList(); - break; - default: - jj_la1[156] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ExpressionList() throws ParseException { - List ret = new LinkedList(); - Expression expr; - expr = Expression(); - ret.add(expr); - label_65: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[157] = jj_gen; - break label_65; - } - jj_consume_token(COMMA); - expr = Expression(); - ret.add(expr); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public List ForUpdate() throws ParseException { - List ret; - ret = ExpressionList(); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public BreakStmt BreakStatement() throws ParseException { - String id = null; - int line; - int column; - jj_consume_token(BREAK); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - id = token.image; - break; - default: - jj_la1[158] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - {if (true) return new BreakStmt(line, column, token.endLine, token.endColumn,id);} - throw new Error("Missing return statement in function"); - } - - final public ContinueStmt ContinueStatement() throws ParseException { - String id = null; - int line; - int column; - jj_consume_token(CONTINUE); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - jj_consume_token(IDENTIFIER); - id = token.image; - break; - default: - jj_la1[159] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - {if (true) return new ContinueStmt(line, column, token.endLine, token.endColumn,id);} - throw new Error("Missing return statement in function"); - } - - final public ReturnStmt ReturnStatement() throws ParseException { - Expression expr = null; - int line; - int column; - jj_consume_token(RETURN); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - expr = Expression(); - break; - default: - jj_la1[160] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - {if (true) return new ReturnStmt(line, column, token.endLine, token.endColumn,expr);} - throw new Error("Missing return statement in function"); - } - - final public ThrowStmt ThrowStatement() throws ParseException { - Expression expr; - int line; - int column; - jj_consume_token(THROW); - line=token.beginLine; column=token.beginColumn; - expr = Expression(); - jj_consume_token(SEMICOLON); - {if (true) return new ThrowStmt(line, column, token.endLine, token.endColumn,expr);} - throw new Error("Missing return statement in function"); - } - - final public SynchronizedStmt SynchronizedStatement() throws ParseException { - Expression expr; - BlockStmt block; - int line; - int column; - jj_consume_token(SYNCHRONIZED); - line=token.beginLine; column=token.beginColumn; - jj_consume_token(LPAREN); - expr = Expression(); - jj_consume_token(RPAREN); - block = Block(); - {if (true) return new SynchronizedStmt(line, column, token.endLine, token.endColumn,expr, block);} - throw new Error("Missing return statement in function"); - } - - final public TryStmt TryStatement() throws ParseException { - List resources = new LinkedList(); - BlockStmt tryBlock; - BlockStmt finallyBlock = null; - List catchs = null; - Parameter except; - BlockStmt catchBlock; - Modifier exceptModifier; - Type exceptType; - List exceptTypes = new LinkedList(); - VariableDeclaratorId exceptId; - int line; - int column; - int cLine; - int cColumn; - jj_consume_token(TRY); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - resources = ResourceSpecification(); - break; - default: - jj_la1[161] = jj_gen; - ; - } - tryBlock = Block(); - label_66: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CATCH: - ; - break; - default: - jj_la1[162] = jj_gen; - break label_66; - } - jj_consume_token(CATCH); - cLine=token.beginLine; cColumn=token.beginColumn; - jj_consume_token(LPAREN); - exceptModifier = Modifiers(); - exceptType = Type(); - exceptTypes.add(exceptType); - label_67: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_OR: - ; - break; - default: - jj_la1[163] = jj_gen; - break label_67; - } - jj_consume_token(BIT_OR); - exceptType = Type(); - exceptTypes.add(exceptType); - } - exceptId = VariableDeclaratorId(); - jj_consume_token(RPAREN); - catchBlock = Block(); - catchs = add(catchs, new CatchClause(cLine, cColumn, token.endLine, token.endColumn, exceptModifier.modifiers, exceptModifier.annotations, exceptTypes, exceptId, catchBlock)); exceptTypes = new LinkedList(); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case FINALLY: - jj_consume_token(FINALLY); - finallyBlock = Block(); - break; - default: - jj_la1[164] = jj_gen; - ; - } - {if (true) return new TryStmt(line, column, token.endLine, token.endColumn, resources, tryBlock, catchs, finallyBlock);} - throw new Error("Missing return statement in function"); - } - - final public List ResourceSpecification() throws ParseException { -List vars; - jj_consume_token(LPAREN); - vars = Resources(); - if (jj_2_42(2)) { - jj_consume_token(SEMICOLON); - } else { - ; - } - jj_consume_token(RPAREN); - {if (true) return vars;} - throw new Error("Missing return statement in function"); - } - - final public List Resources() throws ParseException { - List vars = new LinkedList(); - VariableDeclarationExpr var; - /*this is a bit more lenient than we need to be, eg allowing access modifiers like private*/ - var = VariableDeclarationExpression(); - vars.add(var); - label_68: - while (true) { - if (jj_2_43(2)) { - ; - } else { - break label_68; - } - jj_consume_token(SEMICOLON); - var = VariableDeclarationExpression(); - vars.add(var); - } - {if (true) return vars;} - throw new Error("Missing return statement in function"); - } - -/* We use productions to match >>>, >> and > so that we can keep the - * type declaration syntax with generics clean - */ - final public void RUNSIGNEDSHIFT() throws ParseException { - if (getToken(1).kind == GT && - ((GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT) { - - } else { - jj_consume_token(-1); - throw new ParseException(); - } - jj_consume_token(GT); - jj_consume_token(GT); - jj_consume_token(GT); - } - - final public void RSIGNEDSHIFT() throws ParseException { - if (getToken(1).kind == GT && - ((GTToken)getToken(1)).realKind == RSIGNEDSHIFT) { - - } else { - jj_consume_token(-1); - throw new ParseException(); - } - jj_consume_token(GT); - jj_consume_token(GT); - } - -/* Annotation syntax follows. */ - final public AnnotationExpr Annotation() throws ParseException { - AnnotationExpr ret; - if (jj_2_44(2147483647)) { - ret = NormalAnnotation(); - } else if (jj_2_45(2147483647)) { - ret = SingleMemberAnnotation(); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ret = MarkerAnnotation(); - break; - default: - jj_la1[165] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public NormalAnnotationExpr NormalAnnotation() throws ParseException { - NameExpr name; - List pairs = null; - int line; - int column; - jj_consume_token(AT); - line=token.beginLine; column=token.beginColumn; - name = Name(); - jj_consume_token(LPAREN); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - pairs = MemberValuePairs(); - break; - default: - jj_la1[166] = jj_gen; - ; - } - jj_consume_token(RPAREN); - {if (true) return new NormalAnnotationExpr(line, column, token.endLine, token.endColumn,name, pairs);} - throw new Error("Missing return statement in function"); - } - - final public MarkerAnnotationExpr MarkerAnnotation() throws ParseException { - NameExpr name; - int line; - int column; - jj_consume_token(AT); - line=token.beginLine; column=token.beginColumn; - name = Name(); - {if (true) return new MarkerAnnotationExpr(line, column, token.endLine, token.endColumn,name);} - throw new Error("Missing return statement in function"); - } - - final public SingleMemberAnnotationExpr SingleMemberAnnotation() throws ParseException { - NameExpr name; - Expression memberVal; - int line; - int column; - jj_consume_token(AT); - line=token.beginLine; column=token.beginColumn; - name = Name(); - jj_consume_token(LPAREN); - memberVal = MemberValue(); - jj_consume_token(RPAREN); - {if (true) return new SingleMemberAnnotationExpr(line, column, token.endLine, token.endColumn,name, memberVal);} - throw new Error("Missing return statement in function"); - } - - final public List MemberValuePairs() throws ParseException { - List ret = new LinkedList(); - MemberValuePair pair; - pair = MemberValuePair(); - ret.add(pair); - label_69: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[167] = jj_gen; - break label_69; - } - jj_consume_token(COMMA); - pair = MemberValuePair(); - ret.add(pair); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public MemberValuePair MemberValuePair() throws ParseException { - String name; - Expression value; - int line; - int column; - jj_consume_token(IDENTIFIER); - name = token.image; line=token.beginLine; column=token.beginColumn; - jj_consume_token(ASSIGN); - value = MemberValue(); - {if (true) return new MemberValuePair(line, column, token.endLine, token.endColumn,name, value);} - throw new Error("Missing return statement in function"); - } - - final public Expression MemberValue() throws ParseException { - Expression ret; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AT: - ret = Annotation(); - break; - case LBRACE: - ret = MemberValueArrayInitializer(); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - ret = ConditionalExpression(); - break; - default: - jj_la1[168] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public Expression MemberValueArrayInitializer() throws ParseException { - List ret = new LinkedList(); - Expression member; - int line; - int column; - jj_consume_token(LBRACE); - line=token.beginLine; column=token.beginColumn; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FALSE: - case FLOAT: - case INT: - case LONG: - case NEW: - case NULL: - case SHORT: - case SUPER: - case THIS: - case TRUE: - case VOID: - case LONG_LITERAL: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case CHARACTER_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: - case LBRACE: - case AT: - case BANG: - case TILDE: - case INCR: - case DECR: - case PLUS: - case MINUS: - member = MemberValue(); - ret.add(member); - label_70: - while (true) { - if (jj_2_46(2)) { - ; - } else { - break label_70; - } - jj_consume_token(COMMA); - member = MemberValue(); - ret.add(member); - } - break; - default: - jj_la1[169] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - jj_consume_token(COMMA); - break; - default: - jj_la1[170] = jj_gen; - ; - } - jj_consume_token(RBRACE); - {if (true) return new ArrayInitializerExpr(line, column, token.endLine, token.endColumn,ret);} - throw new Error("Missing return statement in function"); - } - -/* Annotation Types. */ - final public AnnotationDeclaration AnnotationTypeDeclaration(Modifier modifier) throws ParseException { - NameExpr name; - List members; - int line = modifier.beginLine; - int column = modifier.beginColumn; - jj_consume_token(AT); - if (line == -1) {line=token.beginLine; column=token.beginColumn;} - jj_consume_token(INTERFACE); - name = Name(); - members = AnnotationTypeBody(); - AnnotationDeclaration tmp = new AnnotationDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, null, members); - tmp.setNameExpr(name); - {if (true) return tmp;} - throw new Error("Missing return statement in function"); - } - - final public List AnnotationTypeBody() throws ParseException { - List ret = null; - BodyDeclaration member; - jj_consume_token(LBRACE); - label_71: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case CLASS: - case DOUBLE: - case ENUM: - case FINAL: - case FLOAT: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOLATILE: - case IDENTIFIER: - case SEMICOLON: - case AT: - ; - break; - default: - jj_la1[171] = jj_gen; - break label_71; - } - member = AnnotationBodyDeclaration(); - ret = add(ret, member); - } - jj_consume_token(RBRACE); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public BodyDeclaration AnnotationBodyDeclaration() throws ParseException { - Modifier modifier; - BodyDeclaration ret; - - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn); - break; - case ABSTRACT: - case BOOLEAN: - case BYTE: - case CHAR: - case CLASS: - case DOUBLE: - case ENUM: - case FINAL: - case FLOAT: - case INT: - case INTERFACE: - case LONG: - case NATIVE: - case PRIVATE: - case PROTECTED: - case PUBLIC: - case SHORT: - case STATIC: - case STRICTFP: - case SYNCHRONIZED: - case TRANSIENT: - case VOLATILE: - case IDENTIFIER: - case AT: - modifier = Modifiers(); - if (jj_2_47(2147483647)) { - ret = AnnotationTypeMemberDeclaration(modifier); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASS: - case INTERFACE: - ret = ClassOrInterfaceDeclaration(modifier); - break; - case ENUM: - ret = EnumDeclaration(modifier); - break; - case AT: - ret = AnnotationTypeDeclaration(modifier); - break; - case BOOLEAN: - case BYTE: - case CHAR: - case DOUBLE: - case FLOAT: - case INT: - case LONG: - case SHORT: - case IDENTIFIER: - ret = FieldDeclaration(modifier); - break; - default: - jj_la1[172] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - default: - jj_la1[173] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - final public AnnotationMemberDeclaration AnnotationTypeMemberDeclaration(Modifier modifier) throws ParseException { - Type type; - String name; - Expression defaultVal = null; - type = Type(); - jj_consume_token(IDENTIFIER); - name = token.image; - jj_consume_token(LPAREN); - jj_consume_token(RPAREN); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case _DEFAULT: - defaultVal = DefaultValue(); - break; - default: - jj_la1[174] = jj_gen; - ; - } - jj_consume_token(SEMICOLON); - int line = modifier.beginLine; - int column = modifier.beginColumn; - { if (line == -1) {line=type.getBeginLine(); column=type.getBeginColumn();} } - {if (true) return new AnnotationMemberDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, type, name, defaultVal);} - throw new Error("Missing return statement in function"); - } - - final public Expression DefaultValue() throws ParseException { - Expression ret; - jj_consume_token(_DEFAULT); - ret = MemberValue(); - {if (true) return ret;} - throw new Error("Missing return statement in function"); - } - - private boolean jj_2_1(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_1(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(0, xla); } - } - - private boolean jj_2_2(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_2(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(1, xla); } - } - - private boolean jj_2_3(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_3(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(2, xla); } - } - - private boolean jj_2_4(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_4(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(3, xla); } - } - - private boolean jj_2_5(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_5(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(4, xla); } - } - - private boolean jj_2_6(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_6(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(5, xla); } - } - - private boolean jj_2_7(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_7(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(6, xla); } - } - - private boolean jj_2_8(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_8(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(7, xla); } - } - - private boolean jj_2_9(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_9(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(8, xla); } - } - - private boolean jj_2_10(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_10(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(9, xla); } - } - - private boolean jj_2_11(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_11(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(10, xla); } - } - - private boolean jj_2_12(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_12(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(11, xla); } - } - - private boolean jj_2_13(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_13(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(12, xla); } - } - - private boolean jj_2_14(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_14(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(13, xla); } - } - - private boolean jj_2_15(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_15(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(14, xla); } - } - - private boolean jj_2_16(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_16(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(15, xla); } - } - - private boolean jj_2_17(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_17(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(16, xla); } - } - - private boolean jj_2_18(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_18(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(17, xla); } - } - - private boolean jj_2_19(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_19(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(18, xla); } - } - - private boolean jj_2_20(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_20(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(19, xla); } - } - - private boolean jj_2_21(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_21(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(20, xla); } - } - - private boolean jj_2_22(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_22(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(21, xla); } - } - - private boolean jj_2_23(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_23(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(22, xla); } - } - - private boolean jj_2_24(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_24(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(23, xla); } - } - - private boolean jj_2_25(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_25(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(24, xla); } - } - - private boolean jj_2_26(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_26(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(25, xla); } - } - - private boolean jj_2_27(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_27(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(26, xla); } - } - - private boolean jj_2_28(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_28(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(27, xla); } - } - - private boolean jj_2_29(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_29(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(28, xla); } - } - - private boolean jj_2_30(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_30(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(29, xla); } - } - - private boolean jj_2_31(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_31(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(30, xla); } - } - - private boolean jj_2_32(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_32(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(31, xla); } - } - - private boolean jj_2_33(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_33(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(32, xla); } - } - - private boolean jj_2_34(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_34(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(33, xla); } - } - - private boolean jj_2_35(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_35(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(34, xla); } - } - - private boolean jj_2_36(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_36(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(35, xla); } - } - - private boolean jj_2_37(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_37(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(36, xla); } - } - - private boolean jj_2_38(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_38(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(37, xla); } - } - - private boolean jj_2_39(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_39(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(38, xla); } - } - - private boolean jj_2_40(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_40(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(39, xla); } - } - - private boolean jj_2_41(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_41(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(40, xla); } - } - - private boolean jj_2_42(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_42(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(41, xla); } - } - - private boolean jj_2_43(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_43(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(42, xla); } - } - - private boolean jj_2_44(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_44(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(43, xla); } - } - - private boolean jj_2_45(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_45(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(44, xla); } - } - - private boolean jj_2_46(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_46(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(45, xla); } - } - - private boolean jj_2_47(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_47(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(46, xla); } - } - - private boolean jj_3R_454() { - if (jj_scan_token(BIT_OR)) return true; - if (jj_3R_87()) return true; - return false; - } - - private boolean jj_3R_438() { - if (jj_scan_token(FINALLY)) return true; - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_425() { - if (jj_scan_token(FINALLY)) return true; - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3_42() { - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_436() { - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_453()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_42()) jj_scanpos = xsp; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3R_437() { - if (jj_scan_token(CATCH)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_116()) return true; - if (jj_3R_87()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_454()) { jj_scanpos = xsp; break; } - } - if (jj_3R_168()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_92() { - if (jj_3R_133()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_134()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_172() { - if (jj_3R_168()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_207()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_294() { - if (jj_3R_133()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_25()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_422() { - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_88() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_155() { - if (jj_3R_94()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_201()) return true; - return false; - } - - private boolean jj_3R_424() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_437()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_438()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_24() { - if (jj_3R_107()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_388() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_172()) return true; - return false; - } - - private boolean jj_3R_302() { - if (jj_3R_87()) return true; - if (jj_3R_172()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_388()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_421() { - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_423() { - if (jj_3R_436()) return true; - return false; - } - - private boolean jj_3R_154() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_361() { - if (jj_scan_token(TRY)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_423()) jj_scanpos = xsp; - if (jj_3R_128()) return true; - xsp = jj_scanpos; - if (jj_3R_424()) { - jj_scanpos = xsp; - if (jj_3R_425()) return true; - } - return false; - } - - private boolean jj_3R_241() { - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_104() { - if (jj_scan_token(LPAREN)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_154()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3_24()) { - jj_scanpos = xsp; - if (jj_3R_155()) return true; - } - return false; - } - - private boolean jj_3_5() { - if (jj_3R_87()) return true; - if (jj_scan_token(IDENTIFIER)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_88()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_scan_token(88)) { - jj_scanpos = xsp; - if (jj_scan_token(91)) { - jj_scanpos = xsp; - if (jj_scan_token(87)) return true; - } - } - return false; - } - - private boolean jj_3R_420() { - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_86() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3_4() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_86()) jj_scanpos = xsp; - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(LPAREN)) return true; - return false; - } - - private boolean jj_3R_216() { - if (jj_3R_245()) return true; - return false; - } - - private boolean jj_3R_106() { - if (jj_scan_token(DECR)) return true; - return false; - } - - private boolean jj_3_23() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_105()) { - jj_scanpos = xsp; - if (jj_3R_106()) return true; - } - return false; - } - - private boolean jj_3R_105() { - if (jj_scan_token(INCR)) return true; - return false; - } - - private boolean jj_3_22() { - if (jj_3R_104()) return true; - return false; - } - - private boolean jj_3R_277() { - if (jj_3R_303()) return true; - return false; - } - - private boolean jj_3R_271() { - if (jj_scan_token(_DEFAULT)) return true; - if (jj_3R_116()) return true; - return false; - } - - private boolean jj_3R_276() { - if (jj_3R_302()) return true; - return false; - } - - private boolean jj_3R_267() { - if (jj_3R_294()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_23()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_275() { - if (jj_3R_301()) return true; - return false; - } - - private boolean jj_3R_360() { - if (jj_scan_token(SYNCHRONIZED)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_274() { - if (jj_3R_300()) return true; - return false; - } - - private boolean jj_3R_273() { - if (jj_3R_299()) return true; - return false; - } - - private boolean jj_3R_235() { - if (jj_3R_104()) return true; - return false; - } - - private boolean jj_3R_236() { - if (jj_3R_267()) return true; - return false; - } - - private boolean jj_3R_266() { - if (jj_scan_token(BANG)) return true; - return false; - } - - private boolean jj_3R_272() { - if (jj_3R_298()) return true; - return false; - } - - private boolean jj_3R_265() { - if (jj_scan_token(TILDE)) return true; - return false; - } - - private boolean jj_3R_234() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_265()) { - jj_scanpos = xsp; - if (jj_3R_266()) return true; - } - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_359() { - if (jj_scan_token(THROW)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_201() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_234()) { - jj_scanpos = xsp; - if (jj_3R_235()) { - jj_scanpos = xsp; - if (jj_3R_236()) return true; - } - } - return false; - } - - private boolean jj_3R_240() { - if (jj_3R_116()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_271()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_272()) { - jj_scanpos = xsp; - if (jj_3R_273()) { - jj_scanpos = xsp; - if (jj_3R_274()) { - jj_scanpos = xsp; - if (jj_3R_275()) { - jj_scanpos = xsp; - if (jj_3R_276()) { - jj_scanpos = xsp; - if (jj_3R_277()) return true; - } - } - } - } - } - return false; - } - - private boolean jj_3R_358() { - if (jj_scan_token(RETURN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_422()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_461() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3_6() { - if (jj_3R_89()) return true; - return false; - } - - private boolean jj_3R_242() { - if (jj_scan_token(DECR)) return true; - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_357() { - if (jj_scan_token(CONTINUE)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_421()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_206() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_6()) { - jj_scanpos = xsp; - if (jj_3R_240()) { - jj_scanpos = xsp; - if (jj_3R_241()) return true; - } - } - return false; - } - - private boolean jj_3R_417() { - if (jj_scan_token(ELSE)) return true; - if (jj_3R_306()) return true; - return false; - } - - private boolean jj_3R_118() { - if (jj_scan_token(INCR)) return true; - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_211() { - if (jj_3R_201()) return true; - return false; - } - - private boolean jj_3R_435() { - if (jj_3R_452()) return true; - return false; - } - - private boolean jj_3R_356() { - if (jj_scan_token(BREAK)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_420()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_171() { - if (jj_3R_206()) return true; - return false; - } - - private boolean jj_3R_279() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_113() { - if (jj_scan_token(LBRACE)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_171()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_305() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_244() { - if (jj_scan_token(MINUS)) return true; - return false; - } - - private boolean jj_3R_452() { - if (jj_3R_459()) return true; - return false; - } - - private boolean jj_3R_243() { - if (jj_scan_token(PLUS)) return true; - return false; - } - - private boolean jj_3R_280() { - if (jj_scan_token(BIT_AND)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_305()) { jj_scanpos = xsp; break; } - } - if (jj_3R_198()) return true; - return false; - } - - private boolean jj_3R_210() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_243()) { - jj_scanpos = xsp; - if (jj_3R_244()) return true; - } - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_245() { - if (jj_scan_token(EXTENDS)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_279()) { jj_scanpos = xsp; break; } - } - if (jj_3R_198()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_280()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_209() { - if (jj_3R_242()) return true; - return false; - } - - private boolean jj_3_41() { - if (jj_3R_116()) return true; - if (jj_3R_87()) return true; - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_208() { - if (jj_3R_118()) return true; - return false; - } - - private boolean jj_3R_459() { - if (jj_3R_100()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_461()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_458() { - if (jj_3R_459()) return true; - return false; - } - - private boolean jj_3R_434() { - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3_3() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_85()) return true; - return false; - } - - private boolean jj_3R_174() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_208()) { - jj_scanpos = xsp; - if (jj_3R_209()) { - jj_scanpos = xsp; - if (jj_3R_210()) { - jj_scanpos = xsp; - if (jj_3R_211()) return true; - } - } - } - return false; - } - - private boolean jj_3R_457() { - if (jj_3R_117()) return true; - return false; - } - - private boolean jj_3R_182() { - if (jj_scan_token(IDENTIFIER)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_216()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_430() { - if (jj_scan_token(REM)) return true; - return false; - } - - private boolean jj_3R_429() { - if (jj_scan_token(SLASH)) return true; - return false; - } - - private boolean jj_3R_217() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_428() { - if (jj_scan_token(STAR)) return true; - return false; - } - - private boolean jj_3R_451() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_457()) { - jj_scanpos = xsp; - if (jj_3R_458()) return true; - } - return false; - } - - private boolean jj_3R_412() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_428()) { - jj_scanpos = xsp; - if (jj_3R_429()) { - jj_scanpos = xsp; - if (jj_3R_430()) return true; - } - } - if (jj_3R_174()) return true; - return false; - } - - private boolean jj_3R_408() { - if (jj_3R_113()) return true; - return false; - } - - private boolean jj_3R_183() { - if (jj_scan_token(COMMA)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_217()) { jj_scanpos = xsp; break; } - } - if (jj_3R_182()) return true; - return false; - } - - private boolean jj_3R_181() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_376() { - if (jj_3R_174()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_412()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_125() { - if (jj_scan_token(LT)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_181()) { jj_scanpos = xsp; break; } - } - if (jj_3R_182()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_183()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(GT)) return true; - return false; - } - - private boolean jj_3_40() { - if (jj_3R_117()) return true; - if (jj_scan_token(COLON)) return true; - return false; - } - - private boolean jj_3R_414() { - if (jj_scan_token(MINUS)) return true; - return false; - } - - private boolean jj_3R_433() { - if (jj_3R_451()) return true; - return false; - } - - private boolean jj_3R_413() { - if (jj_scan_token(PLUS)) return true; - return false; - } - - private boolean jj_3R_419() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_433()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - xsp = jj_scanpos; - if (jj_3R_434()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - xsp = jj_scanpos; - if (jj_3R_435()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_402() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_413()) { - jj_scanpos = xsp; - if (jj_3R_414()) return true; - } - if (jj_3R_376()) return true; - return false; - } - - private boolean jj_3R_418() { - if (jj_3R_117()) return true; - if (jj_scan_token(COLON)) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_407() { - if (jj_3R_187()) return true; - return false; - } - - private boolean jj_3R_372() { - if (jj_3R_376()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_402()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_355() { - if (jj_scan_token(FOR)) return true; - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_418()) { - jj_scanpos = xsp; - if (jj_3R_419()) return true; - } - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_306()) return true; - return false; - } - - private boolean jj_3R_124() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_85() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_124()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(IDENTIFIER)) return true; - xsp = jj_scanpos; - if (jj_3R_407()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_408()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_21() { - if (jj_3R_103()) return true; - return false; - } - - private boolean jj_3R_398() { - if (jj_3R_206()) return true; - return false; - } - - private boolean jj_3_20() { - if (jj_3R_102()) return true; - return false; - } - - private boolean jj_3R_101() { - if (jj_scan_token(LSHIFT)) return true; - return false; - } - - private boolean jj_3_19() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_101()) { - jj_scanpos = xsp; - if (jj_3_20()) { - jj_scanpos = xsp; - if (jj_3_21()) return true; - } - } - if (jj_3R_372()) return true; - return false; - } - - private boolean jj_3R_383() { - if (jj_scan_token(SEMICOLON)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_398()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_373() { - if (jj_scan_token(INSTANCEOF)) return true; - if (jj_3R_87()) return true; - return false; - } - - private boolean jj_3R_370() { - if (jj_3R_372()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_19()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_354() { - if (jj_scan_token(DO)) return true; - if (jj_3R_306()) return true; - if (jj_scan_token(WHILE)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_395() { - if (jj_scan_token(GE)) return true; - return false; - } - - private boolean jj_3R_394() { - if (jj_scan_token(LE)) return true; - return false; - } - - private boolean jj_3R_393() { - if (jj_scan_token(GT)) return true; - return false; - } - - private boolean jj_3R_392() { - if (jj_scan_token(LT)) return true; - return false; - } - - private boolean jj_3R_382() { - if (jj_3R_85()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_3()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_377() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_392()) { - jj_scanpos = xsp; - if (jj_3R_393()) { - jj_scanpos = xsp; - if (jj_3R_394()) { - jj_scanpos = xsp; - if (jj_3R_395()) return true; - } - } - } - if (jj_3R_370()) return true; - return false; - } - - private boolean jj_3R_353() { - if (jj_scan_token(WHILE)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_306()) return true; - return false; - } - - private boolean jj_3R_381() { - if (jj_3R_397()) return true; - return false; - } - - private boolean jj_3R_368() { - if (jj_3R_370()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_377()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_299() { - if (jj_scan_token(ENUM)) return true; - if (jj_3R_119()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_381()) jj_scanpos = xsp; - if (jj_scan_token(LBRACE)) return true; - xsp = jj_scanpos; - if (jj_3R_382()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(88)) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_383()) jj_scanpos = xsp; - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_369() { - if (jj_scan_token(BIT_AND)) return true; - if (jj_3R_345()) return true; - return false; - } - - private boolean jj_3R_405() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_364() { - if (jj_3R_368()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_373()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_352() { - if (jj_scan_token(IF)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_3R_306()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_417()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_375() { - if (jj_scan_token(NE)) return true; - return false; - } - - private boolean jj_3R_406() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_198()) return true; - return false; - } - - private boolean jj_3R_374() { - if (jj_scan_token(EQ)) return true; - return false; - } - - private boolean jj_3R_371() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_374()) { - jj_scanpos = xsp; - if (jj_3R_375()) return true; - } - if (jj_3R_364()) return true; - return false; - } - - private boolean jj_3R_397() { - if (jj_scan_token(IMPLEMENTS)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_405()) { jj_scanpos = xsp; break; } - } - if (jj_3R_198()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_406()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_365() { - if (jj_scan_token(XOR)) return true; - if (jj_3R_315()) return true; - return false; - } - - private boolean jj_3R_346() { - if (jj_scan_token(BIT_OR)) return true; - if (jj_3R_293()) return true; - return false; - } - - private boolean jj_3R_345() { - if (jj_3R_364()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_371()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_450() { - if (jj_scan_token(_DEFAULT)) return true; - return false; - } - - private boolean jj_3R_403() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_449() { - if (jj_scan_token(CASE)) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_316() { - if (jj_scan_token(SC_AND)) return true; - if (jj_3R_264()) return true; - return false; - } - - private boolean jj_3R_404() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_198()) return true; - return false; - } - - private boolean jj_3R_315() { - if (jj_3R_345()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_369()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_432() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_449()) { - jj_scanpos = xsp; - if (jj_3R_450()) return true; - } - if (jj_scan_token(COLON)) return true; - if (jj_3R_184()) return true; - return false; - } - - private boolean jj_3R_396() { - if (jj_scan_token(EXTENDS)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_403()) { jj_scanpos = xsp; break; } - } - if (jj_3R_198()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_404()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_295() { - if (jj_scan_token(SC_OR)) return true; - if (jj_3R_233()) return true; - return false; - } - - private boolean jj_3R_293() { - if (jj_3R_315()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_365()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_416() { - if (jj_3R_432()) return true; - return false; - } - - private boolean jj_3R_319() { - if (jj_scan_token(INTERFACE)) return true; - return false; - } - - private boolean jj_3R_351() { - if (jj_scan_token(SWITCH)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RPAREN)) return true; - if (jj_scan_token(LBRACE)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_416()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_380() { - if (jj_3R_397()) return true; - return false; - } - - private boolean jj_3R_264() { - if (jj_3R_293()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_346()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_379() { - if (jj_3R_396()) return true; - return false; - } - - private boolean jj_3R_378() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_298() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(20)) { - jj_scanpos = xsp; - if (jj_3R_319()) return true; - } - if (jj_3R_119()) return true; - xsp = jj_scanpos; - if (jj_3R_378()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_379()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_380()) jj_scanpos = xsp; - if (jj_3R_113()) return true; - return false; - } - - private boolean jj_3R_173() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_172()) return true; - return false; - } - - private boolean jj_3R_456() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_233() { - if (jj_3R_264()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_316()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_448() { - if (jj_scan_token(ARROW)) return true; - if (jj_3R_296()) return true; - return false; - } - - private boolean jj_3R_447() { - if (jj_scan_token(DOUBLECOLON)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_456()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(78)) { - jj_scanpos = xsp; - if (jj_scan_token(43)) return true; - } - return false; - } - - private boolean jj_3R_446() { - if (jj_3R_99()) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_445() { - if (jj_scan_token(DECR)) return true; - return false; - } - - private boolean jj_3R_200() { - if (jj_3R_233()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_295()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_444() { - if (jj_scan_token(INCR)) return true; - return false; - } - - private boolean jj_3R_431() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_444()) { - jj_scanpos = xsp; - if (jj_3R_445()) { - jj_scanpos = xsp; - if (jj_3R_446()) { - jj_scanpos = xsp; - if (jj_3R_447()) { - jj_scanpos = xsp; - if (jj_3R_448()) return true; - } - } - } - } - return false; - } - - private boolean jj_3R_367() { - if (jj_3R_294()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_431()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_366() { - if (jj_3R_242()) return true; - return false; - } - - private boolean jj_3R_268() { - if (jj_scan_token(HOOK)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(COLON)) return true; - if (jj_3R_151()) return true; - return false; - } - - private boolean jj_3R_151() { - if (jj_3R_200()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_268()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_39() { - if (jj_3R_118()) return true; - return false; - } - - private boolean jj_3R_350() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_39()) { - jj_scanpos = xsp; - if (jj_3R_366()) { - jj_scanpos = xsp; - if (jj_3R_367()) return true; - } - } - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_150() { - if (jj_scan_token(ORASSIGN)) return true; - return false; - } - - private boolean jj_3R_149() { - if (jj_scan_token(XORASSIGN)) return true; - return false; - } - - private boolean jj_3R_148() { - if (jj_scan_token(ANDASSIGN)) return true; - return false; - } - - private boolean jj_3R_147() { - if (jj_scan_token(RUNSIGNEDSHIFTASSIGN)) return true; - return false; - } - - private boolean jj_3R_146() { - if (jj_scan_token(RSIGNEDSHIFTASSIGN)) return true; - return false; - } - - private boolean jj_3R_145() { - if (jj_scan_token(LSHIFTASSIGN)) return true; - return false; - } - - private boolean jj_3R_144() { - if (jj_scan_token(MINUSASSIGN)) return true; - return false; - } - - private boolean jj_3R_143() { - if (jj_scan_token(PLUSASSIGN)) return true; - return false; - } - - private boolean jj_3R_142() { - if (jj_scan_token(REMASSIGN)) return true; - return false; - } - - private boolean jj_3R_141() { - if (jj_scan_token(SLASHASSIGN)) return true; - return false; - } - - private boolean jj_3R_140() { - if (jj_scan_token(STARASSIGN)) return true; - return false; - } - - private boolean jj_3R_139() { - if (jj_scan_token(ASSIGN)) return true; - return false; - } - - private boolean jj_3R_84() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_83() { - if (jj_scan_token(STRICTFP)) return true; - return false; - } - - private boolean jj_3R_99() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_139()) { - jj_scanpos = xsp; - if (jj_3R_140()) { - jj_scanpos = xsp; - if (jj_3R_141()) { - jj_scanpos = xsp; - if (jj_3R_142()) { - jj_scanpos = xsp; - if (jj_3R_143()) { - jj_scanpos = xsp; - if (jj_3R_144()) { - jj_scanpos = xsp; - if (jj_3R_145()) { - jj_scanpos = xsp; - if (jj_3R_146()) { - jj_scanpos = xsp; - if (jj_3R_147()) { - jj_scanpos = xsp; - if (jj_3R_148()) { - jj_scanpos = xsp; - if (jj_3R_149()) { - jj_scanpos = xsp; - if (jj_3R_150()) return true; - } - } - } - } - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_318() { - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_82() { - if (jj_scan_token(VOLATILE)) return true; - return false; - } - - private boolean jj_3R_81() { - if (jj_scan_token(TRANSIENT)) return true; - return false; - } - - private boolean jj_3R_80() { - if (jj_scan_token(NATIVE)) return true; - return false; - } - - private boolean jj_3R_297() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_79() { - if (jj_scan_token(SYNCHRONIZED)) return true; - return false; - } - - private boolean jj_3R_317() { - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_78() { - if (jj_scan_token(ABSTRACT)) return true; - return false; - } - - private boolean jj_3R_77() { - if (jj_scan_token(FINAL)) return true; - return false; - } - - private boolean jj_3R_114() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_76() { - if (jj_scan_token(PRIVATE)) return true; - return false; - } - - private boolean jj_3R_270() { - if (jj_scan_token(DOUBLECOLON)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_297()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(78)) { - jj_scanpos = xsp; - if (jj_scan_token(43)) return true; - } - return false; - } - - private boolean jj_3R_75() { - if (jj_scan_token(PROTECTED)) return true; - return false; - } - - private boolean jj_3R_296() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_317()) { - jj_scanpos = xsp; - if (jj_3R_318()) return true; - } - return false; - } - - private boolean jj_3R_74() { - if (jj_scan_token(STATIC)) return true; - return false; - } - - private boolean jj_3R_415() { - if (jj_scan_token(COLON)) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_73() { - if (jj_scan_token(PUBLIC)) return true; - return false; - } - - private boolean jj_3_2() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_73()) { - jj_scanpos = xsp; - if (jj_3R_74()) { - jj_scanpos = xsp; - if (jj_3R_75()) { - jj_scanpos = xsp; - if (jj_3R_76()) { - jj_scanpos = xsp; - if (jj_3R_77()) { - jj_scanpos = xsp; - if (jj_3R_78()) { - jj_scanpos = xsp; - if (jj_3R_79()) { - jj_scanpos = xsp; - if (jj_3R_80()) { - jj_scanpos = xsp; - if (jj_3R_81()) { - jj_scanpos = xsp; - if (jj_3R_82()) { - jj_scanpos = xsp; - if (jj_3R_83()) { - jj_scanpos = xsp; - if (jj_3R_84()) return true; - } - } - } - } - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_116() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_2()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_349() { - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3_18() { - if (jj_3R_99()) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3_34() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_114()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_269() { - if (jj_scan_token(ARROW)) return true; - if (jj_3R_296()) return true; - return false; - } - - private boolean jj_3R_411() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_119()) return true; - return false; - } - - private boolean jj_3R_239() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_18()) { - jj_scanpos = xsp; - if (jj_3R_269()) { - jj_scanpos = xsp; - if (jj_3R_270()) return true; - } - } - return false; - } - - private boolean jj_3R_100() { - if (jj_3R_151()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_239()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_38() { - if (jj_3R_117()) return true; - return false; - } - - private boolean jj_3R_117() { - if (jj_3R_116()) return true; - if (jj_3R_87()) return true; - if (jj_3R_172()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_173()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3_37() { - if (jj_3R_116()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(20)) { - jj_scanpos = xsp; - if (jj_scan_token(40)) return true; - } - return false; - } - - private boolean jj_3R_283() { - if (jj_3R_306()) return true; - return false; - } - - private boolean jj_3R_282() { - if (jj_3R_117()) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_281() { - if (jj_3R_116()) return true; - if (jj_3R_298()) return true; - return false; - } - - private boolean jj_3R_122() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_72() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_122()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(PACKAGE)) return true; - if (jj_3R_119()) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3_1() { - if (jj_3R_72()) return true; - return false; - } - - private boolean jj_3R_246() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_281()) { - jj_scanpos = xsp; - if (jj_3R_282()) { - jj_scanpos = xsp; - if (jj_3R_283()) return true; - } - } - return false; - } - - private boolean jj_3R_401() { - if (jj_3R_119()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_411()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_227() { - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_128() { - if (jj_scan_token(LBRACE)) return true; - if (jj_3R_184()) return true; - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_115() { - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(COLON)) return true; - if (jj_3R_306()) return true; - return false; - } - - private boolean jj_3_17() { - if (jj_scan_token(DOT)) return true; - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_119() { - if (jj_scan_token(IDENTIFIER)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_17()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_348() { - if (jj_scan_token(ASSERT)) return true; - if (jj_3R_100()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_415()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_170() { - if (jj_3R_87()) return true; - return false; - } - - private boolean jj_3R_339() { - if (jj_3R_361()) return true; - return false; - } - - private boolean jj_3R_169() { - if (jj_scan_token(VOID)) return true; - return false; - } - - private boolean jj_3R_338() { - if (jj_3R_360()) return true; - return false; - } - - private boolean jj_3R_337() { - if (jj_3R_359()) return true; - return false; - } - - private boolean jj_3R_336() { - if (jj_3R_358()) return true; - return false; - } - - private boolean jj_3R_335() { - if (jj_3R_357()) return true; - return false; - } - - private boolean jj_3R_111() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_169()) { - jj_scanpos = xsp; - if (jj_3R_170()) return true; - } - return false; - } - - private boolean jj_3R_334() { - if (jj_3R_356()) return true; - return false; - } - - private boolean jj_3R_333() { - if (jj_3R_355()) return true; - return false; - } - - private boolean jj_3R_332() { - if (jj_3R_354()) return true; - return false; - } - - private boolean jj_3R_331() { - if (jj_3R_353()) return true; - return false; - } - - private boolean jj_3R_330() { - if (jj_3R_352()) return true; - return false; - } - - private boolean jj_3R_163() { - if (jj_scan_token(DOUBLE)) return true; - return false; - } - - private boolean jj_3R_329() { - if (jj_3R_351()) return true; - return false; - } - - private boolean jj_3R_162() { - if (jj_scan_token(FLOAT)) return true; - return false; - } - - private boolean jj_3R_328() { - if (jj_3R_350()) return true; - return false; - } - - private boolean jj_3R_161() { - if (jj_scan_token(LONG)) return true; - return false; - } - - private boolean jj_3R_327() { - if (jj_3R_349()) return true; - return false; - } - - private boolean jj_3R_160() { - if (jj_scan_token(INT)) return true; - return false; - } - - private boolean jj_3R_363() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_326() { - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_159() { - if (jj_scan_token(SHORT)) return true; - return false; - } - - private boolean jj_3R_325() { - if (jj_3R_348()) return true; - return false; - } - - private boolean jj_3R_362() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_158() { - if (jj_scan_token(BYTE)) return true; - return false; - } - - private boolean jj_3R_157() { - if (jj_scan_token(CHAR)) return true; - return false; - } - - private boolean jj_3_36() { - if (jj_3R_115()) return true; - return false; - } - - private boolean jj_3R_156() { - if (jj_scan_token(BOOLEAN)) return true; - return false; - } - - private boolean jj_3R_344() { - if (jj_scan_token(SUPER)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_363()) { jj_scanpos = xsp; break; } - } - if (jj_3R_94()) return true; - return false; - } - - private boolean jj_3R_107() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_156()) { - jj_scanpos = xsp; - if (jj_3R_157()) { - jj_scanpos = xsp; - if (jj_3R_158()) { - jj_scanpos = xsp; - if (jj_3R_159()) { - jj_scanpos = xsp; - if (jj_3R_160()) { - jj_scanpos = xsp; - if (jj_3R_161()) { - jj_scanpos = xsp; - if (jj_3R_162()) { - jj_scanpos = xsp; - if (jj_3R_163()) return true; - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_343() { - if (jj_scan_token(EXTENDS)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_362()) { jj_scanpos = xsp; break; } - } - if (jj_3R_94()) return true; - return false; - } - - private boolean jj_3R_314() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_343()) { - jj_scanpos = xsp; - if (jj_3R_344()) return true; - } - return false; - } - - private boolean jj_3R_306() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_36()) { - jj_scanpos = xsp; - if (jj_3R_325()) { - jj_scanpos = xsp; - if (jj_3R_326()) { - jj_scanpos = xsp; - if (jj_3R_327()) { - jj_scanpos = xsp; - if (jj_3R_328()) { - jj_scanpos = xsp; - if (jj_3R_329()) { - jj_scanpos = xsp; - if (jj_3R_330()) { - jj_scanpos = xsp; - if (jj_3R_331()) { - jj_scanpos = xsp; - if (jj_3R_332()) { - jj_scanpos = xsp; - if (jj_3R_333()) { - jj_scanpos = xsp; - if (jj_3R_334()) { - jj_scanpos = xsp; - if (jj_3R_335()) { - jj_scanpos = xsp; - if (jj_3R_336()) { - jj_scanpos = xsp; - if (jj_3R_337()) { - jj_scanpos = xsp; - if (jj_3R_338()) { - jj_scanpos = xsp; - if (jj_3R_339()) return true; - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_342() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_229() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_199()) return true; - return false; - } - - private boolean jj_3R_312() { - Token xsp; - if (jj_3R_342()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_342()) { jj_scanpos = xsp; break; } - } - if (jj_3R_185()) return true; - return false; - } - - private boolean jj_3_33() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3_32() { - if (jj_3R_113()) return true; - return false; - } - - private boolean jj_3_35() { - Token xsp; - if (jj_3_33()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3_33()) { jj_scanpos = xsp; break; } - } - while (true) { - xsp = jj_scanpos; - if (jj_3_34()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_263() { - if (jj_scan_token(HOOK)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_314()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_311() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_289() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_311()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3_35()) { - jj_scanpos = xsp; - if (jj_3R_312()) return true; - } - return false; - } - - private boolean jj_3R_313() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_232() { - if (jj_3R_263()) return true; - return false; - } - - private boolean jj_3R_292() { - if (jj_3R_187()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_32()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_231() { - if (jj_3R_94()) return true; - return false; - } - - private boolean jj_3R_230() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_199() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_230()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_231()) { - jj_scanpos = xsp; - if (jj_3R_232()) return true; - } - return false; - } - - private boolean jj_3R_96() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_98() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_460() { - if (jj_3R_462()) return true; - return false; - } - - private boolean jj_3R_291() { - if (jj_3R_289()) return true; - return false; - } - - private boolean jj_3R_138() { - if (jj_scan_token(132)) return true; - return false; - } - - private boolean jj_3R_95() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_290() { - if (jj_3R_97()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_313()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3_13() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_96()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_137() { - if (jj_scan_token(LT)) return true; - if (jj_3R_199()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_229()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(GT)) return true; - return false; - } - - private boolean jj_3R_97() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_137()) { - jj_scanpos = xsp; - if (jj_3R_138()) return true; - } - return false; - } - - private boolean jj_3R_262() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_290()) jj_scanpos = xsp; - if (jj_3R_198()) return true; - xsp = jj_scanpos; - if (jj_3R_291()) { - jj_scanpos = xsp; - if (jj_3R_292()) return true; - } - return false; - } - - private boolean jj_3_16() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_284() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3_15() { - if (jj_scan_token(DOT)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_98()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(IDENTIFIER)) return true; - xsp = jj_scanpos; - if (jj_3_16()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_12() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_95()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_386() { - if (jj_scan_token(THROWS)) return true; - if (jj_3R_401()) return true; - return false; - } - - private boolean jj_3R_261() { - if (jj_3R_107()) return true; - if (jj_3R_289()) return true; - return false; - } - - private boolean jj_3_14() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_198() { - if (jj_scan_token(IDENTIFIER)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_14()) jj_scanpos = xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_15()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_260() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_225() { - if (jj_scan_token(NEW)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_260()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_261()) { - jj_scanpos = xsp; - if (jj_3R_262()) return true; - } - return false; - } - - private boolean jj_3R_136() { - if (jj_3R_198()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_13()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_462() { - if (jj_scan_token(_DEFAULT)) return true; - if (jj_3R_121()) return true; - return false; - } - - private boolean jj_3R_135() { - if (jj_3R_107()) return true; - Token xsp; - if (jj_3_12()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3_12()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_94() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_135()) { - jj_scanpos = xsp; - if (jj_3R_136()) return true; - } - return false; - } - - private boolean jj_3R_247() { - if (jj_3R_100()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_284()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_219() { - if (jj_3R_247()) return true; - return false; - } - - private boolean jj_3R_455() { - if (jj_3R_87()) return true; - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_scan_token(RPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_460()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_126() { - if (jj_3R_107()) return true; - return false; - } - - private boolean jj_3_11() { - if (jj_3R_94()) return true; - return false; - } - - private boolean jj_3_47() { - if (jj_3R_87()) return true; - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(LPAREN)) return true; - return false; - } - - private boolean jj_3R_443() { - if (jj_3R_302()) return true; - return false; - } - - private boolean jj_3R_87() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_11()) { - jj_scanpos = xsp; - if (jj_3R_126()) return true; - } - return false; - } - - private boolean jj_3R_187() { - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_219()) jj_scanpos = xsp; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3R_442() { - if (jj_3R_300()) return true; - return false; - } - - private boolean jj_3R_441() { - if (jj_3R_299()) return true; - return false; - } - - private boolean jj_3R_440() { - if (jj_3R_298()) return true; - return false; - } - - private boolean jj_3R_439() { - if (jj_3R_455()) return true; - return false; - } - - private boolean jj_3R_286() { - if (jj_scan_token(NULL)) return true; - return false; - } - - private boolean jj_3R_308() { - if (jj_scan_token(FALSE)) return true; - return false; - } - - private boolean jj_3R_127() { - if (jj_scan_token(STATIC)) return true; - return false; - } - - private boolean jj_3R_307() { - if (jj_scan_token(TRUE)) return true; - return false; - } - - private boolean jj_3R_89() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_127()) jj_scanpos = xsp; - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3_46() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_121()) return true; - return false; - } - - private boolean jj_3R_426() { - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_427() { - if (jj_3R_116()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_439()) { - jj_scanpos = xsp; - if (jj_3R_440()) { - jj_scanpos = xsp; - if (jj_3R_441()) { - jj_scanpos = xsp; - if (jj_3R_442()) { - jj_scanpos = xsp; - if (jj_3R_443()) return true; - } - } - } - } - return false; - } - - private boolean jj_3R_218() { - if (jj_3R_246()) return true; - return false; - } - - private boolean jj_3R_184() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_218()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_285() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_307()) { - jj_scanpos = xsp; - if (jj_3R_308()) return true; - } - return false; - } - - private boolean jj_3_9() { - if (jj_3R_92()) return true; - if (jj_scan_token(DOT)) return true; - return false; - } - - private boolean jj_3R_254() { - if (jj_3R_286()) return true; - return false; - } - - private boolean jj_3R_409() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_426()) { - jj_scanpos = xsp; - if (jj_3R_427()) return true; - } - return false; - } - - private boolean jj_3R_253() { - if (jj_3R_285()) return true; - return false; - } - - private boolean jj_3R_399() { - if (jj_3R_409()) return true; - return false; - } - - private boolean jj_3R_93() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_189() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_252() { - if (jj_scan_token(STRING_LITERAL)) return true; - return false; - } - - private boolean jj_3_10() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_93()) jj_scanpos = xsp; - if (jj_scan_token(THIS)) return true; - if (jj_scan_token(LPAREN)) return true; - return false; - } - - private boolean jj_3R_188() { - if (jj_3R_92()) return true; - if (jj_scan_token(DOT)) return true; - return false; - } - - private boolean jj_3R_251() { - if (jj_scan_token(CHARACTER_LITERAL)) return true; - return false; - } - - private boolean jj_3R_384() { - if (jj_scan_token(LBRACE)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_399()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_132() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_188()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_189()) jj_scanpos = xsp; - if (jj_scan_token(SUPER)) return true; - if (jj_3R_187()) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_250() { - if (jj_scan_token(FLOATING_POINT_LITERAL)) return true; - return false; - } - - private boolean jj_3R_186() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_131() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_186()) jj_scanpos = xsp; - if (jj_scan_token(THIS)) return true; - if (jj_3R_187()) return true; - if (jj_scan_token(SEMICOLON)) return true; - return false; - } - - private boolean jj_3R_249() { - if (jj_scan_token(LONG_LITERAL)) return true; - return false; - } - - private boolean jj_3R_248() { - if (jj_scan_token(INTEGER_LITERAL)) return true; - return false; - } - - private boolean jj_3R_91() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_131()) { - jj_scanpos = xsp; - if (jj_3R_132()) return true; - } - return false; - } - - private boolean jj_3R_300() { - if (jj_scan_token(AT)) return true; - if (jj_scan_token(INTERFACE)) return true; - if (jj_3R_119()) return true; - if (jj_3R_384()) return true; - return false; - } - - private boolean jj_3R_112() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_220() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_248()) { - jj_scanpos = xsp; - if (jj_3R_249()) { - jj_scanpos = xsp; - if (jj_3R_250()) { - jj_scanpos = xsp; - if (jj_3R_251()) { - jj_scanpos = xsp; - if (jj_3R_252()) { - jj_scanpos = xsp; - if (jj_3R_253()) { - jj_scanpos = xsp; - if (jj_3R_254()) return true; - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_166() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_3R_100()) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3_31() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_112()) jj_scanpos = xsp; - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - - private boolean jj_3R_324() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_323()) return true; - return false; - } - - private boolean jj_3_8() { - if (jj_3R_91()) return true; - return false; - } - - private boolean jj_3R_347() { - if (jj_3R_121()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_46()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3_7() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_90()) return true; - return false; - } - - private boolean jj_3R_238() { - if (jj_3R_187()) return true; - return false; - } - - private boolean jj_3R_237() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3R_167() { - if (jj_scan_token(ELLIPSIS)) return true; - return false; - } - - private boolean jj_3R_278() { - if (jj_3R_304()) return true; - return false; - } - - private boolean jj_3R_204() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_237()) jj_scanpos = xsp; - if (jj_3R_227()) return true; - xsp = jj_scanpos; - if (jj_3R_238()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_212() { - if (jj_scan_token(LBRACE)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_347()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(88)) jj_scanpos = xsp; - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_203() { - if (jj_3R_225()) return true; - return false; - } - - private boolean jj_3R_387() { - if (jj_3R_91()) return true; - return false; - } - - private boolean jj_3R_340() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_110()) return true; - return false; - } - - private boolean jj_3R_202() { - if (jj_scan_token(THIS)) return true; - return false; - } - - private boolean jj_3R_177() { - if (jj_3R_151()) return true; - return false; - } - - private boolean jj_3R_287() { - if (jj_3R_309()) return true; - return false; - } - - private boolean jj_3R_176() { - if (jj_3R_212()) return true; - return false; - } - - private boolean jj_3R_320() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_175() { - if (jj_3R_123()) return true; - return false; - } - - private boolean jj_3R_301() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_320()) jj_scanpos = xsp; - if (jj_3R_227()) return true; - if (jj_3R_385()) return true; - xsp = jj_scanpos; - if (jj_3R_386()) jj_scanpos = xsp; - if (jj_scan_token(LBRACE)) return true; - xsp = jj_scanpos; - if (jj_3R_387()) jj_scanpos = xsp; - if (jj_3R_184()) return true; - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_165() { - if (jj_scan_token(DOT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_202()) { - jj_scanpos = xsp; - if (jj_3R_203()) { - jj_scanpos = xsp; - if (jj_3R_204()) return true; - } - } - return false; - } - - private boolean jj_3R_410() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_110()) return true; - return false; - } - - private boolean jj_3R_121() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_175()) { - jj_scanpos = xsp; - if (jj_3R_176()) { - jj_scanpos = xsp; - if (jj_3R_177()) return true; - } - } - return false; - } - - private boolean jj_3R_109() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_165()) { - jj_scanpos = xsp; - if (jj_3R_166()) return true; - } - return false; - } - - private boolean jj_3R_323() { - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(ASSIGN)) return true; - if (jj_3R_121()) return true; - return false; - } - - private boolean jj_3R_164() { - if (jj_scan_token(DOT)) return true; - if (jj_scan_token(SUPER)) return true; - return false; - } - - private boolean jj_3_30() { - if (jj_3R_109()) return true; - return false; - } - - private boolean jj_3R_226() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_110() { - if (jj_3R_116()) return true; - if (jj_3R_87()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_167()) jj_scanpos = xsp; - if (jj_3R_168()) return true; - return false; - } - - private boolean jj_3R_108() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_30()) { - jj_scanpos = xsp; - if (jj_3R_164()) return true; - } - return false; - } - - private boolean jj_3R_304() { - if (jj_3R_323()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_324()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_228() { - if (jj_3R_187()) return true; - return false; - } - - private boolean jj_3R_389() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_197() { - if (jj_3R_227()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_228()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_341() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_168()) return true; - return false; - } - - private boolean jj_3_29() { - if (jj_3R_111()) return true; - if (jj_scan_token(DOUBLECOLON)) return true; - return false; - } - - private boolean jj_3R_205() { - if (jj_scan_token(LBRACKET)) return true; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - - private boolean jj_3R_214() { - if (jj_scan_token(AT)) return true; - if (jj_3R_119()) return true; - if (jj_scan_token(LPAREN)) return true; - if (jj_3R_121()) return true; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3_28() { - if (jj_3R_111()) return true; - if (jj_scan_token(DOT)) return true; - if (jj_scan_token(CLASS)) return true; - return false; - } - - private boolean jj_3R_310() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_168()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_341()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_120() { - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(ASSIGN)) return true; - return false; - } - - private boolean jj_3R_322() { - if (jj_3R_90()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_7()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_288() { - if (jj_3R_310()) return true; - return false; - } - - private boolean jj_3R_196() { - if (jj_3R_111()) return true; - if (jj_scan_token(DOUBLECOLON)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_226()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(78)) { - jj_scanpos = xsp; - if (jj_scan_token(43)) return true; - } - return false; - } - - private boolean jj_3R_195() { - if (jj_3R_111()) return true; - if (jj_scan_token(DOT)) return true; - if (jj_scan_token(CLASS)) return true; - return false; - } - - private boolean jj_3R_215() { - if (jj_scan_token(AT)) return true; - if (jj_3R_119()) return true; - return false; - } - - private boolean jj_3R_309() { - if (jj_scan_token(COMMA)) return true; - if (jj_3R_110()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_340()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_194() { - if (jj_3R_225()) return true; - return false; - } - - private boolean jj_3_27() { - if (jj_3R_110()) return true; - return false; - } - - private boolean jj_3R_400() { - if (jj_3R_110()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_410()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3_45() { - if (jj_scan_token(AT)) return true; - if (jj_3R_119()) return true; - if (jj_scan_token(LPAREN)) return true; - return false; - } - - private boolean jj_3_43() { - if (jj_scan_token(SEMICOLON)) return true; - if (jj_3R_117()) return true; - return false; - } - - private boolean jj_3_44() { - if (jj_scan_token(AT)) return true; - if (jj_3R_119()) return true; - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_120()) { - jj_scanpos = xsp; - if (jj_scan_token(82)) return true; - } - return false; - } - - private boolean jj_3R_213() { - if (jj_scan_token(AT)) return true; - if (jj_3R_119()) return true; - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_278()) jj_scanpos = xsp; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3R_385() { - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_400()) jj_scanpos = xsp; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3R_259() { - if (jj_3R_100()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_288()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_180() { - if (jj_3R_215()) return true; - return false; - } - - private boolean jj_3R_258() { - if (jj_3R_110()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_287()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_224() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_258()) { - jj_scanpos = xsp; - if (jj_3R_259()) return true; - } - return false; - } - - private boolean jj_3R_179() { - if (jj_3R_214()) return true; - return false; - } - - private boolean jj_3R_178() { - if (jj_3R_213()) return true; - return false; - } - - private boolean jj_3R_257() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_391() { - if (jj_3R_128()) return true; - return false; - } - - private boolean jj_3R_193() { - if (jj_scan_token(LPAREN)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_224()) jj_scanpos = xsp; - if (jj_scan_token(RPAREN)) return true; - return false; - } - - private boolean jj_3R_390() { - if (jj_scan_token(THROWS)) return true; - if (jj_3R_401()) return true; - return false; - } - - private boolean jj_3R_222() { - if (jj_scan_token(DOUBLECOLON)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_257()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(78)) { - jj_scanpos = xsp; - if (jj_scan_token(43)) return true; - } - return false; - } - - private boolean jj_3R_321() { - if (jj_3R_125()) return true; - return false; - } - - private boolean jj_3R_223() { - if (jj_3R_187()) return true; - return false; - } - - private boolean jj_3R_123() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_178()) { - jj_scanpos = xsp; - if (jj_3R_179()) { - jj_scanpos = xsp; - if (jj_3R_180()) return true; - } - } - return false; - } - - private boolean jj_3R_303() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_321()) jj_scanpos = xsp; - if (jj_3R_111()) return true; - if (jj_3R_119()) return true; - if (jj_3R_385()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_389()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_390()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_391()) { - jj_scanpos = xsp; - if (jj_scan_token(87)) return true; - } - return false; - } - - private boolean jj_3R_152() { - return false; - } - - private boolean jj_3R_153() { - return false; - } - - private boolean jj_3R_102() { - jj_lookingAhead = true; - jj_semLA = getToken(1).kind == GT && - ((GTToken)getToken(1)).realKind == RSIGNEDSHIFT; - jj_lookingAhead = false; - if (!jj_semLA || jj_3R_152()) return true; - if (jj_scan_token(GT)) return true; - if (jj_scan_token(GT)) return true; - return false; - } - - private boolean jj_3R_256() { - if (jj_3R_187()) return true; - return false; - } - - private boolean jj_3R_221() { - if (jj_scan_token(DOT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_255()) jj_scanpos = xsp; - if (jj_3R_227()) return true; - xsp = jj_scanpos; - if (jj_3R_256()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_255() { - if (jj_3R_97()) return true; - return false; - } - - private boolean jj_3_26() { - if (jj_3R_109()) return true; - return false; - } - - private boolean jj_3R_185() { - if (jj_scan_token(LBRACE)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_322()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_scan_token(88)) jj_scanpos = xsp; - if (jj_scan_token(RBRACE)) return true; - return false; - } - - private boolean jj_3R_192() { - if (jj_scan_token(SUPER)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_221()) { - jj_scanpos = xsp; - if (jj_3R_222()) { - jj_scanpos = xsp; - if (jj_3R_223()) return true; - } - } - return false; - } - - private boolean jj_3R_103() { - jj_lookingAhead = true; - jj_semLA = getToken(1).kind == GT && - ((GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT; - jj_lookingAhead = false; - if (!jj_semLA || jj_3R_153()) return true; - if (jj_scan_token(GT)) return true; - if (jj_scan_token(GT)) return true; - if (jj_scan_token(GT)) return true; - return false; - } - - private boolean jj_3R_191() { - if (jj_scan_token(THIS)) return true; - return false; - } - - private boolean jj_3R_130() { - if (jj_3R_100()) return true; - return false; - } - - private boolean jj_3R_190() { - if (jj_3R_220()) return true; - return false; - } - - private boolean jj_3R_129() { - if (jj_3R_185()) return true; - return false; - } - - private boolean jj_3R_207() { - if (jj_scan_token(ASSIGN)) return true; - if (jj_3R_90()) return true; - return false; - } - - private boolean jj_3R_134() { - if (jj_3R_109()) return true; - return false; - } - - private boolean jj_3R_453() { - if (jj_3R_117()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_43()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_133() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_190()) { - jj_scanpos = xsp; - if (jj_3R_191()) { - jj_scanpos = xsp; - if (jj_3R_192()) { - jj_scanpos = xsp; - if (jj_3R_193()) { - jj_scanpos = xsp; - if (jj_3R_194()) { - jj_scanpos = xsp; - if (jj_3R_195()) { - jj_scanpos = xsp; - if (jj_3R_196()) { - jj_scanpos = xsp; - if (jj_3R_197()) return true; - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_90() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_129()) { - jj_scanpos = xsp; - if (jj_3R_130()) return true; - } - return false; - } - - private boolean jj_3_25() { - if (jj_3R_108()) return true; - return false; - } - - private boolean jj_3R_168() { - if (jj_scan_token(IDENTIFIER)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_205()) { jj_scanpos = xsp; break; } - } - return false; - } - - /** Generated Token Manager. */ - public ASTParserTokenManager token_source; - JavaCharStream jj_input_stream; - /** Current token. */ - public Token token; - /** Next token. */ - public Token jj_nt; - private int jj_ntk; - private Token jj_scanpos, jj_lastpos; - private int jj_la; - /** Whether we are looking ahead. */ - private boolean jj_lookingAhead = false; - private boolean jj_semLA; - private int jj_gen; - final private int[] jj_la1 = new int[175]; - static private int[] jj_la1_0; - static private int[] jj_la1_1; - static private int[] jj_la1_2; - static private int[] jj_la1_3; - static private int[] jj_la1_4; - static { - jj_la1_init_0(); - jj_la1_init_1(); - jj_la1_init_2(); - jj_la1_init_3(); - jj_la1_init_4(); - } - private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x0,0x48101000,0x1,0x0,0x0,0x0,0x40001000,0x8100000,0x48101000,0x100000,0x0,0x10000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4a995000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000,0x0,0x0,0x0,0x4a995000,0x800000,0x8100000,0x2094000,0x4a995000,0x0,0x0,0x0,0x22094000,0x22094000,0x0,0x0,0x0,0x0,0x0,0x0,0x42095000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22094000,0x6359f000,0x0,0x2094000,0x0,0x0,0x2094000,0x0,0x0,0x0,0x0,0x2094000,0x0,0x0,0x10000000,0x10000000,0x2094000,0x2094000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22094000,0x0,0x0,0x22094000,0x0,0x0,0x2094000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22094000,0x62095000,0x0,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x0,0x0,0x20000000,0x20000000,0x22094000,0x0,0x0,0x0,0x0,0x0,0x2094000,0x0,0x0,0x0,0x0,0x2349e000,0x0,0x2349e000,0x0,0x22094000,0x0,0x0,0x0,0x0,0x22094000,0x820000,0x820000,0x4000000,0x62095000,0x22094000,0x22094000,0x62095000,0x22094000,0x0,0x0,0x0,0x22094000,0x0,0x40000,0x0,0x80000000,0x0,0x0,0x0,0x22094000,0x22094000,0x0,0x4a195000,0xa194000,0x4a195000,0x800000,}; - } - private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x20,0x8899c500,0x0,0x0,0x80000,0x0,0x8899c400,0x100,0x8899c500,0x100,0x0,0x0,0x10,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0xc89dc781,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc89dc781,0x0,0x100,0x40040281,0xc89dc781,0x0,0x0,0x0,0x51241a81,0x51241a81,0x0,0x0,0x0,0x4000000,0x0,0x0,0x889dc681,0x0,0x0,0x0,0x0,0x4000000,0x0,0x0,0x51241a81,0xfbffdf8b,0x80000,0x40281,0x0,0x0,0x40281,0x0,0x0,0x0,0x0,0x40281,0x0,0x0,0x200000,0x200000,0x40281,0x40040281,0x0,0x0,0x0,0x0,0x0,0x800,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x51241a81,0x0,0x0,0x51241a81,0x0,0x0,0x40281,0x0,0x0,0x0,0x800,0x0,0x0,0x0,0x51241a81,0xd9bdde81,0x0,0x800,0x0,0x11201800,0x0,0x0,0x0,0x0,0x1000800,0x0,0x10001000,0x10000000,0x51241a81,0x0,0x0,0x0,0x0,0x0,0x40281,0x0,0x0,0x0,0x0,0x73e61a8b,0x0,0x73e61a8b,0x0,0x51241a81,0x0,0x800,0x0,0x0,0x51241a81,0x0,0x0,0x0,0xd9bdde81,0x51241a81,0x51241a81,0xd9bdde81,0x51241a81,0x0,0x0,0x0,0x51241a81,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x51241a81,0x51241a81,0x0,0x889dc781,0x40381,0x889dc781,0x0,}; - } - private static void jj_la1_init_2() { - jj_la1_2 = new int[] {0x0,0x4800000,0x0,0x4000000,0x0,0x2000000,0x4000000,0x4000000,0x4800000,0x0,0x10000000,0x0,0x0,0x4000000,0x1000000,0x4000000,0x1000000,0x0,0x4004000,0x1000000,0x14884000,0x800000,0x4000000,0x20000,0x80000,0x4000000,0x1000000,0x4000000,0x0,0x4000000,0x0,0x4000000,0x14884000,0x0,0x4000000,0x10004000,0x14804000,0x1000000,0x8000000,0x200000,0x600a7086,0x600a7086,0x1000000,0x10000000,0x200000,0x0,0x880000,0x1000000,0x4004000,0x1000000,0x1000000,0x0,0x10000000,0x0,0x10000000,0x10000000,0x10027086,0x48a7087,0x0,0x0,0x4000000,0x4000000,0x4000,0x4000000,0x1000000,0x10000000,0x4000000,0x80004000,0x4000000,0x4000000,0x0,0x0,0x0,0x4000,0x4000000,0x1000000,0x4000000,0x1000000,0x10000000,0x4000,0x0,0x8000000,0x8000000,0x80000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x0,0x0,0x0,0x0,0x0,0x0,0x60027086,0x60000000,0x60000000,0x27086,0x0,0x4000000,0x4000,0x10000000,0x20000,0x10000000,0x4000,0x2020000,0x1000000,0x1000000,0x60027086,0x64027086,0x10000000,0x4000,0x20000,0x23086,0x4000,0x2000000,0x10000000,0x20000,0x0,0x2200000,0x3086,0x0,0x60027086,0x1000000,0x4000000,0x4000000,0x10000000,0x4220000,0x10004000,0x4000000,0x4000000,0x200000,0x200000,0x8a7087,0x0,0x8a7087,0x1000000,0x600a7086,0x10000000,0x4000,0x8000000,0x8000000,0x27086,0x0,0x0,0x0,0x64027086,0x60027086,0x60027086,0x64827086,0x60027086,0x1000000,0x4000,0x4000,0x60027086,0x20000,0x0,0x0,0x0,0x4000000,0x4000,0x1000000,0x640a7086,0x640a7086,0x1000000,0x4804000,0x4004000,0x4804000,0x0,}; - } - private static void jj_la1_init_3() { - jj_la1_3 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x780,0x780,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x0,0x180,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0000000,0xdffc0000,0x1ffc0000,0x0,0x20,0x40,0x4000,0x8000,0x2000,0x12,0x12,0x0,0xc,0xc,0x20000,0x600,0x600,0x11800,0x11800,0x600,0x780,0x0,0x0,0x0,0x180,0x0,0x0,0x0,0x0,0x0,0x0,0x80000000,0x0,0x0,0x780,0x780,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x780,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x180,0x1,0x180,0x0,0x780,0x0,0x0,0xdffc0180,0xdffc0180,0x100,0x0,0x0,0x0,0x780,0x780,0x780,0x780,0x780,0x0,0x0,0x0,0x780,0x0,0x0,0x4000,0x0,0x0,0x0,0x0,0x780,0x780,0x0,0x0,0x0,0x0,0x0,}; - } - private static void jj_la1_init_4() { - jj_la1_4 = new int[] {0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x10,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; - } - final private JJCalls[] jj_2_rtns = new JJCalls[47]; - private boolean jj_rescan = false; - private int jj_gc = 0; - - /** Constructor with InputStream. */ - public ASTParser(java.io.InputStream stream) { - this(stream, null); - } - /** Constructor with InputStream and supplied encoding */ - public ASTParser(java.io.InputStream stream, String encoding) { - try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source = new ASTParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream stream) { - ReInit(stream, null); - } - /** Reinitialise. */ - public void ReInit(java.io.InputStream stream, String encoding) { - try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - /** Constructor. */ - public ASTParser(java.io.Reader stream) { - jj_input_stream = new JavaCharStream(stream, 1, 1); - token_source = new ASTParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - /** Reinitialise. */ - public void ReInit(java.io.Reader stream) { - jj_input_stream.ReInit(stream, 1, 1); - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - /** Constructor with generated Token Manager. */ - public ASTParser(ASTParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - /** Reinitialise. */ - public void ReInit(ASTParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 175; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - private Token jj_consume_token(int kind) throws ParseException { - Token oldToken; - if ((oldToken = token).next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - if (token.kind == kind) { - jj_gen++; - if (++jj_gc > 100) { - jj_gc = 0; - for (int i = 0; i < jj_2_rtns.length; i++) { - JJCalls c = jj_2_rtns[i]; - while (c != null) { - if (c.gen < jj_gen) c.first = null; - c = c.next; - } - } - } - return token; - } - token = oldToken; - jj_kind = kind; - throw generateParseException(); - } - - static private final class LookaheadSuccess extends java.lang.Error { } - final private LookaheadSuccess jj_ls = new LookaheadSuccess(); - private boolean jj_scan_token(int kind) { - if (jj_scanpos == jj_lastpos) { - jj_la--; - if (jj_scanpos.next == null) { - jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); - } else { - jj_lastpos = jj_scanpos = jj_scanpos.next; - } - } else { - jj_scanpos = jj_scanpos.next; - } - if (jj_rescan) { - int i = 0; Token tok = token; - while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } - if (tok != null) jj_add_error_token(kind, i); - } - if (jj_scanpos.kind != kind) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; - return false; - } - - -/** Get the next Token. */ - final public Token getNextToken() { - if (token.next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - jj_gen++; - return token; - } - -/** Get the specific Token. */ - final public Token getToken(int index) { - Token t = jj_lookingAhead ? jj_scanpos : token; - for (int i = 0; i < index; i++) { - if (t.next != null) t = t.next; - else t = t.next = token_source.getNextToken(); - } - return t; - } - - private int jj_ntk() { - if ((jj_nt=token.next) == null) - return (jj_ntk = (token.next=token_source.getNextToken()).kind); - else - return (jj_ntk = jj_nt.kind); - } - - private java.util.List jj_expentries = new java.util.ArrayList(); - private int[] jj_expentry; - private int jj_kind = -1; - private int[] jj_lasttokens = new int[100]; - private int jj_endpos; - - private void jj_add_error_token(int kind, int pos) { - if (pos >= 100) return; - if (pos == jj_endpos + 1) { - jj_lasttokens[jj_endpos++] = kind; - } else if (jj_endpos != 0) { - jj_expentry = new int[jj_endpos]; - for (int i = 0; i < jj_endpos; i++) { - jj_expentry[i] = jj_lasttokens[i]; - } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { - int[] oldentry = (int[])(it.next()); - if (oldentry.length == jj_expentry.length) { - for (int i = 0; i < jj_expentry.length; i++) { - if (oldentry[i] != jj_expentry[i]) { - continue jj_entries_loop; - } - } - jj_expentries.add(jj_expentry); - break jj_entries_loop; - } - } - if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; - } - } - - /** Generate ParseException. */ - public ParseException generateParseException() { - jj_expentries.clear(); - boolean[] la1tokens = new boolean[133]; - if (jj_kind >= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 175; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1< jj_gen) { - jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; - switch (i) { - case 0: jj_3_1(); break; - case 1: jj_3_2(); break; - case 2: jj_3_3(); break; - case 3: jj_3_4(); break; - case 4: jj_3_5(); break; - case 5: jj_3_6(); break; - case 6: jj_3_7(); break; - case 7: jj_3_8(); break; - case 8: jj_3_9(); break; - case 9: jj_3_10(); break; - case 10: jj_3_11(); break; - case 11: jj_3_12(); break; - case 12: jj_3_13(); break; - case 13: jj_3_14(); break; - case 14: jj_3_15(); break; - case 15: jj_3_16(); break; - case 16: jj_3_17(); break; - case 17: jj_3_18(); break; - case 18: jj_3_19(); break; - case 19: jj_3_20(); break; - case 20: jj_3_21(); break; - case 21: jj_3_22(); break; - case 22: jj_3_23(); break; - case 23: jj_3_24(); break; - case 24: jj_3_25(); break; - case 25: jj_3_26(); break; - case 26: jj_3_27(); break; - case 27: jj_3_28(); break; - case 28: jj_3_29(); break; - case 29: jj_3_30(); break; - case 30: jj_3_31(); break; - case 31: jj_3_32(); break; - case 32: jj_3_33(); break; - case 33: jj_3_34(); break; - case 34: jj_3_35(); break; - case 35: jj_3_36(); break; - case 36: jj_3_37(); break; - case 37: jj_3_38(); break; - case 38: jj_3_39(); break; - case 39: jj_3_40(); break; - case 40: jj_3_41(); break; - case 41: jj_3_42(); break; - case 42: jj_3_43(); break; - case 43: jj_3_44(); break; - case 44: jj_3_45(); break; - case 45: jj_3_46(); break; - case 46: jj_3_47(); break; - } - } - p = p.next; - } while (p != null); - } catch(LookaheadSuccess ls) { } - } - jj_rescan = false; - } - - private void jj_save(int index, int xla) { - JJCalls p = jj_2_rtns[index]; - while (p.gen > jj_gen) { - if (p.next == null) { p = p.next = new JJCalls(); break; } - p = p.next; - } - p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; - } - - static final class JJCalls { - int gen; - Token first; - int arg; - JJCalls next; - } - -} diff --git a/JavaParser/src/com/github/javaparser/ASTParserTokenManager.java b/JavaParser/src/com/github/javaparser/ASTParserTokenManager.java deleted file mode 100644 index 326f573..0000000 --- a/JavaParser/src/com/github/javaparser/ASTParserTokenManager.java +++ /dev/null @@ -1,2559 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ASTParserTokenManager.java */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; -import java.io.*; -import java.util.*; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.comments.*; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -/** Token Manager. */ -public class ASTParserTokenManager implements ASTParserConstants -{ - - /** Debug output. */ - public java.io.PrintStream debugStream = System.out; - /** Set debug output. */ - public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1, long active2) -{ - switch (pos) - { - case 0: - if ((active0 & 0xfffffffffffff000L) != 0L || (active1 & 0x1L) != 0L) - { - jjmatchedKind = 78; - return 43; - } - if ((active0 & 0x100L) != 0L || (active1 & 0x20100000000000L) != 0L) - return 45; - if ((active1 & 0x2000000002000000L) != 0L) - return 1; - return -1; - case 1: - if ((active0 & 0x803000000L) != 0L) - return 43; - if ((active0 & 0xfffffff7fcfff000L) != 0L || (active1 & 0x1L) != 0L) - { - if (jjmatchedPos != 1) - { - jjmatchedKind = 78; - jjmatchedPos = 1; - } - return 43; - } - if ((active0 & 0x100L) != 0L) - return 50; - return -1; - case 2: - if ((active0 & 0x2000098200000000L) != 0L) - return 43; - if ((active0 & 0xdffff675fefff000L) != 0L || (active1 & 0x1L) != 0L) - { - if (jjmatchedPos != 2) - { - jjmatchedKind = 78; - jjmatchedPos = 2; - } - return 43; - } - return -1; - case 3: - if ((active0 & 0x8effe571f2f4f000L) != 0L || (active1 & 0x1L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 3; - return 43; - } - if ((active0 & 0x510012040c0b0000L) != 0L) - return 43; - return -1; - case 4: - if ((active0 & 0x88dbe57012c07000L) != 0L) - { - if (jjmatchedPos != 4) - { - jjmatchedKind = 78; - jjmatchedPos = 4; - } - return 43; - } - if ((active0 & 0x6240001e0348000L) != 0L || (active1 & 0x1L) != 0L) - return 43; - return -1; - case 5: - if ((active0 & 0x44b042002002000L) != 0L) - return 43; - if ((active0 & 0x8890e15090c05000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 5; - return 43; - } - return -1; - case 6: - if ((active0 & 0x600090804000L) != 0L) - return 43; - if ((active0 & 0x8890815000401000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 6; - return 43; - } - return -1; - case 7: - if ((active0 & 0x880815000000000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 7; - return 43; - } - if ((active0 & 0x8010000000401000L) != 0L) - return 43; - return -1; - case 8: - if ((active0 & 0x800810000000000L) != 0L) - return 43; - if ((active0 & 0x80005000000000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 8; - return 43; - } - return -1; - case 9: - if ((active0 & 0x5000000000L) != 0L) - return 43; - if ((active0 & 0x80000000000000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 9; - return 43; - } - return -1; - case 10: - if ((active0 & 0x80000000000000L) != 0L) - { - jjmatchedKind = 78; - jjmatchedPos = 10; - return 43; - } - return -1; - default : - return -1; - } -} -private final int jjStartNfa_0(int pos, long active0, long active1, long active2) -{ - return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1, active2), pos + 1); -} -private int jjStopAtPos(int pos, int kind) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - return pos + 1; -} -private int jjMoveStringLiteralDfa0_0() -{ - switch(curChar) - { - case 26: - return jjStopAtPos(0, 131); - case 33: - jjmatchedKind = 93; - return jjMoveStringLiteralDfa1_0(0x0L, 0x1000000000L, 0x0L); - case 37: - jjmatchedKind = 112; - return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000000000L, 0x0L); - case 38: - jjmatchedKind = 109; - return jjMoveStringLiteralDfa1_0(0x0L, 0x40004000000000L, 0x0L); - case 40: - return jjStopAtPos(0, 81); - case 41: - return jjStopAtPos(0, 82); - case 42: - jjmatchedKind = 107; - return jjMoveStringLiteralDfa1_0(0x0L, 0x10000000000000L, 0x0L); - case 43: - jjmatchedKind = 105; - return jjMoveStringLiteralDfa1_0(0x0L, 0x4008000000000L, 0x0L); - case 44: - return jjStopAtPos(0, 88); - case 45: - jjmatchedKind = 106; - return jjMoveStringLiteralDfa1_0(0x0L, 0x4008010000000000L, 0x0L); - case 46: - jjmatchedKind = 89; - return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000000000000L, 0x0L); - case 47: - jjmatchedKind = 108; - return jjMoveStringLiteralDfa1_0(0x100L, 0x20000000000000L, 0x0L); - case 58: - jjmatchedKind = 96; - return jjMoveStringLiteralDfa1_0(0x0L, 0x8000000000000000L, 0x0L); - case 59: - return jjStopAtPos(0, 87); - case 60: - jjmatchedKind = 92; - return jjMoveStringLiteralDfa1_0(0x0L, 0x402000400000000L, 0x10L); - case 61: - jjmatchedKind = 91; - return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000L, 0x0L); - case 62: - jjmatchedKind = 130; - return jjMoveStringLiteralDfa1_0(0x0L, 0x1800000800000000L, 0x3L); - case 63: - return jjStopAtPos(0, 95); - case 64: - return jjStopAtPos(0, 90); - case 91: - return jjStopAtPos(0, 85); - case 93: - return jjStopAtPos(0, 86); - case 94: - jjmatchedKind = 111; - return jjMoveStringLiteralDfa1_0(0x0L, 0x100000000000000L, 0x0L); - case 97: - return jjMoveStringLiteralDfa1_0(0x3000L, 0x0L, 0x0L); - case 98: - return jjMoveStringLiteralDfa1_0(0x1c000L, 0x0L, 0x0L); - case 99: - return jjMoveStringLiteralDfa1_0(0x7e0000L, 0x0L, 0x0L); - case 100: - return jjMoveStringLiteralDfa1_0(0x3800000L, 0x0L, 0x0L); - case 101: - return jjMoveStringLiteralDfa1_0(0x1c000000L, 0x0L, 0x0L); - case 102: - return jjMoveStringLiteralDfa1_0(0x3e0000000L, 0x0L, 0x0L); - case 103: - return jjMoveStringLiteralDfa1_0(0x400000000L, 0x0L, 0x0L); - case 105: - return jjMoveStringLiteralDfa1_0(0x1f800000000L, 0x0L, 0x0L); - case 108: - return jjMoveStringLiteralDfa1_0(0x20000000000L, 0x0L, 0x0L); - case 110: - return jjMoveStringLiteralDfa1_0(0x1c0000000000L, 0x0L, 0x0L); - case 112: - return jjMoveStringLiteralDfa1_0(0x1e00000000000L, 0x0L, 0x0L); - case 114: - return jjMoveStringLiteralDfa1_0(0x2000000000000L, 0x0L, 0x0L); - case 115: - return jjMoveStringLiteralDfa1_0(0xfc000000000000L, 0x0L, 0x0L); - case 116: - return jjMoveStringLiteralDfa1_0(0x3f00000000000000L, 0x0L, 0x0L); - case 118: - return jjMoveStringLiteralDfa1_0(0xc000000000000000L, 0x0L, 0x0L); - case 119: - return jjMoveStringLiteralDfa1_0(0x0L, 0x1L, 0x0L); - case 123: - return jjStopAtPos(0, 83); - case 124: - jjmatchedKind = 110; - return jjMoveStringLiteralDfa1_0(0x0L, 0x80002000000000L, 0x0L); - case 125: - return jjStopAtPos(0, 84); - case 126: - return jjStopAtPos(0, 94); - default : - return jjMoveNfa_0(0, 0); - } -} -private int jjMoveStringLiteralDfa1_0(long active0, long active1, long active2) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(0, active0, active1, active2); - return 1; - } - switch(curChar) - { - case 38: - if ((active1 & 0x4000000000L) != 0L) - return jjStopAtPos(1, 102); - break; - case 42: - if ((active0 & 0x100L) != 0L) - return jjStartNfaWithStates_0(1, 8, 50); - break; - case 43: - if ((active1 & 0x8000000000L) != 0L) - return jjStopAtPos(1, 103); - break; - case 45: - if ((active1 & 0x10000000000L) != 0L) - return jjStopAtPos(1, 104); - break; - case 46: - return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x2000000000000000L, active2, 0L); - case 58: - if ((active1 & 0x8000000000000000L) != 0L) - return jjStopAtPos(1, 127); - break; - case 60: - if ((active1 & 0x2000000000000L) != 0L) - { - jjmatchedKind = 113; - jjmatchedPos = 1; - } - return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x400000000000000L, active2, 0L); - case 61: - if ((active1 & 0x200000000L) != 0L) - return jjStopAtPos(1, 97); - else if ((active1 & 0x400000000L) != 0L) - return jjStopAtPos(1, 98); - else if ((active1 & 0x800000000L) != 0L) - return jjStopAtPos(1, 99); - else if ((active1 & 0x1000000000L) != 0L) - return jjStopAtPos(1, 100); - else if ((active1 & 0x4000000000000L) != 0L) - return jjStopAtPos(1, 114); - else if ((active1 & 0x8000000000000L) != 0L) - return jjStopAtPos(1, 115); - else if ((active1 & 0x10000000000000L) != 0L) - return jjStopAtPos(1, 116); - else if ((active1 & 0x20000000000000L) != 0L) - return jjStopAtPos(1, 117); - else if ((active1 & 0x40000000000000L) != 0L) - return jjStopAtPos(1, 118); - else if ((active1 & 0x80000000000000L) != 0L) - return jjStopAtPos(1, 119); - else if ((active1 & 0x100000000000000L) != 0L) - return jjStopAtPos(1, 120); - else if ((active1 & 0x200000000000000L) != 0L) - return jjStopAtPos(1, 121); - break; - case 62: - if ((active1 & 0x4000000000000000L) != 0L) - return jjStopAtPos(1, 126); - else if ((active2 & 0x2L) != 0L) - { - jjmatchedKind = 129; - jjmatchedPos = 1; - } - else if ((active2 & 0x10L) != 0L) - return jjStopAtPos(1, 132); - return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x1800000000000000L, active2, 0x1L); - case 97: - return jjMoveStringLiteralDfa2_0(active0, 0x240020060000L, active1, 0L, active2, 0L); - case 98: - return jjMoveStringLiteralDfa2_0(active0, 0x1000L, active1, 0L, active2, 0L); - case 101: - return jjMoveStringLiteralDfa2_0(active0, 0x2080000800000L, active1, 0L, active2, 0L); - case 102: - if ((active0 & 0x800000000L) != 0L) - return jjStartNfaWithStates_0(1, 35, 43); - break; - case 104: - return jjMoveStringLiteralDfa2_0(active0, 0x704000000080000L, active1, 0x1L, active2, 0L); - case 105: - return jjMoveStringLiteralDfa2_0(active0, 0xc0000000L, active1, 0L, active2, 0L); - case 108: - return jjMoveStringLiteralDfa2_0(active0, 0x104100000L, active1, 0L, active2, 0L); - case 109: - return jjMoveStringLiteralDfa2_0(active0, 0x3000000000L, active1, 0L, active2, 0L); - case 110: - return jjMoveStringLiteralDfa2_0(active0, 0x1c008000000L, active1, 0L, active2, 0L); - case 111: - if ((active0 & 0x1000000L) != 0L) - { - jjmatchedKind = 24; - jjmatchedPos = 1; - } - return jjMoveStringLiteralDfa2_0(active0, 0xc000020602604000L, active1, 0L, active2, 0L); - case 114: - return jjMoveStringLiteralDfa2_0(active0, 0x3800c00000008000L, active1, 0L, active2, 0L); - case 115: - return jjMoveStringLiteralDfa2_0(active0, 0x2000L, active1, 0L, active2, 0L); - case 116: - return jjMoveStringLiteralDfa2_0(active0, 0x18000000000000L, active1, 0L, active2, 0L); - case 117: - return jjMoveStringLiteralDfa2_0(active0, 0x21100000000000L, active1, 0L, active2, 0L); - case 119: - return jjMoveStringLiteralDfa2_0(active0, 0x40000000000000L, active1, 0L, active2, 0L); - case 120: - return jjMoveStringLiteralDfa2_0(active0, 0x10000000L, active1, 0L, active2, 0L); - case 121: - return jjMoveStringLiteralDfa2_0(active0, 0x80000000010000L, active1, 0L, active2, 0L); - case 124: - if ((active1 & 0x2000000000L) != 0L) - return jjStopAtPos(1, 101); - break; - default : - break; - } - return jjStartNfa_0(0, active0, active1, active2); -} -private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1, long old2, long active2) -{ - if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) - return jjStartNfa_0(0, old0, old1, old2); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(1, active0, active1, active2); - return 2; - } - switch(curChar) - { - case 46: - if ((active1 & 0x2000000000000000L) != 0L) - return jjStopAtPos(2, 125); - break; - case 61: - if ((active1 & 0x400000000000000L) != 0L) - return jjStopAtPos(2, 122); - else if ((active1 & 0x800000000000000L) != 0L) - return jjStopAtPos(2, 123); - break; - case 62: - if ((active2 & 0x1L) != 0L) - { - jjmatchedKind = 128; - jjmatchedPos = 2; - } - return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x1000000000000000L, active2, 0L); - case 97: - return jjMoveStringLiteralDfa3_0(active0, 0x808000000180000L, active1, 0L, active2, 0L); - case 98: - return jjMoveStringLiteralDfa3_0(active0, 0x1000000000000L, active1, 0L, active2, 0L); - case 99: - return jjMoveStringLiteralDfa3_0(active0, 0x200000000000L, active1, 0L, active2, 0L); - case 101: - return jjMoveStringLiteralDfa3_0(active0, 0x8000L, active1, 0L, active2, 0L); - case 102: - return jjMoveStringLiteralDfa3_0(active0, 0x800000L, active1, 0L, active2, 0L); - case 105: - return jjMoveStringLiteralDfa3_0(active0, 0x4140400000000000L, active1, 0x1L, active2, 0L); - case 108: - return jjMoveStringLiteralDfa3_0(active0, 0x8000100020000000L, active1, 0L, active2, 0L); - case 110: - return jjMoveStringLiteralDfa3_0(active0, 0x800200c0600000L, active1, 0L, active2, 0L); - case 111: - return jjMoveStringLiteralDfa3_0(active0, 0x4800100004000L, active1, 0L, active2, 0L); - case 112: - return jjMoveStringLiteralDfa3_0(active0, 0x20003000000000L, active1, 0L, active2, 0L); - case 114: - if ((active0 & 0x200000000L) != 0L) - return jjStartNfaWithStates_0(2, 33, 43); - return jjMoveStringLiteralDfa3_0(active0, 0x610000000000000L, active1, 0L, active2, 0L); - case 115: - return jjMoveStringLiteralDfa3_0(active0, 0x4004023000L, active1, 0L, active2, 0L); - case 116: - if ((active0 & 0x8000000000L) != 0L) - { - jjmatchedKind = 39; - jjmatchedPos = 2; - } - return jjMoveStringLiteralDfa3_0(active0, 0x2050410050000L, active1, 0L, active2, 0L); - case 117: - return jjMoveStringLiteralDfa3_0(active0, 0x100000000a000000L, active1, 0L, active2, 0L); - case 119: - if ((active0 & 0x80000000000L) != 0L) - return jjStartNfaWithStates_0(2, 43, 43); - break; - case 121: - if ((active0 & 0x2000000000000000L) != 0L) - return jjStartNfaWithStates_0(2, 61, 43); - break; - default : - break; - } - return jjStartNfa_0(1, active0, active1, active2); -} -private int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1, long old2, long active2) -{ - if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) - return jjStartNfa_0(1, old0, old1, old2); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(2, active0, active1, 0L); - return 3; - } - switch(curChar) - { - case 61: - if ((active1 & 0x1000000000000000L) != 0L) - return jjStopAtPos(3, 124); - break; - case 97: - return jjMoveStringLiteralDfa4_0(active0, 0x80000001c0808000L, active1, 0L); - case 98: - return jjMoveStringLiteralDfa4_0(active0, 0x2000000L, active1, 0L); - case 99: - return jjMoveStringLiteralDfa4_0(active0, 0x80000000040000L, active1, 0L); - case 100: - if ((active0 & 0x4000000000000000L) != 0L) - return jjStartNfaWithStates_0(3, 62, 43); - break; - case 101: - if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(3, 16, 43); - else if ((active0 & 0x20000L) != 0L) - return jjStartNfaWithStates_0(3, 17, 43); - else if ((active0 & 0x4000000L) != 0L) - return jjStartNfaWithStates_0(3, 26, 43); - else if ((active0 & 0x1000000000000000L) != 0L) - return jjStartNfaWithStates_0(3, 60, 43); - return jjMoveStringLiteralDfa4_0(active0, 0x20010010002000L, active1, 0L); - case 103: - if ((active0 & 0x20000000000L) != 0L) - return jjStartNfaWithStates_0(3, 41, 43); - break; - case 105: - return jjMoveStringLiteralDfa4_0(active0, 0x10040000000000L, active1, 0L); - case 107: - return jjMoveStringLiteralDfa4_0(active0, 0x200000000000L, active1, 0L); - case 108: - if ((active0 & 0x100000000000L) != 0L) - return jjStartNfaWithStates_0(3, 44, 43); - return jjMoveStringLiteralDfa4_0(active0, 0x1001000004000L, active1, 0x1L); - case 109: - if ((active0 & 0x8000000L) != 0L) - return jjStartNfaWithStates_0(3, 27, 43); - break; - case 110: - return jjMoveStringLiteralDfa4_0(active0, 0x800000000000000L, active1, 0L); - case 111: - if ((active0 & 0x400000000L) != 0L) - return jjStartNfaWithStates_0(3, 34, 43); - return jjMoveStringLiteralDfa4_0(active0, 0x600002000000000L, active1, 0L); - case 114: - if ((active0 & 0x80000L) != 0L) - return jjStartNfaWithStates_0(3, 19, 43); - return jjMoveStringLiteralDfa4_0(active0, 0x4000000000000L, active1, 0L); - case 115: - if ((active0 & 0x100000000000000L) != 0L) - return jjStartNfaWithStates_0(3, 56, 43); - return jjMoveStringLiteralDfa4_0(active0, 0x20300000L, active1, 0L); - case 116: - return jjMoveStringLiteralDfa4_0(active0, 0x48804000401000L, active1, 0L); - case 117: - return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L); - case 118: - return jjMoveStringLiteralDfa4_0(active0, 0x400000000000L, active1, 0L); - default : - break; - } - return jjStartNfa_0(2, active0, active1, 0L); -} -private int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1) -{ - if (((active0 &= old0) | (active1 &= old1)) == 0L) - return jjStartNfa_0(2, old0, old1, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(3, active0, active1, 0L); - return 4; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa5_0(active0, 0x604000000000L, active1, 0L); - case 99: - return jjMoveStringLiteralDfa5_0(active0, 0x50000000000000L, active1, 0L); - case 101: - if ((active0 & 0x20000000L) != 0L) - return jjStartNfaWithStates_0(4, 29, 43); - else if ((active1 & 0x1L) != 0L) - return jjStartNfaWithStates_0(4, 64, 43); - return jjMoveStringLiteralDfa5_0(active0, 0x801000004000L, active1, 0L); - case 104: - if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(4, 18, 43); - return jjMoveStringLiteralDfa5_0(active0, 0x80000000000000L, active1, 0L); - case 105: - return jjMoveStringLiteralDfa5_0(active0, 0x9000000400000L, active1, 0L); - case 107: - if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(4, 15, 43); - break; - case 108: - if ((active0 & 0x40000000L) != 0L) - { - jjmatchedKind = 30; - jjmatchedPos = 4; - } - return jjMoveStringLiteralDfa5_0(active0, 0x82000000L, active1, 0L); - case 110: - return jjMoveStringLiteralDfa5_0(active0, 0x10000000L, active1, 0L); - case 114: - if ((active0 & 0x20000000000000L) != 0L) - return jjStartNfaWithStates_0(4, 53, 43); - return jjMoveStringLiteralDfa5_0(active0, 0x2012000003000L, active1, 0L); - case 115: - if ((active0 & 0x100000L) != 0L) - return jjStartNfaWithStates_0(4, 20, 43); - return jjMoveStringLiteralDfa5_0(active0, 0x800000000000000L, active1, 0L); - case 116: - if ((active0 & 0x200000L) != 0L) - return jjStartNfaWithStates_0(4, 21, 43); - else if ((active0 & 0x100000000L) != 0L) - return jjStartNfaWithStates_0(4, 32, 43); - else if ((active0 & 0x4000000000000L) != 0L) - return jjStartNfaWithStates_0(4, 50, 43); - return jjMoveStringLiteralDfa5_0(active0, 0x8000000000000000L, active1, 0L); - case 117: - return jjMoveStringLiteralDfa5_0(active0, 0x800000L, active1, 0L); - case 118: - return jjMoveStringLiteralDfa5_0(active0, 0x40000000000L, active1, 0L); - case 119: - if ((active0 & 0x200000000000000L) != 0L) - { - jjmatchedKind = 57; - jjmatchedPos = 4; - } - return jjMoveStringLiteralDfa5_0(active0, 0x400000000000000L, active1, 0L); - default : - break; - } - return jjStartNfa_0(3, active0, active1, 0L); -} -private int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1) -{ - if (((active0 &= old0) | (active1 &= old1)) == 0L) - return jjStartNfa_0(3, old0, old1, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(4, active0, 0L, 0L); - return 5; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa6_0(active0, 0x5000L); - case 99: - if ((active0 & 0x1000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 48, 43); - else if ((active0 & 0x8000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 51, 43); - return jjMoveStringLiteralDfa6_0(active0, 0x800000000000L); - case 100: - return jjMoveStringLiteralDfa6_0(active0, 0x10000000L); - case 101: - if ((active0 & 0x2000000L) != 0L) - return jjStartNfaWithStates_0(5, 25, 43); - else if ((active0 & 0x40000000000L) != 0L) - return jjStartNfaWithStates_0(5, 42, 43); - break; - case 102: - return jjMoveStringLiteralDfa6_0(active0, 0x10000000000L); - case 103: - return jjMoveStringLiteralDfa6_0(active0, 0x200000000000L); - case 104: - if ((active0 & 0x40000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 54, 43); - break; - case 105: - return jjMoveStringLiteralDfa6_0(active0, 0x8800000000000000L); - case 108: - return jjMoveStringLiteralDfa6_0(active0, 0x80800000L); - case 109: - return jjMoveStringLiteralDfa6_0(active0, 0x1000000000L); - case 110: - if ((active0 & 0x2000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 49, 43); - return jjMoveStringLiteralDfa6_0(active0, 0x4000400000L); - case 114: - return jjMoveStringLiteralDfa6_0(active0, 0x80000000000000L); - case 115: - if ((active0 & 0x400000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 58, 43); - break; - case 116: - if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(5, 13, 43); - else if ((active0 & 0x2000000000L) != 0L) - return jjStartNfaWithStates_0(5, 37, 43); - return jjMoveStringLiteralDfa6_0(active0, 0x10400000000000L); - default : - break; - } - return jjStartNfa_0(4, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa6_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(4, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(5, active0, 0L, 0L); - return 6; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa7_0(active0, 0x10000000000L); - case 99: - return jjMoveStringLiteralDfa7_0(active0, 0x4000001000L); - case 101: - if ((active0 & 0x200000000000L) != 0L) - return jjStartNfaWithStates_0(6, 45, 43); - else if ((active0 & 0x400000000000L) != 0L) - return jjStartNfaWithStates_0(6, 46, 43); - return jjMoveStringLiteralDfa7_0(active0, 0x800001000000000L); - case 102: - return jjMoveStringLiteralDfa7_0(active0, 0x10000000000000L); - case 108: - return jjMoveStringLiteralDfa7_0(active0, 0x8000000000000000L); - case 110: - if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(6, 14, 43); - break; - case 111: - return jjMoveStringLiteralDfa7_0(active0, 0x80000000000000L); - case 115: - if ((active0 & 0x10000000L) != 0L) - return jjStartNfaWithStates_0(6, 28, 43); - break; - case 116: - if ((active0 & 0x800000L) != 0L) - return jjStartNfaWithStates_0(6, 23, 43); - return jjMoveStringLiteralDfa7_0(active0, 0x800000000000L); - case 117: - return jjMoveStringLiteralDfa7_0(active0, 0x400000L); - case 121: - if ((active0 & 0x80000000L) != 0L) - return jjStartNfaWithStates_0(6, 31, 43); - break; - default : - break; - } - return jjStartNfa_0(5, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa7_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(5, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(6, active0, 0L, 0L); - return 7; - } - switch(curChar) - { - case 99: - return jjMoveStringLiteralDfa8_0(active0, 0x10000000000L); - case 101: - if ((active0 & 0x400000L) != 0L) - return jjStartNfaWithStates_0(7, 22, 43); - else if ((active0 & 0x8000000000000000L) != 0L) - return jjStartNfaWithStates_0(7, 63, 43); - return jjMoveStringLiteralDfa8_0(active0, 0x804000000000L); - case 110: - return jjMoveStringLiteralDfa8_0(active0, 0x880001000000000L); - case 112: - if ((active0 & 0x10000000000000L) != 0L) - return jjStartNfaWithStates_0(7, 52, 43); - break; - case 116: - if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(7, 12, 43); - break; - default : - break; - } - return jjStartNfa_0(6, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa8_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(6, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(7, active0, 0L, 0L); - return 8; - } - switch(curChar) - { - case 100: - if ((active0 & 0x800000000000L) != 0L) - return jjStartNfaWithStates_0(8, 47, 43); - break; - case 101: - if ((active0 & 0x10000000000L) != 0L) - return jjStartNfaWithStates_0(8, 40, 43); - break; - case 105: - return jjMoveStringLiteralDfa9_0(active0, 0x80000000000000L); - case 111: - return jjMoveStringLiteralDfa9_0(active0, 0x4000000000L); - case 116: - if ((active0 & 0x800000000000000L) != 0L) - return jjStartNfaWithStates_0(8, 59, 43); - return jjMoveStringLiteralDfa9_0(active0, 0x1000000000L); - default : - break; - } - return jjStartNfa_0(7, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa9_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(7, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(8, active0, 0L, 0L); - return 9; - } - switch(curChar) - { - case 102: - if ((active0 & 0x4000000000L) != 0L) - return jjStartNfaWithStates_0(9, 38, 43); - break; - case 115: - if ((active0 & 0x1000000000L) != 0L) - return jjStartNfaWithStates_0(9, 36, 43); - break; - case 122: - return jjMoveStringLiteralDfa10_0(active0, 0x80000000000000L); - default : - break; - } - return jjStartNfa_0(8, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa10_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(8, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(9, active0, 0L, 0L); - return 10; - } - switch(curChar) - { - case 101: - return jjMoveStringLiteralDfa11_0(active0, 0x80000000000000L); - default : - break; - } - return jjStartNfa_0(9, active0, 0L, 0L); -} -private int jjMoveStringLiteralDfa11_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(9, old0, 0L, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(10, active0, 0L, 0L); - return 11; - } - switch(curChar) - { - case 100: - if ((active0 & 0x80000000000000L) != 0L) - return jjStartNfaWithStates_0(11, 55, 43); - break; - default : - break; - } - return jjStartNfa_0(10, active0, 0L, 0L); -} -private int jjStartNfaWithStates_0(int pos, int kind, int state) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return pos + 1; } - return jjMoveNfa_0(state, pos + 1); -} -static final long[] jjbitVec0 = { - 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL -}; -static final long[] jjbitVec2 = { - 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL -}; -static final long[] jjbitVec3 = { - 0xfff0000000200002L, 0xffffffffffffdfffL, 0xfffff00f7fffffffL, 0x12000000007fffffL -}; -static final long[] jjbitVec4 = { - 0x0L, 0x0L, 0x420043c00000000L, 0xff7fffffff7fffffL -}; -static final long[] jjbitVec5 = { - 0x7fffffffffffffL, 0xffffffffffff0000L, 0xffffffffffffffffL, 0x401f0003ffc3L -}; -static final long[] jjbitVec6 = { - 0x0L, 0x400000000000000L, 0xfffffffbffffd740L, 0xfbfffffffff7fffL -}; -static final long[] jjbitVec7 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffffc03L, 0x33fffffffff7fffL -}; -static final long[] jjbitVec8 = { - 0xfffe00000000ffffL, 0xfffffffe027fffffL, 0xffL, 0x707ffffff0000L -}; -static final long[] jjbitVec9 = { - 0x7fffffe00000000L, 0xfffec000000007ffL, 0xffffffffffffffffL, 0x9c00c060002fffffL -}; -static final long[] jjbitVec10 = { - 0xfffffffd0000L, 0xe000L, 0x2003fffffffffL, 0x0L -}; -static final long[] jjbitVec11 = { - 0x23fffffffffffff0L, 0x3ff010000L, 0x23c5fdfffff99fe0L, 0xf0003b0000000L -}; -static final long[] jjbitVec12 = { - 0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbbfe0L, 0x2000300010000L -}; -static final long[] jjbitVec13 = { - 0x23edfdfffff99fe0L, 0x20003b0000000L, 0x3bfc718d63dc7e8L, 0x200000000000000L -}; -static final long[] jjbitVec14 = { - 0x3effdfffffddfe0L, 0x300000000L, 0x23effdfffffddfe0L, 0x340000000L -}; -static final long[] jjbitVec15 = { - 0x3fffdfffffddfe0L, 0x300000000L, 0x2ffbfffffc7fffe0L, 0x7fL -}; -static final long[] jjbitVec16 = { - 0x800dfffffffffffeL, 0x7fL, 0x200decaefef02596L, 0x3000005fL -}; -static final long[] jjbitVec17 = { - 0x1L, 0x7fffffffeffL, 0xf00L, 0x0L -}; -static final long[] jjbitVec18 = { - 0x6fbffffffffL, 0x3f0000L, 0xffffffff00000000L, 0x1ffffffffff003fL -}; -static final long[] jjbitVec19 = { - 0xffffffffffffffffL, 0xffffffff83ffffffL, 0xffffff07ffffffffL, 0x3ffffffffffffffL -}; -static final long[] jjbitVec20 = { - 0xffffffffffffff7fL, 0xffffffff3d7f3d7fL, 0x7f3d7fffffff3d7fL, 0xffff7fffff7f7f3dL -}; -static final long[] jjbitVec21 = { - 0xffffffff7f3d7fffL, 0x7ffff7fL, 0xffffffff00000000L, 0x1fffffffffffffL -}; -static final long[] jjbitVec22 = { - 0xffffffffffffffffL, 0x7f9fffffffffffL, 0xffffffff07fffffeL, 0x1c7ffffffffffL -}; -static final long[] jjbitVec23 = { - 0x3ffff0003dfffL, 0x1dfff0003ffffL, 0xfffffffffffffL, 0x18800000L -}; -static final long[] jjbitVec24 = { - 0xffffffff00000000L, 0xffffffffffffffL, 0x1ffffffffffL, 0x0L -}; -static final long[] jjbitVec25 = { - 0x1fffffffL, 0x1f3fffffff0000L, 0x0L, 0x0L -}; -static final long[] jjbitVec26 = { - 0xffffffffffffffffL, 0xfffffffffffL, 0x0L, 0x0L -}; -static final long[] jjbitVec27 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffff0fffffffL, 0x3ffffffffffffffL -}; -static final long[] jjbitVec28 = { - 0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL -}; -static final long[] jjbitVec29 = { - 0x8000000000000000L, 0x8002000000100001L, 0x3ffff00000000L, 0x0L -}; -static final long[] jjbitVec30 = { - 0xe3fbbd503e2ffc84L, 0xffffffff000003e0L, 0xfL, 0x0L -}; -static final long[] jjbitVec31 = { - 0x1f3e03fe000000e0L, 0xfffffffffffffffeL, 0xfffffffee07fffffL, 0xffffffffffffffffL -}; -static final long[] jjbitVec32 = { - 0xfffe1fffffffffe0L, 0xffffffffffffffffL, 0xffffff00007fffL, 0xffff000000000000L -}; -static final long[] jjbitVec33 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffffffL, 0x0L -}; -static final long[] jjbitVec34 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffL, 0x0L -}; -static final long[] jjbitVec35 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL, 0x0L -}; -static final long[] jjbitVec36 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffL, 0x0L -}; -static final long[] jjbitVec37 = { - 0x6L, 0x0L, 0x0L, 0x0L -}; -static final long[] jjbitVec38 = { - 0xffff3fffffffffffL, 0x7ffffffffffL, 0x0L, 0x0L -}; -static final long[] jjbitVec39 = { - 0x5f7ffdffa0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L -}; -static final long[] jjbitVec40 = { - 0x3fffffffffffffffL, 0xffffffffffff0000L, 0xfffffffffffcffffL, 0x1fff0000000000ffL -}; -static final long[] jjbitVec41 = { - 0x18000000000000L, 0xffdf02000000e000L, 0xffffffffffffffffL, 0x1fffffffffffffffL -}; -static final long[] jjbitVec42 = { - 0x87fffffe00000010L, 0xffffffe007fffffeL, 0x7fffffffffffffffL, 0x631cfcfcfcL -}; -static final long[] jjbitVec43 = { - 0x0L, 0x0L, 0x420243cffffffffL, 0xff7fffffff7fffffL -}; -static final long[] jjbitVec44 = { - 0xffffffffffffffffL, 0x400ffffe0ffffffL, 0xfffffffbffffd740L, 0xfbfffffffff7fffL -}; -static final long[] jjbitVec45 = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffffc7bL, 0x33fffffffff7fffL -}; -static final long[] jjbitVec46 = { - 0xfffe00000000ffffL, 0xfffffffe027fffffL, 0xbbfffffbfffe00ffL, 0x707ffffff0016L -}; -static final long[] jjbitVec47 = { - 0x7fffffe003f000fL, 0xffffc3ff01ffffffL, 0xffffffffffffffffL, 0x9ffffdffbfefffffL -}; -static final long[] jjbitVec48 = { - 0xffffffffffff8000L, 0xe7ffL, 0x3ffffffffffffL, 0x0L -}; -static final long[] jjbitVec49 = { - 0xf3fffffffffffffeL, 0xffcfff1f3fffL, 0xf3c5fdfffff99feeL, 0xfffcfb080399fL -}; -static final long[] jjbitVec50 = { - 0xd36dfdfffff987eeL, 0x1fffc05e003987L, 0xf3edfdfffffbbfeeL, 0x2ffcf00013bbfL -}; -static final long[] jjbitVec51 = { - 0xf3edfdfffff99feeL, 0x2ffc3b0c0398fL, 0xc3bfc718d63dc7ecL, 0x200ff8000803dc7L -}; -static final long[] jjbitVec52 = { - 0xc3effdfffffddfeeL, 0xffc300603ddfL, 0xf3effdfffffddfecL, 0xffc340603ddfL -}; -static final long[] jjbitVec53 = { - 0xc3fffdfffffddfecL, 0xffc300803dcfL, 0x2ffbfffffc7fffecL, 0xc0000ff5f847fL -}; -static final long[] jjbitVec54 = { - 0x87fffffffffffffeL, 0x3ff7fffL, 0x3bffecaefef02596L, 0x33ff3f5fL -}; -static final long[] jjbitVec55 = { - 0xc2a003ff03000001L, 0xfffe07fffffffeffL, 0x1ffffffffeff0fdfL, 0x40L -}; -static final long[] jjbitVec56 = { - 0x3c7f6fbffffffffL, 0x3ff03ffL, 0xffffffff00000000L, 0x1ffffffffff003fL -}; -static final long[] jjbitVec57 = { - 0xffffffff7f3d7fffL, 0x3fe0007ffff7fL, 0xffffffff00000000L, 0x1fffffffffffffL -}; -static final long[] jjbitVec58 = { - 0x1fffff001fdfffL, 0xddfff000fffffL, 0xffffffffffffffffL, 0x3ff388fffffL -}; -static final long[] jjbitVec59 = { - 0xffffffff03ff3800L, 0xffffffffffffffL, 0x3ffffffffffL, 0x0L -}; -static final long[] jjbitVec60 = { - 0xfff0fff1fffffffL, 0x1f3fffffffffc0L, 0x0L, 0x0L -}; -static final long[] jjbitVec61 = { - 0x80007c000000f000L, 0x8002fc0f00100001L, 0x3ffff00000000L, 0x7e21fff0000L -}; -static final long[] jjbitVec62 = { - 0x1f3efffe000000e0L, 0xfffffffffffffffeL, 0xfffffffee67fffffL, 0xffffffffffffffffL -}; -static final long[] jjbitVec63 = { - 0x10000000000006L, 0x0L, 0x0L, 0x0L -}; -static final long[] jjbitVec64 = { - 0x3L, 0x0L, 0x0L, 0x0L -}; -static final long[] jjbitVec65 = { - 0x0L, 0x800000000000000L, 0x0L, 0x0L -}; -static final long[] jjbitVec66 = { - 0x5f7ffdffe0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L -}; -static final long[] jjbitVec67 = { - 0x18000f0000ffffL, 0xffdf02000000e000L, 0xffffffffffffffffL, 0x9fffffffffffffffL -}; -static final long[] jjbitVec68 = { - 0x87fffffe03ff0010L, 0xffffffe007fffffeL, 0x7fffffffffffffffL, 0xe0000631cfcfcfcL -}; -private int jjMoveNfa_0(int startState, int curPos) -{ - int startsAt = 0; - jjnewStateCnt = 130; - int i = 1; - jjstateSet[0] = startState; - int kind = 0x7fffffff; - for (;;) - { - if (++jjround == 0x7fffffff) - ReInitRounds(); - if (curChar < 64) - { - long l = 1L << curChar; - do - { - switch(jjstateSet[--i]) - { - case 45: - if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 50; - else if (curChar == 47) - { - if (kind > 6) - kind = 6; - jjCheckNAddStates(0, 2); - } - break; - case 0: - if ((0x3ff000000000000L & l) != 0L) - { - if (kind > 66) - kind = 66; - jjCheckNAddStates(3, 17); - } - else if (curChar == 47) - jjAddStates(18, 19); - else if (curChar == 36) - { - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - } - else if (curChar == 34) - jjCheckNAddStates(20, 23); - else if (curChar == 39) - jjAddStates(24, 26); - else if (curChar == 46) - jjCheckNAdd(1); - if (curChar == 48) - jjAddStates(27, 34); - break; - case 1: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(35, 38); - break; - case 2: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(2, 3); - break; - case 3: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(39, 41); - break; - case 5: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(6); - break; - case 6: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(42, 44); - break; - case 7: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(7, 8); - break; - case 8: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddTwoStates(6, 9); - break; - case 10: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(45, 48); - break; - case 11: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(49, 53); - break; - case 12: - if (curChar == 39) - jjAddStates(24, 26); - break; - case 13: - if ((0xffffff7fffffdbffL & l) != 0L) - jjCheckNAdd(14); - break; - case 14: - if (curChar == 39 && kind > 76) - kind = 76; - break; - case 16: - if ((0x8400000000L & l) != 0L) - jjCheckNAdd(14); - break; - case 17: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddTwoStates(18, 14); - break; - case 18: - if ((0xff000000000000L & l) != 0L) - jjCheckNAdd(14); - break; - case 19: - if ((0xf000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 20; - break; - case 20: - if ((0xff000000000000L & l) != 0L) - jjCheckNAdd(18); - break; - case 22: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 23; - break; - case 23: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 24; - break; - case 24: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 25; - break; - case 25: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAdd(14); - break; - case 27: - if (curChar == 34) - jjCheckNAddStates(20, 23); - break; - case 28: - if ((0xfffffffbffffdbffL & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 30: - if ((0x8400000000L & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 32: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 33; - break; - case 33: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 34; - break; - case 34: - if ((0x3ff000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 35; - break; - case 35: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 37: - if (curChar == 34 && kind > 77) - kind = 77; - break; - case 38: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddStates(54, 58); - break; - case 39: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 40: - if ((0xf000000000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 41; - break; - case 41: - if ((0xff000000000000L & l) != 0L) - jjCheckNAdd(39); - break; - case 42: - if (curChar != 36) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 43: - if ((0x3ff00100fffc1ffL & l) == 0L) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 44: - if (curChar == 47) - jjAddStates(18, 19); - break; - case 46: - if ((0xffffffffffffdbffL & l) == 0L) - break; - if (kind > 6) - kind = 6; - jjCheckNAddStates(0, 2); - break; - case 47: - if ((0x2400L & l) != 0L && kind > 6) - kind = 6; - break; - case 48: - if (curChar == 10 && kind > 6) - kind = 6; - break; - case 49: - if (curChar == 13) - jjstateSet[jjnewStateCnt++] = 48; - break; - case 50: - if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 51; - break; - case 51: - if ((0xffff7fffffffffffL & l) != 0L && kind > 7) - kind = 7; - break; - case 52: - if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 50; - break; - case 53: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 66) - kind = 66; - jjCheckNAddStates(3, 17); - break; - case 54: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(54, 55); - break; - case 55: - case 98: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAdd(56); - break; - case 57: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(57, 58); - break; - case 58: - case 109: - if ((0x3ff000000000000L & l) != 0L && kind > 66) - kind = 66; - break; - case 59: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(59, 60); - break; - case 60: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(59, 61); - break; - case 61: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(62, 65); - break; - case 63: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(64); - break; - case 64: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(66, 68); - break; - case 65: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(65, 66); - break; - case 66: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(64, 9); - break; - case 67: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(69, 72); - break; - case 68: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(73, 77); - break; - case 69: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(69, 70); - break; - case 70: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(71, 72); - break; - case 71: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(78, 80); - break; - case 73: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(74); - break; - case 74: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(81, 83); - break; - case 75: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(75, 76); - break; - case 76: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddTwoStates(74, 9); - break; - case 77: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(84, 87); - break; - case 78: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(88, 91); - break; - case 79: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(79, 80); - break; - case 80: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(81, 82); - break; - case 81: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(92, 94); - break; - case 82: - if (curChar != 46) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(95, 97); - break; - case 83: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(98, 101); - break; - case 84: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(84, 85); - break; - case 85: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(95, 97); - break; - case 87: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(88); - break; - case 88: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(102, 104); - break; - case 89: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(89, 90); - break; - case 90: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddTwoStates(88, 9); - break; - case 91: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(105, 108); - break; - case 92: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddStates(109, 113); - break; - case 93: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(114, 117); - break; - case 94: - if (curChar == 48) - jjAddStates(27, 34); - break; - case 96: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(118, 120); - break; - case 97: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(97, 98); - break; - case 99: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddStates(121, 123); - break; - case 100: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddTwoStates(100, 101); - break; - case 101: - if ((0xff000000000000L & l) != 0L) - jjCheckNAdd(56); - break; - case 103: - if ((0x3000000000000L & l) != 0L) - jjCheckNAddStates(124, 126); - break; - case 104: - if ((0x3000000000000L & l) != 0L) - jjCheckNAddTwoStates(104, 105); - break; - case 105: - if ((0x3000000000000L & l) != 0L) - jjCheckNAdd(56); - break; - case 107: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 66) - kind = 66; - jjCheckNAddTwoStates(108, 109); - break; - case 108: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(108, 109); - break; - case 110: - if ((0xff000000000000L & l) == 0L) - break; - if (kind > 66) - kind = 66; - jjCheckNAddTwoStates(111, 112); - break; - case 111: - if ((0xff000000000000L & l) != 0L) - jjCheckNAddTwoStates(111, 112); - break; - case 112: - if ((0xff000000000000L & l) != 0L && kind > 66) - kind = 66; - break; - case 114: - if ((0x3000000000000L & l) == 0L) - break; - if (kind > 66) - kind = 66; - jjCheckNAddTwoStates(115, 116); - break; - case 115: - if ((0x3000000000000L & l) != 0L) - jjCheckNAddTwoStates(115, 116); - break; - case 116: - if ((0x3000000000000L & l) != 0L && kind > 66) - kind = 66; - break; - case 118: - if ((0x3ff000000000000L & l) != 0L) - jjAddStates(127, 128); - break; - case 119: - if (curChar == 46) - jjCheckNAdd(120); - break; - case 120: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(120, 121); - break; - case 122: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(123); - break; - case 123: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddTwoStates(123, 9); - break; - case 125: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddStates(129, 131); - break; - case 126: - if (curChar == 46) - jjCheckNAdd(127); - break; - case 128: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(129); - break; - case 129: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 71) - kind = 71; - jjCheckNAddTwoStates(129, 9); - break; - default : break; - } - } while(i != startsAt); - } - else if (curChar < 128) - { - long l = 1L << (curChar & 077); - do - { - switch(jjstateSet[--i]) - { - case 0: - if ((0x7fffffe87fffffeL & l) == 0L) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 2: - if (curChar == 95) - jjAddStates(132, 133); - break; - case 4: - if ((0x2000000020L & l) != 0L) - jjAddStates(134, 135); - break; - case 7: - if (curChar == 95) - jjAddStates(136, 137); - break; - case 9: - if ((0x5000000050L & l) != 0L && kind > 71) - kind = 71; - break; - case 13: - if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAdd(14); - break; - case 15: - if (curChar == 92) - jjAddStates(138, 140); - break; - case 16: - if ((0x14404410000000L & l) != 0L) - jjCheckNAdd(14); - break; - case 21: - if (curChar == 117) - jjstateSet[jjnewStateCnt++] = 22; - break; - case 22: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 23; - break; - case 23: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 24; - break; - case 24: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 25; - break; - case 25: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAdd(14); - break; - case 26: - if (curChar == 92) - jjstateSet[jjnewStateCnt++] = 21; - break; - case 28: - if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 29: - if (curChar == 92) - jjAddStates(141, 143); - break; - case 30: - if ((0x14404410000000L & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 31: - if (curChar == 117) - jjstateSet[jjnewStateCnt++] = 32; - break; - case 32: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 33; - break; - case 33: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 34; - break; - case 34: - if ((0x7e0000007eL & l) != 0L) - jjstateSet[jjnewStateCnt++] = 35; - break; - case 35: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAddStates(20, 23); - break; - case 36: - if (curChar == 92) - jjstateSet[jjnewStateCnt++] = 31; - break; - case 43: - if ((0x87fffffe87fffffeL & l) == 0L) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 46: - if (kind > 6) - kind = 6; - jjAddStates(0, 2); - break; - case 51: - if (kind > 7) - kind = 7; - break; - case 54: - if (curChar == 95) - jjAddStates(144, 145); - break; - case 56: - if ((0x100000001000L & l) != 0L && kind > 65) - kind = 65; - break; - case 57: - if (curChar == 95) - jjAddStates(146, 147); - break; - case 59: - if (curChar == 95) - jjAddStates(148, 149); - break; - case 62: - if ((0x2000000020L & l) != 0L) - jjAddStates(150, 151); - break; - case 65: - if (curChar == 95) - jjAddStates(152, 153); - break; - case 69: - if (curChar == 95) - jjAddStates(154, 155); - break; - case 72: - if ((0x2000000020L & l) != 0L) - jjAddStates(156, 157); - break; - case 75: - if (curChar == 95) - jjAddStates(158, 159); - break; - case 79: - if (curChar == 95) - jjAddStates(160, 161); - break; - case 84: - if (curChar == 95) - jjAddStates(162, 163); - break; - case 86: - if ((0x2000000020L & l) != 0L) - jjAddStates(164, 165); - break; - case 89: - if (curChar == 95) - jjAddStates(166, 167); - break; - case 95: - if ((0x100000001000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 96; - break; - case 96: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAddStates(118, 120); - break; - case 97: - if ((0x7e8000007eL & l) != 0L) - jjCheckNAddTwoStates(97, 98); - break; - case 98: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAdd(56); - break; - case 100: - if (curChar == 95) - jjAddStates(168, 169); - break; - case 102: - if ((0x400000004L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 103; - break; - case 104: - if (curChar == 95) - jjAddStates(170, 171); - break; - case 106: - if ((0x100000001000000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 107; - break; - case 107: - if ((0x7e0000007eL & l) == 0L) - break; - if (kind > 66) - kind = 66; - jjCheckNAddTwoStates(108, 109); - break; - case 108: - if ((0x7e8000007eL & l) != 0L) - jjCheckNAddTwoStates(108, 109); - break; - case 109: - if ((0x7e0000007eL & l) != 0L && kind > 66) - kind = 66; - break; - case 111: - if (curChar == 95) - jjAddStates(172, 173); - break; - case 113: - if ((0x400000004L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 114; - break; - case 115: - if (curChar == 95) - jjAddStates(174, 175); - break; - case 117: - if ((0x100000001000000L & l) != 0L) - jjCheckNAddTwoStates(118, 119); - break; - case 118: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAddTwoStates(118, 119); - break; - case 120: - if ((0x7e0000007eL & l) != 0L) - jjAddStates(176, 177); - break; - case 121: - if ((0x1000000010000L & l) != 0L) - jjAddStates(178, 179); - break; - case 124: - if ((0x100000001000000L & l) != 0L) - jjCheckNAdd(125); - break; - case 125: - if ((0x7e0000007eL & l) != 0L) - jjCheckNAddStates(129, 131); - break; - case 127: - if ((0x1000000010000L & l) != 0L) - jjAddStates(180, 181); - break; - default : break; - } - } while(i != startsAt); - } - else - { - int hiByte = (int)(curChar >> 8); - int i1 = hiByte >> 6; - long l1 = 1L << (hiByte & 077); - int i2 = (curChar & 0xff) >> 6; - long l2 = 1L << (curChar & 077); - do - { - switch(jjstateSet[--i]) - { - case 0: - if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 13: - if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjstateSet[jjnewStateCnt++] = 14; - break; - case 28: - if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjAddStates(20, 23); - break; - case 43: - if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) - break; - if (kind > 78) - kind = 78; - jjCheckNAdd(43); - break; - case 46: - if (!jjCanMove_0(hiByte, i1, i2, l1, l2)) - break; - if (kind > 6) - kind = 6; - jjAddStates(0, 2); - break; - case 51: - if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 7) - kind = 7; - break; - default : break; - } - } while(i != startsAt); - } - if (kind != 0x7fffffff) - { - jjmatchedKind = kind; - jjmatchedPos = curPos; - kind = 0x7fffffff; - } - ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 130 - (jjnewStateCnt = startsAt))) - return curPos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return curPos; } - } -} -private int jjMoveStringLiteralDfa0_2() -{ - switch(curChar) - { - case 42: - return jjMoveStringLiteralDfa1_2(0x400L); - default : - return 1; - } -} -private int jjMoveStringLiteralDfa1_2(long active0) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - return 1; - } - switch(curChar) - { - case 47: - if ((active0 & 0x400L) != 0L) - return jjStopAtPos(1, 10); - break; - default : - return 2; - } - return 2; -} -private int jjMoveStringLiteralDfa0_1() -{ - switch(curChar) - { - case 42: - return jjMoveStringLiteralDfa1_1(0x200L); - default : - return 1; - } -} -private int jjMoveStringLiteralDfa1_1(long active0) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - return 1; - } - switch(curChar) - { - case 47: - if ((active0 & 0x200L) != 0L) - return jjStopAtPos(1, 9); - break; - default : - return 2; - } - return 2; -} -static final int[] jjnextStates = { - 46, 47, 49, 54, 55, 56, 57, 58, 59, 62, 9, 69, 72, 79, 82, 93, - 78, 68, 45, 52, 28, 29, 36, 37, 13, 15, 26, 95, 99, 102, 106, 110, - 113, 117, 124, 2, 4, 9, 11, 1, 4, 9, 7, 9, 10, 6, 7, 9, - 10, 1, 2, 4, 9, 11, 28, 29, 39, 36, 37, 61, 62, 9, 59, 62, - 9, 68, 65, 9, 67, 64, 65, 9, 67, 61, 59, 62, 9, 68, 69, 72, - 78, 75, 9, 77, 74, 75, 9, 77, 71, 69, 72, 78, 79, 82, 93, 83, - 86, 9, 84, 86, 9, 92, 89, 9, 91, 88, 89, 9, 91, 83, 84, 86, - 9, 92, 81, 79, 82, 93, 97, 98, 56, 100, 101, 56, 104, 105, 56, 118, - 119, 125, 126, 127, 2, 3, 5, 6, 7, 8, 16, 17, 19, 30, 38, 40, - 54, 55, 57, 58, 59, 60, 63, 64, 65, 66, 69, 70, 73, 74, 75, 76, - 79, 80, 84, 85, 87, 88, 89, 90, 100, 101, 104, 105, 111, 112, 115, 116, - 120, 121, 122, 123, 128, 129, -}; -private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) -{ - switch(hiByte) - { - case 0: - return ((jjbitVec2[i2] & l2) != 0L); - default : - if ((jjbitVec0[i1] & l1) != 0L) - return true; - return false; - } -} -private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) -{ - switch(hiByte) - { - case 0: - return ((jjbitVec4[i2] & l2) != 0L); - case 2: - return ((jjbitVec5[i2] & l2) != 0L); - case 3: - return ((jjbitVec6[i2] & l2) != 0L); - case 4: - return ((jjbitVec7[i2] & l2) != 0L); - case 5: - return ((jjbitVec8[i2] & l2) != 0L); - case 6: - return ((jjbitVec9[i2] & l2) != 0L); - case 7: - return ((jjbitVec10[i2] & l2) != 0L); - case 9: - return ((jjbitVec11[i2] & l2) != 0L); - case 10: - return ((jjbitVec12[i2] & l2) != 0L); - case 11: - return ((jjbitVec13[i2] & l2) != 0L); - case 12: - return ((jjbitVec14[i2] & l2) != 0L); - case 13: - return ((jjbitVec15[i2] & l2) != 0L); - case 14: - return ((jjbitVec16[i2] & l2) != 0L); - case 15: - return ((jjbitVec17[i2] & l2) != 0L); - case 16: - return ((jjbitVec18[i2] & l2) != 0L); - case 17: - return ((jjbitVec19[i2] & l2) != 0L); - case 18: - return ((jjbitVec20[i2] & l2) != 0L); - case 19: - return ((jjbitVec21[i2] & l2) != 0L); - case 20: - return ((jjbitVec0[i2] & l2) != 0L); - case 22: - return ((jjbitVec22[i2] & l2) != 0L); - case 23: - return ((jjbitVec23[i2] & l2) != 0L); - case 24: - return ((jjbitVec24[i2] & l2) != 0L); - case 25: - return ((jjbitVec25[i2] & l2) != 0L); - case 29: - return ((jjbitVec26[i2] & l2) != 0L); - case 30: - return ((jjbitVec27[i2] & l2) != 0L); - case 31: - return ((jjbitVec28[i2] & l2) != 0L); - case 32: - return ((jjbitVec29[i2] & l2) != 0L); - case 33: - return ((jjbitVec30[i2] & l2) != 0L); - case 48: - return ((jjbitVec31[i2] & l2) != 0L); - case 49: - return ((jjbitVec32[i2] & l2) != 0L); - case 77: - return ((jjbitVec33[i2] & l2) != 0L); - case 159: - return ((jjbitVec34[i2] & l2) != 0L); - case 164: - return ((jjbitVec35[i2] & l2) != 0L); - case 215: - return ((jjbitVec36[i2] & l2) != 0L); - case 216: - return ((jjbitVec37[i2] & l2) != 0L); - case 250: - return ((jjbitVec38[i2] & l2) != 0L); - case 251: - return ((jjbitVec39[i2] & l2) != 0L); - case 253: - return ((jjbitVec40[i2] & l2) != 0L); - case 254: - return ((jjbitVec41[i2] & l2) != 0L); - case 255: - return ((jjbitVec42[i2] & l2) != 0L); - default : - if ((jjbitVec3[i1] & l1) != 0L) - return true; - return false; - } -} -private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, long l2) -{ - switch(hiByte) - { - case 0: - return ((jjbitVec43[i2] & l2) != 0L); - case 2: - return ((jjbitVec5[i2] & l2) != 0L); - case 3: - return ((jjbitVec44[i2] & l2) != 0L); - case 4: - return ((jjbitVec45[i2] & l2) != 0L); - case 5: - return ((jjbitVec46[i2] & l2) != 0L); - case 6: - return ((jjbitVec47[i2] & l2) != 0L); - case 7: - return ((jjbitVec48[i2] & l2) != 0L); - case 9: - return ((jjbitVec49[i2] & l2) != 0L); - case 10: - return ((jjbitVec50[i2] & l2) != 0L); - case 11: - return ((jjbitVec51[i2] & l2) != 0L); - case 12: - return ((jjbitVec52[i2] & l2) != 0L); - case 13: - return ((jjbitVec53[i2] & l2) != 0L); - case 14: - return ((jjbitVec54[i2] & l2) != 0L); - case 15: - return ((jjbitVec55[i2] & l2) != 0L); - case 16: - return ((jjbitVec56[i2] & l2) != 0L); - case 17: - return ((jjbitVec19[i2] & l2) != 0L); - case 18: - return ((jjbitVec20[i2] & l2) != 0L); - case 19: - return ((jjbitVec57[i2] & l2) != 0L); - case 20: - return ((jjbitVec0[i2] & l2) != 0L); - case 22: - return ((jjbitVec22[i2] & l2) != 0L); - case 23: - return ((jjbitVec58[i2] & l2) != 0L); - case 24: - return ((jjbitVec59[i2] & l2) != 0L); - case 25: - return ((jjbitVec60[i2] & l2) != 0L); - case 29: - return ((jjbitVec26[i2] & l2) != 0L); - case 30: - return ((jjbitVec27[i2] & l2) != 0L); - case 31: - return ((jjbitVec28[i2] & l2) != 0L); - case 32: - return ((jjbitVec61[i2] & l2) != 0L); - case 33: - return ((jjbitVec30[i2] & l2) != 0L); - case 48: - return ((jjbitVec62[i2] & l2) != 0L); - case 49: - return ((jjbitVec32[i2] & l2) != 0L); - case 77: - return ((jjbitVec33[i2] & l2) != 0L); - case 159: - return ((jjbitVec34[i2] & l2) != 0L); - case 164: - return ((jjbitVec35[i2] & l2) != 0L); - case 215: - return ((jjbitVec36[i2] & l2) != 0L); - case 216: - return ((jjbitVec63[i2] & l2) != 0L); - case 220: - return ((jjbitVec64[i2] & l2) != 0L); - case 221: - return ((jjbitVec65[i2] & l2) != 0L); - case 250: - return ((jjbitVec38[i2] & l2) != 0L); - case 251: - return ((jjbitVec66[i2] & l2) != 0L); - case 253: - return ((jjbitVec40[i2] & l2) != 0L); - case 254: - return ((jjbitVec67[i2] & l2) != 0L); - case 255: - return ((jjbitVec68[i2] & l2) != 0L); - default : - if ((jjbitVec3[i1] & l1) != 0L) - return true; - return false; - } -} - -/** Token literal values. */ -public static final String[] jjstrLiteralImages = { -"", null, null, null, null, null, null, null, null, null, null, null, -"\141\142\163\164\162\141\143\164", "\141\163\163\145\162\164", "\142\157\157\154\145\141\156", -"\142\162\145\141\153", "\142\171\164\145", "\143\141\163\145", "\143\141\164\143\150", -"\143\150\141\162", "\143\154\141\163\163", "\143\157\156\163\164", -"\143\157\156\164\151\156\165\145", "\144\145\146\141\165\154\164", "\144\157", "\144\157\165\142\154\145", -"\145\154\163\145", "\145\156\165\155", "\145\170\164\145\156\144\163", "\146\141\154\163\145", -"\146\151\156\141\154", "\146\151\156\141\154\154\171", "\146\154\157\141\164", "\146\157\162", -"\147\157\164\157", "\151\146", "\151\155\160\154\145\155\145\156\164\163", -"\151\155\160\157\162\164", "\151\156\163\164\141\156\143\145\157\146", "\151\156\164", -"\151\156\164\145\162\146\141\143\145", "\154\157\156\147", "\156\141\164\151\166\145", "\156\145\167", -"\156\165\154\154", "\160\141\143\153\141\147\145", "\160\162\151\166\141\164\145", -"\160\162\157\164\145\143\164\145\144", "\160\165\142\154\151\143", "\162\145\164\165\162\156", -"\163\150\157\162\164", "\163\164\141\164\151\143", "\163\164\162\151\143\164\146\160", -"\163\165\160\145\162", "\163\167\151\164\143\150", -"\163\171\156\143\150\162\157\156\151\172\145\144", "\164\150\151\163", "\164\150\162\157\167", "\164\150\162\157\167\163", -"\164\162\141\156\163\151\145\156\164", "\164\162\165\145", "\164\162\171", "\166\157\151\144", -"\166\157\154\141\164\151\154\145", "\167\150\151\154\145", null, null, null, null, null, null, null, null, null, -null, null, null, null, null, null, null, "\50", "\51", "\173", "\175", "\133", -"\135", "\73", "\54", "\56", "\100", "\75", "\74", "\41", "\176", "\77", "\72", -"\75\75", "\74\75", "\76\75", "\41\75", "\174\174", "\46\46", "\53\53", "\55\55", "\53", -"\55", "\52", "\57", "\46", "\174", "\136", "\45", "\74\74", "\53\75", "\55\75", -"\52\75", "\57\75", "\46\75", "\174\75", "\136\75", "\45\75", "\74\74\75", "\76\76\75", -"\76\76\76\75", "\56\56\56", "\55\76", "\72\72", "\76\76\76", "\76\76", "\76", "\32", -"\74\76", }; - -/** Lexer state names. */ -public static final String[] lexStateNames = { - "DEFAULT", - "IN_JAVA_DOC_COMMENT", - "IN_MULTI_LINE_COMMENT", -}; - -/** Lex State array. */ -public static final int[] jjnewLexState = { - -1, -1, -1, -1, -1, -1, -1, 1, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -}; -static final long[] jjtoToken = { - 0xfffffffffffff001L, 0xfffffffffffe7087L, 0x1fL, -}; -static final long[] jjtoSkip = { - 0x67eL, 0x0L, 0x0L, -}; -static final long[] jjtoSpecial = { - 0x640L, 0x0L, 0x0L, -}; -static final long[] jjtoMore = { - 0x980L, 0x0L, 0x0L, -}; -protected JavaCharStream input_stream; -private final int[] jjrounds = new int[130]; -private final int[] jjstateSet = new int[260]; -private final StringBuilder jjimage = new StringBuilder(); -private StringBuilder image = jjimage; -private int jjimageLen; -private int lengthOfMatch; -protected char curChar; -/** Constructor. */ -public ASTParserTokenManager(JavaCharStream stream){ - if (JavaCharStream.staticFlag) - throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); - input_stream = stream; -} - -/** Constructor. */ -public ASTParserTokenManager(JavaCharStream stream, int lexState){ - this(stream); - SwitchTo(lexState); -} - -/** Reinitialise parser. */ -public void ReInit(JavaCharStream stream) -{ - jjmatchedPos = jjnewStateCnt = 0; - curLexState = defaultLexState; - input_stream = stream; - ReInitRounds(); -} -private void ReInitRounds() -{ - int i; - jjround = 0x80000001; - for (i = 130; i-- > 0;) - jjrounds[i] = 0x80000000; -} - -/** Reinitialise parser. */ -public void ReInit(JavaCharStream stream, int lexState) -{ - ReInit(stream); - SwitchTo(lexState); -} - -/** Switch to specified lex state. */ -public void SwitchTo(int lexState) -{ - if (lexState >= 3 || lexState < 0) - throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); - else - curLexState = lexState; -} - -protected Token jjFillToken() -{ - final Token t; - final String curTokenImage; - final int beginLine; - final int endLine; - final int beginColumn; - final int endColumn; - String im = jjstrLiteralImages[jjmatchedKind]; - curTokenImage = (im == null) ? input_stream.GetImage() : im; - beginLine = input_stream.getBeginLine(); - beginColumn = input_stream.getBeginColumn(); - endLine = input_stream.getEndLine(); - endColumn = input_stream.getEndColumn(); - t = ASTParser.GTToken.newToken(jjmatchedKind, curTokenImage); - - t.beginLine = beginLine; - t.endLine = endLine; - t.beginColumn = beginColumn; - t.endColumn = endColumn; - - return t; -} - -int curLexState = 0; -int defaultLexState = 0; -int jjnewStateCnt; -int jjround; -int jjmatchedPos; -int jjmatchedKind; - -/** Get the next Token. */ -public Token getNextToken() -{ - Token specialToken = null; - Token matchedToken; - int curPos = 0; - - EOFLoop : - for (;;) - { - try - { - curChar = input_stream.BeginToken(); - } - catch(java.io.IOException e) - { - jjmatchedKind = 0; - matchedToken = jjFillToken(); - matchedToken.specialToken = specialToken; - return matchedToken; - } - image = jjimage; - image.setLength(0); - jjimageLen = 0; - - for (;;) - { - switch(curLexState) - { - case 0: - try { input_stream.backup(0); - while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L) - curChar = input_stream.BeginToken(); - } - catch (java.io.IOException e1) { continue EOFLoop; } - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_0(); - break; - case 1: - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_1(); - if (jjmatchedPos == 0 && jjmatchedKind > 11) - { - jjmatchedKind = 11; - } - break; - case 2: - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_2(); - if (jjmatchedPos == 0 && jjmatchedKind > 11) - { - jjmatchedKind = 11; - } - break; - } - if (jjmatchedKind != 0x7fffffff) - { - if (jjmatchedPos + 1 < curPos) - input_stream.backup(curPos - jjmatchedPos - 1); - if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - matchedToken = jjFillToken(); - matchedToken.specialToken = specialToken; - TokenLexicalActions(matchedToken); - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - return matchedToken; - } - else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - matchedToken = jjFillToken(); - if (specialToken == null) - specialToken = matchedToken; - else - { - matchedToken.specialToken = specialToken; - specialToken = (specialToken.next = matchedToken); - } - SkipLexicalActions(matchedToken); - } - else - SkipLexicalActions(null); - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - continue EOFLoop; - } - MoreLexicalActions(); - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - curPos = 0; - jjmatchedKind = 0x7fffffff; - try { - curChar = input_stream.readChar(); - continue; - } - catch (java.io.IOException e1) { } - } - int error_line = input_stream.getEndLine(); - int error_column = input_stream.getEndColumn(); - String error_after = null; - boolean EOFSeen = false; - try { input_stream.readChar(); input_stream.backup(1); } - catch (java.io.IOException e1) { - EOFSeen = true; - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - if (curChar == '\n' || curChar == '\r') { - error_line++; - error_column = 0; - } - else - error_column++; - } - if (!EOFSeen) { - input_stream.backup(1); - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - } - throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); - } - } -} - -void SkipLexicalActions(Token matchedToken) -{ - switch(jjmatchedKind) - { - default : - break; - } -} -void MoreLexicalActions() -{ - jjimageLen += (lengthOfMatch = jjmatchedPos + 1); - switch(jjmatchedKind) - { - case 7 : - image.append(input_stream.GetSuffix(jjimageLen)); - jjimageLen = 0; - input_stream.backup(1); - break; - default : - break; - } -} -void TokenLexicalActions(Token matchedToken) -{ - switch(jjmatchedKind) - { - case 128 : - image.append(jjstrLiteralImages[128]); - lengthOfMatch = jjstrLiteralImages[128].length(); - matchedToken.kind = GT; - ((ASTParser.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT; - input_stream.backup(2); - break; - case 129 : - image.append(jjstrLiteralImages[129]); - lengthOfMatch = jjstrLiteralImages[129].length(); - matchedToken.kind = GT; - ((ASTParser.GTToken)matchedToken).realKind = RSIGNEDSHIFT; - input_stream.backup(1); - break; - default : - break; - } -} -private void jjCheckNAdd(int state) -{ - if (jjrounds[state] != jjround) - { - jjstateSet[jjnewStateCnt++] = state; - jjrounds[state] = jjround; - } -} -private void jjAddStates(int start, int end) -{ - do { - jjstateSet[jjnewStateCnt++] = jjnextStates[start]; - } while (start++ != end); -} -private void jjCheckNAddTwoStates(int state1, int state2) -{ - jjCheckNAdd(state1); - jjCheckNAdd(state2); -} - -private void jjCheckNAddStates(int start, int end) -{ - do { - jjCheckNAdd(jjnextStates[start]); - } while (start++ != end); -} - -} diff --git a/JavaParser/src/com/github/javaparser/CommentsInserter.java b/JavaParser/src/com/github/javaparser/CommentsInserter.java new file mode 100644 index 0000000..869883c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/CommentsInserter.java @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.utils.PositionUtils; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; + +/** + * Assigns comments to nodes of the AST. + * + * @author Sebastian Kuerten + * @author Júlio Vilmar Gesser + */ +class CommentsInserter { + private final ParserConfiguration configuration; + + CommentsInserter(ParserConfiguration configuration) { + this.configuration = configuration; + } + + /** + * Comments are attributed to the thing they comment and are removed from + * the comments. + */ + private void insertComments(CompilationUnit cu, TreeSet comments) { + if (comments.isEmpty()) + return; + + /* I should sort all the direct children and the comments, if a comment + is the first thing then it + a comment to the CompilationUnit */ + + // FIXME if there is no package it could be also a comment to the following class... + // so I could use some heuristics in these cases to distinguish the two + // cases + + List children = cu.getChildNodes(); + + Comment firstComment = comments.iterator().next(); + if (cu.getPackageDeclaration().isPresent() + && (children.isEmpty() || PositionUtils.areInOrder( + firstComment, cu.getPackageDeclaration().get()))) { + cu.setComment(firstComment); + comments.remove(firstComment); + } + } + + /** + * This method try to attributes the nodes received to child of the node. It + * returns the node that were not attributed. + */ + void insertComments(Node node, TreeSet commentsToAttribute) { + if (commentsToAttribute.isEmpty()) + return; + + if (node instanceof CompilationUnit) { + insertComments((CompilationUnit) node, commentsToAttribute); + } + + // the comments can: + // 1) Inside one of the child, then it is the child that have to + // associate them + // 2) If they are not inside a child they could be preceeding nothing, a + // comment or a child + // if they preceed a child they are assigned to it, otherweise they + // remain "orphans" + + List children = node.getChildNodes(); + + for (Node child : children) { + TreeSet commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION); + commentsInsideChild.addAll( + commentsToAttribute.stream() + .filter(c -> c.getRange().isPresent()) + .filter(c -> PositionUtils.nodeContains(child, c, + configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution())).collect(Collectors.toList())); + commentsToAttribute.removeAll(commentsInsideChild); + insertComments(child, commentsInsideChild); + } + + attributeLineCommentsOnSameLine(commentsToAttribute, children); + + /* at this point I create an ordered list of all remaining comments and + children */ + Comment previousComment = null; + final List attributedComments = new LinkedList<>(); + List childrenAndComments = new LinkedList<>(); + // Avoid attributing comments to a meaningless container. + childrenAndComments.addAll(children); + commentsToAttribute.removeAll(attributedComments); + + childrenAndComments.addAll(commentsToAttribute); + PositionUtils.sortByBeginPosition(childrenAndComments, + configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution()); + + for (Node thing : childrenAndComments) { + if (thing instanceof Comment) { + previousComment = (Comment) thing; + if (!previousComment.isOrphan()) { + previousComment = null; + } + } else { + if (previousComment != null && !thing.getComment().isPresent()) { + if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() + || !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 void attributeLineCommentsOnSameLine(TreeSet commentsToAttribute, List children) { + /* I can attribute in line comments to elements preceeding them, if + there is something contained in their line */ + List attributedComments = new LinkedList<>(); + commentsToAttribute.stream() + .filter(comment -> comment.getRange().isPresent()) + .filter(Comment::isLineComment) + .forEach(comment -> children.stream() + .filter(child -> child.getRange().isPresent()) + .forEach(child -> { + Range commentRange = comment.getRange().get(); + Range childRange = child.getRange().get(); + if (childRange.end.line == commentRange.begin.line + && attributeLineCommentToNodeOrChild(child, + comment.asLineComment())) { + attributedComments.add(comment); + } + })); + commentsToAttribute.removeAll(attributedComments); + } + + private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineComment) { + if (!node.getRange().isPresent() || !lineComment.getRange().isPresent()) { + return false; + } + + // The node start and end at the same line as the comment, + // let's give to it the comment + if (node.getBegin().get().line == lineComment.getBegin().get().line + && !node.getComment().isPresent()) { + 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 children = new LinkedList<>(); + children.addAll(node.getChildNodes()); + 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 (!a.getRange().isPresent() || !b.getRange().isPresent()) { + return true; + } + if (!PositionUtils.areInOrder(a, b)) { + return thereAreLinesBetween(b, a); + } + int endOfA = a.getEnd().get().line; + return b.getBegin().get().line > endOfA + 1; + } + +} diff --git a/JavaParser/src/com/github/javaparser/GeneratedJavaParser.java b/JavaParser/src/com/github/javaparser/GeneratedJavaParser.java new file mode 100644 index 0000000..88d8068 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/GeneratedJavaParser.java @@ -0,0 +1,10387 @@ +/* GeneratedJavaParser.java */ +/* Generated By:JavaCC: Do not edit this line. GeneratedJavaParser.java */ +/* + * 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 java.util.*; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import com.github.javaparser.utils.*; +import javax.annotation.Generated; +import static com.github.javaparser.JavaToken.INVALID; +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.Utils.*; +import static com.github.javaparser.ast.NodeList.*; +import static com.github.javaparser.GeneratedJavaParser.*; +import static com.github.javaparser.Range.*; +import static com.github.javaparser.Position.*; +import static com.github.javaparser.ast.type.ArrayType.*; +import static com.github.javaparser.GeneratedJavaParserTokenManagerBase.*; + +@Generated("JavaCC") +final class GeneratedJavaParser extends GeneratedJavaParserBase implements GeneratedJavaParserConstants { + /* Returns the JavaParser specific token type of the last matched token */ + JavaToken token() { + return token.javaToken; + } + + /* Changes the amount by which the horizontal position is increased when a tab character is encountered. + One by default.*/ + void setTabSize(int size) { + jj_input_stream.setTabSize(size); + } + + @Override + GeneratedJavaParserTokenManager getTokenSource() { + return token_source; + } + +/***************************************** + * THE JAVA LANGUAGE GRAMMAR STARTS HERE * + *****************************************/ + +/* + * Program structuring syntax follows. + */ + final public +CompilationUnit CompilationUnit() throws ParseException {PackageDeclaration pakage = null; + NodeList imports = emptyList(); + ImportDeclaration in = null; + NodeList> types = emptyList(); + ModifierHolder modifier; + TypeDeclaration tn = null; + ModuleDeclaration module = null; + try { + label_1: + while (true) { + if (jj_2_1(2)) { + ; + } else { + break label_1; + } + jj_consume_token(SEMICOLON); + } + if (jj_2_2(2147483647)) { + pakage = PackageDeclaration(); + } else { + ; + } + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case CLASS: + case _DEFAULT: + case ENUM: + case FINAL: + case IMPORT: + case INTERFACE: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case OPEN: + case MODULE: + case TRANSITIVE: + case SEMICOLON: + case AT:{ + ; + break; + } + default: + jj_la1[0] = jj_gen; + break label_2; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case IMPORT:{ + in = ImportDeclaration(); +imports = add(imports, in); + break; + } + case ABSTRACT: + case CLASS: + case _DEFAULT: + case ENUM: + case FINAL: + case INTERFACE: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case OPEN: + case MODULE: + case TRANSITIVE: + case SEMICOLON: + case AT:{ + modifier = Modifiers(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS: + case INTERFACE:{ + tn = ClassOrInterfaceDeclaration(modifier); +types = add(types, tn); + break; + } + case ENUM:{ + tn = EnumDeclaration(modifier); +types = add(types, tn); + break; + } + case AT:{ + tn = AnnotationTypeDeclaration(modifier); +types = add(types, tn); + break; + } + case OPEN: + case MODULE:{ + module = ModuleDeclaration(modifier); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 0:{ + jj_consume_token(0); + break; + } + case CTRL_Z:{ + jj_consume_token(CTRL_Z); + break; + } + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module); + } catch (ParseException e) { +recover(EOF, e); + final CompilationUnit compilationUnit = new CompilationUnit(range(token_source.getHomeToken(), token()), null, new NodeList(), new NodeList>(), null); + compilationUnit.setParsed(UNPARSABLE); + return compilationUnit; + } +} + + final public PackageDeclaration PackageDeclaration() throws ParseException {NodeList annotations = new NodeList(); + Name name; + JavaToken begin; + annotations = Annotations(); + jj_consume_token(PACKAGE); +begin = token(); + name = Name(); + jj_consume_token(SEMICOLON); +return new PackageDeclaration(range(begin, token()), annotations, name); +} + + final public ImportDeclaration ImportDeclaration() throws ParseException {Name name; + boolean isStatic = false; + boolean isAsterisk = false; + JavaToken begin; + jj_consume_token(IMPORT); +begin = token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case STATIC:{ + jj_consume_token(STATIC); +isStatic = true; + break; + } + default: + jj_la1[4] = jj_gen; + ; + } + name = Name(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case DOT:{ + jj_consume_token(DOT); + jj_consume_token(STAR); +isAsterisk = true; + break; + } + default: + jj_la1[5] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +return new ImportDeclaration(range(begin, token()), name, isStatic, isAsterisk); +} + +/* + * Modifiers. We match all modifiers in a single rule to reduce the chances of + * syntax errors for simple modifier mistakes. It will also enable us to give + * better error messages. + */ + final public +ModifierHolder Modifiers() throws ParseException {JavaToken begin = INVALID; + EnumSet modifiers = EnumSet.noneOf(Modifier.class); + NodeList annotations = new NodeList(); + AnnotationExpr ann; + label_3: + while (true) { + if (jj_2_3(2)) { + ; + } else { + break label_3; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PUBLIC:{ + jj_consume_token(PUBLIC); +addModifier(modifiers, Modifier.PUBLIC); begin = orIfInvalid(begin, token()); + break; + } + case STATIC:{ + jj_consume_token(STATIC); +addModifier(modifiers, Modifier.STATIC); begin = orIfInvalid(begin, token()); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); +addModifier(modifiers, Modifier.PROTECTED); begin = orIfInvalid(begin, token()); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); +addModifier(modifiers, Modifier.PRIVATE); begin = orIfInvalid(begin, token()); + break; + } + case FINAL:{ + jj_consume_token(FINAL); +addModifier(modifiers, Modifier.FINAL); begin = orIfInvalid(begin, token()); + break; + } + case ABSTRACT:{ + jj_consume_token(ABSTRACT); +addModifier(modifiers, Modifier.ABSTRACT); begin = orIfInvalid(begin, token()); + break; + } + case SYNCHRONIZED:{ + jj_consume_token(SYNCHRONIZED); +addModifier(modifiers, Modifier.SYNCHRONIZED); begin = orIfInvalid(begin, token()); + break; + } + case NATIVE:{ + jj_consume_token(NATIVE); +addModifier(modifiers, Modifier.NATIVE); begin = orIfInvalid(begin, token()); + break; + } + case TRANSIENT:{ + jj_consume_token(TRANSIENT); +addModifier(modifiers, Modifier.TRANSIENT); begin = orIfInvalid(begin, token()); + break; + } + case VOLATILE:{ + jj_consume_token(VOLATILE); +addModifier(modifiers, Modifier.VOLATILE); begin = orIfInvalid(begin, token()); + break; + } + case STRICTFP:{ + jj_consume_token(STRICTFP); +addModifier(modifiers, Modifier.STRICTFP); begin = orIfInvalid(begin, token()); + break; + } + case TRANSITIVE:{ + jj_consume_token(TRANSITIVE); +addModifier(modifiers, Modifier.TRANSITIVE); begin = orIfInvalid(begin, token()); + break; + } + case _DEFAULT:{ + jj_consume_token(_DEFAULT); +addModifier(modifiers, Modifier.DEFAULT); begin = orIfInvalid(begin, token()); + break; + } + case AT:{ + ann = Annotation(); +annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); + break; + } + default: + jj_la1[6] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return new ModifierHolder(begin, modifiers, annotations); +} + +/* + * Declaration syntax follows. + */ + final public +ClassOrInterfaceDeclaration ClassOrInterfaceDeclaration(ModifierHolder modifier) throws ParseException {boolean isInterface = false; + SimpleName name; + RangedList typePar = new RangedList(emptyList()); + NodeList extList = emptyList(); + NodeList impList = emptyList(); + NodeList> members = emptyList(); + JavaToken begin = modifier.begin; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS:{ + jj_consume_token(CLASS); + break; + } + case INTERFACE:{ + jj_consume_token(INTERFACE); +isInterface = true; + break; + } + default: + jj_la1[7] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +begin = orIfInvalid(begin, token()); + name = SimpleName(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typePar = TypeParameters(); + break; + } + default: + jj_la1[8] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EXTENDS:{ + extList = ExtendsList(); + break; + } + default: + jj_la1[9] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case IMPLEMENTS:{ + impList = ImplementsList(); + break; + } + default: + jj_la1[10] = jj_gen; + ; + } + members = ClassOrInterfaceBody(); +return new ClassOrInterfaceDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, isInterface, name, typePar.list, extList, impList, members); +} + + final public NodeList ExtendsList() throws ParseException {boolean extendsMoreThanOne = false; + NodeList ret = new NodeList(); + ClassOrInterfaceType cit; + jj_consume_token(EXTENDS); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[11] = jj_gen; + break label_4; + } + jj_consume_token(COMMA); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); extendsMoreThanOne = true; + } +return ret; +} + + final public NodeList ImplementsList() throws ParseException {NodeList ret = new NodeList(); + ClassOrInterfaceType cit; + jj_consume_token(IMPLEMENTS); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[12] = jj_gen; + break label_5; + } + jj_consume_token(COMMA); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); + } +return ret; +} + + final public EnumDeclaration EnumDeclaration(ModifierHolder modifier) throws ParseException {SimpleName name; + NodeList impList = emptyList(); + EnumConstantDeclaration entry; + NodeList entries = emptyList(); + BodyDeclaration member; + NodeList> members = emptyList(); + JavaToken begin = modifier.begin; + jj_consume_token(ENUM); +begin = orIfInvalid(begin, token()); + name = SimpleName(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case IMPLEMENTS:{ + impList = ImplementsList(); + break; + } + default: + jj_la1[13] = jj_gen; + ; + } + jj_consume_token(LBRACE); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT:{ + entry = EnumConstantDeclaration(); +entries.add(entry); + label_6: + while (true) { + if (jj_2_4(2)) { + ; + } else { + break label_6; + } + jj_consume_token(COMMA); + entry = EnumConstantDeclaration(); +entries.add(entry); + } + break; + } + default: + jj_la1[14] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + jj_consume_token(COMMA); + break; + } + default: + jj_la1[15] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + label_7: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case LBRACE: + case SEMICOLON: + case AT: + case LT:{ + ; + break; + } + default: + jj_la1[16] = jj_gen; + break label_7; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case LBRACE: + case AT: + case LT:{ + member = ClassOrInterfaceBodyDeclaration(); +members = add(members, member); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[17] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + break; + } + default: + jj_la1[18] = jj_gen; + ; + } + jj_consume_token(RBRACE); +return new EnumDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, impList, entries, members); +} + + final public EnumConstantDeclaration EnumConstantDeclaration() throws ParseException {NodeList annotations = new NodeList(); + AnnotationExpr ann; + SimpleName name; + NodeList args = emptyList(); + NodeList> classBody = emptyList(); + JavaToken begin = INVALID; + + label_8: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case AT:{ + ; + break; + } + default: + jj_la1[19] = jj_gen; + break label_8; + } + ann = Annotation(); +annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); + } + name = SimpleName(); +begin = orIfInvalid(begin, token()); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN:{ + args = Arguments(); + break; + } + default: + jj_la1[20] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + classBody = ClassOrInterfaceBody(); + break; + } + default: + jj_la1[21] = jj_gen; + ; + } +return new EnumConstantDeclaration(range(begin, token()), annotations, name, args, classBody); +} + +/** + * If the list inside the returned RangedList is null, there are no brackets. + * If it is empty, there are brackets, but nothing is in them <>. + * The normal case is that it contains TypeParameters, like . + */ + final public RangedList TypeParameters() throws ParseException {RangedList ret = new RangedList(new NodeList()); + TypeParameter tp; + NodeList annotations; + jj_consume_token(LT); +ret.beginAt(token()); + annotations = Annotations(); + tp = TypeParameter(annotations); +ret.add(tp); annotations = null; + label_9: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[22] = jj_gen; + break label_9; + } + jj_consume_token(COMMA); + annotations = Annotations(); + tp = TypeParameter(annotations); +ret.add(tp); annotations = null; + } + jj_consume_token(GT); +ret.endAt(token()); +return ret; +} + + final public TypeParameter TypeParameter(NodeList annotations) throws ParseException {SimpleName name; + NodeList typeBound = emptyList(); + JavaToken begin; + name = SimpleName(); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EXTENDS:{ + typeBound = TypeBound(); + break; + } + default: + jj_la1[23] = jj_gen; + ; + } +return new TypeParameter(range(begin, token()), name, typeBound, annotations); +} + + final public NodeList TypeBound() throws ParseException {NodeList ret = emptyList(); + ClassOrInterfaceType cit; + jj_consume_token(EXTENDS); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); + label_10: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BIT_AND:{ + ; + break; + } + default: + jj_la1[24] = jj_gen; + break label_10; + } + jj_consume_token(BIT_AND); + cit = AnnotatedClassOrInterfaceType(); +ret.add(cit); + } +return ret; +} + + final public NodeList> ClassOrInterfaceBody() throws ParseException {NodeList> ret = emptyList(); + BodyDeclaration member; + jj_consume_token(LBRACE); + label_11: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case LBRACE: + case SEMICOLON: + case AT: + case LT:{ + ; + break; + } + default: + jj_la1[25] = jj_gen; + break label_11; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case LBRACE: + case AT: + case LT:{ + member = ClassOrInterfaceBodyDeclaration(); +ret.add(member); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[26] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(RBRACE); +return ret; +} + + final public BodyDeclaration ClassOrInterfaceBodyDeclaration() throws ParseException {ModifierHolder modifier; + BodyDeclaration ret; + if (jj_2_9(2)) { + ret = InitializerDeclaration(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT: + case LT:{ + // Just get all the modifiers out of the way. If you want to do + // more checks, pass the modifiers down to the member + modifier = Modifiers(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS: + case INTERFACE:{ + ret = ClassOrInterfaceDeclaration(modifier); + break; + } + default: + jj_la1[27] = jj_gen; + if (jj_2_5(2147483647)) { + ret = EnumDeclaration(modifier); + } else if (jj_2_6(2147483647)) { + ret = AnnotationTypeDeclaration(modifier); + } else if (jj_2_7(2147483647)) { + ret = ConstructorDeclaration(modifier); + } else if (jj_2_8(2147483647)) { + ret = FieldDeclaration(modifier); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT: + case LT:{ + ret = MethodDeclaration(modifier); + break; + } + default: + jj_la1[28] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + break; + } + default: + jj_la1[29] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public FieldDeclaration FieldDeclaration(ModifierHolder modifier) throws ParseException {Type partialType; + NodeList variables = new NodeList(); + VariableDeclarator val; + // Modifiers are already matched in the caller + partialType = Type(emptyList()); + val = VariableDeclarator(partialType); +variables.add(val); + label_12: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[30] = jj_gen; + break label_12; + } + jj_consume_token(COMMA); + val = VariableDeclarator(partialType); +variables.add(val); + } + jj_consume_token(SEMICOLON); +JavaToken begin = orIfInvalid(modifier.begin, partialType); + return new FieldDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, variables); +} + + final public VariableDeclarator VariableDeclarator(Type partialType) throws ParseException {Pair> id; + Expression init = null; + id = VariableDeclaratorId(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSIGN:{ + jj_consume_token(ASSIGN); + init = VariableInitializer(); + break; + } + default: + jj_la1[31] = jj_gen; + ; + } +return new VariableDeclarator(range(id.a, token()), juggleArrayType(partialType, id.b), id.a, init); +} + + final public Pair> VariableDeclaratorId() throws ParseException {SimpleName name; + JavaToken begin; + ArrayBracketPair arrayBracketPair; + List arrayBracketPairs = new ArrayList(0); + name = SimpleName(); +begin=token(); + label_13: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACKET: + case AT:{ + ; + break; + } + default: + jj_la1[32] = jj_gen; + break label_13; + } + arrayBracketPair = ArrayBracketPair(Origin.NAME); +arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); + } +if(storeTokens) { + name.setTokenRange(name.getTokenRange().get().withEnd(token())); + } + return new Pair(name, arrayBracketPairs); +} + + final public Expression VariableInitializer() throws ParseException {Expression ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + ret = ArrayInitializer(); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + ret = Expression(); + break; + } + default: + jj_la1[33] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public ArrayInitializerExpr ArrayInitializer() throws ParseException {NodeList values = emptyList(); + Expression val; + JavaToken begin; + jj_consume_token(LBRACE); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + val = VariableInitializer(); +values = add(values, val); + label_14: + while (true) { + if (jj_2_10(2)) { + ; + } else { + break label_14; + } + jj_consume_token(COMMA); + val = VariableInitializer(); +values = add(values, val); + } + break; + } + default: + jj_la1[34] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + jj_consume_token(COMMA); + break; + } + default: + jj_la1[35] = jj_gen; + ; + } + jj_consume_token(RBRACE); +return new ArrayInitializerExpr(range(begin, token()), values); +} + + final public MethodDeclaration MethodDeclaration(ModifierHolder modifier) throws ParseException {RangedList typeParameters = new RangedList(emptyList()); + Type type; + SimpleName name; + Pair, ReceiverParameter> parameters = new Pair, ReceiverParameter>(emptyList(), null); + ArrayBracketPair arrayBracketPair; + List arrayBracketPairs = new ArrayList(0); + NodeList throws_ = emptyList(); + BlockStmt body = null; + NodeList annotations; + JavaToken begin = modifier.begin; + ReferenceType throwType; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeParameters = TypeParameters(); +begin = orIfInvalid(begin, typeParameters.range.getBegin()); + break; + } + default: + jj_la1[36] = jj_gen; + ; + } + annotations = Annotations(); +modifier.annotations.addAll(annotations); begin = orIfInvalid(begin, nodeListBegin(annotations)); + type = ResultType(emptyList()); +begin = orIfInvalid(begin, type); + name = SimpleName(); + parameters = Parameters(); + label_15: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACKET: + case AT:{ + ; + break; + } + default: + jj_la1[37] = jj_gen; + break label_15; + } + arrayBracketPair = ArrayBracketPair(Origin.NAME); +arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + throwType = AnnotatedReferenceType(); +throws_ = add(throws_, throwType); + label_16: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[38] = jj_gen; + break label_16; + } + jj_consume_token(COMMA); + throwType = AnnotatedReferenceType(); +throws_ = add(throws_, throwType); + } + break; + } + default: + jj_la1[39] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + body = Block(); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[40] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +type = juggleArrayType(type, arrayBracketPairs); + return new MethodDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, type, name, parameters.a, throws_, body, parameters.b); +} + + final public ReferenceType AnnotatedReferenceType() throws ParseException {NodeList annotations; + ReferenceType type; + annotations = Annotations(); + type = ReferenceType(annotations); +return type; +} + + final public Type AnnotatedType() throws ParseException {NodeList annotations; + Type type; + annotations = Annotations(); + type = Type(annotations); +return type; +} + + final public Pair, ReceiverParameter> Parameters() throws ParseException {NodeList ret = emptyList(); + Parameter par; + ReceiverParameter rp = null; + jj_consume_token(LPAREN); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT:{ + if (jj_2_11(2147483647)) { + rp = ReceiverParameter(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT:{ + par = Parameter(); +ret = add(ret, par); + break; + } + default: + jj_la1[41] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + label_17: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[42] = jj_gen; + break label_17; + } + jj_consume_token(COMMA); + par = Parameter(); +ret = add(ret, par); + } + break; + } + default: + jj_la1[43] = jj_gen; + ; + } + jj_consume_token(RPAREN); +return new Pair(ret, rp); +} + + final public NodeList LambdaParameters() throws ParseException {NodeList ret = null; + Parameter par; + par = Parameter(); +ret = add(ret, par); + label_18: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[44] = jj_gen; + break label_18; + } + jj_consume_token(COMMA); + par = Parameter(); +ret = add(ret, par); + } +return ret; +} + + final public NodeList InferredLambdaParameters() throws ParseException {NodeList ret = null; + Pair> id; + id = VariableDeclaratorId(); +ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a)); + label_19: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[45] = jj_gen; + break label_19; + } + jj_consume_token(COMMA); + id = VariableDeclaratorId(); +ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a)); + } +return ret; +} + + final public Parameter Parameter() throws ParseException {ModifierHolder modifier; + Type partialType; + boolean isVarArg = false; + Pair> id; + NodeList varArgAnnotations = emptyList(); + modifier = Modifiers(); + partialType = Type(emptyList()); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case AT: + case ELLIPSIS:{ + varArgAnnotations = Annotations(); + jj_consume_token(ELLIPSIS); +isVarArg = true; + break; + } + default: + jj_la1[46] = jj_gen; + ; + } + id = VariableDeclaratorId(); +JavaToken begin = orIfInvalid(modifier.begin, partialType); + return new Parameter(range(begin, token()), modifier.modifiers, modifier.annotations, juggleArrayType(partialType, id.b), isVarArg, varArgAnnotations, id.a); +} + + final public ReceiverParameter ReceiverParameter() throws ParseException {Type partialType; + Name id; + NodeList annotations = emptyList(); + annotations = Annotations(); + partialType = Type(emptyList()); + id = ReceiverParameterId(); +return new ReceiverParameter(range(partialType, token()), annotations, partialType, id); +} + + final public Name ReceiverParameterId() throws ParseException {Name ret = null; + NodeList annotations; + if (jj_2_12(2147483647)) { + ret = Name(); + jj_consume_token(DOT); + } else { + ; + } + annotations = Annotations(); + jj_consume_token(THIS); +return new Name(tokenRange(), ret, token.image, annotations); +} + + final public ConstructorDeclaration ConstructorDeclaration(ModifierHolder modifier) throws ParseException {RangedList typeParameters = new RangedList(emptyList()); + SimpleName name; + Pair, ReceiverParameter> parameters = new Pair, ReceiverParameter>(emptyList(), null); + NodeList throws_ = emptyList(); + ExplicitConstructorInvocationStmt exConsInv = null; + NodeList stmts = emptyList(); + JavaToken begin = modifier.begin; + JavaToken blockBegin = INVALID; + ReferenceType throwType; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeParameters = TypeParameters(); +begin = orIfInvalid(begin, typeParameters.range.getBegin()); + break; + } + default: + jj_la1[47] = jj_gen; + ; + } + // Modifiers matched in the caller + name = SimpleName(); +begin = orIfInvalid(begin, typeParameters.range.getBegin()); begin = orIfInvalid(begin, token()); + parameters = Parameters(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + throwType = AnnotatedReferenceType(); +throws_ = add(throws_, throwType); + label_20: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[48] = jj_gen; + break label_20; + } + jj_consume_token(COMMA); + throwType = AnnotatedReferenceType(); +throws_ = add(throws_, throwType); + } + break; + } + default: + jj_la1[49] = jj_gen; + ; + } + jj_consume_token(LBRACE); +blockBegin=token(); + if (jj_2_13(2147483647)) { + exConsInv = ExplicitConstructorInvocation(); + } else { + ; + } + stmts = Statements(); + jj_consume_token(RBRACE); +if (exConsInv != null) { + stmts = prepend(stmts, exConsInv); + } + return new ConstructorDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, name, parameters.a, throws_, new BlockStmt(range(blockBegin, token()), stmts), parameters.b); +} + + final public ExplicitConstructorInvocationStmt ExplicitConstructorInvocation() throws ParseException {boolean isThis = false; + NodeList args; + Expression expr = null; + RangedList typeArgs = new RangedList(null); + JavaToken begin = INVALID; + if (jj_2_15(2147483647)) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); +begin=typeArgs.range.getBegin(); + break; + } + default: + jj_la1[50] = jj_gen; + ; + } + jj_consume_token(THIS); +begin = orIfInvalid(begin, token()); isThis = true; + args = Arguments(); + jj_consume_token(SEMICOLON); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case LT:{ + if (jj_2_14(2147483647)) { + expr = PrimaryExpressionWithoutSuperSuffix(); + jj_consume_token(DOT); +begin = orIfInvalid(begin, expr); + } else { + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); +begin = orIfInvalid(begin, typeArgs.range.getBegin()); + break; + } + default: + jj_la1[51] = jj_gen; + ; + } + jj_consume_token(SUPER); +begin = orIfInvalid(begin, token()); + args = Arguments(); + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[52] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return new ExplicitConstructorInvocationStmt(range(begin, token()),typeArgs.list, isThis, expr, args); +} + + final public NodeList Statements() throws ParseException {NodeList ret = emptyList(); + Statement stmt; + label_21: + while (true) { + if (jj_2_16(2)) { + ; + } else { + break label_21; + } + stmt = BlockStatement(); +ret = add(ret, stmt); + } +return ret; +} + + final public InitializerDeclaration InitializerDeclaration() throws ParseException {BlockStmt body; + JavaToken begin = INVALID; + boolean isStatic = false; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case STATIC:{ + jj_consume_token(STATIC); +isStatic = true; begin=token(); + break; + } + default: + jj_la1[53] = jj_gen; + ; + } + body = Block(); +begin = orIfInvalid(begin, body); +return new InitializerDeclaration(range(begin, token()), isStatic, body); +} + +/* + * Type, name and expression syntax follows. + */ + final public +Type Type(NodeList annotations) throws ParseException {Type ret; + if (jj_2_17(2)) { + ret = ReferenceType(annotations); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT:{ + ret = PrimitiveType(annotations); + break; + } + default: + jj_la1[54] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public ReferenceType ReferenceType(NodeList annotations) throws ParseException {Type type; + ArrayBracketPair arrayBracketPair; + List arrayBracketPairs = new ArrayList(0); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT:{ + type = PrimitiveType(annotations); + label_22: + while (true) { + arrayBracketPair = ArrayBracketPair(Origin.TYPE); +arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); + if (jj_2_18(2147483647)) { + ; + } else { + break label_22; + } + } + break; + } + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + type = ClassOrInterfaceType(annotations); + label_23: + while (true) { + if (jj_2_19(2147483647)) { + ; + } else { + break label_23; + } + arrayBracketPair = ArrayBracketPair(Origin.TYPE); +arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); + } + break; + } + default: + jj_la1[55] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return (ReferenceType)wrapInArrayTypes(type, arrayBracketPairs); +} + + final public ArrayBracketPair ArrayBracketPair(Origin origin) throws ParseException {NodeList annotations; + JavaToken begin = INVALID; + annotations = Annotations(); + jj_consume_token(LBRACKET); +begin = orIfInvalid(begin, token()); + jj_consume_token(RBRACKET); +return new ArrayBracketPair(range(begin, token()), origin, annotations); +} + + final public IntersectionType IntersectionType(NodeList annotations) throws ParseException {JavaToken begin = INVALID; + ReferenceType elementType; + NodeList elements = emptyList(); + elementType = ReferenceType(annotations); +begin = orIfInvalid(begin, elementType); elements = add(elements, elementType); + jj_consume_token(BIT_AND); + label_24: + while (true) { + elementType = AnnotatedReferenceType(); +elements = add(elements, elementType); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT:{ + ; + break; + } + default: + jj_la1[56] = jj_gen; + break label_24; + } + } +return new IntersectionType(range(begin, token()), elements); +} + + final public ClassOrInterfaceType AnnotatedClassOrInterfaceType() throws ParseException {NodeList annotations = new NodeList(); + ClassOrInterfaceType cit; + annotations = Annotations(); + cit = ClassOrInterfaceType(annotations); +return cit; +} + + final public ClassOrInterfaceType ClassOrInterfaceType(NodeList firstAnnotations) throws ParseException {ClassOrInterfaceType ret; + SimpleName name; + RangedList typeArgs = new RangedList(null); + JavaToken begin; + NodeList annotations = new NodeList(); + name = SimpleName(); +begin=token(); + if (jj_2_20(2)) { + typeArgs = TypeArguments(); + } else { + ; + } +ret = new ClassOrInterfaceType(range(begin, token()), null, name, typeArgs.list, firstAnnotations); + typeArgs = new RangedList(null); + label_25: + while (true) { + if (jj_2_21(2)) { + ; + } else { + break label_25; + } + jj_consume_token(DOT); + annotations = Annotations(); + name = SimpleName(); + if (jj_2_22(2)) { + typeArgs = TypeArguments(); + } else { + ; + } +ret = new ClassOrInterfaceType(range(begin, token()), ret, name, typeArgs.list, annotations); + typeArgs = new RangedList(null); + } +return ret; +} + + final public RangedList TypeArguments() throws ParseException {RangedList ret = new RangedList(new NodeList()); + Type type; + jj_consume_token(LT); +ret.beginAt(token()); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT: + case HOOK:{ + type = TypeArgument(); +ret.add(type); + label_26: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[57] = jj_gen; + break label_26; + } + jj_consume_token(COMMA); + type = TypeArgument(); +ret.add(type); + } + break; + } + default: + jj_la1[58] = jj_gen; + ; + } + jj_consume_token(GT); +ret.endAt(token()); +return ret; +} + + final public Type TypeArgument() throws ParseException {Type ret; + NodeList annotations; + annotations = Annotations(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + ret = Type(annotations); + break; + } + case HOOK:{ + ret = Wildcard(annotations); + break; + } + default: + jj_la1[59] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public WildcardType Wildcard(NodeList firstAnnotations) throws ParseException {ReferenceType ext = null; + ReferenceType sup = null; + JavaToken begin; + NodeList annotations = new NodeList(); + jj_consume_token(HOOK); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EXTENDS: + case SUPER:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EXTENDS:{ + jj_consume_token(EXTENDS); + annotations = Annotations(); + ext = ReferenceType(annotations); + break; + } + case SUPER:{ + jj_consume_token(SUPER); + annotations = Annotations(); + sup = ReferenceType(annotations); + break; + } + default: + jj_la1[60] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[61] = jj_gen; + ; + } +return new WildcardType(range(begin, token()), ext, sup, firstAnnotations); +} + + final public PrimitiveType PrimitiveType(NodeList annotations) throws ParseException {PrimitiveType ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN:{ + jj_consume_token(BOOLEAN); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BOOLEAN, annotations); + break; + } + case CHAR:{ + jj_consume_token(CHAR); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.CHAR, annotations); + break; + } + case BYTE:{ + jj_consume_token(BYTE); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BYTE, annotations); + break; + } + case SHORT:{ + jj_consume_token(SHORT); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.SHORT, annotations); + break; + } + case INT:{ + jj_consume_token(INT); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.INT, annotations); + break; + } + case LONG:{ + jj_consume_token(LONG); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.LONG, annotations); + break; + } + case FLOAT:{ + jj_consume_token(FLOAT); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.FLOAT, annotations); + break; + } + case DOUBLE:{ + jj_consume_token(DOUBLE); +ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.DOUBLE, annotations); + break; + } + default: + jj_la1[62] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Type ResultType(NodeList annotations) throws ParseException {Type ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case VOID:{ + jj_consume_token(VOID); +ret = new VoidType(tokenRange()); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + ret = Type(annotations); + break; + } + default: + jj_la1[63] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Name Name() throws ParseException {Name ret; + NodeList annotations = new NodeList(); + annotations = Annotations(); + Identifier(); +ret = new Name(tokenRange(), null, token.image, annotations); + label_27: + while (true) { + if (jj_2_23(2147483647)) { + ; + } else { + break label_27; + } + jj_consume_token(DOT); + annotations = Annotations(); + Identifier(); +ret = new Name(range(ret, token()), ret, token.image, annotations); + } +return ret; +} + + final public SimpleName SimpleName() throws ParseException {SimpleName ret; + Identifier(); +ret = new SimpleName(tokenRange(), token.image); +return ret; +} + + final public String Identifier() throws ParseException {String ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case MODULE:{ + jj_consume_token(MODULE); + break; + } + case REQUIRES:{ + jj_consume_token(REQUIRES); + break; + } + case TO:{ + jj_consume_token(TO); + break; + } + case WITH:{ + jj_consume_token(WITH); + break; + } + case OPEN:{ + jj_consume_token(OPEN); + break; + } + case OPENS:{ + jj_consume_token(OPENS); + break; + } + case USES:{ + jj_consume_token(USES); + break; + } + case EXPORTS:{ + jj_consume_token(EXPORTS); + break; + } + case PROVIDES:{ + jj_consume_token(PROVIDES); + break; + } + case TRANSITIVE:{ + jj_consume_token(TRANSITIVE); + break; + } + case ENUM:{ + jj_consume_token(ENUM); + break; + } + case STRICTFP:{ + jj_consume_token(STRICTFP); + break; + } + case IDENTIFIER:{ + jj_consume_token(IDENTIFIER); + break; + } + default: + jj_la1[64] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +ret = token.image; setTokenKind(IDENTIFIER); +return ret; +} + +/* + * Expression syntax follows. + */ + final public +Expression Expression() throws ParseException {Expression ret; + AssignExpr.Operator op; + Expression value; + Statement lambdaBody = null; + RangedList typeArgs = new RangedList(null); + ret = ConditionalExpression(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSIGN: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case LSHIFTASSIGN: + case RSIGNEDSHIFTASSIGN: + case RUNSIGNEDSHIFTASSIGN: + case ARROW: + case DOUBLECOLON:{ + if (jj_2_24(2)) { + op = AssignmentOperator(); + value = Expression(); +ret = new AssignExpr(range(ret, token()), ret, value, op); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ARROW:{ + jj_consume_token(ARROW); + lambdaBody = LambdaBody(); +if (ret instanceof CastExpr) { + ret = generateLambda(ret, lambdaBody); + } else if (ret instanceof ConditionalExpr) { + ConditionalExpr ce = (ConditionalExpr) ret; + if(ce.getElseExpr() != null) { + ce.setElseExpr(generateLambda(ce.getElseExpr(), lambdaBody)); + } + } else { + ret = generateLambda(ret, lambdaBody); + } + break; + } + case DOUBLECOLON:{ + jj_consume_token(DOUBLECOLON); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[65] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + Identifier(); + break; + } + case NEW:{ + jj_consume_token(NEW); + break; + } + default: + jj_la1[66] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); + break; + } + default: + jj_la1[67] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + break; + } + default: + jj_la1[68] = jj_gen; + ; + } +return ret; +} + + final public AssignExpr.Operator AssignmentOperator() throws ParseException {AssignExpr.Operator ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSIGN:{ + jj_consume_token(ASSIGN); +ret = AssignExpr.Operator.ASSIGN; + break; + } + case STARASSIGN:{ + jj_consume_token(STARASSIGN); +ret = AssignExpr.Operator.MULTIPLY; + break; + } + case SLASHASSIGN:{ + jj_consume_token(SLASHASSIGN); +ret = AssignExpr.Operator.DIVIDE; + break; + } + case REMASSIGN:{ + jj_consume_token(REMASSIGN); +ret = AssignExpr.Operator.REMAINDER; + break; + } + case PLUSASSIGN:{ + jj_consume_token(PLUSASSIGN); +ret = AssignExpr.Operator.PLUS; + break; + } + case MINUSASSIGN:{ + jj_consume_token(MINUSASSIGN); +ret = AssignExpr.Operator.MINUS; + break; + } + case LSHIFTASSIGN:{ + jj_consume_token(LSHIFTASSIGN); +ret = AssignExpr.Operator.LEFT_SHIFT; + break; + } + case RSIGNEDSHIFTASSIGN:{ + jj_consume_token(RSIGNEDSHIFTASSIGN); +ret = AssignExpr.Operator.SIGNED_RIGHT_SHIFT; + break; + } + case RUNSIGNEDSHIFTASSIGN:{ + jj_consume_token(RUNSIGNEDSHIFTASSIGN); +ret = AssignExpr.Operator.UNSIGNED_RIGHT_SHIFT; + break; + } + case ANDASSIGN:{ + jj_consume_token(ANDASSIGN); +ret = AssignExpr.Operator.BINARY_AND; + break; + } + case XORASSIGN:{ + jj_consume_token(XORASSIGN); +ret = AssignExpr.Operator.XOR; + break; + } + case ORASSIGN:{ + jj_consume_token(ORASSIGN); +ret = AssignExpr.Operator.BINARY_OR; + break; + } + default: + jj_la1[69] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Expression ConditionalExpression() throws ParseException {Expression ret; + Expression left; + Expression right; + ret = ConditionalOrExpression(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case HOOK:{ + jj_consume_token(HOOK); + left = Expression(); + jj_consume_token(COLON); + right = ConditionalExpression(); +ret = new ConditionalExpr(range(ret, token()), ret, left, right); + break; + } + default: + jj_la1[70] = jj_gen; + ; + } +return ret; +} + + final public Expression ConditionalOrExpression() throws ParseException {Expression ret; + Expression right; + ret = ConditionalAndExpression(); + label_28: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case SC_OR:{ + ; + break; + } + default: + jj_la1[71] = jj_gen; + break label_28; + } + jj_consume_token(SC_OR); + right = ConditionalAndExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.OR); + } +return ret; +} + + final public Expression ConditionalAndExpression() throws ParseException {Expression ret; + Expression right; + ret = InclusiveOrExpression(); + label_29: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case SC_AND:{ + ; + break; + } + default: + jj_la1[72] = jj_gen; + break label_29; + } + jj_consume_token(SC_AND); + right = InclusiveOrExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.AND); + } +return ret; +} + + final public Expression InclusiveOrExpression() throws ParseException {Expression ret; + Expression right; + ret = ExclusiveOrExpression(); + label_30: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BIT_OR:{ + ; + break; + } + default: + jj_la1[73] = jj_gen; + break label_30; + } + jj_consume_token(BIT_OR); + right = ExclusiveOrExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_OR); + } +return ret; +} + + final public Expression ExclusiveOrExpression() throws ParseException {Expression ret; + Expression right; + ret = AndExpression(); + label_31: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case XOR:{ + ; + break; + } + default: + jj_la1[74] = jj_gen; + break label_31; + } + jj_consume_token(XOR); + right = AndExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.XOR); + } +return ret; +} + + final public Expression AndExpression() throws ParseException {Expression ret; + Expression right; + ret = EqualityExpression(); + label_32: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BIT_AND:{ + ; + break; + } + default: + jj_la1[75] = jj_gen; + break label_32; + } + jj_consume_token(BIT_AND); + right = EqualityExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_AND); + } +return ret; +} + + final public Expression EqualityExpression() throws ParseException {Expression ret; + Expression right; + BinaryExpr.Operator op; + ret = InstanceOfExpression(); + label_33: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EQ: + case NE:{ + ; + break; + } + default: + jj_la1[76] = jj_gen; + break label_33; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EQ:{ + jj_consume_token(EQ); +op = BinaryExpr.Operator.EQUALS; + break; + } + case NE:{ + jj_consume_token(NE); +op = BinaryExpr.Operator.NOT_EQUALS; + break; + } + default: + jj_la1[77] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + right = InstanceOfExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, op); + } +return ret; +} + + final public Expression InstanceOfExpression() throws ParseException {Expression ret; + ReferenceType type; + NodeList annotations; + ret = RelationalExpression(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INSTANCEOF:{ + jj_consume_token(INSTANCEOF); + type = AnnotatedReferenceType(); +ret = new InstanceOfExpr(range(ret, token()), ret, type); + break; + } + default: + jj_la1[78] = jj_gen; + ; + } +return ret; +} + + final public Expression RelationalExpression() throws ParseException {Expression ret; + Expression right; + BinaryExpr.Operator op; + ret = ShiftExpression(); + label_34: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT: + case LE: + case GE: + case GT:{ + ; + break; + } + default: + jj_la1[79] = jj_gen; + break label_34; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + jj_consume_token(LT); +op = BinaryExpr.Operator.LESS; + break; + } + case GT:{ + jj_consume_token(GT); +op = BinaryExpr.Operator.GREATER; + break; + } + case LE:{ + jj_consume_token(LE); +op = BinaryExpr.Operator.LESS_EQUALS; + break; + } + case GE:{ + jj_consume_token(GE); +op = BinaryExpr.Operator.GREATER_EQUALS; + break; + } + default: + jj_la1[80] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + right = ShiftExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, op); + } +return ret; +} + + final public Expression ShiftExpression() throws ParseException {Expression ret; + Expression right; + BinaryExpr.Operator op; + ret = AdditiveExpression(); + label_35: + while (true) { + if (jj_2_25(1)) { + ; + } else { + break label_35; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LSHIFT:{ + jj_consume_token(LSHIFT); +op = BinaryExpr.Operator.LEFT_SHIFT; + break; + } + default: + jj_la1[81] = jj_gen; + if (jj_2_26(1)) { + RSIGNEDSHIFT(); +op = BinaryExpr.Operator.SIGNED_RIGHT_SHIFT; + } else if (jj_2_27(1)) { + RUNSIGNEDSHIFT(); +op = BinaryExpr.Operator.UNSIGNED_RIGHT_SHIFT; + } else { + jj_consume_token(-1); + throw new ParseException(); + } + } + right = AdditiveExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, op); + } +return ret; +} + + final public Expression AdditiveExpression() throws ParseException {Expression ret; + Expression right; + BinaryExpr.Operator op; + ret = MultiplicativeExpression(); + label_36: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PLUS: + case MINUS:{ + ; + break; + } + default: + jj_la1[82] = jj_gen; + break label_36; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); +op = BinaryExpr.Operator.PLUS; + break; + } + case MINUS:{ + jj_consume_token(MINUS); +op = BinaryExpr.Operator.MINUS; + break; + } + default: + jj_la1[83] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + right = MultiplicativeExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, op); + } +return ret; +} + + final public Expression MultiplicativeExpression() throws ParseException {Expression ret; + Expression right; + BinaryExpr.Operator op; + ret = UnaryExpression(); + label_37: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case STAR: + case SLASH: + case REM:{ + ; + break; + } + default: + jj_la1[84] = jj_gen; + break label_37; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case STAR:{ + jj_consume_token(STAR); +op = BinaryExpr.Operator.MULTIPLY; + break; + } + case SLASH:{ + jj_consume_token(SLASH); +op = BinaryExpr.Operator.DIVIDE; + break; + } + case REM:{ + jj_consume_token(REM); +op = BinaryExpr.Operator.REMAINDER; + break; + } + default: + jj_la1[85] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + right = UnaryExpression(); +ret = new BinaryExpr(range(ret, token()), ret, right, op); + } +return ret; +} + + final public Expression UnaryExpression() throws ParseException {Expression ret; + UnaryExpr.Operator op; + JavaToken begin = INVALID; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INCR:{ + ret = PreIncrementExpression(); + break; + } + case DECR:{ + ret = PreDecrementExpression(); + break; + } + case PLUS: + case MINUS:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); +op = UnaryExpr.Operator.PLUS; begin=token(); + break; + } + case MINUS:{ + jj_consume_token(MINUS); +op = UnaryExpr.Operator.MINUS; begin=token(); + break; + } + default: + jj_la1[86] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + ret = UnaryExpression(); +ret = new UnaryExpr(range(begin, token()), ret, op); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE:{ + ret = UnaryExpressionNotPlusMinus(); + break; + } + default: + jj_la1[87] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Expression PreIncrementExpression() throws ParseException {Expression ret; + JavaToken begin = INVALID; + jj_consume_token(INCR); +begin=token(); + ret = UnaryExpression(); +ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_INCREMENT); +return ret; +} + + final public Expression PreDecrementExpression() throws ParseException {Expression ret; + JavaToken begin; + jj_consume_token(DECR); +begin=token(); + ret = UnaryExpression(); +ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_DECREMENT); +return ret; +} + + final public Expression UnaryExpressionNotPlusMinus() throws ParseException {Expression ret; + UnaryExpr.Operator op; + JavaToken begin = INVALID; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BANG: + case TILDE:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TILDE:{ + jj_consume_token(TILDE); +op = UnaryExpr.Operator.BITWISE_COMPLEMENT; begin=token(); + break; + } + case BANG:{ + jj_consume_token(BANG); +op = UnaryExpr.Operator.LOGICAL_COMPLEMENT; begin=token(); + break; + } + default: + jj_la1[88] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + ret = UnaryExpression(); +ret = new UnaryExpr(range(begin, token()), ret, op); + break; + } + default: + jj_la1[89] = jj_gen; + if (jj_2_28(2147483647)) { + ret = CastExpression(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT:{ + ret = PostfixExpression(); + break; + } + default: + jj_la1[90] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +return ret; +} + + final public Expression PostfixExpression() throws ParseException {Expression ret; + UnaryExpr.Operator op; + ret = PrimaryExpression(); + if (jj_2_29(2)) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INCR:{ + jj_consume_token(INCR); +op = UnaryExpr.Operator.POSTFIX_INCREMENT; + break; + } + case DECR:{ + jj_consume_token(DECR); +op = UnaryExpr.Operator.POSTFIX_DECREMENT; + break; + } + default: + jj_la1[91] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +ret = new UnaryExpr(range(ret, token()), ret, op); + } else { + ; + } +return ret; +} + + final public Expression CastExpression() throws ParseException {Expression ret; + ReferenceType referenceType; + PrimitiveType primitiveType; + JavaToken begin = INVALID; + NodeList annotations; + NodeList typesOfMultiCast = emptyList(); + jj_consume_token(LPAREN); +begin=token(); + annotations = Annotations(); + if (jj_2_30(2)) { + primitiveType = PrimitiveType(annotations); + jj_consume_token(RPAREN); + ret = UnaryExpression(); +ret = new CastExpr(range(begin, token()), primitiveType, ret); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + referenceType = ReferenceType(annotations); +typesOfMultiCast = add(typesOfMultiCast, referenceType); + label_38: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BIT_AND:{ + ; + break; + } + default: + jj_la1[92] = jj_gen; + break label_38; + } + jj_consume_token(BIT_AND); + referenceType = AnnotatedReferenceType(); +typesOfMultiCast = add(typesOfMultiCast, referenceType); + } + jj_consume_token(RPAREN); + ret = UnaryExpressionNotPlusMinus(); +if (typesOfMultiCast.size() > 1) { + ret = new CastExpr(range(begin, token()), new IntersectionType(range(typesOfMultiCast.get(0), typesOfMultiCast.get(typesOfMultiCast.size() -1)), typesOfMultiCast), ret); + } else { + ret = new CastExpr(range(begin, token()), referenceType, ret); + } + break; + } + default: + jj_la1[93] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public Expression PrimaryExpression() throws ParseException {Expression ret; + ret = PrimaryPrefix(); + label_39: + while (true) { + if (jj_2_31(2)) { + ; + } else { + break label_39; + } + ret = PrimarySuffix(ret); + } +return ret; +} + + final public Expression PrimaryExpressionWithoutSuperSuffix() throws ParseException {Expression ret; + ret = PrimaryPrefix(); + label_40: + while (true) { + if (jj_2_32(2147483647)) { + ; + } else { + break label_40; + } + ret = PrimarySuffixWithoutSuper(ret); + } +return ret; +} + + final public Expression PrimaryPrefix() throws ParseException {Expression ret = null; + SimpleName name; + RangedList typeArgs = new RangedList(null); + NodeList args = emptyList(); + NodeList params = emptyList(); + boolean hasArgs = false; + boolean isLambda = false; + Type type; + JavaToken begin; + Parameter p = null; + SimpleName id = null; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case FALSE: + case NULL: + case TRUE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL:{ + ret = Literal(); + break; + } + case THIS:{ + jj_consume_token(THIS); +ret = new ThisExpr(tokenRange(), null); + break; + } + case SUPER:{ + jj_consume_token(SUPER); +ret = new SuperExpr(tokenRange(), null); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case DOT:{ + jj_consume_token(DOT); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[94] = jj_gen; + ; + } + name = SimpleName(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN:{ + args = Arguments(); +hasArgs=true; + break; + } + default: + jj_la1[95] = jj_gen; + ; + } +if (hasArgs) { + ret = new MethodCallExpr(range(ret, token()), ret, typeArgs.list, name, args); + } else { + ret = new FieldAccessExpr(range(ret, token()), ret, emptyList(), name); + } + break; + } + case DOUBLECOLON:{ + jj_consume_token(DOUBLECOLON); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[96] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + Identifier(); + break; + } + case NEW:{ + jj_consume_token(NEW); + break; + } + default: + jj_la1[97] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); + break; + } + default: + jj_la1[98] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + case LPAREN:{ + jj_consume_token(LPAREN); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case RPAREN:{ + jj_consume_token(RPAREN); +ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); + break; + } + default: + jj_la1[99] = jj_gen; + if (jj_2_33(2147483647)) { + params = LambdaParameters(); + jj_consume_token(RPAREN); +ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); + } else if (jj_2_34(2147483647)) { + params = InferredLambdaParameters(); + jj_consume_token(RPAREN); +ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + // This could still be a lambda expression, but this is handled after matching -> elsewhere + ret = Expression(); + jj_consume_token(RPAREN); +ret = new EnclosedExpr(range(begin, token()), ret); + break; + } + default: + jj_la1[100] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + break; + } + case NEW:{ + ret = AllocationExpression(null); + break; + } + default: + jj_la1[104] = jj_gen; + if (jj_2_35(2147483647)) { + type = ResultType(emptyList()); + jj_consume_token(DOT); + jj_consume_token(CLASS); +ret = new ClassExpr(range(type, token()), type); + } else if (jj_2_36(2147483647)) { + type = AnnotatedType(); + jj_consume_token(DOUBLECOLON); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[101] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + Identifier(); + break; + } + case NEW:{ + jj_consume_token(NEW); + break; + } + default: + jj_la1[102] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +ret = new TypeExpr(range(type, type), type); + ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + name = SimpleName(); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN:{ + args = Arguments(); +hasArgs=true; + break; + } + default: + jj_la1[103] = jj_gen; + ; + } +if (hasArgs) { + ret = new MethodCallExpr(range(begin, token()), null, null, name, args); + } else { + ret = new NameExpr(name); + } + break; + } + default: + jj_la1[105] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +return ret; +} + + final public Expression PrimarySuffix(Expression scope) throws ParseException {Expression ret; + if (jj_2_37(2)) { + ret = PrimarySuffixWithoutSuper(scope); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case DOT:{ + jj_consume_token(DOT); + jj_consume_token(SUPER); +ret = new SuperExpr(range(scope, token()), scope); + break; + } + default: + jj_la1[106] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public Expression PrimarySuffixWithoutSuper(Expression scope) throws ParseException {Expression ret; + RangedList typeArgs = new RangedList(null); + NodeList args = emptyList(); + boolean hasArgs = false; + SimpleName name; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case DOT:{ + jj_consume_token(DOT); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case THIS:{ + jj_consume_token(THIS); +ret = new ThisExpr(range(scope, token()), scope); + break; + } + case NEW:{ + ret = AllocationExpression(scope); + break; + } + default: + jj_la1[109] = jj_gen; + if (jj_2_38(2147483647)) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[107] = jj_gen; + ; + } + name = SimpleName(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN:{ + args = Arguments(); +hasArgs=true; + break; + } + default: + jj_la1[108] = jj_gen; + ; + } +if (hasArgs) { + ret = new MethodCallExpr(range(scope, token()), scope, typeArgs.list, name, args); + } else { + ret = new FieldAccessExpr(range(scope, token()), scope, typeArgs.list, name); + } + } else { + jj_consume_token(-1); + throw new ParseException(); + } + } + break; + } + case LBRACKET:{ + jj_consume_token(LBRACKET); + ret = Expression(); + jj_consume_token(RBRACKET); +ret = new ArrayAccessExpr(range(scope, token()), scope, ret); + break; + } + default: + jj_la1[110] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Expression Literal() throws ParseException {Expression ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INTEGER_LITERAL:{ + jj_consume_token(INTEGER_LITERAL); +ret = new IntegerLiteralExpr(tokenRange(), token.image); + break; + } + case LONG_LITERAL:{ + jj_consume_token(LONG_LITERAL); +ret = new LongLiteralExpr(tokenRange(), token.image); + break; + } + case FLOATING_POINT_LITERAL:{ + jj_consume_token(FLOATING_POINT_LITERAL); +ret = new DoubleLiteralExpr(tokenRange(), token.image); + break; + } + case CHARACTER_LITERAL:{ + jj_consume_token(CHARACTER_LITERAL); +ret = new CharLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1)); + break; + } + case STRING_LITERAL:{ + jj_consume_token(STRING_LITERAL); +ret = new StringLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1)); + break; + } + case FALSE: + case TRUE:{ + ret = BooleanLiteral(); + break; + } + case NULL:{ + ret = NullLiteral(); + break; + } + default: + jj_la1[111] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Expression BooleanLiteral() throws ParseException {Expression ret; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TRUE:{ + jj_consume_token(TRUE); +ret = new BooleanLiteralExpr(tokenRange(), true); + break; + } + case FALSE:{ + jj_consume_token(FALSE); +ret = new BooleanLiteralExpr(tokenRange(), false); + break; + } + default: + jj_la1[112] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public Expression NullLiteral() throws ParseException { + jj_consume_token(NULL); +return new NullLiteralExpr(tokenRange()); +} + + final public NodeList Arguments() throws ParseException {NodeList ret = emptyList(); + jj_consume_token(LPAREN); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + ret = ArgumentList(); + break; + } + default: + jj_la1[113] = jj_gen; + ; + } + jj_consume_token(RPAREN); +return ret; +} + + final public NodeList ArgumentList() throws ParseException {NodeList ret = emptyList(); + Expression expr; + expr = Expression(); +ret.add(expr); + label_41: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[114] = jj_gen; + break label_41; + } + jj_consume_token(COMMA); + expr = Expression(); +ret.add(expr); + } +return ret; +} + + final public Expression AllocationExpression(Expression scope) throws ParseException {Expression ret; + Type type; + RangedList typeArgs = new RangedList(null); + NodeList> anonymousBody = null; + NodeList args; + JavaToken begin = INVALID; + NodeList annotations = new NodeList(); + jj_consume_token(NEW); +if(scope==null) {begin=token();} else {begin = orIfInvalid(begin, scope);} + annotations = Annotations(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT:{ + type = PrimitiveType(annotations); + ret = ArrayCreation(begin, type); + break; + } + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT: + case LT:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LT:{ + typeArgs = TypeArguments(); + break; + } + default: + jj_la1[115] = jj_gen; + ; + } + type = AnnotatedClassOrInterfaceType(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACKET: + case AT:{ + ret = ArrayCreation(begin, type); + break; + } + case LPAREN:{ + args = Arguments(); + if (jj_2_39(2)) { + anonymousBody = ClassOrInterfaceBody(); + } else { + ; + } +ret = new ObjectCreationExpr(range(begin, token()), scope, (ClassOrInterfaceType) type, typeArgs.list, args, anonymousBody); + break; + } + default: + jj_la1[116] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[117] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return ret; +} + + final public ArrayCreationExpr ArrayCreation(JavaToken begin, Type type) throws ParseException {Expression expr = null; + ArrayInitializerExpr arrayInitializerExpr = null; + NodeList inits = emptyList(); + List> accum = new ArrayList>(); + NodeList annotations = new NodeList(); + JavaToken arrayCreationLevelStart = INVALID; + List levelRanges = new ArrayList(); + label_42: + while (true) { + annotations = Annotations(); + jj_consume_token(LBRACKET); +arrayCreationLevelStart = annotations.isEmpty() ? token() : orIfInvalid(arrayCreationLevelStart, annotations.get(0)); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + expr = Expression(); + break; + } + default: + jj_la1[118] = jj_gen; + ; + } +accum = add(accum, annotations); inits = add(inits, expr); annotations=null; expr=null; + jj_consume_token(RBRACKET); +levelRanges.add(range(arrayCreationLevelStart, token())); + if (jj_2_40(2)) { + ; + } else { + break label_42; + } + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + arrayInitializerExpr = ArrayInitializer(); + break; + } + default: + jj_la1[119] = jj_gen; + ; + } +return juggleArrayCreation(range(begin, token()), levelRanges, type, inits, accum, arrayInitializerExpr); +} + +/* + * Statement syntax follows. + */ + final public +Statement Statement() throws ParseException {Statement ret; + try { + if (jj_2_41(2)) { + ret = LabeledStatement(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSERT:{ + ret = AssertStatement(); + break; + } + case LBRACE:{ + ret = Block(); + break; + } + case SEMICOLON:{ + ret = EmptyStatement(); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case INCR: + case DECR:{ + ret = StatementExpression(); + break; + } + case SWITCH:{ + ret = SwitchStatement(); + break; + } + case IF:{ + ret = IfStatement(); + break; + } + case WHILE:{ + ret = WhileStatement(); + break; + } + case DO:{ + ret = DoStatement(); + break; + } + case FOR:{ + ret = ForStatement(); + break; + } + case BREAK:{ + ret = BreakStatement(); + break; + } + case CONTINUE:{ + ret = ContinueStatement(); + break; + } + case RETURN:{ + ret = ReturnStatement(); + break; + } + case THROW:{ + ret = ThrowStatement(); + break; + } + case SYNCHRONIZED:{ + ret = SynchronizedStatement(); + break; + } + case TRY:{ + ret = TryStatement(); + break; + } + default: + jj_la1[120] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; + } catch (ParseException e) { +TokenRange errorRange = recover(SEMICOLON, e); + return new UnparsableStmt(errorRange); + } +} + + final public AssertStmt AssertStatement() throws ParseException {Expression check; + Expression msg = null; + JavaToken begin; + jj_consume_token(ASSERT); +begin=token(); + check = Expression(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COLON:{ + jj_consume_token(COLON); + msg = Expression(); + break; + } + default: + jj_la1[121] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +return new AssertStmt(range(begin, token()), check, msg); +} + + final public LabeledStmt LabeledStatement() throws ParseException {SimpleName label; + Statement stmt; + JavaToken begin; + label = SimpleName(); +begin=token(); + jj_consume_token(COLON); + stmt = Statement(); +return new LabeledStmt(range(begin, token()), label, stmt); +} + + final public BlockStmt Block() throws ParseException {NodeList stmts = emptyList(); + JavaToken begin; + jj_consume_token(LBRACE); +begin=token(); + try { + stmts = Statements(); + jj_consume_token(RBRACE); +return new BlockStmt(range(begin, token()), stmts); + } catch (ParseException e) { +recover(RBRACE, e); + BlockStmt block = new BlockStmt(range(begin, token()), new NodeList()); + block.setParsed(UNPARSABLE); + return block; + } +} + +/* + * Classes inside body statements can only be abstract or final. The semantic must check it. + */ + final public Statement BlockStatement() throws ParseException {Statement ret; + Expression expr; + ClassOrInterfaceDeclaration typeDecl; + ModifierHolder modifier; + try { + if (jj_2_42(2147483647)) { + modifier = Modifiers(); + typeDecl = ClassOrInterfaceDeclaration(modifier); +ret = new LocalClassDeclarationStmt(range(typeDecl, token()), typeDecl); + } else if (jj_2_43(2147483647)) { + expr = VariableDeclarationExpression(); + jj_consume_token(SEMICOLON); +ret = new ExpressionStmt(range(expr, token()), expr); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSERT: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CONTINUE: + case DO: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case FOR: + case IF: + case INT: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case STRICTFP: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + case AT: + case INCR: + case DECR:{ + ret = Statement(); + break; + } + default: + jj_la1[122] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; + } catch (ParseException e) { +TokenRange errorRange = recover(SEMICOLON, e); + return new UnparsableStmt(errorRange); + } +} + + final public VariableDeclarationExpr VariableDeclarationExpression() throws ParseException {ModifierHolder modifier; + Type partialType; + NodeList variables = new NodeList(); + VariableDeclarator var; + modifier = Modifiers(); + partialType = Type(emptyList()); + var = VariableDeclarator(partialType); +variables.add(var); + label_43: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[123] = jj_gen; + break label_43; + } + jj_consume_token(COMMA); + var = VariableDeclarator(partialType); +variables.add(var); + } +JavaToken begin=orIfInvalid(modifier.begin, partialType); + return new VariableDeclarationExpr(range(begin, token()), modifier.modifiers, modifier.annotations, variables); +} + + final public EmptyStmt EmptyStatement() throws ParseException { + jj_consume_token(SEMICOLON); +return new EmptyStmt(tokenRange()); +} + + final public Statement LambdaBody() throws ParseException {Expression expr; + Statement n = null; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + expr = Expression(); +n = new ExpressionStmt(range(expr, token()), expr); + break; + } + case LBRACE:{ + n = Block(); + break; + } + default: + jj_la1[124] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +return n; +} + + final public ExpressionStmt StatementExpression() throws ParseException {Expression expr; + AssignExpr.Operator op; + Expression value; + RangedList typeArgs = new RangedList(null); + Statement lambdaBody; + if (jj_2_44(2)) { + expr = PreIncrementExpression(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case DECR:{ + expr = PreDecrementExpression(); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT:{ + expr = PrimaryExpression(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ASSIGN: + case INCR: + case DECR: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case LSHIFTASSIGN: + case RSIGNEDSHIFTASSIGN: + case RUNSIGNEDSHIFTASSIGN:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INCR:{ + jj_consume_token(INCR); +expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_INCREMENT); + break; + } + case DECR:{ + jj_consume_token(DECR); +expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_DECREMENT); + break; + } + case ASSIGN: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case LSHIFTASSIGN: + case RSIGNEDSHIFTASSIGN: + case RUNSIGNEDSHIFTASSIGN:{ + op = AssignmentOperator(); + value = Expression(); +expr = new AssignExpr(range(expr, token()), expr, value, op); + break; + } + default: + jj_la1[125] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[126] = jj_gen; + ; + } + break; + } + default: + jj_la1[127] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(SEMICOLON); +return new ExpressionStmt(range(expr, token()), expr); +} + + final public SwitchStmt SwitchStatement() throws ParseException {Expression selector; + SwitchEntryStmt entry; + NodeList entries = emptyList(); + JavaToken begin; + jj_consume_token(SWITCH); +begin=token(); + jj_consume_token(LPAREN); + selector = Expression(); + jj_consume_token(RPAREN); + jj_consume_token(LBRACE); + label_44: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CASE: + case _DEFAULT:{ + ; + break; + } + default: + jj_la1[128] = jj_gen; + break label_44; + } + entry = SwitchEntry(); +entries = add(entries, entry); + } + jj_consume_token(RBRACE); +return new SwitchStmt(range(begin, token()), selector, entries); +} + + final public SwitchEntryStmt SwitchEntry() throws ParseException {Expression label = null; + NodeList stmts; + JavaToken begin; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CASE:{ + jj_consume_token(CASE); +begin=token(); + label = Expression(); + break; + } + case _DEFAULT:{ + jj_consume_token(_DEFAULT); +begin=token(); + break; + } + default: + jj_la1[129] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(COLON); + stmts = Statements(); +return new SwitchEntryStmt(range(begin, token()),label, stmts); +} + + final public IfStmt IfStatement() throws ParseException {Expression condition; + Statement thenStmt; + Statement elseStmt = null; + JavaToken begin; + jj_consume_token(IF); +begin=token(); + jj_consume_token(LPAREN); + condition = Expression(); + jj_consume_token(RPAREN); + + thenStmt = Statement(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ELSE:{ + jj_consume_token(ELSE); + + elseStmt = Statement(); + break; + } + default: + jj_la1[130] = jj_gen; + ; + } +return new IfStmt(range(begin, token()), condition, thenStmt, elseStmt); +} + + final public WhileStmt WhileStatement() throws ParseException {Expression condition; + Statement body; + JavaToken begin; + jj_consume_token(WHILE); +begin=token(); + jj_consume_token(LPAREN); + condition = Expression(); + jj_consume_token(RPAREN); + body = Statement(); +return new WhileStmt(range(begin, token()),condition, body); +} + + final public DoStmt DoStatement() throws ParseException {Expression condition; + Statement body; + JavaToken begin; + jj_consume_token(DO); +begin=token(); + body = Statement(); + jj_consume_token(WHILE); + jj_consume_token(LPAREN); + condition = Expression(); + jj_consume_token(RPAREN); + jj_consume_token(SEMICOLON); +return new DoStmt(range(begin, token()),body, condition); +} + + final public Statement ForStatement() throws ParseException {VariableDeclarationExpr varExpr = null; + Expression expr = null; + NodeList init = emptyList(); + NodeList update = emptyList(); + Statement body; + JavaToken begin; + jj_consume_token(FOR); +begin=token(); + jj_consume_token(LPAREN); + if (jj_2_45(2147483647)) { + varExpr = VariableDeclarationExpression(); + jj_consume_token(COLON); + expr = Expression(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FALSE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case NATIVE: + case NEW: + case NULL: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SUPER: + case SYNCHRONIZED: + case THIS: + case TRANSIENT: + case TRUE: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case SEMICOLON: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FALSE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case NATIVE: + case NEW: + case NULL: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SUPER: + case SYNCHRONIZED: + case THIS: + case TRANSIENT: + case TRUE: + case VOID: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + init = ForInit(); + break; + } + default: + jj_la1[131] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + expr = Expression(); + break; + } + default: + jj_la1[132] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + update = ForUpdate(); + break; + } + default: + jj_la1[133] = jj_gen; + ; + } + break; + } + default: + jj_la1[134] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(RPAREN); + body = Statement(); +if (varExpr != null) { + return new ForeachStmt(range(begin, token()),varExpr, expr, body); + } + return new ForStmt(range(begin, token()),init, expr, update, body); +} + + final public NodeList ForInit() throws ParseException {NodeList ret; + Expression expr; + if (jj_2_46(2147483647)) { + expr = VariableDeclarationExpression(); +ret = new NodeList(); ret.add(expr); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + ret = ExpressionList(); + break; + } + default: + jj_la1[135] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public NodeList ExpressionList() throws ParseException {NodeList ret = new NodeList(); + Expression expr; + expr = Expression(); +ret.add(expr); + label_45: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[136] = jj_gen; + break label_45; + } + jj_consume_token(COMMA); + expr = Expression(); +ret.add(expr); + } +return ret; +} + + final public NodeList ForUpdate() throws ParseException {NodeList ret; + ret = ExpressionList(); +return ret; +} + + final public BreakStmt BreakStatement() throws ParseException {SimpleName label = null; + JavaToken begin; + jj_consume_token(BREAK); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + label = SimpleName(); + break; + } + default: + jj_la1[137] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +return new BreakStmt(range(begin, token()), label); +} + + final public ContinueStmt ContinueStatement() throws ParseException {SimpleName label = null; + JavaToken begin; + jj_consume_token(CONTINUE); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + label = SimpleName(); + break; + } + default: + jj_la1[138] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +return new ContinueStmt(range(begin, token()), label); +} + + final public ReturnStmt ReturnStatement() throws ParseException {Expression expr = null; + JavaToken begin; + jj_consume_token(RETURN); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + expr = Expression(); + break; + } + default: + jj_la1[139] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +return new ReturnStmt(range(begin, token()),expr); +} + + final public ThrowStmt ThrowStatement() throws ParseException {Expression expr; + JavaToken begin; + jj_consume_token(THROW); +begin=token(); + expr = Expression(); + jj_consume_token(SEMICOLON); +return new ThrowStmt(range(begin, token()),expr); +} + + final public SynchronizedStmt SynchronizedStatement() throws ParseException {Expression expr; + BlockStmt body; + JavaToken begin; + jj_consume_token(SYNCHRONIZED); +begin=token(); + jj_consume_token(LPAREN); + expr = Expression(); + jj_consume_token(RPAREN); + body = Block(); +return new SynchronizedStmt(range(begin, token()),expr, body); +} + + final public TryStmt TryStatement() throws ParseException {NodeList resources = emptyList(); + BlockStmt tryBlock; + BlockStmt finallyBlock = null; + NodeList catchs = emptyList(); + BlockStmt catchBlock; + ModifierHolder exceptModifier; + ReferenceType exceptionType; + NodeList exceptionTypes = emptyList(); + Pair> exceptId; + JavaToken begin; + JavaToken catchBegin; + JavaToken typesBegin; + JavaToken paramEnd; + Type type; + jj_consume_token(TRY); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN:{ + resources = ResourceSpecification(); + break; + } + default: + jj_la1[140] = jj_gen; + ; + } + tryBlock = Block(); + label_46: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CATCH:{ + ; + break; + } + default: + jj_la1[141] = jj_gen; + break label_46; + } + jj_consume_token(CATCH); +catchBegin=token(); + jj_consume_token(LPAREN); +typesBegin=token(); + exceptModifier = Modifiers(); + exceptionType = ReferenceType(emptyList()); +exceptionTypes.add(exceptionType); + label_47: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BIT_OR:{ + ; + break; + } + default: + jj_la1[142] = jj_gen; + break label_47; + } + jj_consume_token(BIT_OR); + exceptionType = AnnotatedReferenceType(); +exceptionTypes.add(exceptionType); + } + exceptId = VariableDeclaratorId(); +paramEnd = token(); + jj_consume_token(RPAREN); + catchBlock = Block(); +if (exceptionTypes.size() > 1) { + type = new UnionType(range(exceptionTypes.get(0), exceptionTypes.get(exceptionTypes.size() - 1)), exceptionTypes); + } else { + type = (Type)exceptionTypes.get(0); + } + Parameter catchType = new Parameter(range(type, paramEnd), exceptModifier.modifiers, exceptModifier.annotations, type, false, emptyList(), exceptId.a); + catchs = add(catchs, new CatchClause(range(catchBegin, token()), catchType, catchBlock)); + exceptionTypes = emptyList(); + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case FINALLY:{ + jj_consume_token(FINALLY); + finallyBlock = Block(); + break; + } + default: + jj_la1[143] = jj_gen; + ; + } +return new TryStmt(range(begin, token()), resources, tryBlock, catchs, finallyBlock); +} + + final public NodeList ResourceSpecification() throws ParseException {NodeList variables; + jj_consume_token(LPAREN); + variables = Resources(); + if (jj_2_47(2)) { + jj_consume_token(SEMICOLON); + } else { + ; + } + jj_consume_token(RPAREN); +return variables; +} + + final public NodeList Resources() throws ParseException {NodeList expressions = new NodeList(); + Expression expr; + expr = Resource(); +expressions.add(expr); + label_48: + while (true) { + if (jj_2_48(2)) { + ; + } else { + break label_48; + } + jj_consume_token(SEMICOLON); + expr = Resource(); +expressions.add(expr); + } +return expressions; +} + + final public Expression Resource() throws ParseException {Expression expr; + if (jj_2_49(2147483647)) { + /*this is a bit more lenient than we need to be, eg allowing access modifiers like private*/ + expr = VariableDeclarationExpression(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT:{ + expr = PrimaryExpression(); + break; + } + default: + jj_la1[144] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return expr; +} + +/* We use productions to match >>>, >> and > so that we can keep the + * type declaration syntax with generics clean + */ + final public +void RUNSIGNEDSHIFT() throws ParseException { + if (getToken(1).kind == GT && + getToken(1).realKind == RUNSIGNEDSHIFT) { + + } else { + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(GT); + jj_consume_token(GT); + jj_consume_token(GT); +} + + final public void RSIGNEDSHIFT() throws ParseException { + if (getToken(1).kind == GT && + getToken(1).realKind == RSIGNEDSHIFT) { + + } else { + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(GT); + jj_consume_token(GT); +} + +/* Annotation syntax follows. */ + final public +NodeList Annotations() throws ParseException {NodeList annotations = new NodeList(); + AnnotationExpr annotation; + label_49: + while (true) { + if (jj_2_50(2147483647)) { + ; + } else { + break label_49; + } + annotation = Annotation(); +annotations = add(annotations, annotation); + } +return annotations; +} + + final public AnnotationExpr Annotation() throws ParseException {AnnotationExpr ret; + Name name; + NodeList pairs = emptyList(); + JavaToken begin; + Expression memberVal; + jj_consume_token(AT); +begin=token(); + name = Name(); + if (jj_2_51(2147483647)) { + jj_consume_token(LPAREN); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ENUM: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + pairs = MemberValuePairs(); + break; + } + default: + jj_la1[145] = jj_gen; + ; + } + jj_consume_token(RPAREN); +ret = new NormalAnnotationExpr(range(begin, token()), name, pairs); + } else if (jj_2_52(2147483647)) { + jj_consume_token(LPAREN); + memberVal = MemberValue(); + jj_consume_token(RPAREN); +ret = new SingleMemberAnnotationExpr(range(begin, token()), name, memberVal); + } else { +ret = new MarkerAnnotationExpr(range(begin, token()), name); + } +return ret; +} + + final public NodeList MemberValuePairs() throws ParseException {NodeList ret = new NodeList(); + MemberValuePair pair; + pair = MemberValuePair(); +ret.add(pair); + label_50: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[146] = jj_gen; + break label_50; + } + jj_consume_token(COMMA); + pair = MemberValuePair(); +ret.add(pair); + } +return ret; +} + + final public MemberValuePair MemberValuePair() throws ParseException {SimpleName name; + Expression value; + JavaToken begin; + name = SimpleName(); +begin=token(); + jj_consume_token(ASSIGN); + value = MemberValue(); +return new MemberValuePair(range(begin, token()),name, value); +} + + final public Expression MemberValue() throws ParseException {Expression ret; + if (jj_2_53(2147483647)) { + ret = Annotation(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + ret = MemberValueArrayInitializer(); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + ret = ConditionalExpression(); + break; + } + default: + jj_la1[147] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return ret; +} + + final public Expression MemberValueArrayInitializer() throws ParseException {NodeList ret = emptyList(); + Expression member; + JavaToken begin; + jj_consume_token(LBRACE); +begin=token(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case AT: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + member = MemberValue(); +ret.add(member); + label_51: + while (true) { + if (jj_2_54(2)) { + ; + } else { + break label_51; + } + jj_consume_token(COMMA); + member = MemberValue(); +ret.add(member); + } + break; + } + default: + jj_la1[148] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + jj_consume_token(COMMA); + break; + } + default: + jj_la1[149] = jj_gen; + ; + } + jj_consume_token(RBRACE); +return new ArrayInitializerExpr(range(begin, token()),ret); +} + +/* Annotation Types. */ + final public +AnnotationDeclaration AnnotationTypeDeclaration(ModifierHolder modifier) throws ParseException {SimpleName name; + NodeList> members = emptyList(); + JavaToken begin = modifier.begin; + jj_consume_token(AT); +begin=orIfInvalid(begin, token()); + jj_consume_token(INTERFACE); + name = SimpleName(); + members = AnnotationTypeBody(); +return new AnnotationDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, members); +} + + final public NodeList> AnnotationTypeBody() throws ParseException {NodeList> ret = emptyList(); + BodyDeclaration member; + jj_consume_token(LBRACE); + label_52: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case SEMICOLON: + case AT:{ + ; + break; + } + default: + jj_la1[150] = jj_gen; + break label_52; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case _DEFAULT: + case DOUBLE: + case ENUM: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case STRICTFP: + case SYNCHRONIZED: + case TRANSIENT: + case VOLATILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER: + case AT:{ + member = AnnotationBodyDeclaration(); +ret = addWhenNotNull(ret, member); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[151] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(RBRACE); +return ret; +} + + final public BodyDeclaration AnnotationBodyDeclaration() throws ParseException {ModifierHolder modifier; + BodyDeclaration ret; + modifier = Modifiers(); + if (jj_2_55(2147483647)) { + ret = AnnotationTypeMemberDeclaration(modifier); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS: + case INTERFACE:{ + ret = ClassOrInterfaceDeclaration(modifier); + break; + } + default: + jj_la1[152] = jj_gen; + if (jj_2_56(2147483647)) { + ret = EnumDeclaration(modifier); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case AT:{ + ret = AnnotationTypeDeclaration(modifier); + break; + } + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FLOAT: + case INT: + case LONG: + case SHORT: + case STRICTFP: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case IDENTIFIER:{ + ret = FieldDeclaration(modifier); + break; + } + default: + jj_la1[153] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } +return ret; +} + + final public AnnotationMemberDeclaration AnnotationTypeMemberDeclaration(ModifierHolder modifier) throws ParseException {Type type; + SimpleName name; + Expression defaultVal = null; + type = Type(emptyList()); + name = SimpleName(); + jj_consume_token(LPAREN); + jj_consume_token(RPAREN); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case _DEFAULT:{ + defaultVal = DefaultValue(); + break; + } + default: + jj_la1[154] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +JavaToken begin = orIfInvalid(modifier.begin, type); + return new AnnotationMemberDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, type, name, defaultVal); +} + + final public Expression DefaultValue() throws ParseException {Expression ret; + jj_consume_token(_DEFAULT); + ret = MemberValue(); +return ret; +} + +/* Module syntax follows */ + final public + +ModuleStmt ModuleStmt() throws ParseException {ModifierHolder modifiers; + Name name; + Name tmpName; + NodeList names=emptyList(); + Type type; + Type tmpType; + NodeList types=emptyList(); + JavaToken begin; + ModuleStmt stmt=new ModuleRequiresStmt(); + JavaToken transitiveExceptionalToken; + if (jj_2_57(2147483647)) { + jj_consume_token(REQUIRES); +begin=token(); + jj_consume_token(TRANSITIVE); +transitiveExceptionalToken=token(); setTokenKind(IDENTIFIER); + jj_consume_token(SEMICOLON); +stmt=new ModuleRequiresStmt(range(begin, token()), EnumSet.noneOf(Modifier.class), new Name(range(transitiveExceptionalToken, transitiveExceptionalToken), null, transitiveExceptionalToken.getText(), new NodeList())); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case REQUIRES:{ + jj_consume_token(REQUIRES); +begin=token(); + modifiers = Modifiers(); + name = Name(); + jj_consume_token(SEMICOLON); +stmt=new ModuleRequiresStmt(range(begin, token()), modifiers.modifiers, name); + break; + } + case EXPORTS:{ + jj_consume_token(EXPORTS); +begin=token(); + name = Name(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TO:{ + jj_consume_token(TO); + tmpName = Name(); +names.add(tmpName); + label_53: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[155] = jj_gen; + break label_53; + } + jj_consume_token(COMMA); + tmpName = Name(); +names.add(tmpName); + } + break; + } + default: + jj_la1[156] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +stmt=new ModuleExportsStmt(range(begin, token()), name, names); + break; + } + case OPENS:{ + jj_consume_token(OPENS); +begin=token(); + name = Name(); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TO:{ + jj_consume_token(TO); + tmpName = Name(); +names.add(tmpName); + label_54: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[157] = jj_gen; + break label_54; + } + jj_consume_token(COMMA); + tmpName = Name(); +names.add(tmpName); + } + break; + } + default: + jj_la1[158] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +stmt=new ModuleOpensStmt(range(begin, token()), name, names); + break; + } + case USES:{ + jj_consume_token(USES); +begin=token(); + type = Type(emptyList()); + jj_consume_token(SEMICOLON); +stmt=new ModuleUsesStmt(range(begin, token()), type); + break; + } + case PROVIDES:{ + jj_consume_token(PROVIDES); +begin=token(); + type = Type(emptyList()); + jj_consume_token(WITH); + tmpType = Type(emptyList()); +types.add(tmpType); + label_55: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case COMMA:{ + ; + break; + } + default: + jj_la1[159] = jj_gen; + break label_55; + } + jj_consume_token(COMMA); + tmpType = Type(emptyList()); +types.add(tmpType); + } + jj_consume_token(SEMICOLON); +stmt=new ModuleProvidesStmt(range(begin, token()), type, types); + break; + } + default: + jj_la1[160] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +return stmt; +} + + final public ModuleDeclaration ModuleDeclaration(ModifierHolder modifier) throws ParseException {NodeList statements = new NodeList(); + boolean open=false; + ModuleStmt st; + Name name; + JavaToken begin = modifier.begin; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case OPEN:{ + jj_consume_token(OPEN); +open=true; begin = orIfInvalid(begin, token()); + break; + } + default: + jj_la1[161] = jj_gen; + ; + } + jj_consume_token(MODULE); +begin = orIfInvalid(begin, token()); + name = Name(); + jj_consume_token(LBRACE); + label_56: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case REQUIRES: + case OPENS: + case USES: + case EXPORTS: + case PROVIDES:{ + ; + break; + } + default: + jj_la1[162] = jj_gen; + break label_56; + } + st = ModuleStmt(); +statements = add(statements, st); + } + jj_consume_token(RBRACE); +return new ModuleDeclaration(range(begin, token()), modifier.annotations, name, open, statements); +} + +/* Rules for matching partial inputs. +These rules are needed to properly terminate them - +if we simply use the usual rules, they will ignore everything in the provider +after they matched their desired input, which will lead to unexpected behaviour +*/ + final public + +BlockStmt BlockParseStart() throws ParseException {BlockStmt ret; + ret = Block(); + jj_consume_token(0); +return ret; +} + + final public Statement BlockStatementParseStart() throws ParseException {Statement ret; + if (jj_2_58(3)) { + ret = BlockStatement(); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case ENUM: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case STRICTFP: + case SUPER: + case THIS: + case TRUE: + case VOID: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + case LONG_LITERAL: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case AT: + case LT:{ + ret = ExplicitConstructorInvocation(); + break; + } + default: + jj_la1[163] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(0); +return ret; +} + + final public ImportDeclaration ImportDeclarationParseStart() throws ParseException {ImportDeclaration ret; + ret = ImportDeclaration(); + jj_consume_token(0); +return ret; +} + + final public Expression ExpressionParseStart() throws ParseException {Expression ret; + ret = Expression(); + jj_consume_token(0); +return ret; +} + + final public AnnotationExpr AnnotationParseStart() throws ParseException {AnnotationExpr ret; + ret = Annotation(); + jj_consume_token(0); +return ret; +} + + final public BodyDeclaration AnnotationBodyDeclarationParseStart() throws ParseException {BodyDeclaration ret; + ret = AnnotationBodyDeclaration(); + jj_consume_token(0); +return ret; +} + + final public BodyDeclaration ClassOrInterfaceBodyDeclarationParseStart() throws ParseException {BodyDeclaration ret; + ret = ClassOrInterfaceBodyDeclaration(); + jj_consume_token(0); +return ret; +} + + final public ClassOrInterfaceType ClassOrInterfaceTypeParseStart() throws ParseException {ClassOrInterfaceType ret; + ret = AnnotatedClassOrInterfaceType(); + jj_consume_token(0); +return ret; +} + + final public Type ResultTypeParseStart() throws ParseException {NodeList annotations; Type ret; + annotations = Annotations(); + ret = ResultType(annotations); + jj_consume_token(0); +return ret; +} + + final public VariableDeclarationExpr VariableDeclarationExpressionParseStart() throws ParseException {VariableDeclarationExpr ret; + ret = VariableDeclarationExpression(); + jj_consume_token(0); +return ret; +} + + final public ExplicitConstructorInvocationStmt ExplicitConstructorInvocationParseStart() throws ParseException {ExplicitConstructorInvocationStmt ret; + ret = ExplicitConstructorInvocation(); + jj_consume_token(0); +return ret; +} + + final public Name NameParseStart() throws ParseException {Name ret; + ret = Name(); + jj_consume_token(0); +return ret; +} + + final public SimpleName SimpleNameParseStart() throws ParseException {SimpleName ret; + ret = SimpleName(); + jj_consume_token(0); +return ret; +} + + final public Parameter ParameterParseStart() throws ParseException {Parameter ret; + ret = Parameter(); + jj_consume_token(0); +return ret; +} + + final public PackageDeclaration PackageDeclarationParseStart() throws ParseException {PackageDeclaration ret; + ret = PackageDeclaration(); + jj_consume_token(0); +return ret; +} + + private boolean jj_2_1(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_1()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_2()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_3()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_4()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_5()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_6()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_2_7(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_7()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + private boolean jj_2_8(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_8()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + private boolean jj_2_9(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_9()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + + private boolean jj_2_10(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_10()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(9, xla); } + } + + private boolean jj_2_11(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_11()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(10, xla); } + } + + private boolean jj_2_12(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_12()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(11, xla); } + } + + private boolean jj_2_13(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_13()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(12, xla); } + } + + private boolean jj_2_14(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_14()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(13, xla); } + } + + private boolean jj_2_15(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_15()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(14, xla); } + } + + private boolean jj_2_16(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_16()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(15, xla); } + } + + private boolean jj_2_17(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_17()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(16, xla); } + } + + private boolean jj_2_18(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_18()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(17, xla); } + } + + private boolean jj_2_19(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_19()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(18, xla); } + } + + private boolean jj_2_20(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_20()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(19, xla); } + } + + private boolean jj_2_21(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_21()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(20, xla); } + } + + private boolean jj_2_22(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_22()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(21, xla); } + } + + private boolean jj_2_23(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_23()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(22, xla); } + } + + private boolean jj_2_24(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_24()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(23, xla); } + } + + private boolean jj_2_25(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_25()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(24, xla); } + } + + private boolean jj_2_26(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_26()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(25, xla); } + } + + private boolean jj_2_27(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_27()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(26, xla); } + } + + private boolean jj_2_28(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_28()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(27, xla); } + } + + private boolean jj_2_29(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_29()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(28, xla); } + } + + private boolean jj_2_30(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_30()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(29, xla); } + } + + private boolean jj_2_31(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_31()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(30, xla); } + } + + private boolean jj_2_32(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_32()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(31, xla); } + } + + private boolean jj_2_33(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_33()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(32, xla); } + } + + private boolean jj_2_34(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_34()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(33, xla); } + } + + private boolean jj_2_35(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_35()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(34, xla); } + } + + private boolean jj_2_36(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_36()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(35, xla); } + } + + private boolean jj_2_37(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_37()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(36, xla); } + } + + private boolean jj_2_38(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_38()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(37, xla); } + } + + private boolean jj_2_39(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_39()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(38, xla); } + } + + private boolean jj_2_40(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_40()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(39, xla); } + } + + private boolean jj_2_41(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_41()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(40, xla); } + } + + private boolean jj_2_42(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_42()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(41, xla); } + } + + private boolean jj_2_43(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_43()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(42, xla); } + } + + private boolean jj_2_44(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_44()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(43, xla); } + } + + private boolean jj_2_45(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_45()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(44, xla); } + } + + private boolean jj_2_46(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_46()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(45, xla); } + } + + private boolean jj_2_47(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_47()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(46, xla); } + } + + private boolean jj_2_48(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_48()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(47, xla); } + } + + private boolean jj_2_49(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_49()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(48, xla); } + } + + private boolean jj_2_50(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_50()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(49, xla); } + } + + private boolean jj_2_51(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_51()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(50, xla); } + } + + private boolean jj_2_52(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_52()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(51, xla); } + } + + private boolean jj_2_53(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_53()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(52, xla); } + } + + private boolean jj_2_54(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_54()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(53, xla); } + } + + private boolean jj_2_55(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_55()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(54, xla); } + } + + private boolean jj_2_56(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_56()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(55, xla); } + } + + private boolean jj_2_57(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_57()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(56, xla); } + } + + private boolean jj_2_58(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return (!jj_3_58()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(57, xla); } + } + + private boolean jj_3R_304() + { + if (jj_scan_token(EXTENDS)) return true; + if (jj_3R_306()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_408()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_296() + { + if (jj_3R_324()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_364()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_227() + { + if (jj_scan_token(INTERFACE)) return true; + return false; + } + + private boolean jj_3R_262() + { + if (jj_3R_305()) return true; + return false; + } + + private boolean jj_3R_286() + { + if (jj_scan_token(DO)) return true; + if (jj_3R_195()) return true; + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_261() + { + if (jj_3R_304()) return true; + return false; + } + + private boolean jj_3R_260() + { + if (jj_3R_117()) return true; + return false; + } + + private boolean jj_3R_248() + { + if (jj_3R_296()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_348()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_194() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(19)) { + jj_scanpos = xsp; + if (jj_3R_227()) return true; + } + if (jj_3R_88()) return true; + xsp = jj_scanpos; + if (jj_3R_260()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_261()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_262()) jj_scanpos = xsp; + if (jj_3R_105()) return true; + return false; + } + + private boolean jj_3R_169() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_112()) return true; + return false; + } + + private boolean jj_3R_285() + { + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_195()) return true; + return false; + } + + private boolean jj_3R_328() + { + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_200() + { + if (jj_3R_248()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_325()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_300() + { + if (jj_scan_token(HOOK)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_149()) return true; + return false; + } + + private boolean jj_3R_149() + { + if (jj_3R_200()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_300()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_284() + { + if (jj_scan_token(IF)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_195()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_411()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_71() + { + if (jj_3R_115()) return true; + return false; + } + + private boolean jj_3R_70() + { + if (jj_scan_token(_DEFAULT)) return true; + return false; + } + + private boolean jj_3R_69() + { + if (jj_scan_token(TRANSITIVE)) return true; + return false; + } + + private boolean jj_3R_148() + { + if (jj_scan_token(ORASSIGN)) return true; + return false; + } + + private boolean jj_3R_147() + { + if (jj_scan_token(XORASSIGN)) return true; + return false; + } + + private boolean jj_3R_68() + { + if (jj_scan_token(STRICTFP)) return true; + return false; + } + + private boolean jj_3R_146() + { + if (jj_scan_token(ANDASSIGN)) return true; + return false; + } + + private boolean jj_3R_145() + { + if (jj_scan_token(RUNSIGNEDSHIFTASSIGN)) return true; + return false; + } + + private boolean jj_3R_431() + { + if (jj_scan_token(_DEFAULT)) return true; + return false; + } + + private boolean jj_3R_67() + { + if (jj_scan_token(VOLATILE)) return true; + return false; + } + + private boolean jj_3R_144() + { + if (jj_scan_token(RSIGNEDSHIFTASSIGN)) return true; + return false; + } + + private boolean jj_3R_143() + { + if (jj_scan_token(LSHIFTASSIGN)) return true; + return false; + } + + private boolean jj_3R_430() + { + if (jj_scan_token(CASE)) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_66() + { + if (jj_scan_token(TRANSIENT)) return true; + return false; + } + + private boolean jj_3R_142() + { + if (jj_scan_token(MINUSASSIGN)) return true; + return false; + } + + private boolean jj_3R_141() + { + if (jj_scan_token(PLUSASSIGN)) return true; + return false; + } + + private boolean jj_3R_65() + { + if (jj_scan_token(NATIVE)) return true; + return false; + } + + private boolean jj_3R_140() + { + if (jj_scan_token(REMASSIGN)) return true; + return false; + } + + private boolean jj_3R_139() + { + if (jj_scan_token(SLASHASSIGN)) return true; + return false; + } + + private boolean jj_3R_64() + { + if (jj_scan_token(SYNCHRONIZED)) return true; + return false; + } + + private boolean jj_3R_138() + { + if (jj_scan_token(STARASSIGN)) return true; + return false; + } + + private boolean jj_3R_327() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_137() + { + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + private boolean jj_3R_63() + { + if (jj_scan_token(ABSTRACT)) return true; + return false; + } + + private boolean jj_3R_62() + { + if (jj_scan_token(FINAL)) return true; + return false; + } + + private boolean jj_3R_424() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_430()) { + jj_scanpos = xsp; + if (jj_3R_431()) return true; + } + if (jj_scan_token(COLON)) return true; + if (jj_3R_179()) return true; + return false; + } + + private boolean jj_3R_61() + { + if (jj_scan_token(PRIVATE)) return true; + return false; + } + + private boolean jj_3R_89() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_137()) { + jj_scanpos = xsp; + if (jj_3R_138()) { + jj_scanpos = xsp; + if (jj_3R_139()) { + jj_scanpos = xsp; + if (jj_3R_140()) { + jj_scanpos = xsp; + if (jj_3R_141()) { + jj_scanpos = xsp; + if (jj_3R_142()) { + jj_scanpos = xsp; + if (jj_3R_143()) { + jj_scanpos = xsp; + if (jj_3R_144()) { + jj_scanpos = xsp; + if (jj_3R_145()) { + jj_scanpos = xsp; + if (jj_3R_146()) { + jj_scanpos = xsp; + if (jj_3R_147()) { + jj_scanpos = xsp; + if (jj_3R_148()) return true; + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_302() + { + if (jj_scan_token(DOUBLECOLON)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_327()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_328()) { + jj_scanpos = xsp; + if (jj_scan_token(42)) return true; + } + return false; + } + + private boolean jj_3R_60() + { + if (jj_scan_token(PROTECTED)) return true; + return false; + } + + private boolean jj_3R_59() + { + if (jj_scan_token(STATIC)) return true; + return false; + } + + private boolean jj_3R_58() + { + if (jj_scan_token(PUBLIC)) return true; + return false; + } + + private boolean jj_3R_410() + { + if (jj_3R_424()) return true; + return false; + } + + private boolean jj_3_3() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_58()) { + jj_scanpos = xsp; + if (jj_3R_59()) { + jj_scanpos = xsp; + if (jj_3R_60()) { + jj_scanpos = xsp; + if (jj_3R_61()) { + jj_scanpos = xsp; + if (jj_3R_62()) { + jj_scanpos = xsp; + if (jj_3R_63()) { + jj_scanpos = xsp; + if (jj_3R_64()) { + jj_scanpos = xsp; + if (jj_3R_65()) { + jj_scanpos = xsp; + if (jj_3R_66()) { + jj_scanpos = xsp; + if (jj_3R_67()) { + jj_scanpos = xsp; + if (jj_3R_68()) { + jj_scanpos = xsp; + if (jj_3R_69()) { + jj_scanpos = xsp; + if (jj_3R_70()) { + jj_scanpos = xsp; + if (jj_3R_71()) return true; + } + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_108() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_3()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_283() + { + if (jj_scan_token(SWITCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_410()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_301() + { + if (jj_scan_token(ARROW)) return true; + if (jj_3R_326()) return true; + return false; + } + + private boolean jj_3R_361() + { + if (jj_3R_89()) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_360() + { + if (jj_scan_token(DECR)) return true; + return false; + } + + private boolean jj_3_24() + { + if (jj_3R_89()) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_359() + { + if (jj_scan_token(INCR)) return true; + return false; + } + + private boolean jj_3R_343() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_359()) { + jj_scanpos = xsp; + if (jj_3R_360()) { + jj_scanpos = xsp; + if (jj_3R_361()) return true; + } + } + return false; + } + + private boolean jj_3R_255() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_24()) { + jj_scanpos = xsp; + if (jj_3R_301()) { + jj_scanpos = xsp; + if (jj_3R_302()) return true; + } + } + return false; + } + + private boolean jj_3R_318() + { + if (jj_3R_211()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_343()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_90() + { + if (jj_3R_149()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_255()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_317() + { + if (jj_3R_257()) return true; + return false; + } + + private boolean jj_3_44() + { + if (jj_3R_110()) return true; + return false; + } + + private boolean jj_3R_282() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_44()) { + jj_scanpos = xsp; + if (jj_3R_317()) { + jj_scanpos = xsp; + if (jj_3R_318()) return true; + } + } + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_57() + { + if (jj_3R_86()) return true; + if (jj_scan_token(PACKAGE)) return true; + if (jj_3R_80()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_350() + { + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_349() + { + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_74() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(70)) { + jj_scanpos = xsp; + if (jj_scan_token(64)) { + jj_scanpos = xsp; + if (jj_scan_token(65)) { + jj_scanpos = xsp; + if (jj_scan_token(66)) { + jj_scanpos = xsp; + if (jj_scan_token(67)) { + jj_scanpos = xsp; + if (jj_scan_token(68)) { + jj_scanpos = xsp; + if (jj_scan_token(69)) { + jj_scanpos = xsp; + if (jj_scan_token(71)) { + jj_scanpos = xsp; + if (jj_scan_token(72)) { + jj_scanpos = xsp; + if (jj_scan_token(73)) { + jj_scanpos = xsp; + if (jj_scan_token(26)) { + jj_scanpos = xsp; + if (jj_scan_token(51)) { + jj_scanpos = xsp; + if (jj_scan_token(89)) return true; + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_326() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_349()) { + jj_scanpos = xsp; + if (jj_3R_350()) return true; + } + return false; + } + + private boolean jj_3_2() + { + if (jj_3R_57()) return true; + return false; + } + + private boolean jj_3_23() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_86()) return true; + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_281() + { + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_88() + { + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3_1() + { + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_125() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_86()) return true; + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_109() + { + if (jj_3R_108()) return true; + if (jj_3R_75()) return true; + if (jj_3R_112()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_169()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_80() + { + if (jj_3R_86()) return true; + if (jj_3R_74()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_125()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_43() + { + if (jj_3R_109()) return true; + return false; + } + + private boolean jj_3_42() + { + if (jj_3R_108()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(19)) { + jj_scanpos = xsp; + if (jj_scan_token(39)) return true; + } + return false; + } + + private boolean jj_3R_132() + { + if (jj_3R_195()) return true; + return false; + } + + private boolean jj_3R_167() + { + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_166() + { + if (jj_scan_token(VOID)) return true; + return false; + } + + private boolean jj_3R_131() + { + if (jj_3R_109()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_130() + { + if (jj_3R_108()) return true; + if (jj_3R_194()) return true; + return false; + } + + private boolean jj_3R_102() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_166()) { + jj_scanpos = xsp; + if (jj_3R_167()) return true; + } + return false; + } + + private boolean jj_3R_336() + { + if (jj_scan_token(COLON)) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_84() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_130()) { + jj_scanpos = xsp; + if (jj_3R_131()) { + jj_scanpos = xsp; + if (jj_3R_132()) return true; + } + } + return false; + } + + private boolean jj_3R_160() + { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + private boolean jj_3R_159() + { + if (jj_scan_token(FLOAT)) return true; + return false; + } + + private boolean jj_3R_158() + { + if (jj_scan_token(LONG)) return true; + return false; + } + + private boolean jj_3R_157() + { + if (jj_scan_token(INT)) return true; + return false; + } + + private boolean jj_3R_156() + { + if (jj_scan_token(SHORT)) return true; + return false; + } + + private boolean jj_3R_155() + { + if (jj_scan_token(BYTE)) return true; + return false; + } + + private boolean jj_3R_154() + { + if (jj_scan_token(CHAR)) return true; + return false; + } + + private boolean jj_3R_358() + { + if (jj_scan_token(SUPER)) return true; + if (jj_3R_86()) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_226() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_199()) return true; + return false; + } + + private boolean jj_3R_153() + { + if (jj_scan_token(BOOLEAN)) return true; + return false; + } + + private boolean jj_3R_357() + { + if (jj_scan_token(EXTENDS)) return true; + if (jj_3R_86()) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_342() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_357()) { + jj_scanpos = xsp; + if (jj_3R_358()) return true; + } + return false; + } + + private boolean jj_3R_97() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_153()) { + jj_scanpos = xsp; + if (jj_3R_154()) { + jj_scanpos = xsp; + if (jj_3R_155()) { + jj_scanpos = xsp; + if (jj_3R_156()) { + jj_scanpos = xsp; + if (jj_3R_157()) { + jj_scanpos = xsp; + if (jj_3R_158()) { + jj_scanpos = xsp; + if (jj_3R_159()) { + jj_scanpos = xsp; + if (jj_3R_160()) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_121() + { + if (jj_scan_token(LBRACE)) return true; + if (jj_3R_179()) return true; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_295() + { + if (jj_scan_token(HOOK)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_342()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_107() + { + if (jj_3R_88()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_195()) return true; + return false; + } + + private boolean jj_3R_280() + { + if (jj_scan_token(ASSERT)) return true; + if (jj_3R_90()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_336()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_247() + { + if (jj_3R_295()) return true; + return false; + } + + private boolean jj_3R_246() + { + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_242() + { + if (jj_3R_293()) return true; + return false; + } + + private boolean jj_3R_199() + { + if (jj_3R_86()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_246()) { + jj_scanpos = xsp; + if (jj_3R_247()) return true; + } + return false; + } + + private boolean jj_3R_241() + { + if (jj_3R_292()) return true; + return false; + } + + private boolean jj_3R_240() + { + if (jj_3R_291()) return true; + return false; + } + + private boolean jj_3R_239() + { + if (jj_3R_290()) return true; + return false; + } + + private boolean jj_3R_238() + { + if (jj_3R_289()) return true; + return false; + } + + private boolean jj_3R_136() + { + if (jj_3R_199()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_226()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_237() + { + if (jj_3R_288()) return true; + return false; + } + + private boolean jj_3R_236() + { + if (jj_3R_287()) return true; + return false; + } + + private boolean jj_3R_87() + { + if (jj_scan_token(LT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_136()) jj_scanpos = xsp; + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_235() + { + if (jj_3R_286()) return true; + return false; + } + + private boolean jj_3R_234() + { + if (jj_3R_285()) return true; + return false; + } + + private boolean jj_3R_233() + { + if (jj_3R_284()) return true; + return false; + } + + private boolean jj_3_22() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_232() + { + if (jj_3R_283()) return true; + return false; + } + + private boolean jj_3R_231() + { + if (jj_3R_282()) return true; + return false; + } + + private boolean jj_3_21() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_86()) return true; + if (jj_3R_88()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_22()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_230() + { + if (jj_3R_281()) return true; + return false; + } + + private boolean jj_3R_229() + { + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_393() + { + if (jj_scan_token(THROWS)) return true; + if (jj_3R_249()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_403()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_228() + { + if (jj_3R_280()) return true; + return false; + } + + private boolean jj_3_19() + { + if (jj_3R_86()) return true; + if (jj_scan_token(LBRACKET)) return true; + return false; + } + + private boolean jj_3_41() + { + if (jj_3R_107()) return true; + return false; + } + + private boolean jj_3_20() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_197() + { + if (jj_3R_88()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_20()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_21()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_195() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_41()) { + jj_scanpos = xsp; + if (jj_3R_228()) { + jj_scanpos = xsp; + if (jj_3R_229()) { + jj_scanpos = xsp; + if (jj_3R_230()) { + jj_scanpos = xsp; + if (jj_3R_231()) { + jj_scanpos = xsp; + if (jj_3R_232()) { + jj_scanpos = xsp; + if (jj_3R_233()) { + jj_scanpos = xsp; + if (jj_3R_234()) { + jj_scanpos = xsp; + if (jj_3R_235()) { + jj_scanpos = xsp; + if (jj_3R_236()) { + jj_scanpos = xsp; + if (jj_3R_237()) { + jj_scanpos = xsp; + if (jj_3R_238()) { + jj_scanpos = xsp; + if (jj_3R_239()) { + jj_scanpos = xsp; + if (jj_3R_240()) { + jj_scanpos = xsp; + if (jj_3R_241()) { + jj_scanpos = xsp; + if (jj_3R_242()) return true; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3_18() + { + if (jj_3R_86()) return true; + if (jj_scan_token(LBRACKET)) return true; + return false; + } + + private boolean jj_3R_198() + { + if (jj_3R_119()) return true; + return false; + } + + private boolean jj_3R_306() + { + if (jj_3R_86()) return true; + if (jj_3R_197()) return true; + return false; + } + + private boolean jj_3_39() + { + if (jj_3R_105()) return true; + return false; + } + + private boolean jj_3R_196() + { + if (jj_3R_119()) return true; + return false; + } + + private boolean jj_3R_106() + { + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_341() + { + if (jj_3R_180()) return true; + return false; + } + + private boolean jj_3_40() + { + if (jj_3R_86()) return true; + if (jj_scan_token(LBRACKET)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_106()) jj_scanpos = xsp; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_313() + { + Token xsp; + if (jj_3_40()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3_40()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_341()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_308() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_316() + { + if (jj_3R_183()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_39()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_315() + { + if (jj_3R_313()) return true; + return false; + } + + private boolean jj_3R_119() + { + if (jj_3R_86()) return true; + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_314() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_279() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_314()) jj_scanpos = xsp; + if (jj_3R_306()) return true; + xsp = jj_scanpos; + if (jj_3R_315()) { + jj_scanpos = xsp; + if (jj_3R_316()) return true; + } + return false; + } + + private boolean jj_3R_278() + { + if (jj_3R_97()) return true; + if (jj_3R_313()) return true; + return false; + } + + private boolean jj_3R_134() + { + if (jj_3R_197()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_198()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_133() + { + if (jj_3R_97()) return true; + Token xsp; + if (jj_3R_196()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_196()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_85() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_133()) { + jj_scanpos = xsp; + if (jj_3R_134()) return true; + } + return false; + } + + private boolean jj_3R_222() + { + if (jj_scan_token(NEW)) return true; + if (jj_3R_86()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_278()) { + jj_scanpos = xsp; + if (jj_3R_279()) return true; + } + return false; + } + + private boolean jj_3R_118() + { + if (jj_3R_97()) return true; + return false; + } + + private boolean jj_3_17() + { + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3_58() + { + if (jj_3R_84()) return true; + return false; + } + + private boolean jj_3R_75() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_17()) { + jj_scanpos = xsp; + if (jj_3R_118()) return true; + } + return false; + } + + private boolean jj_3R_264() + { + if (jj_3R_90()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_308()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_214() + { + if (jj_3R_264()) return true; + return false; + } + + private boolean jj_3R_120() + { + if (jj_scan_token(STATIC)) return true; + return false; + } + + private boolean jj_3R_183() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_214()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_77() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_120()) jj_scanpos = xsp; + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3_16() + { + if (jj_3R_84()) return true; + return false; + } + + private boolean jj_3R_179() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_16()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_14() + { + if (jj_3R_82()) return true; + if (jj_scan_token(DOT)) return true; + return false; + } + + private boolean jj_3R_340() + { + if (jj_scan_token(FALSE)) return true; + return false; + } + + private boolean jj_3R_310() + { + if (jj_scan_token(NULL)) return true; + return false; + } + + private boolean jj_3R_339() + { + if (jj_scan_token(TRUE)) return true; + return false; + } + + private boolean jj_3R_441() + { + if (jj_3R_442()) return true; + return false; + } + + private boolean jj_3R_83() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_185() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3_57() + { + if (jj_scan_token(REQUIRES)) return true; + if (jj_scan_token(TRANSITIVE)) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3_15() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_83()) jj_scanpos = xsp; + if (jj_scan_token(THIS)) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_184() + { + if (jj_3R_82()) return true; + if (jj_scan_token(DOT)) return true; + return false; + } + + private boolean jj_3R_309() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_339()) { + jj_scanpos = xsp; + if (jj_3R_340()) return true; + } + return false; + } + + private boolean jj_3R_127() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_184()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_185()) jj_scanpos = xsp; + if (jj_scan_token(SUPER)) return true; + if (jj_3R_183()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_271() + { + if (jj_3R_310()) return true; + return false; + } + + private boolean jj_3R_182() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_270() + { + if (jj_3R_309()) return true; + return false; + } + + private boolean jj_3R_126() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_182()) jj_scanpos = xsp; + if (jj_scan_token(THIS)) return true; + if (jj_3R_183()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_269() + { + if (jj_scan_token(STRING_LITERAL)) return true; + return false; + } + + private boolean jj_3R_268() + { + if (jj_scan_token(CHARACTER_LITERAL)) return true; + return false; + } + + private boolean jj_3R_81() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_126()) { + jj_scanpos = xsp; + if (jj_3R_127()) return true; + } + return false; + } + + private boolean jj_3R_267() + { + if (jj_scan_token(FLOATING_POINT_LITERAL)) return true; + return false; + } + + private boolean jj_3R_266() + { + if (jj_scan_token(LONG_LITERAL)) return true; + return false; + } + + private boolean jj_3_13() + { + if (jj_3R_81()) return true; + return false; + } + + private boolean jj_3R_265() + { + if (jj_scan_token(INTEGER_LITERAL)) return true; + return false; + } + + private boolean jj_3R_104() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_164() + { + if (jj_3R_86()) return true; + if (jj_scan_token(ELLIPSIS)) return true; + return false; + } + + private boolean jj_3_38() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_104()) jj_scanpos = xsp; + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_394() + { + if (jj_3R_81()) return true; + return false; + } + + private boolean jj_3R_215() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_265()) { + jj_scanpos = xsp; + if (jj_3R_266()) { + jj_scanpos = xsp; + if (jj_3R_267()) { + jj_scanpos = xsp; + if (jj_3R_268()) { + jj_scanpos = xsp; + if (jj_3R_269()) { + jj_scanpos = xsp; + if (jj_3R_270()) { + jj_scanpos = xsp; + if (jj_3R_271()) return true; + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_442() + { + if (jj_scan_token(_DEFAULT)) return true; + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_163() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_254() + { + if (jj_3R_183()) return true; + return false; + } + + private boolean jj_3R_403() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_249()) return true; + return false; + } + + private boolean jj_3R_224() + { + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_253() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_365() + { + if (jj_3R_117()) return true; + return false; + } + + private boolean jj_3R_353() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_365()) jj_scanpos = xsp; + if (jj_3R_88()) return true; + if (jj_3R_392()) return true; + xsp = jj_scanpos; + if (jj_3R_393()) jj_scanpos = xsp; + if (jj_scan_token(LBRACE)) return true; + xsp = jj_scanpos; + if (jj_3R_394()) jj_scanpos = xsp; + if (jj_3R_179()) return true; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_205() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_253()) jj_scanpos = xsp; + if (jj_3R_88()) return true; + xsp = jj_scanpos; + if (jj_3R_254()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_204() + { + if (jj_3R_222()) return true; + return false; + } + + private boolean jj_3_12() + { + if (jj_3R_80()) return true; + return false; + } + + private boolean jj_3_56() + { + if (jj_scan_token(ENUM)) return true; + return false; + } + + private boolean jj_3R_203() + { + if (jj_scan_token(THIS)) return true; + return false; + } + + private boolean jj_3R_439() + { + if (jj_3R_75()) return true; + if (jj_3R_88()) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_scan_token(RPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_441()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3_55() + { + if (jj_3R_75()) return true; + if (jj_3R_74()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_438() + { + if (jj_3R_354()) return true; + return false; + } + + private boolean jj_3R_437() + { + if (jj_3R_352()) return true; + return false; + } + + private boolean jj_3R_436() + { + if (jj_3R_351()) return true; + return false; + } + + private boolean jj_3R_181() + { + if (jj_3R_80()) return true; + if (jj_scan_token(DOT)) return true; + return false; + } + + private boolean jj_3R_162() + { + if (jj_scan_token(DOT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_203()) { + jj_scanpos = xsp; + if (jj_3R_204()) { + jj_scanpos = xsp; + if (jj_3R_205()) return true; + } + } + return false; + } + + private boolean jj_3R_435() + { + if (jj_3R_194()) return true; + return false; + } + + private boolean jj_3R_124() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_181()) jj_scanpos = xsp; + if (jj_3R_86()) return true; + if (jj_scan_token(THIS)) return true; + return false; + } + + private boolean jj_3R_434() + { + if (jj_3R_439()) return true; + return false; + } + + private boolean jj_3_54() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_99() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_162()) { + jj_scanpos = xsp; + if (jj_3R_163()) return true; + } + return false; + } + + private boolean jj_3R_311() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_100()) return true; + return false; + } + + private boolean jj_3R_223() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_79() + { + if (jj_3R_86()) return true; + if (jj_3R_75()) return true; + if (jj_3R_124()) return true; + return false; + } + + private boolean jj_3R_161() + { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(SUPER)) return true; + return false; + } + + private boolean jj_3R_429() + { + if (jj_3R_108()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_434()) { + jj_scanpos = xsp; + if (jj_3R_435()) { + jj_scanpos = xsp; + if (jj_3R_436()) { + jj_scanpos = xsp; + if (jj_3R_437()) { + jj_scanpos = xsp; + if (jj_3R_438()) return true; + } + } + } + } + return false; + } + + private boolean jj_3_37() + { + if (jj_3R_99()) return true; + return false; + } + + private boolean jj_3R_417() + { + if (jj_3R_429()) return true; + return false; + } + + private boolean jj_3R_401() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_417()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + private boolean jj_3R_275() + { + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_98() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_37()) { + jj_scanpos = xsp; + if (jj_3R_161()) return true; + } + return false; + } + + private boolean jj_3R_225() + { + if (jj_3R_183()) return true; + return false; + } + + private boolean jj_3R_391() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_401()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_193() + { + if (jj_3R_88()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_225()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_100() + { + if (jj_3R_108()) return true; + if (jj_3R_75()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_164()) jj_scanpos = xsp; + if (jj_3R_101()) return true; + return false; + } + + private boolean jj_3_36() + { + if (jj_3R_103()) return true; + if (jj_scan_token(DOUBLECOLON)) return true; + return false; + } + + private boolean jj_3_35() + { + if (jj_3R_102()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3R_312() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_101()) return true; + return false; + } + + private boolean jj_3R_352() + { + if (jj_scan_token(AT)) return true; + if (jj_scan_token(INTERFACE)) return true; + if (jj_3R_88()) return true; + if (jj_3R_391()) return true; + return false; + } + + private boolean jj_3R_192() + { + if (jj_3R_103()) return true; + if (jj_scan_token(DOUBLECOLON)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_223()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_224()) { + jj_scanpos = xsp; + if (jj_scan_token(42)) return true; + } + return false; + } + + private boolean jj_3_34() + { + if (jj_3R_101()) return true; + if (jj_scan_token(COMMA)) return true; + return false; + } + + private boolean jj_3R_277() + { + if (jj_3R_101()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_312()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_191() + { + if (jj_3R_102()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3_33() + { + if (jj_3R_100()) return true; + return false; + } + + private boolean jj_3R_190() + { + if (jj_3R_222()) return true; + return false; + } + + private boolean jj_3R_346() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_345()) return true; + return false; + } + + private boolean jj_3R_221() + { + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_362() + { + if (jj_3R_114()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_54()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_274() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3_10() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_78()) return true; + return false; + } + + private boolean jj_3R_220() + { + if (jj_3R_277()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_276() + { + if (jj_3R_100()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_311()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_218() + { + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3_11() + { + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_219() + { + if (jj_3R_276()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_212() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_362()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) jj_scanpos = xsp; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_217() + { + if (jj_scan_token(DOUBLECOLON)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_274()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_275()) { + jj_scanpos = xsp; + if (jj_scan_token(42)) return true; + } + return false; + } + + private boolean jj_3R_420() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_100()) return true; + return false; + } + + private boolean jj_3R_419() + { + if (jj_3R_100()) return true; + return false; + } + + private boolean jj_3R_189() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_218()) { + jj_scanpos = xsp; + if (jj_3R_219()) { + jj_scanpos = xsp; + if (jj_3R_220()) { + jj_scanpos = xsp; + if (jj_3R_221()) return true; + } + } + } + return false; + } + + private boolean jj_3R_176() + { + if (jj_3R_149()) return true; + return false; + } + + private boolean jj_3_53() + { + if (jj_scan_token(AT)) return true; + return false; + } + + private boolean jj_3R_175() + { + if (jj_3R_212()) return true; + return false; + } + + private boolean jj_3R_396() + { + if (jj_3R_119()) return true; + return false; + } + + private boolean jj_3R_418() + { + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_402() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_418()) { + jj_scanpos = xsp; + if (jj_3R_419()) return true; + } + while (true) { + xsp = jj_scanpos; + if (jj_3R_420()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_273() + { + if (jj_3R_183()) return true; + return false; + } + + private boolean jj_3R_174() + { + if (jj_3R_115()) return true; + return false; + } + + private boolean jj_3R_392() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_402()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_216() + { + if (jj_scan_token(DOT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_272()) jj_scanpos = xsp; + if (jj_3R_88()) return true; + xsp = jj_scanpos; + if (jj_3R_273()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_272() + { + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_114() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_174()) { + jj_scanpos = xsp; + if (jj_3R_175()) { + jj_scanpos = xsp; + if (jj_3R_176()) return true; + } + } + return false; + } + + private boolean jj_3_32() + { + if (jj_3R_99()) return true; + return false; + } + + private boolean jj_3R_188() + { + if (jj_scan_token(SUPER)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_216()) { + jj_scanpos = xsp; + if (jj_3R_217()) return true; + } + return false; + } + + private boolean jj_3R_187() + { + if (jj_scan_token(THIS)) return true; + return false; + } + + private boolean jj_3R_345() + { + if (jj_3R_88()) return true; + if (jj_scan_token(ASSIGN)) return true; + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_186() + { + if (jj_3R_215()) return true; + return false; + } + + private boolean jj_3R_103() + { + if (jj_3R_86()) return true; + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_129() + { + if (jj_3R_99()) return true; + return false; + } + + private boolean jj_3R_113() + { + if (jj_3R_74()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + private boolean jj_3R_128() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_186()) { + jj_scanpos = xsp; + if (jj_3R_187()) { + jj_scanpos = xsp; + if (jj_3R_188()) { + jj_scanpos = xsp; + if (jj_3R_189()) { + jj_scanpos = xsp; + if (jj_3R_190()) { + jj_scanpos = xsp; + if (jj_3R_191()) { + jj_scanpos = xsp; + if (jj_3R_192()) { + jj_scanpos = xsp; + if (jj_3R_193()) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3_52() + { + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_323() + { + if (jj_3R_345()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_346()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_31() + { + if (jj_3R_98()) return true; + return false; + } + + private boolean jj_3R_249() + { + if (jj_3R_86()) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3_51() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_113()) { + jj_scanpos = xsp; + if (jj_scan_token(93)) return true; + } + return false; + } + + private boolean jj_3R_245() + { + return false; + } + + private boolean jj_3R_294() + { + if (jj_3R_323()) return true; + return false; + } + + private boolean jj_3R_244() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_114()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_404() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_249()) return true; + return false; + } + + private boolean jj_3R_398() + { + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_243() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_294()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_397() + { + if (jj_scan_token(THROWS)) return true; + if (jj_3R_249()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_404()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_82() + { + if (jj_3R_128()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_129()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_366() + { + if (jj_3R_117()) return true; + return false; + } + + private boolean jj_3R_115() + { + if (jj_scan_token(AT)) return true; + if (jj_3R_80()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_243()) { + jj_scanpos = xsp; + if (jj_3R_244()) { + jj_scanpos = xsp; + if (jj_3R_245()) return true; + } + } + return false; + } + + private boolean jj_3R_335() + { + if (jj_3R_78()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_10()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_355() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_366()) jj_scanpos = xsp; + if (jj_3R_86()) return true; + if (jj_3R_102()) return true; + if (jj_3R_88()) return true; + if (jj_3R_392()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_396()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_397()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_398()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + private boolean jj_3_50() + { + if (jj_scan_token(AT)) return true; + return false; + } + + private boolean jj_3R_211() + { + if (jj_3R_128()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_31()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_165() + { + if (jj_3R_119()) return true; + return false; + } + + private boolean jj_3R_135() + { + if (jj_3R_115()) return true; + return false; + } + + private boolean jj_3R_86() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_135()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_150() + { + return false; + } + + private boolean jj_3R_201() + { + if (jj_scan_token(BIT_AND)) return true; + if (jj_3R_249()) return true; + return false; + } + + private boolean jj_3_48() + { + if (jj_scan_token(SEMICOLON)) return true; + if (jj_3R_111()) return true; + return false; + } + + private boolean jj_3R_152() + { + if (jj_3R_85()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_201()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_202()) return true; + return false; + } + + private boolean jj_3R_180() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_335()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) jj_scanpos = xsp; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3_30() + { + if (jj_3R_97()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_151() + { + return false; + } + + private boolean jj_3R_123() + { + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_92() + { + jj_lookingAhead = true; + jj_semLA = getToken(1).kind == GT && + getToken(1).realKind == RSIGNEDSHIFT; + jj_lookingAhead = false; + if (!jj_semLA || jj_3R_150()) return true; + if (jj_scan_token(GT)) return true; + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_122() + { + if (jj_3R_180()) return true; + return false; + } + + private boolean jj_3R_173() + { + if (jj_scan_token(ASSIGN)) return true; + if (jj_3R_78()) return true; + return false; + } + + private boolean jj_3R_94() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_86()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_30()) { + jj_scanpos = xsp; + if (jj_3R_152()) return true; + } + return false; + } + + private boolean jj_3R_93() + { + jj_lookingAhead = true; + jj_semLA = getToken(1).kind == GT && + getToken(1).realKind == RUNSIGNEDSHIFT; + jj_lookingAhead = false; + if (!jj_semLA || jj_3R_151()) return true; + if (jj_scan_token(GT)) return true; + if (jj_scan_token(GT)) return true; + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_78() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_122()) { + jj_scanpos = xsp; + if (jj_3R_123()) return true; + } + return false; + } + + private boolean jj_3_49() + { + if (jj_3R_108()) return true; + if (jj_3R_75()) return true; + if (jj_3R_112()) return true; + return false; + } + + private boolean jj_3R_172() + { + if (jj_3R_211()) return true; + return false; + } + + private boolean jj_3R_96() + { + if (jj_scan_token(DECR)) return true; + return false; + } + + private boolean jj_3_29() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_95()) { + jj_scanpos = xsp; + if (jj_3R_96()) return true; + } + return false; + } + + private boolean jj_3R_95() + { + if (jj_scan_token(INCR)) return true; + return false; + } + + private boolean jj_3_28() + { + if (jj_3R_94()) return true; + return false; + } + + private boolean jj_3R_101() + { + if (jj_3R_88()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_165()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_76() + { + if (jj_3R_119()) return true; + return false; + } + + private boolean jj_3R_171() + { + if (jj_3R_109()) return true; + return false; + } + + private boolean jj_3R_111() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_171()) { + jj_scanpos = xsp; + if (jj_3R_172()) return true; + } + return false; + } + + private boolean jj_3R_299() + { + if (jj_3R_211()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_29()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_251() + { + if (jj_3R_94()) return true; + return false; + } + + private boolean jj_3R_368() + { + if (jj_3R_111()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_48()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_298() + { + if (jj_scan_token(BANG)) return true; + return false; + } + + private boolean jj_3R_252() + { + if (jj_3R_299()) return true; + return false; + } + + private boolean jj_3R_297() + { + if (jj_scan_token(TILDE)) return true; + return false; + } + + private boolean jj_3R_112() + { + if (jj_3R_101()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_173()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_250() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_297()) { + jj_scanpos = xsp; + if (jj_3R_298()) return true; + } + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_395() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_112()) return true; + return false; + } + + private boolean jj_3R_73() + { + if (jj_3R_117()) return true; + return false; + } + + private boolean jj_3_8() + { + if (jj_3R_75()) return true; + if (jj_3R_74()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_76()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_scan_token(99)) { + jj_scanpos = xsp; + if (jj_scan_token(102)) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + } + return false; + } + + private boolean jj_3R_202() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_250()) { + jj_scanpos = xsp; + if (jj_3R_251()) { + jj_scanpos = xsp; + if (jj_3R_252()) return true; + } + } + return false; + } + + private boolean jj_3R_428() + { + if (jj_scan_token(FINALLY)) return true; + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_413() + { + if (jj_scan_token(FINALLY)) return true; + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3_7() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_73()) jj_scanpos = xsp; + if (jj_3R_74()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3_47() + { + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_354() + { + if (jj_3R_75()) return true; + if (jj_3R_112()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_395()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_344() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_368()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_47()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3_6() + { + if (jj_scan_token(AT)) return true; + if (jj_scan_token(INTERFACE)) return true; + return false; + } + + private boolean jj_3_5() + { + if (jj_scan_token(ENUM)) return true; + return false; + } + + private boolean jj_3R_334() + { + if (jj_3R_355()) return true; + return false; + } + + private boolean jj_3R_433() + { + if (jj_scan_token(BIT_OR)) return true; + if (jj_3R_249()) return true; + return false; + } + + private boolean jj_3R_333() + { + if (jj_3R_354()) return true; + return false; + } + + private boolean jj_3R_257() + { + if (jj_scan_token(DECR)) return true; + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_332() + { + if (jj_3R_353()) return true; + return false; + } + + private boolean jj_3R_427() + { + if (jj_scan_token(CATCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_108()) return true; + if (jj_3R_85()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_433()) { jj_scanpos = xsp; break; } + } + if (jj_3R_101()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_331() + { + if (jj_3R_352()) return true; + return false; + } + + private boolean jj_3R_330() + { + if (jj_3R_351()) return true; + return false; + } + + private boolean jj_3R_329() + { + if (jj_3R_194()) return true; + return false; + } + + private boolean jj_3R_110() + { + if (jj_scan_token(INCR)) return true; + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_303() + { + if (jj_3R_108()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_329()) { + jj_scanpos = xsp; + if (jj_3R_330()) { + jj_scanpos = xsp; + if (jj_3R_331()) { + jj_scanpos = xsp; + if (jj_3R_332()) { + jj_scanpos = xsp; + if (jj_3R_333()) { + jj_scanpos = xsp; + if (jj_3R_334()) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_210() + { + if (jj_3R_202()) return true; + return false; + } + + private boolean jj_3_9() + { + if (jj_3R_77()) return true; + return false; + } + + private boolean jj_3R_259() + { + if (jj_scan_token(MINUS)) return true; + return false; + } + + private boolean jj_3R_258() + { + if (jj_scan_token(PLUS)) return true; + return false; + } + + private boolean jj_3R_213() + { + if (jj_3R_263()) return true; + return false; + } + + private boolean jj_3R_412() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_427()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_428()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_209() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_258()) { + jj_scanpos = xsp; + if (jj_3R_259()) return true; + } + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_208() + { + if (jj_3R_257()) return true; + return false; + } + + private boolean jj_3R_207() + { + if (jj_3R_110()) return true; + return false; + } + + private boolean jj_3R_256() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_9()) { + jj_scanpos = xsp; + if (jj_3R_303()) return true; + } + return false; + } + + private boolean jj_3R_322() + { + if (jj_3R_344()) return true; + return false; + } + + private boolean jj_3R_293() + { + if (jj_scan_token(TRY)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_322()) jj_scanpos = xsp; + if (jj_3R_121()) return true; + xsp = jj_scanpos; + if (jj_3R_412()) { + jj_scanpos = xsp; + if (jj_3R_413()) return true; + } + return false; + } + + private boolean jj_3R_168() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_206()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + private boolean jj_3R_206() + { + if (jj_3R_256()) return true; + return false; + } + + private boolean jj_3R_170() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_207()) { + jj_scanpos = xsp; + if (jj_3R_208()) { + jj_scanpos = xsp; + if (jj_3R_209()) { + jj_scanpos = xsp; + if (jj_3R_210()) return true; + } + } + } + return false; + } + + private boolean jj_3R_423() + { + if (jj_scan_token(REM)) return true; + return false; + } + + private boolean jj_3R_105() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_168()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_422() + { + if (jj_scan_token(SLASH)) return true; + return false; + } + + private boolean jj_3R_421() + { + if (jj_scan_token(STAR)) return true; + return false; + } + + private boolean jj_3R_405() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_421()) { + jj_scanpos = xsp; + if (jj_3R_422()) { + jj_scanpos = xsp; + if (jj_3R_423()) return true; + } + } + if (jj_3R_170()) return true; + return false; + } + + private boolean jj_3R_321() + { + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_307() + { + if (jj_scan_token(BIT_AND)) return true; + if (jj_3R_306()) return true; + return false; + } + + private boolean jj_3R_382() + { + if (jj_3R_170()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_405()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_263() + { + if (jj_scan_token(EXTENDS)) return true; + if (jj_3R_306()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_307()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_292() + { + if (jj_scan_token(SYNCHRONIZED)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_320() + { + if (jj_3R_88()) return true; + return false; + } + + private boolean jj_3R_407() + { + if (jj_scan_token(MINUS)) return true; + return false; + } + + private boolean jj_3R_406() + { + if (jj_scan_token(PLUS)) return true; + return false; + } + + private boolean jj_3R_399() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_406()) { + jj_scanpos = xsp; + if (jj_3R_407()) return true; + } + if (jj_3R_382()) return true; + return false; + } + + private boolean jj_3_4() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_72()) return true; + return false; + } + + private boolean jj_3R_177() + { + if (jj_3R_88()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_213()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_291() + { + if (jj_scan_token(THROW)) return true; + if (jj_3R_90()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_378() + { + if (jj_3R_382()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_399()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_319() + { + if (jj_3R_88()) return true; + return false; + } + + private boolean jj_3R_415() + { + if (jj_3R_105()) return true; + return false; + } + + private boolean jj_3R_178() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_86()) return true; + if (jj_3R_177()) return true; + return false; + } + + private boolean jj_3_27() + { + if (jj_3R_93()) return true; + return false; + } + + private boolean jj_3_26() + { + if (jj_3R_92()) return true; + return false; + } + + private boolean jj_3R_440() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_290() + { + if (jj_scan_token(RETURN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_321()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_91() + { + if (jj_scan_token(LSHIFT)) return true; + return false; + } + + private boolean jj_3_25() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_91()) { + jj_scanpos = xsp; + if (jj_3_26()) { + jj_scanpos = xsp; + if (jj_3_27()) return true; + } + } + if (jj_3R_378()) return true; + return false; + } + + private boolean jj_3R_117() + { + if (jj_scan_token(LT)) return true; + if (jj_3R_86()) return true; + if (jj_3R_177()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_178()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_379() + { + if (jj_scan_token(INSTANCEOF)) return true; + if (jj_3R_249()) return true; + return false; + } + + private boolean jj_3R_376() + { + if (jj_3R_378()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_25()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_289() + { + if (jj_scan_token(CONTINUE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_320()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_387() + { + if (jj_scan_token(GE)) return true; + return false; + } + + private boolean jj_3R_386() + { + if (jj_scan_token(LE)) return true; + return false; + } + + private boolean jj_3R_426() + { + if (jj_3R_432()) return true; + return false; + } + + private boolean jj_3R_385() + { + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_384() + { + if (jj_scan_token(LT)) return true; + return false; + } + + private boolean jj_3R_414() + { + if (jj_3R_183()) return true; + return false; + } + + private boolean jj_3R_383() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_384()) { + jj_scanpos = xsp; + if (jj_3R_385()) { + jj_scanpos = xsp; + if (jj_3R_386()) { + jj_scanpos = xsp; + if (jj_3R_387()) return true; + } + } + } + if (jj_3R_376()) return true; + return false; + } + + private boolean jj_3R_288() + { + if (jj_scan_token(BREAK)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_319()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_116() + { + if (jj_3R_115()) return true; + return false; + } + + private boolean jj_3R_72() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_116()) { jj_scanpos = xsp; break; } + } + if (jj_3R_88()) return true; + xsp = jj_scanpos; + if (jj_3R_414()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_415()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_373() + { + if (jj_3R_376()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_383()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_432() + { + if (jj_3R_375()) return true; + return false; + } + + private boolean jj_3R_416() + { + if (jj_3R_256()) return true; + return false; + } + + private boolean jj_3R_411() + { + if (jj_scan_token(ELSE)) return true; + if (jj_3R_195()) return true; + return false; + } + + private boolean jj_3R_400() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_416()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + private boolean jj_3_46() + { + if (jj_3R_108()) return true; + if (jj_3R_75()) return true; + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3R_374() + { + if (jj_scan_token(BIT_AND)) return true; + if (jj_3R_363()) return true; + return false; + } + + private boolean jj_3R_369() + { + if (jj_3R_373()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_379()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_390() + { + if (jj_scan_token(SEMICOLON)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_400()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_375() + { + if (jj_3R_90()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_440()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_372() + { + if (jj_3R_375()) return true; + return false; + } + + private boolean jj_3R_425() + { + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_389() + { + if (jj_3R_72()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_4()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_371() + { + if (jj_3R_109()) return true; + return false; + } + + private boolean jj_3R_388() + { + if (jj_3R_305()) return true; + return false; + } + + private boolean jj_3R_381() + { + if (jj_scan_token(NE)) return true; + return false; + } + + private boolean jj_3R_380() + { + if (jj_scan_token(EQ)) return true; + return false; + } + + private boolean jj_3R_377() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_380()) { + jj_scanpos = xsp; + if (jj_3R_381()) return true; + } + if (jj_3R_369()) return true; + return false; + } + + private boolean jj_3R_370() + { + if (jj_scan_token(XOR)) return true; + if (jj_3R_347()) return true; + return false; + } + + private boolean jj_3R_351() + { + if (jj_scan_token(ENUM)) return true; + if (jj_3R_88()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_388()) jj_scanpos = xsp; + if (jj_scan_token(LBRACE)) return true; + xsp = jj_scanpos; + if (jj_3R_389()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_390()) jj_scanpos = xsp; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_367() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_371()) { + jj_scanpos = xsp; + if (jj_3R_372()) return true; + } + return false; + } + + private boolean jj_3R_364() + { + if (jj_scan_token(BIT_OR)) return true; + if (jj_3R_324()) return true; + return false; + } + + private boolean jj_3R_363() + { + if (jj_3R_369()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_377()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_45() + { + if (jj_3R_109()) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + private boolean jj_3R_348() + { + if (jj_scan_token(SC_AND)) return true; + if (jj_3R_296()) return true; + return false; + } + + private boolean jj_3R_409() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_306()) return true; + return false; + } + + private boolean jj_3R_347() + { + if (jj_3R_363()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_374()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_356() + { + if (jj_3R_367()) return true; + return false; + } + + private boolean jj_3R_305() + { + if (jj_scan_token(IMPLEMENTS)) return true; + if (jj_3R_306()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_409()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_338() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_356()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_425()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_426()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_325() + { + if (jj_scan_token(SC_OR)) return true; + if (jj_3R_248()) return true; + return false; + } + + private boolean jj_3R_337() + { + if (jj_3R_109()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_90()) return true; + return false; + } + + private boolean jj_3R_324() + { + if (jj_3R_347()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_370()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_408() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_306()) return true; + return false; + } + + private boolean jj_3R_287() + { + if (jj_scan_token(FOR)) return true; + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_337()) { + jj_scanpos = xsp; + if (jj_3R_338()) return true; + } + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_195()) return true; + return false; + } + + /** Generated Token Manager. */ + public GeneratedJavaParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + /** Whether we are looking ahead. */ + private boolean jj_lookingAhead = false; + private boolean jj_semLA; + private int jj_gen; + final private int[] jj_la1 = new int[164]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static private int[] jj_la1_3; + static private int[] jj_la1_4; + static { + jj_la1_init_0(); + jj_la1_init_1(); + jj_la1_init_2(); + jj_la1_init_3(); + jj_la1_init_4(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x24480800,0x4080000,0x24480800,0x1,0x0,0x0,0x20400800,0x80000,0x0,0x8000000,0x0,0x0,0x0,0x0,0x4000000,0x0,0xa54ca800,0xa54ca800,0x0,0x0,0x0,0x0,0x0,0x8000000,0x0,0xa54ca800,0xa54ca800,0x80000,0x8504a000,0xa54ca800,0x0,0x0,0x0,0x9504a000,0x9504a000,0x0,0x0,0x0,0x0,0x0,0x0,0xa544a800,0x0,0xa544a800,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9504a000,0x0,0x8104a000,0x8504a000,0x8504a000,0x0,0x8504a000,0x8504a000,0x8000000,0x8000000,0x8104a000,0x8504a000,0x4000000,0x0,0x4000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9504a000,0x0,0x0,0x9504a000,0x0,0x0,0x8504a000,0x0,0x0,0x0,0x4000000,0x0,0x0,0x9504a000,0x0,0x4000000,0x0,0x10000000,0x4000000,0x0,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x9504a000,0x0,0x0,0x0,0x8504a000,0x9504a000,0x0,0x95a4f000,0x0,0x95a4f000,0x0,0x9504a000,0x0,0x0,0x9504a000,0x410000,0x410000,0x2000000,0xb544a800,0x9504a000,0x9504a000,0xb544a800,0x9504a000,0x0,0x4000000,0x4000000,0x9504a000,0x0,0x20000,0x0,0x40000000,0x9504a000,0x4000000,0x0,0x9504a000,0x9504a000,0x0,0xa54ca800,0xa54ca800,0x80000,0x8504a000,0x400000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9504a000,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x444ce290,0x80,0x444ce290,0x0,0x40000,0x0,0x444ce200,0x80,0x0,0x0,0x8,0x0,0x0,0x8,0x80000,0x0,0x644ee3c0,0x644ee3c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x644ee3c0,0x644ee3c0,0x80,0x200a0140,0x644ee3c0,0x0,0x0,0x0,0x289a0d40,0x289a0d40,0x0,0x0,0x0,0x0,0x2000000,0x0,0x444ee340,0x0,0x444ee340,0x0,0x0,0x0,0x0,0x0,0x2000000,0x0,0x0,0x289a0d40,0x40000,0x20140,0xa0140,0xa0140,0x0,0xa0140,0xa0140,0x100000,0x100000,0x20140,0x200a0140,0x80000,0x0,0x80400,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x289a0d40,0x0,0x0,0x289a0d40,0x0,0x0,0xa0140,0x0,0x0,0x0,0x80400,0x0,0x0,0x289a0d40,0x0,0x80400,0x0,0x8900c00,0x80000,0x0,0x0,0x0,0x800400,0x0,0x8000800,0x8000000,0x289a0d40,0x0,0x0,0x0,0xa0140,0x289a0d40,0x0,0xb9fb0d45,0x0,0xb9fb0d45,0x0,0x289a0d40,0x0,0x0,0x289a0d40,0x0,0x0,0x0,0x6cdeef40,0x289a0d40,0x289a0d40,0x6cdeef40,0x289a0d40,0x0,0x80000,0x80000,0x289a0d40,0x0,0x0,0x0,0x0,0x289a0d40,0x80000,0x0,0x289a0d40,0x289a0d40,0x0,0x444ee3c0,0x444ee3c0,0x80,0xa0140,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x289a0d40,}; + } + private static void jj_la1_init_2() { + jj_la1_2 = new int[] {0x248,0x48,0x248,0x0,0x0,0x0,0x200,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20003ff,0x0,0x420003ff,0x420003ff,0x0,0x0,0x10000000,0x40000000,0x0,0x0,0x0,0x420003ff,0x420003ff,0x0,0x20003ff,0x20003ff,0x0,0x0,0x0,0x53810fff,0x53810fff,0x0,0x0,0x0,0x0,0x0,0x40000000,0x20003ff,0x0,0x20003ff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x13810fff,0x0,0x0,0x20003ff,0x20003ff,0x0,0x20003ff,0x20003ff,0x0,0x0,0x0,0x20003ff,0x20003ff,0x0,0x20003ff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x13810fff,0x0,0x0,0x13810fff,0x0,0x0,0x20003ff,0x0,0x10000000,0x0,0x20003ff,0x0,0x20000000,0x13810fff,0x0,0x20003ff,0x10000000,0x11810c00,0x20003ff,0x0,0x0,0x10000000,0x0,0x0,0x1810c00,0x0,0x13810fff,0x0,0x0,0x10000000,0x20003ff,0x13810fff,0x40000000,0x53810fff,0x0,0x53810fff,0x0,0x53810fff,0x0,0x0,0x13810fff,0x0,0x0,0x0,0x13810fff,0x13810fff,0x13810fff,0x13810fff,0x13810fff,0x0,0x20003ff,0x20003ff,0x13810fff,0x10000000,0x0,0x0,0x0,0x13810fff,0x20003ff,0x0,0x53810fff,0x53810fff,0x0,0x20003ff,0x20003ff,0x0,0x20003ff,0x0,0x0,0x2,0x0,0x2,0x0,0x1b1,0x8,0x1b1,0x13810fff,}; + } + private static void jj_la1_init_3() { + jj_la1_3 = new int[] {0x24,0x24,0x24,0x0,0x0,0x10,0x20,0x0,0x80,0x0,0x0,0x8,0x8,0x0,0x20,0x8,0xa4,0xa4,0x4,0x20,0x0,0x0,0x8,0x0,0x1000000,0xa4,0xa4,0x0,0xa0,0xa0,0x8,0x40,0x21,0x3c0320,0x3c0320,0x8,0x80,0x21,0x8,0x0,0x4,0x20,0x8,0x20,0x8,0x8,0x20,0x80,0x8,0x0,0x80,0x80,0xa0,0x0,0x0,0x0,0x20,0x8,0x420,0x400,0x0,0x0,0x0,0x0,0x0,0x80,0x0,0x0,0xe0000040,0xe0000040,0x400,0x10000,0x20000,0x2000000,0x4000000,0x1000000,0x9000,0x9000,0x0,0x6080,0x6080,0x10000000,0x300000,0x300000,0x8c00000,0x8c00000,0x300000,0x3c0320,0x300,0x300,0x20,0xc0000,0x1000000,0x0,0x80,0x0,0x80,0x0,0x10,0x0,0x3c0320,0x80,0x0,0x0,0x0,0x0,0x10,0x80,0x0,0x0,0x11,0x0,0x0,0x3c0320,0x8,0x80,0x21,0xa0,0x3c0320,0x0,0xc0024,0x800,0xc0024,0x8,0x3c0320,0xe00c0040,0xe00c0040,0x80020,0x0,0x0,0x0,0x3c0320,0x3c0320,0x3c0320,0x3c0324,0x3c0320,0x8,0x0,0x0,0x3c0320,0x0,0x0,0x2000000,0x0,0x20,0x0,0x8,0x3c0320,0x3c0320,0x8,0x24,0x24,0x0,0x20,0x0,0x8,0x0,0x8,0x0,0x8,0x0,0x0,0x0,0xa0,}; + } + private static void jj_la1_init_4() { + jj_la1_4 = new int[] {0x0,0x0,0x0,0x4000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x600,0x6ff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2000,0x2000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[58]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor. */ + public GeneratedJavaParser(Provider stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new GeneratedJavaParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 164; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public GeneratedJavaParser(String dsl) throws ParseException, TokenMgrException { + this(new StringProvider(dsl)); + } + + public void ReInit(String s) { + ReInit(new StringProvider(s)); + } + /** Reinitialise. */ + public void ReInit(Provider stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.ReInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new GeneratedJavaParserTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 164; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public GeneratedJavaParser(GeneratedJavaParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 164; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(GeneratedJavaParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 164; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + @SuppressWarnings("serial") + static private final class LookaheadSuccess extends java.lang.RuntimeException { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = jj_lookingAhead ? jj_scanpos : token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk_f() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) { + return; + } + + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + + for (int[] oldentry : jj_expentries) { + if (oldentry.length == jj_expentry.length) { + boolean isMatched = true; + + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + isMatched = false; + break; + } + + } + if (isMatched) { + jj_expentries.add(jj_expentry); + break; + } + } + } + + if (pos != 0) { + jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[143]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 164; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + case 8: jj_3_9(); break; + case 9: jj_3_10(); break; + case 10: jj_3_11(); break; + case 11: jj_3_12(); break; + case 12: jj_3_13(); break; + case 13: jj_3_14(); break; + case 14: jj_3_15(); break; + case 15: jj_3_16(); break; + case 16: jj_3_17(); break; + case 17: jj_3_18(); break; + case 18: jj_3_19(); break; + case 19: jj_3_20(); break; + case 20: jj_3_21(); break; + case 21: jj_3_22(); break; + case 22: jj_3_23(); break; + case 23: jj_3_24(); break; + case 24: jj_3_25(); break; + case 25: jj_3_26(); break; + case 26: jj_3_27(); break; + case 27: jj_3_28(); break; + case 28: jj_3_29(); break; + case 29: jj_3_30(); break; + case 30: jj_3_31(); break; + case 31: jj_3_32(); break; + case 32: jj_3_33(); break; + case 33: jj_3_34(); break; + case 34: jj_3_35(); break; + case 35: jj_3_36(); break; + case 36: jj_3_37(); break; + case 37: jj_3_38(); break; + case 38: jj_3_39(); break; + case 39: jj_3_40(); break; + case 40: jj_3_41(); break; + case 41: jj_3_42(); break; + case 42: jj_3_43(); break; + case 43: jj_3_44(); break; + case 44: jj_3_45(); break; + case 45: jj_3_46(); break; + case 46: jj_3_47(); break; + case 47: jj_3_48(); break; + case 48: jj_3_49(); break; + case 49: jj_3_50(); break; + case 50: jj_3_51(); break; + case 51: jj_3_52(); break; + case 52: jj_3_53(); break; + case 53: jj_3_54(); break; + case 54: jj_3_55(); break; + case 55: jj_3_56(); break; + case 56: jj_3_57(); break; + case 57: jj_3_58(); break; + } + } + p = p.next; + } while (p != null); + + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + + p.gen = jj_gen + xla - jj_la; + p.first = token; + p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/JavaParser/src/com/github/javaparser/GeneratedJavaParserBase.java b/JavaParser/src/com/github/javaparser/GeneratedJavaParserBase.java new file mode 100644 index 0000000..ef0b7ef --- /dev/null +++ b/JavaParser/src/com/github/javaparser/GeneratedJavaParserBase.java @@ -0,0 +1,369 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.comments.CommentsCollection; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.utils.Pair; + +import java.util.*; + +import static com.github.javaparser.GeneratedJavaParserConstants.EOF; +import static com.github.javaparser.ast.type.ArrayType.unwrapArrayTypes; +import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Base class for {@link GeneratedJavaParser} + */ +abstract class GeneratedJavaParserBase { + //// Interface with the generated code + abstract GeneratedJavaParserTokenManager getTokenSource(); + + abstract void ReInit(Provider provider); + + /* Returns the JavaParser specific token type of the last matched token */ + abstract JavaToken token(); + + abstract Token getNextToken(); + + //// + + /* The problems encountered while parsing */ + List problems = new ArrayList<>(); + /* Configuration flag whether we store tokens and tokenranges */ + boolean storeTokens; + + /* Resets the parser for reuse, gaining a little performance */ + void reset(Provider provider) { + ReInit(provider); + problems = new ArrayList<>(); + getTokenSource().reset(); + } + + /** + * Return the list of JavaParser specific tokens that have been encountered while parsing code using this parser. + * + * @return a list of tokens + */ + public List getTokens() { + return getTokenSource().getTokens(); + } + + /* The collection of comments encountered */ + CommentsCollection getCommentsCollection() { + return getTokenSource().getCommentsCollection(); + } + + /* Reports a problem to the user */ + void addProblem(String message) { + // TODO tokenRange only takes the final token. Need all the tokens. + problems.add(new Problem(message, tokenRange(), null)); + } + + /* Returns a tokenRange that spans the last matched token */ + TokenRange tokenRange() { + if (storeTokens) { + return new TokenRange(token(), token()); + } + return null; + } + + /** + * Return a TokenRange spanning from begin to end + */ + TokenRange range(JavaToken begin, JavaToken end) { + if (storeTokens) { + return new TokenRange(begin, end); + } + return null; + } + + /** + * Return a TokenRange spanning from begin to end + */ + TokenRange range(Node begin, JavaToken end) { + if (storeTokens) { + return new TokenRange(begin.getTokenRange().get().getBegin(), end); + } + return null; + } + + /** + * Return a TokenRange spanning from begin to end + */ + TokenRange range(JavaToken begin, Node end) { + if (storeTokens) { + return new TokenRange(begin, end.getTokenRange().get().getEnd()); + } + return null; + } + + /** + * Return a TokenRange spanning from begin to end + */ + TokenRange range(Node begin, Node end) { + if (storeTokens) { + return new TokenRange(begin.getTokenRange().get().getBegin(), end.getTokenRange().get().getEnd()); + } + return null; + } + + /** + * @return secondChoice if firstChoice is JavaToken.UNKNOWN, otherwise firstChoice + */ + JavaToken orIfInvalid(JavaToken firstChoice, JavaToken secondChoice) { + if (storeTokens) { + assertNotNull(firstChoice); + assertNotNull(secondChoice); + if (firstChoice.valid() || secondChoice.invalid()) { + return firstChoice; + } + return secondChoice; + } + return null; + } + + /** + * @return the begin-token secondChoice if firstChoice is JavaToken.UNKNOWN, otherwise firstChoice + */ + JavaToken orIfInvalid(JavaToken firstChoice, Node secondChoice) { + if (storeTokens) { + return orIfInvalid(firstChoice, secondChoice.getTokenRange().get().getBegin()); + } + return null; + } + + /** + * Get the token that starts the NodeList l + */ + JavaToken nodeListBegin(NodeList l) { + if (!storeTokens || l.isEmpty()) { + return JavaToken.INVALID; + } + return l.get(0).getTokenRange().get().getBegin(); + } + + /* Sets the kind of the last matched token to newKind */ + void setTokenKind(int newKind) { + token().setKind(newKind); + } + + /* Makes the parser keep a list of tokens */ + void setStoreTokens(boolean storeTokens) { + this.storeTokens = storeTokens; + getTokenSource().setStoreTokens(storeTokens); + } + + /* Called from within a catch block to skip forward to a known token, + and report the occurred exception as a problem. */ + TokenRange recover(int recoveryTokenType, ParseException p) { + JavaToken begin = null; + if (p.currentToken != null) { + begin = token(); + } + Token t; + do { + t = getNextToken(); + } while (t.kind != recoveryTokenType && t.kind != EOF); + + JavaToken end = token(); + + TokenRange tokenRange = null; + if (begin != null && end != null) { + tokenRange = range(begin, end); + } + + problems.add(new Problem(makeMessageForParseException(p), tokenRange, p)); + return tokenRange; + } + + /** + * Quickly create a new NodeList + */ + NodeList emptyList() { + return new NodeList<>(); + } + + /** + * Add obj to list and return it. Create a new list if list is null + */ + NodeList add(NodeList list, T obj) { + if (list == null) { + list = new NodeList<>(); + } + list.add(obj); + return list; + } + + /** + * Add obj to list only when list is not null + */ + NodeList addWhenNotNull(NodeList list, T obj) { + if (obj == null) { + return list; + } + return add(list, obj); + } + + /** + * Add obj to list at position pos + */ + NodeList prepend(NodeList list, T obj) { + if (list == null) { + list = new NodeList<>(); + } + list.addFirst(obj); + return list; + } + + /** + * Add obj to list + */ + List add(List list, T obj) { + if (list == null) { + list = new LinkedList<>(); + } + list.add(obj); + return list; + } + + /** + * Add modifier mod to modifiers + */ + void addModifier(EnumSet modifiers, Modifier mod) { + if (modifiers.contains(mod)) { + addProblem("Duplicated modifier"); + } + modifiers.add(mod); + } + + /** + * Propagate expansion of the range on the right to the parent. This is necessary when the right border of the child + * is determining the right border of the parent (i.e., the child is the last element of the parent). In this case + * when we "enlarge" the child we should enlarge also the parent. + */ + private void propagateRangeGrowthOnRight(Node node, Node endNode) { + if (storeTokens) { + node.getParentNode().ifPresent(nodeParent -> { + boolean isChildOnTheRightBorderOfParent = node.getTokenRange().get().getEnd().equals(nodeParent.getTokenRange().get().getEnd()); + if (isChildOnTheRightBorderOfParent) { + propagateRangeGrowthOnRight(nodeParent, endNode); + } + }); + node.setTokenRange(range(node, endNode)); + } + } + + /** + * Workaround for rather complex ambiguity that lambda's create + */ + Expression generateLambda(Expression ret, Statement lambdaBody) { + if (ret instanceof EnclosedExpr) { + Expression inner = ((EnclosedExpr) ret).getInner(); + SimpleName id = ((NameExpr) inner).getName(); + NodeList params = add(new NodeList<>(), new Parameter(ret.getTokenRange().orElse(null), EnumSet.noneOf(Modifier.class), new NodeList<>(), new UnknownType(), false, new NodeList<>(), id)); + ret = new LambdaExpr(range(ret, lambdaBody), params, lambdaBody, true); + } else if (ret instanceof NameExpr) { + SimpleName id = ((NameExpr) ret).getName(); + NodeList params = add(new NodeList<>(), new Parameter(ret.getTokenRange().orElse(null), EnumSet.noneOf(Modifier.class), new NodeList<>(), new UnknownType(), false, new NodeList<>(), id)); + ret = new LambdaExpr(range(ret, lambdaBody), params, lambdaBody, false); + } else if (ret instanceof LambdaExpr) { + ((LambdaExpr) ret).setBody(lambdaBody); + propagateRangeGrowthOnRight(ret, lambdaBody); + } else if (ret instanceof CastExpr) { + CastExpr castExpr = (CastExpr) ret; + Expression inner = generateLambda(castExpr.getExpression(), lambdaBody); + castExpr.setExpression(inner); + } else { + addProblem("Failed to parse lambda expression! Please create an issue at https://github.com/javaparser/javaparser/issues"); + } + return ret; + } + + /** + * Throws together an ArrayCreationExpr from a lot of pieces + */ + ArrayCreationExpr juggleArrayCreation(TokenRange range, List levelRanges, Type type, NodeList dimensions, List> arrayAnnotations, ArrayInitializerExpr arrayInitializerExpr) { + NodeList levels = new NodeList<>(); + + for (int i = 0; i < arrayAnnotations.size(); i++) { + levels.add(new ArrayCreationLevel(levelRanges.get(i), dimensions.get(i), arrayAnnotations.get(i))); + } + return new ArrayCreationExpr(range, type, levels, arrayInitializerExpr); + } + + /** + * Throws together a Type, taking care of all the array brackets + */ + Type juggleArrayType(Type partialType, List additionalBrackets) { + Pair> partialParts = unwrapArrayTypes(partialType); + Type elementType = partialParts.a; + List leftMostBrackets = partialParts.b; + return wrapInArrayTypes(elementType, leftMostBrackets, additionalBrackets).clone(); + } + + /** + * This is the code from ParseException.initialise, modified to be more horizontal. + */ + private String makeMessageForParseException(ParseException exception) { + final StringBuilder sb = new StringBuilder("Parse error. Found "); + final StringBuilder expected = new StringBuilder(); + + int maxExpectedTokenSequenceLength = 0; + TreeSet sortedOptions = new TreeSet<>(); + for (int i = 0; i < exception.expectedTokenSequences.length; i++) { + if (maxExpectedTokenSequenceLength < exception.expectedTokenSequences[i].length) { + maxExpectedTokenSequenceLength = exception.expectedTokenSequences[i].length; + } + for (int j = 0; j < exception.expectedTokenSequences[i].length; j++) { + sortedOptions.add(exception.tokenImage[exception.expectedTokenSequences[i][j]]); + } + } + + for (String option : sortedOptions) { + expected.append(" ").append(option); + } + + sb.append(""); + + Token token = exception.currentToken.next; + for (int i = 0; i < maxExpectedTokenSequenceLength; i++) { + String tokenText = token.image; + String escapedTokenText = ParseException.add_escapes(tokenText); + if (i != 0) { + sb.append(" "); + } + if (token.kind == 0) { + sb.append(exception.tokenImage[0]); + break; + } + escapedTokenText = "\"" + escapedTokenText + "\""; + String image = exception.tokenImage[token.kind]; + if (image.equals(escapedTokenText)) { + sb.append(image); + } else { + sb.append(" ") + .append(escapedTokenText) + .append(" ") + .append(image); + } + token = token.next; + } + + if (exception.expectedTokenSequences.length != 0) { + int numExpectedTokens = exception.expectedTokenSequences.length; + sb.append(", expected") + .append(numExpectedTokens == 1 ? "" : " one of ") + .append(expected.toString()); + } + return sb.toString(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ASTParserConstants.java b/JavaParser/src/com/github/javaparser/GeneratedJavaParserConstants.java similarity index 56% rename from JavaParser/src/com/github/javaparser/ASTParserConstants.java rename to JavaParser/src/com/github/javaparser/GeneratedJavaParserConstants.java index e328d8c..e59d1e3 100644 --- a/JavaParser/src/com/github/javaparser/ASTParserConstants.java +++ b/JavaParser/src/com/github/javaparser/GeneratedJavaParserConstants.java @@ -1,414 +1,472 @@ -/* Generated By:JavaCC: Do not edit this line. ASTParserConstants.java */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - - -/** - * Token literal values and constants. - * Generated by org.javacc.parser.OtherFilesGen#start() - */ -public interface ASTParserConstants { - - /** End of File. */ - int EOF = 0; - /** RegularExpression Id. */ - int SINGLE_LINE_COMMENT = 6; - /** RegularExpression Id. */ - int JAVA_DOC_COMMENT = 9; - /** RegularExpression Id. */ - int MULTI_LINE_COMMENT = 10; - /** RegularExpression Id. */ - int ABSTRACT = 12; - /** RegularExpression Id. */ - int ASSERT = 13; - /** RegularExpression Id. */ - int BOOLEAN = 14; - /** RegularExpression Id. */ - int BREAK = 15; - /** RegularExpression Id. */ - int BYTE = 16; - /** RegularExpression Id. */ - int CASE = 17; - /** RegularExpression Id. */ - int CATCH = 18; - /** RegularExpression Id. */ - int CHAR = 19; - /** RegularExpression Id. */ - int CLASS = 20; - /** RegularExpression Id. */ - int CONST = 21; - /** RegularExpression Id. */ - int CONTINUE = 22; - /** RegularExpression Id. */ - int _DEFAULT = 23; - /** RegularExpression Id. */ - int DO = 24; - /** RegularExpression Id. */ - int DOUBLE = 25; - /** RegularExpression Id. */ - int ELSE = 26; - /** RegularExpression Id. */ - int ENUM = 27; - /** RegularExpression Id. */ - int EXTENDS = 28; - /** RegularExpression Id. */ - int FALSE = 29; - /** RegularExpression Id. */ - int FINAL = 30; - /** RegularExpression Id. */ - int FINALLY = 31; - /** RegularExpression Id. */ - int FLOAT = 32; - /** RegularExpression Id. */ - int FOR = 33; - /** RegularExpression Id. */ - int GOTO = 34; - /** RegularExpression Id. */ - int IF = 35; - /** RegularExpression Id. */ - int IMPLEMENTS = 36; - /** RegularExpression Id. */ - int IMPORT = 37; - /** RegularExpression Id. */ - int INSTANCEOF = 38; - /** RegularExpression Id. */ - int INT = 39; - /** RegularExpression Id. */ - int INTERFACE = 40; - /** RegularExpression Id. */ - int LONG = 41; - /** RegularExpression Id. */ - int NATIVE = 42; - /** RegularExpression Id. */ - int NEW = 43; - /** RegularExpression Id. */ - int NULL = 44; - /** RegularExpression Id. */ - int PACKAGE = 45; - /** RegularExpression Id. */ - int PRIVATE = 46; - /** RegularExpression Id. */ - int PROTECTED = 47; - /** RegularExpression Id. */ - int PUBLIC = 48; - /** RegularExpression Id. */ - int RETURN = 49; - /** RegularExpression Id. */ - int SHORT = 50; - /** RegularExpression Id. */ - int STATIC = 51; - /** RegularExpression Id. */ - int STRICTFP = 52; - /** RegularExpression Id. */ - int SUPER = 53; - /** RegularExpression Id. */ - int SWITCH = 54; - /** RegularExpression Id. */ - int SYNCHRONIZED = 55; - /** RegularExpression Id. */ - int THIS = 56; - /** RegularExpression Id. */ - int THROW = 57; - /** RegularExpression Id. */ - int THROWS = 58; - /** RegularExpression Id. */ - int TRANSIENT = 59; - /** RegularExpression Id. */ - int TRUE = 60; - /** RegularExpression Id. */ - int TRY = 61; - /** RegularExpression Id. */ - int VOID = 62; - /** RegularExpression Id. */ - int VOLATILE = 63; - /** RegularExpression Id. */ - int WHILE = 64; - /** RegularExpression Id. */ - int LONG_LITERAL = 65; - /** RegularExpression Id. */ - int INTEGER_LITERAL = 66; - /** RegularExpression Id. */ - int DECIMAL_LITERAL = 67; - /** RegularExpression Id. */ - int HEX_LITERAL = 68; - /** RegularExpression Id. */ - int OCTAL_LITERAL = 69; - /** RegularExpression Id. */ - int BINARY_LITERAL = 70; - /** RegularExpression Id. */ - int FLOATING_POINT_LITERAL = 71; - /** RegularExpression Id. */ - int DECIMAL_FLOATING_POINT_LITERAL = 72; - /** RegularExpression Id. */ - int DECIMAL_EXPONENT = 73; - /** RegularExpression Id. */ - int HEXADECIMAL_FLOATING_POINT_LITERAL = 74; - /** RegularExpression Id. */ - int HEXADECIMAL_EXPONENT = 75; - /** RegularExpression Id. */ - int CHARACTER_LITERAL = 76; - /** RegularExpression Id. */ - int STRING_LITERAL = 77; - /** RegularExpression Id. */ - int IDENTIFIER = 78; - /** RegularExpression Id. */ - int LETTER = 79; - /** RegularExpression Id. */ - int PART_LETTER = 80; - /** RegularExpression Id. */ - int LPAREN = 81; - /** RegularExpression Id. */ - int RPAREN = 82; - /** RegularExpression Id. */ - int LBRACE = 83; - /** RegularExpression Id. */ - int RBRACE = 84; - /** RegularExpression Id. */ - int LBRACKET = 85; - /** RegularExpression Id. */ - int RBRACKET = 86; - /** RegularExpression Id. */ - int SEMICOLON = 87; - /** RegularExpression Id. */ - int COMMA = 88; - /** RegularExpression Id. */ - int DOT = 89; - /** RegularExpression Id. */ - int AT = 90; - /** RegularExpression Id. */ - int ASSIGN = 91; - /** RegularExpression Id. */ - int LT = 92; - /** RegularExpression Id. */ - int BANG = 93; - /** RegularExpression Id. */ - int TILDE = 94; - /** RegularExpression Id. */ - int HOOK = 95; - /** RegularExpression Id. */ - int COLON = 96; - /** RegularExpression Id. */ - int EQ = 97; - /** RegularExpression Id. */ - int LE = 98; - /** RegularExpression Id. */ - int GE = 99; - /** RegularExpression Id. */ - int NE = 100; - /** RegularExpression Id. */ - int SC_OR = 101; - /** RegularExpression Id. */ - int SC_AND = 102; - /** RegularExpression Id. */ - int INCR = 103; - /** RegularExpression Id. */ - int DECR = 104; - /** RegularExpression Id. */ - int PLUS = 105; - /** RegularExpression Id. */ - int MINUS = 106; - /** RegularExpression Id. */ - int STAR = 107; - /** RegularExpression Id. */ - int SLASH = 108; - /** RegularExpression Id. */ - int BIT_AND = 109; - /** RegularExpression Id. */ - int BIT_OR = 110; - /** RegularExpression Id. */ - int XOR = 111; - /** RegularExpression Id. */ - int REM = 112; - /** RegularExpression Id. */ - int LSHIFT = 113; - /** RegularExpression Id. */ - int PLUSASSIGN = 114; - /** RegularExpression Id. */ - int MINUSASSIGN = 115; - /** RegularExpression Id. */ - int STARASSIGN = 116; - /** RegularExpression Id. */ - int SLASHASSIGN = 117; - /** RegularExpression Id. */ - int ANDASSIGN = 118; - /** RegularExpression Id. */ - int ORASSIGN = 119; - /** RegularExpression Id. */ - int XORASSIGN = 120; - /** RegularExpression Id. */ - int REMASSIGN = 121; - /** RegularExpression Id. */ - int LSHIFTASSIGN = 122; - /** RegularExpression Id. */ - int RSIGNEDSHIFTASSIGN = 123; - /** RegularExpression Id. */ - int RUNSIGNEDSHIFTASSIGN = 124; - /** RegularExpression Id. */ - int ELLIPSIS = 125; - /** RegularExpression Id. */ - int ARROW = 126; - /** RegularExpression Id. */ - int DOUBLECOLON = 127; - /** RegularExpression Id. */ - int RUNSIGNEDSHIFT = 128; - /** RegularExpression Id. */ - int RSIGNEDSHIFT = 129; - /** RegularExpression Id. */ - int GT = 130; - - /** Lexical state. */ - int DEFAULT = 0; - /** Lexical state. */ - int IN_JAVA_DOC_COMMENT = 1; - /** Lexical state. */ - int IN_MULTI_LINE_COMMENT = 2; - - /** Literal token values. */ - String[] tokenImage = { - "", - "\" \"", - "\"\\t\"", - "\"\\n\"", - "\"\\r\"", - "\"\\f\"", - "", - "", - "\"/*\"", - "\"*/\"", - "\"*/\"", - "", - "\"abstract\"", - "\"assert\"", - "\"boolean\"", - "\"break\"", - "\"byte\"", - "\"case\"", - "\"catch\"", - "\"char\"", - "\"class\"", - "\"const\"", - "\"continue\"", - "\"default\"", - "\"do\"", - "\"double\"", - "\"else\"", - "\"enum\"", - "\"extends\"", - "\"false\"", - "\"final\"", - "\"finally\"", - "\"float\"", - "\"for\"", - "\"goto\"", - "\"if\"", - "\"implements\"", - "\"import\"", - "\"instanceof\"", - "\"int\"", - "\"interface\"", - "\"long\"", - "\"native\"", - "\"new\"", - "\"null\"", - "\"package\"", - "\"private\"", - "\"protected\"", - "\"public\"", - "\"return\"", - "\"short\"", - "\"static\"", - "\"strictfp\"", - "\"super\"", - "\"switch\"", - "\"synchronized\"", - "\"this\"", - "\"throw\"", - "\"throws\"", - "\"transient\"", - "\"true\"", - "\"try\"", - "\"void\"", - "\"volatile\"", - "\"while\"", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "\"(\"", - "\")\"", - "\"{\"", - "\"}\"", - "\"[\"", - "\"]\"", - "\";\"", - "\",\"", - "\".\"", - "\"@\"", - "\"=\"", - "\"<\"", - "\"!\"", - "\"~\"", - "\"?\"", - "\":\"", - "\"==\"", - "\"<=\"", - "\">=\"", - "\"!=\"", - "\"||\"", - "\"&&\"", - "\"++\"", - "\"--\"", - "\"+\"", - "\"-\"", - "\"*\"", - "\"/\"", - "\"&\"", - "\"|\"", - "\"^\"", - "\"%\"", - "\"<<\"", - "\"+=\"", - "\"-=\"", - "\"*=\"", - "\"/=\"", - "\"&=\"", - "\"|=\"", - "\"^=\"", - "\"%=\"", - "\"<<=\"", - "\">>=\"", - "\">>>=\"", - "\"...\"", - "\"->\"", - "\"::\"", - "\">>>\"", - "\">>\"", - "\">\"", - "\"\\u001a\"", - "\"<>\"", - }; - -} +/* Generated By:JavaCC: Do not edit this line. GeneratedJavaParserConstants.java */ +/* + * 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; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface GeneratedJavaParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int SPACE = 1; + /** RegularExpression Id. */ + int WINDOWS_EOL = 2; + /** RegularExpression Id. */ + int UNIX_EOL = 3; + /** RegularExpression Id. */ + int OLD_MAC_EOL = 4; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 5; + /** RegularExpression Id. */ + int ENTER_JAVADOC_COMMENT = 6; + /** RegularExpression Id. */ + int ENTER_MULTILINE_COMMENT = 7; + /** RegularExpression Id. */ + int JAVADOC_COMMENT = 8; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 9; + /** RegularExpression Id. */ + int COMMENT_CONTENT = 10; + /** RegularExpression Id. */ + int ABSTRACT = 11; + /** RegularExpression Id. */ + int ASSERT = 12; + /** RegularExpression Id. */ + int BOOLEAN = 13; + /** RegularExpression Id. */ + int BREAK = 14; + /** RegularExpression Id. */ + int BYTE = 15; + /** RegularExpression Id. */ + int CASE = 16; + /** RegularExpression Id. */ + int CATCH = 17; + /** RegularExpression Id. */ + int CHAR = 18; + /** RegularExpression Id. */ + int CLASS = 19; + /** RegularExpression Id. */ + int CONST = 20; + /** RegularExpression Id. */ + int CONTINUE = 21; + /** RegularExpression Id. */ + int _DEFAULT = 22; + /** RegularExpression Id. */ + int DO = 23; + /** RegularExpression Id. */ + int DOUBLE = 24; + /** RegularExpression Id. */ + int ELSE = 25; + /** RegularExpression Id. */ + int ENUM = 26; + /** RegularExpression Id. */ + int EXTENDS = 27; + /** RegularExpression Id. */ + int FALSE = 28; + /** RegularExpression Id. */ + int FINAL = 29; + /** RegularExpression Id. */ + int FINALLY = 30; + /** RegularExpression Id. */ + int FLOAT = 31; + /** RegularExpression Id. */ + int FOR = 32; + /** RegularExpression Id. */ + int GOTO = 33; + /** RegularExpression Id. */ + int IF = 34; + /** RegularExpression Id. */ + int IMPLEMENTS = 35; + /** RegularExpression Id. */ + int IMPORT = 36; + /** RegularExpression Id. */ + int INSTANCEOF = 37; + /** RegularExpression Id. */ + int INT = 38; + /** RegularExpression Id. */ + int INTERFACE = 39; + /** RegularExpression Id. */ + int LONG = 40; + /** RegularExpression Id. */ + int NATIVE = 41; + /** RegularExpression Id. */ + int NEW = 42; + /** RegularExpression Id. */ + int NULL = 43; + /** RegularExpression Id. */ + int PACKAGE = 44; + /** RegularExpression Id. */ + int PRIVATE = 45; + /** RegularExpression Id. */ + int PROTECTED = 46; + /** RegularExpression Id. */ + int PUBLIC = 47; + /** RegularExpression Id. */ + int RETURN = 48; + /** RegularExpression Id. */ + int SHORT = 49; + /** RegularExpression Id. */ + int STATIC = 50; + /** RegularExpression Id. */ + int STRICTFP = 51; + /** RegularExpression Id. */ + int SUPER = 52; + /** RegularExpression Id. */ + int SWITCH = 53; + /** RegularExpression Id. */ + int SYNCHRONIZED = 54; + /** RegularExpression Id. */ + int THIS = 55; + /** RegularExpression Id. */ + int THROW = 56; + /** RegularExpression Id. */ + int THROWS = 57; + /** RegularExpression Id. */ + int TRANSIENT = 58; + /** RegularExpression Id. */ + int TRUE = 59; + /** RegularExpression Id. */ + int TRY = 60; + /** RegularExpression Id. */ + int VOID = 61; + /** RegularExpression Id. */ + int VOLATILE = 62; + /** RegularExpression Id. */ + int WHILE = 63; + /** RegularExpression Id. */ + int REQUIRES = 64; + /** RegularExpression Id. */ + int TO = 65; + /** RegularExpression Id. */ + int WITH = 66; + /** RegularExpression Id. */ + int OPEN = 67; + /** RegularExpression Id. */ + int OPENS = 68; + /** RegularExpression Id. */ + int USES = 69; + /** RegularExpression Id. */ + int MODULE = 70; + /** RegularExpression Id. */ + int EXPORTS = 71; + /** RegularExpression Id. */ + int PROVIDES = 72; + /** RegularExpression Id. */ + int TRANSITIVE = 73; + /** RegularExpression Id. */ + int LONG_LITERAL = 74; + /** RegularExpression Id. */ + int INTEGER_LITERAL = 75; + /** RegularExpression Id. */ + int DECIMAL_LITERAL = 76; + /** RegularExpression Id. */ + int HEX_LITERAL = 77; + /** RegularExpression Id. */ + int OCTAL_LITERAL = 78; + /** RegularExpression Id. */ + int BINARY_LITERAL = 79; + /** RegularExpression Id. */ + int FLOATING_POINT_LITERAL = 80; + /** RegularExpression Id. */ + int DECIMAL_FLOATING_POINT_LITERAL = 81; + /** RegularExpression Id. */ + int DECIMAL_EXPONENT = 82; + /** RegularExpression Id. */ + int HEXADECIMAL_FLOATING_POINT_LITERAL = 83; + /** RegularExpression Id. */ + int HEXADECIMAL_EXPONENT = 84; + /** RegularExpression Id. */ + int HEX_DIGITS = 85; + /** RegularExpression Id. */ + int UNICODE_ESCAPE = 86; + /** RegularExpression Id. */ + int CHARACTER_LITERAL = 87; + /** RegularExpression Id. */ + int STRING_LITERAL = 88; + /** RegularExpression Id. */ + int IDENTIFIER = 89; + /** RegularExpression Id. */ + int LETTER = 90; + /** RegularExpression Id. */ + int PART_LETTER = 91; + /** RegularExpression Id. */ + int LPAREN = 92; + /** RegularExpression Id. */ + int RPAREN = 93; + /** RegularExpression Id. */ + int LBRACE = 94; + /** RegularExpression Id. */ + int RBRACE = 95; + /** RegularExpression Id. */ + int LBRACKET = 96; + /** RegularExpression Id. */ + int RBRACKET = 97; + /** RegularExpression Id. */ + int SEMICOLON = 98; + /** RegularExpression Id. */ + int COMMA = 99; + /** RegularExpression Id. */ + int DOT = 100; + /** RegularExpression Id. */ + int AT = 101; + /** RegularExpression Id. */ + int ASSIGN = 102; + /** RegularExpression Id. */ + int LT = 103; + /** RegularExpression Id. */ + int BANG = 104; + /** RegularExpression Id. */ + int TILDE = 105; + /** RegularExpression Id. */ + int HOOK = 106; + /** RegularExpression Id. */ + int COLON = 107; + /** RegularExpression Id. */ + int EQ = 108; + /** RegularExpression Id. */ + int LE = 109; + /** RegularExpression Id. */ + int GE = 110; + /** RegularExpression Id. */ + int NE = 111; + /** RegularExpression Id. */ + int SC_OR = 112; + /** RegularExpression Id. */ + int SC_AND = 113; + /** RegularExpression Id. */ + int INCR = 114; + /** RegularExpression Id. */ + int DECR = 115; + /** RegularExpression Id. */ + int PLUS = 116; + /** RegularExpression Id. */ + int MINUS = 117; + /** RegularExpression Id. */ + int STAR = 118; + /** RegularExpression Id. */ + int SLASH = 119; + /** RegularExpression Id. */ + int BIT_AND = 120; + /** RegularExpression Id. */ + int BIT_OR = 121; + /** RegularExpression Id. */ + int XOR = 122; + /** RegularExpression Id. */ + int REM = 123; + /** RegularExpression Id. */ + int LSHIFT = 124; + /** RegularExpression Id. */ + int PLUSASSIGN = 125; + /** RegularExpression Id. */ + int MINUSASSIGN = 126; + /** RegularExpression Id. */ + int STARASSIGN = 127; + /** RegularExpression Id. */ + int SLASHASSIGN = 128; + /** RegularExpression Id. */ + int ANDASSIGN = 129; + /** RegularExpression Id. */ + int ORASSIGN = 130; + /** RegularExpression Id. */ + int XORASSIGN = 131; + /** RegularExpression Id. */ + int REMASSIGN = 132; + /** RegularExpression Id. */ + int LSHIFTASSIGN = 133; + /** RegularExpression Id. */ + int RSIGNEDSHIFTASSIGN = 134; + /** RegularExpression Id. */ + int RUNSIGNEDSHIFTASSIGN = 135; + /** RegularExpression Id. */ + int ELLIPSIS = 136; + /** RegularExpression Id. */ + int ARROW = 137; + /** RegularExpression Id. */ + int DOUBLECOLON = 138; + /** RegularExpression Id. */ + int RUNSIGNEDSHIFT = 139; + /** RegularExpression Id. */ + int RSIGNEDSHIFT = 140; + /** RegularExpression Id. */ + int GT = 141; + /** RegularExpression Id. */ + int CTRL_Z = 142; + + /** Lexical state. */ + int DEFAULT = 0; + /** Lexical state. */ + int IN_JAVADOC_COMMENT = 1; + /** Lexical state. */ + int IN_MULTI_LINE_COMMENT = 2; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "\"\\r\\n\"", + "\"\\n\"", + "\"\\r\"", + "", + "", + "\"/*\"", + "\"*/\"", + "\"*/\"", + "", + "\"abstract\"", + "\"assert\"", + "\"boolean\"", + "\"break\"", + "\"byte\"", + "\"case\"", + "\"catch\"", + "\"char\"", + "\"class\"", + "\"const\"", + "\"continue\"", + "\"default\"", + "\"do\"", + "\"double\"", + "\"else\"", + "\"enum\"", + "\"extends\"", + "\"false\"", + "\"final\"", + "\"finally\"", + "\"float\"", + "\"for\"", + "\"goto\"", + "\"if\"", + "\"implements\"", + "\"import\"", + "\"instanceof\"", + "\"int\"", + "\"interface\"", + "\"long\"", + "\"native\"", + "\"new\"", + "\"null\"", + "\"package\"", + "\"private\"", + "\"protected\"", + "\"public\"", + "\"return\"", + "\"short\"", + "\"static\"", + "\"strictfp\"", + "\"super\"", + "\"switch\"", + "\"synchronized\"", + "\"this\"", + "\"throw\"", + "\"throws\"", + "\"transient\"", + "\"true\"", + "\"try\"", + "\"void\"", + "\"volatile\"", + "\"while\"", + "\"requires\"", + "\"to\"", + "\"with\"", + "\"open\"", + "\"opens\"", + "\"uses\"", + "\"module\"", + "\"exports\"", + "\"provides\"", + "\"transitive\"", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\";\"", + "\",\"", + "\".\"", + "\"@\"", + "\"=\"", + "\"<\"", + "\"!\"", + "\"~\"", + "\"?\"", + "\":\"", + "\"==\"", + "\"<=\"", + "\">=\"", + "\"!=\"", + "\"||\"", + "\"&&\"", + "\"++\"", + "\"--\"", + "\"+\"", + "\"-\"", + "\"*\"", + "\"/\"", + "\"&\"", + "\"|\"", + "\"^\"", + "\"%\"", + "\"<<\"", + "\"+=\"", + "\"-=\"", + "\"*=\"", + "\"/=\"", + "\"&=\"", + "\"|=\"", + "\"^=\"", + "\"%=\"", + "\"<<=\"", + "\">>=\"", + "\">>>=\"", + "\"...\"", + "\"->\"", + "\"::\"", + "\">>>\"", + "\">>\"", + "\">\"", + "\"\\u001a\"", + }; + +} diff --git a/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManager.java b/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManager.java new file mode 100644 index 0000000..93f3408 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManager.java @@ -0,0 +1,2966 @@ +/* GeneratedJavaParserTokenManager.java */ +/* Generated By:JavaCC: Do not edit this line. GeneratedJavaParserTokenManager.java */ +/* + * 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 java.util.*; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import com.github.javaparser.utils.*; +import javax.annotation.Generated; +import static com.github.javaparser.JavaToken.INVALID; +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.Utils.*; +import static com.github.javaparser.ast.NodeList.*; +import static com.github.javaparser.GeneratedJavaParser.*; +import static com.github.javaparser.Range.*; +import static com.github.javaparser.Position.*; +import static com.github.javaparser.ast.type.ArrayType.*; +import static com.github.javaparser.GeneratedJavaParserTokenManagerBase.*; + +/** Token Manager. */ +public class GeneratedJavaParserTokenManager implements GeneratedJavaParserConstants { + private List tokens = new ArrayList(); + private CommentsCollection commentsCollection = new CommentsCollection(); + private JavaToken homeToken; + private Stack tokenWorkStack = new Stack(); + private boolean storeTokens; + + void reset() { + tokens = new ArrayList(); + commentsCollection = new CommentsCollection(); + homeToken = null; + } + + List getTokens() { + if(storeTokens) { + return tokens; + } + return null; + } + + CommentsCollection getCommentsCollection() { + return commentsCollection; + } + + /* Get the very first token in the file */ + JavaToken getHomeToken() { + return homeToken; + } + + /* Makes the parser keep a list of tokens */ + public void setStoreTokens(boolean storeTokens) { + this.storeTokens = storeTokens; + } + + private void CommonTokenAction(Token token) { + // Use an intermediary stack to avoid recursion, see issue 1003 + do { + tokenWorkStack.push(token); + token = token.specialToken; + } while (token != null); + + // The stack is now filled with tokens in left-to-right order. Process them. + while(!tokenWorkStack.empty()) { + token = tokenWorkStack.pop(); + token.javaToken = new JavaToken(token, tokens); + + if(storeTokens) { + tokens.add(token.javaToken); + } + + if (homeToken == null) { + homeToken = token.javaToken; + } + + if(TokenTypes.isComment(token.kind)) { + Comment comment = createCommentFromToken(token); + commentsCollection.addComment(comment); + } + } + } + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1, long active2){ + switch (pos) + { + case 0: + if ((active1 & 0x1000000000L) != 0L || (active2 & 0x100L) != 0L) + return 2; + if ((active0 & 0xfffffffffffff800L) != 0L || (active1 & 0x3ffL) != 0L) + { + jjmatchedKind = 89; + return 144; + } + if ((active0 & 0x80L) != 0L || (active1 & 0x80000000000000L) != 0L || (active2 & 0x1L) != 0L) + return 56; + return -1; + case 1: + if ((active0 & 0x80L) != 0L) + return 61; + if ((active0 & 0xfffffffbfe7ff800L) != 0L || (active1 & 0x3fdL) != 0L) + { + if (jjmatchedPos != 1) + { + jjmatchedKind = 89; + jjmatchedPos = 1; + } + return 144; + } + if ((active0 & 0x401800000L) != 0L || (active1 & 0x2L) != 0L) + return 144; + return -1; + case 2: + if ((active0 & 0x100004c100000000L) != 0L) + return 144; + if ((active0 & 0xeffffb3aff7ff800L) != 0L || (active1 & 0x3fdL) != 0L) + { + if (jjmatchedPos != 2) + { + jjmatchedKind = 89; + jjmatchedPos = 2; + } + return 144; + } + return -1; + case 3: + if ((active0 & 0x2880090206058000L) != 0L || (active1 & 0x3cL) != 0L) + return 144; + if ((active0 & 0xc77ff2b8f97a7800L) != 0L || (active1 & 0x3c1L) != 0L) + { + if (jjmatchedPos != 3) + { + jjmatchedKind = 89; + jjmatchedPos = 3; + } + return 144; + } + return -1; + case 4: + if ((active0 & 0x446df2b809603800L) != 0L || (active1 & 0x3c1L) != 0L) + { + if (jjmatchedPos != 4) + { + jjmatchedKind = 89; + jjmatchedPos = 4; + } + return 144; + } + if ((active0 & 0x83120000f01a4000L) != 0L || (active1 & 0x10L) != 0L) + return 144; + return -1; + case 5: + if ((active0 & 0x225821001001000L) != 0L || (active1 & 0x40L) != 0L) + return 144; + if ((active0 & 0x444870a848602800L) != 0L || (active1 & 0x381L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 5; + return 144; + } + return -1; + case 6: + if ((active0 & 0x300048402000L) != 0L || (active1 & 0x80L) != 0L) + return 144; + if ((active0 & 0x444840a800200800L) != 0L || (active1 & 0x301L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 6; + return 144; + } + return -1; + case 7: + if ((active0 & 0x44040a800000000L) != 0L || (active1 & 0x200L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 7; + return 144; + } + if ((active0 & 0x4008000000200800L) != 0L || (active1 & 0x101L) != 0L) + return 144; + return -1; + case 8: + if ((active0 & 0x400408000000000L) != 0L) + return 144; + if ((active0 & 0x40002800000000L) != 0L || (active1 & 0x200L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 8; + return 144; + } + return -1; + case 9: + if ((active0 & 0x2800000000L) != 0L || (active1 & 0x200L) != 0L) + return 144; + if ((active0 & 0x40000000000000L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 9; + return 144; + } + return -1; + case 10: + if ((active0 & 0x40000000000000L) != 0L) + { + jjmatchedKind = 89; + jjmatchedPos = 10; + return 144; + } + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0, long active1, long active2){ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1, active2), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case 10: + return jjStopAtPos(0, 3); + case 13: + jjmatchedKind = 4; + return jjMoveStringLiteralDfa1_0(0x4L, 0x0L, 0x0L); + case 26: + return jjStopAtPos(0, 142); + case 33: + jjmatchedKind = 104; + return jjMoveStringLiteralDfa1_0(0x0L, 0x800000000000L, 0x0L); + case 37: + jjmatchedKind = 123; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x10L); + case 38: + jjmatchedKind = 120; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000000000L, 0x2L); + case 40: + return jjStopAtPos(0, 92); + case 41: + return jjStopAtPos(0, 93); + case 42: + jjmatchedKind = 118; + return jjMoveStringLiteralDfa1_0(0x0L, 0x8000000000000000L, 0x0L); + case 43: + jjmatchedKind = 116; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2004000000000000L, 0x0L); + case 44: + return jjStopAtPos(0, 99); + case 45: + jjmatchedKind = 117; + return jjMoveStringLiteralDfa1_0(0x0L, 0x4008000000000000L, 0x200L); + case 46: + jjmatchedKind = 100; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x100L); + case 47: + jjmatchedKind = 119; + return jjMoveStringLiteralDfa1_0(0x80L, 0x0L, 0x1L); + case 58: + jjmatchedKind = 107; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x400L); + case 59: + return jjStopAtPos(0, 98); + case 60: + jjmatchedKind = 103; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1000200000000000L, 0x20L); + case 61: + jjmatchedKind = 102; + return jjMoveStringLiteralDfa1_0(0x0L, 0x100000000000L, 0x0L); + case 62: + jjmatchedKind = 141; + return jjMoveStringLiteralDfa1_0(0x0L, 0x400000000000L, 0x18c0L); + case 63: + return jjStopAtPos(0, 106); + case 64: + return jjStopAtPos(0, 101); + case 91: + return jjStopAtPos(0, 96); + case 93: + return jjStopAtPos(0, 97); + case 94: + jjmatchedKind = 122; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x8L); + case 97: + return jjMoveStringLiteralDfa1_0(0x1800L, 0x0L, 0x0L); + case 98: + return jjMoveStringLiteralDfa1_0(0xe000L, 0x0L, 0x0L); + case 99: + return jjMoveStringLiteralDfa1_0(0x3f0000L, 0x0L, 0x0L); + case 100: + return jjMoveStringLiteralDfa1_0(0x1c00000L, 0x0L, 0x0L); + case 101: + return jjMoveStringLiteralDfa1_0(0xe000000L, 0x80L, 0x0L); + case 102: + return jjMoveStringLiteralDfa1_0(0x1f0000000L, 0x0L, 0x0L); + case 103: + return jjMoveStringLiteralDfa1_0(0x200000000L, 0x0L, 0x0L); + case 105: + return jjMoveStringLiteralDfa1_0(0xfc00000000L, 0x0L, 0x0L); + case 108: + return jjMoveStringLiteralDfa1_0(0x10000000000L, 0x0L, 0x0L); + case 109: + return jjMoveStringLiteralDfa1_0(0x0L, 0x40L, 0x0L); + case 110: + return jjMoveStringLiteralDfa1_0(0xe0000000000L, 0x0L, 0x0L); + case 111: + return jjMoveStringLiteralDfa1_0(0x0L, 0x18L, 0x0L); + case 112: + return jjMoveStringLiteralDfa1_0(0xf00000000000L, 0x100L, 0x0L); + case 114: + return jjMoveStringLiteralDfa1_0(0x1000000000000L, 0x1L, 0x0L); + case 115: + return jjMoveStringLiteralDfa1_0(0x7e000000000000L, 0x0L, 0x0L); + case 116: + return jjMoveStringLiteralDfa1_0(0x1f80000000000000L, 0x202L, 0x0L); + case 117: + return jjMoveStringLiteralDfa1_0(0x0L, 0x20L, 0x0L); + case 118: + return jjMoveStringLiteralDfa1_0(0x6000000000000000L, 0x0L, 0x0L); + case 119: + return jjMoveStringLiteralDfa1_0(0x8000000000000000L, 0x4L, 0x0L); + case 123: + return jjStopAtPos(0, 94); + case 124: + jjmatchedKind = 121; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1000000000000L, 0x4L); + case 125: + return jjStopAtPos(0, 95); + case 126: + return jjStopAtPos(0, 105); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0, long active1, long active2){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0, active1, active2); + return 1; + } + switch(curChar) + { + case 10: + if ((active0 & 0x4L) != 0L) + return jjStopAtPos(1, 2); + break; + case 38: + if ((active1 & 0x2000000000000L) != 0L) + return jjStopAtPos(1, 113); + break; + case 42: + if ((active0 & 0x80L) != 0L) + return jjStartNfaWithStates_0(1, 7, 61); + break; + case 43: + if ((active1 & 0x4000000000000L) != 0L) + return jjStopAtPos(1, 114); + break; + case 45: + if ((active1 & 0x8000000000000L) != 0L) + return jjStopAtPos(1, 115); + break; + case 46: + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x100L); + case 58: + if ((active2 & 0x400L) != 0L) + return jjStopAtPos(1, 138); + break; + case 60: + if ((active1 & 0x1000000000000000L) != 0L) + { + jjmatchedKind = 124; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x20L); + case 61: + if ((active1 & 0x100000000000L) != 0L) + return jjStopAtPos(1, 108); + else if ((active1 & 0x200000000000L) != 0L) + return jjStopAtPos(1, 109); + else if ((active1 & 0x400000000000L) != 0L) + return jjStopAtPos(1, 110); + else if ((active1 & 0x800000000000L) != 0L) + return jjStopAtPos(1, 111); + else if ((active1 & 0x2000000000000000L) != 0L) + return jjStopAtPos(1, 125); + else if ((active1 & 0x4000000000000000L) != 0L) + return jjStopAtPos(1, 126); + else if ((active1 & 0x8000000000000000L) != 0L) + return jjStopAtPos(1, 127); + else if ((active2 & 0x1L) != 0L) + return jjStopAtPos(1, 128); + else if ((active2 & 0x2L) != 0L) + return jjStopAtPos(1, 129); + else if ((active2 & 0x4L) != 0L) + return jjStopAtPos(1, 130); + else if ((active2 & 0x8L) != 0L) + return jjStopAtPos(1, 131); + else if ((active2 & 0x10L) != 0L) + return jjStopAtPos(1, 132); + break; + case 62: + if ((active2 & 0x200L) != 0L) + return jjStopAtPos(1, 137); + else if ((active2 & 0x1000L) != 0L) + { + jjmatchedKind = 140; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x8c0L); + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x120010030000L, active1, 0L, active2, 0L); + case 98: + return jjMoveStringLiteralDfa2_0(active0, 0x800L, active1, 0L, active2, 0L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x1040000400000L, active1, 0x1L, active2, 0L); + case 102: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(1, 34, 144); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x8382000000040000L, active1, 0L, active2, 0L); + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x60000000L, active1, 0x4L, active2, 0L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x82080000L, active1, 0L, active2, 0L); + case 109: + return jjMoveStringLiteralDfa2_0(active0, 0x1800000000L, active1, 0L, active2, 0L); + case 110: + return jjMoveStringLiteralDfa2_0(active0, 0xe004000000L, active1, 0L, active2, 0L); + case 111: + if ((active0 & 0x800000L) != 0L) + { + jjmatchedKind = 23; + jjmatchedPos = 1; + } + else if ((active1 & 0x2L) != 0L) + return jjStartNfaWithStates_0(1, 65, 144); + return jjMoveStringLiteralDfa2_0(active0, 0x6000010301302000L, active1, 0x40L, active2, 0L); + case 112: + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x18L, active2, 0L); + case 114: + return jjMoveStringLiteralDfa2_0(active0, 0x1c00600000004000L, active1, 0x300L, active2, 0L); + case 115: + return jjMoveStringLiteralDfa2_0(active0, 0x1000L, active1, 0x20L, active2, 0L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0xc000000000000L, active1, 0L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x10880000000000L, active1, 0L, active2, 0L); + case 119: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000000000L, active1, 0L, active2, 0L); + case 120: + return jjMoveStringLiteralDfa2_0(active0, 0x8000000L, active1, 0x80L, active2, 0L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x40000000008000L, active1, 0L, active2, 0L); + case 124: + if ((active1 & 0x1000000000000L) != 0L) + return jjStopAtPos(1, 112); + break; + default : + break; + } + return jjStartNfa_0(0, active0, active1, active2); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1, long old2, long active2){ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(0, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0, active1, active2); + return 2; + } + switch(curChar) + { + case 46: + if ((active2 & 0x100L) != 0L) + return jjStopAtPos(2, 136); + break; + case 61: + if ((active2 & 0x20L) != 0L) + return jjStopAtPos(2, 133); + else if ((active2 & 0x40L) != 0L) + return jjStopAtPos(2, 134); + break; + case 62: + if ((active2 & 0x800L) != 0L) + { + jjmatchedKind = 139; + jjmatchedPos = 2; + } + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0L, active2, 0x80L); + case 97: + return jjMoveStringLiteralDfa3_0(active0, 0x4040000000c0000L, active1, 0x200L, active2, 0L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x800000000000L, active1, 0L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa3_0(active0, 0x100000000000L, active1, 0L, active2, 0L); + case 100: + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x40L, active2, 0L); + case 101: + return jjMoveStringLiteralDfa3_0(active0, 0x4000L, active1, 0x38L, active2, 0L); + case 102: + return jjMoveStringLiteralDfa3_0(active0, 0x400000L, active1, 0L, active2, 0L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0xa0a0200000000000L, active1, 0L, active2, 0L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x4000080010000000L, active1, 0L, active2, 0L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x40010060300000L, active1, 0L, active2, 0L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x2400080002000L, active1, 0x100L, active2, 0L); + case 112: + return jjMoveStringLiteralDfa3_0(active0, 0x10001800000000L, active1, 0x80L, active2, 0L); + case 113: + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x1L, active2, 0L); + case 114: + if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(2, 32, 144); + return jjMoveStringLiteralDfa3_0(active0, 0x308000000000000L, active1, 0L, active2, 0L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x2002011800L, active1, 0L, active2, 0L); + case 116: + if ((active0 & 0x4000000000L) != 0L) + { + jjmatchedKind = 38; + jjmatchedPos = 2; + } + return jjMoveStringLiteralDfa3_0(active0, 0x1028208028000L, active1, 0x4L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x800000005000000L, active1, 0L, active2, 0L); + case 119: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(2, 42, 144); + break; + case 121: + if ((active0 & 0x1000000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 60, 144); + break; + default : + break; + } + return jjStartNfa_0(1, active0, active1, active2); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1, long old2, long active2){ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(1, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0, active1, active2); + return 3; + } + switch(curChar) + { + case 61: + if ((active2 & 0x80L) != 0L) + return jjStopAtPos(3, 135); + break; + case 97: + return jjMoveStringLiteralDfa4_0(active0, 0x40000000e0404000L, active1, 0L, active2, 0L); + case 98: + return jjMoveStringLiteralDfa4_0(active0, 0x1000000L, active1, 0L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa4_0(active0, 0x40000000020000L, active1, 0L, active2, 0L); + case 100: + if ((active0 & 0x2000000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 61, 144); + break; + case 101: + if ((active0 & 0x8000L) != 0L) + return jjStartNfaWithStates_0(3, 15, 144); + else if ((active0 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(3, 16, 144); + else if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(3, 25, 144); + else if ((active0 & 0x800000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 59, 144); + return jjMoveStringLiteralDfa4_0(active0, 0x10008008001000L, active1, 0L, active2, 0L); + case 103: + if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(3, 40, 144); + break; + case 104: + if ((active1 & 0x4L) != 0L) + return jjStartNfaWithStates_0(3, 66, 144); + break; + case 105: + return jjMoveStringLiteralDfa4_0(active0, 0x8020000000000L, active1, 0L, active2, 0L); + case 107: + return jjMoveStringLiteralDfa4_0(active0, 0x100000000000L, active1, 0L, active2, 0L); + case 108: + if ((active0 & 0x80000000000L) != 0L) + return jjStartNfaWithStates_0(3, 43, 144); + return jjMoveStringLiteralDfa4_0(active0, 0x8000800800002000L, active1, 0L, active2, 0L); + case 109: + if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(3, 26, 144); + break; + case 110: + if ((active1 & 0x8L) != 0L) + { + jjmatchedKind = 67; + jjmatchedPos = 3; + } + return jjMoveStringLiteralDfa4_0(active0, 0x400000000000000L, active1, 0x210L, active2, 0L); + case 111: + if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(3, 33, 144); + return jjMoveStringLiteralDfa4_0(active0, 0x300001000000000L, active1, 0x80L, active2, 0L); + case 114: + if ((active0 & 0x40000L) != 0L) + return jjStartNfaWithStates_0(3, 18, 144); + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L, active2, 0L); + case 115: + if ((active0 & 0x80000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 55, 144); + else if ((active1 & 0x20L) != 0L) + return jjStartNfaWithStates_0(3, 69, 144); + return jjMoveStringLiteralDfa4_0(active0, 0x10180000L, active1, 0L, active2, 0L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x24402000200800L, active1, 0L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x1000000000000L, active1, 0x41L, active2, 0L); + case 118: + return jjMoveStringLiteralDfa4_0(active0, 0x200000000000L, active1, 0x100L, active2, 0L); + default : + break; + } + return jjStartNfa_0(2, active0, active1, active2); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1, long old2, long active2){ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(2, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0, active1, 0L); + return 4; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa5_0(active0, 0x302000000000L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa5_0(active0, 0x28000000000000L, active1, 0L); + case 101: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(4, 28, 144); + else if ((active0 & 0x8000000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 63, 144); + return jjMoveStringLiteralDfa5_0(active0, 0x400800002000L, active1, 0L); + case 104: + if ((active0 & 0x20000L) != 0L) + return jjStartNfaWithStates_0(4, 17, 144); + return jjMoveStringLiteralDfa5_0(active0, 0x40000000000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x4800000200000L, active1, 0x101L); + case 107: + if ((active0 & 0x4000L) != 0L) + return jjStartNfaWithStates_0(4, 14, 144); + break; + case 108: + if ((active0 & 0x20000000L) != 0L) + { + jjmatchedKind = 29; + jjmatchedPos = 4; + } + return jjMoveStringLiteralDfa5_0(active0, 0x41000000L, active1, 0x40L); + case 110: + return jjMoveStringLiteralDfa5_0(active0, 0x8000000L, active1, 0L); + case 114: + if ((active0 & 0x10000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 52, 144); + return jjMoveStringLiteralDfa5_0(active0, 0x1009000001800L, active1, 0x80L); + case 115: + if ((active0 & 0x80000L) != 0L) + return jjStartNfaWithStates_0(4, 19, 144); + else if ((active1 & 0x10L) != 0L) + return jjStartNfaWithStates_0(4, 68, 144); + return jjMoveStringLiteralDfa5_0(active0, 0x400000000000000L, active1, 0x200L); + case 116: + if ((active0 & 0x100000L) != 0L) + return jjStartNfaWithStates_0(4, 20, 144); + else if ((active0 & 0x80000000L) != 0L) + return jjStartNfaWithStates_0(4, 31, 144); + else if ((active0 & 0x2000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 49, 144); + return jjMoveStringLiteralDfa5_0(active0, 0x4000000000000000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa5_0(active0, 0x400000L, active1, 0L); + case 118: + return jjMoveStringLiteralDfa5_0(active0, 0x20000000000L, active1, 0L); + case 119: + if ((active0 & 0x100000000000000L) != 0L) + { + jjmatchedKind = 56; + jjmatchedPos = 4; + } + return jjMoveStringLiteralDfa5_0(active0, 0x200000000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(3, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(3, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0, active1, 0L); + return 5; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa6_0(active0, 0x2800L, active1, 0L); + case 99: + if ((active0 & 0x800000000000L) != 0L) + return jjStartNfaWithStates_0(5, 47, 144); + else if ((active0 & 0x4000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 50, 144); + return jjMoveStringLiteralDfa6_0(active0, 0x400000000000L, active1, 0L); + case 100: + return jjMoveStringLiteralDfa6_0(active0, 0x8000000L, active1, 0x100L); + case 101: + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(5, 24, 144); + else if ((active0 & 0x20000000000L) != 0L) + return jjStartNfaWithStates_0(5, 41, 144); + else if ((active1 & 0x40L) != 0L) + return jjStartNfaWithStates_0(5, 70, 144); + break; + case 102: + return jjMoveStringLiteralDfa6_0(active0, 0x8000000000L, active1, 0L); + case 103: + return jjMoveStringLiteralDfa6_0(active0, 0x100000000000L, active1, 0L); + case 104: + if ((active0 & 0x20000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 53, 144); + break; + case 105: + return jjMoveStringLiteralDfa6_0(active0, 0x4400000000000000L, active1, 0x200L); + case 108: + return jjMoveStringLiteralDfa6_0(active0, 0x40400000L, active1, 0L); + case 109: + return jjMoveStringLiteralDfa6_0(active0, 0x800000000L, active1, 0L); + case 110: + if ((active0 & 0x1000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 48, 144); + return jjMoveStringLiteralDfa6_0(active0, 0x2000200000L, active1, 0L); + case 114: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000000000L, active1, 0x1L); + case 115: + if ((active0 & 0x200000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 57, 144); + break; + case 116: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(5, 12, 144); + else if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(5, 36, 144); + return jjMoveStringLiteralDfa6_0(active0, 0x8200000000000L, active1, 0x80L); + default : + break; + } + return jjStartNfa_0(4, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(4, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(5, active0, active1, 0L); + return 6; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x8000000000L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000800L, active1, 0L); + case 101: + if ((active0 & 0x100000000000L) != 0L) + return jjStartNfaWithStates_0(6, 44, 144); + else if ((active0 & 0x200000000000L) != 0L) + return jjStartNfaWithStates_0(6, 45, 144); + return jjMoveStringLiteralDfa7_0(active0, 0x400000800000000L, active1, 0x101L); + case 102: + return jjMoveStringLiteralDfa7_0(active0, 0x8000000000000L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa7_0(active0, 0x4000000000000000L, active1, 0L); + case 110: + if ((active0 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(6, 13, 144); + break; + case 111: + return jjMoveStringLiteralDfa7_0(active0, 0x40000000000000L, active1, 0L); + case 115: + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(6, 27, 144); + else if ((active1 & 0x80L) != 0L) + return jjStartNfaWithStates_0(6, 71, 144); + break; + case 116: + if ((active0 & 0x400000L) != 0L) + return jjStartNfaWithStates_0(6, 22, 144); + return jjMoveStringLiteralDfa7_0(active0, 0x400000000000L, active1, 0x200L); + case 117: + return jjMoveStringLiteralDfa7_0(active0, 0x200000L, active1, 0L); + case 121: + if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(6, 30, 144); + break; + default : + break; + } + return jjStartNfa_0(5, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(5, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(6, active0, active1, 0L); + return 7; + } + switch(curChar) + { + case 99: + return jjMoveStringLiteralDfa8_0(active0, 0x8000000000L, active1, 0L); + case 101: + if ((active0 & 0x200000L) != 0L) + return jjStartNfaWithStates_0(7, 21, 144); + else if ((active0 & 0x4000000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 62, 144); + return jjMoveStringLiteralDfa8_0(active0, 0x402000000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa8_0(active0, 0L, active1, 0x200L); + case 110: + return jjMoveStringLiteralDfa8_0(active0, 0x440000800000000L, active1, 0L); + case 112: + if ((active0 & 0x8000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 51, 144); + break; + case 115: + if ((active1 & 0x1L) != 0L) + return jjStartNfaWithStates_0(7, 64, 144); + else if ((active1 & 0x100L) != 0L) + return jjStartNfaWithStates_0(7, 72, 144); + break; + case 116: + if ((active0 & 0x800L) != 0L) + return jjStartNfaWithStates_0(7, 11, 144); + break; + default : + break; + } + return jjStartNfa_0(6, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(6, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(7, active0, active1, 0L); + return 8; + } + switch(curChar) + { + case 100: + if ((active0 & 0x400000000000L) != 0L) + return jjStartNfaWithStates_0(8, 46, 144); + break; + case 101: + if ((active0 & 0x8000000000L) != 0L) + return jjStartNfaWithStates_0(8, 39, 144); + break; + case 105: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa9_0(active0, 0x2000000000L, active1, 0L); + case 116: + if ((active0 & 0x400000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 58, 144); + return jjMoveStringLiteralDfa9_0(active0, 0x800000000L, active1, 0L); + case 118: + return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0x200L); + default : + break; + } + return jjStartNfa_0(7, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(7, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0, active1, 0L); + return 9; + } + switch(curChar) + { + case 101: + if ((active1 & 0x200L) != 0L) + return jjStartNfaWithStates_0(9, 73, 144); + break; + case 102: + if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(9, 37, 144); + break; + case 115: + if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(9, 35, 144); + break; + case 122: + return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(8, active0, active1, 0L); +} +private int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long active1){ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(8, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0, 0L, 0L); + return 10; + } + switch(curChar) + { + case 101: + return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L); + default : + break; + } + return jjStartNfa_0(9, active0, 0L, 0L); +} +private int jjMoveStringLiteralDfa11_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(9, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0, 0L, 0L); + return 11; + } + switch(curChar) + { + case 100: + if ((active0 & 0x40000000000000L) != 0L) + return jjStartNfaWithStates_0(11, 54, 144); + break; + default : + break; + } + return jjStartNfa_0(10, active0, 0L, 0L); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0x100000020L, 0x0L +}; +static final long[] jjbitVec1 = { + 0x0L, 0x0L, 0x1L, 0x0L +}; +static final long[] jjbitVec2 = { + 0x4000L, 0x0L, 0x0L, 0x0L +}; +static final long[] jjbitVec3 = { + 0x830000003fffL, 0x180000000L, 0x0L, 0x0L +}; +static final long[] jjbitVec4 = { + 0x1L, 0x0L, 0x0L, 0x0L +}; +static final long[] jjbitVec5 = { + 0x0L, 0x0L, 0x0L, 0x8000000000000000L +}; +static final long[] jjbitVec6 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec8 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec9 = { + 0xfff0000040220002L, 0xffffffffffffdfffL, 0xfffff02f7fffffffL, 0x12000000ff7fffffL +}; +static final long[] jjbitVec10 = { + 0x0L, 0x0L, 0x420043c00000000L, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec11 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x501f0003ffc3L +}; +static final long[] jjbitVec12 = { + 0x0L, 0x3cdf000000000000L, 0xfffffffbffffd740L, 0xffbfffffffffffffL +}; +static final long[] jjbitVec13 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffffc03L, 0xffffffffffffffffL +}; +static final long[] jjbitVec14 = { + 0xfffe00ffffffffffL, 0xfffffffe027fffffL, 0x80ffL, 0x707ffffff0000L +}; +static final long[] jjbitVec15 = { + 0xffffffff00000800L, 0xfffec000000007ffL, 0xffffffffffffffffL, 0x9c00c060002fffffL +}; +static final long[] jjbitVec16 = { + 0xfffffffd0000L, 0xffffffffffffe000L, 0x2003fffffffffL, 0x43007fffffffc00L +}; +static final long[] jjbitVec17 = { + 0x110043fffffL, 0x1ffffffL, 0x1ffd00000000L, 0x0L +}; +static final long[] jjbitVec18 = { + 0x23fffffffffffff0L, 0xfefe0003ff010000L, 0x23c5fdfffff99fe0L, 0x80f0003b0004000L +}; +static final long[] jjbitVec19 = { + 0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbbfe0L, 0x2000300010000L +}; +static final long[] jjbitVec20 = { + 0x23edfdfffff99fe0L, 0x20003b0000000L, 0x3ffc718d63dc7e8L, 0x200000000010000L +}; +static final long[] jjbitVec21 = { + 0x23effdfffffddfe0L, 0x303000000L, 0x23effdfffffddfe0L, 0x6000340000000L +}; +static final long[] jjbitVec22 = { + 0x27fffffffffddfe0L, 0xfc00000300004000L, 0x2ffbfffffc7fffe0L, 0x7fL +}; +static final long[] jjbitVec23 = { + 0x800dfffffffffffeL, 0x7fL, 0x200decaefef02596L, 0xf000005fL +}; +static final long[] jjbitVec24 = { + 0x1L, 0x1ffffffffeffL, 0x1f00L, 0x0L +}; +static final long[] jjbitVec25 = { + 0x800007ffffffffffL, 0xffe1c0623c3f0000L, 0xffffffff00004003L, 0xf7ffffffffff20bfL +}; +static final long[] jjbitVec26 = { + 0xffffffffffffffffL, 0xffffffff3d7f3dffL, 0x7f3dffffffff3dffL, 0xffffffffff7fff3dL +}; +static final long[] jjbitVec27 = { + 0xffffffffff3dffffL, 0x7ffffffL, 0xffffffff0000ffffL, 0x1fffffffffffffL +}; +static final long[] jjbitVec28 = { + 0xffffffffffffffffL, 0xffff9fffffffffffL, 0xffffffff07fffffeL, 0x1c7ffffffffffL +}; +static final long[] jjbitVec29 = { + 0x3ffff0003dfffL, 0x1dfff0003ffffL, 0xfffffffffffffL, 0x18800000L +}; +static final long[] jjbitVec30 = { + 0xffffffff00000000L, 0xffffffffffffffL, 0xffff05ffffffffffL, 0x3fffffffffffffL +}; +static final long[] jjbitVec31 = { + 0x1fffffffL, 0x1f3fffffff0000L, 0xfffffffffffL, 0xfeL +}; +static final long[] jjbitVec32 = { + 0xffffffff007fffffL, 0x1fffffL, 0x8000000000L, 0x0L +}; +static final long[] jjbitVec33 = { + 0xfffffffffffe0L, 0xfe0L, 0xfc00c001fffffff8L, 0x3fffffffffL +}; +static final long[] jjbitVec34 = { + 0xfffffffffL, 0x3ffffffffc00e000L, 0x0L, 0x63de0000000000L +}; +static final long[] jjbitVec35 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L +}; +static final long[] jjbitVec36 = { + 0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL +}; +static final long[] jjbitVec37 = { + 0x8000000000000000L, 0x8002000000100001L, 0x7ffffff1fff0000L, 0x0L +}; +static final long[] jjbitVec38 = { + 0xf3ffbd503e2ffc84L, 0xffffffff000043e0L, 0x1ffL, 0x0L +}; +static final long[] jjbitVec39 = { + 0xffff7fffffffffffL, 0xffffffff7fffffffL, 0xffffffffffffffffL, 0xc781fffffffffL +}; +static final long[] jjbitVec40 = { + 0xffff20bfffffffffL, 0x80ffffffffffL, 0x7f7f7f7f007fffffL, 0x7f7f7f7fL +}; +static final long[] jjbitVec41 = { + 0x800000000000L, 0x0L, 0x0L, 0x0L +}; +static final long[] jjbitVec42 = { + 0x1f3e03fe000000e0L, 0xfffffffffffffffeL, 0xfffffffee07fffffL, 0xf7ffffffffffffffL +}; +static final long[] jjbitVec43 = { + 0xfffe3fffffffffe0L, 0xffffffffffffffffL, 0x7ffffff00007fffL, 0xffff000000000000L +}; +static final long[] jjbitVec44 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffffffL, 0x0L +}; +static final long[] jjbitVec45 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL +}; +static final long[] jjbitVec46 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL, 0x3fffffffffff0000L +}; +static final long[] jjbitVec47 = { + 0xc00ffff1fffL, 0x80007fffffffffffL, 0xffffffff00ffffffL, 0xffffffffffffL +}; +static final long[] jjbitVec48 = { + 0xfffffffcff800000L, 0xffffffffffffffffL, 0x7ff000f79ffL, 0xff00000000000000L +}; +static final long[] jjbitVec49 = { + 0x1000007fffff7bbL, 0xfffffffffffffL, 0xffffffffffffcL, 0x8fc000000000000L +}; +static final long[] jjbitVec50 = { + 0xffff003ffffffc00L, 0x1fffffff0000007fL, 0x7fffffffffff0L, 0x8000L +}; +static final long[] jjbitVec51 = { + 0x1ffffffffffL, 0x47fffff00000ff7L, 0x3e62ffffffffffffL, 0x1c07ff38000005L +}; +static final long[] jjbitVec52 = { + 0x7f7f007e7e7eL, 0x0L, 0x0L, 0x7ffffffffL +}; +static final long[] jjbitVec53 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffff000fffffffffL, 0xffffffffffff87fL +}; +static final long[] jjbitVec54 = { + 0xffffffffffffffffL, 0xffff3fffffffffffL, 0xffffffffffffffffL, 0x3ffffffL +}; +static final long[] jjbitVec55 = { + 0x5f7ffdffa0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L +}; +static final long[] jjbitVec56 = { + 0x3fffffffffffffffL, 0xffffffffffff0000L, 0xfffffffffffcffffL, 0x1fff0000000000ffL +}; +static final long[] jjbitVec57 = { + 0x18000000000000L, 0xffdf02000000e000L, 0xffffffffffffffffL, 0x1fffffffffffffffL +}; +static final long[] jjbitVec58 = { + 0x87fffffe00000010L, 0xffffffc007fffffeL, 0x7fffffffffffffffL, 0x631cfcfcfcL +}; +static final long[] jjbitVec59 = { + 0x0L, 0x0L, 0x420243cffffffffL, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec60 = { + 0xffffffffffffffffL, 0x3cdfffffffffffffL, 0xfffffffbffffd740L, 0xffbfffffffffffffL +}; +static final long[] jjbitVec61 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffffcfbL, 0xffffffffffffffffL +}; +static final long[] jjbitVec62 = { + 0xfffe00ffffffffffL, 0xfffffffe027fffffL, 0xbffffffffffe80ffL, 0x707ffffff00b6L +}; +static final long[] jjbitVec63 = { + 0xffffffff07ff081fL, 0xffffc3ffffffffffL, 0xffffffffffffffffL, 0x9ffffdffbfefffffL +}; +static final long[] jjbitVec64 = { + 0xffffffffffff8000L, 0xffffffffffffe7ffL, 0x3ffffffffffffL, 0x43fffffffffffffL +}; +static final long[] jjbitVec65 = { + 0x3fffffffffffL, 0xfffffffL, 0x1ffd00000000L, 0x7ffffff000000000L +}; +static final long[] jjbitVec66 = { + 0xffffffffffffffffL, 0xfefeffcfffffffffL, 0xf3c5fdfffff99feeL, 0x80fffcfb080799fL +}; +static final long[] jjbitVec67 = { + 0xd36dfdfffff987eeL, 0x3fffc05e023987L, 0xf3edfdfffffbbfeeL, 0x2ffcf00013bbfL +}; +static final long[] jjbitVec68 = { + 0xf3edfdfffff99feeL, 0x2ffcfb0c0399fL, 0xc3ffc718d63dc7ecL, 0x200ffc000813dc7L +}; +static final long[] jjbitVec69 = { + 0xe3effdfffffddfeeL, 0xffcf03603ddfL, 0xf3effdfffffddfecL, 0x6ffcf40603ddfL +}; +static final long[] jjbitVec70 = { + 0xe7fffffffffddfecL, 0xfc00ffcf00807ddfL, 0x2ffbfffffc7fffecL, 0xc0000ff5f847fL +}; +static final long[] jjbitVec71 = { + 0x87fffffffffffffeL, 0x3ff7fffL, 0x3bffecaefef02596L, 0xf3ff3f5fL +}; +static final long[] jjbitVec72 = { + 0xc2a003ff03000001L, 0xfffe1ffffffffeffL, 0x1ffffffffeffffdfL, 0x40L +}; +static final long[] jjbitVec73 = { + 0xffffffffffffffffL, 0xffffffffffff03ffL, 0xffffffff3fffffffL, 0xf7ffffffffff20bfL +}; +static final long[] jjbitVec74 = { + 0xffffffffff3dffffL, 0xe7ffffffL, 0xffffffff0000ffffL, 0x1fffffffffffffL +}; +static final long[] jjbitVec75 = { + 0x1fffff001fdfffL, 0xddfff000fffffL, 0xffffffffffffffffL, 0x3ff388fffffL +}; +static final long[] jjbitVec76 = { + 0xffffffff03ff3800L, 0xffffffffffffffL, 0xffff07ffffffffffL, 0x3fffffffffffffL +}; +static final long[] jjbitVec77 = { + 0xfff0fff1fffffffL, 0x1f3fffffffffc0L, 0xffff0fffffffffffL, 0x3ff03ffL +}; +static final long[] jjbitVec78 = { + 0xffffffff0fffffffL, 0x9fffffff7fffffffL, 0x8003ff03ffL, 0x0L +}; +static final long[] jjbitVec79 = { + 0xffffffffffffffffL, 0xff80003ff0fffL, 0xffffffffffffffffL, 0xfffffffffffffL +}; +static final long[] jjbitVec80 = { + 0xffffffffffffffL, 0x3fffffffffffe3ffL, 0x0L, 0x7ffffffff70000L +}; +static final long[] jjbitVec81 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xf000007fffffffffL +}; +static final long[] jjbitVec82 = { + 0x80007c000000f800L, 0x8002fc1f00100001L, 0x7ffffff1fff0000L, 0x1ffe21fff0000L +}; +static final long[] jjbitVec83 = { + 0xffff7fffffffffffL, 0xffffffff7fffffffL, 0xffffffffffffffffL, 0xff81fffffffffL +}; +static final long[] jjbitVec84 = { + 0xffff20bfffffffffL, 0x800080ffffffffffL, 0x7f7f7f7f007fffffL, 0xffffffff7f7f7f7fL +}; +static final long[] jjbitVec85 = { + 0x1f3efffe000000e0L, 0xfffffffffffffffeL, 0xfffffffee67fffffL, 0xf7ffffffffffffffL +}; +static final long[] jjbitVec86 = { + 0xfffffff1fffL, 0xbff0ffffffffffffL, 0xffffffff80ffffffL, 0x3ffffffffffffL +}; +static final long[] jjbitVec87 = { + 0x10000ffffffffffL, 0xfffffffffffffL, 0xffffffffffffffffL, 0x8ffffff03ff001fL +}; +static final long[] jjbitVec88 = { + 0xffff3fffffffffffL, 0x1fffffff000fffffL, 0xffffffffffffffffL, 0x3ff8001L +}; +static final long[] jjbitVec89 = { + 0x7fffffffffffffL, 0xc7fffff03ff3fffL, 0xffffffffffffffffL, 0x7cffff38000007L +}; +static final long[] jjbitVec90 = { + 0x7f7f007e7e7eL, 0x0L, 0x0L, 0x3ff37ffffffffffL +}; +static final long[] jjbitVec91 = { + 0x5f7ffdffe0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L +}; +static final long[] jjbitVec92 = { + 0x18007f0000ffffL, 0xffdf02000000e000L, 0xffffffffffffffffL, 0x9fffffffffffffffL +}; +static final long[] jjbitVec93 = { + 0x87fffffe03ff0010L, 0xffffffc007fffffeL, 0x7fffffffffffffffL, 0xe0000631cfcfcfcL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 144; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 144: + case 43: + if ((0x3ff00100fffc1ffL & l) == 0L) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 56: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 61; + else if (curChar == 47) + { + if (kind > 5) + kind = 5; + { jjCheckNAddStates(0, 2); } + } + break; + case 0: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 75) + kind = 75; + { jjCheckNAddStates(3, 17); } + } + else if ((0x100001200L & l) != 0L) + { + if (kind > 1) + kind = 1; + } + else if (curChar == 47) + { jjAddStates(18, 19); } + else if (curChar == 36) + { + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + } + else if (curChar == 34) + { jjCheckNAddStates(20, 23); } + else if (curChar == 39) + { jjAddStates(24, 26); } + else if (curChar == 46) + jjstateSet[jjnewStateCnt++] = 2; + if (curChar == 48) + { jjAddStates(27, 34); } + break; + case 1: + if (curChar == 46) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 2: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(35, 38); } + break; + case 3: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(3, 4); } + break; + case 4: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddTwoStates(5, 10); } + break; + case 6: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(7); } + break; + case 7: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(39, 41); } + break; + case 8: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(8, 9); } + break; + case 9: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddTwoStates(7, 10); } + break; + case 11: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(42, 45); } + break; + case 12: + if (curChar == 39) + { jjAddStates(24, 26); } + break; + case 13: + if ((0xffffff7fffffdbffL & l) != 0L) + { jjCheckNAdd(14); } + break; + case 14: + if (curChar == 39 && kind > 87) + kind = 87; + break; + case 16: + if ((0x8400000000L & l) != 0L) + { jjCheckNAdd(14); } + break; + case 17: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(18, 14); } + break; + case 18: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAdd(14); } + break; + case 19: + if ((0xf000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 20; + break; + case 20: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAdd(18); } + break; + case 22: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 23; + break; + case 23: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 24: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 25; + break; + case 25: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(14); } + break; + case 27: + if (curChar == 34) + { jjCheckNAddStates(20, 23); } + break; + case 28: + if ((0xfffffffbffffdbffL & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 30: + if ((0x8400000000L & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 32: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 33; + break; + case 33: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 34; + break; + case 34: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 35; + break; + case 35: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 37: + if (curChar == 34 && kind > 88) + kind = 88; + break; + case 38: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddStates(46, 50); } + break; + case 39: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 40: + if ((0xf000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 41; + break; + case 41: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAdd(39); } + break; + case 42: + if (curChar != 36) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 45: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 46; + break; + case 46: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 47; + break; + case 47: + case 53: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(48); } + break; + case 48: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 51: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 52; + break; + case 52: + if ((0x3ff000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 53; + break; + case 55: + if (curChar == 47) + { jjAddStates(18, 19); } + break; + case 57: + if ((0xffffffffffffdbffL & l) == 0L) + break; + if (kind > 5) + kind = 5; + { jjCheckNAddStates(0, 2); } + break; + case 58: + if ((0x2400L & l) != 0L && kind > 5) + kind = 5; + break; + case 59: + if (curChar == 10 && kind > 5) + kind = 5; + break; + case 60: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 59; + break; + case 61: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 62; + break; + case 62: + if ((0xffff7fffffffffffL & l) != 0L && kind > 6) + kind = 6; + break; + case 63: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 61; + break; + case 64: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 75) + kind = 75; + { jjCheckNAddStates(3, 17); } + break; + case 65: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(65, 66); } + break; + case 66: + case 102: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(67); } + break; + case 68: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(68, 69); } + break; + case 69: + case 113: + if ((0x3ff000000000000L & l) != 0L && kind > 75) + kind = 75; + break; + case 70: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(70, 71); } + break; + case 71: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(72, 10); } + break; + case 73: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(74); } + break; + case 74: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(51, 53); } + break; + case 75: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(75, 76); } + break; + case 76: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(74, 10); } + break; + case 77: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(54, 57); } + break; + case 78: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(78, 79); } + break; + case 79: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(80); } + break; + case 81: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(82); } + break; + case 82: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(58, 60); } + break; + case 83: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(83, 84); } + break; + case 84: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddTwoStates(82, 10); } + break; + case 85: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(61, 64); } + break; + case 86: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(86, 87); } + break; + case 87: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(88); } + break; + case 88: + if (curChar != 46) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(65, 67); } + break; + case 89: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(68, 71); } + break; + case 90: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(90, 91); } + break; + case 91: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddTwoStates(92, 10); } + break; + case 93: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(94); } + break; + case 94: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(72, 74); } + break; + case 95: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(95, 96); } + break; + case 96: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddTwoStates(94, 10); } + break; + case 97: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(75, 78); } + break; + case 98: + if (curChar == 48) + { jjAddStates(27, 34); } + break; + case 100: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(79, 81); } + break; + case 101: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(101, 102); } + break; + case 103: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddStates(82, 84); } + break; + case 104: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(104, 105); } + break; + case 105: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAdd(67); } + break; + case 107: + if ((0x3000000000000L & l) != 0L) + { jjCheckNAddStates(85, 87); } + break; + case 108: + if ((0x3000000000000L & l) != 0L) + { jjCheckNAddTwoStates(108, 109); } + break; + case 109: + if ((0x3000000000000L & l) != 0L) + { jjCheckNAdd(67); } + break; + case 111: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 75) + kind = 75; + { jjCheckNAddTwoStates(112, 113); } + break; + case 112: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(112, 113); } + break; + case 114: + if ((0xff000000000000L & l) == 0L) + break; + if (kind > 75) + kind = 75; + { jjCheckNAddTwoStates(115, 116); } + break; + case 115: + if ((0xff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(115, 116); } + break; + case 116: + if ((0xff000000000000L & l) != 0L && kind > 75) + kind = 75; + break; + case 118: + if ((0x3000000000000L & l) == 0L) + break; + if (kind > 75) + kind = 75; + { jjCheckNAddTwoStates(119, 120); } + break; + case 119: + if ((0x3000000000000L & l) != 0L) + { jjCheckNAddTwoStates(119, 120); } + break; + case 120: + if ((0x3000000000000L & l) != 0L && kind > 75) + kind = 75; + break; + case 122: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(88, 90); } + break; + case 123: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(123, 124); } + break; + case 124: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(125); } + break; + case 125: + if (curChar == 46) + jjstateSet[jjnewStateCnt++] = 126; + break; + case 126: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(91, 93); } + break; + case 127: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(127, 128); } + break; + case 128: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAdd(129); } + break; + case 130: + if ((0x280000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 131; + break; + case 131: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(94, 96); } + break; + case 132: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(132, 133); } + break; + case 133: + case 143: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAdd(10); } + break; + case 135: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddStates(97, 100); } + break; + case 136: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(136, 137); } + break; + case 137: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(138, 139); } + break; + case 138: + if (curChar == 46) + { jjCheckNAdd(139); } + break; + case 140: + if ((0x280000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 141; + break; + case 141: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 80) + kind = 80; + { jjCheckNAddStates(101, 103); } + break; + case 142: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(142, 143); } + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 144: + if ((0x87fffffe87fffffeL & l) != 0L) + { + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + } + else if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 44; + break; + case 0: + if ((0x7fffffe87fffffeL & l) != 0L) + { + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + } + else if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 50; + break; + case 3: + if (curChar == 95) + { jjAddStates(104, 105); } + break; + case 5: + if ((0x2000000020L & l) != 0L) + { jjAddStates(106, 107); } + break; + case 8: + if (curChar == 95) + { jjAddStates(108, 109); } + break; + case 10: + if ((0x5000000050L & l) != 0L && kind > 80) + kind = 80; + break; + case 13: + if ((0xffffffffefffffffL & l) != 0L) + { jjCheckNAdd(14); } + break; + case 15: + if (curChar == 92) + { jjAddStates(110, 112); } + break; + case 16: + if ((0x14404410000000L & l) != 0L) + { jjCheckNAdd(14); } + break; + case 21: + if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 22; + break; + case 22: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 23; + break; + case 23: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 24: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 25; + break; + case 25: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAdd(14); } + break; + case 26: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 21; + break; + case 28: + if ((0xffffffffefffffffL & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 29: + if (curChar == 92) + { jjAddStates(113, 115); } + break; + case 30: + if ((0x14404410000000L & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 31: + if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 32: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 33; + break; + case 33: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 34; + break; + case 34: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 35; + break; + case 35: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddStates(20, 23); } + break; + case 36: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 31; + break; + case 42: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 43: + if ((0x87fffffe87fffffeL & l) == 0L) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 44: + if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 45; + break; + case 45: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 46; + break; + case 46: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 47; + break; + case 47: + case 53: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAdd(48); } + break; + case 48: + if ((0x7e0000007eL & l) == 0L) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 49: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 44; + break; + case 50: + if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 51; + break; + case 51: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 52; + break; + case 52: + if ((0x7e0000007eL & l) != 0L) + jjstateSet[jjnewStateCnt++] = 53; + break; + case 54: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 50; + break; + case 57: + if (kind > 5) + kind = 5; + { jjAddStates(0, 2); } + break; + case 62: + if (kind > 6) + kind = 6; + break; + case 65: + if (curChar == 95) + { jjAddStates(116, 117); } + break; + case 67: + if ((0x100000001000L & l) != 0L && kind > 74) + kind = 74; + break; + case 68: + if (curChar == 95) + { jjAddStates(118, 119); } + break; + case 70: + if (curChar == 95) + { jjAddStates(120, 121); } + break; + case 72: + if ((0x2000000020L & l) != 0L) + { jjAddStates(122, 123); } + break; + case 75: + if (curChar == 95) + { jjAddStates(124, 125); } + break; + case 78: + if (curChar == 95) + { jjAddStates(126, 127); } + break; + case 80: + if ((0x2000000020L & l) != 0L) + { jjAddStates(128, 129); } + break; + case 83: + if (curChar == 95) + { jjAddStates(130, 131); } + break; + case 86: + if (curChar == 95) + { jjAddStates(132, 133); } + break; + case 90: + if (curChar == 95) + { jjAddStates(134, 135); } + break; + case 92: + if ((0x2000000020L & l) != 0L) + { jjAddStates(136, 137); } + break; + case 95: + if (curChar == 95) + { jjAddStates(138, 139); } + break; + case 99: + if ((0x100000001000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 100; + break; + case 100: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddStates(79, 81); } + break; + case 101: + if ((0x7e8000007eL & l) != 0L) + { jjCheckNAddTwoStates(101, 102); } + break; + case 102: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAdd(67); } + break; + case 104: + if (curChar == 95) + { jjAddStates(140, 141); } + break; + case 106: + if ((0x400000004L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 107; + break; + case 108: + if (curChar == 95) + { jjAddStates(142, 143); } + break; + case 110: + if ((0x100000001000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 111; + break; + case 111: + if ((0x7e0000007eL & l) == 0L) + break; + if (kind > 75) + kind = 75; + { jjCheckNAddTwoStates(112, 113); } + break; + case 112: + if ((0x7e8000007eL & l) != 0L) + { jjCheckNAddTwoStates(112, 113); } + break; + case 113: + if ((0x7e0000007eL & l) != 0L && kind > 75) + kind = 75; + break; + case 115: + if (curChar == 95) + { jjAddStates(144, 145); } + break; + case 117: + if ((0x400000004L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 118; + break; + case 119: + if (curChar == 95) + { jjAddStates(146, 147); } + break; + case 121: + if ((0x100000001000000L & l) != 0L) + { jjCheckNAddTwoStates(122, 125); } + break; + case 122: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddStates(88, 90); } + break; + case 123: + if ((0x7e8000007eL & l) != 0L) + { jjCheckNAddTwoStates(123, 124); } + break; + case 124: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAdd(125); } + break; + case 126: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddStates(91, 93); } + break; + case 127: + if ((0x7e8000007eL & l) != 0L) + { jjCheckNAddTwoStates(127, 128); } + break; + case 128: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAdd(129); } + break; + case 129: + if ((0x1000000010000L & l) != 0L) + { jjAddStates(148, 149); } + break; + case 132: + if (curChar == 95) + { jjAddStates(150, 151); } + break; + case 134: + if ((0x100000001000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 135; + break; + case 135: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddStates(97, 100); } + break; + case 136: + if ((0x7e8000007eL & l) != 0L) + { jjCheckNAddTwoStates(136, 137); } + break; + case 137: + if ((0x7e0000007eL & l) != 0L) + { jjCheckNAddTwoStates(138, 139); } + break; + case 139: + if ((0x1000000010000L & l) != 0L) + { jjAddStates(152, 153); } + break; + case 142: + if (curChar == 95) + { jjAddStates(154, 155); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 144: + case 43: + if (!jjCanMove_3(hiByte, i1, i2, l1, l2)) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 0: + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) + { + if (kind > 1) + kind = 1; + } + if (jjCanMove_2(hiByte, i1, i2, l1, l2)) + { + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + } + break; + case 13: + if (jjCanMove_1(hiByte, i1, i2, l1, l2)) + jjstateSet[jjnewStateCnt++] = 14; + break; + case 28: + if (jjCanMove_1(hiByte, i1, i2, l1, l2)) + { jjAddStates(20, 23); } + break; + case 42: + if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) + break; + if (kind > 89) + kind = 89; + { jjCheckNAddTwoStates(43, 49); } + break; + case 57: + if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) + break; + if (kind > 5) + kind = 5; + { jjAddStates(0, 2); } + break; + case 62: + if (jjCanMove_1(hiByte, i1, i2, l1, l2) && kind > 6) + kind = 6; + break; + default : if (i1 == 0 || l1 == 0 || i2 == 0 || l2 == 0) break; else break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 144 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_2(){ + switch(curChar) + { + case 42: + return jjMoveStringLiteralDfa1_2(0x200L); + default : + return 1; + } +} +private int jjMoveStringLiteralDfa1_2(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + return 1; + } + switch(curChar) + { + case 47: + if ((active0 & 0x200L) != 0L) + return jjStopAtPos(1, 9); + break; + default : + return 2; + } + return 2; +} +private int jjMoveStringLiteralDfa0_1(){ + switch(curChar) + { + case 42: + return jjMoveStringLiteralDfa1_1(0x100L); + default : + return 1; + } +} +private int jjMoveStringLiteralDfa1_1(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + return 1; + } + switch(curChar) + { + case 47: + if ((active0 & 0x100L) != 0L) + return jjStopAtPos(1, 8); + break; + default : + return 2; + } + return 2; +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, null, null, null, +"\141\142\163\164\162\141\143\164", "\141\163\163\145\162\164", "\142\157\157\154\145\141\156", +"\142\162\145\141\153", "\142\171\164\145", "\143\141\163\145", "\143\141\164\143\150", +"\143\150\141\162", "\143\154\141\163\163", "\143\157\156\163\164", +"\143\157\156\164\151\156\165\145", "\144\145\146\141\165\154\164", "\144\157", "\144\157\165\142\154\145", +"\145\154\163\145", "\145\156\165\155", "\145\170\164\145\156\144\163", "\146\141\154\163\145", +"\146\151\156\141\154", "\146\151\156\141\154\154\171", "\146\154\157\141\164", "\146\157\162", +"\147\157\164\157", "\151\146", "\151\155\160\154\145\155\145\156\164\163", +"\151\155\160\157\162\164", "\151\156\163\164\141\156\143\145\157\146", "\151\156\164", +"\151\156\164\145\162\146\141\143\145", "\154\157\156\147", "\156\141\164\151\166\145", "\156\145\167", +"\156\165\154\154", "\160\141\143\153\141\147\145", "\160\162\151\166\141\164\145", +"\160\162\157\164\145\143\164\145\144", "\160\165\142\154\151\143", "\162\145\164\165\162\156", +"\163\150\157\162\164", "\163\164\141\164\151\143", "\163\164\162\151\143\164\146\160", +"\163\165\160\145\162", "\163\167\151\164\143\150", +"\163\171\156\143\150\162\157\156\151\172\145\144", "\164\150\151\163", "\164\150\162\157\167", "\164\150\162\157\167\163", +"\164\162\141\156\163\151\145\156\164", "\164\162\165\145", "\164\162\171", "\166\157\151\144", +"\166\157\154\141\164\151\154\145", "\167\150\151\154\145", "\162\145\161\165\151\162\145\163", "\164\157", +"\167\151\164\150", "\157\160\145\156", "\157\160\145\156\163", "\165\163\145\163", +"\155\157\144\165\154\145", "\145\170\160\157\162\164\163", "\160\162\157\166\151\144\145\163", +"\164\162\141\156\163\151\164\151\166\145", null, null, null, null, null, null, null, null, null, null, null, null, null, +null, null, null, null, null, "\50", "\51", "\173", "\175", "\133", "\135", "\73", +"\54", "\56", "\100", "\75", "\74", "\41", "\176", "\77", "\72", "\75\75", "\74\75", +"\76\75", "\41\75", "\174\174", "\46\46", "\53\53", "\55\55", "\53", "\55", "\52", +"\57", "\46", "\174", "\136", "\45", "\74\74", "\53\75", "\55\75", "\52\75", +"\57\75", "\46\75", "\174\75", "\136\75", "\45\75", "\74\74\75", "\76\76\75", +"\76\76\76\75", "\56\56\56", "\55\76", "\72\72", "\76\76\76", "\76\76", "\76", "\32", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = { + 57, 58, 60, 65, 66, 67, 68, 69, 70, 71, 72, 10, 78, 79, 80, 86, + 87, 88, 56, 63, 28, 29, 36, 37, 13, 15, 26, 99, 103, 106, 110, 114, + 117, 121, 134, 3, 4, 5, 10, 8, 10, 11, 7, 8, 10, 11, 28, 29, + 39, 36, 37, 75, 10, 77, 74, 75, 10, 77, 83, 10, 85, 82, 83, 10, + 85, 89, 92, 10, 90, 91, 92, 10, 95, 10, 97, 94, 95, 10, 97, 101, + 102, 67, 104, 105, 67, 108, 109, 67, 123, 124, 125, 127, 128, 129, 132, 133, + 10, 136, 137, 138, 139, 142, 143, 10, 3, 4, 6, 7, 8, 9, 16, 17, + 19, 30, 38, 40, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, + 81, 82, 83, 84, 86, 87, 90, 91, 93, 94, 95, 96, 104, 105, 108, 109, + 115, 116, 119, 120, 130, 131, 132, 133, 140, 141, 142, 143, +}; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec0[i2] & l2) != 0L); + case 22: + return ((jjbitVec1[i2] & l2) != 0L); + case 24: + return ((jjbitVec2[i2] & l2) != 0L); + case 32: + return ((jjbitVec3[i2] & l2) != 0L); + case 48: + return ((jjbitVec4[i2] & l2) != 0L); + case 254: + return ((jjbitVec5[i2] & l2) != 0L); + default : + return false; + } +} +private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec8[i2] & l2) != 0L); + default : + if ((jjbitVec6[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec10[i2] & l2) != 0L); + case 2: + return ((jjbitVec11[i2] & l2) != 0L); + case 3: + return ((jjbitVec12[i2] & l2) != 0L); + case 4: + return ((jjbitVec13[i2] & l2) != 0L); + case 5: + return ((jjbitVec14[i2] & l2) != 0L); + case 6: + return ((jjbitVec15[i2] & l2) != 0L); + case 7: + return ((jjbitVec16[i2] & l2) != 0L); + case 8: + return ((jjbitVec17[i2] & l2) != 0L); + case 9: + return ((jjbitVec18[i2] & l2) != 0L); + case 10: + return ((jjbitVec19[i2] & l2) != 0L); + case 11: + return ((jjbitVec20[i2] & l2) != 0L); + case 12: + return ((jjbitVec21[i2] & l2) != 0L); + case 13: + return ((jjbitVec22[i2] & l2) != 0L); + case 14: + return ((jjbitVec23[i2] & l2) != 0L); + case 15: + return ((jjbitVec24[i2] & l2) != 0L); + case 16: + return ((jjbitVec25[i2] & l2) != 0L); + case 18: + return ((jjbitVec26[i2] & l2) != 0L); + case 19: + return ((jjbitVec27[i2] & l2) != 0L); + case 20: + return ((jjbitVec6[i2] & l2) != 0L); + case 22: + return ((jjbitVec28[i2] & l2) != 0L); + case 23: + return ((jjbitVec29[i2] & l2) != 0L); + case 24: + return ((jjbitVec30[i2] & l2) != 0L); + case 25: + return ((jjbitVec31[i2] & l2) != 0L); + case 26: + return ((jjbitVec32[i2] & l2) != 0L); + case 27: + return ((jjbitVec33[i2] & l2) != 0L); + case 28: + return ((jjbitVec34[i2] & l2) != 0L); + case 29: + return ((jjbitVec35[i2] & l2) != 0L); + case 31: + return ((jjbitVec36[i2] & l2) != 0L); + case 32: + return ((jjbitVec37[i2] & l2) != 0L); + case 33: + return ((jjbitVec38[i2] & l2) != 0L); + case 44: + return ((jjbitVec39[i2] & l2) != 0L); + case 45: + return ((jjbitVec40[i2] & l2) != 0L); + case 46: + return ((jjbitVec41[i2] & l2) != 0L); + case 48: + return ((jjbitVec42[i2] & l2) != 0L); + case 49: + return ((jjbitVec43[i2] & l2) != 0L); + case 77: + return ((jjbitVec44[i2] & l2) != 0L); + case 159: + return ((jjbitVec45[i2] & l2) != 0L); + case 164: + return ((jjbitVec46[i2] & l2) != 0L); + case 166: + return ((jjbitVec47[i2] & l2) != 0L); + case 167: + return ((jjbitVec48[i2] & l2) != 0L); + case 168: + return ((jjbitVec49[i2] & l2) != 0L); + case 169: + return ((jjbitVec50[i2] & l2) != 0L); + case 170: + return ((jjbitVec51[i2] & l2) != 0L); + case 171: + return ((jjbitVec52[i2] & l2) != 0L); + case 215: + return ((jjbitVec53[i2] & l2) != 0L); + case 250: + return ((jjbitVec54[i2] & l2) != 0L); + case 251: + return ((jjbitVec55[i2] & l2) != 0L); + case 253: + return ((jjbitVec56[i2] & l2) != 0L); + case 254: + return ((jjbitVec57[i2] & l2) != 0L); + case 255: + return ((jjbitVec58[i2] & l2) != 0L); + default : + if ((jjbitVec9[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_3(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec59[i2] & l2) != 0L); + case 2: + return ((jjbitVec11[i2] & l2) != 0L); + case 3: + return ((jjbitVec60[i2] & l2) != 0L); + case 4: + return ((jjbitVec61[i2] & l2) != 0L); + case 5: + return ((jjbitVec62[i2] & l2) != 0L); + case 6: + return ((jjbitVec63[i2] & l2) != 0L); + case 7: + return ((jjbitVec64[i2] & l2) != 0L); + case 8: + return ((jjbitVec65[i2] & l2) != 0L); + case 9: + return ((jjbitVec66[i2] & l2) != 0L); + case 10: + return ((jjbitVec67[i2] & l2) != 0L); + case 11: + return ((jjbitVec68[i2] & l2) != 0L); + case 12: + return ((jjbitVec69[i2] & l2) != 0L); + case 13: + return ((jjbitVec70[i2] & l2) != 0L); + case 14: + return ((jjbitVec71[i2] & l2) != 0L); + case 15: + return ((jjbitVec72[i2] & l2) != 0L); + case 16: + return ((jjbitVec73[i2] & l2) != 0L); + case 18: + return ((jjbitVec26[i2] & l2) != 0L); + case 19: + return ((jjbitVec74[i2] & l2) != 0L); + case 20: + return ((jjbitVec6[i2] & l2) != 0L); + case 22: + return ((jjbitVec28[i2] & l2) != 0L); + case 23: + return ((jjbitVec75[i2] & l2) != 0L); + case 24: + return ((jjbitVec76[i2] & l2) != 0L); + case 25: + return ((jjbitVec77[i2] & l2) != 0L); + case 26: + return ((jjbitVec78[i2] & l2) != 0L); + case 27: + return ((jjbitVec79[i2] & l2) != 0L); + case 28: + return ((jjbitVec80[i2] & l2) != 0L); + case 29: + return ((jjbitVec81[i2] & l2) != 0L); + case 31: + return ((jjbitVec36[i2] & l2) != 0L); + case 32: + return ((jjbitVec82[i2] & l2) != 0L); + case 33: + return ((jjbitVec38[i2] & l2) != 0L); + case 44: + return ((jjbitVec83[i2] & l2) != 0L); + case 45: + return ((jjbitVec84[i2] & l2) != 0L); + case 46: + return ((jjbitVec41[i2] & l2) != 0L); + case 48: + return ((jjbitVec85[i2] & l2) != 0L); + case 49: + return ((jjbitVec43[i2] & l2) != 0L); + case 77: + return ((jjbitVec44[i2] & l2) != 0L); + case 159: + return ((jjbitVec45[i2] & l2) != 0L); + case 164: + return ((jjbitVec46[i2] & l2) != 0L); + case 166: + return ((jjbitVec86[i2] & l2) != 0L); + case 167: + return ((jjbitVec48[i2] & l2) != 0L); + case 168: + return ((jjbitVec87[i2] & l2) != 0L); + case 169: + return ((jjbitVec88[i2] & l2) != 0L); + case 170: + return ((jjbitVec89[i2] & l2) != 0L); + case 171: + return ((jjbitVec90[i2] & l2) != 0L); + case 215: + return ((jjbitVec53[i2] & l2) != 0L); + case 250: + return ((jjbitVec54[i2] & l2) != 0L); + case 251: + return ((jjbitVec91[i2] & l2) != 0L); + case 253: + return ((jjbitVec56[i2] & l2) != 0L); + case 254: + return ((jjbitVec92[i2] & l2) != 0L); + case 255: + return ((jjbitVec93[i2] & l2) != 0L); + default : + if ((jjbitVec9[i1] & l1) != 0L) + return true; + return false; + } +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token specialToken = null; + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + matchedToken.specialToken = specialToken; + CommonTokenAction(matchedToken); + return matchedToken; + } + image = jjimage; + image.setLength(0); + jjimageLen = 0; + + for (;;) + { + switch(curLexState) + { + case 0: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + break; + case 1: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_1(); + if (jjmatchedPos == 0 && jjmatchedKind > 10) + { + jjmatchedKind = 10; + } + break; + case 2: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_2(); + if (jjmatchedPos == 0 && jjmatchedKind > 10) + { + jjmatchedKind = 10; + } + break; + } + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + matchedToken.specialToken = specialToken; + TokenLexicalActions(matchedToken); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + CommonTokenAction(matchedToken); + return matchedToken; + } + else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + if (specialToken == null) + specialToken = matchedToken; + else + { + matchedToken.specialToken = specialToken; + specialToken = (specialToken.next = matchedToken); + } + SkipLexicalActions(matchedToken); + } + else + SkipLexicalActions(null); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + continue EOFLoop; + } + MoreLexicalActions(); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + curPos = 0; + jjmatchedKind = 0x7fffffff; + try { + curChar = input_stream.readChar(); + continue; + } + catch (java.io.IOException e1) { } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + case 6 : + image.append(input_stream.GetSuffix(jjimageLen)); + jjimageLen = 0; + input_stream.backup(1); + break; + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 139 : + image.append(jjstrLiteralImages[139]); + lengthOfMatch = jjstrLiteralImages[139].length(); + matchedToken.kind = GT; + matchedToken.realKind = RUNSIGNEDSHIFT; + input_stream.backup(2); + break; + case 140 : + image.append(jjstrLiteralImages[140]); + lengthOfMatch = jjstrLiteralImages[140].length(); + matchedToken.kind = GT; + matchedToken.realKind = RSIGNEDSHIFT; + input_stream.backup(1); + break; + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + + /** Constructor. */ + public GeneratedJavaParserTokenManager(SimpleCharStream stream){ + + if (SimpleCharStream.staticFlag) + throw new RuntimeException("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + + input_stream = stream; + } + + /** Constructor. */ + public GeneratedJavaParserTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 144; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 3 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", + "IN_JAVADOC_COMMENT", + "IN_MULTI_LINE_COMMENT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, 1, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xfffffffffffff801L, 0xfffffffff3810fffL, 0x7fffL, +}; +static final long[] jjtoSkip = { + 0x33eL, 0x0L, 0x0L, +}; +static final long[] jjtoSpecial = { + 0x33eL, 0x0L, 0x0L, +}; +static final long[] jjtoMore = { + 0x4c0L, 0x0L, 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[144]; + private final int[] jjstateSet = new int[2 * 144]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java b/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java new file mode 100644 index 0000000..da4331e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java @@ -0,0 +1,46 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.Position.pos; + +/** + * Base class for {@link com.github.javaparser.GeneratedJavaParserTokenManager} + */ +abstract class GeneratedJavaParserTokenManagerBase { + /** + * Create a TokenRange that spans exactly one token + */ + private static TokenRange tokenRange(Token token) { + JavaToken javaToken = token.javaToken; + return new TokenRange(javaToken, javaToken); + } + + /** + * Since comments are completely captured in a single token, including their delimiters, deconstruct them here so we + * can turn them into nodes later on. + */ + static Comment createCommentFromToken(Token token) { + String commentText = token.image; + if (token.kind == JAVADOC_COMMENT) { + return new JavadocComment(tokenRange(token), commentText.substring(3, commentText.length() - 2)); + } else if (token.kind == MULTI_LINE_COMMENT) { + return new BlockComment(tokenRange(token), commentText.substring(2, commentText.length() - 2)); + } else if (token.kind == SINGLE_LINE_COMMENT) { + // line comments have their end of line character(s) included, and we don't want that. + Range range = new Range(pos(token.beginLine, token.beginColumn), pos(token.endLine, token.endColumn)); + while (commentText.endsWith("\r") || commentText.endsWith("\n")) { + commentText = commentText.substring(0, commentText.length() - 1); + } + range = range.withEnd(pos(range.begin.line, range.begin.column + commentText.length())); + LineComment comment = new LineComment(tokenRange(token), commentText.substring(2)); + comment.setRange(range); + return comment; + } + throw new AssertionError("Unexpectedly got passed a non-comment token."); + } +} diff --git a/JavaParser/src/com/github/javaparser/HasParentNode.java b/JavaParser/src/com/github/javaparser/HasParentNode.java new file mode 100644 index 0000000..03df0d6 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/HasParentNode.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.Observable; + +import java.util.Optional; + +/** + * An object that has a parent node. + */ +public interface HasParentNode extends Observable { + + /** + * Return the parent node or null, if no parent is set. + */ + Optional getParentNode(); + + /** + * Set the parent node. + * + * @param parentNode the parent node or null, to set no parent + * @return return this + */ + T setParentNode(Node parentNode); + + /** + * this for everything except NodeLists. NodeLists use their parent as their children parent. + */ + Node getParentNodeForChildren(); + + /** + * Get the ancestor of the node having the given type, or null if no ancestor of the given type is found. + */ + default Optional getAncestorOfType(Class classType) { + Node parent = getParentNode().orElse(null); + while (parent != null) { + if (classType.isAssignableFrom(parent.getClass())) { + return Optional.of(classType.cast(parent)); + } + parent = parent.getParentNode().orElse(null); + } + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/JavaCharStream.java b/JavaParser/src/com/github/javaparser/JavaCharStream.java deleted file mode 100644 index 2b1cd7b..0000000 --- a/JavaParser/src/com/github/javaparser/JavaCharStream.java +++ /dev/null @@ -1,629 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 5.0 */ -/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (with java-like unicode escape processing). - */ - -public -class JavaCharStream -{ - /** Whether parser is static. */ - public static final boolean staticFlag = false; - - static final int hexval(char c) throws java.io.IOException { - switch(c) - { - case '0' : - return 0; - case '1' : - return 1; - case '2' : - return 2; - case '3' : - return 3; - case '4' : - return 4; - case '5' : - return 5; - case '6' : - return 6; - case '7' : - return 7; - case '8' : - return 8; - case '9' : - return 9; - - case 'a' : - case 'A' : - return 10; - case 'b' : - case 'B' : - return 11; - case 'c' : - case 'C' : - return 12; - case 'd' : - case 'D' : - return 13; - case 'e' : - case 'E' : - return 14; - case 'f' : - case 'F' : - return 15; - } - - throw new java.io.IOException(); // Should never come here - } - -/** Position in buffer. */ - public int bufpos = -1; - int bufsize; - int available; - int tokenBegin; - protected int bufline[]; - protected int bufcolumn[]; - - protected int column = 0; - protected int line = 1; - - protected boolean prevCharIsCR = false; - protected boolean prevCharIsLF = false; - - protected java.io.Reader inputStream; - - protected char[] nextCharBuf; - protected char[] buffer; - protected int maxNextCharInd = 0; - protected int nextCharInd = -1; - protected int inBuf = 0; - protected int tabSize = 8; - - protected void setTabSize(int i) { tabSize = i; } - protected int getTabSize(int i) { return tabSize; } - - protected void ExpandBuff(boolean wrapAround) - { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; - - try - { - if (wrapAround) - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - - bufpos += (bufsize - tokenBegin); - } - else - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - - bufpos -= tokenBegin; - } - } - catch (Throwable t) - { - throw new Error(t.getMessage()); - } - - available = (bufsize += 2048); - tokenBegin = 0; - } - - protected void FillBuff() throws java.io.IOException - { - int i; - if (maxNextCharInd == 4096) - maxNextCharInd = nextCharInd = 0; - - try { - if ((i = inputStream.read(nextCharBuf, maxNextCharInd, - 4096 - maxNextCharInd)) == -1) - { - inputStream.close(); - throw new java.io.IOException(); - } - else - maxNextCharInd += i; - return; - } - catch(java.io.IOException e) { - if (bufpos != 0) - { - --bufpos; - backup(0); - } - else - { - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - throw e; - } - } - - protected char ReadByte() throws java.io.IOException - { - if (++nextCharInd >= maxNextCharInd) - FillBuff(); - - return nextCharBuf[nextCharInd]; - } - -/** @return starting character for token. */ - public char BeginToken() throws java.io.IOException - { - if (inBuf > 0) - { - --inBuf; - - if (++bufpos == bufsize) - bufpos = 0; - - tokenBegin = bufpos; - return buffer[bufpos]; - } - - tokenBegin = 0; - bufpos = -1; - - return readChar(); - } - - protected void AdjustBuffSize() - { - if (available == bufsize) - { - if (tokenBegin > 2048) - { - bufpos = 0; - available = tokenBegin; - } - else - ExpandBuff(false); - } - else if (available > tokenBegin) - available = bufsize; - else if ((tokenBegin - available) < 2048) - ExpandBuff(true); - else - available = tokenBegin; - } - - protected void UpdateLineColumn(char c) - { - column++; - - if (prevCharIsLF) - { - prevCharIsLF = false; - line += (column = 1); - } - else if (prevCharIsCR) - { - prevCharIsCR = false; - if (c == '\n') - { - prevCharIsLF = true; - } - else - line += (column = 1); - } - - switch (c) - { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - -/** Read a character. */ - public char readChar() throws java.io.IOException - { - if (inBuf > 0) - { - --inBuf; - - if (++bufpos == bufsize) - bufpos = 0; - - return buffer[bufpos]; - } - - char c; - - if (++bufpos == available) - AdjustBuffSize(); - - if ((buffer[bufpos] = c = ReadByte()) == '\\') - { - UpdateLineColumn(c); - - int backSlashCnt = 1; - - for (;;) // Read all the backslashes - { - if (++bufpos == available) - AdjustBuffSize(); - - try - { - if ((buffer[bufpos] = c = ReadByte()) != '\\') - { - UpdateLineColumn(c); - // found a non-backslash char. - if ((c == 'u') && ((backSlashCnt & 1) == 1)) - { - if (--bufpos < 0) - bufpos = bufsize - 1; - - break; - } - - backup(backSlashCnt); - return '\\'; - } - } - catch(java.io.IOException e) - { - // We are returning one backslash so we should only backup (count-1) - if (backSlashCnt > 1) - backup(backSlashCnt-1); - - return '\\'; - } - - UpdateLineColumn(c); - backSlashCnt++; - } - - // Here, we have seen an odd number of backslash's followed by a 'u' - try - { - while ((c = ReadByte()) == 'u') - ++column; - - buffer[bufpos] = c = (char)(hexval(c) << 12 | - hexval(ReadByte()) << 8 | - hexval(ReadByte()) << 4 | - hexval(ReadByte())); - - column += 4; - } - catch(java.io.IOException e) - { - throw new Error("Invalid escape character at line " + line + - " column " + column + "."); - } - - if (backSlashCnt == 1) - return c; - else - { - backup(backSlashCnt - 1); - return '\\'; - } - } - else - { - UpdateLineColumn(c); - return c; - } - } - - @Deprecated - /** - * @deprecated - * @see #getEndColumn - */ - public int getColumn() { - return bufcolumn[bufpos]; - } - - @Deprecated - /** - * @deprecated - * @see #getEndLine - */ - public int getLine() { - return bufline[bufpos]; - } - -/** Get end column. */ - public int getEndColumn() { - return bufcolumn[bufpos]; - } - -/** Get end line. */ - public int getEndLine() { - return bufline[bufpos]; - } - -/** @return column of token start */ - public int getBeginColumn() { - return bufcolumn[tokenBegin]; - } - -/** @return line number of token start */ - public int getBeginLine() { - return bufline[tokenBegin]; - } - -/** Retreat. */ - public void backup(int amount) { - - inBuf += amount; - if ((bufpos -= amount) < 0) - bufpos += bufsize; - } - -/** Constructor. */ - public JavaCharStream(java.io.Reader dstream, - int startline, int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - nextCharBuf = new char[4096]; - } - -/** Constructor. */ - public JavaCharStream(java.io.Reader dstream, - int startline, int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - -/** Constructor. */ - public JavaCharStream(java.io.Reader dstream) - { - this(dstream, 1, 1, 4096); - } -/** Reinitialise. */ - public void ReInit(java.io.Reader dstream, - int startline, int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - if (buffer == null || buffersize != buffer.length) - { - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - nextCharBuf = new char[4096]; - } - prevCharIsLF = prevCharIsCR = false; - tokenBegin = inBuf = maxNextCharInd = 0; - nextCharInd = bufpos = -1; - } - -/** Reinitialise. */ - public void ReInit(java.io.Reader dstream, - int startline, int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } - -/** Reinitialise. */ - public void ReInit(java.io.Reader dstream) - { - ReInit(dstream, 1, 1, 4096); - } -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); - } - -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, startline, startcolumn, 4096); - } - -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream, int startline, - int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, 1, 1, 4096); - } - -/** Constructor. */ - public JavaCharStream(java.io.InputStream dstream) - { - this(dstream, 1, 1, 4096); - } - -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, startline, startcolumn, 4096); - } -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, 1, 1, 4096); - } - -/** Reinitialise. */ - public void ReInit(java.io.InputStream dstream) - { - ReInit(dstream, 1, 1, 4096); - } - - /** @return token image as String */ - public String GetImage() - { - if (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); - } - - /** @return suffix */ - public char[] GetSuffix(int len) - { - char[] ret = new char[len]; - - if ((bufpos + 1) >= len) - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else - { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); - } - - return ret; - } - - /** Set buffers back to null when finished. */ - public void Done() - { - nextCharBuf = null; - buffer = null; - bufline = null; - bufcolumn = null; - } - - /** - * Method to adjust line and column numbers for the start of a token. - */ - public void adjustBeginLineColumn(int newLine, int newCol) - { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) - { - len = bufpos - tokenBegin + inBuf + 1; - } - else - { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) - { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - } - - if (i < len) - { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) - { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - } - } - - line = bufline[j]; - column = bufcolumn[j]; - } - -} -/* JavaCC - OriginalChecksum=3649c6eda7de43379bae4f73069e5c10 (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/JavaParser.java b/JavaParser/src/com/github/javaparser/JavaParser.java index 4876154..7b8ee87 100644 --- a/JavaParser/src/com/github/javaparser/JavaParser.java +++ b/JavaParser/src/com/github/javaparser/JavaParser.java @@ -1,451 +1,522 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser; - -import static com.github.javaparser.PositionUtils.areInOrder; -import static com.github.javaparser.PositionUtils.sortByBeginPosition; - -import com.github.javaparser.ASTParser; -import com.github.javaparser.ParseException; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.comments.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.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.Statement; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -// FIXME this file does not seem to be generated by javacc. Is the doc wrong, or the javacc config? -/** - *

- * This class was generated automatically by javacc, do not edit. - *

- *

- * Parse Java 1.5 source code and creates Abstract Syntax Tree classes. - *

- * - * @author Júlio Vilmar Gesser - */ -public final class JavaParser { - private JavaParser() { - // hide the constructor - } - - private static boolean _doNotAssignCommentsPreceedingEmptyLines = true; - - private static boolean _doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false; - - public static boolean getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() - { - return _doNotConsiderAnnotationsAsNodeStartForCodeAttribution; - } - - public static void setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution) { - _doNotConsiderAnnotationsAsNodeStartForCodeAttribution = doNotConsiderAnnotationsAsNodeStartForCodeAttribution; - } - - public static boolean getDoNotAssignCommentsPreceedingEmptyLines() - { - return _doNotAssignCommentsPreceedingEmptyLines; - } - - public static void setDoNotAssignCommentsPreceedingEmptyLines(boolean doNotAssignCommentsPreceedingEmptyLines) - { - _doNotAssignCommentsPreceedingEmptyLines = doNotAssignCommentsPreceedingEmptyLines; - } - - public static CompilationUnit parse(final InputStream in, - final String 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, - final String encoding, boolean considerComments) throws ParseException { - try { - String code = SourcesHelper.streamToString(in, encoding); - InputStream in1 = SourcesHelper.stringToStream(code, encoding); - CompilationUnit cu = new ASTParser(in1, encoding).CompilationUnit(); - if (considerComments){ - insertComments(cu,code); - } - return cu; - } 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. - * - * @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, null,true); - } - - public static CompilationUnit parse(final File file, final String 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 - * @throws IOException - */ - public static CompilationUnit parse(final File file, final String encoding, boolean considerComments) - throws ParseException, IOException { - final FileInputStream in = new FileInputStream(file); - try { - return parse(in, encoding, considerComments); - } finally { - in.close(); - } - } - - /** - * 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 - * @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, null,true); - } - - public static CompilationUnit parse(final Reader reader, boolean considerComments) - throws ParseException { - try { - String code = SourcesHelper.readerToString(reader); - Reader reader1 = SourcesHelper.stringToReader(code); - CompilationUnit cu = new ASTParser(reader1).CompilationUnit(); - if (considerComments){ - insertComments(cu,code); - } - return cu; - } catch (IOException ioe){ - throw new ParseException(ioe.getMessage()); - } - } - - /** - * 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 { - StringReader sr = new StringReader(blockStatement); - BlockStmt result = new ASTParser(sr).Block(); - sr.close(); - return result; - } - - /** - * 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 { - StringReader sr = new StringReader(statement); - Statement stmt = new ASTParser(sr).Statement(); - sr.close(); - return stmt; - } - - /** - * 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 { - StringReader sr = new StringReader(importDeclaration); - ImportDeclaration id = new ASTParser(sr).ImportDeclaration(); - sr.close(); - return id; - } - - /** - * 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 { - StringReader sr = new StringReader(expression); - Expression e = new ASTParser(sr).Expression(); - sr.close(); - return e; - } - - /** - * 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 { - StringReader sr = new StringReader(annotation); - AnnotationExpr ae = new ASTParser(sr).Annotation(); - sr.close(); - return ae; - } - - /** - * 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 { - StringReader sr = new StringReader(body); - BodyDeclaration bd = new ASTParser(sr).AnnotationBodyDeclaration(); - sr.close(); - return bd; - } - - /** - * Comments are attributed to the thing the comment and are removed from - * allComments. - */ - private static 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 comments = commentsCollection.getAll(); - PositionUtils.sortByBeginPosition(comments); - List children = cu.getChildrenNodes(); - PositionUtils.sortByBeginPosition(children); - - if (cu.getPackage()!=null && (children.size()==0 || PositionUtils.areInOrder(comments.get(0), children.get(0)))){ - cu.setComment(comments.get(0)); - comments.remove(0); - } - - insertCommentsInNode(cu,comments); - } - - private static 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.getBeginLine()==lineComment.getBeginLine() && !node.hasComment()) - { - 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 children = new LinkedList(); - children.addAll(node.getChildrenNodes()); - PositionUtils.sortByBeginPosition(children); - Collections.reverse(children); - - for (Node child : children) - { - if (attributeLineCommentToNodeOrChild(child, lineComment)) - { - return true; - } - } - - return false; - } - } - - /** - * This method try to attributes the nodes received to child of the node. - * It returns the node that were not attributed. - */ - private static void insertCommentsInNode(Node node, List commentsToAttribute){ - if (commentsToAttribute.size()==0) 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 children = node.getChildrenNodes(); - PositionUtils.sortByBeginPosition(children); - - for (Node child : children){ - List commentsInsideChild = new LinkedList(); - 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 attributedComments = new LinkedList(); - for (Comment comment : commentsToAttribute) - { - if (comment.isLineComment()) - { - for (Node child : children) - { - if (child.getEndLine()==comment.getBeginLine()) - { - if (attributeLineCommentToNodeOrChild(child, comment.asLineComment())) - { - attributedComments.add(comment); - } - } - } - } - } - - // at this point I create an ordered list of all remaining comments and children - Comment previousComment = null; - attributedComments = new LinkedList(); - List childrenAndComments = new LinkedList(); - 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 static boolean thereAreLinesBetween(Node a, Node b) - { - if (!PositionUtils.areInOrder(a, b)) - { - return thereAreLinesBetween(b, a); - } - int endOfA = a.getEndLine(); - return b.getBeginLine()>(a.getEndLine()+1); - } - - private static void insertComments(CompilationUnit cu, String code) throws IOException { - CommentsParser commentsParser = new CommentsParser(); - CommentsCollection allComments = commentsParser.parse(code); - - insertCommentsInCu(cu,allComments); - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.javadoc.Javadoc; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.file.Path; + +import static com.github.javaparser.ParseStart.*; +import static com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION; +import static com.github.javaparser.Providers.*; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Parse Java source code and creates Abstract Syntax Trees. + * + * @author Júlio Vilmar Gesser + */ +public final class JavaParser { + private final ParserConfiguration configuration; + + private GeneratedJavaParser astParser = null; + private static ParserConfiguration staticConfiguration = new ParserConfiguration(); + + /** + * Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on + * this class. + * Creating an instance will reduce setup time between parsing files. + */ + public JavaParser() { + this(new ParserConfiguration()); + } + + /** + * Instantiate the parser. Note that parsing can also be done with the static methods on this class. + * Creating an instance will reduce setup time between parsing files. + */ + public JavaParser(ParserConfiguration configuration) { + this.configuration = configuration; + } + + /** + * Get the configuration for the static parse... methods. + * This is a STATIC field, so modifying it will directly change how all static parse... methods work! + */ + public static ParserConfiguration getStaticConfiguration() { + return staticConfiguration; + } + + /** + * Set the configuration for the static parse... methods. + * This is a STATIC field, so modifying it will directly change how all static parse... methods work! + */ + public static void setStaticConfiguration(ParserConfiguration staticConfiguration) { + JavaParser.staticConfiguration = staticConfiguration; + } + + /** + * Get the non-static configuration for this parser. + * + * @return The non-static configuration for this parser. + */ + public ParserConfiguration getParserConfiguration() { + return this.configuration; + } + + private GeneratedJavaParser getParserForProvider(Provider provider) { + if (astParser == null) { + astParser = new GeneratedJavaParser(provider); + } else { + astParser.reset(provider); + } + astParser.setTabSize(configuration.getTabSize()); + astParser.setStoreTokens(configuration.isStoreTokens()); + return astParser; + } + + /** + * Parses source code. + * It takes the source code from a Provider. + * The start indicates what can be found in the source code (compilation unit, block, import...) + * + * @param start refer to the constants in ParseStart to see what can be parsed. + * @param provider refer to Providers to see how you can read source. The provider will be closed after parsing. + * @param the subclass of Node that is the result of parsing in the start. + * @return the parse result, a collection of encountered problems, and some extra data. + */ + public ParseResult parse(ParseStart start, Provider provider) { + assertNotNull(start); + assertNotNull(provider); + final GeneratedJavaParser parser = getParserForProvider(provider); + try { + N resultNode = start.parse(parser); + ParseResult result = new ParseResult<>(resultNode, parser.problems, parser.getTokens(), + parser.getCommentsCollection()); + + configuration.getPostProcessors().forEach(postProcessor -> + postProcessor.process(result, configuration)); + + result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION); + + return result; + } catch (Exception e) { + final String message = e.getMessage() == null ? "Unknown error" : e.getMessage(); + parser.problems.add(new Problem(message, null, e)); + return new ParseResult<>(null, parser.problems, parser.getTokens(), parser.getCommentsCollection()); + } finally { + try { + provider.close(); + } catch (IOException e) { + // Since we're done parsing and have our result, we don't care about any errors. + } + } + } + + /** + * Parses the Java code contained in the {@link InputStream} and returns a + * {@link CompilationUnit} that represents it. + * + * @param in {@link InputStream} containing Java source code. It will be closed after parsing. + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final InputStream in, Charset encoding) { + return simplifiedParse(COMPILATION_UNIT, provider(in, encoding)); + } + + /** + * Parses the Java code contained in the {@link InputStream} and returns a + * {@link CompilationUnit} that represents it.
+ * Note: Uses UTF-8 encoding + * + * @param in {@link InputStream} containing Java source code. It will be closed after parsing. + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final InputStream in) { + return parse(in, UTF8); + } + + /** + * Parses the Java code contained in a {@link File} and returns a + * {@link CompilationUnit} that represents it. + * + * @param file {@link File} containing Java source code. It will be closed after parsing. + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws FileNotFoundException the file was not found + */ + public static CompilationUnit parse(final File file, final Charset encoding) throws FileNotFoundException { + return simplifiedParse(COMPILATION_UNIT, provider(file, encoding)).setStorage(file.toPath()); + } + + /** + * Parses the Java code contained in a {@link File} and returns a + * {@link CompilationUnit} that represents it.
+ * Note: Uses UTF-8 encoding + * + * @param file {@link File} containing Java source code. It will be closed after parsing. + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws FileNotFoundException the file was not found + */ + public static CompilationUnit parse(final File file) throws FileNotFoundException { + return simplifiedParse(COMPILATION_UNIT, provider(file)).setStorage(file.toPath()); + } + + /** + * Parses the Java code contained in a file and returns a + * {@link CompilationUnit} that represents it. + * + * @param path path to a file containing Java source code + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws IOException the path could not be accessed + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final Path path, final Charset encoding) throws IOException { + return simplifiedParse(COMPILATION_UNIT, provider(path, encoding)).setStorage(path); + } + + /** + * Parses the Java code contained in a file and returns a + * {@link CompilationUnit} that represents it.
+ * Note: Uses UTF-8 encoding + * + * @param path path to a file containing Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws IOException the path could not be accessed + */ + public static CompilationUnit parse(final Path path) throws IOException { + return simplifiedParse(COMPILATION_UNIT, provider(path)).setStorage(path); + } + + /** + * Parses the Java code contained in a resource and returns a + * {@link CompilationUnit} that represents it.
+ * Note: Uses UTF-8 encoding + * + * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a + * leading "/" is not allowed in pathToResource + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws IOException the path could not be accessed + */ + public static CompilationUnit parseResource(final String path) throws IOException { + return simplifiedParse(COMPILATION_UNIT, resourceProvider(path)); + } + + /** + * Parses the Java code contained in a resource and returns a + * {@link CompilationUnit} that represents it.
+ * + * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a + * leading "/" is not allowed in pathToResource + * @param encoding encoding of the source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws IOException the path could not be accessed + */ + public static CompilationUnit parseResource(final String path, Charset encoding) throws IOException { + return simplifiedParse(COMPILATION_UNIT, resourceProvider(path, encoding)); + } + + /** + * Parses the Java code contained in a resource and returns a + * {@link CompilationUnit} that represents it.
+ * + * @param classLoader the classLoader that is asked to load the resource + * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a + * leading "/" is not allowed in pathToResource + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + * @throws IOException the path could not be accessed + */ + public static CompilationUnit parseResource(final ClassLoader classLoader, final String path, Charset encoding) throws IOException { + return simplifiedParse(COMPILATION_UNIT, resourceProvider(classLoader, path, encoding)); + } + + /** + * Parses Java code from a Reader and returns a + * {@link CompilationUnit} that represents it.
+ * + * @param reader the reader containing Java source code. It will be closed after parsing. + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(final Reader reader) { + return simplifiedParse(COMPILATION_UNIT, provider(reader)); + } + + /** + * Parses the Java code contained in code and returns a + * {@link CompilationUnit} that represents it. + * + * @param code Java source code + * @return CompilationUnit representing the Java source code + * @throws ParseProblemException if the source code has parser errors + */ + public static CompilationUnit parse(String code) { + return simplifiedParse(COMPILATION_UNIT, provider(code)); + } + + /** + * Parses the Java block contained in a {@link String} and returns a + * {@link BlockStmt} that represents it. + * + * @param blockStatement {@link String} containing Java block code + * @return BlockStmt representing the Java block + * @throws ParseProblemException if the source code has parser errors + */ + public static BlockStmt parseBlock(final String blockStatement) { + return simplifiedParse(BLOCK, provider(blockStatement)); + } + + /** + * Parses the Java statement contained in a {@link String} and returns a + * {@link Statement} that represents it. + * + * @param statement {@link String} containing Java statement code + * @return Statement representing the Java statement + * @throws ParseProblemException if the source code has parser errors + */ + public static Statement parseStatement(final String statement) { + return simplifiedParse(STATEMENT, provider(statement)); + } + + private static T simplifiedParse(ParseStart context, Provider provider) { + ParseResult result = new JavaParser(staticConfiguration).parse(context, provider); + if (result.isSuccessful()) { + return result.getResult().get(); + } + throw new ParseProblemException(result.getProblems()); + } + + /** + * Parses the Java import contained in a {@link String} and returns a + * {@link ImportDeclaration} that represents it. + * + * @param importDeclaration {@link String} containing Java import code + * @return ImportDeclaration representing the Java import declaration + * @throws ParseProblemException if the source code has parser errors + */ + public static ImportDeclaration parseImport(final String importDeclaration) { + return simplifiedParse(IMPORT_DECLARATION, provider(importDeclaration)); + } + + /** + * Parses the Java expression contained in a {@link String} and returns a + * {@link Expression} that represents it. + * + * @param expression {@link String} containing Java expression + * @return Expression representing the Java expression + * @throws ParseProblemException if the source code has parser errors + */ + @SuppressWarnings("unchecked") + public static T parseExpression(final String expression) { + return (T) simplifiedParse(EXPRESSION, provider(expression)); + } + + /** + * Parses the Java annotation contained in a {@link String} and returns a + * {@link AnnotationExpr} that represents it. + * + * @param annotation {@link String} containing Java annotation + * @return AnnotationExpr representing the Java annotation + * @throws ParseProblemException if the source code has parser errors + */ + public static AnnotationExpr parseAnnotation(final String annotation) { + return simplifiedParse(ANNOTATION, provider(annotation)); + } + + /** + * Parses the Java annotation body declaration(e.g fields or methods) contained in a + * {@link String} and returns a {@link BodyDeclaration} that represents it. + * + * @param body {@link String} containing Java body declaration + * @return BodyDeclaration representing the Java annotation + * @throws ParseProblemException if the source code has parser errors + */ + public static BodyDeclaration parseAnnotationBodyDeclaration(final String body) { + return simplifiedParse(ANNOTATION_BODY, provider(body)); + } + + /** + * Parses a Java class body declaration(e.g fields or methods) and returns a + * {@link BodyDeclaration} that represents it. + * + * @param body the body of a class + * @return BodyDeclaration representing the Java class body + * @throws ParseProblemException if the source code has parser errors + * @deprecated just use parseBodyDeclaration now. + */ + @Deprecated + public static BodyDeclaration parseClassBodyDeclaration(String body) { + return parseBodyDeclaration(body); + } + + /** + * Parses a Java interface body declaration(e.g fields or methods) and returns a + * {@link BodyDeclaration} that represents it. + * + * @param body the body of an interface + * @return BodyDeclaration representing the Java interface body + * @throws ParseProblemException if the source code has parser errors + * @deprecated just use parseBodyDeclaration now. + */ + @Deprecated + public static BodyDeclaration parseInterfaceBodyDeclaration(String body) { + return parseBodyDeclaration(body); + } + + /** + * Parses a Java class or interface body declaration(e.g fields or methods) and returns a + * {@link BodyDeclaration} that represents it. + * + * @param body the body of a class or interface + * @return BodyDeclaration representing the Java interface body + * @throws ParseProblemException if the source code has parser errors + */ + public static BodyDeclaration parseBodyDeclaration(String body) { + return simplifiedParse(CLASS_BODY, provider(body)); + } + + /** + * Parses a Java class or interface type name and returns a {@link ClassOrInterfaceType} that represents it. + * + * @param type the type name like a.b.c.X or Y + * @return ClassOrInterfaceType representing the type + * @throws ParseProblemException if the source code has parser errors + */ + public static ClassOrInterfaceType parseClassOrInterfaceType(String type) { + return simplifiedParse(CLASS_OR_INTERFACE_TYPE, provider(type)); + } + + /** + * Parses a Java type name and returns a {@link Type} that represents it. + * + * @param type the type name like a.b.c.X, Y, or int + * @return ClassOrInterfaceType representing the type + * @throws ParseProblemException if the source code has parser errors + */ + public static Type parseType(String type) { + return simplifiedParse(TYPE, provider(type)); + } + + /** + * Parses a variable declaration expression and returns a {@link com.github.javaparser.ast.expr.VariableDeclarationExpr} + * that represents it. + * + * @param declaration a variable declaration like int x=2; + * @return VariableDeclarationExpr representing the type + * @throws ParseProblemException if the source code has parser errors + */ + public static VariableDeclarationExpr parseVariableDeclarationExpr(String declaration) { + return simplifiedParse(VARIABLE_DECLARATION_EXPR, provider(declaration)); + } + + /** + * Parses the content of a JavadocComment and returns a {@link com.github.javaparser.javadoc.Javadoc} that + * represents it. + * + * @param content a variable declaration like content of my javadoc\n * second line\n * third line + * @return Javadoc representing the content of the comment + * @throws ParseProblemException if the source code has parser errors + */ + public static Javadoc parseJavadoc(String content) { + return JavadocParser.parse(content); + } + + /** + * Parses the this(...) and super(...) statements that may occur at the start of a constructor. + * + * @param statement a statement like super("hello"); + * @return the AST for the statement. + * @throws ParseProblemException if the source code has parser errors + */ + public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) { + return simplifiedParse(EXPLICIT_CONSTRUCTOR_INVOCATION_STMT, provider(statement)); + } + + /** + * Parses a qualified name (one that can have "."s in it) and returns it as a Name. + * + * @param qualifiedName a name like "com.laamella.parameter_source" + * @return the AST for the name + * @throws ParseProblemException if the source code has parser errors + */ + public static Name parseName(String qualifiedName) { + return simplifiedParse(NAME, provider(qualifiedName)); + } + + /** + * Parses a simple name (one that can NOT have "."s in it) and returns it as a SimpleName. + * + * @param name a name like "parameter_source" + * @return the AST for the name + * @throws ParseProblemException if the source code has parser errors + */ + public static SimpleName parseSimpleName(String name) { + return simplifiedParse(SIMPLE_NAME, provider(name)); + } + + /** + * Parses a single parameter (a type and a name) and returns it as a Parameter. + * + * @param parameter a parameter like "int[] x" + * @return the AST for the parameter + * @throws ParseProblemException if the source code has parser errors + */ + public static Parameter parseParameter(String parameter) { + return simplifiedParse(PARAMETER, provider(parameter)); + } + + + /** + * Parses a package declaration and returns it as a PackageDeclaration. + * + * @param packageDeclaration a declaration like "package com.microsoft.java;" + * @return the AST for the parameter + * @throws ParseProblemException if the source code has parser errors + */ + public static PackageDeclaration parsePackageDeclaration(String packageDeclaration) { + return simplifiedParse(PACKAGE_DECLARATION, provider(packageDeclaration)); + } +} diff --git a/JavaParser/src/com/github/javaparser/JavaParserBuild.java b/JavaParser/src/com/github/javaparser/JavaParserBuild.java new file mode 100644 index 0000000..4eaf016 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/JavaParserBuild.java @@ -0,0 +1,19 @@ +package com.github.javaparser; + +/** + * Some information that was available when this library was built by Maven. + */ +public class JavaParserBuild { + public static final String PROJECT_VERSION = "3.5.17-SNAPSHOT"; + public static final String PROJECT_NAME = "javaparser-core"; + public static final String PROJECT_BUILD_FINAL_NAME = "javaparser-core-3.5.17-SNAPSHOT"; + public static final String MAVEN_VERSION = "3.3.9"; + public static final String MAVEN_BUILD_VERSION = "Apache Maven 3.3.9"; + public static final String MAVEN_BUILD_TIMESTAMP = "2018-03-08T13:23:02Z"; + public static final String JAVA_VENDOR ="Oracle Corporation"; + public static final String JAVA_VENDOR_URL ="http://java.oracle.com/"; + public static final String JAVA_VERSION ="1.8.0_151"; + public static final String OS_ARCH ="amd64"; + public static final String OS_NAME ="Linux"; + public static final String OS_VERSION ="4.4.0-116-generic"; +} \ No newline at end of file diff --git a/JavaParser/src/com/github/javaparser/JavaToken.java b/JavaParser/src/com/github/javaparser/JavaToken.java new file mode 100644 index 0000000..ad56ff5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/JavaToken.java @@ -0,0 +1,796 @@ +/* + * 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.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import static com.github.javaparser.utils.Utils.EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; + +/** + * A token from a parsed source file. + * (Awkwardly named "Java"Token since JavaCC already generates an internal class Token.) + * It is a node in a double linked list called token list. + */ +public class JavaToken { + + public static final JavaToken INVALID = new JavaToken(); + + private Range range; + + private int kind; + + private String text; + + private JavaToken previousToken = null; + + private JavaToken nextToken = null; + + private JavaToken() { + this(null, 0, "INVALID", null, null); + } + + public JavaToken(int kind, String text) { + this(null, kind, text, null, null); + } + + JavaToken(Token token, List tokens) { + // You could be puzzled by the following lines + // + // The reason why these lines are necessary is the fact that Java is ambiguous. There are cases where the + // sequence of characters ">>>" and ">>" should be recognized as the single tokens ">>>" and ">>". In other + // cases however we want to split those characters in single GT tokens (">"). + // + // For example, in expressions ">>" and ">>>" are valid, while when defining types we could have this: + // + // List>>> + // + // You can see that the sequence ">>>>" should be interpreted as four consecutive ">" tokens closing a type + // parameter list. + // + // The JavaCC handle this case by first recognizing always the longest token, and then depending on the context + // putting back the unused chars in the stream. However in those cases the token provided is invalid: it has an + // image corresponding to the text originally recognized, without considering that after some characters could + // have been put back into the stream. + // + // So in the case of: + // + // List>>> + // ___ -> recognized as ">>>", then ">>" put back in the stream but Token(type=GT, image=">>>") passed to this class + // ___ -> recognized as ">>>", then ">>" put back in the stream but Token(type=GT, image=">>>") passed to this class + // __ -> recognized as ">>", then ">" put back in the stream but Token(type=GT, image=">>") passed to this class + // _ -> Token(type=GT, image=">") good! + // + // So given the image could be wrong but the type is correct, we look at the type of the token and we fix + // the image. Everybody is happy and we can keep this horrible thing as our little secret. + Range range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.endColumn); + String text = token.image; + if (token.kind == GeneratedJavaParserConstants.GT) { + range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.beginColumn); + text = ">"; + } else if (token.kind == GeneratedJavaParserConstants.RSIGNEDSHIFT) { + range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.beginColumn + 1); + text = ">>"; + } + this.range = range; + this.kind = token.kind; + this.text = text; + if (!tokens.isEmpty()) { + final JavaToken previousToken = tokens.get(tokens.size() - 1); + this.previousToken = previousToken; + previousToken.nextToken = this; + } else { + previousToken = null; + } + } + + /** + * Create a token of a certain kind. + */ + public JavaToken(int kind) { + String content = GeneratedJavaParserConstants.tokenImage[kind]; + if (content.startsWith("\"")) { + content = content.substring(1, content.length() - 1); + } + if (TokenTypes.isEndOfLineToken(kind)) { + content = EOL; + } else if (TokenTypes.isWhitespace(kind)) { + content = " "; + } + this.kind = kind; + this.text = content; + } + + public JavaToken(Range range, int kind, String text, JavaToken previousToken, JavaToken nextToken) { + assertNotNull(text); + this.range = range; + this.kind = kind; + this.text = text; + this.previousToken = previousToken; + this.nextToken = nextToken; + } + + public Optional getRange() { + return Optional.ofNullable(range); + } + + public int getKind() { + return kind; + } + + void setKind(int kind) { + this.kind = kind; + } + + public String getText() { + return text; + } + + public Optional getNextToken() { + return Optional.ofNullable(nextToken); + } + + public Optional getPreviousToken() { + return Optional.ofNullable(previousToken); + } + + public void setRange(Range range) { + this.range = range; + } + + public void setText(String text) { + this.text = text; + } + + public String asString() { + return text; + } + + /** + * @return the token range that goes from the beginning to the end of the token list this token is a part of. + */ + public TokenRange toTokenRange() { + return new TokenRange(findFirstToken(), findLastToken()); + } + + @Override + public String toString() { + String text = getText().replace("\n", "\\n").replace("\r", "\\r").replace("\r\n", "\\r\\n").replace("\t", "\\t"); + return f("\"%s\" <%s> %s", text, getKind(), getRange().map(Range::toString).orElse("(?)-(?)")); + } + + /** + * Used by the parser while constructing nodes. No tokens should be invalid when the parser is done. + */ + public boolean valid() { + return !invalid(); + } + + /** + * Used by the parser while constructing nodes. No tokens should be invalid when the parser is done. + */ + public boolean invalid() { + return this == INVALID; + } + + public enum Category { + + WHITESPACE_NO_EOL, + EOL, + COMMENT, + IDENTIFIER, + KEYWORD, + LITERAL, + SEPARATOR, + OPERATOR; + + public boolean isWhitespaceOrComment() { + return isWhitespace() || this == COMMENT; + } + + public boolean isWhitespace() { + return this == WHITESPACE_NO_EOL || this == EOL; + } + + public boolean isEndOfLine() { + return this == EOL; + } + + public boolean isComment() { + return this == COMMENT; + } + + public boolean isWhitespaceButNotEndOfLine() { + return this == WHITESPACE_NO_EOL; + } + + public boolean isIdentifier() { + return this == IDENTIFIER; + } + + public boolean isKeyword() { + return this == KEYWORD; + } + + public boolean isLiteral() { + return this == LITERAL; + } + + public boolean isSeparator() { + return this == SEPARATOR; + } + + public boolean isOperator() { + return this == OPERATOR; + } + } + + @Generated("com.github.javaparser.generator.core.other.TokenKindGenerator") + public enum Kind { + + EOF(0), + SPACE(1), + WINDOWS_EOL(2), + UNIX_EOL(3), + OLD_MAC_EOL(4), + SINGLE_LINE_COMMENT(5), + ENTER_JAVADOC_COMMENT(6), + ENTER_MULTILINE_COMMENT(7), + JAVADOC_COMMENT(8), + MULTI_LINE_COMMENT(9), + COMMENT_CONTENT(10), + ABSTRACT(11), + ASSERT(12), + BOOLEAN(13), + BREAK(14), + BYTE(15), + CASE(16), + CATCH(17), + CHAR(18), + CLASS(19), + CONST(20), + CONTINUE(21), + _DEFAULT(22), + DO(23), + DOUBLE(24), + ELSE(25), + ENUM(26), + EXTENDS(27), + FALSE(28), + FINAL(29), + FINALLY(30), + FLOAT(31), + FOR(32), + GOTO(33), + IF(34), + IMPLEMENTS(35), + IMPORT(36), + INSTANCEOF(37), + INT(38), + INTERFACE(39), + LONG(40), + NATIVE(41), + NEW(42), + NULL(43), + PACKAGE(44), + PRIVATE(45), + PROTECTED(46), + PUBLIC(47), + RETURN(48), + SHORT(49), + STATIC(50), + STRICTFP(51), + SUPER(52), + SWITCH(53), + SYNCHRONIZED(54), + THIS(55), + THROW(56), + THROWS(57), + TRANSIENT(58), + TRUE(59), + TRY(60), + VOID(61), + VOLATILE(62), + WHILE(63), + REQUIRES(64), + TO(65), + WITH(66), + OPEN(67), + OPENS(68), + USES(69), + MODULE(70), + EXPORTS(71), + PROVIDES(72), + TRANSITIVE(73), + LONG_LITERAL(74), + INTEGER_LITERAL(75), + DECIMAL_LITERAL(76), + HEX_LITERAL(77), + OCTAL_LITERAL(78), + BINARY_LITERAL(79), + FLOATING_POINT_LITERAL(80), + DECIMAL_FLOATING_POINT_LITERAL(81), + DECIMAL_EXPONENT(82), + HEXADECIMAL_FLOATING_POINT_LITERAL(83), + HEXADECIMAL_EXPONENT(84), + HEX_DIGITS(85), + UNICODE_ESCAPE(86), + CHARACTER_LITERAL(87), + STRING_LITERAL(88), + IDENTIFIER(89), + LETTER(90), + PART_LETTER(91), + LPAREN(92), + RPAREN(93), + LBRACE(94), + RBRACE(95), + LBRACKET(96), + RBRACKET(97), + SEMICOLON(98), + COMMA(99), + DOT(100), + AT(101), + ASSIGN(102), + LT(103), + BANG(104), + TILDE(105), + HOOK(106), + COLON(107), + EQ(108), + LE(109), + GE(110), + NE(111), + SC_OR(112), + SC_AND(113), + INCR(114), + DECR(115), + PLUS(116), + MINUS(117), + STAR(118), + SLASH(119), + BIT_AND(120), + BIT_OR(121), + XOR(122), + REM(123), + LSHIFT(124), + PLUSASSIGN(125), + MINUSASSIGN(126), + STARASSIGN(127), + SLASHASSIGN(128), + ANDASSIGN(129), + ORASSIGN(130), + XORASSIGN(131), + REMASSIGN(132), + LSHIFTASSIGN(133), + RSIGNEDSHIFTASSIGN(134), + RUNSIGNEDSHIFTASSIGN(135), + ELLIPSIS(136), + ARROW(137), + DOUBLECOLON(138), + RUNSIGNEDSHIFT(139), + RSIGNEDSHIFT(140), + GT(141), + CTRL_Z(142); + + private final int kind; + + Kind(int kind) { + this.kind = kind; + } + + public static Kind valueOf(int kind) { + switch(kind) { + case 142: + return CTRL_Z; + case 141: + return GT; + case 140: + return RSIGNEDSHIFT; + case 139: + return RUNSIGNEDSHIFT; + case 138: + return DOUBLECOLON; + case 137: + return ARROW; + case 136: + return ELLIPSIS; + case 135: + return RUNSIGNEDSHIFTASSIGN; + case 134: + return RSIGNEDSHIFTASSIGN; + case 133: + return LSHIFTASSIGN; + case 132: + return REMASSIGN; + case 131: + return XORASSIGN; + case 130: + return ORASSIGN; + case 129: + return ANDASSIGN; + case 128: + return SLASHASSIGN; + case 127: + return STARASSIGN; + case 126: + return MINUSASSIGN; + case 125: + return PLUSASSIGN; + case 124: + return LSHIFT; + case 123: + return REM; + case 122: + return XOR; + case 121: + return BIT_OR; + case 120: + return BIT_AND; + case 119: + return SLASH; + case 118: + return STAR; + case 117: + return MINUS; + case 116: + return PLUS; + case 115: + return DECR; + case 114: + return INCR; + case 113: + return SC_AND; + case 112: + return SC_OR; + case 111: + return NE; + case 110: + return GE; + case 109: + return LE; + case 108: + return EQ; + case 107: + return COLON; + case 106: + return HOOK; + case 105: + return TILDE; + case 104: + return BANG; + case 103: + return LT; + case 102: + return ASSIGN; + case 101: + return AT; + case 100: + return DOT; + case 99: + return COMMA; + case 98: + return SEMICOLON; + case 97: + return RBRACKET; + case 96: + return LBRACKET; + case 95: + return RBRACE; + case 94: + return LBRACE; + case 93: + return RPAREN; + case 92: + return LPAREN; + case 91: + return PART_LETTER; + case 90: + return LETTER; + case 89: + return IDENTIFIER; + case 88: + return STRING_LITERAL; + case 87: + return CHARACTER_LITERAL; + case 86: + return UNICODE_ESCAPE; + case 85: + return HEX_DIGITS; + case 84: + return HEXADECIMAL_EXPONENT; + case 83: + return HEXADECIMAL_FLOATING_POINT_LITERAL; + case 82: + return DECIMAL_EXPONENT; + case 81: + return DECIMAL_FLOATING_POINT_LITERAL; + case 80: + return FLOATING_POINT_LITERAL; + case 79: + return BINARY_LITERAL; + case 78: + return OCTAL_LITERAL; + case 77: + return HEX_LITERAL; + case 76: + return DECIMAL_LITERAL; + case 75: + return INTEGER_LITERAL; + case 74: + return LONG_LITERAL; + case 73: + return TRANSITIVE; + case 72: + return PROVIDES; + case 71: + return EXPORTS; + case 70: + return MODULE; + case 69: + return USES; + case 68: + return OPENS; + case 67: + return OPEN; + case 66: + return WITH; + case 65: + return TO; + case 64: + return REQUIRES; + case 63: + return WHILE; + case 62: + return VOLATILE; + case 61: + return VOID; + case 60: + return TRY; + case 59: + return TRUE; + case 58: + return TRANSIENT; + case 57: + return THROWS; + case 56: + return THROW; + case 55: + return THIS; + case 54: + return SYNCHRONIZED; + case 53: + return SWITCH; + case 52: + return SUPER; + case 51: + return STRICTFP; + case 50: + return STATIC; + case 49: + return SHORT; + case 48: + return RETURN; + case 47: + return PUBLIC; + case 46: + return PROTECTED; + case 45: + return PRIVATE; + case 44: + return PACKAGE; + case 43: + return NULL; + case 42: + return NEW; + case 41: + return NATIVE; + case 40: + return LONG; + case 39: + return INTERFACE; + case 38: + return INT; + case 37: + return INSTANCEOF; + case 36: + return IMPORT; + case 35: + return IMPLEMENTS; + case 34: + return IF; + case 33: + return GOTO; + case 32: + return FOR; + case 31: + return FLOAT; + case 30: + return FINALLY; + case 29: + return FINAL; + case 28: + return FALSE; + case 27: + return EXTENDS; + case 26: + return ENUM; + case 25: + return ELSE; + case 24: + return DOUBLE; + case 23: + return DO; + case 22: + return _DEFAULT; + case 21: + return CONTINUE; + case 20: + return CONST; + case 19: + return CLASS; + case 18: + return CHAR; + case 17: + return CATCH; + case 16: + return CASE; + case 15: + return BYTE; + case 14: + return BREAK; + case 13: + return BOOLEAN; + case 12: + return ASSERT; + case 11: + return ABSTRACT; + case 10: + return COMMENT_CONTENT; + case 9: + return MULTI_LINE_COMMENT; + case 8: + return JAVADOC_COMMENT; + case 7: + return ENTER_MULTILINE_COMMENT; + case 6: + return ENTER_JAVADOC_COMMENT; + case 5: + return SINGLE_LINE_COMMENT; + case 4: + return OLD_MAC_EOL; + case 3: + return UNIX_EOL; + case 2: + return WINDOWS_EOL; + case 1: + return SPACE; + case 0: + return EOF; + default: + throw new IllegalArgumentException(f("Token kind %i is unknown.", kind)); + } + } + + public int getKind() { + return kind; + } + } + + public JavaToken.Category getCategory() { + return TokenTypes.getCategory(kind); + } + + /** + * Inserts newToken into the token list just before this token. + */ + public void insert(JavaToken newToken) { + assertNotNull(newToken); + getPreviousToken().ifPresent(p -> { + p.nextToken = newToken; + newToken.previousToken = p; + }); + previousToken = newToken; + newToken.nextToken = this; + } + + /** + * Inserts newToken into the token list just after this token. + */ + public void insertAfter(JavaToken newToken) { + assertNotNull(newToken); + getNextToken().ifPresent(n -> { + n.previousToken = newToken; + newToken.nextToken = n; + }); + nextToken = newToken; + newToken.previousToken = this; + } + + /** + * Links the tokens around the current token together, making the current token disappear from the list. + */ + public void deleteToken() { + final Optional nextToken = getNextToken(); + final Optional previousToken = getPreviousToken(); + previousToken.ifPresent(p -> p.nextToken = nextToken.orElse(null)); + nextToken.ifPresent(n -> n.previousToken = previousToken.orElse(null)); + } + + /** + * Replaces the current token with newToken. + */ + public void replaceToken(JavaToken newToken) { + assertNotNull(newToken); + getPreviousToken().ifPresent(p -> { + p.nextToken = newToken; + newToken.previousToken = p; + }); + getNextToken().ifPresent(n -> { + n.previousToken = newToken; + newToken.nextToken = n; + }); + } + + /** + * @return the last token in the token list. + */ + public JavaToken findLastToken() { + JavaToken current = this; + while (current.getNextToken().isPresent()) { + current = current.getNextToken().get(); + } + return current; + } + + /** + * @return the first token in the token list. + */ + public JavaToken findFirstToken() { + JavaToken current = this; + while (current.getPreviousToken().isPresent()) { + current = current.getPreviousToken().get(); + } + return current; + } + + @Override + public int hashCode() { + int result = kind; + result = 31 * result + text.hashCode(); + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + JavaToken javaToken = (JavaToken) o; + if (kind != javaToken.kind) + return false; + if (!text.equals(javaToken.text)) + return false; + return true; + } +} diff --git a/JavaParser/src/com/github/javaparser/JavadocParser.java b/JavaParser/src/com/github/javaparser/JavadocParser.java new file mode 100644 index 0000000..bbe9797 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/JavadocParser.java @@ -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; + +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.javadoc.JavadocBlockTag; +import com.github.javaparser.javadoc.description.JavadocDescription; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static com.github.javaparser.utils.Utils.*; +import static com.github.javaparser.utils.Utils.nextWord; + +/** + * The class responsible for parsing the content of JavadocComments and produce JavadocDocuments. + */ +class JavadocParser { + + private static String BLOCK_TAG_PREFIX = "@"; + private static Pattern BLOCK_PATTERN = Pattern.compile("^" + BLOCK_TAG_PREFIX, Pattern.MULTILINE); + + public static Javadoc parse(JavadocComment comment) { + return parse(comment.getContent()); + } + + public static Javadoc parse(String commentContent) { + List cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, EOL)); + int indexOfFirstBlockTag = cleanLines.stream() + .filter(JavadocParser::isABlockLine) + .map(cleanLines::indexOf) + .findFirst() + .orElse(-1); + List blockLines; + String descriptionText; + if (indexOfFirstBlockTag == -1) { + descriptionText = trimRight(String.join(EOL, cleanLines)); + blockLines = Collections.emptyList(); + } else { + descriptionText = trimRight(String.join(EOL, cleanLines.subList(0, indexOfFirstBlockTag))); + + //Combine cleaned lines, but only starting with the first block tag till the end + //In this combined string it is easier to handle multiple lines which actually belong together + String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()) + .stream() + .collect(Collectors.joining(EOL)); + + //Split up the entire tag back again, considering now that some lines belong to the same block tag. + //The pattern splits the block at each new line starting with the '@' symbol, thus the symbol + //then needs to be added again so that the block parsers handles everything correctly. + blockLines = BLOCK_PATTERN + .splitAsStream(tagBlock) + .filter(STRING_NOT_EMPTY) + .map(s -> BLOCK_TAG_PREFIX + s) + .collect(Collectors.toList()); + } + Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText)); + blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l))); + return document; + } + + private static JavadocBlockTag parseBlockTag(String line) { + line = line.trim().substring(1); + String tagName = nextWord(line); + String rest = line.substring(tagName.length()).trim(); + return new JavadocBlockTag(tagName, rest); + } + + private static boolean isABlockLine(String line) { + return line.trim().startsWith(BLOCK_TAG_PREFIX); + } + + private static String trimRight(String string) { + while (!string.isEmpty() && Character.isWhitespace(string.charAt(string.length() - 1))) { + string = string.substring(0, string.length() - 1); + } + return string; + } + + private static List cleanLines(String content) { + String[] lines = content.split(EOL); + List cleanedLines = Arrays.stream(lines).map(l -> { + int asteriskIndex = startsWithAsterisk(l); + if (asteriskIndex == -1) { + return l; + } else { + // if a line starts with space followed by an asterisk drop to the asterisk + // if there is a space immediately after the asterisk drop it also + if (l.length() > (asteriskIndex + 1)) { + + char c = l.charAt(asteriskIndex + 1); + if (c == ' ' || c == '\t') { + return l.substring(asteriskIndex + 2); + } + } + return l.substring(asteriskIndex + 1); + } + }).collect(Collectors.toList()); + // lines containing only whitespace are normalized to empty lines + cleanedLines = cleanedLines.stream().map(l -> l.trim().isEmpty() ? "" : l).collect(Collectors.toList()); + // if the first starts with a space, remove it + if (!cleanedLines.get(0).isEmpty() && (cleanedLines.get(0).charAt(0) == ' ' || cleanedLines.get(0).charAt(0) == '\t')) { + cleanedLines.set(0, cleanedLines.get(0).substring(1)); + } + // drop empty lines at the beginning and at the end + while (cleanedLines.size() > 0 && cleanedLines.get(0).trim().isEmpty()) { + cleanedLines = cleanedLines.subList(1, cleanedLines.size()); + } + while (cleanedLines.size() > 0 && cleanedLines.get(cleanedLines.size() - 1).trim().isEmpty()) { + cleanedLines = cleanedLines.subList(0, cleanedLines.size() - 1); + } + return cleanedLines; + } + + // Visible for testing + static int startsWithAsterisk(String line) { + if (line.startsWith("*")) { + return 0; + } else if ((line.startsWith(" ") || line.startsWith("\t")) && line.length() > 1) { + int res = startsWithAsterisk(line.substring(1)); + if (res == -1) { + return -1; + } else { + return 1 + res; + } + } else { + return -1; + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ModifierHolder.java b/JavaParser/src/com/github/javaparser/ModifierHolder.java new file mode 100644 index 0000000..46d2e8f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ModifierHolder.java @@ -0,0 +1,24 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; + +import java.util.EnumSet; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Helper class for {@link GeneratedJavaParser} + */ +class ModifierHolder { + final EnumSet modifiers; + final NodeList annotations; + final JavaToken begin; + + ModifierHolder(JavaToken begin, EnumSet modifiers, NodeList annotations) { + this.begin = begin; + this.modifiers = assertNotNull(modifiers); + this.annotations = annotations; + } +} diff --git a/JavaParser/src/com/github/javaparser/ParseException.java b/JavaParser/src/com/github/javaparser/ParseException.java index 2930289..5d25eae 100644 --- a/JavaParser/src/com/github/javaparser/ParseException.java +++ b/JavaParser/src/com/github/javaparser/ParseException.java @@ -1,199 +1,235 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ -/* JavaCCOptions:KEEP_LINE_COL=null */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generateParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the public fields. - */ -public class ParseException extends Exception { - - /** - * The version identifier for this Serializable class. - * Increment only if the serialized form of the - * class changes. - */ - private static final long serialVersionUID = 1L; - - /** - * This constructor is used by the method "generateParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. - */ - public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal - ) - { - super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); - currentToken = currentTokenVal; - expectedTokenSequences = expectedTokenSequencesVal; - tokenImage = tokenImageVal; - } - - /** - * The following constructors are for use by you for whatever - * purpose you can think of. Constructing the exception in this - * manner makes the exception behave in the normal way - i.e., as - * documented in the class "Throwable". The fields "errorToken", - * "expectedTokenSequences", and "tokenImage" do not contain - * relevant information. The JavaCC generated code does not use - * these constructors. - */ - - public ParseException() { - super(); - } - - /** Constructor with message. */ - public ParseException(String message) { - super(message); - } - - - /** - * This is the last token that has been consumed successfully. If - * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. - */ - public Token currentToken; - - /** - * Each entry in this array is an array of integers. Each array - * of integers represents a sequence of tokens (by their ordinal - * values) that is expected at this point of the parse. - */ - public int[][] expectedTokenSequences; - - /** - * This is a reference to the "tokenImage" array of the generated - * parser within which the parse error occurred. This array is - * defined in the generated ...Constants interface. - */ - public String[] tokenImage; - - /** - * It uses "currentToken" and "expectedTokenSequences" to generate a parse - * error message and returns it. If this object has been created - * due to a parse error, and you do not catch it (it gets thrown - * from the parser) the correct error message - * gets displayed. - */ - private static String initialise(Token currentToken, - int[][] expectedTokenSequences, - String[] tokenImage) { - String eol = System.getProperty("line.separator", "\n"); - StringBuffer expected = new StringBuffer(); - int maxSize = 0; - for (int i = 0; i < expectedTokenSequences.length; i++) { - if (maxSize < expectedTokenSequences[i].length) { - maxSize = expectedTokenSequences[i].length; - } - for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); - } - if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { - expected.append("..."); - } - expected.append(eol).append(" "); - } - String retval = "Encountered \""; - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += " "; - if (tok.kind == 0) { - retval += tokenImage[0]; - break; - } - retval += " " + tokenImage[tok.kind]; - retval += " \""; - retval += add_escapes(tok.image); - retval += " \""; - tok = tok.next; - } - retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; - retval += "." + eol; - if (expectedTokenSequences.length == 1) { - retval += "Was expecting:" + eol + " "; - } else { - retval += "Was expecting one of:" + eol + " "; - } - retval += expected.toString(); - return retval; - } - - /** - * The end of line string for this machine. - */ - protected String eol = System.getProperty("line.separator", "\n"); - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - static String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - -} -/* JavaCC - OriginalChecksum=487f1a4a684cd8cca16b3139685ab5dd (do not edit this line) */ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 7.0 */ +/* JavaCCOptions:KEEP_LINE_COLUMN=true */ +/* + * 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; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + private static final String INDENT = " "; + + /** + * The end of line string (we do not use System.getProperty("") so that we are compatible with Android/GWT); + */ + protected static String EOL = "\n"; + + + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + this (currentTokenVal, expectedTokenSequencesVal, tokenImageVal, null); + } + + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal, + String lexicalStateName + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal, lexicalStateName)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage, + String lexicalStateName) { + StringBuilder sb = new StringBuilder(); + StringBuffer expected = new StringBuffer(); + + int maxSize = 0; + java.util.TreeSet sortedOptions = new java.util.TreeSet(); + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + sortedOptions.add(tokenImage[expectedTokenSequences[i][j]]); + } + } + + for (String option : sortedOptions) { + expected.append(INDENT).append(option).append(EOL); + } + + sb.append("Encountered unexpected token:"); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) { + sb.append(" "); + } + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + sb.append(" " + tokenImage[tok.kind]); + tok = tok.next; + } + sb.append(EOL).append(INDENT).append("at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + int numExpectedTokens = expectedTokenSequences.length; + sb.append(EOL).append("Was expecting"+ (numExpectedTokens == 1 ? ":" : " one of:") + EOL + EOL); + sb.append(expected.toString()); + } + // 2013/07/30 --> Seems to be inaccurate as represents the readahead state, not the lexical state BEFORE the unknown token +// if (lexicalStateName != null) { +// sb.append(EOL).append("** Lexical State : ").append(lexicalStateName).append(EOL).append(EOL); +// } + + return sb.toString(); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=f4d1610e84d3d5884564259f96f1c24b (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/ParseProblemException.java b/JavaParser/src/com/github/javaparser/ParseProblemException.java new file mode 100644 index 0000000..50064dc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ParseProblemException.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.Collections.singletonList; + +/** + * Thrown when parsing problems occur during parsing with the static methods on JavaParser. + */ +public class ParseProblemException extends RuntimeException { + /** + * The problems that were encountered during parsing + */ + private final List problems; + + public ParseProblemException(List problems) { + super(createMessage(assertNotNull(problems))); + this.problems = problems; + } + + public ParseProblemException(Throwable throwable) { + this(singletonList(new Problem(throwable.getMessage(), null, throwable))); + } + + private static String createMessage(List problems) { + StringBuilder message = new StringBuilder(); + for (Problem problem : problems) { + message.append(problem.toString()).append(EOL); + } + return message.toString(); + } + + public List getProblems() { + return problems; + } +} diff --git a/JavaParser/src/com/github/javaparser/ParseResult.java b/JavaParser/src/com/github/javaparser/ParseResult.java new file mode 100644 index 0000000..4edc79a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ParseResult.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.CommentsCollection; + +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +import static com.github.javaparser.utils.Utils.EOL; + +/** + * The results given when parsing with an instance of JavaParser. + */ +public class ParseResult { + private final T result; + private final List problems; + private final List tokens; + private final CommentsCollection commentsCollection; + + /** + * General constructor. + * + * @param result the AST, or empty if it wasn't created. + * @param problems a list of encountered parsing problems. + * @param tokens the complete list of tokens that were parsed, or empty if parsing failed completely. + */ + public ParseResult(T result, List problems, List tokens, CommentsCollection commentsCollection) { + this.commentsCollection = commentsCollection; + this.result = result; + this.problems = problems; + this.tokens = tokens; + } + + /** + * @return if parsing was successful, meaning no errors of any kind were encountered. + */ + public boolean isSuccessful() { + return problems.isEmpty() && result != null; + } + + /** + * Calls the consumer with the result if parsing was succesful. + */ + public void ifSuccessful(Consumer consumer) { + if (isSuccessful()) { + consumer.accept(result); + } + } + + /** + * @return the list of encountered parsing problems. Empty when no problems were encountered. + */ + public List getProblems() { + return problems; + } + + /** + * @return the i'th encountered parsing problem. May throw IndexOutOfBoundsException. + */ + public Problem getProblem(int i) { + return getProblems().get(i); + } + + /** + * @return the complete list of tokens that were parsed, or empty if parsing failed completely. + * @deprecated lists of tokens are now kept in every node. + * Calling this method is comparable to calling getResult().get().getTokenRange().get() + */ + @Deprecated + public Optional> getTokens() { + return Optional.ofNullable(tokens); + } + + /** + * @return the complete collection of comments encountered while parsing. + */ + public Optional getCommentsCollection() { + return Optional.ofNullable(commentsCollection); + } + + /** + * @return the AST of the parsed source code, or empty if parsing failed completely. + */ + public Optional getResult() { + return Optional.ofNullable(result); + } + + @Override + public String toString() { + if (isSuccessful()) { + return "Parsing successful"; + } + StringBuilder message = new StringBuilder("Parsing failed:").append(EOL); + for (Problem problem : problems) { + message.append(problem.toString()).append(EOL); + } + return message.toString(); + } + + /** + * A post processor that can be added to ParserConfiguration to add some processing right after parsing. + */ + public interface PostProcessor { + void process(ParseResult result, ParserConfiguration configuration); + } +} diff --git a/JavaParser/src/com/github/javaparser/ParseStart.java b/JavaParser/src/com/github/javaparser/ParseStart.java new file mode 100644 index 0000000..ecb562c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ParseStart.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; + +/** + * The start production for JavaParser. + * Tells JavaParser what piece of Java code it can expect. + * For example, + * COMPILATION_UNIT indicates a complete Java file, + * and CLASS_BODY would indicate the part of a class that is within { and }. + * + * @see JavaParser#parse(ParseStart, Provider) + */ +@FunctionalInterface +public interface ParseStart { + ParseStart COMPILATION_UNIT = GeneratedJavaParser::CompilationUnit; + ParseStart BLOCK = GeneratedJavaParser::BlockParseStart; + ParseStart STATEMENT = GeneratedJavaParser::BlockStatementParseStart; + ParseStart IMPORT_DECLARATION = GeneratedJavaParser::ImportDeclarationParseStart; + ParseStart EXPRESSION = GeneratedJavaParser::ExpressionParseStart; + ParseStart ANNOTATION = GeneratedJavaParser::AnnotationParseStart; + ParseStart> ANNOTATION_BODY = GeneratedJavaParser::AnnotationBodyDeclarationParseStart; + ParseStart> CLASS_BODY = GeneratedJavaParser::ClassOrInterfaceBodyDeclarationParseStart; + ParseStart CLASS_OR_INTERFACE_TYPE = GeneratedJavaParser::ClassOrInterfaceTypeParseStart; + ParseStart TYPE = GeneratedJavaParser::ResultTypeParseStart; + ParseStart VARIABLE_DECLARATION_EXPR = GeneratedJavaParser::VariableDeclarationExpressionParseStart; + ParseStart EXPLICIT_CONSTRUCTOR_INVOCATION_STMT = GeneratedJavaParser::ExplicitConstructorInvocationParseStart; + ParseStart NAME = GeneratedJavaParser::NameParseStart; + ParseStart SIMPLE_NAME = GeneratedJavaParser::SimpleNameParseStart; + ParseStart PARAMETER = GeneratedJavaParser::ParameterParseStart; + ParseStart PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart; + + R parse(GeneratedJavaParser parser) throws ParseException; +} diff --git a/JavaParser/src/com/github/javaparser/ParserConfiguration.java b/JavaParser/src/com/github/javaparser/ParserConfiguration.java new file mode 100644 index 0000000..e5be2b8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ParserConfiguration.java @@ -0,0 +1,271 @@ +/* + * 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.validator.*; +import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; +import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.version.Java10PostProcessor; +import com.github.javaparser.version.Java11PostProcessor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * The configuration that is used by the parser. + * Note that this can be changed even when reusing the same JavaParser instance. + * It will pick up the changes. + */ +public class ParserConfiguration { + public enum LanguageLevel { + /** Does no post processing or validation. Only for people wanting the fastest parsing. */ + RAW(null, null), + /** The most used Java version. */ + POPULAR(new Java8Validator(), null), + /** The latest Java version that is available. */ + CURRENT(new Java8Validator(), null), + /** The newest Java features supported. */ + BLEEDING_EDGE(new Java11Validator(), new Java11PostProcessor()), + /** Java 1.0 */ + JAVA_1_0(new Java1_0Validator(), null), + /** Java 1.1 */ + JAVA_1_1(new Java1_1Validator(), null), + /** Java 1.2 */ + JAVA_1_2(new Java1_2Validator(), null), + /** Java 1.3 */ + JAVA_1_3(new Java1_3Validator(), null), + /** Java 1.4 */ + JAVA_1_4(new Java1_4Validator(), null), + /** Java 5 */ + JAVA_5(new Java5Validator(), null), + /** Java 6 */ + JAVA_6(new Java6Validator(), null), + /** Java 7 */ + JAVA_7(new Java7Validator(), null), + /** Java 8 */ + JAVA_8(new Java8Validator(), null), + /** Java 9 */ + JAVA_9(new Java9Validator(), null), + /** Java 10 */ + JAVA_10(new Java10Validator(), new Java10PostProcessor()), + /** Java 11 (work in progress) */ + JAVA_11_PREVIEW(new Java11Validator(), new Java11PostProcessor()); + + final Validator validator; + final ParseResult.PostProcessor postProcessor; + + LanguageLevel(Validator validator, ParseResult.PostProcessor postProcessor) { + this.validator = validator; + this.postProcessor = postProcessor; + } + } + + private boolean storeTokens = true; + private boolean attributeComments = true; + private boolean doNotAssignCommentsPrecedingEmptyLines = true; + private boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false; + private boolean lexicalPreservationEnabled = false; + private SymbolResolver symbolResolver = null; + private int tabSize = 1; + private LanguageLevel languageLevel = CURRENT; + + private final List postProcessors = new ArrayList<>(); + + public ParserConfiguration() { + postProcessors.add((result, configuration) -> { + if (configuration.isLexicalPreservationEnabled()) { + if (configuration.isLexicalPreservationEnabled()) { + result.ifSuccessful(LexicalPreservingPrinter::setup); + } + } + }); + postProcessors.add((result, configuration) -> { + if (configuration.isAttributeComments()) { + result.ifSuccessful(resultNode -> result + .getCommentsCollection().ifPresent(comments -> + new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); + } + }); + postProcessors.add((result, configuration) -> { + LanguageLevel languageLevel = getLanguageLevel(); + if (languageLevel.postProcessor != null) { + languageLevel.postProcessor.process(result, configuration); + } + if (languageLevel.validator != null) { + languageLevel.validator.accept(result.getResult().get(), new ProblemReporter(newProblem -> result.getProblems().add(newProblem))); + } + }); + postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver -> + result.ifSuccessful(resultNode -> { + if (resultNode instanceof CompilationUnit) { + resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); + } + }) + )); + } + + public boolean isAttributeComments() { + return attributeComments; + } + + /** + * Whether to run CommentsInserter, which will put the comments that were found in the source code into the comment + * and javadoc fields of the nodes it thinks they refer to. + */ + public ParserConfiguration setAttributeComments(boolean attributeComments) { + this.attributeComments = attributeComments; + return this; + } + + public boolean isDoNotAssignCommentsPrecedingEmptyLines() { + return doNotAssignCommentsPrecedingEmptyLines; + } + + public ParserConfiguration setDoNotAssignCommentsPrecedingEmptyLines(boolean doNotAssignCommentsPrecedingEmptyLines) { + this.doNotAssignCommentsPrecedingEmptyLines = doNotAssignCommentsPrecedingEmptyLines; + return this; + } + + public boolean isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() { + return doNotConsiderAnnotationsAsNodeStartForCodeAttribution; + } + + public ParserConfiguration setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution) { + this.doNotConsiderAnnotationsAsNodeStartForCodeAttribution = doNotConsiderAnnotationsAsNodeStartForCodeAttribution; + return this; + } + + public ParserConfiguration setStoreTokens(boolean storeTokens) { + this.storeTokens = storeTokens; + if (!storeTokens) { + setAttributeComments(false); + } + return this; + } + + public boolean isStoreTokens() { + return storeTokens; + } + + public int getTabSize() { + return tabSize; + } + + /** + * When a TAB character is encountered during parsing, the column position will be increased by this value. + * By default it is 1. + */ + public ParserConfiguration setTabSize(int tabSize) { + this.tabSize = tabSize; + return this; + } + + /** + * @deprecated use getLanguageLevel + */ + @Deprecated + public Optional getValidator() { + throw new IllegalStateException("method is deprecated"); + } + + /** + * @deprecated use setLanguageLevel, or getPostProcessors if you use a custom validator. + */ + @Deprecated + public ParserConfiguration setValidator(Validator validator) { + // This whole method is a backwards compatability hack. + if (validator instanceof Java10Validator) { + setLanguageLevel(JAVA_10); + } else if (validator instanceof Java9Validator) { + setLanguageLevel(JAVA_9); + } else if (validator instanceof Java8Validator) { + setLanguageLevel(JAVA_8); + } else if (validator instanceof Java7Validator) { + setLanguageLevel(JAVA_7); + } else if (validator instanceof Java6Validator) { + setLanguageLevel(JAVA_6); + } else if (validator instanceof Java5Validator) { + setLanguageLevel(JAVA_5); + } else if (validator instanceof Java1_4Validator) { + setLanguageLevel(JAVA_1_4); + } else if (validator instanceof Java1_3Validator) { + setLanguageLevel(JAVA_1_3); + } else if (validator instanceof Java1_2Validator) { + setLanguageLevel(JAVA_1_2); + } else if (validator instanceof Java1_1Validator) { + setLanguageLevel(JAVA_1_1); + } else if (validator instanceof Java1_0Validator) { + setLanguageLevel(JAVA_1_0); + } else if (validator instanceof NoProblemsValidator) { + setLanguageLevel(RAW); + } + return this; + } + + /** + * Disabled by default. + * When this is enabled, LexicalPreservingPrinter.print can be used to reproduce + * the original formatting of the file. + */ + public ParserConfiguration setLexicalPreservationEnabled(boolean lexicalPreservationEnabled) { + this.lexicalPreservationEnabled = lexicalPreservationEnabled; + return this; + } + + public boolean isLexicalPreservationEnabled() { + return lexicalPreservationEnabled; + } + + /** + * Retrieve the SymbolResolver to be used while parsing, if any. + */ + public Optional getSymbolResolver() { + return Optional.ofNullable(symbolResolver); + } + + /** + * Set the SymbolResolver to be injected while parsing. + */ + public ParserConfiguration setSymbolResolver(SymbolResolver symbolResolver) { + this.symbolResolver = symbolResolver; + return this; + } + + public List getPostProcessors() { + return postProcessors; + } + + public ParserConfiguration setLanguageLevel(LanguageLevel languageLevel) { + this.languageLevel = assertNotNull(languageLevel); + return this; + } + + public LanguageLevel getLanguageLevel() { + return languageLevel; + } +} diff --git a/JavaParser/src/com/github/javaparser/Position.java b/JavaParser/src/com/github/javaparser/Position.java index 0637661..78e95d8 100644 --- a/JavaParser/src/com/github/javaparser/Position.java +++ b/JavaParser/src/com/github/javaparser/Position.java @@ -1,52 +1,140 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser; - -import com.github.javaparser.ast.Node; - -public class Position { - private int line; - private 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); - - public static Position beginOf(Node node){ - return new Position(node.getBeginLine(),node.getBeginColumn()); - } - - public static Position endOf(Node node){ - return new Position(node.getEndLine(),node.getEndColumn()); - } - - public Position(int line, int column){ - this.line = line; - this.column = column; - } - - public int getLine(){ - return this.line; - } - - public int getColumn(){ - return this.column; - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +import com.github.javaparser.ast.Node; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * A position in a source file. Lines and columns start counting at 1. + */ +public class Position implements Comparable { + public final int line; + public final int column; + + /** + * The first position in the file + */ + public static final Position HOME = new Position(1, 1); + + 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) { + assertNotNull(anotherPosition); + if (valid() || anotherPosition.invalid()) { + return this; + } + return anotherPosition; + } + + public boolean isAfter(Position position) { + assertNotNull(position); + if (position.line == Node.ABSOLUTE_BEGIN_LINE) return true; + if (line > position.line) { + return true; + } else if (line == position.line) { + return column > position.column; + } + return false; + + } + + public boolean isBefore(Position position) { + assertNotNull(position); + if (position.line == Node.ABSOLUTE_END_LINE) return true; + if (line < position.line) { + return true; + } else if (line == position.line) { + return column < position.column; + } + return false; + } + + @Override + public int compareTo(Position o) { + assertNotNull(o); + if (isBefore(o)) { + return -1; + } + if (isAfter(o)) { + return 1; + } + return 0; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Position position = (Position) o; + + return line == position.line && column == position.column; + } + + @Override + public int hashCode() { + return 31 * line + column; + } + + @Override + public String toString() { + return "(line " + line + ",col " + column + ")"; + } +} diff --git a/JavaParser/src/com/github/javaparser/PositionUtils.java b/JavaParser/src/com/github/javaparser/PositionUtils.java deleted file mode 100644 index 47db3cb..0000000 --- a/JavaParser/src/com/github/javaparser/PositionUtils.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.AnnotableNode; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.expr.AnnotationExpr; - -import java.lang.Override; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - -import static java.lang.Integer.signum; - -public class PositionUtils { - - public static void sortByBeginPosition(List nodes){ - sortByBeginPosition(nodes, false); - } - - public static void sortByBeginPosition(List nodes, final boolean ignoringAnnotations){ - Collections.sort(nodes, new Comparator() { - @Override - public int compare(Node o1, Node o2) { - return PositionUtils.compare(o1, o2, ignoringAnnotations); - } - }); - } - - public static boolean areInOrder(Node a, Node b){ - return areInOrder(a, b, false); - } - - public static boolean areInOrder(Node a, Node b, boolean ignoringAnnotations){ - return compare(a, b, ignoringAnnotations) <= 0; - } - - private static int compare(Node a, Node b, boolean ignoringAnnotations) { - if (ignoringAnnotations) { - int signLine = signum(beginLineWithoutConsideringAnnotation(a) - beginLineWithoutConsideringAnnotation(b)); - if (signLine == 0) { - return signum(beginColumnWithoutConsideringAnnotation(a) - beginColumnWithoutConsideringAnnotation(b)); - } else { - return signLine; - } - } - - int signLine = signum( a.getBeginLine() - b.getBeginLine() ); - if (signLine == 0) { - return signum(a.getBeginColumn() - b.getBeginColumn()); - } else { - return signLine; - } - } - - public static AnnotationExpr getLastAnnotation(Node node) { - if (node instanceof AnnotableNode){ - List annotations = new LinkedList(); - annotations.addAll(((AnnotableNode) node).getAnnotations()); - if (annotations.size()==0){ - return null; - } - sortByBeginPosition(annotations); - return annotations.get(annotations.size()-1); - } else { - return null; - } - } - - private static int beginLineWithoutConsideringAnnotation(Node node) { - return beginNodeWithoutConsideringAnnotations(node).getBeginLine(); - } - - - private static int beginColumnWithoutConsideringAnnotation(Node node) { - return beginNodeWithoutConsideringAnnotations(node).getBeginColumn(); - } - - private static Node beginNodeWithoutConsideringAnnotations(Node node) { - if (node instanceof MethodDeclaration) { - MethodDeclaration casted = (MethodDeclaration) node; - return casted.getType(); - } else if (node instanceof FieldDeclaration) { - FieldDeclaration casted = (FieldDeclaration) node; - return casted.getType(); - } else if (node instanceof ClassOrInterfaceDeclaration) { - ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; - return casted.getNameExpr(); - } else { - return node; - } - } - - public static boolean nodeContains(Node container, Node contained, boolean ignoringAnnotations){ - if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container)==null){ - return container.contains(contained); - } - if (!container.contains(contained)){ - return false; - } - // if the node is contained, but it comes immediately after the annotations, - // let's not consider it contained - if (container instanceof AnnotableNode){ - int bl = beginLineWithoutConsideringAnnotation(container); - int bc = beginColumnWithoutConsideringAnnotation(container); - if (bl>contained.getBeginLine()) return false; - if (bl==contained.getBeginLine() && bc>contained.getBeginColumn()) return false; - if (container.getEndLine() l.getBegin().getRange().map(r -> r.begin.toString()).orElse("(line ?,col ?)") + " " + message).orElse(message); + } + + /** + * @return the location that was passed into the constructor. + */ + public Optional getLocation() { + return Optional.ofNullable(location); + } + + /** + * @deprecated use getLocation() + */ + @Deprecated + public Optional getRange() { + return getLocation(); + } + + /** + * @return the cause that was passed into the constructor. + */ + public Optional getCause() { + return Optional.ofNullable(cause); + } + + /** + * Sorts problems on position. + */ + public static Comparator PROBLEM_BY_BEGIN_POSITION = (a, b) -> { + final Optional aBegin= a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + final Optional bBegin = b.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + + if (aBegin.isPresent() && bBegin.isPresent()) { + return aBegin.get().compareTo(bBegin.get()); + } + if (a.getLocation().isPresent() || b.getLocation().isPresent()) { + if (a.getLocation().isPresent()) { + return 1; + } + return -1; + } + return 0; + }; + + +} diff --git a/JavaParser/src/com/github/javaparser/Provider.java b/JavaParser/src/com/github/javaparser/Provider.java new file mode 100644 index 0000000..6dcbfb3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/Provider.java @@ -0,0 +1,47 @@ +/* Generated By:JavaCC: Do not edit this line. Provider.java Version 7.0 */ +/* JavaCCOptions:KEEP_LINE_COLUMN=true */ +/* + * 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.IOException; + +public interface Provider { + /** + * Reads characters into an array + * @param buffer Destination buffer + * @param offset Offset at which to start storing characters + * @param length The maximum possible number of characters to read + * @return The number of characters read, or -1 if all read + * @exception IOException + */ + public int read(char buffer[], int offset, int len) throws IOException; + + /** + * Closes the stream and releases any system resources associated with + * it. + * @exception IOException + */ + public void close() throws IOException; + +} +/* JavaCC - OriginalChecksum=2a9bd492caf4b9d28bb7522391baadbc (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/Providers.java b/JavaParser/src/com/github/javaparser/Providers.java new file mode 100644 index 0000000..f4b3df9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/Providers.java @@ -0,0 +1,111 @@ +/* + * 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 java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Factory for providers of source code for JavaParser. Providers that have no parameter for encoding but need it will + * use UTF-8. + */ +public final class Providers { + public static final Charset UTF8 = Charset.forName("utf-8"); + + private Providers() { + } + + public static Provider provider(Reader reader) { + return new StreamProvider(assertNotNull(reader)); + } + + public static Provider provider(InputStream input, Charset encoding) { + assertNotNull(input); + assertNotNull(encoding); + try { + return new StreamProvider(input, encoding.name()); + } catch (IOException e) { + // The only one that is thrown is UnsupportedCharacterEncodingException, + // and that's a fundamental problem, so runtime exception. + throw new RuntimeException(e); + } + } + + public static Provider provider(InputStream input) { + return provider(input, UTF8); + } + + public static Provider provider(File file, Charset encoding) throws FileNotFoundException { + return provider(new FileInputStream(assertNotNull(file)), assertNotNull(encoding)); + } + + public static Provider provider(File file) throws FileNotFoundException { + return provider(assertNotNull(file), UTF8); + } + + public static Provider provider(Path path, Charset encoding) throws IOException { + return provider(Files.newInputStream(assertNotNull(path)), assertNotNull(encoding)); + } + + public static Provider provider(Path path) throws IOException { + return provider(assertNotNull(path), UTF8); + } + + public static Provider provider(String source) { + return new StringProvider(assertNotNull(source)); + } + + + /** + * Provide a Provider from the resource found in class loader with the provided encoding.
As resource is + * accessed through a class loader, a leading "/" is not allowed in pathToResource + */ + public static Provider resourceProvider(ClassLoader classLoader, String pathToResource, Charset encoding) throws IOException { + InputStream resourceAsStream = classLoader.getResourceAsStream(pathToResource); + if (resourceAsStream == null) { + throw new IOException("Cannot find " + pathToResource); + } + return provider(resourceAsStream, encoding); + } + + /** + * Provide a Provider from the resource found in the current class loader with the provided encoding.
As + * resource is accessed through a class loader, a leading "/" is not allowed in pathToResource + */ + public static Provider resourceProvider(String pathToResource, Charset encoding) throws IOException { + ClassLoader classLoader = Provider.class.getClassLoader(); + return resourceProvider(classLoader, pathToResource, encoding); + } + + /** + * Provide a Provider from the resource found in the current class loader with UTF-8 encoding.
As resource is + * accessed through a class loader, a leading "/" is not allowed in pathToResource + */ + public static Provider resourceProvider(String pathToResource) throws IOException { + return resourceProvider(pathToResource, UTF8); + } + +} diff --git a/JavaParser/src/com/github/javaparser/Range.java b/JavaParser/src/com/github/javaparser/Range.java new file mode 100644 index 0000000..dc5b329 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/Range.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser; + +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 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); + } + + /** + * As strictlyContains, but two exactly matching ranges are also considered contained one in each other. + */ + public boolean contains(Range other) { + return (begin.isBefore(other.begin) || begin.equals(other.begin)) && + (end.isAfter(other.end) || end.equals(other.end)); + } + + /** + * Do this strictly contains other? It means that this has to be larger than other and it has to start as other + * or before and end as other or after. + */ + public boolean strictlyContains(Range other) { + return begin.isBefore(other.begin) && end.isAfter(other.end); + } + + public boolean isBefore(Position position) { + return end.isBefore(position); + } + + public boolean isAfter(Position position) { + return begin.isAfter(position); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Range range = (Range) o; + + return begin.equals(range.begin) && end.equals(range.end); + + } + + @Override + public int hashCode() { + return 31 * begin.hashCode() + end.hashCode(); + } + + @Override + public String toString() { + return begin + "-" + end; + } +} diff --git a/JavaParser/src/com/github/javaparser/RangedList.java b/JavaParser/src/com/github/javaparser/RangedList.java new file mode 100644 index 0000000..328ec50 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/RangedList.java @@ -0,0 +1,33 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; + +/** + * Helper class for {@link GeneratedJavaParser} + */ +class RangedList { + /* A ranged list MUST be set to a begin and end, + or these temporary values will leak out */ + TokenRange range = new TokenRange(JavaToken.INVALID, JavaToken.INVALID); + NodeList list; + + RangedList(NodeList list) { + this.list = list; + } + + void beginAt(JavaToken begin) { + range = range.withBegin(begin); + } + + void endAt(JavaToken end) { + range = range.withEnd(end); + } + + void add(T t) { + if (list == null) { + list = new NodeList<>(); + } + list.add(t); + } +} diff --git a/JavaParser/src/com/github/javaparser/SimpleCharStream.java b/JavaParser/src/com/github/javaparser/SimpleCharStream.java new file mode 100644 index 0000000..8f2bd22 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/SimpleCharStream.java @@ -0,0 +1,419 @@ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 7.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/* + * 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; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public class SimpleCharStream +{ +/** Whether parser is static. */ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; +/** Position in buffer. */ + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected Provider inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 1; + protected boolean trackLineColumn = true; + + public void setTabSize(int i) { tabSize = i; } + public int getTabSize() { return tabSize; } + + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new RuntimeException(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + +/** Start. */ + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + @Deprecated + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + /** Get token end column number. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get token end line number. */ + public int getEndLine() { + return bufline[bufpos]; + } + + /** Get token beginning column number. */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** Get token beginning line number. */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Backup a number of characters. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + public SimpleCharStream(Provider dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + /** Constructor. */ + public SimpleCharStream(Provider dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(Provider dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(Provider dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + /** Reinitialise. */ + public void ReInit(Provider dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(Provider dstream) + { + ReInit(dstream, 1, 1, 4096); + } + + + /** Get token literal value. */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** Get the suffix. */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Reset buffer when finished. */ + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + boolean getTrackLineColumn() { return trackLineColumn; } + void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; } +} +/* JavaCC - OriginalChecksum=426048510a1ecd9a28c73d4def7423eb (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/SourcesHelper.java b/JavaParser/src/com/github/javaparser/SourcesHelper.java deleted file mode 100644 index c106b4f..0000000 --- a/JavaParser/src/com/github/javaparser/SourcesHelper.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser; - -import java.io.*; - -public class SourcesHelper { - - static String streamToString(InputStream in, String encoding){ - if (encoding == null) { - return streamToString(in); - } else { - java.util.Scanner s = new java.util.Scanner(in, encoding).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } - } - - static String streamToString(InputStream in){ - java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } - - static InputStream stringToStream(String s, String encoding) throws UnsupportedEncodingException { - byte[] rawData = encoding != null ? s.getBytes(encoding) : s.getBytes(); - return new ByteArrayInputStream(rawData); - } - - static String readerToString(Reader reader) throws IOException { - char[] arr = new char[8*1024]; // 8K at a time - StringBuilder buf = new StringBuilder(); - int numChars; - - while ((numChars = reader.read(arr, 0, arr.length)) > 0) { - buf.append(arr, 0, numChars); - } - - return buf.toString(); - } - - static Reader stringToReader(String s){ - return new StringReader(s); - } - -} diff --git a/JavaParser/src/com/github/javaparser/StreamProvider.java b/JavaParser/src/com/github/javaparser/StreamProvider.java new file mode 100644 index 0000000..b3b3416 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/StreamProvider.java @@ -0,0 +1,78 @@ +/* Generated By:JavaCC: Do not edit this line. StreamProvider.java Version 7.0 */ +/* JavaCCOptions:KEEP_LINE_COLUMN=true */ +/* + * 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.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +/** + * NOTE : This generated class can be safely deleted if installing in a GWT installation (use StringProvider instead) + */ +public class StreamProvider implements Provider { + + Reader _reader; + + public StreamProvider(Reader reader) { + _reader = reader; + } + + public StreamProvider(InputStream stream) throws IOException { + _reader = new BufferedReader(new InputStreamReader(stream)); + } + + public StreamProvider(InputStream stream, String charsetName) throws IOException { + _reader = new BufferedReader(new InputStreamReader(stream, charsetName)); + } + + @Override + public int read(char[] buffer, int off, int len) throws IOException { + int result = _reader.read(buffer, off, len); + + /* CBA -- Added 2014/03/29 -- + This logic allows the generated Java code to be easily translated to C# (via sharpen) - + as in C# 0 represents end of file, and in Java, -1 represents end of file + See : http://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx + ** Technically, this is not required for java but the overhead is extremely low compared to the code generation benefits. + */ + + if (result == 0) { + if (off < buffer.length && len > 0) { + result = -1; + } + } + + return result; + } + + @Override + public void close() throws IOException { + _reader.close(); + } + +} + +/* JavaCC - OriginalChecksum=bc0ddea608a1ea01a8e32fee4c628d00 (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/StringProvider.java b/JavaParser/src/com/github/javaparser/StringProvider.java new file mode 100644 index 0000000..14c7d6d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/StringProvider.java @@ -0,0 +1,68 @@ +/* Generated By:JavaCC: Do not edit this line. StringProvider.java Version 7.0 */ +/* JavaCCOptions:KEEP_LINE_COLUMN=true */ +/* + * 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.IOException; + + public class StringProvider implements Provider { + + String _string; + int _position = 0; + int _size; + + public StringProvider(String string) { + _string = string; + _size = string.length(); + } + + @Override + public int read(char[] cbuf, int off, int len) throws IOException { + int numCharsOutstandingInString = _size - _position; + + if (numCharsOutstandingInString == 0) { + return -1; + } + + int numBytesInBuffer = cbuf.length; + int numBytesToRead = numBytesInBuffer -off; + numBytesToRead = numBytesToRead > len ? len : numBytesToRead; + + if (numBytesToRead > numCharsOutstandingInString) { + numBytesToRead = numCharsOutstandingInString; + } + + _string.getChars(_position, _position + numBytesToRead, cbuf, off); + + _position += numBytesToRead; + + return numBytesToRead; + } + + @Override + public void close() throws IOException { + _string = null; + } + + } +/* JavaCC - OriginalChecksum=38052dc5b81585946987664a01065e9e (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/Token.java b/JavaParser/src/com/github/javaparser/Token.java index de6d476..b8764d4 100644 --- a/JavaParser/src/com/github/javaparser/Token.java +++ b/JavaParser/src/com/github/javaparser/Token.java @@ -1,143 +1,152 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ -/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - -/** - * Describes the input token stream. - */ - -public class Token implements java.io.Serializable { - - /** - * The version identifier for this Serializable class. - * Increment only if the serialized form of the - * class changes. - */ - private static final long serialVersionUID = 1L; - - /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; - - /** The line number of the first character of this Token. */ - public int beginLine; - /** The column number of the first character of this Token. */ - public int beginColumn; - /** The line number of the last character of this Token. */ - public int endLine; - /** The column number of the last character of this Token. */ - public int endColumn; - - /** - * The string image of the token. - */ - public String image; - - /** - * A reference to the next regular (non-special) token from the input - * stream. If this is the last token from the input stream, or if the - * token manager has not read tokens beyond this one, this field is - * set to null. This is true only if this token is also a regular - * token. Otherwise, see below for a description of the contents of - * this field. - */ - public Token next; - - /** - * This field is used to access special tokens that occur prior to this - * token, but after the immediately preceding regular (non-special) token. - * If there are no such special tokens, this field is set to null. - * When there are more than one such special token, this field refers - * to the last of these special tokens, which in turn refers to the next - * previous special token through its specialToken field, and so on - * until the first special token (whose specialToken field is null). - * The next fields of special tokens refer to other special tokens that - * immediately follow it (without an intervening regular token). If there - * is no such token, this field is null. - */ - public Token specialToken; - - /** - * An optional attribute value of the Token. - * Tokens which are not used as syntactic sugar will often contain - * meaningful values that will be used later on by the compiler or - * interpreter. This attribute value is often different from the image. - * Any subclass of Token that actually wants to return a non-null value can - * override this method as appropriate. - */ - public Object getValue() { - return null; - } - - /** - * No-argument constructor - */ - public Token() {} - - /** - * Constructs a new token for the specified Image. - */ - public Token(int kind) - { - this(kind, null); - } - - /** - * Constructs a new token for the specified Image and Kind. - */ - public Token(int kind, String image) - { - this.kind = kind; - this.image = image; - } - - /** - * Returns the image. - */ - public String toString() - { - return image; - } - - /** - * Returns a new Token object, by default. However, if you want, you - * can create and return subclass objects based on the value of ofKind. - * Simply add the cases to the switch for all those special cases. - * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simply add something like : - * - * case MyParserConstants.ID : return new IDToken(ofKind, image); - * - * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use sit in your lexical actions. - */ - public static Token newToken(int ofKind, String image) - { - switch(ofKind) - { - default : return new Token(ofKind, image); - } - } - - public static Token newToken(int ofKind) - { - return newToken(ofKind, null); - } - -} -/* JavaCC - OriginalChecksum=94d97e8f7f7c1e886e63e0e426e23c5c (do not edit this line) */ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 7.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=TokenBase,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/* + * 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; + +/** + * Describes the input token stream. + */ + +public class Token extends TokenBase implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=4dee3ecb0b873195e388b52791f0170e (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/TokenBase.java b/JavaParser/src/com/github/javaparser/TokenBase.java new file mode 100644 index 0000000..c52663c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/TokenBase.java @@ -0,0 +1,18 @@ +package com.github.javaparser; + +import static com.github.javaparser.GeneratedJavaParserConstants.GT; + +/** + * Base class for the generated {@link Token} + */ +abstract class TokenBase { + /** + * For tracking the >> >>> ambiguity. + */ + int realKind = GT; + + /** + * This is the link to the token that JavaParser presents to the user + */ + JavaToken javaToken = null; +} diff --git a/JavaParser/src/com/github/javaparser/TokenMgrError.java b/JavaParser/src/com/github/javaparser/TokenMgrException.java similarity index 67% rename from JavaParser/src/com/github/javaparser/TokenMgrError.java rename to JavaParser/src/com/github/javaparser/TokenMgrException.java index 5cfc0e4..a34079b 100644 --- a/JavaParser/src/com/github/javaparser/TokenMgrError.java +++ b/JavaParser/src/com/github/javaparser/TokenMgrException.java @@ -1,159 +1,167 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ -/* JavaCCOptions: */ -/* - * - * This file is part of Java 1.8 parser and Abstract Syntax Tree. - * - * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java 1.8 parser and Abstract Syntax Tree. If not, see . - */ -package com.github.javaparser; - -/** Token Manager Error. */ -public class TokenMgrError extends Error -{ - - /** - * The version identifier for this Serializable class. - * Increment only if the serialized form of the - * class changes. - */ - private static final long serialVersionUID = 1L; - - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occurred. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt was made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * Replaces unprintable characters by their escaped (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexical error - * curLexState : lexical state in which this error occurred - * errorLine : line number when the error occurred - * errorColumn : column number when the error occurred - * errorAfter : prefix that was seen before this error occurred - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - /** No arg constructor. */ - public TokenMgrError() { - } - - /** Constructor with message and reason. */ - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - /** Full Constructor. */ - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} -/* JavaCC - OriginalChecksum=5e7ab877e2fba6070ac338db7fdc70d3 (do not edit this line) */ +/* Generated By:JavaCC: Do not edit this line. TokenMgrException.java Version 7.0 */ +/* JavaCCOptions: */ +/* + * 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; + +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=a12f92ff78a572ce135bdb1f55ed69c1 (do not edit this line) */ diff --git a/JavaParser/src/com/github/javaparser/TokenRange.java b/JavaParser/src/com/github/javaparser/TokenRange.java new file mode 100644 index 0000000..c0cb038 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/TokenRange.java @@ -0,0 +1,82 @@ +package com.github.javaparser; + +import java.util.Iterator; +import java.util.Optional; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * The range of tokens covered by this node. + */ +public class TokenRange implements Iterable { + public static final TokenRange INVALID = new TokenRange(JavaToken.INVALID, JavaToken.INVALID); + + private final JavaToken begin; + private final JavaToken end; + + public TokenRange(JavaToken begin, JavaToken end) { + this.begin = assertNotNull(begin); + this.end = assertNotNull(end); + } + + public JavaToken getBegin() { + return begin; + } + + public JavaToken getEnd() { + return end; + } + + public Optional toRange() { + if (begin.getRange().isPresent() && end.getRange().isPresent()) { + return Optional.of(new Range(begin.getRange().get().begin, end.getRange().get().end)); + } + return Optional.empty(); + } + + public TokenRange withBegin(JavaToken begin) { + return new TokenRange(assertNotNull(begin), end); + } + + public TokenRange withEnd(JavaToken end) { + return new TokenRange(begin, assertNotNull(end)); + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + for(JavaToken t: this) { + result.append(t.getText()); + } + return result.toString(); + } + + @Override + public Iterator iterator() { + return new Iterator() { + private boolean hasNext = true; + private JavaToken current = begin; + + @Override + public boolean hasNext() { + return hasNext; + } + + @Override + public JavaToken next() { + JavaToken retval = current; + if(current == null){ + throw new IllegalStateException("Attempting to move past end of range."); + } + if (current == end) { + hasNext = false; + } + current = current.getNextToken().orElse(null); + if(current == null && hasNext){ + throw new IllegalStateException("End token is not linked to begin token."); + } + return retval; + } + }; + } +} diff --git a/JavaParser/src/com/github/javaparser/TokenTypes.java b/JavaParser/src/com/github/javaparser/TokenTypes.java new file mode 100644 index 0000000..8b90aa7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/TokenTypes.java @@ -0,0 +1,239 @@ +package com.github.javaparser; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.utils.Utils.EOL; + +/** + * Complements GeneratedJavaParserConstants + */ +public class TokenTypes { + public static boolean isWhitespace(int kind) { + return getCategory(kind).isWhitespace(); + } + + /** + * @deprecated use isEndOfLineToken + */ + @Deprecated + public static boolean isEndOfLineCharacter(int kind) { + return isEndOfLineToken(kind); + } + + public static boolean isEndOfLineToken(int kind) { + return getCategory(kind).isEndOfLine(); + } + + public static boolean isWhitespaceOrComment(int kind) { + return getCategory(kind).isWhitespaceOrComment(); + } + + public static boolean isSpaceOrTab(int kind) { + return getCategory(kind).isWhitespaceButNotEndOfLine(); + } + + public static boolean isComment(int kind) { + return getCategory(kind).isComment(); + } + + /** + * @deprecated use eolTokenKind + */ + @Deprecated + public static int eolToken() { + return eolTokenKind(); + } + + /** + * @return the kind of EOL token to use on the platform you're running on. + */ + public static int eolTokenKind() { + if (EOL.equals("\n")) { + return UNIX_EOL; + } + if (EOL.equals("\r\n")) { + return WINDOWS_EOL; + } + if (EOL.equals("\r")) { + return OLD_MAC_EOL; + } + throw new AssertionError("Unknown EOL character sequence"); + } + + /** + * @return the token kind for a single space. + */ + public static int spaceTokenKind() { + return SPACE; + } + + /** + * @deprecated use spaceTokenKind + */ + @Deprecated + public static int spaceToken() { + return spaceTokenKind(); + } + + /** + * Category of a token, a little more detailed than + * The JLS. + */ + public static JavaToken.Category getCategory(int kind) { + switch (kind) { + case WINDOWS_EOL: + case UNIX_EOL: + case OLD_MAC_EOL: + return JavaToken.Category.EOL; + case EOF: + case SPACE: + case CTRL_Z: + return JavaToken.Category.WHITESPACE_NO_EOL; + case SINGLE_LINE_COMMENT: + case JAVADOC_COMMENT: + case MULTI_LINE_COMMENT: + return JavaToken.Category.COMMENT; + case ABSTRACT: + case ASSERT: + case BOOLEAN: + case BREAK: + case BYTE: + case CASE: + case CATCH: + case CHAR: + case CLASS: + case CONST: + case CONTINUE: + case _DEFAULT: + case DO: + case DOUBLE: + case ELSE: + case ENUM: + case EXTENDS: + case FALSE: + case FINAL: + case FINALLY: + case FLOAT: + case FOR: + case GOTO: + case IF: + case IMPLEMENTS: + case IMPORT: + case INSTANCEOF: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case NEW: + case NULL: + case PACKAGE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case RETURN: + case SHORT: + case STATIC: + case STRICTFP: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case THROWS: + case TRANSIENT: + case TRUE: + case TRY: + case VOID: + case VOLATILE: + case WHILE: + case REQUIRES: + case TO: + case WITH: + case OPEN: + case OPENS: + case USES: + case MODULE: + case EXPORTS: + case PROVIDES: + case TRANSITIVE: + return JavaToken.Category.KEYWORD; + case LONG_LITERAL: + case INTEGER_LITERAL: + case DECIMAL_LITERAL: + case HEX_LITERAL: + case OCTAL_LITERAL: + case BINARY_LITERAL: + case FLOATING_POINT_LITERAL: + case DECIMAL_FLOATING_POINT_LITERAL: + case DECIMAL_EXPONENT: + case HEXADECIMAL_FLOATING_POINT_LITERAL: + case HEXADECIMAL_EXPONENT: + case CHARACTER_LITERAL: + case STRING_LITERAL: + return JavaToken.Category.LITERAL; + case IDENTIFIER: + return JavaToken.Category.IDENTIFIER; + case LPAREN: + case RPAREN: + case LBRACE: + case RBRACE: + case LBRACKET: + case RBRACKET: + case SEMICOLON: + case COMMA: + case DOT: + case AT: + return JavaToken.Category.SEPARATOR; + case ASSIGN: + case LT: + case BANG: + case TILDE: + case HOOK: + case COLON: + case EQ: + case LE: + case GE: + case NE: + case SC_OR: + case SC_AND: + case INCR: + case DECR: + case PLUS: + case MINUS: + case STAR: + case SLASH: + case BIT_AND: + case BIT_OR: + case XOR: + case REM: + case LSHIFT: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case LSHIFTASSIGN: + case RSIGNEDSHIFTASSIGN: + case RUNSIGNEDSHIFTASSIGN: + case ELLIPSIS: + case ARROW: + case DOUBLECOLON: + case RUNSIGNEDSHIFT: + case RSIGNEDSHIFT: + case GT: + return JavaToken.Category.OPERATOR; + // The following are tokens that are only used internally by the lexer + case ENTER_JAVADOC_COMMENT: + case ENTER_MULTILINE_COMMENT: + case COMMENT_CONTENT: + case HEX_DIGITS: + case LETTER: + case UNICODE_ESCAPE: + case PART_LETTER: + default: + throw new AssertionError("Invalid token kind " + kind); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/AccessSpecifier.java b/JavaParser/src/com/github/javaparser/ast/AccessSpecifier.java index 963c74a..63e96b8 100644 --- a/JavaParser/src/com/github/javaparser/ast/AccessSpecifier.java +++ b/JavaParser/src/com/github/javaparser/ast/AccessSpecifier.java @@ -1,46 +1,47 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -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; - - private AccessSpecifier(String codeRepresentation) { - this.codeRepresenation = codeRepresentation; - } - - public String getCodeRepresenation(){ - return this.codeRepresenation; - } -} +/* + * 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 asString() { + return this.codeRepresenation; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/AllFieldsConstructor.java b/JavaParser/src/com/github/javaparser/ast/AllFieldsConstructor.java new file mode 100644 index 0000000..33d58e4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/AllFieldsConstructor.java @@ -0,0 +1,14 @@ +package com.github.javaparser.ast; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Tells tools that this is the constructor which directly initializes all fields (except "range" and "comment") + */ +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +public @interface AllFieldsConstructor { +} diff --git a/JavaParser/src/com/github/javaparser/ast/ArrayCreationLevel.java b/JavaParser/src/com/github/javaparser/ast/ArrayCreationLevel.java new file mode 100644 index 0000000..09148fe --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/ArrayCreationLevel.java @@ -0,0 +1,193 @@ +/* + * 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.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ArrayCreationLevelMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; + +/** + * In new int[1][2]; there are two ArrayCreationLevel objects, + * the first one contains the expression "1", + * the second the expression "2". + */ +public final class ArrayCreationLevel extends Node implements NodeWithAnnotations { + + @OptionalProperty + private Expression dimension; + + private NodeList annotations = new NodeList<>(); + + public ArrayCreationLevel() { + this(null, null, new NodeList<>()); + } + + public ArrayCreationLevel(int dimension) { + this(null, new IntegerLiteralExpr("" + dimension), new NodeList<>()); + } + + public ArrayCreationLevel(Expression dimension) { + this(null, dimension, new NodeList<>()); + } + + @AllFieldsConstructor + public ArrayCreationLevel(Expression dimension, NodeList annotations) { + this(null, dimension, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ArrayCreationLevel(TokenRange tokenRange, Expression dimension, NodeList annotations) { + super(tokenRange); + setDimension(dimension); + setAnnotations(annotations); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Sets the dimension + * + * @param dimension the dimension, can be null + * @return this, the ArrayCreationLevel + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationLevel setDimension(final Expression dimension) { + if (dimension == this.dimension) { + return (ArrayCreationLevel) this; + } + notifyPropertyChange(ObservableProperty.DIMENSION, this.dimension, dimension); + if (this.dimension != null) + this.dimension.setParentNode(null); + this.dimension = dimension; + setAsParentNodeOf(dimension); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getDimension() { + return Optional.ofNullable(dimension); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationLevel setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (ArrayCreationLevel) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ArrayCreationLevel removeDimension() { + return setDimension((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + if (dimension != null) { + if (node == dimension) { + removeDimension(); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ArrayCreationLevel clone() { + return (ArrayCreationLevel) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ArrayCreationLevelMetaModel getMetaModel() { + return JavaParserMetaModel.arrayCreationLevelMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + if (dimension != null) { + if (node == dimension) { + setDimension((Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/CompilationUnit.java b/JavaParser/src/com/github/javaparser/ast/CompilationUnit.java index b547dc2..fd8bb20 100644 --- a/JavaParser/src/com/github/javaparser/ast/CompilationUnit.java +++ b/JavaParser/src/com/github/javaparser/ast/CompilationUnit.java @@ -1,179 +1,694 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -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.comments.Comment; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - *

- * This class represents the entire compilation unit. Each java file denotes a - * compilation unit. - *

- * The CompilationUnit is constructed following the syntax:
- *
- * {@code
- * CompilationUnit ::=  ( }{@link PackageDeclaration}{@code )?
- *                      ( }{@link ImportDeclaration}{@code )*
- *                      ( }{@link TypeDeclaration}{@code )*
- * }
- * 
- * @author Julio Vilmar Gesser - */ -public final class CompilationUnit extends Node { - - private PackageDeclaration pakage; - - private List imports; - - private List types; - - public CompilationUnit() { - } - - public CompilationUnit(PackageDeclaration pakage, List imports, List types) { - setPackage(pakage); - setImports(imports); - setTypes(types); - } - - public CompilationUnit(int beginLine, int beginColumn, int endLine, int endColumn, PackageDeclaration pakage, List imports, List types) { - super(beginLine, beginColumn, endLine, endColumn); - setPackage(pakage); - setImports(imports); - setTypes(types); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public
void accept(VoidVisitor 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.
- * If there is no comment, null is returned. - * - * @return list with all comments of this compilation unit or - * null - * @see JavadocComment - * @see com.github.javaparser.ast.comments.LineComment - * @see com.github.javaparser.ast.comments.BlockComment - */ - public List getComments() { - return this.getAllContainedComments(); - } - - /** - * Retrieves the list of imports declared in this compilation unit or - * null if there is no import. - * - * @return the list of imports or null if there is no import - */ - public List getImports() { - return imports; - } - - /** - * Retrieves the package declaration of this compilation unit.
- * If this compilation unit has no package declaration (default package), - * null is returned. - * - * @return the package declaration or null - */ - public PackageDeclaration getPackage() { - return pakage; - } - - /** - * Return the list of types declared in this compilation unit.
- * If there is no types declared, null is returned. - * - * @return the list of types or null null if there is no type - * @see AnnotationDeclaration - * @see ClassOrInterfaceDeclaration - * @see EmptyTypeDeclaration - * @see EnumDeclaration - */ - public List getTypes() { - return types; - } - - /** - * Sets the list of comments of this compilation unit. - * - * @param comments - * the list of comments - */ - public void setComments(List comments) { - throw new RuntimeException("Not implemented!"); - } - - /** - * Sets the list of imports of this compilation unit. The list is initially - * null. - * - * @param imports - * the list of imports - */ - public void setImports(List 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 null 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 types) { - this.types = types; - setAsParentNodeOf(this.types); - } -} +/* + * 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.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParseStart; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.CompilationUnitMetaModel; +import com.github.javaparser.metamodel.InternalProperty; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.printer.PrettyPrinter; +import com.github.javaparser.utils.ClassUtils; +import com.github.javaparser.utils.CodeGenerationUtils; +import com.github.javaparser.utils.Utils; +import javax.annotation.Generated; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import static com.github.javaparser.JavaParser.parseName; +import static com.github.javaparser.Providers.UTF8; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.CodeGenerationUtils.subtractPaths; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; + +/** + *

+ * This class represents the entire compilation unit. Each java file denotes a + * compilation unit. + *

+ * A compilation unit start with an optional package declaration, + * followed by zero or more import declarations, + * followed by zero or more type declarations. + * + * @author Julio Vilmar Gesser + * @see PackageDeclaration + * @see ImportDeclaration + * @see TypeDeclaration + * @see Storage + */ +public final class CompilationUnit extends Node { + + @OptionalProperty + private PackageDeclaration packageDeclaration; + + private NodeList imports; + + private NodeList> types; + + @OptionalProperty + private ModuleDeclaration module; + + @InternalProperty + private Storage storage; + + public CompilationUnit() { + this(null, null, new NodeList<>(), new NodeList<>(), null); + } + + public CompilationUnit(String packageDeclaration) { + this(null, new PackageDeclaration(new Name(packageDeclaration)), new NodeList<>(), new NodeList<>(), null); + } + + @AllFieldsConstructor + public CompilationUnit(PackageDeclaration packageDeclaration, NodeList imports, NodeList> types, ModuleDeclaration module) { + this(null, packageDeclaration, imports, types, module); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public CompilationUnit(TokenRange tokenRange, PackageDeclaration packageDeclaration, NodeList imports, NodeList> types, ModuleDeclaration module) { + super(tokenRange); + setPackageDeclaration(packageDeclaration); + setImports(imports); + setTypes(types); + setModule(module); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final 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.
+ * If there is no comment, an empty list is returned. + * + * @return list with all comments of this compilation unit. + * @see JavadocComment + * @see com.github.javaparser.ast.comments.LineComment + * @see com.github.javaparser.ast.comments.BlockComment + */ + public List getComments() { + return this.getAllContainedComments(); + } + + /** + * Retrieves the list of imports declared in this compilation unit or + * null if there is no import. + * + * @return the list of imports or none if there is no import + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getImports() { + return imports; + } + + public ImportDeclaration getImport(int i) { + return getImports().get(i); + } + + /** + * Retrieves the package declaration of this compilation unit.
+ * If this compilation unit has no package declaration (default package), + * Optional.none() is returned. + * + * @return the package declaration or none + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getPackageDeclaration() { + return Optional.ofNullable(packageDeclaration); + } + + /** + * Return the list of top level types declared in this compilation unit.
+ * If there are no types declared, none is returned. + * + * @return the list of types or none null if there is no type + * @see AnnotationDeclaration + * @see ClassOrInterfaceDeclaration + * @see EnumDeclaration + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList> getTypes() { + return types; + } + + /** + * Convenience method that wraps getTypes().
+ * If i is out of bounds, throws IndexOutOfBoundsException. + * + * @param i the index of the type declaration to retrieve + */ + public TypeDeclaration getType(int i) { + return getTypes().get(i); + } + + /** + * Sets the list of imports of this compilation unit. The list is initially + * null. + * + * @param imports the list of imports + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CompilationUnit setImports(final NodeList imports) { + assertNotNull(imports); + if (imports == this.imports) { + return (CompilationUnit) this; + } + notifyPropertyChange(ObservableProperty.IMPORTS, this.imports, imports); + if (this.imports != null) + this.imports.setParentNode(null); + this.imports = imports; + setAsParentNodeOf(imports); + return this; + } + + public CompilationUnit setImport(int i, ImportDeclaration imports) { + getImports().set(i, imports); + return this; + } + + public CompilationUnit addImport(ImportDeclaration imports) { + getImports().add(imports); + return this; + } + + /** + * Sets or clear the package declarations of this compilation unit. + * + * @param packageDeclaration the packageDeclaration declaration to set or null to default package + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CompilationUnit setPackageDeclaration(final PackageDeclaration packageDeclaration) { + if (packageDeclaration == this.packageDeclaration) { + return (CompilationUnit) this; + } + notifyPropertyChange(ObservableProperty.PACKAGE_DECLARATION, this.packageDeclaration, packageDeclaration); + if (this.packageDeclaration != null) + this.packageDeclaration.setParentNode(null); + this.packageDeclaration = packageDeclaration; + setAsParentNodeOf(packageDeclaration); + return this; + } + + /** + * Sets the list of types declared in this compilation unit. + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CompilationUnit setTypes(final NodeList> types) { + assertNotNull(types); + if (types == this.types) { + return (CompilationUnit) this; + } + notifyPropertyChange(ObservableProperty.TYPES, this.types, types); + if (this.types != null) + this.types.setParentNode(null); + this.types = types; + setAsParentNodeOf(types); + return this; + } + + public CompilationUnit setType(int i, TypeDeclaration type) { + NodeList> copy = new NodeList<>(); + copy.addAll(getTypes()); + getTypes().set(i, type); + notifyPropertyChange(ObservableProperty.TYPES, copy, types); + return this; + } + + public CompilationUnit addType(TypeDeclaration type) { + NodeList> copy = new NodeList<>(); + copy.addAll(getTypes()); + getTypes().add(type); + notifyPropertyChange(ObservableProperty.TYPES, copy, types); + return this; + } + + /** + * sets the package declaration of this compilation unit + * + * @param name the name of the package + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit setPackageDeclaration(String name) { + setPackageDeclaration(new PackageDeclaration(parseName(name))); + return this; + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit
+ * 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
+ * shorthand for {@link #addImport(String)} with clazz.getName() + * + * @param clazz the class to import + * @return this, the {@link CompilationUnit} + * @throws RuntimeException if clazz is an anonymous or local class + */ + public CompilationUnit addImport(Class clazz) { + if (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.getName().startsWith("java.lang")) + return this; + else if (clazz.isMemberClass()) + return addImport(clazz.getName().replace("$", ".")); + else if (clazz.isArray() && !ClassUtils.isPrimitiveOrWrapper(clazz.getComponentType()) && !clazz.getComponentType().getName().startsWith("java.lang")) + return addImport(clazz.getComponentType().getName()); + else if (clazz.isAnonymousClass() || clazz.isLocalClass()) + throw new RuntimeException(clazz.getName() + " is an anonymous or local class therefore it can't be added with addImport"); + return addImport(clazz.getName()); + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit
+ * This method check if no import with the same name is already in the list + * + * @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) { + final StringBuilder i = new StringBuilder("import "); + if (isStatic) { + i.append("static "); + } + i.append(name); + if (isAsterisk) { + i.append(".*"); + } + i.append(";"); + ImportDeclaration importDeclaration = JavaParser.parseImport(i.toString()); + if (getImports().stream().anyMatch(im -> im.toString().equals(importDeclaration.toString()))) + return this; + else { + getImports().add(importDeclaration); + 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); + 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); + 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); + 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); + return annotationDeclaration; + } + + /** + * Try to get a top level class declaration by its name + * + * @param className the class name (case-sensitive) + */ + public Optional getClassByName(String className) { + return getTypes().stream().filter(type -> type.getNameAsString().equals(className) && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); + } + + /** + * Try to get a top level interface declaration by its name + * + * @param interfaceName the interface name (case-sensitive) + */ + public Optional getInterfaceByName(String interfaceName) { + return getTypes().stream().filter(type -> type.getNameAsString().equals(interfaceName) && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); + } + + /** + * Try to get a top level enum declaration by its name + * + * @param enumName the enum name (case-sensitive) + */ + public Optional getEnumByName(String enumName) { + return getTypes().stream().filter(type -> type.getNameAsString().equals(enumName) && type instanceof EnumDeclaration).findFirst().map(t -> (EnumDeclaration) t); + } + + /** + * @return the name that the primary type in this file should have, according to the filename in {@link Storage#getFileName()}. + * Empty if no file information is present (when this compilation unit wasn't parsed from a file.) + */ + public Optional getPrimaryTypeName() { + return getStorage().map(Storage::getFileName).map(Utils::removeFileExtension); + } + + /** + * @return the type whose name corresponds to the file name. + * Empty if no file information is present (when this compilation unit wasn't parsed from a file.) + * If for some strange reason there are multiple types of this name, the first one is returned. + */ + public Optional> getPrimaryType() { + return getPrimaryTypeName().flatMap(name -> getTypes().stream().filter(t -> t.getNameAsString().equals(name)).findFirst()); + } + + /** + * Try to get a top level annotation type declaration by its name + * + * @param annotationName the annotation name (case-sensitive) + */ + public Optional getAnnotationDeclarationByName(String annotationName) { + return getTypes().stream().filter(type -> type.getNameAsString().equals(annotationName) && type instanceof AnnotationDeclaration).findFirst().map(t -> (AnnotationDeclaration) t); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < imports.size(); i++) { + if (imports.get(i) == node) { + imports.remove(i); + return true; + } + } + if (module != null) { + if (node == module) { + removeModule(); + return true; + } + } + if (packageDeclaration != null) { + if (node == packageDeclaration) { + removePackageDeclaration(); + return true; + } + } + for (int i = 0; i < types.size(); i++) { + if (types.get(i) == node) { + types.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public CompilationUnit removePackageDeclaration() { + return setPackageDeclaration((PackageDeclaration) null); + } + + /** + * @return the module declared in this compilation unit. + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getModule() { + return Optional.ofNullable(module); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CompilationUnit setModule(final ModuleDeclaration module) { + if (module == this.module) { + return (CompilationUnit) this; + } + notifyPropertyChange(ObservableProperty.MODULE, this.module, module); + if (this.module != null) + this.module.setParentNode(null); + this.module = module; + setAsParentNodeOf(module); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public CompilationUnit removeModule() { + return setModule((ModuleDeclaration) null); + } + + /** + * @return information about where this compilation unit was loaded from, or empty if it wasn't loaded from a file. + */ + public Optional getStorage() { + return Optional.ofNullable(storage); + } + + public CompilationUnit setStorage(Path path) { + this.storage = new Storage(this, path); + return this; + } + + /** + * Information about where this compilation unit was loaded from. + * This class only stores the absolute location. + * For more flexibility use SourceRoot. + */ + public static class Storage { + + private final CompilationUnit compilationUnit; + + private final Path path; + + private Storage(CompilationUnit compilationUnit, Path path) { + this.compilationUnit = compilationUnit; + this.path = path.toAbsolutePath(); + } + + /** + * @return the path to the source for this CompilationUnit + */ + public Path getPath() { + return path; + } + + /** + * @return the CompilationUnit this Storage is about. + */ + public CompilationUnit getCompilationUnit() { + return compilationUnit; + } + + /** + * @return the source root directory, calculated from the path of this compiation unit, and the package + * declaration of this compilation unit. If the package declaration is invalid (when it does not match the end + * of the path) a RuntimeException is thrown. + */ + public Path getSourceRoot() { + final Optional pkgAsString = compilationUnit.getPackageDeclaration().map(NodeWithName::getNameAsString); + return pkgAsString.map(p -> Paths.get(CodeGenerationUtils.packageToPath(p))).map(pkg -> subtractPaths(getDirectory(), pkg)).orElse(getDirectory()); + } + + public String getFileName() { + return path.getFileName().toString(); + } + + public Path getDirectory() { + return path.getParent(); + } + + /** + * Saves the compilation unit to its original location + */ + public void save() { + save(cu -> new PrettyPrinter().print(cu)); + } + + /** + * Saves a compilation unit to its original location with formatting according to the function + * passed as a parameter. + * + * @param makeOutput a function that formats the compilation unit + */ + public void save(Function makeOutput) { + try { + Files.createDirectories(path.getParent()); + final String code = makeOutput.apply(getCompilationUnit()); + Files.write(path, code.getBytes(UTF8)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public ParseResult reparse(JavaParser javaParser) { + try { + return javaParser.parse(ParseStart.COMPILATION_UNIT, provider(getPath())); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public CompilationUnit clone() { + return (CompilationUnit) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CompilationUnitMetaModel getMetaModel() { + return JavaParserMetaModel.compilationUnitMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < imports.size(); i++) { + if (imports.get(i) == node) { + imports.set(i, (ImportDeclaration) replacementNode); + return true; + } + } + if (module != null) { + if (node == module) { + setModule((ModuleDeclaration) replacementNode); + return true; + } + } + if (packageDeclaration != null) { + if (node == packageDeclaration) { + setPackageDeclaration((PackageDeclaration) replacementNode); + return true; + } + } + for (int i = 0; i < types.size(); i++) { + if (types.get(i) == node) { + types.set(i, (TypeDeclaration) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/DataKey.java b/JavaParser/src/com/github/javaparser/ast/DataKey.java new file mode 100644 index 0000000..2f2115d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/DataKey.java @@ -0,0 +1,56 @@ +/* + * 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; + +/** + * A key to a piece of data associated with a {@link Node} at runtime. + * The key contains type information that can be used to check the + * type of any user data value for the key when the value is set. DataKey is abstract in order to + * force the creation of a subtype. That subtype is used to test for identity when looking for the + * user data because actual object identity would suffer from problems under serialization. + * So, the correct way to declare a DataKey is like this: + *

+ *

+ * 
+ * public static final DataKey<Role> ROLE = new DataKey<Role>() { };
+ * 
+ * 
+ *

+ * This code was taken from the Wicket project. + * + * @param The type of the object which is stored + * @see Node#getData(DataKey) + */ +public abstract class DataKey { + @Override + public int hashCode() { + return getClass().hashCode(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj != null && getClass().equals(obj.getClass()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/DocumentableNode.java b/JavaParser/src/com/github/javaparser/ast/DocumentableNode.java deleted file mode 100644 index 63964fc..0000000 --- a/JavaParser/src/com/github/javaparser/ast/DocumentableNode.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -import com.github.javaparser.ast.comments.JavadocComment; - -/** - * Node which can be documented through a Javadoc comment. - */ -public interface DocumentableNode { - - public JavadocComment getJavaDoc(); - public void setJavaDoc(JavadocComment javadocComment); -} diff --git a/JavaParser/src/com/github/javaparser/ast/ImportDeclaration.java b/JavaParser/src/com/github/javaparser/ast/ImportDeclaration.java index 7875195..88ab096 100644 --- a/JavaParser/src/com/github/javaparser/ast/ImportDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/ImportDeclaration.java @@ -1,134 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - *

- * This class represents a import declaration. Imports are optional for the - * {@link CompilationUnit}. - *

- * The ImportDeclaration is constructed following the syntax:
- *
- * {@code
- * ImportDeclaration ::= "import" ( "static" )? }{@link NameExpr}{@code ( "." "*" )? ";"
- * }
- * 
- * @author Julio Vilmar Gesser - */ -public final class ImportDeclaration extends Node { - - private NameExpr name; - - private boolean static_; - - private boolean asterisk; - - public ImportDeclaration() { - } - - public ImportDeclaration(NameExpr name, boolean isStatic, boolean isAsterisk) { - setAsterisk(isAsterisk); - setName(name); - setStatic(isStatic); - } - - public ImportDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, NameExpr name, boolean isStatic, boolean isAsterisk) { - super(beginLine, beginColumn, endLine, endColumn); - setAsterisk(isAsterisk); - setName(name); - setStatic(isStatic); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - /** - * Retrieves the name of the import. - * - * @return the name of the import - */ - public NameExpr getName() { - return name; - } - - /** - * Return if the import ends with "*". - * - * @return true if the import ends with "*", false - * otherwise - */ - public boolean isAsterisk() { - return asterisk; - } - - /** - * Return if the import is static. - * - * @return true if the import is static, false - * otherwise - */ - public boolean isStatic() { - return static_; - } - - /** - * Sets if this import is asterisk. - * - * @param asterisk - * true if this import is asterisk - */ - public void setAsterisk(boolean asterisk) { - this.asterisk = asterisk; - } - - /** - * Sets the name this import. - * - * @param name - * the name to set - */ - public void setName(NameExpr name) { - this.name = name; - setAsParentNodeOf(this.name); - } - - /** - * Sets if this import is static. - * - * @param static_ - * true if this import is static - */ - public void setStatic(boolean static_) { - this.static_ = static_; - } - -} +/* + * 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.JavaParser; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.JavaParser.*; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ImportDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * An import declaration. + *
import com.github.javaparser.JavaParser; + *
import com.github.javaparser.*; + *
import com.github.javaparser.JavaParser.*; + *
import static com.github.javaparser.JavaParser.*; + *
import static com.github.javaparser.JavaParser.parse; + * + *

The name does not include the asterisk or the static keyword.

+ * @author Julio Vilmar Gesser + */ +public final class ImportDeclaration extends Node implements NodeWithName { + + private Name name; + + private boolean isStatic; + + private boolean isAsterisk; + + private ImportDeclaration() { + this(null, new Name(), false, false); + } + + public ImportDeclaration(String name, boolean isStatic, boolean isAsterisk) { + this(null, parseName(name), isStatic, isAsterisk); + } + + @AllFieldsConstructor + public ImportDeclaration(Name name, boolean isStatic, boolean isAsterisk) { + this(null, name, isStatic, isAsterisk); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ImportDeclaration(TokenRange tokenRange, Name name, boolean isStatic, boolean isAsterisk) { + super(tokenRange); + setName(name); + setStatic(isStatic); + setAsterisk(isAsterisk); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Retrieves the name of the import (.* is not included.) + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + /** + * Return if the import ends with "*". + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isAsterisk() { + return isAsterisk; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isStatic() { + return isStatic; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ImportDeclaration setAsterisk(final boolean isAsterisk) { + if (isAsterisk == this.isAsterisk) { + return (ImportDeclaration) this; + } + notifyPropertyChange(ObservableProperty.ASTERISK, this.isAsterisk, isAsterisk); + this.isAsterisk = isAsterisk; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ImportDeclaration setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ImportDeclaration) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ImportDeclaration setStatic(final boolean isStatic) { + if (isStatic == this.isStatic) { + return (ImportDeclaration) this; + } + notifyPropertyChange(ObservableProperty.STATIC, this.isStatic, isStatic); + this.isStatic = isStatic; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ImportDeclaration clone() { + return (ImportDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ImportDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.importDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/Modifier.java b/JavaParser/src/com/github/javaparser/ast/Modifier.java new file mode 100644 index 0000000..b6d0309 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/Modifier.java @@ -0,0 +1,72 @@ +/* + * 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 java.util.EnumSet; + +/** + * One of the modifiers known in Java. + */ +public enum Modifier { + PUBLIC, + PROTECTED, + PRIVATE, + ABSTRACT, + STATIC, + FINAL, + TRANSIENT, + VOLATILE, + SYNCHRONIZED, + NATIVE, + STRICTFP, + TRANSITIVE, + DEFAULT; + + final String codeRepresentation; + + Modifier() { + this.codeRepresentation = name().toLowerCase(); + } + + /** + * @return the keyword represented by this modifier. + */ + public String asString() { + return codeRepresentation; + } + + public EnumSet toEnumSet() { + return EnumSet.of(this); + } + + public static AccessSpecifier getAccessSpecifier(EnumSet modifiers) { + if (modifiers.contains(Modifier.PUBLIC)) { + return AccessSpecifier.PUBLIC; + } else if (modifiers.contains(Modifier.PROTECTED)) { + return AccessSpecifier.PROTECTED; + } else if (modifiers.contains(Modifier.PRIVATE)) { + return AccessSpecifier.PRIVATE; + } else { + return AccessSpecifier.DEFAULT; + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/NamedNode.java b/JavaParser/src/com/github/javaparser/ast/NamedNode.java deleted file mode 100644 index fa695c6..0000000 --- a/JavaParser/src/com/github/javaparser/ast/NamedNode.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.javaparser.ast; - -/** - * 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 NamedNode { - String getName(); -} diff --git a/JavaParser/src/com/github/javaparser/ast/Node.java b/JavaParser/src/com/github/javaparser/ast/Node.java index 726bd90..98d0bbc 100644 --- a/JavaParser/src/com/github/javaparser/ast/Node.java +++ b/JavaParser/src/com/github/javaparser/ast/Node.java @@ -1,370 +1,1004 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.visitor.DumpVisitor; -import com.github.javaparser.ast.visitor.EqualsVisitor; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * 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 { - - private int beginLine; - - private int beginColumn; - - private int endLine; - - private int endColumn; - - private Node parentNode; - - private List childrenNodes = new LinkedList(); - private List orphanComments = new LinkedList(); - - /** - * This attribute can store additional information from semantic analysis. - */ - private Object data; - - private Comment comment; - - public Node() { - } - - public Node(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - this.beginLine = beginLine; - this.beginColumn = beginColumn; - this.endLine = endLine; - this.endColumn = endColumn; - } - - /** - * Accept method for visitor support. - * - * @param - * the type the return value of the visitor - * @param - * 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 accept(GenericVisitor v, A arg); - - /** - * Accept method for visitor support. - * - * @param - * the type the argument passed for the visitor - * @param v - * the visitor implementation - * @param arg - * any value relevant for the visitor - */ - public abstract void accept(VoidVisitor v, A arg); - - /** - * Return the begin column of this node. - * - * @return the begin column of this node - */ - public final int getBeginColumn() { - return beginColumn; - } - - /** - * Return the begin line of this node. - * - * @return the begin line of this node - */ - public final int getBeginLine() { - return beginLine; - } - - /** - * 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; - } - - /** - * Return the end column of this node. - * - * @return the end column of this node - */ - public final int getEndColumn() { - return endColumn; - } - - /** - * Return the end line of this node. - * - * @return the end line of this node - */ - public final int getEndLine() { - return endLine; - } - - /** - * Sets the begin column of this node. - * - * @param beginColumn - * the begin column of this node - */ - public final void setBeginColumn(final int beginColumn) { - this.beginColumn = beginColumn; - } - - /** - * Sets the begin line of this node. - * - * @param beginLine - * the begin line of this node - */ - public final void setBeginLine(final int beginLine) { - this.beginLine = beginLine; - } - - /** - * 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 data to be set - */ - public final void setData(final Object data) { - this.data = data; - } - - /** - * Sets the end column of this node. - * - * @param endColumn - * the end column of this node - */ - public final void setEndColumn(final int endColumn) { - this.endColumn = endColumn; - } - - /** - * Sets the end line of this node. - * - * @param endLine - * the end line of this node - */ - public final void setEndLine(final int endLine) { - this.endLine = endLine; - } - - /** - * 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); - } - - public Node getParentNode() { - return parentNode; - } - - public List getChildrenNodes(){ - return childrenNodes; - } - - public boolean contains(Node other){ - if (getBeginLine()>other.getBeginLine()) return false; - if (getBeginLine()==other.getBeginLine() && getBeginColumn()>other.getBeginColumn()) return false; - if (getEndLine() 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 getAllContainedComments(){ - List 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 childNodes) { - if(childNodes != null){ - Iterator it = childNodes.iterator(); - while(it.hasNext()){ - Node current = it.next(); - 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(int line, int column){ - if (line==ABSOLUTE_BEGIN_LINE) return true; - if (getBeginLine()>line){ - return true; - } else if (getBeginLine()==line){ - return getBeginColumn()>column; - } else { - return false; - } - } - - public boolean isPositionedBefore(int line, int column){ - if (line==ABSOLUTE_END_LINE) return true; - if (getEndLine()Construction + *

The tree is built by instantiating the required nodes, then adding them to other nodes. + * If it is the parser who is building the tree, it will use the largest constructor, + * the one with "range" as the first parameter. + * If you want to manually instantiate nodes, we suggest to... + *

    + *
  • use a convenience method, like "addStatement(...)", or if none are available...
  • + *
  • use a convenient constructor, like ClassOrInterfaceType(String name), or if none are available...
  • + *
  • use the default constructor.
  • + *
  • Alternatively, use one of the JavaParser.parse(snippet) methods.
  • + *
+ * ... and use the various methods on the node to initialize it further, if needed. + *

Parent/child

+ *

The parent node field is managed automatically and can be seen as read only. + * Note that there is only one parent, + * and trying to use the same node in two places will lead to unexpected behaviour. + * It is advised to clone() a node before moving it around. + *

Comments

+ *

Each Node can have one associated comment which describes it and + * a number of "orphan comments" which it contains but are not specifically + * associated to any child. + *

Positions

+ *

When the parser creates nodes, it sets their source code position in the "range" field. + * When you manually instantiate nodes, their range is not set. + * The top left character is position 1, 1. + * Note that since this is an abstract syntax tree, + * it leaves out a lot of text from the original source file, + * like where braces or comma's are exactly. + * Therefore there is no position information on everything in the original source file. + *

Observers

+ *

It is possible to add observers to the the tree. + * Any change in the tree is sent as an event to any observers watching. + *

Visitors

+ *

The most comfortable way of working with an abstract syntax tree is using visitors. + * You can use one of the visitors in the visitor package, or extend one of them. + * A visitor can be "run" by calling accept on a node: + *

node.accept(visitor, argument);
+ * where argument is an object of your choice (often simply null.) + * + * @author Julio Vilmar Gesser + */ +public abstract class Node implements Cloneable, HasParentNode, Visitable, NodeWithRange, NodeWithTokenRange { + + /** + * Different registration mode for observers on nodes. + */ + public enum ObserverRegistrationMode { + + /** + * Notify exclusively for changes happening on this node alone. + */ + JUST_THIS_NODE, + /** + * Notify for changes happening on this node and all its descendants existing at the moment in + * which the observer was registered. Nodes attached later will not be observed. + */ + THIS_NODE_AND_EXISTING_DESCENDANTS, + /** + * Notify for changes happening on this node and all its descendants. The descendants existing at the moment in + * which the observer was registered will be observed immediately. As new nodes are attached later they are + * automatically registered to be observed. + */ + SELF_PROPAGATING + } + + public enum Parsedness { + + PARSED, UNPARSABLE + } + + /** + * This can be used to sort nodes on position. + */ + public static Comparator> NODE_BY_BEGIN_POSITION = (a, b) -> { + if (a.getRange().isPresent() && b.getRange().isPresent()) { + return a.getRange().get().begin.compareTo(b.getRange().get().begin); + } + if (a.getRange().isPresent() || b.getRange().isPresent()) { + if (a.getRange().isPresent()) { + return 1; + } + return -1; + } + return 0; + }; + + private static final PrettyPrinter toStringPrinter = new PrettyPrinter(new PrettyPrinterConfiguration()); + + protected static final PrettyPrinterConfiguration prettyPrinterNoCommentsConfiguration = new PrettyPrinterConfiguration().setPrintComments(false); + + @InternalProperty + private Range range; + + @InternalProperty + private TokenRange tokenRange; + + @InternalProperty + private Node parentNode; + + @InternalProperty + private List childNodes = new LinkedList<>(); + + @InternalProperty + private List orphanComments = new LinkedList<>(); + + @InternalProperty + private IdentityHashMap, Object> data = null; + + @OptionalProperty + private Comment comment; + + @InternalProperty + private List observers = new ArrayList<>(); + + @InternalProperty + private Parsedness parsed = PARSED; + + protected Node(TokenRange tokenRange) { + setTokenRange(tokenRange); + } + + /** + * Called in every constructor for node specific code. + * It can't be written in the constructor itself because it will + * be overwritten during code generation. + */ + protected void customInitialization() { + } + + /** + * This is a comment associated with this node. + * + * @return comment property + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getComment() { + return Optional.ofNullable(comment); + } + + /** + * @return the range of characters in the source code that this node covers. + */ + public Optional getRange() { + return Optional.ofNullable(range); + } + + /** + * @return the range of tokens that this node covers. + */ + public Optional getTokenRange() { + return Optional.ofNullable(tokenRange); + } + + public Node setTokenRange(TokenRange tokenRange) { + this.tokenRange = tokenRange; + if (tokenRange == null || !(tokenRange.getBegin().getRange().isPresent() && tokenRange.getBegin().getRange().isPresent())) { + range = null; + } else { + range = new Range(tokenRange.getBegin().getRange().get().begin, tokenRange.getEnd().getRange().get().end); + } + return this; + } + + /** + * @param range the range of characters in the source code that this node covers. null can be used to indicate that + * no range information is known, or that it is not of interest. + */ + public Node setRange(Range range) { + if (this.range == range) { + return this; + } + notifyPropertyChange(ObservableProperty.RANGE, this.range, range); + this.range = range; + return this; + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setComment(final Comment comment) { + if (this.comment == comment) { + return this; + } + if (comment != null && (this instanceof Comment)) { + throw new RuntimeException("A comment can not be commented"); + } + notifyPropertyChange(ObservableProperty.COMMENT, this.comment, comment); + if (this.comment != null) { + this.comment.setCommentedNode(null); + } + this.comment = comment; + if (comment != null) { + this.comment.setCommentedNode(this); + } + return this; + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setLineComment(String comment) { + return setComment(new LineComment(comment)); + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + public final Node setBlockComment(String comment) { + return setComment(new BlockComment(comment)); + } + + /** + * Return the String representation of this node. + * + * @return the String representation of this node + */ + @Override + public final String toString() { + return toStringPrinter.print(this); + } + + public final String toString(PrettyPrinterConfiguration prettyPrinterConfiguration) { + return new PrettyPrinter(prettyPrinterConfiguration).print(this); + } + + @Override + public final int hashCode() { + return HashCodeVisitor.hashCode(this); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof Node)) { + return false; + } + return EqualsVisitor.equals(this, (Node) obj); + } + + @Override + public Optional getParentNode() { + return Optional.ofNullable(parentNode); + } + + /** + * Contains all nodes that have this node set as their parent. + * You can add and remove nodes from this list by adding or removing nodes from the fields of this node. + * + * @return all nodes that have this node as their parent. + */ + public List getChildNodes() { + return unmodifiableList(childNodes); + } + + public void addOrphanComment(Comment comment) { + orphanComments.add(comment); + comment.setParentNode(this); + } + + public boolean removeOrphanComment(Comment comment) { + boolean removed = orphanComments.remove(comment); + if (removed) { + comment.setParentNode(null); + } + return removed; + } + + /** + * 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. + *

+ * Changes to this list are not persisted. + * + * @return all comments that cannot be attributed to a concept + */ + public List getOrphanComments() { + return new LinkedList<>(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 getAllContainedComments() { + List comments = new LinkedList<>(); + comments.addAll(getOrphanComments()); + for (Node child : getChildNodes()) { + child.getComment().ifPresent(comments::add); + 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 newParentNode node to be set as parent + */ + @Override + public Node setParentNode(Node newParentNode) { + if (newParentNode == parentNode) { + return this; + } + observers.forEach(o -> o.parentChange(this, parentNode, newParentNode)); + // remove from old parent, if any + if (parentNode != null) { + final List parentChildNodes = parentNode.childNodes; + for (int i = 0; i < parentChildNodes.size(); i++) { + if (parentChildNodes.get(i) == this) { + parentChildNodes.remove(i); + } + } + } + parentNode = newParentNode; + // add to new parent, if any + if (parentNode != null) { + parentNode.childNodes.add(this); + } + return this; + } + + protected void setAsParentNodeOf(Node childNode) { + if (childNode != null) { + childNode.setParentNode(getParentNodeForChildren()); + } + } + + public static final int ABSOLUTE_BEGIN_LINE = -1; + + public static final int ABSOLUTE_END_LINE = -2; + + /** + * @deprecated use getComment().isPresent() + */ + @Deprecated + public boolean hasComment() { + return comment != null; + } + + public void tryAddImportToParentCompilationUnit(Class clazz) { + getAncestorOfType(CompilationUnit.class).ifPresent(p -> p.addImport(clazz)); + } + + /** + * Recursively finds all nodes of a certain type. + * + * @param clazz the type of node to find. + * @deprecated use find(Class) + */ + public List getChildNodesByType(Class clazz) { + List nodes = new ArrayList<>(); + for (Node child : getChildNodes()) { + if (clazz.isInstance(child)) { + nodes.add(clazz.cast(child)); + } + nodes.addAll(child.getChildNodesByType(clazz)); + } + return nodes; + } + + /** + * @deprecated use findAll(Class) + */ + @Deprecated + public List getNodesByType(Class clazz) { + return getChildNodesByType(clazz); + } + + /** + * Gets data for this node using the given key. + * + * @param The type of the data. + * @param key The key for the data + * @return The data or null of no data was found for the given key + * @see DataKey + */ + @SuppressWarnings("unchecked") + public M getData(final DataKey key) { + if (data == null) { + return null; + } + return (M) data.get(key); + } + + /** + * Sets data for this node using the given key. + * For information on creating DataKey, see {@link DataKey}. + * + * @param The type of data + * @param key The singleton key for the data + * @param object The data object + * @see DataKey + */ + public void setData(DataKey key, M object) { + if (data == null) { + data = new IdentityHashMap<>(); + } + data.put(key, object); + } + + /** + * @return does this node have data for this key? + */ + public boolean containsData(DataKey key) { + if (data == null) { + return false; + } + return data.get(key) != null; + } + + /** + * Try to remove this node from the parent + * + * @return true if removed, false if it is a required property of the parent, or if the parent isn't set. + * @throws RuntimeException if it fails in an unexpected way + */ + public boolean remove() { + if (parentNode == null) { + return false; + } + return parentNode.remove(this); + } + + /** + * Try to replace this node in the parent with the supplied node. + * + * @return true if removed, or if the parent isn't set. + * @throws RuntimeException if it fails in an unexpected way + */ + public boolean replace(Node node) { + if (parentNode == null) { + return false; + } + return parentNode.replace(this, node); + } + + /** + * Forcibly removes this node from the AST. + * If it cannot be removed from the parent with remove(), + * it will try to remove its parent instead, + * until it finds a node that can be removed, + * or no parent can be found. + *

+ * Since everything at CompilationUnit level is removable, + * this method will only (silently) fail when the node is in a detached AST fragment. + */ + public void removeForced() { + if (!remove()) { + getParentNode().ifPresent(Node::remove); + } + } + + @Override + public Node getParentNodeForChildren() { + return this; + } + + protected void setAsParentNodeOf(NodeList list) { + if (list != null) { + list.setParentNode(getParentNodeForChildren()); + } + } + + public

void notifyPropertyChange(ObservableProperty property, P oldValue, P newValue) { + this.observers.forEach(o -> o.propertyChange(this, property, oldValue, newValue)); + } + + @Override + public void unregister(AstObserver observer) { + this.observers.remove(observer); + } + + @Override + public void register(AstObserver observer) { + this.observers.add(observer); + } + + /** + * Register a new observer for the given node. Depending on the mode specified also descendants, existing + * and new, could be observed. For more details see ObserverRegistrationMode. + */ + public void register(AstObserver observer, ObserverRegistrationMode mode) { + if (mode == null) { + throw new IllegalArgumentException("Mode should be not null"); + } + switch(mode) { + case JUST_THIS_NODE: + register(observer); + break; + case THIS_NODE_AND_EXISTING_DESCENDANTS: + registerForSubtree(observer); + break; + case SELF_PROPAGATING: + registerForSubtree(PropagatingAstObserver.transformInPropagatingObserver(observer)); + break; + default: + throw new UnsupportedOperationException("This mode is not supported: " + mode); + } + } + + /** + * Register the observer for the current node and all the contained node and nodelists, recursively. + */ + public void registerForSubtree(AstObserver observer) { + register(observer); + this.getChildNodes().forEach(c -> c.registerForSubtree(observer)); + for (PropertyMetaModel property : getMetaModel().getAllPropertyMetaModels()) { + if (property.isNodeList()) { + NodeList nodeList = (NodeList) property.getValue(this); + if (nodeList != null) + nodeList.register(observer); + } + } + } + + @Override + public boolean isRegistered(AstObserver observer) { + return this.observers.contains(observer); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (comment != null) { + if (node == comment) { + removeComment(); + return true; + } + } + return false; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public Node removeComment() { + return setComment((Comment) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Node clone() { + return (Node) accept(new CloneVisitor(), null); + } + + /** + * @return get JavaParser specific node introspection information. + */ + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public NodeMetaModel getMetaModel() { + return JavaParserMetaModel.nodeMetaModel; + } + + /** + * @return whether this node was successfully parsed or not. + * If it was not, only the range and tokenRange fields will be valid. + */ + public Parsedness getParsed() { + return parsed; + } + + /** + * Used by the parser to flag unparsable nodes. + */ + public Node setParsed(Parsedness parsed) { + this.parsed = parsed; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (comment != null) { + if (node == comment) { + setComment((Comment) replacementNode); + return true; + } + } + return false; + } + + /** + * Finds the root node of this AST by finding the topmost parent. + */ + public Node findRootNode() { + Node n = this; + while (n.getParentNode().isPresent()) { + n = n.getParentNode().get(); + } + return n; + } + + /** + * @return the containing CompilationUnit, or empty if this node is not inside a compilation unit. + */ + public Optional findCompilationUnit() { + Node rootNode = findRootNode(); + if (rootNode instanceof CompilationUnit) { + return Optional.of((CompilationUnit) rootNode); + } + return Optional.empty(); + } + + protected SymbolResolver getSymbolResolver() { + return findCompilationUnit().map(cu -> { + SymbolResolver symbolResolver = cu.getData(SYMBOL_RESOLVER_KEY); + if (symbolResolver == null) { + throw new IllegalStateException("Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration"); + } + return symbolResolver; + }).orElseThrow(() -> new IllegalStateException("The node is not inserted in a CompilationUnit")); + } + + // We need to expose it because we will need to use it to inject the SymbolSolver + public static final DataKey SYMBOL_RESOLVER_KEY = new DataKey() { + }; + + public enum TreeTraversal { + + PREORDER, BREADTHFIRST, POSTORDER, PARENTS, DIRECT_CHILDREN + } + + private Iterator treeIterator(TreeTraversal traversal) { + switch(traversal) { + case BREADTHFIRST: + return new BreadthFirstIterator(this); + case POSTORDER: + return new PostOrderIterator(this); + case PREORDER: + return new PreOrderIterator(this); + case DIRECT_CHILDREN: + return new DirectChildrenIterator(this); + case PARENTS: + return new ParentsVisitor(this); + default: + throw new IllegalArgumentException("Unknown traversal choice."); + } + } + + private Iterable treeIterable(TreeTraversal traversal) { + return () -> treeIterator(traversal); + } + + /** + * Make a stream of nodes using traversal algorithm "traversal". + */ + public Stream stream(TreeTraversal traversal) { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(traversal), NONNULL | DISTINCT), false); + } + + /** + * Make a stream of nodes using pre-order traversal. + */ + public Stream stream() { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(PREORDER), NONNULL | DISTINCT), false); + } + + /** + * Walks the AST, calling the consumer for every node, with traversal algorithm "traversal". + *
This is the most general walk method. All other walk and findAll methods are based on this. + */ + public void walk(TreeTraversal traversal, Consumer consumer) { + // Could be implemented as a call to the above walk method, but this is a little more efficient. + for (Node node : treeIterable(traversal)) { + consumer.accept(node); + } + } + + /** + * Walks the AST, calling the consumer for every node with pre-order traversal. + */ + public void walk(Consumer consumer) { + walk(PREORDER, consumer); + } + + /** + * Walks the AST with pre-order traversal, calling the consumer for every node of type "nodeType". + */ + public void walk(Class nodeType, Consumer consumer) { + walk(TreeTraversal.PREORDER, node -> { + if (nodeType.isAssignableFrom(node.getClass())) { + consumer.accept(nodeType.cast(node)); + } + }); + } + + /** + * Walks the AST with pre-order traversal, returning all nodes of type "nodeType". + */ + public List findAll(Class nodeType) { + final List found = new ArrayList<>(); + walk(nodeType, found::add); + return found; + } + + /** + * Walks the AST with pre-order traversal, returning all nodes of type "nodeType" that match the predicate. + */ + public List findAll(Class nodeType, Predicate predicate) { + final List found = new ArrayList<>(); + walk(nodeType, n -> { + if (predicate.test(n)) + found.add(n); + }); + return found; + } + + /** + * Walks the AST, applying the function for every node, with traversal algorithm "traversal". If the function + * returns something else than null, the traversal is stopped and the function result is returned.
This is the + * most general findFirst method. All other findFirst methods are based on this. + */ + public Optional findFirst(TreeTraversal traversal, Function> consumer) { + for (Node node : treeIterable(traversal)) { + final Optional result = consumer.apply(node); + if (result.isPresent()) { + return result; + } + } + return Optional.empty(); + } + + /** + * Walks the AST with pre-order traversal, returning the first node of type "nodeType" or empty() if none is found. + */ + public Optional findFirst(Class nodeType) { + return findFirst(TreeTraversal.PREORDER, node -> { + if (nodeType.isAssignableFrom(node.getClass())) { + return Optional.of(nodeType.cast(node)); + } + return Optional.empty(); + }); + } + + /** + * Walks the AST with pre-order traversal, returning the first node of type "nodeType" that matches "predicate" or empty() if none is + * found. + */ + public Optional findFirst(Class nodeType, Predicate predicate) { + return findFirst(TreeTraversal.PREORDER, node -> { + if (nodeType.isAssignableFrom(node.getClass())) { + final N castNode = nodeType.cast(node); + if (predicate.test(castNode)) { + return Optional.of(castNode); + } + } + return Optional.empty(); + }); + } + + /** + * Walks the parents of this node, returning the first node of type "nodeType" or empty() if none is found. + */ + public Optional findParent(Class nodeType) { + Node n = this; + while (n.getParentNode().isPresent()) { + n = n.getParentNode().get(); + if (nodeType.isAssignableFrom(n.getClass())) { + return Optional.of(nodeType.cast(n)); + } + } + return Optional.empty(); + } + + /** + * Performs a breadth-first node traversal starting with a given node. + * + * @see
Breadth-first traversal + */ + public static class BreadthFirstIterator implements Iterator { + + private final Queue queue = new LinkedList<>(); + + public BreadthFirstIterator(Node node) { + queue.add(node); + } + + @Override + public boolean hasNext() { + return !queue.isEmpty(); + } + + @Override + public Node next() { + Node next = queue.remove(); + queue.addAll(next.getChildNodes()); + return next; + } + } + + /** + * Performs a simple traversal over all nodes that have the passed node as their parent. + */ + public static class DirectChildrenIterator implements Iterator { + + private final Iterator childrenIterator; + + public DirectChildrenIterator(Node node) { + childrenIterator = new ArrayList<>(node.getChildNodes()).iterator(); + } + + @Override + public boolean hasNext() { + return childrenIterator.hasNext(); + } + + @Override + public Node next() { + return childrenIterator.next(); + } + } + + /** + * Iterates over the parent of the node, then the parent's parent, then the parent's parent's parent, until running + * out of parents. + */ + public static class ParentsVisitor implements Iterator { + + private Node node; + + public ParentsVisitor(Node node) { + this.node = node; + } + + @Override + public boolean hasNext() { + return node.getParentNode().isPresent(); + } + + @Override + public Node next() { + node = node.getParentNode().orElse(null); + return node; + } + } + + /** + * Performs a pre-order (or depth-first) node traversal starting with a given node. + * + * @see Pre-order traversal + */ + public static class PreOrderIterator implements Iterator { + + private final Stack stack = new Stack<>(); + + public PreOrderIterator(Node node) { + stack.add(node); + } + + @Override + public boolean hasNext() { + return !stack.isEmpty(); + } + + @Override + public Node next() { + Node next = stack.pop(); + List children = next.getChildNodes(); + for (int i = children.size() - 1; i >= 0; i--) { + stack.add(children.get(i)); + } + return next; + } + } + + /** + * Performs a post-order (or leaves-first) node traversal starting with a given node. + * + * @see Post-order traversal + */ + public static class PostOrderIterator implements Iterator { + + private final Stack> nodesStack = new Stack<>(); + + private final Stack cursorStack = new Stack<>(); + + private final Node root; + + private boolean hasNext = true; + + public PostOrderIterator(Node root) { + this.root = root; + fillStackToLeaf(root); + } + + private void fillStackToLeaf(Node node) { + while (true) { + List childNodes = new ArrayList<>(node.getChildNodes()); + if (childNodes.isEmpty()) { + break; + } + nodesStack.push(childNodes); + cursorStack.push(0); + node = childNodes.get(0); + } + } + + @Override + public boolean hasNext() { + return hasNext; + } + + @Override + public Node next() { + final List nodes = nodesStack.peek(); + final int cursor = cursorStack.peek(); + final boolean levelHasNext = cursor < nodes.size(); + if (levelHasNext) { + Node node = nodes.get(cursor); + fillStackToLeaf(node); + return nextFromLevel(); + } else { + nodesStack.pop(); + cursorStack.pop(); + hasNext = !nodesStack.empty(); + if (hasNext) { + return nextFromLevel(); + } + return root; + } + } + + private Node nextFromLevel() { + final List nodes = nodesStack.peek(); + final int cursor = cursorStack.pop(); + cursorStack.push(cursor + 1); + return nodes.get(cursor); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/NodeList.java b/JavaParser/src/com/github/javaparser/ast/NodeList.java new file mode 100644 index 0000000..f370e96 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/NodeList.java @@ -0,0 +1,542 @@ +/* + * 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.HasParentNode; +import com.github.javaparser.ast.observer.AstObserver; +import com.github.javaparser.ast.observer.Observable; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.InternalProperty; + +import java.util.*; +import java.util.function.*; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A list of nodes. + * It usually has a parent node. + * Unlike normal Nodes, this does not mean that it is a child of that parent. + * Instead, this list will make every node it contains a child of its parent. + * This way, a NodeList does not create an extra level inside the AST. + * + * @param the type of nodes contained. + */ +public class NodeList implements List, Iterable, HasParentNode>, Visitable, Observable { + @InternalProperty + private List innerList = new ArrayList<>(0); + + private Node parentNode; + + private List observers = new ArrayList<>(); + + public NodeList() { + parentNode = null; + } + + public NodeList(Collection n) { + this.addAll(n); + } + + public NodeList(N... n) { + this.addAll(Arrays.asList(n)); + } + + @Override + public boolean add(N node) { + notifyElementAdded(innerList.size(), node); + own(node); + return innerList.add(node); + } + + private void own(N node) { + if (node == null) { + return; + } + setAsParentNodeOf(node); + } + + public boolean remove(Node node) { + int index = innerList.indexOf(node); + if (index != -1) { + notifyElementRemoved(index, node); + node.setParentNode(null); + } + return innerList.remove(node); + } + + public N removeFirst() { + return remove(0); + } + + public N removeLast() { + return remove(innerList.size() - 1); + } + + @SafeVarargs + public static NodeList nodeList(X... nodes) { + final NodeList nodeList = new NodeList<>(); + Collections.addAll(nodeList, nodes); + return nodeList; + } + + public static NodeList nodeList(Collection nodes) { + final NodeList nodeList = new NodeList<>(); + nodeList.addAll(nodes); + return nodeList; + } + + public static NodeList nodeList(NodeList nodes) { + final NodeList nodeList = new NodeList<>(); + nodeList.addAll(nodes); + return nodeList; + } + + public boolean contains(N node) { + return innerList.contains(node); + } + + @Override + public int size() { + return innerList.size(); + } + + @Override + public N get(int i) { + return innerList.get(i); + } + + @Override + public Iterator iterator() { + // TODO take care of "Iterator.remove" + return innerList.iterator(); + } + + @Override + public N set(int index, N element) { + if (index < 0 || index >= innerList.size()) { + throw new IllegalArgumentException("Illegal index. The index should be between 0 and " + innerList.size() + + " excluded. It is instead " + index); + } + if (element == innerList.get(index)) { + return element; + } + notifyElementReplaced(index, element); + innerList.get(index).setParentNode(null); + setAsParentNodeOf(element); + return innerList.set(index, element); + } + + @Override + public N remove(int index) { + notifyElementRemoved(index, innerList.get(index)); + N remove = innerList.remove(index); + if (remove != null) + remove.setParentNode(null); + return remove; + } + + @Override + public boolean isEmpty() { + return innerList.isEmpty(); + } + + @Override + public void sort(Comparator comparator) { + innerList.sort(comparator); + } + + public void addAll(NodeList otherList) { + for (N node : otherList) { + add(node); + } + } + + @Override + public void add(int index, N node) { + notifyElementAdded(index, node); + own(node); + innerList.add(index, node); + } + + /** + * Inserts the node before all other nodes. + */ + public NodeList addFirst(N node) { + add(0, node); + return this; + } + + /** + * Inserts the node after all other nodes. (This is simply an alias for add.) + */ + public NodeList addLast(N node) { + add(node); + return this; + } + + /** + * Inserts the node after afterThisNode. + * + * @throws IllegalArgumentException when afterThisNode is not in this list. + */ + public NodeList addAfter(N node, N afterThisNode) { + int i = indexOf(afterThisNode); + if (i == -1) { + throw new IllegalArgumentException("Can't find node to insert after."); + } + add(i + 1, node); + return this; + } + + /** + * Inserts the node before beforeThisNode. + * + * @throws IllegalArgumentException when beforeThisNode is not in this list. + */ + public NodeList addBefore(N node, N beforeThisNode) { + int i = indexOf(beforeThisNode); + if (i == -1) { + throw new IllegalArgumentException("Can't find node to insert before."); + } + add(i, node); + return this; + } + + + @Override + public Optional getParentNode() { + return Optional.ofNullable(parentNode); + } + + /** + * Sets the parentNode + * + * @param parentNode the parentNode + * @return this, the NodeList + */ + @Override + public NodeList setParentNode(Node parentNode) { + this.parentNode = parentNode; + setAsParentNodeOf(innerList); + return this; + } + + @Override + public Node getParentNodeForChildren() { + return parentNode; + } + + @Override + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * @see java.lang.Iterable#forEach(java.util.function.Consumer) + */ + @Override + public void forEach(Consumer action) { + innerList.forEach(action); + } + + /** + * @see java.util.List#contains(java.lang.Object) + */ + @Override + public boolean contains(Object o) { + return innerList.contains(o); + } + + /** + * @see java.util.List#toArray() + */ + @Override + public Object[] toArray() { + return innerList.toArray(); + } + + /** + * @see java.util.List#toArray(java.lang.Object[]) + */ + @Override + public T[] toArray(T[] a) { + return innerList.toArray(a); + } + + /** + * @see java.util.List#remove(java.lang.Object) + */ + @Override + public boolean remove(Object o) { + if (o instanceof Node) { + return remove((Node) o); + } else { + return false; + } + } + + /** + * @see java.util.List#containsAll(java.util.Collection) + */ + @Override + public boolean containsAll(Collection c) { + return innerList.containsAll(c); + } + + /** + * @see java.util.List#addAll(java.util.Collection) + */ + @Override + public boolean addAll(Collection c) { + c.forEach(this::add); + return !c.isEmpty(); + } + + /** + * @see java.util.List#addAll(int, java.util.Collection) + */ + @Override + public boolean addAll(int index, Collection c) { + for (N e : c) { + add(index++, e); + } + return !c.isEmpty(); + } + + /** + * @see java.util.List#removeAll(java.util.Collection) + */ + @Override + public boolean removeAll(Collection c) { + boolean changed = false; + for (Object e : c) { + changed = remove(e) || changed; + } + return changed; + } + + /** + * @see java.util.List#retainAll(java.util.Collection) + */ + @Override + public boolean retainAll(Collection c) { + boolean changed = false; + for (Object e : this.stream().filter(it -> !c.contains(it)).toArray()) { + if (!c.contains(e)) { + changed = remove(e) || changed; + } + } + return changed; + } + + /** + * @see java.util.List#replaceAll(java.util.function.UnaryOperator) + */ + @Override + public void replaceAll(UnaryOperator operator) { + for (int i = 0; i < this.size(); i++) { + set(i, operator.apply(this.get(i))); + } + } + + /** + * @see java.util.Collection#removeIf(java.util.function.Predicate) + */ + @Override + public boolean removeIf(Predicate filter) { + boolean changed = false; + for (Object e : this.stream().filter(filter).toArray()) { + changed = remove(e) || changed; + } + return changed; + } + + /** + * @see java.util.List#clear() + */ + @Override + public void clear() { + while (!isEmpty()) { + remove(0); + } + } + + /** + * @see java.util.List#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + return innerList.equals(o); + } + + /** + * @see java.util.List#hashCode() + */ + @Override + public int hashCode() { + return innerList.hashCode(); + } + + /** + * @see java.util.List#indexOf(java.lang.Object) + */ + @Override + public int indexOf(Object o) { + return innerList.indexOf(o); + } + + /** + * @see java.util.List#lastIndexOf(java.lang.Object) + */ + @Override + public int lastIndexOf(Object o) { + return innerList.lastIndexOf(o); + } + + /** + * @see java.util.List#listIterator() + */ + @Override + public ListIterator listIterator() { + return innerList.listIterator(); + } + + /** + * @see java.util.List#listIterator(int) + */ + @Override + public ListIterator listIterator(int index) { + return innerList.listIterator(index); + } + + /** + * @see java.util.Collection#parallelStream() + */ + @Override + public Stream parallelStream() { + return innerList.parallelStream(); + } + + /** + * @see java.util.List#subList(int, int) + */ + @Override + public List subList(int fromIndex, int toIndex) { + return innerList.subList(fromIndex, toIndex); + } + + /** + * @see java.util.List#spliterator() + */ + @Override + public Spliterator spliterator() { + return innerList.spliterator(); + } + + private void notifyElementAdded(int index, Node nodeAddedOrRemoved) { + this.observers.forEach(o -> o.listChange(this, AstObserver.ListChangeType.ADDITION, index, nodeAddedOrRemoved)); + } + + private void notifyElementRemoved(int index, Node nodeAddedOrRemoved) { + this.observers.forEach(o -> o.listChange(this, AstObserver.ListChangeType.REMOVAL, index, nodeAddedOrRemoved)); + } + + private void notifyElementReplaced(int index, Node nodeAddedOrRemoved) { + this.observers.forEach(o -> o.listReplacement(this, index, this.get(index), nodeAddedOrRemoved)); + } + + @Override + public void unregister(AstObserver observer) { + this.observers.remove(observer); + } + + @Override + public void register(AstObserver observer) { + this.observers.add(observer); + } + + @Override + public boolean isRegistered(AstObserver observer) { + return this.observers.contains(observer); + } + + /** + * Replaces the first node that is equal to "old" with "replacement". + * + * @return true if a replacement has happened. + */ + public boolean replace(N old, N replacement) { + int i = indexOf(old); + if (i == -1) { + return false; + } + set(i, replacement); + return true; + } + + /** + * @return the opposite of isEmpty() + */ + public boolean isNonEmpty() { + return !isEmpty(); + } + + public void ifNonEmpty(Consumer> consumer) { + if (isNonEmpty()) + consumer.accept(this); + } + + public static Collector, NodeList> toNodeList() { + return Collector.of(NodeList::new, NodeList::add, (left, right) -> { + left.addAll(right); + return left; + }); + } + + private void setAsParentNodeOf(List childNodes) { + if (childNodes != null) { + for (HasParentNode current : childNodes) { + current.setParentNode(getParentNodeForChildren()); + } + } + } + + private void setAsParentNodeOf(Node childNode) { + if (childNode != null) { + childNode.setParentNode(getParentNodeForChildren()); + } + } + + @Override + public String toString() { + return innerList.stream().map(Node::toString).collect(Collectors.joining(", ", "[", "]")); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/PackageDeclaration.java b/JavaParser/src/com/github/javaparser/ast/PackageDeclaration.java index 4c2392e..65a1ca7 100644 --- a/JavaParser/src/com/github/javaparser/ast/PackageDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/PackageDeclaration.java @@ -1,116 +1,189 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - *

- * This class represents the package declaration. The package declaration is - * optional for the {@link CompilationUnit}. - *

- * The PackageDeclaration is constructed following the syntax:
- *
- * {@code
- * PackageDeclaration ::= ( }{@link AnnotationExpr}{@code )* "package" }{@link NameExpr}{@code ) ";"
- * }
- * 
- * @author Julio Vilmar Gesser - */ -public final class PackageDeclaration extends Node { - - private List annotations; - - private NameExpr name; - - public PackageDeclaration() { - } - - public PackageDeclaration(NameExpr name) { - setName(name); - } - - public PackageDeclaration(List annotations, NameExpr name) { - setAnnotations(annotations); - setName(name); - } - - public PackageDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, List annotations, NameExpr name) { - super(beginLine, beginColumn, endLine, endColumn); - setAnnotations(annotations); - setName(name); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public
void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - /** - * Retrieves the list of annotations declared before the package - * declaration. Return null if there are no annotations. - * - * @return list of annotations or null - */ - public List getAnnotations() { - return annotations; - } - - /** - * Return the name of the package. - * - * @return the name of the package - */ - public NameExpr getName() { - return name; - } - - /** - * @param annotations - * the annotations to set - */ - public void setAnnotations(List 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); - } - -} +/* + * 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.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.PackageDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * A package declaration. + *
package com.github.javaparser.ast; + *
@Wonderful package anything.can.be.annotated.nowadays; + * + * @author Julio Vilmar Gesser + */ +public final class PackageDeclaration extends Node implements NodeWithAnnotations, NodeWithName { + + private NodeList annotations = new NodeList<>(); + + private Name name; + + public PackageDeclaration() { + this(null, new NodeList<>(), new Name()); + } + + public PackageDeclaration(Name name) { + this(null, new NodeList<>(), name); + } + + @AllFieldsConstructor + public PackageDeclaration(NodeList annotations, Name name) { + this(null, annotations, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public PackageDeclaration(TokenRange tokenRange, NodeList annotations, Name name) { + super(tokenRange); + setAnnotations(annotations); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Retrieves the list of annotations declared before the package + * declaration. Return null if there are no annotations. + * + * @return list of annotations or null + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + /** + * Return the name expression of the package. + * + * @return the name of the package + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + /** + * @param annotations the annotations to set + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public PackageDeclaration setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (PackageDeclaration) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + /** + * Sets the name of this package declaration. + * + * @param name the name to set + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public PackageDeclaration setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (PackageDeclaration) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public PackageDeclaration clone() { + return (PackageDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public PackageDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.packageDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/TreeVisitor.java b/JavaParser/src/com/github/javaparser/ast/TreeVisitor.java deleted file mode 100644 index 0ed7f23..0000000 --- a/JavaParser/src/com/github/javaparser/ast/TreeVisitor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -public abstract class TreeVisitor { - - public void visitDepthFirst(Node node){ - process(node); - for (Node child : node.getChildrenNodes()){ - visitDepthFirst(child); - } - } - - public abstract void process(Node node); - -} diff --git a/JavaParser/src/com/github/javaparser/ast/TypeParameter.java b/JavaParser/src/com/github/javaparser/ast/TypeParameter.java deleted file mode 100644 index fec24a5..0000000 --- a/JavaParser/src/com/github/javaparser/ast/TypeParameter.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast; - -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; - -import java.util.List; - -/** - *

- * This class represents the declaration of a generics argument. - *

- * The TypeParameter is constructed following the syntax:
- *
- * {@code
- * TypeParameter ::=  ( "extends" }{@link ClassOrInterfaceType}{@code ( "&" }{@link ClassOrInterfaceType}{@code )* )?
- * }
- * 
- * @author Julio Vilmar Gesser - */ -public final class TypeParameter extends Node implements NamedNode { - - private String name; - - private List annotations; - - private List typeBound; - - public TypeParameter() { - } - - public TypeParameter(final String name, final List typeBound) { - setName(name); - setTypeBound(typeBound); - } - - public TypeParameter(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String name, final List typeBound) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setTypeBound(typeBound); - } - - public TypeParameter(int beginLine, int beginColumn, int endLine, - int endColumn, String name, List typeBound, List annotations) { - this(beginLine, beginColumn, endLine, endColumn, name, typeBound); - setName(name); - setTypeBound(typeBound); - this.annotations = annotations; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public
void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - /** - * Return the name of the paramenter. - * - * @return the name of the paramenter - */ - public String getName() { - return name; - } - - /** - * Return the list of {@link ClassOrInterfaceType} that this parameter - * extends. Return null null if there are no type. - * - * @return list of types that this paramente extends or null - */ - public List getTypeBound() { - return typeBound; - } - - /** - * Sets the name of this type parameter. - * - * @param name - * the name to set - */ - public void setName(final String name) { - this.name = name; - } - - /** - * Sets the list o types. - * - * @param typeBound - * the typeBound to set - */ - public void setTypeBound(final List typeBound) { - this.typeBound = typeBound; - setAsParentNodeOf(typeBound); - } - - public List getAnnotations() { - return annotations; - } - - public void setAnnotations(List annotations) { - this.annotations = annotations; - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/AnnotableNode.java b/JavaParser/src/com/github/javaparser/ast/body/AnnotableNode.java deleted file mode 100644 index 1f6df64..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/AnnotableNode.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.expr.AnnotationExpr; - -import java.util.List; - -/** - * An element which can be the target of annotations. - * - * @author Federico Tomassetti - * @since July 2014 - */ -public interface AnnotableNode { - public List getAnnotations(); -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/AnnotationDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/AnnotationDeclaration.java index 18f03c7..aa793ef 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/AnnotationDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/AnnotationDeclaration.java @@ -1,72 +1,142 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class AnnotationDeclaration extends TypeDeclaration implements DocumentableNode { - - public AnnotationDeclaration() { - } - - public AnnotationDeclaration(int modifiers, String name) { - super(modifiers, name); - } - - public AnnotationDeclaration(int modifiers, List annotations, String name, List members) { - super(annotations, modifiers, name, members); - } - - public AnnotationDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, String name, List members) { - super(beginLine, beginColumn, endLine, endColumn, annotations, modifiers, name, members); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.AnnotationDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An annotation type declaration.
@interface X { ... } + * + * @author Julio Vilmar Gesser + */ +public final class AnnotationDeclaration extends TypeDeclaration implements NodeWithAbstractModifier, Resolvable { + + public AnnotationDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>()); + } + + public AnnotationDeclaration(EnumSet modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>()); + } + + @AllFieldsConstructor + public AnnotationDeclaration(EnumSet modifiers, NodeList annotations, SimpleName name, NodeList> members) { + this(null, modifiers, annotations, name, members); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public AnnotationDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, SimpleName name, NodeList> members) { + super(tokenRange, modifiers, annotations, name, members); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public AnnotationDeclaration clone() { + return (AnnotationDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public AnnotationDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.annotationDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationDeclaration asAnnotationDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedAnnotationDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedAnnotationDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java index ff92d71..48b6db6 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java @@ -1,134 +1,275 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.NamedNode; -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.type.Type; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class AnnotationMemberDeclaration extends BodyDeclaration implements DocumentableNode, NamedNode { - - private int modifiers; - - private Type type; - - private String name; - - private Expression defaultValue; - - public AnnotationMemberDeclaration() { - } - - public AnnotationMemberDeclaration(int modifiers, Type type, String name, Expression defaultValue) { - setModifiers(modifiers); - setType(type); - setName(name); - setDefaultValue(defaultValue); - } - - public AnnotationMemberDeclaration(int modifiers, List annotations, Type type, String name, Expression defaultValue) { - super(annotations); - setModifiers(modifiers); - setType(type); - setName(name); - setDefaultValue(defaultValue); - } - - public AnnotationMemberDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, Type type, String name, Expression defaultValue) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setModifiers(modifiers); - setType(type); - setName(name); - setDefaultValue(defaultValue); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Expression getDefaultValue() { - return defaultValue; - } - - /** - * Return the modifiers of this member declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public String getName() { - return name; - } - - public Type getType() { - return type; - } - - public void setDefaultValue(Expression defaultValue) { - this.defaultValue = defaultValue; - setAsParentNodeOf(defaultValue); - } - - public void setModifiers(int modifiers) { - this.modifiers = modifiers; - } - - public void setName(String name) { - this.name = name; - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(type); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.AnnotationMemberDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import javax.annotation.Generated; +import java.util.EnumSet; +import java.util.Optional; +import java.util.function.Consumer; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * The "int id();" in @interface X { int id(); } + *

+ *
All annotations preceding the type will be set on this object, not on the type. JavaParser doesn't know if it + * they are applicable to the method or the type. + * + * @author Julio Vilmar Gesser + */ +public final class AnnotationMemberDeclaration extends BodyDeclaration implements NodeWithJavadoc, NodeWithSimpleName, NodeWithType, NodeWithPublicModifier, NodeWithAbstractModifier, Resolvable { + + private EnumSet modifiers; + + private Type type; + + private SimpleName name; + + @OptionalProperty + private Expression defaultValue; + + public AnnotationMemberDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), null); + } + + public AnnotationMemberDeclaration(EnumSet modifiers, Type type, String name, Expression defaultValue) { + this(null, modifiers, new NodeList<>(), type, new SimpleName(name), defaultValue); + } + + @AllFieldsConstructor + public AnnotationMemberDeclaration(EnumSet modifiers, NodeList annotations, Type type, SimpleName name, Expression defaultValue) { + this(null, modifiers, annotations, type, name, defaultValue); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public AnnotationMemberDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, Type type, SimpleName name, Expression defaultValue) { + super(tokenRange, annotations); + setModifiers(modifiers); + setType(type); + setName(name); + setDefaultValue(defaultValue); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getDefaultValue() { + return Optional.ofNullable(defaultValue); + } + + /** + * Return the modifiers of this member declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public AnnotationMemberDeclaration removeDefaultValue() { + return setDefaultValue((Expression) null); + } + + /** + * Sets the default value + * + * @param defaultValue the default value, can be null + * @return this, the AnnotationMemberDeclaration + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AnnotationMemberDeclaration setDefaultValue(final Expression defaultValue) { + if (defaultValue == this.defaultValue) { + return (AnnotationMemberDeclaration) this; + } + notifyPropertyChange(ObservableProperty.DEFAULT_VALUE, this.defaultValue, defaultValue); + if (this.defaultValue != null) + this.defaultValue.setParentNode(null); + this.defaultValue = defaultValue; + setAsParentNodeOf(defaultValue); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AnnotationMemberDeclaration setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (AnnotationMemberDeclaration) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AnnotationMemberDeclaration setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (AnnotationMemberDeclaration) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AnnotationMemberDeclaration setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (AnnotationMemberDeclaration) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (defaultValue != null) { + if (node == defaultValue) { + removeDefaultValue(); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public AnnotationMemberDeclaration clone() { + return (AnnotationMemberDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public AnnotationMemberDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.annotationMemberDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (defaultValue != null) { + if (node == defaultValue) { + setDefaultValue((Expression) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationMemberDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationMemberDeclaration asAnnotationMemberDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationMemberDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedAnnotationMemberDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedAnnotationMemberDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationMemberDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/BaseParameter.java b/JavaParser/src/com/github/javaparser/ast/body/BaseParameter.java deleted file mode 100644 index cca4c3a..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/BaseParameter.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.AnnotationExpr; - -import java.util.List; - -public abstract class BaseParameter extends Node { - private int modifiers; - - private List annotations; - - private VariableDeclaratorId id; - - public BaseParameter() { - } - - public BaseParameter(VariableDeclaratorId id) { - setId(id); - } - - public BaseParameter(int modifiers, VariableDeclaratorId id) { - setModifiers(modifiers); - setId(id); - } - - public BaseParameter(int modifiers, List annotations, VariableDeclaratorId id) { - setModifiers(modifiers); - setAnnotations(annotations); - setId(id); - } - - public BaseParameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, VariableDeclaratorId id) { - super(beginLine, beginColumn, endLine, endColumn); - setModifiers(modifiers); - setAnnotations(annotations); - setId(id); - } - - public List getAnnotations() { - return annotations; - } - - public VariableDeclaratorId getId() { - return id; - } - - /** - * Return the modifiers of this parameter declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public void setAnnotations(List annotations) { - this.annotations = annotations; - setAsParentNodeOf(this.annotations); - } - - public void setId(VariableDeclaratorId id) { - this.id = id; - setAsParentNodeOf(this.id); - } - - public void setModifiers(int modifiers) { - this.modifiers = modifiers; - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/BodyDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/BodyDeclaration.java index f1eb1f3..dc871e3 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/BodyDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/BodyDeclaration.java @@ -1,59 +1,339 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.AnnotationExpr; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class BodyDeclaration extends Node implements AnnotableNode { - - private List annotations; - - public BodyDeclaration() { - } - - public BodyDeclaration(List annotations) { - setAnnotations(annotations); - } - - public BodyDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, List annotations) { - super(beginLine, beginColumn, endLine, endColumn); - setAnnotations(annotations); - } - - public final List getAnnotations() { - if (annotations==null){ - annotations = new ArrayList(); - } - return annotations; - } - - public final void setAnnotations(List annotations) { - this.annotations = annotations; - setAsParentNodeOf(this.annotations); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BodyDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import java.util.Optional; + +/** + * Any declaration that can appear between the { and } of a class, interface, or enum. + * + * @author Julio Vilmar Gesser + */ +public abstract class BodyDeclaration> extends Node implements NodeWithAnnotations { + + private NodeList annotations; + + public BodyDeclaration() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public BodyDeclaration(NodeList annotations) { + this(null, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BodyDeclaration(TokenRange tokenRange, NodeList annotations) { + super(tokenRange); + setAnnotations(annotations); + customInitialization(); + } + + protected BodyDeclaration(TokenRange range) { + this(range, new NodeList<>()); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return (T) this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BodyDeclaration clone() { + return (BodyDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BodyDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.bodyDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationDeclaration asAnnotationDeclaration() { + throw new IllegalStateException(f("%s is not an AnnotationDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationMemberDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationMemberDeclaration asAnnotationMemberDeclaration() { + throw new IllegalStateException(f("%s is not an AnnotationMemberDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCallableDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CallableDeclaration asCallableDeclaration() { + throw new IllegalStateException(f("%s is not an CallableDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassOrInterfaceDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassOrInterfaceDeclaration asClassOrInterfaceDeclaration() { + throw new IllegalStateException(f("%s is not an ClassOrInterfaceDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isConstructorDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ConstructorDeclaration asConstructorDeclaration() { + throw new IllegalStateException(f("%s is not an ConstructorDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnumConstantDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnumConstantDeclaration asEnumConstantDeclaration() { + throw new IllegalStateException(f("%s is not an EnumConstantDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnumDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnumDeclaration asEnumDeclaration() { + throw new IllegalStateException(f("%s is not an EnumDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isFieldDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public FieldDeclaration asFieldDeclaration() { + throw new IllegalStateException(f("%s is not an FieldDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isInitializerDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public InitializerDeclaration asInitializerDeclaration() { + throw new IllegalStateException(f("%s is not an InitializerDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodDeclaration asMethodDeclaration() { + throw new IllegalStateException(f("%s is not an MethodDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeDeclaration() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeDeclaration asTypeDeclaration() { + throw new IllegalStateException(f("%s is not an TypeDeclaration", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationMemberDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCallableDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConstructorDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumConstantDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInitializerDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeDeclaration(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationMemberDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCallableDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassOrInterfaceDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toConstructorDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnumConstantDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnumDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toFieldDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toInitializerDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeDeclaration() { + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/CallableDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/CallableDeclaration.java new file mode 100644 index 0000000..e2e41fe --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/body/CallableDeclaration.java @@ -0,0 +1,428 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.nodeTypes.modifiers.*; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.CallableDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import javax.annotation.Generated; +import java.util.EnumSet; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import java.util.Optional; +import java.util.function.Consumer; + +/** + * Represents a declaration which is callable eg. a method or a constructor. + */ +public abstract class CallableDeclaration> extends BodyDeclaration implements NodeWithAccessModifiers, NodeWithDeclaration, NodeWithSimpleName, NodeWithParameters, NodeWithThrownExceptions, NodeWithTypeParameters, NodeWithJavadoc, NodeWithAbstractModifier, NodeWithStaticModifier, NodeWithFinalModifier, NodeWithStrictfpModifier { + + private EnumSet modifiers; + + private NodeList typeParameters; + + private SimpleName name; + + private NodeList parameters; + + private NodeList thrownExceptions; + + @OptionalProperty + private ReceiverParameter receiverParameter; + + @AllFieldsConstructor + CallableDeclaration(EnumSet modifiers, NodeList annotations, NodeList typeParameters, SimpleName name, NodeList parameters, NodeList thrownExceptions, ReceiverParameter receiverParameter) { + this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public CallableDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, NodeList typeParameters, SimpleName name, NodeList parameters, NodeList thrownExceptions, ReceiverParameter receiverParameter) { + super(tokenRange, annotations); + setModifiers(modifiers); + setTypeParameters(typeParameters); + setName(name); + setParameters(parameters); + setThrownExceptions(thrownExceptions); + setReceiverParameter(receiverParameter); + customInitialization(); + } + + /** + * Return the modifiers of this member declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getParameters() { + return parameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setParameters(final NodeList parameters) { + assertNotNull(parameters); + if (parameters == this.parameters) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.PARAMETERS, this.parameters, parameters); + if (this.parameters != null) + this.parameters.setParentNode(null); + this.parameters = parameters; + setAsParentNodeOf(parameters); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getThrownExceptions() { + return thrownExceptions; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setThrownExceptions(final NodeList thrownExceptions) { + assertNotNull(thrownExceptions); + if (thrownExceptions == this.thrownExceptions) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.THROWN_EXCEPTIONS, this.thrownExceptions, thrownExceptions); + if (this.thrownExceptions != null) + this.thrownExceptions.setParentNode(null); + this.thrownExceptions = thrownExceptions; + setAsParentNodeOf(thrownExceptions); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getTypeParameters() { + return typeParameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setTypeParameters(final NodeList typeParameters) { + assertNotNull(typeParameters); + if (typeParameters == this.typeParameters) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.TYPE_PARAMETERS, this.typeParameters, typeParameters); + if (this.typeParameters != null) + this.typeParameters.setParentNode(null); + this.typeParameters = typeParameters; + setAsParentNodeOf(typeParameters); + return (T) this; + } + + public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows) { + return getDeclarationAsString(includingModifiers, includingThrows, true); + } + + public String getDeclarationAsString() { + return getDeclarationAsString(true, true, true); + } + + public abstract String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName); + + protected String appendThrowsIfRequested(boolean includingThrows) { + StringBuilder sb = new StringBuilder(); + if (includingThrows) { + boolean firstThrow = true; + for (ReferenceType thr : getThrownExceptions()) { + if (firstThrow) { + firstThrow = false; + sb.append(" throws "); + } else { + sb.append(", "); + } + sb.append(thr.toString(prettyPrinterNoCommentsConfiguration)); + } + } + return sb.toString(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < parameters.size(); i++) { + if (parameters.get(i) == node) { + parameters.remove(i); + return true; + } + } + if (receiverParameter != null) { + if (node == receiverParameter) { + removeReceiverParameter(); + return true; + } + } + for (int i = 0; i < thrownExceptions.size(); i++) { + if (thrownExceptions.get(i) == node) { + thrownExceptions.remove(i); + return true; + } + } + for (int i = 0; i < typeParameters.size(); i++) { + if (typeParameters.get(i) == node) { + typeParameters.remove(i); + return true; + } + } + return super.remove(node); + } + + /** + * A method or constructor signature. + *

Note that since JavaParser has no real knowledge of types - only the text found in the source file - using + * this will fail in some cases. (java.util.String != String for example, and generics are not taken into account.) + */ + public static class Signature { + + private final String name; + + private final List parameterTypes; + + private Signature(String name, List parameterTypes) { + this.name = name; + this.parameterTypes = parameterTypes; + } + + public String getName() { + return name; + } + + public List getParameterTypes() { + return parameterTypes; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Signature signature = (Signature) o; + if (!name.equals(signature.name)) + return false; + if (!parameterTypes.equals(signature.parameterTypes)) + return false; + return true; + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + parameterTypes.hashCode(); + return result; + } + + public String asString() { + return parameterTypes.stream().map(Type::asString).collect(joining(", ", name + "(", ")")); + } + + @Override + public String toString() { + return asString(); + } + } + + public Signature getSignature() { + return new Signature(getName().getIdentifier(), getParameters().stream().map(this::getTypeWithVarargsAsArray).map(this::stripGenerics).map(this::stripAnnotations).collect(toList())); + } + + private Type stripAnnotations(Type type) { + if (type instanceof NodeWithAnnotations) { + ((NodeWithAnnotations) type).setAnnotations(new NodeList<>()); + } + return type; + } + + private Type stripGenerics(Type type) { + if (type instanceof NodeWithTypeArguments) { + ((NodeWithTypeArguments) type).setTypeArguments((NodeList) null); + } + return type; + } + + private Type getTypeWithVarargsAsArray(Parameter p) { + /* A signature includes the varargs ellipsis. + This is a field on parameter which we lose when we only get the type, + so we represent it as an additional [] on the type. */ + Type t = p.getType().clone(); + if (p.isVarArgs()) { + t = new ArrayType(t); + } + return t; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public CallableDeclaration clone() { + return (CallableDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CallableDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.callableDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + for (int i = 0; i < parameters.size(); i++) { + if (parameters.get(i) == node) { + parameters.set(i, (Parameter) replacementNode); + return true; + } + } + if (receiverParameter != null) { + if (node == receiverParameter) { + setReceiverParameter((ReceiverParameter) replacementNode); + return true; + } + } + for (int i = 0; i < thrownExceptions.size(); i++) { + if (thrownExceptions.get(i) == node) { + thrownExceptions.set(i, (ReferenceType) replacementNode); + return true; + } + } + for (int i = 0; i < typeParameters.size(); i++) { + if (typeParameters.get(i) == node) { + typeParameters.set(i, (TypeParameter) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCallableDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CallableDeclaration asCallableDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCallableDeclaration(Consumer action) { + action.accept(this); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getReceiverParameter() { + return Optional.ofNullable(receiverParameter); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setReceiverParameter(final ReceiverParameter receiverParameter) { + if (receiverParameter == this.receiverParameter) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.RECEIVER_PARAMETER, this.receiverParameter, receiverParameter); + if (this.receiverParameter != null) + this.receiverParameter.setParentNode(null); + this.receiverParameter = receiverParameter; + setAsParentNodeOf(receiverParameter); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public CallableDeclaration removeReceiverParameter() { + return setReceiverParameter((ReceiverParameter) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCallableDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java index be77a36..a275066 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java @@ -1,132 +1,286 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -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.type.ClassOrInterfaceType; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ClassOrInterfaceDeclaration extends TypeDeclaration implements DocumentableNode { - - private boolean interface_; - - private List typeParameters; - - // Can contain more than one item if this is an interface - private List extendsList; - - private List implementsList; - - public ClassOrInterfaceDeclaration() { - } - - public ClassOrInterfaceDeclaration(final int modifiers, final boolean isInterface, final String name) { - super(modifiers, name); - setInterface(isInterface); - } - - public ClassOrInterfaceDeclaration(final int modifiers, - final List annotations, final boolean isInterface, final String name, - final List typeParameters, final List extendsList, - final List implementsList, final List members) { - super(annotations, modifiers, name, members); - setInterface(isInterface); - setTypeParameters(typeParameters); - setExtends(extendsList); - setImplements(implementsList); - } - - public ClassOrInterfaceDeclaration(final int beginLine, final int beginColumn, final int endLine, - final int endColumn, final int modifiers, - final List annotations, final boolean isInterface, final String name, - final List typeParameters, final List extendsList, - final List implementsList, final List members) { - super(beginLine, beginColumn, endLine, endColumn, annotations, modifiers, name, members); - setInterface(isInterface); - setTypeParameters(typeParameters); - setExtends(extendsList); - setImplements(implementsList); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getExtends() { - return extendsList; - } - - public List getImplements() { - return implementsList; - } - - public List getTypeParameters() { - return typeParameters; - } - - public boolean isInterface() { - return interface_; - } - - public void setExtends(final List extendsList) { - this.extendsList = extendsList; - setAsParentNodeOf(this.extendsList); - } - - public void setImplements(final List implementsList) { - this.implementsList = implementsList; - setAsParentNodeOf(this.implementsList); - } - - public void setInterface(final boolean interface_) { - this.interface_ = interface_; - } - - public void setTypeParameters(final List typeParameters) { - this.typeParameters = typeParameters; - setAsParentNodeOf(this.typeParameters); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithConstructors; +import com.github.javaparser.ast.nodeTypes.NodeWithExtends; +import com.github.javaparser.ast.nodeTypes.NodeWithImplements; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.ClassOrInterfaceDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import javax.annotation.Generated; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A definition of a class or interface.
class X { ... } + * + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceDeclaration extends TypeDeclaration implements NodeWithImplements, NodeWithExtends, NodeWithTypeParameters, NodeWithAbstractModifier, NodeWithFinalModifier, NodeWithConstructors, Resolvable { + + private boolean isInterface; + + private NodeList typeParameters; + + // Can contain more than one item if this is an interface + private NodeList extendedTypes; + + private NodeList implementedTypes; + + public ClassOrInterfaceDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), false, new SimpleName(), new NodeList<>(), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + public ClassOrInterfaceDeclaration(final EnumSet modifiers, final boolean isInterface, final String name) { + this(null, modifiers, new NodeList<>(), isInterface, new SimpleName(name), new NodeList<>(), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + @AllFieldsConstructor + public ClassOrInterfaceDeclaration(final EnumSet modifiers, final NodeList annotations, final boolean isInterface, final SimpleName name, final NodeList typeParameters, final NodeList extendedTypes, final NodeList implementedTypes, final NodeList> members) { + this(null, modifiers, annotations, isInterface, name, typeParameters, extendedTypes, implementedTypes, members); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ClassOrInterfaceDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, boolean isInterface, SimpleName name, NodeList typeParameters, NodeList extendedTypes, NodeList implementedTypes, NodeList> members) { + super(tokenRange, modifiers, annotations, name, members); + setInterface(isInterface); + setTypeParameters(typeParameters); + setExtendedTypes(extendedTypes); + setImplementedTypes(implementedTypes); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getExtendedTypes() { + return extendedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getImplementedTypes() { + return implementedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getTypeParameters() { + return typeParameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isInterface() { + return isInterface; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceDeclaration setExtendedTypes(final NodeList extendedTypes) { + assertNotNull(extendedTypes); + if (extendedTypes == this.extendedTypes) { + return (ClassOrInterfaceDeclaration) this; + } + notifyPropertyChange(ObservableProperty.EXTENDED_TYPES, this.extendedTypes, extendedTypes); + if (this.extendedTypes != null) + this.extendedTypes.setParentNode(null); + this.extendedTypes = extendedTypes; + setAsParentNodeOf(extendedTypes); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceDeclaration setImplementedTypes(final NodeList implementedTypes) { + assertNotNull(implementedTypes); + if (implementedTypes == this.implementedTypes) { + return (ClassOrInterfaceDeclaration) this; + } + notifyPropertyChange(ObservableProperty.IMPLEMENTED_TYPES, this.implementedTypes, implementedTypes); + if (this.implementedTypes != null) + this.implementedTypes.setParentNode(null); + this.implementedTypes = implementedTypes; + setAsParentNodeOf(implementedTypes); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceDeclaration setInterface(final boolean isInterface) { + if (isInterface == this.isInterface) { + return (ClassOrInterfaceDeclaration) this; + } + notifyPropertyChange(ObservableProperty.INTERFACE, this.isInterface, isInterface); + this.isInterface = isInterface; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceDeclaration setTypeParameters(final NodeList typeParameters) { + assertNotNull(typeParameters); + if (typeParameters == this.typeParameters) { + return (ClassOrInterfaceDeclaration) this; + } + notifyPropertyChange(ObservableProperty.TYPE_PARAMETERS, this.typeParameters, typeParameters); + if (this.typeParameters != null) + this.typeParameters.setParentNode(null); + this.typeParameters = typeParameters; + setAsParentNodeOf(typeParameters); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < extendedTypes.size(); i++) { + if (extendedTypes.get(i) == node) { + extendedTypes.remove(i); + return true; + } + } + for (int i = 0; i < implementedTypes.size(); i++) { + if (implementedTypes.get(i) == node) { + implementedTypes.remove(i); + return true; + } + } + for (int i = 0; i < typeParameters.size(); i++) { + if (typeParameters.get(i) == node) { + typeParameters.remove(i); + return true; + } + } + return super.remove(node); + } + + /** + * @return is this class's parent a LocalClassDeclarationStmt ? + */ + public boolean isLocalClassDeclaration() { + return getParentNode().map(p -> p instanceof LocalClassDeclarationStmt).orElse(false); + } + + /** + * @return is this an inner class? + * NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html . + */ + public boolean isInnerClass() { + return isNestedType() && !isInterface && !isStatic(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ClassOrInterfaceDeclaration clone() { + return (ClassOrInterfaceDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ClassOrInterfaceDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.classOrInterfaceDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < extendedTypes.size(); i++) { + if (extendedTypes.get(i) == node) { + extendedTypes.set(i, (ClassOrInterfaceType) replacementNode); + return true; + } + } + for (int i = 0; i < implementedTypes.size(); i++) { + if (implementedTypes.get(i) == node) { + implementedTypes.set(i, (ClassOrInterfaceType) replacementNode); + return true; + } + } + for (int i = 0; i < typeParameters.size(); i++) { + if (typeParameters.get(i) == node) { + typeParameters.set(i, (TypeParameter) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassOrInterfaceDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassOrInterfaceDeclaration asClassOrInterfaceDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedReferenceTypeDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedReferenceTypeDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassOrInterfaceDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/ConstructorDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/ConstructorDeclaration.java index d5c23a8..ab1dad9 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/ConstructorDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/ConstructorDeclaration.java @@ -1,232 +1,248 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import java.util.List; -import java.util.ArrayList; - -import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.NamedNode; -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.stmt.BlockStmt; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.ast.type.Type; - -/** - * @author Julio Vilmar Gesser - */ -public final class ConstructorDeclaration extends BodyDeclaration implements DocumentableNode, WithDeclaration, NamedNode { - - private int modifiers; - - private List typeParameters; - - private NameExpr name; - - private List parameters; - - private List throws_; - - private BlockStmt block; - - public ConstructorDeclaration() { - } - - public ConstructorDeclaration(int modifiers, String name) { - setModifiers(modifiers); - setName(name); - } - - public ConstructorDeclaration(int modifiers, List annotations, List typeParameters, String name, List parameters, List throws_, BlockStmt block) { - super(annotations); - setModifiers(modifiers); - setTypeParameters(typeParameters); - setName(name); - setParameters(parameters); - setThrows(throws_); - setBlock(block); - } - - public ConstructorDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, List typeParameters, String name, List parameters, List throws_, BlockStmt block) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setModifiers(modifiers); - setTypeParameters(typeParameters); - setName(name); - setParameters(parameters); - setThrows(throws_); - setBlock(block); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public BlockStmt getBlock() { - return block; - } - - /** - * Return the modifiers of this member declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public String getName() { - return name == null ? null : name.getName(); - } - - public NameExpr getNameExpr() { - return name; - } - - public List getParameters() { - if (parameters == null) { - parameters = new ArrayList(); - } - return parameters; - } - - public List getThrows() { - if (throws_ == null) { - throws_ = new ArrayList(); - } - return throws_; - } - - public List getTypeParameters() { - return typeParameters; - } - - public void setBlock(BlockStmt block) { - this.block = block; - setAsParentNodeOf(this.block); - } - - public void setModifiers(int modifiers) { - this.modifiers = modifiers; - } - - public void setName(String name) { - this.name = new NameExpr(name); - } - - public void setNameExpr(NameExpr name) { - this.name = name; - } - - public void setParameters(List parameters) { - this.parameters = parameters; - setAsParentNodeOf(this.parameters); - } - - public void setThrows(List throws_) { - this.throws_ = throws_; - setAsParentNodeOf(this.throws_); - } - - public void setTypeParameters(List 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) { - StringBuffer sb = new StringBuffer(); - if (includingModifiers) { - AccessSpecifier accessSpecifier = ModifierSet.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 (NameExpr 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 void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.ast.AccessSpecifier; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ConstructorDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A constructor declaration: class X { X() { } } where X(){} is the constructor declaration. + * + *
All annotations preceding the name will be set on this object, not on the class. + * JavaParser doesn't know if it they are applicable to the method or the class. + * + * @author Julio Vilmar Gesser + */ +public final class ConstructorDeclaration extends CallableDeclaration implements NodeWithBlockStmt, NodeWithAccessModifiers, NodeWithJavadoc, NodeWithSimpleName, NodeWithParameters, NodeWithThrownExceptions, NodeWithTypeParameters, Resolvable { + + private BlockStmt body; + + public ConstructorDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public ConstructorDeclaration(String name) { + this(null, EnumSet.of(Modifier.PUBLIC), new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public ConstructorDeclaration(EnumSet modifiers, String name) { + this(null, modifiers, new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public ConstructorDeclaration(EnumSet modifiers, NodeList annotations, NodeList typeParameters, SimpleName name, NodeList parameters, NodeList thrownExceptions, BlockStmt body) { + this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, null); + } + + @AllFieldsConstructor + public ConstructorDeclaration(EnumSet modifiers, NodeList annotations, NodeList typeParameters, SimpleName name, NodeList parameters, NodeList thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { + this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ConstructorDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, NodeList typeParameters, SimpleName name, NodeList parameters, NodeList thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { + super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt getBody() { + return body; + } + + /** + * Sets the body + * + * @param body the body, can not be null + * @return this, the ConstructorDeclaration + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ConstructorDeclaration setBody(final BlockStmt body) { + assertNotNull(body); + if (body == this.body) { + return (ConstructorDeclaration) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Override + public ConstructorDeclaration setModifiers(final EnumSet modifiers) { + return super.setModifiers(modifiers); + } + + @Override + public ConstructorDeclaration setName(final SimpleName name) { + return super.setName(name); + } + + @Override + public ConstructorDeclaration setParameters(final NodeList parameters) { + return super.setParameters(parameters); + } + + @Override + public ConstructorDeclaration setThrownExceptions(final NodeList thrownExceptions) { + return super.setThrownExceptions(thrownExceptions); + } + + @Override + public ConstructorDeclaration setTypeParameters(final NodeList typeParameters) { + return super.setTypeParameters(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.asString()); + 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.toString(prettyPrinterNoCommentsConfiguration)); + } else { + sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); + } + } + sb.append(")"); + sb.append(appendThrowsIfRequested(includingThrows)); + return sb.toString(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ConstructorDeclaration clone() { + return (ConstructorDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ConstructorDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.constructorDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((BlockStmt) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isConstructorDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ConstructorDeclaration asConstructorDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConstructorDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedConstructorDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toConstructorDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/EmptyMemberDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/EmptyMemberDeclaration.java deleted file mode 100644 index 96f0fac..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/EmptyMemberDeclaration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class EmptyMemberDeclaration extends BodyDeclaration implements DocumentableNode { - - public EmptyMemberDeclaration() { - super(null); - } - - public EmptyMemberDeclaration(int beginLine, int beginColumn, int endLine, int endColumn) { - super(beginLine, beginColumn, endLine, endColumn, null); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/EmptyTypeDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/EmptyTypeDeclaration.java deleted file mode 100644 index 79d4d71..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/EmptyTypeDeclaration.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class EmptyTypeDeclaration extends TypeDeclaration implements DocumentableNode { - - public EmptyTypeDeclaration() { - super(null, 0, null, null); - } - - public EmptyTypeDeclaration(int beginLine, int beginColumn, int endLine, int endColumn) { - super(beginLine, beginColumn, endLine, endColumn, null, 0, null, null); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - @Override - public JavadocComment getJavaDoc() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/EnumConstantDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/EnumConstantDeclaration.java index a872d20..5a331e4 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/EnumConstantDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/EnumConstantDeclaration.java @@ -1,112 +1,239 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.NamedNode; -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.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class EnumConstantDeclaration extends BodyDeclaration implements DocumentableNode, NamedNode { - - private String name; - - private List args; - - private List classBody; - - public EnumConstantDeclaration() { - } - - public EnumConstantDeclaration(String name) { - setName(name); - } - - public EnumConstantDeclaration(List annotations, String name, List args, List classBody) { - super(annotations); - setName(name); - setArgs(args); - setClassBody(classBody); - } - - public EnumConstantDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, List annotations, String name, List args, List classBody) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setName(name); - setArgs(args); - setClassBody(classBody); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public List getArgs() { - return args; - } - - public List getClassBody() { - return classBody; - } - - public String getName() { - return name; - } - - public void setArgs(List args) { - this.args = args; - setAsParentNodeOf(this.args); - } - - public void setClassBody(List classBody) { - this.classBody = classBody; - setAsParentNodeOf(this.classBody); - } - - public void setName(String name) { - this.name = name; - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.EnumConstantDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * One of the values an enum can take. A(1) and B(2) in this example: enum X { A(1), B(2) } + * + * @author Julio Vilmar Gesser + */ +public final class EnumConstantDeclaration extends BodyDeclaration implements NodeWithJavadoc, NodeWithSimpleName, NodeWithArguments, Resolvable { + + private SimpleName name; + + private NodeList arguments; + + private NodeList> classBody; + + public EnumConstantDeclaration() { + this(null, new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>()); + } + + public EnumConstantDeclaration(String name) { + this(null, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>()); + } + + @AllFieldsConstructor + public EnumConstantDeclaration(NodeList annotations, SimpleName name, NodeList arguments, NodeList> classBody) { + this(null, annotations, name, arguments, classBody); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public EnumConstantDeclaration(TokenRange tokenRange, NodeList annotations, SimpleName name, NodeList arguments, NodeList> classBody) { + super(tokenRange, annotations); + setName(name); + setArguments(arguments); + setClassBody(classBody); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getArguments() { + return arguments; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList> getClassBody() { + return classBody; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumConstantDeclaration setArguments(final NodeList arguments) { + assertNotNull(arguments); + if (arguments == this.arguments) { + return (EnumConstantDeclaration) this; + } + notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments); + if (this.arguments != null) + this.arguments.setParentNode(null); + this.arguments = arguments; + setAsParentNodeOf(arguments); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumConstantDeclaration setClassBody(final NodeList> classBody) { + assertNotNull(classBody); + if (classBody == this.classBody) { + return (EnumConstantDeclaration) this; + } + notifyPropertyChange(ObservableProperty.CLASS_BODY, this.classBody, classBody); + if (this.classBody != null) + this.classBody.setParentNode(null); + this.classBody = classBody; + setAsParentNodeOf(classBody); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumConstantDeclaration setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (EnumConstantDeclaration) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.remove(i); + return true; + } + } + for (int i = 0; i < classBody.size(); i++) { + if (classBody.get(i) == node) { + classBody.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public EnumConstantDeclaration clone() { + return (EnumConstantDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public EnumConstantDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.enumConstantDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.set(i, (Expression) replacementNode); + return true; + } + } + for (int i = 0; i < classBody.size(); i++) { + if (classBody.get(i) == node) { + classBody.set(i, (BodyDeclaration) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnumConstantDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnumConstantDeclaration asEnumConstantDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumConstantDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedEnumConstantDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedEnumConstantDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnumConstantDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/EnumDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/EnumDeclaration.java index e93e3b1..44fb1e4 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/EnumDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/EnumDeclaration.java @@ -1,100 +1,233 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -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; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class EnumDeclaration extends TypeDeclaration implements DocumentableNode { - - private List implementsList; - - private List entries; - - public EnumDeclaration() { - } - - public EnumDeclaration(int modifiers, String name) { - super(modifiers, name); - } - - public EnumDeclaration(int modifiers, List annotations, String name, List implementsList, List entries, List members) { - super(annotations, modifiers, name, members); - setImplements(implementsList); - setEntries(entries); - } - - public EnumDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, String name, List implementsList, List entries, List members) { - super(beginLine, beginColumn, endLine, endColumn, annotations, modifiers, name, members); - setImplements(implementsList); - setEntries(entries); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public List getEntries() { - return entries; - } - - public List getImplements() { - return implementsList; - } - - public void setEntries(List entries) { - this.entries = entries; - setAsParentNodeOf(this.entries); - } - - public void setImplements(List implementsList) { - this.implementsList = implementsList; - setAsParentNodeOf(this.implementsList); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithConstructors; +import com.github.javaparser.ast.nodeTypes.NodeWithImplements; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.EnumDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; +import javax.annotation.Generated; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNonEmpty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * The declaration of an enum.
enum X { ... } + * + * @author Julio Vilmar Gesser + */ +public final class EnumDeclaration extends TypeDeclaration implements NodeWithImplements, NodeWithConstructors, Resolvable { + + private NodeList implementedTypes; + + private NodeList entries; + + public EnumDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + public EnumDeclaration(EnumSet modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + @AllFieldsConstructor + public EnumDeclaration(EnumSet modifiers, NodeList annotations, SimpleName name, NodeList implementedTypes, NodeList entries, NodeList> members) { + this(null, modifiers, annotations, name, implementedTypes, entries, members); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public EnumDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, SimpleName name, NodeList implementedTypes, NodeList entries, NodeList> members) { + super(tokenRange, modifiers, annotations, name, members); + setImplementedTypes(implementedTypes); + setEntries(entries); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getEntries() { + return entries; + } + + public EnumConstantDeclaration getEntry(int i) { + return getEntries().get(i); + } + + public EnumDeclaration setEntry(int i, EnumConstantDeclaration element) { + getEntries().set(i, element); + return this; + } + + public EnumDeclaration addEntry(EnumConstantDeclaration element) { + getEntries().add(element); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getImplementedTypes() { + return implementedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumDeclaration setEntries(final NodeList entries) { + assertNotNull(entries); + if (entries == this.entries) { + return (EnumDeclaration) this; + } + notifyPropertyChange(ObservableProperty.ENTRIES, this.entries, entries); + if (this.entries != null) + this.entries.setParentNode(null); + this.entries = entries; + setAsParentNodeOf(entries); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumDeclaration setImplementedTypes(final NodeList implementedTypes) { + assertNotNull(implementedTypes); + if (implementedTypes == this.implementedTypes) { + return (EnumDeclaration) this; + } + notifyPropertyChange(ObservableProperty.IMPLEMENTED_TYPES, this.implementedTypes, implementedTypes); + if (this.implementedTypes != null) + this.implementedTypes.setParentNode(null); + this.implementedTypes = implementedTypes; + setAsParentNodeOf(implementedTypes); + return this; + } + + public EnumConstantDeclaration addEnumConstant(String name) { + assertNonEmpty(name); + EnumConstantDeclaration enumConstant = new EnumConstantDeclaration(name); + getEntries().add(enumConstant); + return enumConstant; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i) == node) { + entries.remove(i); + return true; + } + } + for (int i = 0; i < implementedTypes.size(); i++) { + if (implementedTypes.get(i) == node) { + implementedTypes.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public EnumDeclaration clone() { + return (EnumDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public EnumDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.enumDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i) == node) { + entries.set(i, (EnumConstantDeclaration) replacementNode); + return true; + } + } + for (int i = 0; i < implementedTypes.size(); i++) { + if (implementedTypes.get(i) == node) { + implementedTypes.set(i, (ClassOrInterfaceType) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnumDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnumDeclaration asEnumDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedEnumDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedEnumDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnumDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/FieldDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/FieldDeclaration.java index 7568ae8..547e95a 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/FieldDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/FieldDeclaration.java @@ -1,128 +1,307 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -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; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class FieldDeclaration extends BodyDeclaration implements DocumentableNode { - - private int modifiers; - - private Type type; - - private List variables; - - public FieldDeclaration() { - } - - public FieldDeclaration(int modifiers, Type type, VariableDeclarator variable) { - setModifiers(modifiers); - setType(type); - List aux = new ArrayList(); - aux.add(variable); - setVariables(aux); - } - - public FieldDeclaration(int modifiers, Type type, List variables) { - setModifiers(modifiers); - setType(type); - setVariables(variables); - } - - public FieldDeclaration(int modifiers, List annotations, Type type, List variables) { - super(annotations); - setModifiers(modifiers); - setType(type); - setVariables(variables); - } - - public FieldDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, Type type, List variables) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setModifiers(modifiers); - setType(type); - setVariables(variables); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - /** - * Return the modifiers of this member declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public Type getType() { - return type; - } - - public List getVariables() { - return variables; - } - - public void setModifiers(int modifiers) { - this.modifiers = modifiers; - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - public void setVariables(List variables) { - this.variables = variables; - setAsParentNodeOf(this.variables); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.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.NodeWithVariables; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +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.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.FieldDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.ast.Modifier.*; +import static com.github.javaparser.ast.NodeList.nodeList; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; +import java.util.function.Consumer; + +/** + * The declaration of a field in a class. "private static int a=15*15;" in this example: class X { private static + * int a=15*15; } + * + *
All annotations preceding the type will be set on this object, not on the type. + * JavaParser doesn't know if it they are applicable to the method or the type. + * + * @author Julio Vilmar Gesser + */ +public final class FieldDeclaration extends BodyDeclaration implements NodeWithJavadoc, NodeWithVariables, NodeWithAccessModifiers, NodeWithStaticModifier, NodeWithFinalModifier, Resolvable { + + private EnumSet modifiers; + + @NonEmptyProperty + private NodeList variables; + + public FieldDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>()); + } + + public FieldDeclaration(EnumSet modifiers, VariableDeclarator variable) { + this(null, modifiers, new NodeList<>(), nodeList(variable)); + } + + public FieldDeclaration(EnumSet modifiers, NodeList variables) { + this(null, modifiers, new NodeList<>(), variables); + } + + @AllFieldsConstructor + public FieldDeclaration(EnumSet modifiers, NodeList annotations, NodeList variables) { + this(null, modifiers, annotations, variables); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public FieldDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, NodeList variables) { + super(tokenRange, annotations); + setModifiers(modifiers); + setVariables(variables); + customInitialization(); + } + + /** + * Creates a {@link FieldDeclaration}. + * + * @param modifiers modifiers + * @param type type + * @param name field name + */ + public FieldDeclaration(EnumSet modifiers, Type type, String name) { + this(assertNotNull(modifiers), new VariableDeclarator(type, assertNotNull(name))); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Return the modifiers of this member declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getVariables() { + return variables; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldDeclaration setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (FieldDeclaration) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldDeclaration setVariables(final NodeList variables) { + assertNotNull(variables); + if (variables == this.variables) { + return (FieldDeclaration) this; + } + notifyPropertyChange(ObservableProperty.VARIABLES, this.variables, variables); + if (this.variables != null) + this.variables.setParentNode(null); + this.variables = variables; + setAsParentNodeOf(variables); + return this; + } + + /** + * Create a getter for this field, will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration + * + * @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"); + Optional parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class); + Optional parentEnum = getAncestorOfType(EnumDeclaration.class); + if (!(parentClass.isPresent() || parentEnum.isPresent()) || (parentClass.isPresent() && parentClass.get().isInterface())) + throw new IllegalStateException("You can use this only when the field is attached to a class or an enum"); + VariableDeclarator variable = getVariable(0); + String fieldName = variable.getNameAsString(); + String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); + final MethodDeclaration getter; + getter = parentClass.map(clazz -> clazz.addMethod("get" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("get" + fieldNameUpper, PUBLIC)); + getter.setType(variable.getType()); + BlockStmt blockStmt = new BlockStmt(); + getter.setBody(blockStmt); + blockStmt.addStatement(new ReturnStmt(fieldName)); + return getter; + } + + /** + * Create a setter for this field, will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration + * + * @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"); + Optional parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class); + Optional parentEnum = getAncestorOfType(EnumDeclaration.class); + if (!(parentClass.isPresent() || parentEnum.isPresent()) || (parentClass.isPresent() && parentClass.get().isInterface())) + throw new IllegalStateException("You can use this only when the field is attached to a class or an enum"); + VariableDeclarator variable = getVariable(0); + String fieldName = variable.getNameAsString(); + String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); + final MethodDeclaration setter; + setter = parentClass.map(clazz -> clazz.addMethod("set" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("set" + fieldNameUpper, PUBLIC)); + setter.setType(new VoidType()); + setter.getParameters().add(new Parameter(variable.getType(), fieldName)); + BlockStmt blockStmt2 = new BlockStmt(); + setter.setBody(blockStmt2); + blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.ASSIGN)); + return setter; + } + + public boolean isTransient() { + return getModifiers().contains(TRANSIENT); + } + + public boolean isVolatile() { + return getModifiers().contains(VOLATILE); + } + + public FieldDeclaration setTransient(boolean set) { + return setModifier(TRANSIENT, set); + } + + public FieldDeclaration setVolatile(boolean set) { + return setModifier(VOLATILE, set); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < variables.size(); i++) { + if (variables.get(i) == node) { + variables.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public FieldDeclaration clone() { + return (FieldDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public FieldDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.fieldDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < variables.size(); i++) { + if (variables.get(i) == node) { + variables.set(i, (VariableDeclarator) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isFieldDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public FieldDeclaration asFieldDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedFieldDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedFieldDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toFieldDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/InitializerDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/InitializerDeclaration.java index 6c2a5b7..06fe78e 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/InitializerDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/InitializerDeclaration.java @@ -1,91 +1,174 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.comments.JavadocComment; -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 implements DocumentableNode { - - private boolean isStatic; - - private BlockStmt block; - - public InitializerDeclaration() { - } - - public InitializerDeclaration(boolean isStatic, BlockStmt block) { - super(null); - setStatic(isStatic); - setBlock(block); - } - - public InitializerDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, boolean isStatic, BlockStmt block) { - super(beginLine, beginColumn, endLine, endColumn, null); - setStatic(isStatic); - setBlock(block); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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 void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt; +import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.InitializerDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A (possibly static) initializer body. "static { a=3; }" in this example: class X { static { a=3; } } + * + * @author Julio Vilmar Gesser + */ +public final class InitializerDeclaration extends BodyDeclaration implements NodeWithJavadoc, NodeWithBlockStmt { + + private boolean isStatic; + + private BlockStmt body; + + public InitializerDeclaration() { + this(null, false, new BlockStmt()); + } + + @AllFieldsConstructor + public InitializerDeclaration(boolean isStatic, BlockStmt body) { + this(null, isStatic, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public InitializerDeclaration(TokenRange tokenRange, boolean isStatic, BlockStmt body) { + super(tokenRange); + setStatic(isStatic); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isStatic() { + return isStatic; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public InitializerDeclaration setBody(final BlockStmt body) { + assertNotNull(body); + if (body == this.body) { + return (InitializerDeclaration) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public InitializerDeclaration setStatic(final boolean isStatic) { + if (isStatic == this.isStatic) { + return (InitializerDeclaration) this; + } + notifyPropertyChange(ObservableProperty.STATIC, this.isStatic, isStatic); + this.isStatic = isStatic; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public InitializerDeclaration clone() { + return (InitializerDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public InitializerDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.initializerDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((BlockStmt) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isInitializerDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public InitializerDeclaration asInitializerDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInitializerDeclaration(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toInitializerDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/MethodDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/MethodDeclaration.java index a13a163..dff4cad 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/MethodDeclaration.java @@ -1,304 +1,348 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.DocumentableNode; -import com.github.javaparser.ast.NamedNode; -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.stmt.BlockStmt; -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 java.util.ArrayList; - -/** - * @author Julio Vilmar Gesser - */ -public final class MethodDeclaration extends BodyDeclaration implements DocumentableNode, WithDeclaration, NamedNode { - - private int modifiers; - - private List typeParameters; - - private Type type; - - private NameExpr name; - - private List parameters; - - private int arrayCount; - - private List throws_; - - private BlockStmt body; - - private boolean isDefault = false; - - public MethodDeclaration() { - } - - public MethodDeclaration(final int modifiers, final Type type, final String name) { - setModifiers(modifiers); - setType(type); - setName(name); - } - - public MethodDeclaration(final int modifiers, final Type type, final String name, final List parameters) { - setModifiers(modifiers); - setType(type); - setName(name); - setParameters(parameters); - } - - public MethodDeclaration(final int modifiers, final List annotations, - final List typeParameters, final Type type, final String name, - final List parameters, final int arrayCount, final List throws_, final BlockStmt block) { - super(annotations); - setModifiers(modifiers); - setTypeParameters(typeParameters); - setType(type); - setName(name); - setParameters(parameters); - setArrayCount(arrayCount); - setThrows(throws_); - setBody(block); - } - - public MethodDeclaration(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final int modifiers, final List annotations, - final List typeParameters, final Type type, final String name, - final List parameters, final int arrayCount, final List throws_, final BlockStmt block) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setModifiers(modifiers); - setTypeParameters(typeParameters); - setType(type); - setName(name); - setParameters(parameters); - setArrayCount(arrayCount); - setThrows(throws_); - setBody(block); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public int getArrayCount() { - return arrayCount; - } - - // FIXME this is called "Block" in the constructor. Pick one. - public BlockStmt getBody() { - return body; - } - - /** - * Return the modifiers of this member declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public String getName() { - return name.getName(); - } - - public NameExpr getNameExpr() { - return name; - } - - public List getParameters() { - if (parameters == null) { - parameters = new ArrayList(); - } - return parameters; - } - - public List getThrows() { - if (throws_ == null) { - throws_ = new ArrayList(); - } - return throws_; - } - - public Type getType() { - return type; - } - - public List getTypeParameters() { - return typeParameters; - } - - public void setArrayCount(final int arrayCount) { - this.arrayCount = arrayCount; - } - - public void setBody(final BlockStmt body) { - this.body = body; - setAsParentNodeOf(this.body); - } - - public void setModifiers(final int modifiers) { - this.modifiers = modifiers; - } - - public void setName(final String name) { - this.name = new NameExpr(name); - } - - public void setNameExpr(final NameExpr name) { - this.name = name; - } - - public void setParameters(final List parameters) { - this.parameters = parameters; - setAsParentNodeOf(this.parameters); - } - - public void setThrows(final List throws_) { - this.throws_ = throws_; - setAsParentNodeOf(this.throws_); - } - - public void setType(final Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - public void setTypeParameters(final List typeParameters) { - this.typeParameters = typeParameters; - setAsParentNodeOf(typeParameters); - } - - - public boolean isDefault() { - return isDefault; - } - - public void setDefault(boolean isDefault) { - this.isDefault = isDefault; - } - - - @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) { - StringBuffer sb = new StringBuffer(); - if (includingModifiers) { - AccessSpecifier accessSpecifier = ModifierSet.getAccessSpecifier(getModifiers()); - sb.append(accessSpecifier.getCodeRepresenation()); - sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " "); - if (ModifierSet.isStatic(getModifiers())){ - sb.append("static "); - } - if (ModifierSet.isAbstract(getModifiers())){ - sb.append("abstract "); - } - if (ModifierSet.isFinal(getModifiers())){ - sb.append("final "); - } - if (ModifierSet.isNative(getModifiers())){ - sb.append("native "); - } - if (ModifierSet.isSynchronized(getModifiers())){ - 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 (NameExpr thr : getThrows()) { - if (firstThrow) { - firstThrow = false; - sb.append(" throws "); - } else { - sb.append(", "); - } - sb.append(thr.toStringWithoutComments()); - } - } - return sb.toString(); - } - - @Override - public void setJavaDoc(JavadocComment javadocComment) { - this.javadocComment = javadocComment; - } - - @Override - public JavadocComment getJavaDoc() { - return javadocComment; - } - - private JavadocComment javadocComment; -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.ast.AccessSpecifier; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.nodeTypes.modifiers.*; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.EnumSet; +import java.util.Optional; +import static com.github.javaparser.ast.Modifier.*; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.MethodDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import java.util.function.Consumer; + +/** + * A method declaration. "public int abc() {return 1;}" in this example: class X { public int abc() {return 1;} + * } + * + *
All annotations preceding the return type will be set on this object, not on the return type. + * JavaParser doesn't know if it they are applicable to the method or the type. + * + * @author Julio Vilmar Gesser + */ +public final class MethodDeclaration extends CallableDeclaration implements NodeWithType, NodeWithOptionalBlockStmt, NodeWithJavadoc, NodeWithDeclaration, NodeWithSimpleName, NodeWithParameters, NodeWithThrownExceptions, NodeWithTypeParameters, NodeWithAccessModifiers, NodeWithAbstractModifier, NodeWithStaticModifier, NodeWithFinalModifier, NodeWithStrictfpModifier, Resolvable { + + private Type type; + + @OptionalProperty + private BlockStmt body; + + public MethodDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public MethodDeclaration(final EnumSet modifiers, final Type type, final String name) { + this(null, modifiers, new NodeList<>(), new NodeList<>(), type, new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public MethodDeclaration(final EnumSet modifiers, final String name, final Type type, final NodeList parameters) { + this(null, modifiers, new NodeList<>(), new NodeList<>(), type, new SimpleName(name), parameters, new NodeList<>(), new BlockStmt(), null); + } + + public MethodDeclaration(final EnumSet modifiers, final NodeList annotations, final NodeList typeParameters, final Type type, final SimpleName name, final NodeList parameters, final NodeList thrownExceptions, final BlockStmt body) { + this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, null); + } + + @AllFieldsConstructor + public MethodDeclaration(final EnumSet modifiers, final NodeList annotations, final NodeList typeParameters, final Type type, final SimpleName name, final NodeList parameters, final NodeList thrownExceptions, final BlockStmt body, ReceiverParameter receiverParameter) { + this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, receiverParameter); + } + + /** + * @deprecated this constructor allows you to set "isDefault", but this is no longer a field of this node, but simply one of the modifiers. Use setDefault(boolean) or add DEFAULT to the modifiers set. + */ + @Deprecated + public MethodDeclaration(final EnumSet modifiers, final NodeList annotations, final NodeList typeParameters, final Type type, final SimpleName name, final boolean isDefault, final NodeList parameters, final NodeList thrownExceptions, final BlockStmt body) { + this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, null); + setDefault(isDefault); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public MethodDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, NodeList typeParameters, Type type, SimpleName name, NodeList parameters, NodeList thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { + super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); + setType(type); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getBody() { + return Optional.ofNullable(body); + } + + /** + * Sets the body + * + * @param body the body, can be null + * @return this, the MethodDeclaration + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodDeclaration setBody(final BlockStmt body) { + if (body == this.body) { + return (MethodDeclaration) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodDeclaration setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (MethodDeclaration) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + public MethodDeclaration setModifiers(final EnumSet modifiers) { + return super.setModifiers(modifiers); + } + + @Override + public MethodDeclaration setName(final SimpleName name) { + return super.setName(name); + } + + @Override + public MethodDeclaration setParameters(final NodeList parameters) { + return super.setParameters(parameters); + } + + @Override + public MethodDeclaration setThrownExceptions(final NodeList thrownExceptions) { + return super.setThrownExceptions(thrownExceptions); + } + + @Override + public MethodDeclaration setTypeParameters(final NodeList typeParameters) { + return super.setTypeParameters(typeParameters); + } + + /** + * 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 = getAccessSpecifier(getModifiers()); + sb.append(accessSpecifier.asString()); + sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " "); + if (getModifiers().contains(STATIC)) { + sb.append("static "); + } + if (getModifiers().contains(ABSTRACT)) { + sb.append("abstract "); + } + if (getModifiers().contains(FINAL)) { + sb.append("final "); + } + if (getModifiers().contains(NATIVE)) { + sb.append("native "); + } + if (getModifiers().contains(SYNCHRONIZED)) { + sb.append("synchronized "); + } + } + sb.append(getType().toString(prettyPrinterNoCommentsConfiguration)); + 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.toString(prettyPrinterNoCommentsConfiguration)); + } else { + sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); + if (param.isVarArgs()) { + sb.append("..."); + } + } + } + sb.append(")"); + sb.append(appendThrowsIfRequested(includingThrows)); + return sb.toString(); + } + + public boolean isNative() { + return getModifiers().contains(NATIVE); + } + + public boolean isSynchronized() { + return getModifiers().contains(SYNCHRONIZED); + } + + public boolean isDefault() { + return getModifiers().contains(DEFAULT); + } + + public MethodDeclaration setNative(boolean set) { + return setModifier(NATIVE, set); + } + + public MethodDeclaration setSynchronized(boolean set) { + return setModifier(SYNCHRONIZED, set); + } + + public MethodDeclaration setDefault(boolean set) { + return setModifier(DEFAULT, set); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (body != null) { + if (node == body) { + removeBody(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public MethodDeclaration removeBody() { + return setBody((BlockStmt) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public MethodDeclaration clone() { + return (MethodDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public MethodDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.methodDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (body != null) { + if (node == body) { + setBody((BlockStmt) replacementNode); + return true; + } + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodDeclaration asMethodDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodDeclaration(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedMethodDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedMethodDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/ModifierSet.java b/JavaParser/src/com/github/javaparser/ast/body/ModifierSet.java deleted file mode 100644 index 4963fdc..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/ModifierSet.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.AccessSpecifier; - -import java.lang.reflect.Modifier; - -/** - * Class to hold modifiers.
- * The modifier constants declared here holds equivalent values to - * {@link Modifier} constants. - */ -public final class ModifierSet { - - /* Definitions of the bits in the modifiers field. */ - - public static final int PUBLIC = Modifier.PUBLIC; - - public static final int PRIVATE = Modifier.PRIVATE; - - public static final int PROTECTED = Modifier.PROTECTED; - - public static final int STATIC = Modifier.STATIC; - - public static final int FINAL = Modifier.FINAL; - - public static final int SYNCHRONIZED = Modifier.SYNCHRONIZED; - - public static final int VOLATILE = Modifier.VOLATILE; - - public static final int TRANSIENT = Modifier.TRANSIENT; - - public static final int NATIVE = Modifier.NATIVE; - - public static final int ABSTRACT = Modifier.ABSTRACT; - - public static final int STRICTFP = Modifier.STRICT; - - public static AccessSpecifier getAccessSpecifier(int modifiers) { - if (isPublic(modifiers)){ - return AccessSpecifier.PUBLIC; - } else if (isProtected(modifiers)){ - return AccessSpecifier.PROTECTED; - } else if (isPrivate(modifiers)){ - return AccessSpecifier.PRIVATE; - } else { - return AccessSpecifier.DEFAULT; - } - } - - public static int addModifier(int modifiers, int mod) { - return modifiers | mod; - } - - public static boolean hasModifier(int modifiers, int modifier) { - return (modifiers & modifier) != 0; - } - - public static boolean isAbstract(int modifiers) { - return (modifiers & ABSTRACT) != 0; - } - - public static boolean isFinal(int modifiers) { - return (modifiers & FINAL) != 0; - } - - public static boolean isNative(int modifiers) { - return (modifiers & NATIVE) != 0; - } - - public static boolean isPrivate(int modifiers) { - return (modifiers & PRIVATE) != 0; - } - - public static boolean isProtected(int modifiers) { - return (modifiers & PROTECTED) != 0; - } - - /** - * Is the element accessible from within the package? - * It is the level of access which is applied if no modifiers are chosen, - * it is sometimes called "default". - * @param modifiers indicator - * @return true if modifier denotes package level access - */ - public static boolean hasPackageLevelAccess(int modifiers) { - return !isPublic(modifiers) && !isProtected(modifiers) && !isPrivate(modifiers); - } - - public static boolean isPublic(int modifiers) { - return (modifiers & PUBLIC) != 0; - } - - public static boolean isStatic(int modifiers) { - return (modifiers & STATIC) != 0; - } - - public static boolean isStrictfp(int modifiers) { - return (modifiers & STRICTFP) != 0; - } - - public static boolean isSynchronized(int modifiers) { - return (modifiers & SYNCHRONIZED) != 0; - } - - public static boolean isTransient(int modifiers) { - return (modifiers & TRANSIENT) != 0; - } - - public static boolean isVolatile(int modifiers) { - return (modifiers & VOLATILE) != 0; - } - - /** - * Removes the given modifier. - * @param modifiers existing modifiers - * @param mod modifier to be removed - * @return result for removing modifier - */ - public static int removeModifier(int modifiers, int mod) { - return modifiers & ~mod; - } - - private ModifierSet() { - } -} \ No newline at end of file diff --git a/JavaParser/src/com/github/javaparser/ast/body/MultiTypeParameter.java b/JavaParser/src/com/github/javaparser/ast/body/MultiTypeParameter.java deleted file mode 100644 index 2885144..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/MultiTypeParameter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -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; - -import java.util.List; - -public class MultiTypeParameter extends BaseParameter { - private List types; - - public MultiTypeParameter() {} - - public MultiTypeParameter(int modifiers, List annotations, List types, VariableDeclaratorId id) { - super(modifiers, annotations, id); - this.types = types; - } - - public MultiTypeParameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, List types, VariableDeclaratorId id) { - super(beginLine, beginColumn, endLine, endColumn, modifiers, annotations, id); - this.types = types; - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public
void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public List getTypes() { - return types; - } - - public void setTypes(List types) { - this.types = types; - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/body/Parameter.java b/JavaParser/src/com/github/javaparser/ast/body/Parameter.java index cb7d4c2..a7cf357 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/Parameter.java +++ b/JavaParser/src/com/github/javaparser/ast/body/Parameter.java @@ -1,83 +1,311 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -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; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class Parameter extends BaseParameter { - private Type type; - - private boolean isVarArgs; - - public Parameter() { - } - - public Parameter(Type type, VariableDeclaratorId id) { - super(id); - setType(type); - } - - public Parameter(int modifiers, Type type, VariableDeclaratorId id) { - super(modifiers, id); - setType(type); - } - - public Parameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List annotations, Type type, boolean isVarArgs, VariableDeclaratorId id) { - super(beginLine, beginColumn, endLine, endColumn, modifiers, annotations, id); - setType(type); - setVarArgs(isVarArgs); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Type getType() { - return type; - } - - public boolean isVarArgs() { - return isVarArgs; - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - public void setVarArgs(boolean isVarArgs) { - this.isVarArgs = isVarArgs; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ParameterMetaModel; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; + +/** + * The parameters to a method or lambda. Lambda parameters may have inferred types, in that case "type" is UnknownType. + *
Note that
parameters + * are different from arguments.
"String x" and "float y" are the parameters in int abc(String x, float + * y) {...} + * + *
All annotations preceding the type will be set on this object, not on the type. + * JavaParser doesn't know if it they are applicable to the parameter or the type. + * + * @author Julio Vilmar Gesser + */ +public final class Parameter extends Node implements NodeWithType, NodeWithAnnotations, NodeWithSimpleName, NodeWithFinalModifier, Resolvable { + + private Type type; + + private boolean isVarArgs; + + private NodeList varArgsAnnotations; + + private EnumSet modifiers; + + private NodeList annotations; + + private SimpleName name; + + public Parameter() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new ClassOrInterfaceType(), false, new NodeList<>(), new SimpleName()); + } + + public Parameter(Type type, SimpleName name) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), type, false, new NodeList<>(), name); + } + + /** + * Creates a new {@link Parameter}. + * + * @param type type of the parameter + * @param name name of the parameter + */ + public Parameter(Type type, String name) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), type, false, new NodeList<>(), new SimpleName(name)); + } + + public Parameter(EnumSet modifiers, Type type, SimpleName name) { + this(null, modifiers, new NodeList<>(), type, false, new NodeList<>(), name); + } + + @AllFieldsConstructor + public Parameter(EnumSet modifiers, NodeList annotations, Type type, boolean isVarArgs, NodeList varArgsAnnotations, SimpleName name) { + this(null, modifiers, annotations, type, isVarArgs, varArgsAnnotations, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Parameter(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, Type type, boolean isVarArgs, NodeList varArgsAnnotations, SimpleName name) { + super(tokenRange); + setModifiers(modifiers); + setAnnotations(annotations); + setType(type); + setVarArgs(isVarArgs); + setVarArgsAnnotations(varArgsAnnotations); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isVarArgs() { + return isVarArgs; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setVarArgs(final boolean isVarArgs) { + if (isVarArgs == this.isVarArgs) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.VAR_ARGS, this.isVarArgs, isVarArgs); + this.isVarArgs = isVarArgs; + return this; + } + + /** + * @return the list returned could be immutable (in that case it will be empty) + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + /** + * Return the modifiers of this parameter declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet 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 + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + for (int i = 0; i < varArgsAnnotations.size(); i++) { + if (varArgsAnnotations.get(i) == node) { + varArgsAnnotations.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getVarArgsAnnotations() { + return varArgsAnnotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setVarArgsAnnotations(final NodeList varArgsAnnotations) { + assertNotNull(varArgsAnnotations); + if (varArgsAnnotations == this.varArgsAnnotations) { + return (Parameter) this; + } + notifyPropertyChange(ObservableProperty.VAR_ARGS_ANNOTATIONS, this.varArgsAnnotations, varArgsAnnotations); + if (this.varArgsAnnotations != null) + this.varArgsAnnotations.setParentNode(null); + this.varArgsAnnotations = varArgsAnnotations; + setAsParentNodeOf(varArgsAnnotations); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Parameter clone() { + return (Parameter) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ParameterMetaModel getMetaModel() { + return JavaParserMetaModel.parameterMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + for (int i = 0; i < varArgsAnnotations.size(); i++) { + if (varArgsAnnotations.get(i) == node) { + varArgsAnnotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + public ResolvedParameterDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedParameterDeclaration.class); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/ReceiverParameter.java b/JavaParser/src/com/github/javaparser/ast/body/ReceiverParameter.java new file mode 100644 index 0000000..b0038e1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/body/ReceiverParameter.java @@ -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.body; + +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ParameterMetaModel; +import javax.annotation.Generated; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.metamodel.ReceiverParameterMetaModel; + +/** + * The rather obscure "receiver parameter" feature of Java. + * + *
All annotations preceding the type will be set on this object, not on the type. + * JavaParser doesn't know if it they are applicable to the receiver parameter or the type. + * + * @author Julio Vilmar Gesser + */ +public final class ReceiverParameter extends Node implements NodeWithType, NodeWithAnnotations, NodeWithName { + + private Type type; + + private NodeList annotations; + + private Name name; + + public ReceiverParameter() { + this(null, new NodeList<>(), new ClassOrInterfaceType(), new Name()); + } + + public ReceiverParameter(Type type, Name name) { + this(null, new NodeList<>(), type, name); + } + + /** + * Creates a new {@link ReceiverParameter}. + * + * @param type type of the parameter + * @param name name of the parameter + */ + public ReceiverParameter(Type type, String name) { + this(null, new NodeList<>(), type, new Name(name)); + } + + @AllFieldsConstructor + public ReceiverParameter(NodeList annotations, Type type, Name name) { + this(null, annotations, type, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ReceiverParameter(TokenRange tokenRange, NodeList annotations, Type type, Name name) { + super(tokenRange); + setAnnotations(annotations); + setType(type); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ReceiverParameter setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (ReceiverParameter) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + /** + * @return the list returned could be immutable (in that case it will be empty) + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + 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 + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ReceiverParameter setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (ReceiverParameter) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ReceiverParameter clone() { + return (ReceiverParameter) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ReceiverParameterMetaModel getMetaModel() { + return JavaParserMetaModel.receiverParameterMetaModel; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ReceiverParameter setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ReceiverParameter) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + if (node == name) { + setName((Name) replacementNode); + return true; + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/TypeDeclaration.java b/JavaParser/src/com/github/javaparser/ast/body/TypeDeclaration.java index dac3ea6..06f9753 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/TypeDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/body/TypeDeclaration.java @@ -1,105 +1,246 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.NamedNode; -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.expr.NameExpr; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class TypeDeclaration extends BodyDeclaration implements NamedNode { - - private NameExpr name; - - private int modifiers; - - private List members; - - public TypeDeclaration() { - } - - public TypeDeclaration(int modifiers, String name) { - setName(name); - setModifiers(modifiers); - } - - public TypeDeclaration(List annotations, - int modifiers, String name, - List members) { - super(annotations); - setName(name); - setModifiers(modifiers); - setMembers(members); - } - - public TypeDeclaration(int beginLine, int beginColumn, int endLine, - int endColumn, List annotations, - int modifiers, String name, - List members) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setName(name); - setModifiers(modifiers); - setMembers(members); - } - - public final List getMembers() { - return members; - } - - /** - * Return the modifiers of this type declaration. - * - * @see ModifierSet - * @return modifiers - */ - public final int getModifiers() { - return modifiers; - } - - public final String getName() { - return name.getName(); - } - - public void setMembers(List members) { - this.members = members; - setAsParentNodeOf(this.members); - } - - public final void setModifiers(int modifiers) { - this.modifiers = modifiers; - } - - public final void setName(String name) { - this.name = new NameExpr(name); - } - - public final void setNameExpr(NameExpr nameExpr) { - this.name = nameExpr; - } - - public final NameExpr getNameExpr() { - return name; - } -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; +import com.github.javaparser.ast.nodeTypes.NodeWithMembers; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStrictfpModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.TypeDeclarationMetaModel; +import javax.annotation.Generated; +import java.util.EnumSet; +import java.util.List; +import java.util.function.Consumer; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; +import com.github.javaparser.ast.Node; +import java.util.Optional; + +/** + * A base class for all types of type declarations. + * + * @author Julio Vilmar Gesser + */ +public abstract class TypeDeclaration> extends BodyDeclaration implements NodeWithSimpleName, NodeWithJavadoc, NodeWithMembers, NodeWithAccessModifiers, NodeWithStaticModifier, NodeWithStrictfpModifier { + + private SimpleName name; + + private EnumSet modifiers; + + private NodeList> members; + + public TypeDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>()); + } + + public TypeDeclaration(EnumSet modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>()); + } + + @AllFieldsConstructor + public TypeDeclaration(EnumSet modifiers, NodeList annotations, SimpleName name, NodeList> members) { + this(null, modifiers, annotations, name, members); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public TypeDeclaration(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, SimpleName name, NodeList> members) { + super(tokenRange, annotations); + setModifiers(modifiers); + setName(name); + setMembers(members); + customInitialization(); + } + + /** + * Adds the given declaration to the specified type. + * + * @param decl member declaration + */ + public T addMember(BodyDeclaration decl) { + NodeList> members = getMembers(); + members.add(decl); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList> getMembers() { + return members; + } + + /** + * Return the modifiers of this type declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setMembers(final NodeList> members) { + assertNotNull(members); + if (members == this.members) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.MEMBERS, this.members, members); + if (this.members != null) + this.members.setParentNode(null); + this.members = members; + setAsParentNodeOf(members); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (T) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < members.size(); i++) { + if (members.get(i) == node) { + members.remove(i); + return true; + } + } + return super.remove(node); + } + + /** + * @return is this type's parent a CompilationUnit? + */ + public boolean isTopLevelType() { + return getParentNode().map(p -> p instanceof CompilationUnit).orElse(false); + } + + /** + * @return methods or constructors whose signatures match the passed signature. + */ + public List> getCallablesWithSignature(CallableDeclaration.Signature signature) { + return getMembers().stream().filter(m -> m instanceof CallableDeclaration).map(m -> ((CallableDeclaration) m)).filter(m -> m.getSignature().equals(signature)).collect(toList()); + } + + /** + * @return is this type's parent a TypeDeclaration? + * NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html . + */ + public boolean isNestedType() { + return getParentNode().map(p -> p instanceof TypeDeclaration).orElse(false); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public TypeDeclaration clone() { + return (TypeDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public TypeDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.typeDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < members.size(); i++) { + if (members.get(i) == node) { + members.set(i, (BodyDeclaration) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeDeclaration() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeDeclaration asTypeDeclaration() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeDeclaration(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeDeclaration() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/VariableDeclarator.java b/JavaParser/src/com/github/javaparser/ast/body/VariableDeclarator.java index 9c68bc7..0d342ac 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/VariableDeclarator.java +++ b/JavaParser/src/com/github/javaparser/ast/body/VariableDeclarator.java @@ -1,82 +1,281 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -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); - } - - public VariableDeclarator(VariableDeclaratorId id, Expression init) { - setId(id); - setInit(init); - } - - public VariableDeclarator(int beginLine, int beginColumn, int endLine, int endColumn, VariableDeclaratorId id, Expression init) { - super(beginLine, beginColumn, endLine, endColumn); - setId(id); - setInit(init); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.observer.AstObserverAdapter; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.VariableDeclaratorMetaModel; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNonEmpty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; + +/** + * The declaration of a variable.
In int x = 14, y = 3; "int x = 14" and "int y = 3" are + * VariableDeclarators. + *

The type is on all of the variable declarators because, thanks to array brackets, each variable can have a different type. + * + * @author Julio Vilmar Gesser + */ +public final class VariableDeclarator extends Node implements NodeWithType, NodeWithSimpleName, Resolvable { + + private SimpleName name; + + @OptionalProperty + @NonEmptyProperty + private Expression initializer; + + private Type type; + + public VariableDeclarator() { + this(null, new ClassOrInterfaceType(), new SimpleName(), null); + } + + public VariableDeclarator(Type type, String variableName) { + this(null, type, new SimpleName(variableName), null); + } + + public VariableDeclarator(Type type, SimpleName name) { + this(null, type, name, null); + } + + public VariableDeclarator(Type type, String variableName, Expression initializer) { + this(null, type, new SimpleName(variableName), initializer); + } + + /** + * Defines the declaration of a variable. + * + * @param name The identifier for this variable. IE. The variables name. + * @param initializer What this variable should be initialized to. An {@link com.github.javaparser.ast.expr.AssignExpr} + * is unnecessary as the = operator is already added. + */ + @AllFieldsConstructor + public VariableDeclarator(Type type, SimpleName name, Expression initializer) { + this(null, type, name, initializer); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer) { + super(tokenRange); + setType(type); + setName(name); + setInitializer(initializer); + customInitialization(); + } + + @Override + protected void customInitialization() { + // We register an observer on the type property. When it is changed the MaximumCommonType is changes as well, + // because it is derived from the type of the variables it contains, for this reason we notify about the change + register(new AstObserverAdapter() { + + @Override + public void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + if (property == ObservableProperty.TYPE) { + VariableDeclarator vd = VariableDeclarator.this; + if (vd.getParentNode().isPresent() && vd.getParentNode().get() instanceof NodeWithVariables) { + NodeWithVariables nodeWithVariables = (NodeWithVariables) vd.getParentNode().get(); + // We calculate the value the property will assume after the change will be completed + Optional currentMaxCommonType = nodeWithVariables.getMaximumCommonType(); + List types = new LinkedList<>(); + int index = nodeWithVariables.getVariables().indexOf(vd); + for (int i = 0; i < nodeWithVariables.getVariables().size(); i++) { + if (i == index) { + types.add((Type) newValue); + } else { + types.add(nodeWithVariables.getVariable(i).getType()); + } + } + Optional newMaxCommonType = NodeWithVariables.calculateMaximumCommonType(types); + ((Node) nodeWithVariables).notifyPropertyChange(ObservableProperty.MAXIMUM_COMMON_TYPE, currentMaxCommonType.orElse(null), newMaxCommonType.orElse(null)); + } + } + } + }); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getInitializer() { + return Optional.ofNullable(initializer); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarator setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (VariableDeclarator) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + /** + * Sets the initializer expression + * + * @param initializer the initializer expression, can be null + * @return this, the VariableDeclarator + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarator setInitializer(final Expression initializer) { + if (initializer == this.initializer) { + return (VariableDeclarator) this; + } + notifyPropertyChange(ObservableProperty.INITIALIZER, this.initializer, initializer); + if (this.initializer != null) + this.initializer.setParentNode(null); + this.initializer = initializer; + setAsParentNodeOf(initializer); + return this; + } + + /** + * Will create a {@link NameExpr} with the initializer param + * + * @param init the initializer expression, can be null + * @return this, the VariableDeclarator + */ + public VariableDeclarator setInitializer(String init) { + return setInitializer(new NameExpr(assertNonEmpty(init))); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarator setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (VariableDeclarator) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (initializer != null) { + if (node == initializer) { + removeInitializer(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public VariableDeclarator removeInitializer() { + return setInitializer((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public VariableDeclarator clone() { + return (VariableDeclarator) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public VariableDeclaratorMetaModel getMetaModel() { + return JavaParserMetaModel.variableDeclaratorMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (initializer != null) { + if (node == initializer) { + setInitializer((Expression) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + public ResolvedFieldDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedFieldDeclaration.class); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/VariableDeclaratorId.java b/JavaParser/src/com/github/javaparser/ast/body/VariableDeclaratorId.java deleted file mode 100644 index b2c1dc5..0000000 --- a/JavaParser/src/com/github/javaparser/ast/body/VariableDeclaratorId.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -import com.github.javaparser.ast.NamedNode; -import com.github.javaparser.ast.Node; -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 NamedNode { - - private String name; - - private int arrayCount; - - public VariableDeclaratorId() { - } - - public VariableDeclaratorId(String name) { - setName(name); - } - - public VariableDeclaratorId(int beginLine, int beginColumn, int endLine, int endColumn, String name, int arrayCount) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setArrayCount(arrayCount); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public int getArrayCount() { - return arrayCount; - } - - public String getName() { - return name; - } - - public void setArrayCount(int arrayCount) { - this.arrayCount = arrayCount; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/BlockComment.java b/JavaParser/src/com/github/javaparser/ast/comments/BlockComment.java index 405dea3..8d30b28 100644 --- a/JavaParser/src/com/github/javaparser/ast/comments/BlockComment.java +++ b/JavaParser/src/com/github/javaparser/ast/comments/BlockComment.java @@ -1,57 +1,126 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.comments; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - *

- * AST node that represent block comments. - *

- * Block comments can has multi lines and are delimited by "/*" and - * "*/". - * - * @author Julio Vilmar Gesser - */ -public final class BlockComment extends Comment { - - public BlockComment() { - } - - public BlockComment(String content) { - super(content); - } - - public BlockComment(int beginLine, int beginColumn, int endLine, int endColumn, String content) { - super(beginLine, beginColumn, endLine, endColumn, content); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BlockCommentMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + *

+ * AST node that represent block comments. + *

+ * Block comments can has multi lines and are delimited by "/*" and + * "*/". + * + * @author Julio Vilmar Gesser + */ +public final class BlockComment extends Comment { + + public BlockComment() { + this(null, "empty"); + } + + @AllFieldsConstructor + public BlockComment(String content) { + this(null, content); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BlockComment(TokenRange tokenRange, String content) { + super(tokenRange, content); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BlockComment clone() { + return (BlockComment) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BlockCommentMetaModel getMetaModel() { + return JavaParserMetaModel.blockCommentMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBlockComment() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BlockComment asBlockComment() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBlockComment(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBlockComment() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/Comment.java b/JavaParser/src/com/github/javaparser/ast/comments/Comment.java index 79a76c1..0c5f6b4 100644 --- a/JavaParser/src/com/github/javaparser/ast/comments/Comment.java +++ b/JavaParser/src/com/github/javaparser/ast/comments/Comment.java @@ -1,111 +1,220 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.comments; - -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(int beginLine, int beginColumn, int endLine, int endColumn, String content) { - super(beginLine, beginColumn, endLine, endColumn); - 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 = commentedNode; - return; - } - if (commentedNode==this) - { - throw new IllegalArgumentException(); - } - if (commentedNode instanceof Comment) - { - throw new IllegalArgumentException(); - } - this.commentedNode = commentedNode; - } - - public boolean isOrphan() - { - return this.commentedNode == null; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.CommentMetaModel; +import com.github.javaparser.metamodel.InternalProperty; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * Abstract class for all AST nodes that represent comments. + * + * @author Julio Vilmar Gesser + * @see BlockComment + * @see LineComment + * @see JavadocComment + */ +public abstract class Comment extends Node { + + private String content; + + @InternalProperty + private Node commentedNode; + + @AllFieldsConstructor + public Comment(String content) { + this(null, content); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Comment(TokenRange tokenRange, String content) { + super(tokenRange); + setContent(content); + customInitialization(); + } + + /** + * Return the text of the comment. + * + * @return text of the comment + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public String getContent() { + return content; + } + + /** + * Sets the text of the comment. + * + * @param content the text of the comment to set + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Comment setContent(final String content) { + assertNotNull(content); + if (content == this.content) { + return (Comment) this; + } + notifyPropertyChange(ObservableProperty.CONTENT, this.content, content); + this.content = content; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLineComment() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LineComment asLineComment() { + throw new IllegalStateException(f("%s is not an LineComment", this)); + } + + public Optional getCommentedNode() { + return Optional.ofNullable(this.commentedNode); + } + + /** + * Sets the commentedNode + * + * @param commentedNode the commentedNode, can be null + * @return this, the Comment + */ + public Comment setCommentedNode(Node commentedNode) { + notifyPropertyChange(ObservableProperty.COMMENTED_NODE, this.commentedNode, commentedNode); + if (commentedNode == null) { + this.commentedNode = null; + return this; + } + if (commentedNode == this) { + throw new IllegalArgumentException(); + } + if (commentedNode instanceof Comment) { + throw new IllegalArgumentException(); + } + this.commentedNode = commentedNode; + return this; + } + + public boolean isOrphan() { + return this.commentedNode == null; + } + + @Override + public boolean remove() { + // the other are orphan comments and remove should work with them + if (this.commentedNode != null) { + this.commentedNode.setComment(null); + return true; + } else if (this.getParentNode().isPresent()) { + return this.getParentNode().get().removeOrphanComment(this); + } else { + return false; + } + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Comment clone() { + return (Comment) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CommentMetaModel getMetaModel() { + return JavaParserMetaModel.commentMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBlockComment() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BlockComment asBlockComment() { + throw new IllegalStateException(f("%s is not an BlockComment", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isJavadocComment() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public JavadocComment asJavadocComment() { + throw new IllegalStateException(f("%s is not an JavadocComment", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBlockComment(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifJavadocComment(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLineComment(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBlockComment() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toJavadocComment() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLineComment() { + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/CommentsCollection.java b/JavaParser/src/com/github/javaparser/ast/comments/CommentsCollection.java index 7da4fc6..f3f2577 100644 --- a/JavaParser/src/com/github/javaparser/ast/comments/CommentsCollection.java +++ b/JavaParser/src/com/github/javaparser/ast/comments/CommentsCollection.java @@ -1,104 +1,112 @@ - -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -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 lineComments = new LinkedList(); - private List blockComments = new LinkedList(); - private List javadocComments = new LinkedList(); - - public List getLineComments(){ - return lineComments; - } - - public List getBlockComments(){ - return blockComments; - } - - public List 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 tollerate a difference of one element in the end column: - // it depends how \r and \n are calculated... - if ( c.getBeginLine()==comment.getBeginLine() && - c.getBeginColumn()==comment.getBeginColumn() && - c.getEndLine()==comment.getEndLine() && - Math.abs(c.getEndColumn()-comment.getEndColumn())<2 ){ - return true; - } - } - return false; - } - - public List getAll(){ - List comments = new LinkedList(); - 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; - } -} +/* + * 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 java.util.Collection; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; + +/** + * The comments contained in a certain parsed piece of source code. + */ +public class CommentsCollection { + private final TreeSet comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); + + public CommentsCollection() { + } + + public CommentsCollection(Collection commentsToCopy) { + comments.addAll(commentsToCopy); + } + + public Set getLineComments() { + return comments.stream() + .filter(comment -> comment instanceof LineComment) + .map(comment -> (LineComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set getBlockComments() { + return comments.stream() + .filter(comment -> comment instanceof BlockComment) + .map(comment -> (BlockComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set getJavadocComments() { + return comments.stream() + .filter(comment -> comment instanceof JavadocComment) + .map(comment -> (JavadocComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public void addComment(Comment comment) { + comments.add(comment); + } + + public boolean contains(Comment comment) { + if (!comment.getRange().isPresent()) { + return false; + } + Range commentRange = comment.getRange().get(); + for (Comment c : getComments()) { + if (!c.getRange().isPresent()) { + return false; + } + Range cRange = c.getRange().get(); + // we tolerate a difference of one element in the end column: + // it depends how \r and \n are calculated... + if (cRange.begin.equals(commentRange.begin) && + cRange.end.line == commentRange.end.line && + Math.abs(cRange.end.column - commentRange.end.column) < 2) { + return true; + } + } + return false; + } + + public TreeSet getComments() { + return comments; + } + + public int size() { + return comments.size(); + } + + public CommentsCollection minus(CommentsCollection other) { + CommentsCollection result = new CommentsCollection(); + result.comments.addAll( + comments.stream() + .filter(comment -> !other.contains(comment)) + .collect(Collectors.toList())); + return result; + } + + public CommentsCollection copy() { + return new CommentsCollection(comments); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/CommentsParser.java b/JavaParser/src/com/github/javaparser/ast/comments/CommentsParser.java deleted file mode 100644 index aa93585..0000000 --- a/JavaParser/src/com/github/javaparser/ast/comments/CommentsParser.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.comments; - -import java.io.*; -import java.nio.charset.Charset; -import java.util.*; - -/** - * This parser cares exclusively about comments. - */ -public class CommentsParser { - - private enum State { - CODE, - IN_LINE_COMMENT, - IN_BLOCK_COMMENT, - IN_STRING; - } - - private static final int COLUMNS_PER_TAB = 4; - - public CommentsCollection parse(final String source) throws IOException, UnsupportedEncodingException { - InputStream in = new ByteArrayInputStream(source.getBytes(Charset.defaultCharset())); - return parse(in, Charset.defaultCharset().name()); - } - - public CommentsCollection parse(final InputStream in, final String charsetName) throws IOException, UnsupportedEncodingException { - boolean lastWasASlashR = false; - BufferedReader br = new BufferedReader(new InputStreamReader(in, charsetName)); - CommentsCollection comments = new CommentsCollection(); - int r; - - Deque prevTwoChars = new LinkedList(Arrays.asList('z','z')); - - State state = State.CODE; - LineComment currentLineComment = null; - BlockComment currentBlockComment = null; - StringBuffer 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 (prevTwoChars.peekLast().equals('/') && c == '/') { - currentLineComment = new LineComment(); - currentLineComment.setBeginLine(currLine); - currentLineComment.setBeginColumn(currCol - 1); - state = State.IN_LINE_COMMENT; - currentContent = new StringBuffer(); - } else if (prevTwoChars.peekLast().equals('/') && c == '*') { - currentBlockComment = new BlockComment(); - currentBlockComment.setBeginLine(currLine); - currentBlockComment.setBeginColumn(currCol - 1); - state = State.IN_BLOCK_COMMENT; - currentContent = new StringBuffer(); - } else if (c == '"') { - state = State.IN_STRING; - } else { - // nothing to do - } - break; - case IN_LINE_COMMENT: - if (c=='\n' || c=='\r'){ - currentLineComment.setContent(currentContent.toString()); - currentLineComment.setEndLine(currLine); - currentLineComment.setEndColumn(currCol); - comments.addComment(currentLineComment); - state = State.CODE; - } else { - currentContent.append(c); - } - break; - case IN_BLOCK_COMMENT: - if (prevTwoChars.peekLast().equals('*') && c=='/' && !prevTwoChars.peekFirst().equals('/')){ - - // 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.setBeginLine(currentBlockComment.getBeginLine()); - javadocComment.setBeginColumn(currentBlockComment.getBeginColumn()); - javadocComment.setEndLine(currLine); - javadocComment.setEndColumn(currCol+1); - comments.addComment(javadocComment); - } else { - currentBlockComment.setContent(content); - currentBlockComment.setEndLine(currLine); - currentBlockComment.setEndColumn(currCol+1); - comments.addComment(currentBlockComment); - } - state = State.CODE; - } else { - currentContent.append(c=='\r'?'\n':c); - } - break; - case IN_STRING: - if (!prevTwoChars.peekLast().equals('\\') && 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; - } - prevTwoChars.remove(); - prevTwoChars.add(c); - } - - if (state==State.IN_LINE_COMMENT){ - currentLineComment.setContent(currentContent.toString()); - currentLineComment.setEndLine(currLine); - currentLineComment.setEndColumn(currCol); - comments.addComment(currentLineComment); - } - - return comments; - } - -} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/JavadocComment.java b/JavaParser/src/com/github/javaparser/ast/comments/JavadocComment.java index d7221a4..d795997 100644 --- a/JavaParser/src/com/github/javaparser/ast/comments/JavadocComment.java +++ b/JavaParser/src/com/github/javaparser/ast/comments/JavadocComment.java @@ -1,51 +1,128 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.comments; - -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(int beginLine, int beginColumn, int endLine, int endColumn, String content) { - super(beginLine, beginColumn, endLine, endColumn, content); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } -} +/* + * 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.JavaParser; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavadocCommentMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A Javadoc comment. /** a comment */ + * + * @author Julio Vilmar Gesser + */ +public final class JavadocComment extends Comment { + + public JavadocComment() { + this(null, "empty"); + } + + @AllFieldsConstructor + public JavadocComment(String content) { + this(null, content); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public JavadocComment(TokenRange tokenRange, String content) { + super(tokenRange, content); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + public Javadoc parse() { + return JavaParser.parseJavadoc(getContent()); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public JavadocComment clone() { + return (JavadocComment) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public JavadocCommentMetaModel getMetaModel() { + return JavaParserMetaModel.javadocCommentMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isJavadocComment() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public JavadocComment asJavadocComment() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifJavadocComment(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toJavadocComment() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/comments/LineComment.java b/JavaParser/src/com/github/javaparser/ast/comments/LineComment.java index eb063b0..ddbce80 100644 --- a/JavaParser/src/com/github/javaparser/ast/comments/LineComment.java +++ b/JavaParser/src/com/github/javaparser/ast/comments/LineComment.java @@ -1,61 +1,125 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.comments; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - *

- * AST node that represent line comments. - *

- * 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(int beginLine, int beginColumn, int endLine, int endColumn, String content) { - super(beginLine, beginColumn, endLine, endColumn, content); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public
void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public boolean isLineComment() - { - return true; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.LineCommentMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + *

+ * AST node that represent line comments. + *

+ * Line comments start with "//" and finish at the end of the line ("\n"). + * + * @author Julio Vilmar Gesser + */ +public final class LineComment extends Comment { + + public LineComment() { + this(null, "empty"); + } + + @AllFieldsConstructor + public LineComment(String content) { + this(null, content); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LineComment(TokenRange tokenRange, String content) { + super(tokenRange, content); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLineComment() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LineComment clone() { + return (LineComment) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LineCommentMetaModel getMetaModel() { + return JavaParserMetaModel.lineCommentMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LineComment asLineComment() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLineComment(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLineComment() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/AnnotationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/AnnotationExpr.java index 067e5db..31c70fb 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/AnnotationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/AnnotationExpr.java @@ -1,45 +1,137 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class AnnotationExpr extends Expression { - - protected NameExpr name; - - public AnnotationExpr() {} - - public AnnotationExpr(int beginLine, int beginColumn, int endLine, - int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - - public NameExpr getName() { - return name; - } - - public void setName(NameExpr name) { - this.name = name; - setAsParentNodeOf(name); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.AnnotationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A base class for the different types of annotations. + * + * @author Julio Vilmar Gesser + */ +public abstract class AnnotationExpr extends Expression implements NodeWithName { + + protected Name name; + + public AnnotationExpr() { + this(null, new Name()); + } + + @AllFieldsConstructor + public AnnotationExpr(Name name) { + this(null, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public AnnotationExpr(TokenRange tokenRange, Name name) { + super(tokenRange); + setName(name); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AnnotationExpr setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (AnnotationExpr) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public AnnotationExpr clone() { + return (AnnotationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public AnnotationExprMetaModel getMetaModel() { + return JavaParserMetaModel.annotationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationExpr asAnnotationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ArrayAccessExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ArrayAccessExpr.java index a8bffbb..6945dd9 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ArrayAccessExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ArrayAccessExpr.java @@ -1,76 +1,177 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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(int beginLine, int beginColumn, int endLine, int endColumn, Expression name, Expression index) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setIndex(index); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ArrayAccessExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Array brackets [] being used to get a value from an array. + * In
getNames()[15*15] the name expression is getNames() and the index expression is 15*15. + * + * @author Julio Vilmar Gesser + */ +public final class ArrayAccessExpr extends Expression { + + private Expression name; + + private Expression index; + + public ArrayAccessExpr() { + this(null, new NameExpr(), new IntegerLiteralExpr()); + } + + @AllFieldsConstructor + public ArrayAccessExpr(Expression name, Expression index) { + this(null, name, index); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ArrayAccessExpr(TokenRange tokenRange, Expression name, Expression index) { + super(tokenRange); + setName(name); + setIndex(index); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getIndex() { + return index; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayAccessExpr setIndex(final Expression index) { + assertNotNull(index); + if (index == this.index) { + return (ArrayAccessExpr) this; + } + notifyPropertyChange(ObservableProperty.INDEX, this.index, index); + if (this.index != null) + this.index.setParentNode(null); + this.index = index; + setAsParentNodeOf(index); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayAccessExpr setName(final Expression name) { + assertNotNull(name); + if (name == this.name) { + return (ArrayAccessExpr) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ArrayAccessExpr clone() { + return (ArrayAccessExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ArrayAccessExprMetaModel getMetaModel() { + return JavaParserMetaModel.arrayAccessExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == index) { + setIndex((Expression) replacementNode); + return true; + } + if (node == name) { + setName((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayAccessExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayAccessExpr asArrayAccessExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayAccessExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayAccessExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ArrayCreationExpr.java index 23024e0..5099258 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ArrayCreationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ArrayCreationExpr.java @@ -1,130 +1,281 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ArrayCreationExpr extends Expression { - - private Type type; - - private int arrayCount; - - private ArrayInitializerExpr initializer; - - private List dimensions; - - private List> arraysAnnotations; - - public ArrayCreationExpr() { - } - - public ArrayCreationExpr(Type type, int arrayCount, ArrayInitializerExpr initializer) { - setType(type); - setArrayCount(arrayCount); - setInitializer(initializer); - setDimensions(null); - } - - public ArrayCreationExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type, int arrayCount, ArrayInitializerExpr initializer) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - setArrayCount(arrayCount); - setInitializer(initializer); - setDimensions(null); - } - - public ArrayCreationExpr(Type type, List dimensions, int arrayCount) { - setType(type); - setArrayCount(arrayCount); - setDimensions(dimensions); - setInitializer(null); - } - - public ArrayCreationExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type, List dimensions, int arrayCount) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - setArrayCount(arrayCount); - setDimensions(dimensions); - setInitializer(null); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public int getArrayCount() { - return arrayCount; - } - - public List getDimensions() { - return dimensions; - } - - public ArrayInitializerExpr getInitializer() { - return initializer; - } - - public Type getType() { - return type; - } - - public void setArrayCount(int arrayCount) { - this.arrayCount = arrayCount; - } - - public void setDimensions(List dimensions) { - this.dimensions = dimensions; - setAsParentNodeOf(this.dimensions); - } - - public void setInitializer(ArrayInitializerExpr initializer) { - this.initializer = initializer; - setAsParentNodeOf(this.initializer); - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - public List> getArraysAnnotations() { - return arraysAnnotations; - } - - public void setArraysAnnotations( - List> arraysAnnotations) { - this.arraysAnnotations = arraysAnnotations; - } -} +/* + * 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.*; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.ArrayCreationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.JavaParser.parseType; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.Node; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * new int[5][4][][] or new int[][]{{1},{2,3}}. + * + *
"int" is the element type. + *
All the brackets are stored in the levels field, from left to right. + * + * @author Julio Vilmar Gesser + */ +public final class ArrayCreationExpr extends Expression { + + @NonEmptyProperty + private NodeList levels; + + private Type elementType; + + @OptionalProperty + private ArrayInitializerExpr initializer; + + public ArrayCreationExpr() { + this(null, new ClassOrInterfaceType(), new NodeList<>(), new ArrayInitializerExpr()); + } + + @AllFieldsConstructor + public ArrayCreationExpr(Type elementType, NodeList levels, ArrayInitializerExpr initializer) { + this(null, elementType, levels, initializer); + } + + public ArrayCreationExpr(Type elementType) { + this(null, elementType, new NodeList<>(), new ArrayInitializerExpr()); + } + + /** + * @deprecated range shouldn't be in utility constructors. + */ + @Deprecated + public ArrayCreationExpr(Range range, Type elementType) { + this(null, elementType, new NodeList<>(), new ArrayInitializerExpr()); + setRange(range); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ArrayCreationExpr(TokenRange tokenRange, Type elementType, NodeList levels, ArrayInitializerExpr initializer) { + super(tokenRange); + setElementType(elementType); + setLevels(levels); + setInitializer(initializer); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getInitializer() { + return Optional.ofNullable(initializer); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getElementType() { + return elementType; + } + + /** + * Sets the initializer + * + * @param initializer the initializer, can be null + * @return this, the ArrayCreationExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationExpr setInitializer(final ArrayInitializerExpr initializer) { + if (initializer == this.initializer) { + return (ArrayCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.INITIALIZER, this.initializer, initializer); + if (this.initializer != null) + this.initializer.setParentNode(null); + this.initializer = initializer; + setAsParentNodeOf(initializer); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationExpr setElementType(final Type elementType) { + assertNotNull(elementType); + if (elementType == this.elementType) { + return (ArrayCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.ELEMENT_TYPE, this.elementType, elementType); + if (this.elementType != null) + this.elementType.setParentNode(null); + this.elementType = elementType; + setAsParentNodeOf(elementType); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getLevels() { + return levels; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationExpr setLevels(final NodeList levels) { + assertNotNull(levels); + if (levels == this.levels) { + return (ArrayCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.LEVELS, this.levels, levels); + if (this.levels != null) + this.levels.setParentNode(null); + this.levels = levels; + setAsParentNodeOf(levels); + return this; + } + + /** + * Takes the element type and wraps it in an ArrayType for every array creation level. + */ + public Type createdType() { + Type result = elementType; + for (int i = 0; i < levels.size(); i++) { + result = new ArrayType(result, ArrayType.Origin.TYPE, new NodeList<>()); + } + return result; + } + + /** + * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed + * + * @param typeClass the type + * @return this + */ + public ArrayCreationExpr setElementType(Class typeClass) { + tryAddImportToParentCompilationUnit(typeClass); + return setElementType(parseType(typeClass.getSimpleName())); + } + + public ArrayCreationExpr setElementType(final String type) { + return setElementType(parseType(type)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (initializer != null) { + if (node == initializer) { + removeInitializer(); + return true; + } + } + for (int i = 0; i < levels.size(); i++) { + if (levels.get(i) == node) { + levels.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ArrayCreationExpr removeInitializer() { + return setInitializer((ArrayInitializerExpr) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ArrayCreationExpr clone() { + return (ArrayCreationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ArrayCreationExprMetaModel getMetaModel() { + return JavaParserMetaModel.arrayCreationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == elementType) { + setElementType((Type) replacementNode); + return true; + } + if (initializer != null) { + if (node == initializer) { + setInitializer((ArrayInitializerExpr) replacementNode); + return true; + } + } + for (int i = 0; i < levels.size(); i++) { + if (levels.get(i) == node) { + levels.set(i, (ArrayCreationLevel) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayCreationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayCreationExpr asArrayCreationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayCreationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayCreationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ArrayInitializerExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ArrayInitializerExpr.java index cd1098e..d585a18 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ArrayInitializerExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ArrayInitializerExpr.java @@ -1,65 +1,164 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ArrayInitializerExpr extends Expression { - - private List values; - - public ArrayInitializerExpr() { - } - - public ArrayInitializerExpr(List values) { - setValues(values); - } - - public ArrayInitializerExpr(int beginLine, int beginColumn, int endLine, int endColumn, List values) { - super(beginLine, beginColumn, endLine, endColumn); - setValues(values); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public List getValues() { - return values; - } - - public void setValues(List values) { - this.values = values; - setAsParentNodeOf(this.values); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ArrayInitializerExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * The initialization of an array. In the following sample, the outer { } is an ArrayInitializerExpr. + * It has two expressions inside: two ArrayInitializerExprs. + * These have two expressions each, one has 1 and 1, the other two and two. + *
new int[][]{{1, 1}, {2, 2}}; + * + * @author Julio Vilmar Gesser + */ +public final class ArrayInitializerExpr extends Expression { + + private NodeList values; + + public ArrayInitializerExpr() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public ArrayInitializerExpr(NodeList values) { + this(null, values); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ArrayInitializerExpr(TokenRange tokenRange, NodeList values) { + super(tokenRange); + setValues(values); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getValues() { + return values; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayInitializerExpr setValues(final NodeList values) { + assertNotNull(values); + if (values == this.values) { + return (ArrayInitializerExpr) this; + } + notifyPropertyChange(ObservableProperty.VALUES, this.values, values); + if (this.values != null) + this.values.setParentNode(null); + this.values = values; + setAsParentNodeOf(values); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < values.size(); i++) { + if (values.get(i) == node) { + values.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ArrayInitializerExpr clone() { + return (ArrayInitializerExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ArrayInitializerExprMetaModel getMetaModel() { + return JavaParserMetaModel.arrayInitializerExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < values.size(); i++) { + if (values.get(i) == node) { + values.set(i, (Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayInitializerExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayInitializerExpr asArrayInitializerExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayInitializerExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayInitializerExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/AssignExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/AssignExpr.java index 0d2d9f0..fbb4687 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/AssignExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/AssignExpr.java @@ -1,103 +1,256 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 static 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(int beginLine, int beginColumn, int endLine, int endColumn, Expression target, Expression value, Operator op) { - super(beginLine, beginColumn, endLine, endColumn); - setTarget(target); - setValue(value); - setOperator(op); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.AssignExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.printer.Printable; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An assignment expression. It supports the operators that are found the the AssignExpr.Operator enum. + *
a=5 + *
time+=500 + *
watch.time+=500 + *
(((time)))=100*60 + *
peanut[a]=true + * + * @author Julio Vilmar Gesser + */ +public final class AssignExpr extends Expression { + + public enum Operator implements Printable { + + ASSIGN("="), + PLUS("+="), + MINUS("-="), + MULTIPLY("*="), + DIVIDE("/="), + BINARY_AND("&="), + BINARY_OR("|="), + XOR("^="), + REMAINDER("%="), + LEFT_SHIFT("<<="), + SIGNED_RIGHT_SHIFT(">>="), + UNSIGNED_RIGHT_SHIFT(">>>="); + + private final String codeRepresentation; + + Operator(String codeRepresentation) { + this.codeRepresentation = codeRepresentation; + } + + public String asString() { + return codeRepresentation; + } + + public Optional toBinaryOperator() { + switch(this) { + case PLUS: + return Optional.of(BinaryExpr.Operator.PLUS); + case MINUS: + return Optional.of(BinaryExpr.Operator.MINUS); + case MULTIPLY: + return Optional.of(BinaryExpr.Operator.MULTIPLY); + case DIVIDE: + return Optional.of(BinaryExpr.Operator.DIVIDE); + case BINARY_AND: + return Optional.of(BinaryExpr.Operator.BINARY_AND); + case BINARY_OR: + return Optional.of(BinaryExpr.Operator.BINARY_OR); + case XOR: + return Optional.of(BinaryExpr.Operator.XOR); + case REMAINDER: + return Optional.of(BinaryExpr.Operator.REMAINDER); + case LEFT_SHIFT: + return Optional.of(BinaryExpr.Operator.LEFT_SHIFT); + case SIGNED_RIGHT_SHIFT: + return Optional.of(BinaryExpr.Operator.SIGNED_RIGHT_SHIFT); + case UNSIGNED_RIGHT_SHIFT: + return Optional.of(BinaryExpr.Operator.UNSIGNED_RIGHT_SHIFT); + default: + return Optional.empty(); + } + } + } + + private Expression target; + + private Expression value; + + private Operator operator; + + public AssignExpr() { + this(null, new NameExpr(), new StringLiteralExpr(), Operator.ASSIGN); + } + + @AllFieldsConstructor + public AssignExpr(Expression target, Expression value, Operator operator) { + this(null, target, value, operator); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public AssignExpr(TokenRange tokenRange, Expression target, Expression value, Operator operator) { + super(tokenRange); + setTarget(target); + setValue(value); + setOperator(operator); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Operator getOperator() { + return operator; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getTarget() { + return target; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getValue() { + return value; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AssignExpr setOperator(final Operator operator) { + assertNotNull(operator); + if (operator == this.operator) { + return (AssignExpr) this; + } + notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator); + this.operator = operator; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AssignExpr setTarget(final Expression target) { + assertNotNull(target); + if (target == this.target) { + return (AssignExpr) this; + } + notifyPropertyChange(ObservableProperty.TARGET, this.target, target); + if (this.target != null) + this.target.setParentNode(null); + this.target = target; + setAsParentNodeOf(target); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AssignExpr setValue(final Expression value) { + assertNotNull(value); + if (value == this.value) { + return (AssignExpr) this; + } + notifyPropertyChange(ObservableProperty.VALUE, this.value, value); + if (this.value != null) + this.value.setParentNode(null); + this.value = value; + setAsParentNodeOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public AssignExpr clone() { + return (AssignExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public AssignExprMetaModel getMetaModel() { + return JavaParserMetaModel.assignExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == target) { + setTarget((Expression) replacementNode); + return true; + } + if (node == value) { + setValue((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAssignExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AssignExpr asAssignExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAssignExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAssignExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/BinaryExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/BinaryExpr.java index d5cdffa..5ec79c0 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/BinaryExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/BinaryExpr.java @@ -1,110 +1,261 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 static 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(int beginLine, int beginColumn, int endLine, int endColumn, Expression left, Expression right, Operator op) { - super(beginLine, beginColumn, endLine, endColumn); - setLeft(left); - setRight(right); - setOperator(op); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BinaryExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.printer.Printable; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An expression with an expression on the left, an expression on the right, and an operator in the middle. + * It supports the operators that are found the the BinaryExpr.Operator enum. + *
a && b + *
155 * 33 + * + * @author Julio Vilmar Gesser + */ +public final class BinaryExpr extends Expression { + + public enum Operator implements Printable { + + OR("||"), + AND("&&"), + BINARY_OR("|"), + BINARY_AND("&"), + XOR("^"), + EQUALS("=="), + NOT_EQUALS("!="), + LESS("<"), + GREATER(">"), + LESS_EQUALS("<="), + GREATER_EQUALS(">="), + LEFT_SHIFT("<<"), + SIGNED_RIGHT_SHIFT(">>"), + UNSIGNED_RIGHT_SHIFT(">>>"), + PLUS("+"), + MINUS("-"), + MULTIPLY("*"), + DIVIDE("/"), + REMAINDER("%"); + + private final String codeRepresentation; + + Operator(String codeRepresentation) { + this.codeRepresentation = codeRepresentation; + } + + public String asString() { + return codeRepresentation; + } + + public Optional toAssignOperator() { + switch(this) { + case BINARY_OR: + return Optional.of(AssignExpr.Operator.BINARY_OR); + case BINARY_AND: + return Optional.of(AssignExpr.Operator.BINARY_AND); + case XOR: + return Optional.of(AssignExpr.Operator.XOR); + case LEFT_SHIFT: + return Optional.of(AssignExpr.Operator.LEFT_SHIFT); + case SIGNED_RIGHT_SHIFT: + return Optional.of(AssignExpr.Operator.SIGNED_RIGHT_SHIFT); + case UNSIGNED_RIGHT_SHIFT: + return Optional.of(AssignExpr.Operator.UNSIGNED_RIGHT_SHIFT); + case PLUS: + return Optional.of(AssignExpr.Operator.PLUS); + case MINUS: + return Optional.of(AssignExpr.Operator.MINUS); + case MULTIPLY: + return Optional.of(AssignExpr.Operator.MULTIPLY); + case DIVIDE: + return Optional.of(AssignExpr.Operator.DIVIDE); + case REMAINDER: + return Optional.of(AssignExpr.Operator.REMAINDER); + default: + return Optional.empty(); + } + } + } + + private Expression left; + + private Expression right; + + private Operator operator; + + public BinaryExpr() { + this(null, new BooleanLiteralExpr(), new BooleanLiteralExpr(), Operator.EQUALS); + } + + @AllFieldsConstructor + public BinaryExpr(Expression left, Expression right, Operator operator) { + this(null, left, right, operator); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BinaryExpr(TokenRange tokenRange, Expression left, Expression right, Operator operator) { + super(tokenRange); + setLeft(left); + setRight(right); + setOperator(operator); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getLeft() { + return left; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Operator getOperator() { + return operator; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getRight() { + return right; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BinaryExpr setLeft(final Expression left) { + assertNotNull(left); + if (left == this.left) { + return (BinaryExpr) this; + } + notifyPropertyChange(ObservableProperty.LEFT, this.left, left); + if (this.left != null) + this.left.setParentNode(null); + this.left = left; + setAsParentNodeOf(left); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BinaryExpr setOperator(final Operator operator) { + assertNotNull(operator); + if (operator == this.operator) { + return (BinaryExpr) this; + } + notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator); + this.operator = operator; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BinaryExpr setRight(final Expression right) { + assertNotNull(right); + if (right == this.right) { + return (BinaryExpr) this; + } + notifyPropertyChange(ObservableProperty.RIGHT, this.right, right); + if (this.right != null) + this.right.setParentNode(null); + this.right = right; + setAsParentNodeOf(right); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BinaryExpr clone() { + return (BinaryExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BinaryExprMetaModel getMetaModel() { + return JavaParserMetaModel.binaryExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == left) { + setLeft((Expression) replacementNode); + return true; + } + if (node == right) { + setRight((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBinaryExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BinaryExpr asBinaryExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBinaryExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBinaryExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/BooleanLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/BooleanLiteralExpr.java index 6b30bca..4be43b2 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/BooleanLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/BooleanLiteralExpr.java @@ -1,62 +1,143 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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(int beginLine, int beginColumn, int endLine, int endColumn, boolean value) { - super(beginLine, beginColumn, endLine, endColumn); - setValue(value); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public boolean getValue() { - return value; - } - - public void setValue(boolean value) { - this.value = value; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BooleanLiteralExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * The boolean literals. + *
true + *
false + * + * @author Julio Vilmar Gesser + */ +public final class BooleanLiteralExpr extends LiteralExpr { + + private boolean value; + + public BooleanLiteralExpr() { + this(null, false); + } + + @AllFieldsConstructor + public BooleanLiteralExpr(boolean value) { + this(null, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BooleanLiteralExpr(TokenRange tokenRange, boolean value) { + super(tokenRange); + setValue(value); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean getValue() { + return value; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BooleanLiteralExpr setValue(final boolean value) { + if (value == this.value) { + return (BooleanLiteralExpr) this; + } + notifyPropertyChange(ObservableProperty.VALUE, this.value, value); + this.value = value; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BooleanLiteralExpr clone() { + return (BooleanLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BooleanLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.booleanLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBooleanLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BooleanLiteralExpr asBooleanLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBooleanLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBooleanLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/CastExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/CastExpr.java index 5596cd0..174d24c 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/CastExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/CastExpr.java @@ -1,77 +1,180 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 { - - private Type type; - - private Expression expr; - - public CastExpr() { - } - - public CastExpr(Type type, Expression expr) { - setType(type); - setExpr(expr); - } - - public CastExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type, Expression expr) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - setExpr(expr); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Expression getExpr() { - return expr; - } - - public Type getType() { - return type; - } - - public void setExpr(Expression expr) { - this.expr = expr; - setAsParentNodeOf(this.expr); - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.CastExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A typecast. The (long) in (long)15 + * + * @author Julio Vilmar Gesser + */ +public final class CastExpr extends Expression implements NodeWithType, NodeWithExpression { + + private Type type; + + private Expression expression; + + public CastExpr() { + this(null, new ClassOrInterfaceType(), new NameExpr()); + } + + @AllFieldsConstructor + public CastExpr(Type type, Expression expression) { + this(null, type, expression); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public CastExpr(TokenRange tokenRange, Type type, Expression expression) { + super(tokenRange); + setType(type); + setExpression(expression); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CastExpr setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (CastExpr) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CastExpr setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (CastExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public CastExpr clone() { + return (CastExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CastExprMetaModel getMetaModel() { + return JavaParserMetaModel.castExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCastExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CastExpr asCastExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCastExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCastExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/CharLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/CharLiteralExpr.java index 4ba61a2..bc2db00 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/CharLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/CharLiteralExpr.java @@ -1,51 +1,163 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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(int beginLine, int beginColumn, int endLine, int endColumn, String value) { - super(beginLine, beginColumn, endLine, endColumn, value); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.CharLiteralExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.utils.StringEscapeUtils; +import com.github.javaparser.utils.Utils; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A literal character. + *
'a' + *
'\t' + *
'Ω' + *
'\177' + *
'💩' + * + * @author Julio Vilmar Gesser + */ +public final class CharLiteralExpr extends LiteralStringValueExpr { + + public CharLiteralExpr() { + this(null, "?"); + } + + @AllFieldsConstructor + public CharLiteralExpr(String value) { + this(null, value); + } + + /** + * Constructs a CharLiteralExpr with given escaped character. + * + * @param value a char + */ + public CharLiteralExpr(char value) { + this(null, StringEscapeUtils.escapeJava(String.valueOf(value))); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public CharLiteralExpr(TokenRange tokenRange, String value) { + super(tokenRange, value); + customInitialization(); + } + + /** + * Utility method that creates a new StringLiteralExpr. Escapes EOL characters. + */ + public static CharLiteralExpr escape(String string) { + return new CharLiteralExpr(Utils.escapeEndOfLines(string)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + /** + * @return the unescaped value character of this literal + */ + public char asChar() { + return StringEscapeUtils.unescapeJava(value).charAt(0); + } + + /** + * Sets the given char as the literal value + * + * @param value a char + * @return this expression + */ + public CharLiteralExpr setChar(char value) { + this.value = String.valueOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public CharLiteralExpr clone() { + return (CharLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CharLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.charLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCharLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CharLiteralExpr asCharLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCharLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCharLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ClassExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ClassExpr.java index 78bb225..729bd4f 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ClassExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ClassExpr.java @@ -1,64 +1,154 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 ClassExpr extends Expression { - - private Type type; - - public ClassExpr() { - } - - public ClassExpr(Type type) { - setType(type); - } - - public ClassExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Type getType() { - return type; - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ClassExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Defines an expression that accesses the class of a type. + *
Object.class + * + * @author Julio Vilmar Gesser + */ +public final class ClassExpr extends Expression implements NodeWithType { + + private Type type; + + public ClassExpr() { + this(null, new ClassOrInterfaceType()); + } + + @AllFieldsConstructor + public ClassExpr(Type type) { + this(null, type); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ClassExpr(TokenRange tokenRange, Type type) { + super(tokenRange); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassExpr setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (ClassExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ClassExpr clone() { + return (ClassExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ClassExprMetaModel getMetaModel() { + return JavaParserMetaModel.classExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassExpr asClassExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ConditionalExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ConditionalExpr.java index 01aa2da..bdc50a0 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ConditionalExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ConditionalExpr.java @@ -1,89 +1,204 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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(int beginLine, int beginColumn, int endLine, int endColumn, Expression condition, Expression thenExpr, Expression elseExpr) { - super(beginLine, beginColumn, endLine, endColumn); - setCondition(condition); - setThenExpr(thenExpr); - setElseExpr(elseExpr); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithCondition; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ConditionalExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * The ternary conditional expression. + * In b==0?x:y, b==0 is the condition, x is thenExpr, and y is elseExpr. + * + * @author Julio Vilmar Gesser + */ +public final class ConditionalExpr extends Expression implements NodeWithCondition { + + private Expression condition; + + private Expression thenExpr; + + private Expression elseExpr; + + public ConditionalExpr() { + this(null, new BooleanLiteralExpr(), new StringLiteralExpr(), new StringLiteralExpr()); + } + + @AllFieldsConstructor + public ConditionalExpr(Expression condition, Expression thenExpr, Expression elseExpr) { + this(null, condition, thenExpr, elseExpr); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ConditionalExpr(TokenRange tokenRange, Expression condition, Expression thenExpr, Expression elseExpr) { + super(tokenRange); + setCondition(condition); + setThenExpr(thenExpr); + setElseExpr(elseExpr); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCondition() { + return condition; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getElseExpr() { + return elseExpr; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getThenExpr() { + return thenExpr; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ConditionalExpr setCondition(final Expression condition) { + assertNotNull(condition); + if (condition == this.condition) { + return (ConditionalExpr) this; + } + notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition); + if (this.condition != null) + this.condition.setParentNode(null); + this.condition = condition; + setAsParentNodeOf(condition); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ConditionalExpr setElseExpr(final Expression elseExpr) { + assertNotNull(elseExpr); + if (elseExpr == this.elseExpr) { + return (ConditionalExpr) this; + } + notifyPropertyChange(ObservableProperty.ELSE_EXPR, this.elseExpr, elseExpr); + if (this.elseExpr != null) + this.elseExpr.setParentNode(null); + this.elseExpr = elseExpr; + setAsParentNodeOf(elseExpr); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ConditionalExpr setThenExpr(final Expression thenExpr) { + assertNotNull(thenExpr); + if (thenExpr == this.thenExpr) { + return (ConditionalExpr) this; + } + notifyPropertyChange(ObservableProperty.THEN_EXPR, this.thenExpr, thenExpr); + if (this.thenExpr != null) + this.thenExpr.setParentNode(null); + this.thenExpr = thenExpr; + setAsParentNodeOf(thenExpr); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ConditionalExpr clone() { + return (ConditionalExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ConditionalExprMetaModel getMetaModel() { + return JavaParserMetaModel.conditionalExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == condition) { + setCondition((Expression) replacementNode); + return true; + } + if (node == elseExpr) { + setElseExpr((Expression) replacementNode); + return true; + } + if (node == thenExpr) { + setThenExpr((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isConditionalExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ConditionalExpr asConditionalExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConditionalExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toConditionalExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/DoubleLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/DoubleLiteralExpr.java index ba1c1f4..007fdf3 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/DoubleLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/DoubleLiteralExpr.java @@ -1,50 +1,141 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String value) { - super(beginLine, beginColumn, endLine, endColumn, value); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.DoubleLiteralExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A float or a double constant. This value is stored exactly as found in the source. + *
100.1f + *
23958D + *
0x4.5p1f + * + * @author Julio Vilmar Gesser + */ +public final class DoubleLiteralExpr extends LiteralStringValueExpr { + + public DoubleLiteralExpr() { + this(null, "0"); + } + + @AllFieldsConstructor + public DoubleLiteralExpr(final String value) { + this(null, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public DoubleLiteralExpr(TokenRange tokenRange, String value) { + super(tokenRange, value); + customInitialization(); + } + + public DoubleLiteralExpr(final double value) { + this(null, String.valueOf(value)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + /** + * @return the literal value as a double + */ + public double asDouble() { + return Double.parseDouble(value); + } + + public DoubleLiteralExpr setDouble(double value) { + this.value = String.valueOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public DoubleLiteralExpr clone() { + return (DoubleLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public DoubleLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.doubleLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isDoubleLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public DoubleLiteralExpr asDoubleLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoubleLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toDoubleLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/EnclosedExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/EnclosedExpr.java index aa32cb0..c3d56d8 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/EnclosedExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/EnclosedExpr.java @@ -1,62 +1,162 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression inner) { - super(beginLine, beginColumn, endLine, endColumn); - setInner(inner); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.EnclosedExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.function.Consumer; + +/** + * An expression between ( ). + *
(1+1) + * + * @author Julio Vilmar Gesser + */ +public final class EnclosedExpr extends Expression { + + private Expression inner; + + public EnclosedExpr() { + this(null, new StringLiteralExpr()); + } + + @AllFieldsConstructor + public EnclosedExpr(final Expression inner) { + this(null, inner); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public EnclosedExpr(TokenRange tokenRange, Expression inner) { + super(tokenRange); + setInner(inner); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getInner() { + return inner; + } + + /** + * Sets the inner expression + * + * @param inner the inner expression, can be null + * @return this, the EnclosedExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnclosedExpr setInner(final Expression inner) { + assertNotNull(inner); + if (inner == this.inner) { + return (EnclosedExpr) this; + } + notifyPropertyChange(ObservableProperty.INNER, this.inner, inner); + if (this.inner != null) + this.inner.setParentNode(null); + this.inner = inner; + setAsParentNodeOf(inner); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public EnclosedExpr removeInner() { + return setInner((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public EnclosedExpr clone() { + return (EnclosedExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public EnclosedExprMetaModel getMetaModel() { + return JavaParserMetaModel.enclosedExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == inner) { + setInner((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnclosedExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnclosedExpr asEnclosedExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnclosedExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnclosedExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/Expression.java b/JavaParser/src/com/github/javaparser/ast/expr/Expression.java index 9238c52..de9e52b 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/Expression.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/Expression.java @@ -1,37 +1,733 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.Node; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class Expression extends Node { - - public Expression() { - } - - public Expression(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ExpressionMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedType; +import java.util.function.Consumer; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import java.util.Optional; + +/** + * A base class for all expressions. + * + * @author Julio Vilmar Gesser + */ +public abstract class Expression extends Node { + + @AllFieldsConstructor + public Expression() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Expression(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Expression clone() { + return (Expression) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ExpressionMetaModel getMetaModel() { + return JavaParserMetaModel.expressionMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAnnotationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AnnotationExpr asAnnotationExpr() { + throw new IllegalStateException(f("%s is not an AnnotationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayAccessExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayAccessExpr asArrayAccessExpr() { + throw new IllegalStateException(f("%s is not an ArrayAccessExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayCreationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayCreationExpr asArrayCreationExpr() { + throw new IllegalStateException(f("%s is not an ArrayCreationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayInitializerExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayInitializerExpr asArrayInitializerExpr() { + throw new IllegalStateException(f("%s is not an ArrayInitializerExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAssignExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AssignExpr asAssignExpr() { + throw new IllegalStateException(f("%s is not an AssignExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBinaryExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BinaryExpr asBinaryExpr() { + throw new IllegalStateException(f("%s is not an BinaryExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBooleanLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BooleanLiteralExpr asBooleanLiteralExpr() { + throw new IllegalStateException(f("%s is not an BooleanLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCastExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CastExpr asCastExpr() { + throw new IllegalStateException(f("%s is not an CastExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isCharLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public CharLiteralExpr asCharLiteralExpr() { + throw new IllegalStateException(f("%s is not an CharLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassExpr asClassExpr() { + throw new IllegalStateException(f("%s is not an ClassExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isConditionalExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ConditionalExpr asConditionalExpr() { + throw new IllegalStateException(f("%s is not an ConditionalExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isDoubleLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public DoubleLiteralExpr asDoubleLiteralExpr() { + throw new IllegalStateException(f("%s is not an DoubleLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEnclosedExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EnclosedExpr asEnclosedExpr() { + throw new IllegalStateException(f("%s is not an EnclosedExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isFieldAccessExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public FieldAccessExpr asFieldAccessExpr() { + throw new IllegalStateException(f("%s is not an FieldAccessExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isInstanceOfExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public InstanceOfExpr asInstanceOfExpr() { + throw new IllegalStateException(f("%s is not an InstanceOfExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIntegerLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IntegerLiteralExpr asIntegerLiteralExpr() { + throw new IllegalStateException(f("%s is not an IntegerLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLambdaExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LambdaExpr asLambdaExpr() { + throw new IllegalStateException(f("%s is not an LambdaExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LiteralExpr asLiteralExpr() { + throw new IllegalStateException(f("%s is not an LiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLiteralStringValueExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LiteralStringValueExpr asLiteralStringValueExpr() { + throw new IllegalStateException(f("%s is not an LiteralStringValueExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLongLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LongLiteralExpr asLongLiteralExpr() { + throw new IllegalStateException(f("%s is not an LongLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMarkerAnnotationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MarkerAnnotationExpr asMarkerAnnotationExpr() { + throw new IllegalStateException(f("%s is not an MarkerAnnotationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodCallExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodCallExpr asMethodCallExpr() { + throw new IllegalStateException(f("%s is not an MethodCallExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodReferenceExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodReferenceExpr asMethodReferenceExpr() { + throw new IllegalStateException(f("%s is not an MethodReferenceExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNameExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NameExpr asNameExpr() { + throw new IllegalStateException(f("%s is not an NameExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNormalAnnotationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NormalAnnotationExpr asNormalAnnotationExpr() { + throw new IllegalStateException(f("%s is not an NormalAnnotationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNullLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NullLiteralExpr asNullLiteralExpr() { + throw new IllegalStateException(f("%s is not an NullLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isObjectCreationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ObjectCreationExpr asObjectCreationExpr() { + throw new IllegalStateException(f("%s is not an ObjectCreationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSingleMemberAnnotationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SingleMemberAnnotationExpr asSingleMemberAnnotationExpr() { + throw new IllegalStateException(f("%s is not an SingleMemberAnnotationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isStringLiteralExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public StringLiteralExpr asStringLiteralExpr() { + throw new IllegalStateException(f("%s is not an StringLiteralExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSuperExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SuperExpr asSuperExpr() { + throw new IllegalStateException(f("%s is not an SuperExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isThisExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ThisExpr asThisExpr() { + throw new IllegalStateException(f("%s is not an ThisExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeExpr asTypeExpr() { + throw new IllegalStateException(f("%s is not an TypeExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnaryExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnaryExpr asUnaryExpr() { + throw new IllegalStateException(f("%s is not an UnaryExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVariableDeclarationExpr() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VariableDeclarationExpr asVariableDeclarationExpr() { + throw new IllegalStateException(f("%s is not an VariableDeclarationExpr", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayAccessExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayCreationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayInitializerExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAssignExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBinaryExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBooleanLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCastExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCharLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConditionalExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoubleLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnclosedExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldAccessExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInstanceOfExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntegerLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLambdaExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralStringValueExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLongLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMarkerAnnotationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodCallExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodReferenceExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNameExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNormalAnnotationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNullLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifObjectCreationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSingleMemberAnnotationExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifStringLiteralExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSuperExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThisExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnaryExpr(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVariableDeclarationExpr(Consumer action) { + } + + public ResolvedType calculateResolvedType() { + return getSymbolResolver().calculateType(this); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayAccessExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayCreationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayInitializerExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAssignExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBinaryExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBooleanLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCastExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toCharLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toConditionalExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toDoubleLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEnclosedExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toFieldAccessExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toInstanceOfExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIntegerLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLambdaExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLiteralStringValueExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLongLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMarkerAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodCallExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodReferenceExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNameExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNormalAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNullLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toObjectCreationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSingleMemberAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toStringLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSuperExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toThisExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnaryExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVariableDeclarationExpr() { + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/FieldAccessExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/FieldAccessExpr.java index 9fbb275..c6b9e0a 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/FieldAccessExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/FieldAccessExpr.java @@ -1,97 +1,262 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class FieldAccessExpr extends Expression { - - private Expression scope; - - private List typeArgs; - - private NameExpr field; - - public FieldAccessExpr() { - } - - public FieldAccessExpr(final Expression scope, final String field) { - setScope(scope); - setField(field); - } - - public FieldAccessExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression scope, final List typeArgs, final String field) { - super(beginLine, beginColumn, endLine, endColumn); - setScope(scope); - setTypeArgs(typeArgs); - setField(field); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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 getTypeArgs() { - return typeArgs; - } - - public void setField(final String field) { - this.field = new NameExpr(field); - } - - public void setFieldExpr(NameExpr field) { - this.field = field; - } - - public void setScope(final Expression scope) { - this.scope = scope; - setAsParentNodeOf(this.scope); - } - - public void setTypeArgs(final List typeArgs) { - this.typeArgs = typeArgs; - setAsParentNodeOf(this.typeArgs); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithScope; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.FieldAccessExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * Access of a field of an object. + *
In person.name "name" is the name and "person" is the scope. + * + * @author Julio Vilmar Gesser + */ +public final class FieldAccessExpr extends Expression implements NodeWithSimpleName, NodeWithTypeArguments, NodeWithScope { + + private Expression scope; + + @OptionalProperty + private NodeList typeArguments; + + private SimpleName name; + + public FieldAccessExpr() { + this(null, new ThisExpr(), new NodeList<>(), new SimpleName()); + } + + public FieldAccessExpr(final Expression scope, final String name) { + this(null, scope, new NodeList<>(), new SimpleName(name)); + } + + @AllFieldsConstructor + public FieldAccessExpr(final Expression scope, final NodeList typeArguments, final SimpleName name) { + this(null, scope, typeArguments, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public FieldAccessExpr(TokenRange tokenRange, Expression scope, NodeList typeArguments, SimpleName name) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldAccessExpr setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (FieldAccessExpr) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + /** + * Use {@link #getName} instead. + */ + @Deprecated + public SimpleName getField() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getScope() { + return scope; + } + + /** + * Use {@link #setName} with new SimpleName(field) instead. + */ + @Deprecated + public FieldAccessExpr setField(final String field) { + setName(new SimpleName(field)); + return this; + } + + /** + * Use {@link #setName} instead. + */ + @Deprecated + public FieldAccessExpr setFieldExpr(SimpleName inner) { + return setName(inner); + } + + /** + * Sets the scope + * + * @param scope the scope, can not be null + * @return this, the FieldAccessExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldAccessExpr setScope(final Expression scope) { + assertNotNull(scope); + if (scope == this.scope) { + return (FieldAccessExpr) this; + } + notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope); + if (this.scope != null) + this.scope.setParentNode(null); + this.scope = scope; + setAsParentNodeOf(scope); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the type arguments + * + * @param typeArguments the type arguments, can be null + * @return this, the FieldAccessExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldAccessExpr setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (FieldAccessExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public FieldAccessExpr clone() { + return (FieldAccessExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public FieldAccessExprMetaModel getMetaModel() { + return JavaParserMetaModel.fieldAccessExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (node == scope) { + setScope((Expression) replacementNode); + return true; + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isFieldAccessExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public FieldAccessExpr asFieldAccessExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldAccessExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toFieldAccessExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/InstanceOfExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/InstanceOfExpr.java index 9c466fc..69a505b 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/InstanceOfExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/InstanceOfExpr.java @@ -1,76 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 { - - private Expression expr; - - private Type type; - - public InstanceOfExpr() { - } - - public InstanceOfExpr(final Expression expr, final Type type) { - setExpr(expr); - setType(type); - } - - public InstanceOfExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression expr, final Type type) { - super(beginLine, beginColumn, endLine, endColumn); - setExpr(expr); - setType(type); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public Expression getExpr() { - return expr; - } - - public Type getType() { - return type; - } - - public void setExpr(final Expression expr) { - this.expr = expr; - setAsParentNodeOf(this.expr); - } - - public void setType(final Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.InstanceOfExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Usage of the instanceof operator. + *
tool instanceof Drill + * + * @author Julio Vilmar Gesser + */ +public final class InstanceOfExpr extends Expression implements NodeWithType, NodeWithExpression { + + private Expression expression; + + private ReferenceType type; + + public InstanceOfExpr() { + this(null, new NameExpr(), new ClassOrInterfaceType()); + } + + @AllFieldsConstructor + public InstanceOfExpr(final Expression expression, final ReferenceType type) { + this(null, expression, type); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public InstanceOfExpr(TokenRange tokenRange, Expression expression, ReferenceType type) { + super(tokenRange); + setExpression(expression); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ReferenceType getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public InstanceOfExpr setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (InstanceOfExpr) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public InstanceOfExpr setType(final ReferenceType type) { + assertNotNull(type); + if (type == this.type) { + return (InstanceOfExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public InstanceOfExpr clone() { + return (InstanceOfExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public InstanceOfExprMetaModel getMetaModel() { + return JavaParserMetaModel.instanceOfExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + if (node == type) { + setType((ReferenceType) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isInstanceOfExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public InstanceOfExpr asInstanceOfExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInstanceOfExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toInstanceOfExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralExpr.java index 38d2e9d..a0d3949 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralExpr.java @@ -1,60 +1,153 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String value) { - super(beginLine, beginColumn, endLine, endColumn, value); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public final boolean isMinValue() { - return value != null && // - value.length() == 10 && // - value.equals(UNSIGNED_MIN_VALUE); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.IntegerLiteralExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * All ways to specify an int literal. + *
8934 + *
0x01 + *
022 + *
0B10101010 + *
99999999L + * + * @author Julio Vilmar Gesser + */ +public final class IntegerLiteralExpr extends LiteralStringValueExpr { + + public IntegerLiteralExpr() { + this(null, "0"); + } + + @AllFieldsConstructor + public IntegerLiteralExpr(final String value) { + this(null, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public IntegerLiteralExpr(TokenRange tokenRange, String value) { + super(tokenRange, value); + customInitialization(); + } + + public IntegerLiteralExpr(final int value) { + this(null, String.valueOf(value)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + /** + * @return the literal value as an integer while respecting different number representations + */ + public int asInt() { + String result = value.replaceAll("_", ""); + if (result.startsWith("0x") || result.startsWith("0X")) { + return Integer.parseUnsignedInt(result.substring(2), 16); + } + if (result.startsWith("0b") || result.startsWith("0B")) { + return Integer.parseUnsignedInt(result.substring(2), 2); + } + if (result.length() > 1 && result.startsWith("0")) { + return Integer.parseUnsignedInt(result.substring(1), 8); + } + return Integer.parseInt(result); + } + + public IntegerLiteralExpr setInt(int value) { + this.value = String.valueOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public IntegerLiteralExpr clone() { + return (IntegerLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public IntegerLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.integerLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIntegerLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IntegerLiteralExpr asIntegerLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntegerLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIntegerLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java deleted file mode 100644 index f2bffc6..0000000 --- a/JavaParser/src/com/github/javaparser/ast/expr/IntegerLiteralMinValueExpr.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn, MIN_VALUE); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - -} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/LambdaExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/LambdaExpr.java index 6d1ee9c..a69176f 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/LambdaExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/LambdaExpr.java @@ -1,93 +1,236 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - - -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; - -/** - * Lambda expressions. - * @author Raquel Pau - * - */ -public class LambdaExpr extends Expression { - - private List parameters; - - private boolean parametersEnclosed; - - private Statement body; - - public LambdaExpr() { - } - - public LambdaExpr(int beginLine, int beginColumn, int endLine, - int endColumn, List parameters, Statement body, - boolean parametersEnclosed) { - - super(beginLine, beginColumn, endLine, endColumn); - setParameters(parameters); - setBody(body); - setParametersEnclosed(parametersEnclosed); - } - - public List getParameters() { - return parameters; - } - - public void setParameters(List 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 accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public boolean isParametersEnclosed() { - return parametersEnclosed; - } - - public void setParametersEnclosed(boolean parametersEnclosed) { - this.parametersEnclosed = parametersEnclosed; - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.nodeTypes.NodeWithParameters; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.DerivedProperty; +import com.github.javaparser.metamodel.LambdaExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; + +/** + *

A lambda expression

+ *

Java 1-7

+ * Does not exist. + *

Java 8+

+ * (a, b) -> a + b + *
a -> ... + *
(Long a) -> { println(a); } + *

The parameters are on the left side of the ->. + * If a parameter uses type inference (it has no type specified) then its type is set to UnknownType. + * If they are in ( ), "isEnclosingParameters" is true. + *
The body is to the right of the ->. + * The body is either a BlockStatement when it is in { } braces, or an ExpressionStatement when it is not in braces. + * + * @author Raquel Pau + */ +public final class LambdaExpr extends Expression implements NodeWithParameters { + + private NodeList parameters; + + private boolean isEnclosingParameters; + + private Statement body; + + public LambdaExpr() { + this(null, new NodeList<>(), new ReturnStmt(), false); + } + + @AllFieldsConstructor + public LambdaExpr(NodeList parameters, Statement body, boolean isEnclosingParameters) { + this(null, parameters, body, isEnclosingParameters); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LambdaExpr(TokenRange tokenRange, NodeList parameters, Statement body, boolean isEnclosingParameters) { + super(tokenRange); + setParameters(parameters); + setBody(body); + setEnclosingParameters(isEnclosingParameters); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getParameters() { + return parameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LambdaExpr setParameters(final NodeList parameters) { + assertNotNull(parameters); + if (parameters == this.parameters) { + return (LambdaExpr) this; + } + notifyPropertyChange(ObservableProperty.PARAMETERS, this.parameters, parameters); + if (this.parameters != null) + this.parameters.setParentNode(null); + this.parameters = parameters; + setAsParentNodeOf(parameters); + return this; + } + + /** + * @return a BlockStatement or an ExpressionStatement. See class Javadoc. + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LambdaExpr setBody(final Statement body) { + assertNotNull(body); + if (body == this.body) { + return (LambdaExpr) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isEnclosingParameters() { + return isEnclosingParameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LambdaExpr setEnclosingParameters(final boolean isEnclosingParameters) { + if (isEnclosingParameters == this.isEnclosingParameters) { + return (LambdaExpr) this; + } + notifyPropertyChange(ObservableProperty.ENCLOSING_PARAMETERS, this.isEnclosingParameters, isEnclosingParameters); + this.isEnclosingParameters = isEnclosingParameters; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < parameters.size(); i++) { + if (parameters.get(i) == node) { + parameters.remove(i); + return true; + } + } + return super.remove(node); + } + + /** + * @return if the body of this lambda is a simple expression, return that expression. + * Otherwise (when the body is a block) return Optional.empty(). + */ + @DerivedProperty + public Optional getExpressionBody() { + if (body.isExpressionStmt()) { + return Optional.of(body.asExpressionStmt().getExpression()); + } else { + return Optional.empty(); + } + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LambdaExpr clone() { + return (LambdaExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LambdaExprMetaModel getMetaModel() { + return JavaParserMetaModel.lambdaExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((Statement) replacementNode); + return true; + } + for (int i = 0; i < parameters.size(); i++) { + if (parameters.get(i) == node) { + parameters.set(i, (Parameter) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLambdaExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LambdaExpr asLambdaExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLambdaExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLambdaExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/LiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/LiteralExpr.java index 8190061..2c81560 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/LiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/LiteralExpr.java @@ -1,34 +1,104 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class LiteralExpr extends Expression { - - public LiteralExpr() { - } - - public LiteralExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.LiteralExprMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A base class for all literal expressions. + * + * @author Julio Vilmar Gesser + */ +public abstract class LiteralExpr extends Expression { + + @AllFieldsConstructor + public LiteralExpr() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LiteralExpr(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LiteralExpr clone() { + return (LiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.literalExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LiteralExpr asLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/LiteralStringValueExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/LiteralStringValueExpr.java new file mode 100644 index 0000000..4956146 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/expr/LiteralStringValueExpr.java @@ -0,0 +1,123 @@ +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.LiteralStringValueExprMetaModel; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Any literal value that is stored internally as a String. + */ +public abstract class LiteralStringValueExpr extends LiteralExpr { + + protected String value; + + @AllFieldsConstructor + public LiteralStringValueExpr(final String value) { + this(null, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LiteralStringValueExpr(TokenRange tokenRange, String value) { + super(tokenRange); + setValue(value); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public String getValue() { + return value; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LiteralStringValueExpr setValue(final String value) { + assertNotNull(value); + if (value == this.value) { + return (LiteralStringValueExpr) this; + } + notifyPropertyChange(ObservableProperty.VALUE, this.value, value); + this.value = value; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LiteralStringValueExpr clone() { + return (LiteralStringValueExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LiteralStringValueExprMetaModel getMetaModel() { + return JavaParserMetaModel.literalStringValueExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLiteralStringValueExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LiteralStringValueExpr asLiteralStringValueExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralStringValueExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLiteralStringValueExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralExpr.java index 711fd5a..d15442f 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralExpr.java @@ -1,61 +1,157 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String value) { - super(beginLine, beginColumn, endLine, endColumn, value); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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'); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.LongLiteralExprMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * All ways to specify a long literal. + *
8934l + *
0x01L + *
022l + *
0B10101010L + *
99999999L + * + * @author Julio Vilmar Gesser + */ +public final class LongLiteralExpr extends LiteralStringValueExpr { + + public LongLiteralExpr() { + this(null, "0"); + } + + @AllFieldsConstructor + public LongLiteralExpr(final String value) { + this(null, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LongLiteralExpr(TokenRange tokenRange, String value) { + super(tokenRange, value); + customInitialization(); + } + + public LongLiteralExpr(final long value) { + this(null, String.valueOf(value)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + /** + * @return the literal value as an long while respecting different number representations + */ + public long asLong() { + String result = value.replaceAll("_", ""); + char lastChar = result.charAt(result.length() - 1); + if (lastChar == 'l' || lastChar == 'L') { + result = result.substring(0, result.length() - 1); + } + if (result.startsWith("0x") || result.startsWith("0X")) { + return Long.parseUnsignedLong(result.substring(2), 16); + } + if (result.startsWith("0b") || result.startsWith("0B")) { + return Long.parseUnsignedLong(result.substring(2), 2); + } + if (result.length() > 1 && result.startsWith("0")) { + return Long.parseUnsignedLong(result.substring(1), 8); + } + return Long.parseLong(result); + } + + public LongLiteralExpr setLong(long value) { + this.value = String.valueOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LongLiteralExpr clone() { + return (LongLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LongLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.longLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLongLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LongLiteralExpr asLongLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLongLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLongLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java deleted file mode 100644 index 78ef85e..0000000 --- a/JavaParser/src/com/github/javaparser/ast/expr/LongLiteralMinValueExpr.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn, MIN_VALUE); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - -} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java index d3af7cd..e9ab894 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java @@ -1,52 +1,128 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final NameExpr name) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.MarkerAnnotationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import static com.github.javaparser.JavaParser.parseName; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An annotation that uses only the annotation type name. + *
@Override + * + * @author Julio Vilmar Gesser + */ +public final class MarkerAnnotationExpr extends AnnotationExpr { + + public MarkerAnnotationExpr() { + this(null, new Name()); + } + + public MarkerAnnotationExpr(final String name) { + this(null, parseName(name)); + } + + @AllFieldsConstructor + public MarkerAnnotationExpr(final Name name) { + this(null, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public MarkerAnnotationExpr(TokenRange tokenRange, Name name) { + super(tokenRange, name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public MarkerAnnotationExpr clone() { + return (MarkerAnnotationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public MarkerAnnotationExprMetaModel getMetaModel() { + return JavaParserMetaModel.markerAnnotationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMarkerAnnotationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MarkerAnnotationExpr asMarkerAnnotationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMarkerAnnotationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMarkerAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/MemberValuePair.java b/JavaParser/src/com/github/javaparser/ast/expr/MemberValuePair.java index 398a212..8accb7b 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/MemberValuePair.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/MemberValuePair.java @@ -1,76 +1,157 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.NamedNode; -import com.github.javaparser.ast.Node; -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 NamedNode { - - private String name; - - private Expression value; - - public MemberValuePair() { - } - - public MemberValuePair(final String name, final Expression value) { - setName(name); - setValue(value); - } - - public MemberValuePair(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String name, final Expression value) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setValue(value); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public String getName() { - return name; - } - - public Expression getValue() { - return value; - } - - public void setName(final String name) { - this.name = name; - } - - public void setValue(final Expression value) { - this.value = value; - setAsParentNodeOf(this.value); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.MemberValuePairMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * A value for a member of an annotation. + * In @Counters(a=15) a=15 is a MemberValuePair. Its name is a, and its value is 15. + * + * @author Julio Vilmar Gesser + */ +public final class MemberValuePair extends Node implements NodeWithSimpleName { + + private SimpleName name; + + private Expression value; + + public MemberValuePair() { + this(null, new SimpleName(), new StringLiteralExpr()); + } + + public MemberValuePair(final String name, final Expression value) { + this(null, new SimpleName(name), value); + } + + @AllFieldsConstructor + public MemberValuePair(final SimpleName name, final Expression value) { + this(null, name, value); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public MemberValuePair(TokenRange tokenRange, SimpleName name, Expression value) { + super(tokenRange); + setName(name); + setValue(value); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getValue() { + return value; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MemberValuePair setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (MemberValuePair) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MemberValuePair setValue(final Expression value) { + assertNotNull(value); + if (value == this.value) { + return (MemberValuePair) this; + } + notifyPropertyChange(ObservableProperty.VALUE, this.value, value); + if (this.value != null) + this.value.setParentNode(null); + this.value = value; + setAsParentNodeOf(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public MemberValuePair clone() { + return (MemberValuePair) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public MemberValuePairMetaModel getMetaModel() { + return JavaParserMetaModel.memberValuePairMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (node == value) { + setValue((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/MethodCallExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/MethodCallExpr.java index 3b0a348..dc914c9 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/MethodCallExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/MethodCallExpr.java @@ -1,115 +1,301 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class MethodCallExpr extends Expression { - - private Expression scope; - - private List typeArgs; - - private NameExpr name; - - private List 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 args) { - setScope(scope); - setName(name); - setArgs(args); - } - - public MethodCallExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression scope, final List typeArgs, final String name, final List args) { - super(beginLine, beginColumn, endLine, endColumn); - setScope(scope); - setTypeArgs(typeArgs); - setName(name); - setArgs(args); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getArgs() { - return args; - } - - public String getName() { - return name.getName(); - } - - public NameExpr getNameExpr() { - return name; - } - - public Expression getScope() { - return scope; - } - - public List getTypeArgs() { - return typeArgs; - } - - public void setArgs(final List args) { - this.args = args; - setAsParentNodeOf(this.args); - } - - public void setName(final String name) { - this.name = new NameExpr(name); - } - - public void setNameExpr(NameExpr name) { - this.name = name; - } - - public void setScope(final Expression scope) { - this.scope = scope; - setAsParentNodeOf(this.scope); - } - - public void setTypeArgs(final List typeArgs) { - this.typeArgs = typeArgs; - setAsParentNodeOf(this.typeArgs); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.MethodCallExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import java.util.function.Consumer; + +/** + * A method call on an object.
circle.circumference()
In a.<String>bb(15); a + * is the scope, String is a type argument, bb is the name and 15 is an argument. + * + * @author Julio Vilmar Gesser + */ +public final class MethodCallExpr extends Expression implements NodeWithTypeArguments, NodeWithArguments, NodeWithSimpleName, NodeWithOptionalScope { + + @OptionalProperty + private Expression scope; + + @OptionalProperty + private NodeList typeArguments; + + private SimpleName name; + + private NodeList arguments; + + public MethodCallExpr() { + this(null, null, new NodeList<>(), new SimpleName(), new NodeList<>()); + } + + public MethodCallExpr(String name, Expression... arguments) { + this(null, null, new NodeList<>(), new SimpleName(name), new NodeList<>(arguments)); + } + + public MethodCallExpr(final Expression scope, final String name) { + this(null, scope, new NodeList<>(), new SimpleName(name), new NodeList<>()); + } + + public MethodCallExpr(final Expression scope, final SimpleName name) { + this(null, scope, new NodeList<>(), name, new NodeList<>()); + } + + public MethodCallExpr(final Expression scope, final String name, final NodeList arguments) { + this(null, scope, new NodeList<>(), new SimpleName(name), arguments); + } + + public MethodCallExpr(final Expression scope, final SimpleName name, final NodeList arguments) { + this(null, scope, new NodeList<>(), name, arguments); + } + + @AllFieldsConstructor + public MethodCallExpr(final Expression scope, final NodeList typeArguments, final SimpleName name, final NodeList arguments) { + this(null, scope, typeArguments, name, arguments); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public MethodCallExpr(TokenRange tokenRange, Expression scope, NodeList typeArguments, SimpleName name, NodeList arguments) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setName(name); + setArguments(arguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getArguments() { + return arguments; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getScope() { + return Optional.ofNullable(scope); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodCallExpr setArguments(final NodeList arguments) { + assertNotNull(arguments); + if (arguments == this.arguments) { + return (MethodCallExpr) this; + } + notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments); + if (this.arguments != null) + this.arguments.setParentNode(null); + this.arguments = arguments; + setAsParentNodeOf(arguments); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodCallExpr setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (MethodCallExpr) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodCallExpr setScope(final Expression scope) { + if (scope == this.scope) { + return (MethodCallExpr) this; + } + notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope); + if (this.scope != null) + this.scope.setParentNode(null); + this.scope = scope; + setAsParentNodeOf(scope); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the MethodCallExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodCallExpr setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (MethodCallExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.remove(i); + return true; + } + } + if (scope != null) { + if (node == scope) { + removeScope(); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public MethodCallExpr removeScope() { + return setScope((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public MethodCallExpr clone() { + return (MethodCallExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public MethodCallExprMetaModel getMetaModel() { + return JavaParserMetaModel.methodCallExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.set(i, (Expression) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (scope != null) { + if (node == scope) { + setScope((Expression) replacementNode); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodCallExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodCallExpr asMethodCallExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodCallExpr(Consumer action) { + action.accept(this); + } + + public ResolvedMethodDeclaration resolveInvokedMethod() { + return getSymbolResolver().resolveDeclaration(this, ResolvedMethodDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodCallExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/MethodReferenceExpr.java index 93e103f..8ddaac0 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/MethodReferenceExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/MethodReferenceExpr.java @@ -1,97 +1,229 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * 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 List typeParameters; - - private String identifier; - - public MethodReferenceExpr() { - } - - public MethodReferenceExpr(int beginLine, int beginColumn, int endLine, - int endColumn, Expression scope, - List typeParameters, String identifier) { - - super(beginLine, beginColumn, endLine, endColumn); - setIdentifier(identifier); - setScope(scope); - setTypeParameters(typeParameters); - } - - @Override - public R accept(GenericVisitor v, A arg) { - - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Expression getScope() { - return scope; - } - - public void setScope(Expression scope) { - this.scope = scope; - setAsParentNodeOf(this.scope); - } - - public List getTypeParameters() { - return typeParameters; - } - - public void setTypeParameters(List typeParameters) { - this.typeParameters = typeParameters; - setAsParentNodeOf(this.typeParameters); - } - - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNonEmpty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.MethodReferenceExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * Method reference expressions introduced in Java 8 specifically designed to simplify lambda Expressions. + * Note that the field "identifier", indicating the word to the right of the ::, is not always a method name, + * it can be "new". + *
In System.out::println; the scope is System.out and the identifier is "println" + *
(test ? stream.map(String::trim) : stream)::toArray; + *
In Bar<String>::<Integer>new the String type argument is on the scope, + * and the Integer type argument is on this MethodReferenceExpr. + * + * @author Raquel Pau + */ +public final class MethodReferenceExpr extends Expression implements NodeWithTypeArguments, NodeWithIdentifier { + + private Expression scope; + + @OptionalProperty + private NodeList typeArguments; + + @NonEmptyProperty + private String identifier; + + public MethodReferenceExpr() { + this(null, new ClassExpr(), null, "empty"); + } + + @AllFieldsConstructor + public MethodReferenceExpr(Expression scope, NodeList typeArguments, String identifier) { + this(null, scope, typeArguments, identifier); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public MethodReferenceExpr(TokenRange tokenRange, Expression scope, NodeList typeArguments, String identifier) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setIdentifier(identifier); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getScope() { + return scope; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodReferenceExpr setScope(final Expression scope) { + assertNotNull(scope); + if (scope == this.scope) { + return (MethodReferenceExpr) this; + } + notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope); + if (this.scope != null) + this.scope.setParentNode(null); + this.scope = scope; + setAsParentNodeOf(scope); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the MethodReferenceExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodReferenceExpr setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (MethodReferenceExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public String getIdentifier() { + return identifier; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodReferenceExpr setIdentifier(final String identifier) { + assertNonEmpty(identifier); + if (identifier == this.identifier) { + return (MethodReferenceExpr) this; + } + notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier); + this.identifier = identifier; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public MethodReferenceExpr clone() { + return (MethodReferenceExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public MethodReferenceExprMetaModel getMetaModel() { + return JavaParserMetaModel.methodReferenceExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == scope) { + setScope((Expression) replacementNode); + return true; + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isMethodReferenceExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public MethodReferenceExpr asMethodReferenceExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodReferenceExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toMethodReferenceExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/Name.java b/JavaParser/src/com/github/javaparser/ast/expr/Name.java new file mode 100644 index 0000000..0eeabd3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/expr/Name.java @@ -0,0 +1,241 @@ +/* + * 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.JavaParser; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NameMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNonEmpty; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; + +/** + * A name that may consist of multiple identifiers. + * In other words: it.may.contain.dots. + *

+ * The rightmost identifier is "identifier", + * The one to the left of it is "qualifier.identifier", etc. + *

+ * You can construct one from a String with the name(...) method. + * + * @author Julio Vilmar Gesser + * @see SimpleName + */ +public final class Name extends Node implements NodeWithIdentifier, NodeWithAnnotations { + + @NonEmptyProperty + private String identifier; + + @OptionalProperty + private Name qualifier; + + private NodeList annotations; + + public Name() { + this(null, null, "empty", new NodeList<>()); + } + + public Name(final String identifier) { + this(null, null, identifier, new NodeList<>()); + } + + public Name(Name qualifier, final String identifier) { + this(null, qualifier, identifier, new NodeList<>()); + } + + @AllFieldsConstructor + public Name(Name qualifier, final String identifier, NodeList annotations) { + this(null, qualifier, identifier, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Name(TokenRange tokenRange, Name qualifier, String identifier, NodeList annotations) { + super(tokenRange); + setQualifier(qualifier); + setIdentifier(identifier); + setAnnotations(annotations); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public String getIdentifier() { + return identifier; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name setIdentifier(final String identifier) { + assertNonEmpty(identifier); + if (identifier == this.identifier) { + return (Name) this; + } + notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier); + this.identifier = identifier; + return this; + } + + /** + * Creates a new {@link Name} from a qualified name.
+ * The qualified name can contains "." (dot) characters. + * + * @param qualifiedName qualified name + * @return instanceof {@link Name} + * @deprecated use JavaParser.parseName instead + */ + @Deprecated + public static Name parse(String qualifiedName) { + assertNonEmpty(qualifiedName); + return JavaParser.parseName(qualifiedName); + } + + /** + * @return the complete qualified name. Only the identifiers and the dots, so no comments or whitespace. + */ + public String asString() { + if (qualifier != null) { + return qualifier.asString() + "." + identifier; + } + return identifier; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getQualifier() { + return Optional.ofNullable(qualifier); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name setQualifier(final Name qualifier) { + if (qualifier == this.qualifier) { + return (Name) this; + } + notifyPropertyChange(ObservableProperty.QUALIFIER, this.qualifier, qualifier); + if (this.qualifier != null) + this.qualifier.setParentNode(null); + this.qualifier = qualifier; + setAsParentNodeOf(qualifier); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + if (qualifier != null) { + if (node == qualifier) { + removeQualifier(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public Name removeQualifier() { + return setQualifier((Name) null); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (Name) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Name clone() { + return (Name) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public NameMetaModel getMetaModel() { + return JavaParserMetaModel.nameMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + if (qualifier != null) { + if (node == qualifier) { + setQualifier((Name) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/NameExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/NameExpr.java index 0e56798..d871589 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/NameExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/NameExpr.java @@ -1,63 +1,165 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.NamedNode; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public class NameExpr extends Expression implements NamedNode { - - private String name; - - public NameExpr() { - } - - public NameExpr(final String name) { - this.name = name; - } - - public NameExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String name) { - super(beginLine, beginColumn, endLine, endColumn); - this.name = name; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public
void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public final String getName() { - return name; - } - - public final void setName(final String name) { - this.name = name; - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.NameExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.types.ResolvedUnionType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Whenever a SimpleName is used in an expression, it is wrapped in NameExpr. + *
In int x = a + 3; a is a SimpleName inside a NameExpr. + * + * @author Julio Vilmar Gesser + */ +public final class NameExpr extends Expression implements NodeWithSimpleName, Resolvable { + + private SimpleName name; + + public NameExpr() { + this(null, new SimpleName()); + } + + public NameExpr(final String name) { + this(null, new SimpleName(name)); + } + + @AllFieldsConstructor + public NameExpr(final SimpleName name) { + this(name.getTokenRange().orElse(null), name); + setRange(name.getRange().orElse(null)); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public NameExpr(TokenRange tokenRange, SimpleName name) { + super(tokenRange); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NameExpr setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (NameExpr) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public NameExpr clone() { + return (NameExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public NameExprMetaModel getMetaModel() { + return JavaParserMetaModel.nameExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNameExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NameExpr asNameExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNameExpr(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedValueDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedValueDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNameExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/NormalAnnotationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/NormalAnnotationExpr.java index 8854586..dd0fce5 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/NormalAnnotationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/NormalAnnotationExpr.java @@ -1,66 +1,180 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class NormalAnnotationExpr extends AnnotationExpr { - - private List pairs; - - public NormalAnnotationExpr() { - } - - public NormalAnnotationExpr(final NameExpr name, final List pairs) { - setName(name); - setPairs(pairs); - } - - public NormalAnnotationExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final NameExpr name, final List pairs) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setPairs(pairs); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getPairs() { - return pairs; - } - - public void setPairs(final List pairs) { - this.pairs = pairs; - setAsParentNodeOf(this.pairs); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.NormalAnnotationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An annotation that has zero or more key-value pairs.
@Mapping(a=5, d=10) + * @author Julio Vilmar Gesser + */ +public final class NormalAnnotationExpr extends AnnotationExpr { + + private NodeList pairs; + + public NormalAnnotationExpr() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public NormalAnnotationExpr(final Name name, final NodeList pairs) { + this(null, name, pairs); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public NormalAnnotationExpr(TokenRange tokenRange, Name name, NodeList pairs) { + super(tokenRange, name); + setPairs(pairs); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getPairs() { + return pairs; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NormalAnnotationExpr setPairs(final NodeList pairs) { + assertNotNull(pairs); + if (pairs == this.pairs) { + return (NormalAnnotationExpr) this; + } + notifyPropertyChange(ObservableProperty.PAIRS, this.pairs, pairs); + if (this.pairs != null) + this.pairs.setParentNode(null); + this.pairs = pairs; + setAsParentNodeOf(pairs); + return this; + } + + /** + * adds a pair to this annotation + * + * @return this, the {@link NormalAnnotationExpr} + */ + public NormalAnnotationExpr addPair(String key, String value) { + return addPair(key, new NameExpr(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); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < pairs.size(); i++) { + if (pairs.get(i) == node) { + pairs.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public NormalAnnotationExpr clone() { + return (NormalAnnotationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public NormalAnnotationExprMetaModel getMetaModel() { + return JavaParserMetaModel.normalAnnotationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < pairs.size(); i++) { + if (pairs.get(i) == node) { + pairs.set(i, (MemberValuePair) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNormalAnnotationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NormalAnnotationExpr asNormalAnnotationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNormalAnnotationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNormalAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/NullLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/NullLiteralExpr.java index 3bc68fa..b71ed5b 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/NullLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/NullLiteralExpr.java @@ -1,45 +1,119 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.NullLiteralExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A literal "null". + *
null + * + * @author Julio Vilmar Gesser + */ +public final class NullLiteralExpr extends LiteralExpr { + + @AllFieldsConstructor + public NullLiteralExpr() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public NullLiteralExpr(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public NullLiteralExpr clone() { + return (NullLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public NullLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.nullLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isNullLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public NullLiteralExpr asNullLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNullLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toNullLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ObjectCreationExpr.java index 0d431e9..c4fe045 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ObjectCreationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ObjectCreationExpr.java @@ -1,118 +1,355 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ObjectCreationExpr extends Expression { - - private Expression scope; - - private ClassOrInterfaceType type; - - private List typeArgs; - - private List args; - - private List anonymousClassBody; - - public ObjectCreationExpr() { - } - - public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final List args) { - setScope(scope); - setType(type); - setArgs(args); - } - - public ObjectCreationExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression scope, final ClassOrInterfaceType type, final List typeArgs, - final List args, final List anonymousBody) { - super(beginLine, beginColumn, endLine, endColumn); - setScope(scope); - setType(type); - setTypeArgs(typeArgs); - setArgs(args); - setAnonymousClassBody(anonymousBody); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getAnonymousClassBody() { - return anonymousClassBody; - } - - public List getArgs() { - return args; - } - - public Expression getScope() { - return scope; - } - - public ClassOrInterfaceType getType() { - return type; - } - - public List getTypeArgs() { - return typeArgs; - } - - public void setAnonymousClassBody(final List anonymousClassBody) { - this.anonymousClassBody = anonymousClassBody; - setAsParentNodeOf(this.anonymousClassBody); - } - - public void setArgs(final List 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 typeArgs) { - this.typeArgs = typeArgs; - setAsParentNodeOf(this.typeArgs); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ObjectCreationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import java.util.function.Consumer; + +/** + * A constructor call. + *
In new HashMap.Entry<String, Long>(15) {public String getKey() {return null;}}; + * HashMap.Entry is the type, String and Long are type arguments, 15 is an argument, and everything in { } + * is the anonymous class body. + *

In class B { class C { public void a() { new B().new C(); } } } the scope is new B() + * of ObjectCreationExpr new B().new C() + * + * @author Julio Vilmar Gesser + */ +public final class ObjectCreationExpr extends Expression implements NodeWithTypeArguments, NodeWithType, NodeWithArguments, NodeWithOptionalScope { + + @OptionalProperty + private Expression scope; + + private ClassOrInterfaceType type; + + @OptionalProperty + private NodeList typeArguments; + + private NodeList arguments; + + @OptionalProperty + private NodeList> anonymousClassBody; + + public ObjectCreationExpr() { + this(null, null, new ClassOrInterfaceType(), new NodeList<>(), new NodeList<>(), null); + } + + /** + * 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 arguments Any arguments to pass to the constructor + */ + public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList arguments) { + this(null, scope, type, new NodeList<>(), arguments, null); + } + + @AllFieldsConstructor + public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList typeArguments, final NodeList arguments, final NodeList> anonymousClassBody) { + this(null, scope, type, typeArguments, arguments, anonymousClassBody); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ObjectCreationExpr(TokenRange tokenRange, Expression scope, ClassOrInterfaceType type, NodeList typeArguments, NodeList arguments, NodeList> anonymousClassBody) { + super(tokenRange); + setScope(scope); + setType(type); + setTypeArguments(typeArguments); + setArguments(arguments); + setAnonymousClassBody(anonymousClassBody); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional>> getAnonymousClassBody() { + return Optional.ofNullable(anonymousClassBody); + } + + public void addAnonymousClassBody(BodyDeclaration body) { + if (anonymousClassBody == null) + anonymousClassBody = new NodeList<>(); + anonymousClassBody.add(body); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getArguments() { + return arguments; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getScope() { + return Optional.ofNullable(scope); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceType getType() { + return type; + } + + /** + * Sets the anonymousClassBody
+ * Null means no class body
+ * Empty NodeList means new ClassName(){ } + * + * @param anonymousClassBody the anonymousClassBody, can be null or empty + * @return this, the ObjectCreationExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ObjectCreationExpr setAnonymousClassBody(final NodeList> anonymousClassBody) { + if (anonymousClassBody == this.anonymousClassBody) { + return (ObjectCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.ANONYMOUS_CLASS_BODY, this.anonymousClassBody, anonymousClassBody); + if (this.anonymousClassBody != null) + this.anonymousClassBody.setParentNode(null); + this.anonymousClassBody = anonymousClassBody; + setAsParentNodeOf(anonymousClassBody); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ObjectCreationExpr setArguments(final NodeList arguments) { + assertNotNull(arguments); + if (arguments == this.arguments) { + return (ObjectCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments); + if (this.arguments != null) + this.arguments.setParentNode(null); + this.arguments = arguments; + setAsParentNodeOf(arguments); + return this; + } + + /** + * Sets the scope + * + * @param scope the scope, can be null + * @return this, the ObjectCreationExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ObjectCreationExpr setScope(final Expression scope) { + if (scope == this.scope) { + return (ObjectCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope); + if (this.scope != null) + this.scope.setParentNode(null); + this.scope = scope; + setAsParentNodeOf(scope); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ObjectCreationExpr setType(final ClassOrInterfaceType type) { + assertNotNull(type); + if (type == this.type) { + return (ObjectCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ObjectCreationExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ObjectCreationExpr setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (ObjectCreationExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (anonymousClassBody != null) { + for (int i = 0; i < anonymousClassBody.size(); i++) { + if (anonymousClassBody.get(i) == node) { + anonymousClassBody.remove(i); + return true; + } + } + } + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.remove(i); + return true; + } + } + if (scope != null) { + if (node == scope) { + removeScope(); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ObjectCreationExpr removeScope() { + return setScope((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ObjectCreationExpr clone() { + return (ObjectCreationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ObjectCreationExprMetaModel getMetaModel() { + return JavaParserMetaModel.objectCreationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (anonymousClassBody != null) { + for (int i = 0; i < anonymousClassBody.size(); i++) { + if (anonymousClassBody.get(i) == node) { + anonymousClassBody.set(i, (BodyDeclaration) replacementNode); + return true; + } + } + } + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.set(i, (Expression) replacementNode); + return true; + } + } + if (scope != null) { + if (node == scope) { + setScope((Expression) replacementNode); + return true; + } + } + if (node == type) { + setType((ClassOrInterfaceType) replacementNode); + return true; + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isObjectCreationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ObjectCreationExpr asObjectCreationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifObjectCreationExpr(Consumer action) { + action.accept(this); + } + + public ResolvedConstructorDeclaration resolveInvokedConstructor() { + return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toObjectCreationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/QualifiedNameExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/QualifiedNameExpr.java deleted file mode 100644 index a1c2caa..0000000 --- a/JavaParser/src/com/github/javaparser/ast/expr/QualifiedNameExpr.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final NameExpr scope, final String name) { - super(beginLine, beginColumn, endLine, endColumn, name); - setQualifier(scope); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public
void accept(final VoidVisitor 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); - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/SimpleName.java b/JavaParser/src/com/github/javaparser/ast/expr/SimpleName.java new file mode 100644 index 0000000..faaa541 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/expr/SimpleName.java @@ -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.expr; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNonEmpty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.NonEmptyProperty; +import com.github.javaparser.metamodel.SimpleNameMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * A name that consists of a single identifier. + * In other words: it.does.NOT.contain.dots. + * + * @see Name + */ +public final class SimpleName extends Node implements NodeWithIdentifier { + + @NonEmptyProperty + private String identifier; + + public SimpleName() { + this(null, "empty"); + } + + @AllFieldsConstructor + public SimpleName(final String identifier) { + this(null, identifier); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SimpleName(TokenRange tokenRange, String identifier) { + super(tokenRange); + setIdentifier(identifier); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public String getIdentifier() { + return identifier; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName setIdentifier(final String identifier) { + assertNonEmpty(identifier); + if (identifier == this.identifier) { + return (SimpleName) this; + } + notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier); + this.identifier = identifier; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + public String asString() { + return identifier; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SimpleName clone() { + return (SimpleName) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SimpleNameMetaModel getMetaModel() { + return JavaParserMetaModel.simpleNameMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java index 8aed8f5..679c714 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java @@ -1,64 +1,150 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, - final int endColumn, final NameExpr name, final Expression memberValue) { - super(beginLine, beginColumn, endLine, endColumn); - setName(name); - setMemberValue(memberValue); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.SingleMemberAnnotationExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An annotation that has a single value.
@Count(15) + * + * @author Julio Vilmar Gesser + */ +public final class SingleMemberAnnotationExpr extends AnnotationExpr { + + private Expression memberValue; + + public SingleMemberAnnotationExpr() { + this(null, new Name(), new StringLiteralExpr()); + } + + @AllFieldsConstructor + public SingleMemberAnnotationExpr(final Name name, final Expression memberValue) { + this(null, name, memberValue); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SingleMemberAnnotationExpr(TokenRange tokenRange, Name name, Expression memberValue) { + super(tokenRange, name); + setMemberValue(memberValue); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getMemberValue() { + return memberValue; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SingleMemberAnnotationExpr setMemberValue(final Expression memberValue) { + assertNotNull(memberValue); + if (memberValue == this.memberValue) { + return (SingleMemberAnnotationExpr) this; + } + notifyPropertyChange(ObservableProperty.MEMBER_VALUE, this.memberValue, memberValue); + if (this.memberValue != null) + this.memberValue.setParentNode(null); + this.memberValue = memberValue; + setAsParentNodeOf(memberValue); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SingleMemberAnnotationExpr clone() { + return (SingleMemberAnnotationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SingleMemberAnnotationExprMetaModel getMetaModel() { + return JavaParserMetaModel.singleMemberAnnotationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == memberValue) { + setMemberValue((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSingleMemberAnnotationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SingleMemberAnnotationExpr asSingleMemberAnnotationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSingleMemberAnnotationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSingleMemberAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/StringLiteralExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/StringLiteralExpr.java index e2582a6..a7b4dd5 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/StringLiteralExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/StringLiteralExpr.java @@ -1,61 +1,173 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public class StringLiteralExpr extends LiteralExpr { - - protected String value; - - public StringLiteralExpr() { - } - - public StringLiteralExpr(final String value) { - this.value = value; - } - - public StringLiteralExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String value) { - super(beginLine, beginColumn, endLine, endColumn); - this.value = value; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public final String getValue() { - return value; - } - - public final void setValue(final String value) { - this.value = value; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.StringLiteralExprMetaModel; +import com.github.javaparser.utils.StringEscapeUtils; +import com.github.javaparser.utils.Utils; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A literal string. + *
"Hello World!" + *
"\"\n" + *
"\u2122" + *
"™" + *
"💩" + * + * @author Julio Vilmar Gesser + */ +public final class StringLiteralExpr extends LiteralStringValueExpr { + + public StringLiteralExpr() { + this(null, "empty"); + } + + /** + * Creates a string literal expression from given string. Escapes EOL characters. + * + * @param value the value of the literal + */ + @AllFieldsConstructor + public StringLiteralExpr(final String value) { + this(null, Utils.escapeEndOfLines(value)); + } + + /** + * Utility method that creates a new StringLiteralExpr. Escapes EOL characters. + * + * @deprecated Use {@link #StringLiteralExpr(String)} instead. + */ + @Deprecated + public static StringLiteralExpr escape(String string) { + return new StringLiteralExpr(Utils.escapeEndOfLines(string)); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public StringLiteralExpr(TokenRange tokenRange, String value) { + super(tokenRange, value); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + /** + * Sets the content of this expressions to given value. Escapes EOL characters. + * + * @param value the new literal value + * @return self + */ + public StringLiteralExpr setEscapedValue(String value) { + this.value = Utils.escapeEndOfLines(value); + return this; + } + + /** + * @return the unescaped literal value + */ + public String asString() { + return StringEscapeUtils.unescapeJava(value); + } + + /** + * Escapes the given string from special characters and uses it as the literal value. + * + * @param value unescaped string + * @return this literal expression + */ + public StringLiteralExpr setString(String value) { + this.value = StringEscapeUtils.escapeJava(value); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public StringLiteralExpr clone() { + return (StringLiteralExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public StringLiteralExprMetaModel getMetaModel() { + return JavaParserMetaModel.stringLiteralExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isStringLiteralExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public StringLiteralExpr asStringLiteralExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifStringLiteralExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toStringLiteralExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/SuperExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/SuperExpr.java index 6d3f171..2de37fb 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/SuperExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/SuperExpr.java @@ -1,62 +1,173 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression classExpr) { - super(beginLine, beginColumn, endLine, endColumn); - setClassExpr(classExpr); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.SuperExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; + +/** + * An occurrence of the "super" keyword.
World.super.greet() is a MethodCallExpr of method name greet, + * and scope "World.super" which is a SuperExpr with classExpr "World".
super.name is a + * FieldAccessExpr of field greet, and a SuperExpr as its scope. The SuperExpr has no classExpr. + * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt + * @see ThisExpr + */ +public final class SuperExpr extends Expression { + + @OptionalProperty + private Expression classExpr; + + public SuperExpr() { + this(null, null); + } + + @AllFieldsConstructor + public SuperExpr(final Expression classExpr) { + this(null, classExpr); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SuperExpr(TokenRange tokenRange, Expression classExpr) { + super(tokenRange); + setClassExpr(classExpr); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getClassExpr() { + return Optional.ofNullable(classExpr); + } + + /** + * Sets the classExpr + * + * @param classExpr the classExpr, can be null + * @return this, the SuperExpr + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SuperExpr setClassExpr(final Expression classExpr) { + if (classExpr == this.classExpr) { + return (SuperExpr) this; + } + notifyPropertyChange(ObservableProperty.CLASS_EXPR, this.classExpr, classExpr); + if (this.classExpr != null) + this.classExpr.setParentNode(null); + this.classExpr = classExpr; + setAsParentNodeOf(classExpr); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (classExpr != null) { + if (node == classExpr) { + removeClassExpr(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public SuperExpr removeClassExpr() { + return setClassExpr((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SuperExpr clone() { + return (SuperExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SuperExprMetaModel getMetaModel() { + return JavaParserMetaModel.superExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (classExpr != null) { + if (node == classExpr) { + setClassExpr((Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSuperExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SuperExpr asSuperExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSuperExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSuperExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/ThisExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/ThisExpr.java index 6a6aba8..dc9981d 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/ThisExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/ThisExpr.java @@ -1,62 +1,176 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression classExpr) { - super(beginLine, beginColumn, endLine, endColumn); - setClassExpr(classExpr); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.ThisExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import java.util.function.Consumer; + +/** + * An occurrence of the "this" keyword.
World.this.greet() is a MethodCallExpr of method name greet, + * and scope "World.super" which is a ThisExpr with classExpr "World".
this.name is a + * FieldAccessExpr of field greet, and a ThisExpr as its scope. The ThisExpr has no classExpr. + * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt + * @see ThisExpr + */ +public final class ThisExpr extends Expression implements Resolvable { + + @OptionalProperty + private Expression classExpr; + + public ThisExpr() { + this(null, null); + } + + @AllFieldsConstructor + public ThisExpr(final Expression classExpr) { + this(null, classExpr); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ThisExpr(TokenRange tokenRange, Expression classExpr) { + super(tokenRange); + setClassExpr(classExpr); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getClassExpr() { + return Optional.ofNullable(classExpr); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ThisExpr setClassExpr(final Expression classExpr) { + if (classExpr == this.classExpr) { + return (ThisExpr) this; + } + notifyPropertyChange(ObservableProperty.CLASS_EXPR, this.classExpr, classExpr); + if (this.classExpr != null) + this.classExpr.setParentNode(null); + this.classExpr = classExpr; + setAsParentNodeOf(classExpr); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (classExpr != null) { + if (node == classExpr) { + removeClassExpr(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ThisExpr removeClassExpr() { + return setClassExpr((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ThisExpr clone() { + return (ThisExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ThisExprMetaModel getMetaModel() { + return JavaParserMetaModel.thisExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (classExpr != null) { + if (node == classExpr) { + setClassExpr((Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isThisExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ThisExpr asThisExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThisExpr(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedTypeDeclaration resolve() { + return getSymbolResolver().resolveDeclaration(this, ResolvedTypeDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toThisExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/TypeExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/TypeExpr.java index 8cbd796..3d74b6e 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/TypeExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/TypeExpr.java @@ -1,64 +1,155 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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{ - - private Type type; - - public TypeExpr(){} - - public TypeExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - } - - @Override - public R accept(GenericVisitor v, A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(VoidVisitor v, A arg) { - v.visit(this, arg); - } - - public Type getType() { - return type; - } - - public void setType(Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.TypeExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * This class is just instantiated as scopes for MethodReferenceExpr nodes to encapsulate Types. + *
In World::greet the ClassOrInterfaceType "World" is wrapped in a TypeExpr + * before it is set as the scope of the MethodReferenceExpr. + * + * @author Raquel Pau + */ +public final class TypeExpr extends Expression implements NodeWithType { + + private Type type; + + public TypeExpr() { + this(null, new ClassOrInterfaceType()); + } + + @AllFieldsConstructor + public TypeExpr(Type type) { + this(null, type); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public TypeExpr(TokenRange tokenRange, Type type) { + super(tokenRange); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TypeExpr setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (TypeExpr) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public TypeExpr clone() { + return (TypeExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public TypeExprMetaModel getMetaModel() { + return JavaParserMetaModel.typeExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeExpr asTypeExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/UnaryExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/UnaryExpr.java index b71825a..4008544 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/UnaryExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/UnaryExpr.java @@ -1,85 +1,220 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -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 static 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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression expr, final Operator op) { - super(beginLine, beginColumn, endLine, endColumn); - setExpr(expr); - setOperator(op); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.DerivedProperty; +import com.github.javaparser.metamodel.UnaryExprMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.printer.Printable; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An expression where an operator is applied to a single expression. + * It supports the operators that are found the the UnaryExpr.Operator enum. + *
11++ + *
++11 + *
~1 + *
-333 + * + * @author Julio Vilmar Gesser + */ +public final class UnaryExpr extends Expression implements NodeWithExpression { + + public enum Operator implements Printable { + + PLUS("+", false), + MINUS("-", false), + PREFIX_INCREMENT("++", false), + PREFIX_DECREMENT("--", false), + LOGICAL_COMPLEMENT("!", false), + BITWISE_COMPLEMENT("~", false), + POSTFIX_INCREMENT("++", true), + POSTFIX_DECREMENT("--", true); + + private final String codeRepresentation; + + private final boolean isPostfix; + + Operator(String codeRepresentation, boolean isPostfix) { + this.codeRepresentation = codeRepresentation; + this.isPostfix = isPostfix; + } + + public String asString() { + return codeRepresentation; + } + + public boolean isPostfix() { + return isPostfix; + } + + public boolean isPrefix() { + return !isPostfix(); + } + } + + private Expression expression; + + private Operator operator; + + public UnaryExpr() { + this(null, new IntegerLiteralExpr(), Operator.POSTFIX_INCREMENT); + } + + @AllFieldsConstructor + public UnaryExpr(final Expression expression, final Operator operator) { + this(null, expression, operator); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public UnaryExpr(TokenRange tokenRange, Expression expression, Operator operator) { + super(tokenRange); + setExpression(expression); + setOperator(operator); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Operator getOperator() { + return operator; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public UnaryExpr setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (UnaryExpr) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public UnaryExpr setOperator(final Operator operator) { + assertNotNull(operator); + if (operator == this.operator) { + return (UnaryExpr) this; + } + notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator); + this.operator = operator; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @DerivedProperty + public boolean isPostfix() { + return operator.isPostfix(); + } + + @DerivedProperty + public boolean isPrefix() { + return !isPostfix(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public UnaryExpr clone() { + return (UnaryExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public UnaryExprMetaModel getMetaModel() { + return JavaParserMetaModel.unaryExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnaryExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnaryExpr asUnaryExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnaryExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnaryExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/expr/VariableDeclarationExpr.java b/JavaParser/src/com/github/javaparser/ast/expr/VariableDeclarationExpr.java index 42d1e39..8745ce7 100644 --- a/JavaParser/src/com/github/javaparser/ast/expr/VariableDeclarationExpr.java +++ b/JavaParser/src/com/github/javaparser/ast/expr/VariableDeclarationExpr.java @@ -1,116 +1,261 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.expr; - -import com.github.javaparser.ast.body.ModifierSet; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class VariableDeclarationExpr extends Expression { - - private int modifiers; - - private List annotations; - - private Type type; - - private List vars; - - public VariableDeclarationExpr() { - } - - public VariableDeclarationExpr(final Type type, final List vars) { - setType(type); - setVars(vars); - } - - public VariableDeclarationExpr(final int modifiers, final Type type, final List vars) { - setModifiers(modifiers); - setType(type); - setVars(vars); - } - - public VariableDeclarationExpr(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final int modifiers, final List annotations, final Type type, - final List vars) { - super(beginLine, beginColumn, endLine, endColumn); - setModifiers(modifiers); - setAnnotations(annotations); - setType(type); - setVars(vars); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getAnnotations() { - return annotations; - } - - /** - * Return the modifiers of this variable declaration. - * - * @see ModifierSet - * @return modifiers - */ - public int getModifiers() { - return modifiers; - } - - public Type getType() { - return type; - } - - public List getVars() { - return vars; - } - - public void setAnnotations(final List annotations) { - this.annotations = annotations; - setAsParentNodeOf(this.annotations); - } - - public void setModifiers(final int modifiers) { - this.modifiers = modifiers; - } - - public void setType(final Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - public void setVars(final List vars) { - this.vars = vars; - setAsParentNodeOf(this.vars); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import com.github.javaparser.metamodel.VariableDeclarationExprMetaModel; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Collectors; +import static com.github.javaparser.ast.NodeList.nodeList; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A declaration of variables. + * It is an expression, so it can be put in places like the initializer of a for loop, + * or the resources part of the try statement. + *
final int x=3, y=55 + * + *
All annotations preceding the type will be set on this object, not on the type. + * JavaParser doesn't know if it they are applicable to the method or the type. + * + * @author Julio Vilmar Gesser + */ +public final class VariableDeclarationExpr extends Expression implements NodeWithFinalModifier, NodeWithAnnotations, NodeWithVariables { + + private EnumSet modifiers; + + private NodeList annotations; + + @NonEmptyProperty + private NodeList variables; + + public VariableDeclarationExpr() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>()); + } + + public VariableDeclarationExpr(final Type type, String variableName) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), nodeList(new VariableDeclarator(type, variableName))); + } + + public VariableDeclarationExpr(VariableDeclarator var) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), nodeList(var)); + } + + public VariableDeclarationExpr(final Type type, String variableName, Modifier... modifiers) { + this(null, Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), new NodeList<>(), nodeList(new VariableDeclarator(type, variableName))); + } + + public VariableDeclarationExpr(VariableDeclarator var, Modifier... modifiers) { + this(null, Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), new NodeList<>(), nodeList(var)); + } + + public VariableDeclarationExpr(final NodeList variables) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), variables); + } + + public VariableDeclarationExpr(final EnumSet modifiers, final NodeList variables) { + this(null, modifiers, new NodeList<>(), variables); + } + + @AllFieldsConstructor + public VariableDeclarationExpr(final EnumSet modifiers, final NodeList annotations, final NodeList variables) { + this(null, modifiers, annotations, variables); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public VariableDeclarationExpr(TokenRange tokenRange, EnumSet modifiers, NodeList annotations, NodeList variables) { + super(tokenRange); + setModifiers(modifiers); + setAnnotations(annotations); + setVariables(variables); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + /** + * Return the modifiers of this variable declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getVariables() { + return variables; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarationExpr setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (VariableDeclarationExpr) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarationExpr setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (VariableDeclarationExpr) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarationExpr setVariables(final NodeList variables) { + assertNotNull(variables); + if (variables == this.variables) { + return (VariableDeclarationExpr) this; + } + notifyPropertyChange(ObservableProperty.VARIABLES, this.variables, variables); + if (this.variables != null) + this.variables.setParentNode(null); + this.variables = variables; + setAsParentNodeOf(variables); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + for (int i = 0; i < variables.size(); i++) { + if (variables.get(i) == node) { + variables.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public VariableDeclarationExpr clone() { + return (VariableDeclarationExpr) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public VariableDeclarationExprMetaModel getMetaModel() { + return JavaParserMetaModel.variableDeclarationExprMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + for (int i = 0; i < variables.size(); i++) { + if (variables.get(i) == node) { + variables.set(i, (VariableDeclarator) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVariableDeclarationExpr() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VariableDeclarationExpr asVariableDeclarationExpr() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVariableDeclarationExpr(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVariableDeclarationExpr() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/internal/Utils.java b/JavaParser/src/com/github/javaparser/ast/internal/Utils.java deleted file mode 100644 index 091c2e2..0000000 --- a/JavaParser/src/com/github/javaparser/ast/internal/Utils.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.javaparser.ast.internal; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * @author Federico Tomassetti - * @since 2.0.1 - */ -public class Utils { - - public static List ensureNotNull(List list) { - return list == null ? Collections.emptyList() : list; - } - - public static boolean isNullOrEmpty(Collection collection) { - return collection == null || collection.isEmpty(); - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleDeclaration.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleDeclaration.java new file mode 100644 index 0000000..547c2cc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleDeclaration.java @@ -0,0 +1,200 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleDeclarationMetaModel; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * A Java 9 Jigsaw module declaration. @Foo module com.github.abc { requires a.B; } + */ +public final class ModuleDeclaration extends Node implements NodeWithName, NodeWithAnnotations { + + private Name name; + + private NodeList annotations; + + private boolean isOpen; + + private NodeList moduleStmts; + + public ModuleDeclaration() { + this(null, new NodeList<>(), new Name(), false, new NodeList<>()); + } + + public ModuleDeclaration(Name name, boolean isOpen) { + this(null, new NodeList<>(), name, isOpen, new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleDeclaration(NodeList annotations, Name name, boolean isOpen, NodeList moduleStmts) { + this(null, annotations, name, isOpen, moduleStmts); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleDeclaration(TokenRange tokenRange, NodeList annotations, Name name, boolean isOpen, NodeList moduleStmts) { + super(tokenRange); + setAnnotations(annotations); + setName(name); + setOpen(isOpen); + setModuleStmts(moduleStmts); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ModuleDeclaration) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (ModuleDeclaration) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + for (int i = 0; i < moduleStmts.size(); i++) { + if (moduleStmts.get(i) == node) { + moduleStmts.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isOpen() { + return isOpen; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setOpen(final boolean isOpen) { + if (isOpen == this.isOpen) { + return (ModuleDeclaration) this; + } + notifyPropertyChange(ObservableProperty.OPEN, this.isOpen, isOpen); + this.isOpen = isOpen; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getModuleStmts() { + return moduleStmts; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setModuleStmts(final NodeList moduleStmts) { + assertNotNull(moduleStmts); + if (moduleStmts == this.moduleStmts) { + return (ModuleDeclaration) this; + } + notifyPropertyChange(ObservableProperty.MODULE_STMTS, this.moduleStmts, moduleStmts); + if (this.moduleStmts != null) + this.moduleStmts.setParentNode(null); + this.moduleStmts = moduleStmts; + setAsParentNodeOf(moduleStmts); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleDeclaration clone() { + return (ModuleDeclaration) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleDeclarationMetaModel getMetaModel() { + return JavaParserMetaModel.moduleDeclarationMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + for (int i = 0; i < moduleStmts.size(); i++) { + if (moduleStmts.get(i) == node) { + moduleStmts.set(i, (ModuleStmt) replacementNode); + return true; + } + } + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleExportsStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleExportsStmt.java new file mode 100644 index 0000000..61440b1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleExportsStmt.java @@ -0,0 +1,164 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleExportsStmtMetaModel; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +public final class ModuleExportsStmt extends ModuleStmt implements NodeWithName { + + private Name name; + + private NodeList moduleNames; + + public ModuleExportsStmt() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleExportsStmt(Name name, NodeList moduleNames) { + this(null, name, moduleNames); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleExportsStmt(TokenRange tokenRange, Name name, NodeList moduleNames) { + super(tokenRange); + setName(name); + setModuleNames(moduleNames); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < moduleNames.size(); i++) { + if (moduleNames.get(i) == node) { + moduleNames.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleExportsStmt setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ModuleExportsStmt) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getModuleNames() { + return moduleNames; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleExportsStmt setModuleNames(final NodeList moduleNames) { + assertNotNull(moduleNames); + if (moduleNames == this.moduleNames) { + return (ModuleExportsStmt) this; + } + notifyPropertyChange(ObservableProperty.MODULE_NAMES, this.moduleNames, moduleNames); + if (this.moduleNames != null) + this.moduleNames.setParentNode(null); + this.moduleNames = moduleNames; + setAsParentNodeOf(moduleNames); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleExportsStmt clone() { + return (ModuleExportsStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleExportsStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleExportsStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < moduleNames.size(); i++) { + if (moduleNames.get(i) == node) { + moduleNames.set(i, (Name) replacementNode); + return true; + } + } + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleExportsStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleExportsStmt asModuleExportsStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleExportsStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleExportsStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleOpensStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleOpensStmt.java new file mode 100644 index 0000000..25565da --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleOpensStmt.java @@ -0,0 +1,164 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleOpensStmtMetaModel; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +public final class ModuleOpensStmt extends ModuleStmt implements NodeWithName { + + private Name name; + + private NodeList moduleNames; + + public ModuleOpensStmt() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleOpensStmt(Name name, NodeList moduleNames) { + this(null, name, moduleNames); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleOpensStmt(TokenRange tokenRange, Name name, NodeList moduleNames) { + super(tokenRange); + setName(name); + setModuleNames(moduleNames); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < moduleNames.size(); i++) { + if (moduleNames.get(i) == node) { + moduleNames.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleOpensStmt setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ModuleOpensStmt) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getModuleNames() { + return moduleNames; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleOpensStmt setModuleNames(final NodeList moduleNames) { + assertNotNull(moduleNames); + if (moduleNames == this.moduleNames) { + return (ModuleOpensStmt) this; + } + notifyPropertyChange(ObservableProperty.MODULE_NAMES, this.moduleNames, moduleNames); + if (this.moduleNames != null) + this.moduleNames.setParentNode(null); + this.moduleNames = moduleNames; + setAsParentNodeOf(moduleNames); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleOpensStmt clone() { + return (ModuleOpensStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleOpensStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleOpensStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < moduleNames.size(); i++) { + if (moduleNames.get(i) == node) { + moduleNames.set(i, (Name) replacementNode); + return true; + } + } + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleOpensStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleOpensStmt asModuleOpensStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleOpensStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleOpensStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleProvidesStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleProvidesStmt.java new file mode 100644 index 0000000..4ddbced --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleProvidesStmt.java @@ -0,0 +1,165 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleProvidesStmtMetaModel; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +public final class ModuleProvidesStmt extends ModuleStmt implements NodeWithType { + + private Type type; + + private NodeList withTypes; + + public ModuleProvidesStmt() { + this(null, new ClassOrInterfaceType(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleProvidesStmt(Type type, NodeList withTypes) { + this(null, type, withTypes); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleProvidesStmt(TokenRange tokenRange, Type type, NodeList withTypes) { + super(tokenRange); + setType(type); + setWithTypes(withTypes); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < withTypes.size(); i++) { + if (withTypes.get(i) == node) { + withTypes.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleProvidesStmt setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (ModuleProvidesStmt) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getWithTypes() { + return withTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleProvidesStmt setWithTypes(final NodeList withTypes) { + assertNotNull(withTypes); + if (withTypes == this.withTypes) { + return (ModuleProvidesStmt) this; + } + notifyPropertyChange(ObservableProperty.WITH_TYPES, this.withTypes, withTypes); + if (this.withTypes != null) + this.withTypes.setParentNode(null); + this.withTypes = withTypes; + setAsParentNodeOf(withTypes); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleProvidesStmt clone() { + return (ModuleProvidesStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleProvidesStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleProvidesStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == type) { + setType((Type) replacementNode); + return true; + } + for (int i = 0; i < withTypes.size(); i++) { + if (withTypes.get(i) == node) { + withTypes.set(i, (Type) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleProvidesStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleProvidesStmt asModuleProvidesStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleProvidesStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleProvidesStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleRequiresStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleRequiresStmt.java new file mode 100644 index 0000000..cede81c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleRequiresStmt.java @@ -0,0 +1,161 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleRequiresStmtMetaModel; +import java.util.EnumSet; +import static com.github.javaparser.ast.Modifier.TRANSITIVE; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A require statement in module-info.java. require a.b.C; + */ +public final class ModuleRequiresStmt extends ModuleStmt implements NodeWithStaticModifier, NodeWithName { + + private EnumSet modifiers; + + private Name name; + + public ModuleRequiresStmt() { + this(null, EnumSet.noneOf(Modifier.class), new Name()); + } + + @AllFieldsConstructor + public ModuleRequiresStmt(EnumSet modifiers, Name name) { + this(null, modifiers, name); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleRequiresStmt(TokenRange tokenRange, EnumSet modifiers, Name name) { + super(tokenRange); + setModifiers(modifiers); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleRequiresStmt setModifiers(final EnumSet modifiers) { + assertNotNull(modifiers); + if (modifiers == this.modifiers) { + return (ModuleRequiresStmt) this; + } + notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers); + this.modifiers = modifiers; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleRequiresStmt setName(final Name name) { + assertNotNull(name); + if (name == this.name) { + return (ModuleRequiresStmt) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + public boolean isTransitive() { + return getModifiers().contains(TRANSITIVE); + } + + public ModuleRequiresStmt setTransitive(boolean set) { + return setModifier(TRANSITIVE, set); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleRequiresStmt clone() { + return (ModuleRequiresStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleRequiresStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleRequiresStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((Name) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleRequiresStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleRequiresStmt asModuleRequiresStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleRequiresStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleRequiresStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleStmt.java new file mode 100644 index 0000000..176c791 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleStmt.java @@ -0,0 +1,152 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleStmtMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import java.util.Optional; + +public abstract class ModuleStmt extends Node { + + @AllFieldsConstructor + public ModuleStmt() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleStmt(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleStmt clone() { + return (ModuleStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleExportsStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleExportsStmt asModuleExportsStmt() { + throw new IllegalStateException(f("%s is not an ModuleExportsStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleOpensStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleOpensStmt asModuleOpensStmt() { + throw new IllegalStateException(f("%s is not an ModuleOpensStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleProvidesStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleProvidesStmt asModuleProvidesStmt() { + throw new IllegalStateException(f("%s is not an ModuleProvidesStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleRequiresStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleRequiresStmt asModuleRequiresStmt() { + throw new IllegalStateException(f("%s is not an ModuleRequiresStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleUsesStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleUsesStmt asModuleUsesStmt() { + throw new IllegalStateException(f("%s is not an ModuleUsesStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleExportsStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleOpensStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleProvidesStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleRequiresStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleUsesStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleExportsStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleOpensStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleProvidesStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleRequiresStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleUsesStmt() { + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/modules/ModuleUsesStmt.java b/JavaParser/src/com/github/javaparser/ast/modules/ModuleUsesStmt.java new file mode 100644 index 0000000..2bf9856 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/modules/ModuleUsesStmt.java @@ -0,0 +1,127 @@ +package com.github.javaparser.ast.modules; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleUsesStmtMetaModel; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +public final class ModuleUsesStmt extends ModuleStmt implements NodeWithType { + + private Type type; + + public ModuleUsesStmt() { + this(null); + } + + @AllFieldsConstructor + public ModuleUsesStmt(Type type) { + this(null, type); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ModuleUsesStmt(TokenRange tokenRange, Type type) { + super(tokenRange); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getType() { + return type; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleUsesStmt setType(final Type type) { + assertNotNull(type); + if (type == this.type) { + return (ModuleUsesStmt) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + if (this.type != null) + this.type.setParentNode(null); + this.type = type; + setAsParentNodeOf(type); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ModuleUsesStmt clone() { + return (ModuleUsesStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ModuleUsesStmtMetaModel getMetaModel() { + return JavaParserMetaModel.moduleUsesStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == type) { + setType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isModuleUsesStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ModuleUsesStmt asModuleUsesStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleUsesStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toModuleUsesStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java new file mode 100644 index 0000000..72060c6 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java @@ -0,0 +1,214 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.*; + +import java.lang.annotation.Annotation; +import java.util.Optional; + +import static com.github.javaparser.JavaParser.parseExpression; +import static com.github.javaparser.JavaParser.parseName; + +/** + * A node that can be annotated. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public interface NodeWithAnnotations { + NodeList getAnnotations(); + + N setAnnotations(NodeList annotations); + + void tryAddImportToParentCompilationUnit(Class clazz); + + default AnnotationExpr getAnnotation(int i) { + return getAnnotations().get(i); + } + + @SuppressWarnings("unchecked") + default N setAnnotation(int i, AnnotationExpr element) { + getAnnotations().set(i, element); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addAnnotation(AnnotationExpr element) { + getAnnotations().add(element); + return (N) this; + } + + /** + * Annotates this + * + * @param name the name of the annotation + * @return this + */ + @SuppressWarnings("unchecked") + default N addAnnotation(String name) { + NormalAnnotationExpr annotation = new NormalAnnotationExpr( + parseName(name), new NodeList<>()); + getAnnotations().add(annotation); + return (N) this; + } + + /** + * Annotates this + * + * @param name the name of the annotation + * @return the {@link NormalAnnotationExpr} added + */ + @SuppressWarnings("unchecked") + default NormalAnnotationExpr addAndGetAnnotation(String name) { + NormalAnnotationExpr annotation = new NormalAnnotationExpr( + parseName(name), new NodeList<>()); + getAnnotations().add(annotation); + return annotation; + } + + /** + * Annotates this node and automatically add the import + * + * @param clazz the class of the annotation + * @return this + */ + default N addAnnotation(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addAnnotation(clazz.getSimpleName()); + } + + /** + * Annotates this node and automatically add the import + * + * @param clazz the class of the annotation + * @return the {@link NormalAnnotationExpr} added + */ + default NormalAnnotationExpr addAndGetAnnotation(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addAndGetAnnotation(clazz.getSimpleName()); + } + + /** + * Annotates this with a marker annotation + * + * @param name the name of the annotation + * @return this + */ + @SuppressWarnings("unchecked") + default N addMarkerAnnotation(String name) { + MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr( + parseName(name)); + getAnnotations().add(markerAnnotationExpr); + return (N) this; + } + + /** + * Annotates this with a marker annotation and automatically add the import + * + * @param clazz the class of the annotation + * @return this + */ + default N addMarkerAnnotation(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addMarkerAnnotation(clazz.getSimpleName()); + } + + /** + * Annotates this with a single member annotation + * + * @param name the name of the annotation + * @param expression the part between () + * @return this + */ + @SuppressWarnings("unchecked") + default N addSingleMemberAnnotation(String name, Expression expression) { + SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr( + parseName(name), expression); + getAnnotations().add(singleMemberAnnotationExpr); + return (N) this; + } + + /** + * Annotates this with a single member annotation + * + * @param name the name of the annotation + * @param value the value, don't forget to add \"\" for a string value + * @return this + */ + default N addSingleMemberAnnotation(String name, String value) { + return addSingleMemberAnnotation(name, parseExpression(value)); + } + + /** + * Annotates this with a single member annotation and automatically add the import + * + * @param clazz the class of the annotation + * @param value the value, don't forget to add \"\" for a string value + * @return this + */ + default N addSingleMemberAnnotation(Class clazz, + String value) { + 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 + */ + default boolean isAnnotationPresent(String annotationName) { + return getAnnotations().stream().anyMatch(a -> a.getName().getIdentifier().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 + */ + default boolean isAnnotationPresent(Class annotationClass) { + return isAnnotationPresent(annotationClass.getSimpleName()); + } + + /** + * Try to find an annotation by its name + * + * @param annotationName the name of the annotation + */ + default Optional getAnnotationByName(String annotationName) { + return getAnnotations().stream().filter(a -> a.getName().getIdentifier().equals(annotationName)).findFirst(); + } + + /** + * Try to find an annotation by its class + * + * @param annotationClass the class of the annotation + */ + default Optional getAnnotationByClass(Class annotationClass) { + return getAnnotationByName(annotationClass.getSimpleName()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java new file mode 100644 index 0000000..702707c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; + +import static com.github.javaparser.JavaParser.parseExpression; + +/** + * A node with arguments. + */ +public interface NodeWithArguments { + N setArguments(NodeList arguments); + + NodeList getArguments(); + + default Expression getArgument(int i) { + return getArguments().get(i); + } + + @SuppressWarnings("unchecked") + default N addArgument(String arg) { + return addArgument(parseExpression(arg)); + } + + @SuppressWarnings("unchecked") + default N addArgument(Expression arg) { + getArguments().add(arg); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N setArgument(int i, Expression arg) { + getArguments().set(i, arg); + return (N) this; + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java new file mode 100644 index 0000000..a23e3e2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java @@ -0,0 +1,40 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.stmt.BlockStmt; + +/** + * A node with a body that is a BlockStmt. + */ +public interface NodeWithBlockStmt { + BlockStmt getBody(); + + N setBody(BlockStmt block); + + default BlockStmt createBody() { + BlockStmt block = new BlockStmt(); + setBody(block); + return block; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBody.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBody.java new file mode 100644 index 0000000..2388824 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithBody.java @@ -0,0 +1,38 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; + +public interface NodeWithBody { + Statement getBody(); + + N setBody(final Statement body); + + default BlockStmt createBlockStatementAsBody() { + BlockStmt b = new BlockStmt(); + setBody(b); + return b; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java new file mode 100644 index 0000000..4113f8b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java @@ -0,0 +1,10 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; + +public interface NodeWithCondition { + Expression getCondition(); + + N setCondition(Expression condition); +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java new file mode 100644 index 0000000..b2f2507 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java @@ -0,0 +1,71 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.ConstructorDeclaration; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +import static java.util.Collections.unmodifiableList; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toList; + +public interface NodeWithConstructors extends NodeWithSimpleName, NodeWithMembers { + /** + * Try to find a {@link ConstructorDeclaration} with no parameters by its name + * + * @return the constructors found (multiple in case of polymorphism) + */ + default Optional getDefaultConstructor() { + return getMembers().stream().filter(bd -> bd instanceof ConstructorDeclaration).map(bd -> (ConstructorDeclaration) bd).filter(cd -> cd.getParameters().isEmpty()).findFirst(); + } + + /** + * Adds a constructor to this + * + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the created constructor + */ + default ConstructorDeclaration addConstructor(Modifier... modifiers) { + ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration(); + constructorDeclaration.setModifiers(Arrays.stream(modifiers).collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + constructorDeclaration.setName(getName()); + getMembers().add(constructorDeclaration); + return constructorDeclaration; + } + + /** + * Find all constructors for this class. + * + * @return the constructors found. This list is immutable. + */ + default List getConstructors() { + return unmodifiableList(getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).collect(toList())); + } + + /** + * Try to find a {@link ConstructorDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return the constructor found (multiple in case of overloading) + */ + default Optional getConstructorByParameterTypes(String... paramTypes) { + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); + } + + /** + * Try to find a {@link ConstructorDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return the constructors found (multiple in case of overloading) + */ + default Optional getConstructorByParameterTypes(Class... paramTypes) { + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/body/WithDeclaration.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java similarity index 63% rename from JavaParser/src/com/github/javaparser/ast/body/WithDeclaration.java rename to JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java index 11db41d..d490ed1 100644 --- a/JavaParser/src/com/github/javaparser/ast/body/WithDeclaration.java +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java @@ -1,56 +1,61 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.body; - -/** - * Element with a declaration representable as a String. - * - * @author Federico Tomassetti - * @since July 2014 - */ -public interface WithDeclaration { - - /** - * As {@link WithDeclaration#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 WithDeclaration#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); -} +/* + * 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.nodeTypes; + +/** + * Node with a declaration representable as a String. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public interface NodeWithDeclaration { + + /** + * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including + * the modifiers, the throws clause and the parameters with both type and name. + * + * @return String representation of declaration + */ + String getDeclarationAsString(); + + /** + * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including + * the parameters with both type and name. + * + * @param includingModifiers flag to include the modifiers (if present) in the string produced + * @param includingThrows flag to include the throws clause (if present) in the string produced + * @return String representation of declaration based on parameter flags + */ + String getDeclarationAsString(boolean includingModifiers, boolean includingThrows); + + /** + * A simple representation of the element declaration. + * It should fit one string. + * + * @param includingModifiers flag to include the modifiers (if present) in the string produced + * @param includingThrows flag to include the throws clause (if present) in the string produced + * @param includingParameterName flag to include the parameter name (while the parameter type is always included) in + * the string produced + * @return String representation of declaration based on parameter flags + */ + String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName); +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java new file mode 100644 index 0000000..3a1dd71 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java @@ -0,0 +1,40 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; + +import static com.github.javaparser.JavaParser.parseExpression; + +/** + * A node that has an expression in it. + */ +public interface NodeWithExpression { + Expression getExpression(); + + N setExpression(Expression expression); + + default N setExpression(String expression) { + return setExpression(parseExpression(expression)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java new file mode 100644 index 0000000..af4adf8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.ClassOrInterfaceType; + +import static com.github.javaparser.JavaParser.parseClassOrInterfaceType; + +/** + * A node that extends other types. + */ +public interface NodeWithExtends { + NodeList getExtendedTypes(); + + void tryAddImportToParentCompilationUnit(Class clazz); + + default ClassOrInterfaceType getExtendedTypes(int i) { + return getExtendedTypes().get(i); + } + + N setExtendedTypes(NodeList extendsList); + + @SuppressWarnings("unchecked") + default N setExtendedType(int i, ClassOrInterfaceType extend) { + getExtendedTypes().set(i, extend); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addExtendedType(ClassOrInterfaceType extend) { + getExtendedTypes().add(extend); + return (N) this; + } + + /** + * @deprecated use addExtendedType + */ + default N addExtends(Class clazz) { + return addExtendedType(clazz); + } + + /** + * @deprecated use addExtendedType + */ + default N addExtends(String name) { + return addExtendedType(name); + } + + /** + * Add an "extends" to this and automatically add the import + * + * @param clazz the class to extand from + * @return this + */ + default N addExtendedType(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addExtendedType(clazz.getSimpleName()); + } + + /** + * Add an "extends" to this + * + * @param name the name of the type to extends from + * @return this + */ + @SuppressWarnings("unchecked") + default N addExtendedType(String name) { + getExtendedTypes().add(parseClassOrInterfaceType(name)); + return (N) this; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java new file mode 100644 index 0000000..22a583a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java @@ -0,0 +1,41 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; + +import static com.github.javaparser.utils.Utils.assertNonEmpty; + +public interface NodeWithIdentifier { + String getIdentifier(); + + N setIdentifier(String identifier); + + default String getId() { + return getIdentifier(); + } + + default N setId(String identifier) { + assertNonEmpty(identifier); + return setIdentifier(identifier); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java new file mode 100644 index 0000000..84cee4d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.ClassOrInterfaceType; + +import static com.github.javaparser.JavaParser.parseClassOrInterfaceType; + +/** + * A node that implements other types. + */ +public interface NodeWithImplements { + NodeList getImplementedTypes(); + + default ClassOrInterfaceType getImplementedTypes(int i) { + return getImplementedTypes().get(i); + } + + N setImplementedTypes(NodeList implementsList); + + void tryAddImportToParentCompilationUnit(Class clazz); + + @SuppressWarnings("unchecked") + default N setImplementedType(int i, ClassOrInterfaceType implement) { + getImplementedTypes().set(i, implement); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addImplementedType(ClassOrInterfaceType implement) { + getImplementedTypes().add(implement); + return (N) this; + } + + /** @deprecated use addImplementedType instead */ + default N addImplements(String name) { + return addImplementedType(name); + } + + /** @deprecated use addImplementedType instead */ + default N addImplements(Class clazz) { + return addImplementedType(clazz); + } + + /** + * Add an implements to this + * + * @param name the name of the type to extends from + * @return this + */ + @SuppressWarnings("unchecked") + default N addImplementedType(String name) { + getImplementedTypes().add(parseClassOrInterfaceType(name)); + return (N) this; + } + + /** + * Add an implements to this and automatically add the import + * + * @param clazz the type to implements from + * @return this + */ + default N addImplementedType(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addImplementedType(clazz.getSimpleName()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java new file mode 100644 index 0000000..592947e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java @@ -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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.javadoc.Javadoc; + +import java.util.Optional; + +/** + * A node that can be documented with a Javadoc comment. + */ +public interface NodeWithJavadoc { + Optional getComment(); + + Node setComment(Comment comment); + + /** + * Gets the JavadocComment for this node. You can set the JavadocComment by calling setJavadocComment passing a + * JavadocComment. + * + * @return The JavadocComment for this node wrapped in an optional as it may be absent. + */ + default Optional getJavadocComment() { + return getComment() + .filter(comment -> comment instanceof JavadocComment) + .map(comment -> (JavadocComment) comment); + } + + /** + * Gets the Javadoc for this node. You can set the Javadoc by calling setJavadocComment passing a Javadoc. + * + * @return The Javadoc for this node wrapped in an optional as it may be absent. + */ + default Optional getJavadoc() { + return getJavadocComment().map(JavadocComment::parse); + } + + /** + * Use this to store additional information to this node. + * + * @param comment to be set + */ + @SuppressWarnings("unchecked") + default N setJavadocComment(String comment) { + return setJavadocComment(new JavadocComment(" " + comment)); + } + + default N setJavadocComment(JavadocComment comment) { + setComment(comment); + return (N) this; + } + + default N setJavadocComment(String indentation, Javadoc javadoc) { + return setJavadocComment(javadoc.toComment(indentation)); + } + + default N setJavadocComment(Javadoc javadoc) { + return setJavadocComment(javadoc.toComment()); + } + + default boolean removeJavaDocComment() { + return hasJavaDocComment() && getComment().get().remove(); + } + + default boolean hasJavaDocComment() { + return getComment().isPresent() && getComment().get() instanceof JavadocComment; + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java new file mode 100644 index 0000000..6d5f0c3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java @@ -0,0 +1,328 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.VoidType; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +import static com.github.javaparser.JavaParser.parseType; +import static java.util.Collections.unmodifiableList; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toList; + +/** + * 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 { + /** + * @return all members inside the braces of this node, + * like fields, methods, nested types, etc. + */ + NodeList> getMembers(); + + void tryAddImportToParentCompilationUnit(Class clazz); + + default BodyDeclaration getMember(int i) { + return getMembers().get(i); + } + + @SuppressWarnings("unchecked") + default N setMember(int i, BodyDeclaration member) { + getMembers().set(i, member); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addMember(BodyDeclaration member) { + getMembers().add(member); + return (N) this; + } + + N setMembers(NodeList> 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) { + 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(parseType(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(); + VariableDeclarator variable = new VariableDeclarator(type, name); + fieldDeclaration.getVariables().add(variable); + fieldDeclaration.setModifiers(Arrays.stream(modifiers) + .collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + getMembers().add(fieldDeclaration); + return fieldDeclaration; + } + + /** + * Add a field to this. + * + * @param type the type of the field + * @param name the name of the field + * @param initializer the initializer of the field + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addFieldWithInitializer(Type type, String name, Expression initializer, Modifier... modifiers) { + FieldDeclaration declaration = addField(type, name, modifiers); + declaration.getVariables().iterator().next().setInitializer(initializer); + return declaration; + } + + /** + * Add a private field to this. + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPrivateField(Class typeClass, String name) { + return addField(typeClass, name, Modifier.PRIVATE); + } + + /** + * Add a private field to this and automatically add the import of the type if + * needed. + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPrivateField(String type, String name) { + return addField(type, name, Modifier.PRIVATE); + } + + /** + * Add a public field to this. + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPublicField(Class typeClass, String name) { + return addField(typeClass, name, Modifier.PUBLIC); + } + + /** + * Add a public field to this and automatically add the import of the type if + * needed. + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addPublicField(String type, String name) { + return addField(type, name, Modifier.PUBLIC); + } + + /** + * Add a protected field to this. + * + * @param typeClass the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addProtectedField(Class typeClass, String name) { + return addField(typeClass, name, Modifier.PROTECTED); + } + + /** + * Add a protected field to this and automatically add the import of the type + * if needed. + * + * @param type the type of the field + * @param name the name of the field + * @return the {@link FieldDeclaration} created + */ + default FieldDeclaration addProtectedField(String type, String name) { + return addField(type, name, Modifier.PROTECTED); + } + + /** + * Adds a methods with void return by default to this. + * + * @param methodName the method name + * @param modifiers the modifiers like {@link Modifier#PUBLIC} + * @return the {@link MethodDeclaration} created + */ + default MethodDeclaration addMethod(String methodName, Modifier... modifiers) { + MethodDeclaration methodDeclaration = new MethodDeclaration(); + methodDeclaration.setName(methodName); + methodDeclaration.setType(new VoidType()); + methodDeclaration.setModifiers(Arrays.stream(modifiers) + .collect(toCollection(() -> EnumSet.noneOf(Modifier.class)))); + getMembers().add(methodDeclaration); + return methodDeclaration; + } + + /** + * Add an initializer block ({@link InitializerDeclaration}) to this. + */ + default BlockStmt addInitializer() { + BlockStmt block = new BlockStmt(); + InitializerDeclaration initializerDeclaration = new InitializerDeclaration(false, block); + getMembers().add(initializerDeclaration); + return block; + } + + /** + * Add a static initializer block ({@link InitializerDeclaration}) to this. + */ + default BlockStmt addStaticInitializer() { + BlockStmt block = new BlockStmt(); + InitializerDeclaration initializerDeclaration = new InitializerDeclaration(true, block); + getMembers().add(initializerDeclaration); + 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 overloading) + */ + default List getMethodsByName(String name) { + return unmodifiableList(getMethods().stream() + .filter(m -> m.getNameAsString().equals(name)) + .collect(toList())); + } + + /** + * Find all methods in the members of this node. + * + * @return the methods found. This list is immutable. + */ + default List getMethods() { + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof MethodDeclaration) + .map(m -> (MethodDeclaration) m) + .collect(toList())); + } + + /** + * Try to find a {@link MethodDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return the methods found (multiple in case of overloading) + */ + default List getMethodsByParameterTypes(String... paramTypes) { + return unmodifiableList(getMethods().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .collect(toList())); + } + + /** + * Try to find {@link MethodDeclaration}s by their name and parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return the methods found (multiple in case of overloading) + */ + default List getMethodsBySignature(String name, String... paramTypes) { + return unmodifiableList(getMethodsByName(name).stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .collect(toList())); + } + + /** + * Try to find a {@link MethodDeclaration} by its parameters types + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return the methods found (multiple in case of overloading) + */ + default List getMethodsByParameterTypes(Class... paramTypes) { + return unmodifiableList(getMethods().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .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 Optional getFieldByName(String name) { + return getMembers().stream() + .filter(m -> m instanceof FieldDeclaration) + .map(f -> (FieldDeclaration) f) + .filter(f -> f.getVariables().stream() + .anyMatch(var -> var.getNameAsString().equals(name))) + .findFirst(); + } + + /** + * Find all fields in the members of this node. + * + * @return the fields found. This list is immutable. + */ + default List getFields() { + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof FieldDeclaration) + .map(m -> (FieldDeclaration) m) + .collect(toList())); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java new file mode 100644 index 0000000..3a499bf --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java @@ -0,0 +1,73 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.stream.Collectors; + +/** + * A Node with Modifiers. + * Note that not all modifiers may be valid for this node. + */ +public interface NodeWithModifiers { + /** + * Return the modifiers of this variable declaration. + * Warning: modifying the returned set will not trigger observers, + * you have to use setModifiers for that. + * + * @return modifiers + * @see Modifier + */ + EnumSet getModifiers(); + + N setModifiers(EnumSet modifiers); + + @SuppressWarnings("unchecked") + default N addModifier(Modifier... modifiers) { + EnumSet newModifiers = getModifiers().clone(); + newModifiers.addAll(Arrays.stream(modifiers) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class)))); + setModifiers(newModifiers); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N removeModifier(Modifier... m) { + EnumSet newModifiers = getModifiers().clone(); + newModifiers.removeAll(Arrays.stream(m) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class)))); + setModifiers(newModifiers); + return (N) this; + } + default N setModifier(Modifier m, boolean set) { + if (set) { + return addModifier(m); + } else { + return removeModifier(m); + } + } + +} \ No newline at end of file diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithName.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithName.java new file mode 100644 index 0000000..bc25cad --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithName.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Name; + +import static com.github.javaparser.JavaParser.parseName; +import static com.github.javaparser.utils.Utils.assertNonEmpty; + +/** + * A node with a (qualified) 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 { + Name getName(); + + N setName(Name name); + + @SuppressWarnings("unchecked") + default N setName(String name) { + assertNonEmpty(name); + return setName(parseName(name)); + } + + default String getNameAsString() { + return getName().asString(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java new file mode 100644 index 0000000..0bf89a4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.stmt.BlockStmt; + +import java.util.Optional; + +/** + * A node with a body that is a BlockStmt, which is optional. + */ +public interface NodeWithOptionalBlockStmt { + Optional getBody(); + + N setBody(BlockStmt block); + + N removeBody(); + + default BlockStmt createBody() { + BlockStmt block = new BlockStmt(); + setBody(block); + return block; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java new file mode 100644 index 0000000..93ab11a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java @@ -0,0 +1,28 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.SimpleName; + +import java.util.Optional; + +import static com.github.javaparser.utils.Utils.assertNonEmpty; + +/** + * A node that has an optional label. + */ +public interface NodeWithOptionalLabel { + Optional getLabel(); + + T setLabel(SimpleName label); + + T removeLabel(); + + default T setLabel(String label) { + assertNonEmpty(label); + return setLabel(new SimpleName(label)); + } + + default Optional getLabelAsString() { + return getLabel().flatMap(l -> Optional.of(l.getIdentifier())); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java new file mode 100644 index 0000000..46bd59c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.expr.Expression; + +import java.util.Optional; + +/** + * Represents a node which has an optional scope expression eg. method calls (object.method()). + */ +public interface NodeWithOptionalScope extends NodeWithTraversableScope { + + Optional getScope(); + + N setScope(Expression scope); + + N removeScope(); + + default Optional traverseScope() { + return getScope(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java new file mode 100644 index 0000000..517d8f5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java @@ -0,0 +1,162 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.type.Type; + +import java.util.Optional; +import java.util.stream.Stream; + +import static com.github.javaparser.JavaParser.parseType; +import static java.util.stream.Collectors.toSet; + +public interface NodeWithParameters { + NodeList getParameters(); + + default Parameter getParameter(int i) { + return getParameters().get(i); + } + + void tryAddImportToParentCompilationUnit(Class clazz); + + @SuppressWarnings("unchecked") + default N setParameter(int i, Parameter parameter) { + getParameters().set(i, parameter); + return (N) this; + } + + N setParameters(NodeList parameters); + + default N addParameter(Type type, String name) { + return addParameter(new Parameter(type, name)); + } + + default N addParameter(Class paramClass, String name) { + tryAddImportToParentCompilationUnit(paramClass); + return addParameter(parseType(paramClass.getSimpleName()), name); + } + + /** + * Remember to import the class in the compilation unit yourself + * + * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import + * @param name the name of the parameter + */ + default N addParameter(String className, String name) { + return addParameter(parseType(className), name); + } + + @SuppressWarnings("unchecked") + default N addParameter(Parameter parameter) { + getParameters().add(parameter); + return (N) this; + } + + default Parameter addAndGetParameter(Type type, String name) { + return addAndGetParameter(new Parameter(type, name)); + } + + default Parameter addAndGetParameter(Class paramClass, String name) { + tryAddImportToParentCompilationUnit(paramClass); + return addAndGetParameter(parseType(paramClass.getSimpleName()), name); + } + + /** + * Remember to import the class in the compilation unit yourself + * + * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import + * @param name the name of the parameter + * @return the {@link Parameter} created + */ + default Parameter addAndGetParameter(String className, String name) { + return addAndGetParameter(parseType(className), name); + } + + default Parameter addAndGetParameter(Parameter parameter) { + getParameters().add(parameter); + 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 Optional getParameterByName(String name) { + return getParameters().stream() + .filter(p -> p.getNameAsString().equals(name)).findFirst(); + } + + /** + * 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 Optional getParameterByType(String type) { + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type)).findFirst(); + } + + /** + * Try to find a {@link Parameter} by its type + * + * @param type the type of the param take care about generics, it wont work + * @return null if not found, the param found otherwise + */ + default Optional getParameterByType(Class type) { + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); + } + + /** + * Check if the parameters have certain types. + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return true if all parameters match + */ + default boolean hasParametersOfType(String... paramTypes) { + return getParameters().stream() + .map(p -> p.getType().toString()) + .collect(toSet()) + .equals(Stream.of(paramTypes).collect(toSet())); + } + + /** + * Check if the parameters have certain types. Note that this is a match in SimpleName, so "java.awt.List" and + * "java.util.List" are identical to this algorithm. + * + * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match
void + * foo(Map<Integer,String> myMap,int number) + * @return true if all parameters match + */ + default boolean hasParametersOfType(Class... paramTypes) { + return getParameters().stream().map(p -> p.getType().toString()) + .collect(toSet()) + .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toSet())); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithRange.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithRange.java new file mode 100644 index 0000000..d1e2fb7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithRange.java @@ -0,0 +1,54 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.Position; +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; + +import java.util.Optional; + +/** + * A node that has a Range, which is every Node. + * + */ +public interface NodeWithRange { + Optional getRange(); + + N setRange(Range range); + + /** + * The begin position of this node in the source file. + */ + default Optional getBegin() { + return getRange().map(r -> r.begin); + } + + /** + * The end position of this node in the source file. + */ + default Optional getEnd() { + return getRange().map(r -> r.end); + } + + default boolean containsWithin(Node other) { + if (getRange().isPresent() && other.getRange().isPresent()) { + return getRange().get().contains(other.getRange().get()); + } + return false; + } + + /** + * @deprecated use isAfter() on range + */ + @Deprecated + default boolean isPositionedAfter(Position position) { + return getRange().map(r -> r.isAfter(position)).orElse(false); + } + + /** + * @deprecated use isBefore() on range + */ + @Deprecated + default boolean isPositionedBefore(Position position) { + return getRange().map(r -> r.isBefore(position)).orElse(false); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithScope.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithScope.java new file mode 100644 index 0000000..15ea3ac --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithScope.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.expr.Expression; + +import java.util.Optional; + +/** + * Represents a node which has a required scope expression eg. field access (object.method). + */ +public interface NodeWithScope extends NodeWithTraversableScope { + + Expression getScope(); + + N setScope(Expression scope); + + default Optional traverseScope() { + return Optional.of(getScope()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java new file mode 100644 index 0000000..ebd3957 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.SimpleName; + +import static com.github.javaparser.utils.Utils.assertNonEmpty; + +/** + * A node with a name. + *

+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. + */ +public interface NodeWithSimpleName { + SimpleName getName(); + + N setName(SimpleName name); + + @SuppressWarnings("unchecked") + default N setName(String name) { + assertNonEmpty(name); + return setName(new SimpleName(name)); + } + + default String getNameAsString() { + return getName().getIdentifier(); + } + + default NameExpr getNameAsExpression() { + return new NameExpr(getName()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java new file mode 100644 index 0000000..4d2c90c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -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.nodeTypes; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.Statement; + +import static com.github.javaparser.JavaParser.*; + +/** + * A node that contains a list of statements. + */ +public interface NodeWithStatements { + NodeList getStatements(); + + default Statement getStatement(int i) { + return getStatements().get(i); + } + + @SuppressWarnings("unchecked") + default N setStatement(int i, Statement statement) { + getStatements().set(i, statement); + return (N) this; + } + + N setStatements(final NodeList statements); + + @SuppressWarnings("unchecked") + default N addStatement(Statement statement) { + getStatements().add(statement); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addStatement(int index, final Statement statement) { + getStatements().add(index, statement); + return (N) this; + } + + default N addStatement(Expression expr) { + return addStatement(new ExpressionStmt(expr)); + } + + /** + * It will use {@link JavaParser#parseStatement(String)} inside, so it should end with a semi column + */ + default N addStatement(String statement) { + return addStatement(parseStatement(statement)); + } + + default N addStatement(int index, final Expression expr) { + Statement stmt = new ExpressionStmt(expr); + return addStatement(index, stmt); + } + + default A addAndGetStatement(A statement) { + getStatements().add(statement); + return statement; + } + + default Statement addAndGetStatement(int index, final Statement statement) { + getStatements().add(index, statement); + return statement; + } + + default ExpressionStmt addAndGetStatement(Expression expr) { + ExpressionStmt statement = new ExpressionStmt(expr); + return addAndGetStatement(statement); + } + + default ExpressionStmt addAndGetStatement(String statement) { + return addAndGetStatement(new NameExpr(statement)); + } + + default boolean isEmpty() { + return getStatements().isEmpty(); + } + + @SuppressWarnings("unchecked") + default N copyStatements(NodeList nodeList) { + for (Statement n : nodeList) { + addStatement(n.clone()); + } + return (N) this; + } + + default N copyStatements(NodeWithStatements other) { + return copyStatements(other.getStatements()); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java new file mode 100644 index 0000000..e1b9007 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.ReferenceType; + +import static com.github.javaparser.JavaParser.parseClassOrInterfaceType; + +/** + * A node that declares the types of exception it throws. + */ +public interface NodeWithThrownExceptions { + N setThrownExceptions(NodeList thrownExceptions); + + NodeList getThrownExceptions(); + + void tryAddImportToParentCompilationUnit(Class clazz); + + default ReferenceType getThrownException(int i) { + return getThrownExceptions().get(i); + } + + /** + * Adds this type to the throws clause + * + * @param throwType the exception type + * @return this + */ + @SuppressWarnings("unchecked") + default N addThrownException(ReferenceType throwType) { + getThrownExceptions().add(throwType); + return (N) this; + } + + /** + * Adds this class to the throws clause + * + * @param clazz the exception class + * @return this + */ + default N addThrownException(Class clazz) { + tryAddImportToParentCompilationUnit(clazz); + return addThrownException(parseClassOrInterfaceType(clazz.getSimpleName())); + } + + /** + * Check whether this elements throws this exception class. + * Note that this is simply a text compare of the simple name of the class, + * no actual type resolution takes place. + * + * @param clazz the class of the exception + * @return true if found in throws clause, false if not + */ + default boolean isThrown(Class clazz) { + return isThrown(clazz.getSimpleName()); + } + + /** + * Check whether this elements throws this exception class + * Note that this is simply a text compare, + * no actual type resolution takes place. + * + * @param throwableName the class of the exception + * @return true if found in throws clause, false if not + */ + default boolean isThrown(String throwableName) { + return getThrownExceptions().stream().anyMatch(t -> t.toString().equals(throwableName)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java new file mode 100644 index 0000000..b043f64 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java @@ -0,0 +1,15 @@ +package com.github.javaparser.ast.nodeTypes; + +import com.github.javaparser.TokenRange; + +import java.util.Optional; + +/** + * A node that has a Range, which is every Node. + * + */ +public interface NodeWithTokenRange { + Optional getTokenRange(); + + N setTokenRange(TokenRange range); +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java new file mode 100644 index 0000000..a1b9b3b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.expr.Expression; + +import java.util.Optional; + +/** + * Represents a node which has a scope expression that can be traversed/walked. + * This unifies scope access for NodeWithScope and NodeWithOptionalScope. + */ +public interface NodeWithTraversableScope { + + /** + * @return the scope of this node, regardless of optionality. + * An optional scope is returned directly. + * A required scope is returned in an "Optional", but will never be empty. + */ + Optional traverseScope(); +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithType.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithType.java new file mode 100644 index 0000000..06e66fb --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithType.java @@ -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.nodeTypes; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.Type; + +import static com.github.javaparser.JavaParser.parseType; +import static com.github.javaparser.utils.Utils.assertNonEmpty; + +/** + * A node with 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 { + /** + * Gets the type + * + * @return the type + */ + T getType(); + + /** + * Sets the type + * + * @param type the type + * @return this + */ + N setType(T type); + + void tryAddImportToParentCompilationUnit(Class clazz); + + /** + * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed + * + * @param typeClass the type + * @return this + */ + @SuppressWarnings("unchecked") + default N setType(Class typeClass) { + tryAddImportToParentCompilationUnit(typeClass); + return setType((T) parseType(typeClass.getSimpleName())); + } + + @SuppressWarnings("unchecked") + default N setType(final String typeString) { + assertNonEmpty(typeString); + return setType((T) parseType(typeString)); + } + + default String getTypeAsString() { + return getType().asString(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java new file mode 100644 index 0000000..0c72b22 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.metamodel.DerivedProperty; + +import java.util.Optional; + +import static com.github.javaparser.ast.NodeList.nodeList; + +/** + * A node that can have type arguments. + *

+ *

+ *     new X();        --> typeArguments == Optional is empty
+ *     new X<>();      --> typeArguments = [], diamondOperator = true
+ *     new X<C,D>();   --> typeArguments = [C,D], diamondOperator = false
+ * 
+ */ +public interface NodeWithTypeArguments { + /** + * @return the types that can be found in the type arguments: <String, Integer>. + */ + Optional> getTypeArguments(); + + /** + * Allows you to set the generic arguments + * + * @param typeArguments The list of types of the generics, can be null + */ + N setTypeArguments(NodeList typeArguments); + + /** + * @return whether the type arguments look like <>. + */ + @DerivedProperty + default boolean isUsingDiamondOperator() { + return getTypeArguments().isPresent() && getTypeArguments().get().isEmpty(); + } + + /** + * Sets the type arguments to <>. + */ + @SuppressWarnings("unchecked") + default N setDiamondOperator() { + return setTypeArguments(new NodeList<>()); + } + + /** + * Removes all type arguments, including the surrounding <>. + */ + @SuppressWarnings("unchecked") + default N removeTypeArguments() { + return setTypeArguments((NodeList) null); + } + + @SuppressWarnings("unchecked") + default N setTypeArguments(Type... typeArguments) { + return setTypeArguments(nodeList(typeArguments)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java new file mode 100644 index 0000000..8817a76 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java @@ -0,0 +1,60 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.TypeParameter; + +/** + * A node that can have type parameters. + *
+ *     class X {}        --> typeParameters == []
+ *     class X<> {}      --> does not occur.
+ *     class X<C,D> {}   --> typeParameters = [C,D]
+ * 
+ */ +public interface NodeWithTypeParameters { + NodeList getTypeParameters(); + + default TypeParameter getTypeParameter(int i) { + return getTypeParameters().get(i); + } + + @SuppressWarnings("unchecked") + default N setTypeParameter(int i, TypeParameter typeParameter) { + getTypeParameters().set(i, typeParameter); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addTypeParameter(TypeParameter typeParameter) { + getTypeParameters().add(typeParameter); + return (N) this; + } + + N setTypeParameters(NodeList typeParameters); + + default boolean isGeneric() { + return getTypeParameters().size() > 0; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java new file mode 100644 index 0000000..5daf38a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java @@ -0,0 +1,161 @@ +/* + * 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.nodeTypes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.metamodel.DerivedProperty; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * A node which has a list of variables. + */ +public interface NodeWithVariables { + NodeList getVariables(); + + N setVariables(NodeList variables); + + default VariableDeclarator getVariable(int i) { + return getVariables().get(i); + } + + @SuppressWarnings("unchecked") + default N setVariable(int i, VariableDeclarator variableDeclarator) { + getVariables().set(i, variableDeclarator); + return (N) this; + } + + @SuppressWarnings("unchecked") + default N addVariable(VariableDeclarator variableDeclarator) { + getVariables().add(variableDeclarator); + return (N) this; + } + + /** + * Returns the type that is shared between all variables. + * This is a shortcut for when you are certain that all variables share one type. + * What makes this difficult is arrays, and being able to set the type. + *
For int a; this is int. + *
For int a,b,c,d; this is also int. + *
For int a,b[],c; this is an assertion error since b is an int[], not an int. + *
For int a,b;, then doing setType(String) on b, this is an assertion error. It is also a situation that you don't really want. + */ + default Type getCommonType() { + NodeList variables = getVariables(); + if (variables.isEmpty()) { + throw new AssertionError("There is no common type since there are no variables."); + } + Type type = variables.get(0).getType(); + for (int i = 1; i < variables.size(); i++) { + if (!variables.get(i).getType().equals(type)) { + throw new AssertionError("The variables do not have a common type."); + } + } + return type; + } + + /** + * Returns the element type. + *
For int a; this is int. + *
For int a,b,c,d; this is also int. + *
For int a,b[],c; this is also int. Note: no mention of b being an array. + *
For int a,b;, then doing setType(String) on b, then calling getElementType(). This is an assertion error. It is also a situation that you don't really want. + */ + default Type getElementType() { + NodeList variables = getVariables(); + if (variables.isEmpty()) { + throw new AssertionError("There is no element type since there are no variables."); + } + Type type = variables.get(0).getType().getElementType(); + for (int i = 1; i < variables.size(); i++) { + if (!variables.get(i).getType().getElementType().equals(type)) { + throw new AssertionError("The variables do not have a common type."); + } + } + return type; + } + + /** + * Returns the type that maximum shared type between all variables. + * The minimum common type does never include annotations on the array level. + *

+ *
For int a; this is int. + *
For int a,b,c,d; this is also int. + *
For int a,b[],c; this is also int. + *
For int[] a[][],b[],c[][]; this is int[][]. + */ + @DerivedProperty + default Optional getMaximumCommonType() { + return calculateMaximumCommonType(getVariables().stream().map(v -> v.getType()).collect(Collectors.toList())); + } + + static Optional calculateMaximumCommonType(List types) { + // we use a local class because we cannot use an helper static method in an interface + class Helper { + // Conceptually: given a type we start from the Element Type and get as many array levels as indicated + // From the implementation point of view we start from the actual type and we remove how many array + // levels as needed to get the target level of arrays + // It returns null if the type has less array levels then the desired target + private Optional toArrayLevel(Type type, int level) { + if (level > type.getArrayLevel()) { + return Optional.empty(); + } + for (int i = type.getArrayLevel(); i > level; i--) { + if (!(type instanceof ArrayType)) { + return Optional.empty(); + } + type = ((ArrayType) type).getComponentType(); + } + return Optional.of(type); + } + } + + Helper helper = new Helper(); + int level = 0; + boolean keepGoing = true; + // In practice we want to check for how many levels of arrays all the variables have the same type, + // including also the annotations + while (keepGoing) { + final int currentLevel = level; + // Now, given that equality on nodes consider the position the simplest way is to compare + // the pretty-printed string got for a node. We just check all them are the same and if they + // are we just just is not null + Object[] values = types.stream().map(v -> { + Optional t = helper.toArrayLevel(v, currentLevel); + return t.map(Node::toString).orElse(null); + }).distinct().toArray(); + if (values.length == 1 && values[0] != null) { + level++; + } else { + keepGoing = false; + } + } + return helper.toArrayLevel(types.get(0), --level); + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java new file mode 100644 index 0000000..c81c4c6 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.ABSTRACT; + +/** + * A node that can be abstract. + */ +public interface NodeWithAbstractModifier extends NodeWithModifiers { + default boolean isAbstract() { + return getModifiers().contains(ABSTRACT); + } + + @SuppressWarnings("unchecked") + default N setAbstract(boolean set) { + return setModifier(ABSTRACT, set); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java new file mode 100644 index 0000000..9569624 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java @@ -0,0 +1,9 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; + +/** + * A node that can be public, protected, and/or private. + */ +public interface NodeWithAccessModifiers extends NodeWithPublicModifier, NodeWithPrivateModifier, NodeWithProtectedModifier { +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java new file mode 100644 index 0000000..91aae40 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.FINAL; + +/** + * A node that can be final. + */ +public interface NodeWithFinalModifier extends NodeWithModifiers { + default boolean isFinal() { + return getModifiers().contains(FINAL); + } + + @SuppressWarnings("unchecked") + default N setFinal(boolean set) { + return setModifier(FINAL, set); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java new file mode 100644 index 0000000..4aa022c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.*; + +/** + * A node that can be private. + */ +public interface NodeWithPrivateModifier extends NodeWithModifiers { + default boolean isPrivate() { + return getModifiers().contains(PRIVATE); + } + + @SuppressWarnings("unchecked") + default N setPrivate(boolean set) { + return setModifier(PRIVATE, set); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java new file mode 100644 index 0000000..d2200b7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.*; + +/** + * A node that can be protected. + */ +public interface NodeWithProtectedModifier extends NodeWithModifiers { + default boolean isProtected() { + return getModifiers().contains(PROTECTED); + } + + @SuppressWarnings("unchecked") + default N setProtected(boolean set) { + return setModifier(PROTECTED, set); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java new file mode 100644 index 0000000..64b4067 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java @@ -0,0 +1,21 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.*; + +/** + * A node that can be public. + */ +public interface NodeWithPublicModifier extends NodeWithModifiers { + default boolean isPublic() { + return getModifiers().contains(PUBLIC); + } + + @SuppressWarnings("unchecked") + default N setPublic(boolean set) { + return setModifier(PUBLIC, set); + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java new file mode 100644 index 0000000..5ac63ea --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java @@ -0,0 +1,22 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.STATIC; + +/** + * A node that can be static. + */ +public interface NodeWithStaticModifier extends NodeWithModifiers { + + default boolean isStatic() { + return getModifiers().contains(STATIC); + } + + @SuppressWarnings("unchecked") + default N setStatic(boolean set) { + return setModifier(STATIC, set); + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java new file mode 100644 index 0000000..1d8fb41 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.nodeTypes.modifiers; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; + +import static com.github.javaparser.ast.Modifier.STRICTFP; + +/** + * A node that can be strictfp. + */ +public interface NodeWithStrictfpModifier extends NodeWithModifiers { + default boolean isStrictfp() { + return getModifiers().contains(STRICTFP); + } + + @SuppressWarnings("unchecked") + default N setStrictfp(boolean set) { + return setModifier(STRICTFP, set); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/observer/AstObserver.java b/JavaParser/src/com/github/javaparser/ast/observer/AstObserver.java new file mode 100644 index 0000000..6c41f4b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/observer/AstObserver.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.observer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; + +/** + * An Observer for an AST element (either a Node or a NodeList). + */ +public interface AstObserver { + + /** + * Type of change occurring on a List + */ + enum ListChangeType { + ADDITION, + REMOVAL + } + + /** + * The value of a property is changed + * + * @param observedNode owner of the property + * @param property property changed + * @param oldValue value of the property before the change + * @param newValue value of the property after the change + */ + void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue); + + /** + * The parent of a node is changed + * + * @param observedNode node of which the parent is changed + * @param previousParent previous parent + * @param newParent new parent + */ + void parentChange(Node observedNode, Node previousParent, Node newParent); + + /** + * A list is changed + * + * @param observedNode list changed + * @param type type of change + * @param index position at which the changed occurred + * @param nodeAddedOrRemoved element added or removed + */ + void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved); + + void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode); +} diff --git a/JavaParser/src/com/github/javaparser/ast/observer/AstObserverAdapter.java b/JavaParser/src/com/github/javaparser/ast/observer/AstObserverAdapter.java new file mode 100644 index 0000000..82b9194 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/observer/AstObserverAdapter.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.observer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; + +public abstract class AstObserverAdapter implements AstObserver { + + @Override + public void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + // do nothing + } + + @Override + public void parentChange(Node observedNode, Node previousParent, Node newParent) { + // do nothing + } + + @Override + public void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) { + // do nothing + } + + @Override + public void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode) { + // do nothing + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/observer/Observable.java b/JavaParser/src/com/github/javaparser/ast/observer/Observable.java new file mode 100644 index 0000000..ce0f926 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/observer/Observable.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.observer; + +/** + * Observable element. + */ +public interface Observable { + + /** + * Register an observer. + */ + void register(AstObserver observer); + + /** + * Unregister an observer. If the given observer was not registered there are no effects. + */ + void unregister(AstObserver observer); + + /** + * Was this observer registered? + * Note that equals is used to determine if the given observer was registered. + */ + boolean isRegistered(AstObserver observer); +} diff --git a/JavaParser/src/com/github/javaparser/ast/observer/ObservableProperty.java b/JavaParser/src/com/github/javaparser/ast/observer/ObservableProperty.java new file mode 100644 index 0000000..d7f82f3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/observer/ObservableProperty.java @@ -0,0 +1,298 @@ +/* + * 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.observer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.utils.Utils; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.Optional; +import java.util.Arrays; +import javax.annotation.Generated; + +/** + * Properties considered by the AstObserver + */ +@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") +public enum ObservableProperty { + + ANNOTATIONS(Type.MULTIPLE_REFERENCE), + ANONYMOUS_CLASS_BODY(Type.MULTIPLE_REFERENCE), + ARGUMENTS(Type.MULTIPLE_REFERENCE), + ASTERISK(Type.SINGLE_ATTRIBUTE), + BODY(Type.SINGLE_REFERENCE), + CATCH_CLAUSES(Type.MULTIPLE_REFERENCE), + CHECK(Type.SINGLE_REFERENCE), + CLASS_BODY(Type.MULTIPLE_REFERENCE), + CLASS_DECLARATION(Type.SINGLE_REFERENCE), + CLASS_EXPR(Type.SINGLE_REFERENCE), + COMMENT(Type.SINGLE_REFERENCE), + COMPARE(Type.SINGLE_REFERENCE), + COMPONENT_TYPE(Type.SINGLE_REFERENCE), + CONDITION(Type.SINGLE_REFERENCE), + CONTENT(Type.SINGLE_ATTRIBUTE), + DEFAULT_VALUE(Type.SINGLE_REFERENCE), + DIMENSION(Type.SINGLE_REFERENCE), + ELEMENTS(Type.MULTIPLE_REFERENCE), + ELEMENT_TYPE(Type.SINGLE_REFERENCE), + ELSE_EXPR(Type.SINGLE_REFERENCE), + ELSE_STMT(Type.SINGLE_REFERENCE), + ENCLOSING_PARAMETERS(Type.SINGLE_ATTRIBUTE), + ENTRIES(Type.MULTIPLE_REFERENCE), + EXPRESSION(Type.SINGLE_REFERENCE), + EXTENDED_TYPE(Type.SINGLE_REFERENCE), + EXTENDED_TYPES(Type.MULTIPLE_REFERENCE), + FINALLY_BLOCK(Type.SINGLE_REFERENCE), + IDENTIFIER(Type.SINGLE_ATTRIBUTE), + IMPLEMENTED_TYPES(Type.MULTIPLE_REFERENCE), + IMPORTS(Type.MULTIPLE_REFERENCE), + INDEX(Type.SINGLE_REFERENCE), + INITIALIZATION(Type.MULTIPLE_REFERENCE), + INITIALIZER(Type.SINGLE_REFERENCE), + INNER(Type.SINGLE_REFERENCE), + INTERFACE(Type.SINGLE_ATTRIBUTE), + ITERABLE(Type.SINGLE_REFERENCE), + LABEL(Type.SINGLE_REFERENCE), + LEFT(Type.SINGLE_REFERENCE), + LEVELS(Type.MULTIPLE_REFERENCE), + MEMBERS(Type.MULTIPLE_REFERENCE), + MEMBER_VALUE(Type.SINGLE_REFERENCE), + MESSAGE(Type.SINGLE_REFERENCE), + MODIFIERS(Type.MULTIPLE_ATTRIBUTE), + MODULE(Type.SINGLE_REFERENCE), + MODULE_NAMES(Type.MULTIPLE_REFERENCE), + MODULE_STMTS(Type.MULTIPLE_REFERENCE), + NAME(Type.SINGLE_REFERENCE), + OPEN(Type.SINGLE_ATTRIBUTE), + OPERATOR(Type.SINGLE_ATTRIBUTE), + ORIGIN(Type.SINGLE_ATTRIBUTE), + PACKAGE_DECLARATION(Type.SINGLE_REFERENCE), + PAIRS(Type.MULTIPLE_REFERENCE), + PARAMETER(Type.SINGLE_REFERENCE), + PARAMETERS(Type.MULTIPLE_REFERENCE), + QUALIFIER(Type.SINGLE_REFERENCE), + RECEIVER_PARAMETER(Type.SINGLE_REFERENCE), + RESOURCES(Type.MULTIPLE_REFERENCE), + RIGHT(Type.SINGLE_REFERENCE), + SCOPE(Type.SINGLE_REFERENCE), + SELECTOR(Type.SINGLE_REFERENCE), + STATEMENT(Type.SINGLE_REFERENCE), + STATEMENTS(Type.MULTIPLE_REFERENCE), + STATIC(Type.SINGLE_ATTRIBUTE), + SUPER_TYPE(Type.SINGLE_REFERENCE), + TARGET(Type.SINGLE_REFERENCE), + THEN_EXPR(Type.SINGLE_REFERENCE), + THEN_STMT(Type.SINGLE_REFERENCE), + THIS(Type.SINGLE_ATTRIBUTE), + THROWN_EXCEPTIONS(Type.MULTIPLE_REFERENCE), + TRY_BLOCK(Type.SINGLE_REFERENCE), + TYPE(Type.SINGLE_REFERENCE), + TYPES(Type.MULTIPLE_REFERENCE), + TYPE_ARGUMENTS(Type.MULTIPLE_REFERENCE), + TYPE_BOUND(Type.MULTIPLE_REFERENCE), + TYPE_PARAMETERS(Type.MULTIPLE_REFERENCE), + UPDATE(Type.MULTIPLE_REFERENCE), + VALUE(Type.SINGLE_REFERENCE), + VALUES(Type.MULTIPLE_REFERENCE), + VARIABLE(Type.SINGLE_REFERENCE), + VARIABLES(Type.MULTIPLE_REFERENCE), + VAR_ARGS(Type.SINGLE_ATTRIBUTE), + VAR_ARGS_ANNOTATIONS(Type.MULTIPLE_REFERENCE), + WITH_TYPES(Type.MULTIPLE_REFERENCE), + CASCADING_IF_STMT(Type.SINGLE_ATTRIBUTE, true), + ELSE_BLOCK(Type.SINGLE_ATTRIBUTE, true), + ELSE_BRANCH(Type.SINGLE_ATTRIBUTE, true), + EXPRESSION_BODY(Type.SINGLE_REFERENCE, true), + MAXIMUM_COMMON_TYPE(Type.SINGLE_REFERENCE, true), + POSTFIX(Type.SINGLE_ATTRIBUTE, true), + PREFIX(Type.SINGLE_ATTRIBUTE, true), + THEN_BLOCK(Type.SINGLE_ATTRIBUTE, true), + USING_DIAMOND_OPERATOR(Type.SINGLE_ATTRIBUTE, true), + RANGE, + COMMENTED_NODE; + + enum Type { + + SINGLE_ATTRIBUTE(false, false), SINGLE_REFERENCE(false, true), MULTIPLE_ATTRIBUTE(true, false), MULTIPLE_REFERENCE(true, true); + + private boolean multiple; + + private boolean node; + + Type(boolean multiple, boolean node) { + this.multiple = multiple; + this.node = node; + } + } + + private Type type; + + private boolean derived; + + public static ObservableProperty fromCamelCaseName(String camelCaseName) { + Optional observableProperty = Arrays.stream(values()).filter(v -> v.camelCaseName().equals(camelCaseName)).findFirst(); + if (observableProperty.isPresent()) { + return observableProperty.get(); + } else { + throw new IllegalArgumentException("No property found with the given camel case name: " + camelCaseName); + } + } + + ObservableProperty(Type type) { + this.type = type; + this.derived = false; + } + + ObservableProperty(Type type, boolean derived) { + this.type = type; + this.derived = derived; + } + + ObservableProperty() { + this(Type.SINGLE_REFERENCE, false); + } + + public boolean isDerived() { + return derived; + } + + public boolean isAboutNodes() { + return type.node; + } + + public boolean isAboutValues() { + return !isAboutNodes(); + } + + public boolean isMultiple() { + return type.multiple; + } + + public boolean isSingle() { + return !isMultiple(); + } + + public String camelCaseName() { + return Utils.screamingToCamelCase(name()); + } + + public Node getValueAsSingleReference(Node node) { + Object rawValue = getRawValue(node); + try { + if (rawValue instanceof Node) { + return (Node) rawValue; + } else if (rawValue instanceof Optional) { + Optional opt = (Optional) rawValue; + if (opt.isPresent()) { + return opt.get(); + } else { + return null; + } + } else { + throw new RuntimeException(String.format("Property %s returned %s (%s)", this.name(), rawValue.toString(), rawValue.getClass().getCanonicalName())); + } + } catch (ClassCastException e) { + throw new RuntimeException(e); + } + } + + private boolean hasMethod(Node node, String name) { + try { + node.getClass().getMethod(name); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + + public NodeList getValueAsMultipleReference(Node node) { + Object rawValue = getRawValue(node); + try { + if (rawValue == null) { + return null; + } + if (rawValue instanceof NodeList) { + return (NodeList) rawValue; + } else { + Optional opt = (Optional) rawValue; + if (opt.isPresent()) { + return opt.get(); + } else { + return null; + } + } + } catch (ClassCastException e) { + throw new RuntimeException("Unable to get list value for " + this.name() + " from " + node + " (class: " + node.getClass().getSimpleName() + ")", e); + } + } + + public Collection getValueAsCollection(Node node) { + Object rawValue = getRawValue(node); + try { + return (Collection) rawValue; + } catch (ClassCastException e) { + throw new RuntimeException("Unable to get list value for " + this.name() + " from " + node + " (class: " + node.getClass().getSimpleName() + ")", e); + } + } + + public String getValueAsStringAttribute(Node node) { + return (String) getRawValue(node); + } + + public Boolean getValueAsBooleanAttribute(Node node) { + return (Boolean) getRawValue(node); + } + + public Object getRawValue(Node node) { + String getterName = "get" + Utils.capitalize(camelCaseName()); + if (!hasMethod(node, getterName)) { + getterName = "is" + Utils.capitalize(camelCaseName()); + if (!hasMethod(node, getterName)) { + getterName = "has" + Utils.capitalize(camelCaseName()); + } + } + try { + return node.getClass().getMethod(getterName).invoke(node); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException("Unable to get value for " + this.name() + " from " + node + " (" + node.getClass().getSimpleName() + ")", e); + } + } + + public boolean isNull(Node node) { + return null == getRawValue(node); + } + + public boolean isNullOrNotPresent(Node node) { + Object result = getRawValue(node); + if (result == null) { + return true; + } + if (result instanceof Optional) { + return !((Optional) result).isPresent(); + } + return false; + } + + public boolean isNullOrEmpty(Node node) { + return Utils.valueIsNullOrEmpty(getRawValue(node)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/observer/PropagatingAstObserver.java b/JavaParser/src/com/github/javaparser/ast/observer/PropagatingAstObserver.java new file mode 100644 index 0000000..1579474 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/observer/PropagatingAstObserver.java @@ -0,0 +1,118 @@ +/* + * 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.observer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; + +/** + * This AstObserver attach itself to all new nodes added to the nodes already observed. + */ +public abstract class PropagatingAstObserver implements AstObserver { + + /** + * Wrap a given observer to make it self-propagating. If the given observer is an instance of PropagatingAstObserver + * the observer is returned without changes. + */ + public static PropagatingAstObserver transformInPropagatingObserver(final AstObserver observer) { + if (observer instanceof PropagatingAstObserver) { + return (PropagatingAstObserver) observer; + } + return new PropagatingAstObserver() { + @Override + public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + observer.propertyChange(observedNode, property, oldValue, newValue); + } + + @Override + public void concreteListChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) { + observer.listChange(observedNode, type, index, nodeAddedOrRemoved); + } + + @Override + public void parentChange(Node observedNode, Node previousParent, Node newParent) { + observer.parentChange(observedNode, previousParent, newParent); + } + }; + } + + @Override + public final void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + considerRemoving(oldValue); + considerAdding(newValue); + concretePropertyChange(observedNode, property, oldValue, newValue); + } + + @Override + public final void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) { + if (type == ListChangeType.REMOVAL) { + considerRemoving(nodeAddedOrRemoved); + } else if (type == ListChangeType.ADDITION) { + considerAdding(nodeAddedOrRemoved); + } + concreteListChange(observedNode, type, index, nodeAddedOrRemoved); + } + + @Override + public void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode) { + if (oldNode == newNode) { + return; + } + considerRemoving(oldNode); + considerAdding(newNode); + concreteListReplacement(observedNode, index, oldNode, newNode); + } + + public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + // do nothing + } + + public void concreteListChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) { + // do nothing + } + + public void concreteListReplacement(NodeList observedNode, int index, Node oldValue, Node newValue) { + // do nothing + } + + @Override + public void parentChange(Node observedNode, Node previousParent, Node newParent) { + // do nothing + } + + private void considerRemoving(Object element) { + if (element instanceof Observable) { + if (((Observable) element).isRegistered(this)) { + ((Observable) element).unregister(this); + } + } + } + + private void considerAdding(Object element) { + if (element instanceof Node) { + ((Node) element).registerForSubtree(this); + } else if (element instanceof Observable) { + ((Observable) element).register(this); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/AssertStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/AssertStmt.java index 42774c0..a6eb59f 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/AssertStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/AssertStmt.java @@ -1,82 +1,202 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression check, final Expression msg) { - super(beginLine, beginColumn, endLine, endColumn); - - setCheck(check); - setMessage(msg); - - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public
void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.AssertStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * A usage of the keyword "assert" + *
In assert dead : "Wasn't expecting to be dead here"; the check is "dead" and the message is the string. + * @author Julio Vilmar Gesser + */ +public final class AssertStmt extends Statement { + + private Expression check; + + @OptionalProperty + private Expression message; + + public AssertStmt() { + this(null, new BooleanLiteralExpr(), null); + } + + public AssertStmt(final Expression check) { + this(null, check, null); + } + + @AllFieldsConstructor + public AssertStmt(final Expression check, final Expression message) { + this(null, check, message); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public AssertStmt(TokenRange tokenRange, Expression check, Expression message) { + super(tokenRange); + setCheck(check); + setMessage(message); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCheck() { + return check; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getMessage() { + return Optional.ofNullable(message); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AssertStmt setCheck(final Expression check) { + assertNotNull(check); + if (check == this.check) { + return (AssertStmt) this; + } + notifyPropertyChange(ObservableProperty.CHECK, this.check, check); + if (this.check != null) + this.check.setParentNode(null); + this.check = check; + setAsParentNodeOf(check); + return this; + } + + /** + * Sets the message + * + * @param message the message, can be null + * @return this, the AssertStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public AssertStmt setMessage(final Expression message) { + if (message == this.message) { + return (AssertStmt) this; + } + notifyPropertyChange(ObservableProperty.MESSAGE, this.message, message); + if (this.message != null) + this.message.setParentNode(null); + this.message = message; + setAsParentNodeOf(message); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (message != null) { + if (node == message) { + removeMessage(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public AssertStmt removeMessage() { + return setMessage((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public AssertStmt clone() { + return (AssertStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public AssertStmtMetaModel getMetaModel() { + return JavaParserMetaModel.assertStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == check) { + setCheck((Expression) replacementNode); + return true; + } + if (message != null) { + if (node == message) { + setMessage((Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAssertStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AssertStmt asAssertStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAssertStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAssertStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/BlockStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/BlockStmt.java index e356f33..3e25b96 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/BlockStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/BlockStmt.java @@ -1,66 +1,162 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class BlockStmt extends Statement { - - private List stmts; - - public BlockStmt() { - } - - public BlockStmt(final List stmts) { - setStmts(stmts); - } - - public BlockStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, final List stmts) { - super(beginLine, beginColumn, endLine, endColumn); - setStmts(stmts); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getStmts() { - return stmts; - } - - public void setStmts(final List stmts) { - this.stmts = stmts; - setAsParentNodeOf(this.stmts); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithStatements; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BlockStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Statements in between { and }. + * + * @author Julio Vilmar Gesser + */ +public final class BlockStmt extends Statement implements NodeWithStatements { + + private NodeList statements; + + public BlockStmt() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public BlockStmt(final NodeList statements) { + this(null, statements); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BlockStmt(TokenRange tokenRange, NodeList statements) { + super(tokenRange); + setStatements(statements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getStatements() { + return statements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt setStatements(final NodeList statements) { + assertNotNull(statements); + if (statements == this.statements) { + return (BlockStmt) this; + } + notifyPropertyChange(ObservableProperty.STATEMENTS, this.statements, statements); + if (this.statements != null) + this.statements.setParentNode(null); + this.statements = statements; + setAsParentNodeOf(statements); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < statements.size(); i++) { + if (statements.get(i) == node) { + statements.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BlockStmt clone() { + return (BlockStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BlockStmtMetaModel getMetaModel() { + return JavaParserMetaModel.blockStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < statements.size(); i++) { + if (statements.get(i) == node) { + statements.set(i, (Statement) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBlockStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BlockStmt asBlockStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBlockStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBlockStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/BreakStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/BreakStmt.java index 45ed459..4a0b411 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/BreakStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/BreakStmt.java @@ -1,60 +1,175 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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 int beginLine, final int beginColumn, final int endLine, final int endColumn, final String id) { - super(beginLine, beginColumn, endLine, endColumn); - this.id = id; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.BreakStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * A usage of the break keyword. + *
In break abc; the label is abc. + * + * @author Julio Vilmar Gesser + */ +public final class BreakStmt extends Statement { + + @OptionalProperty + private SimpleName label; + + public BreakStmt() { + this(null, new SimpleName()); + } + + public BreakStmt(final String label) { + this(null, new SimpleName(label)); + } + + @AllFieldsConstructor + public BreakStmt(final SimpleName label) { + this(null, label); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public BreakStmt(TokenRange tokenRange, SimpleName label) { + super(tokenRange); + setLabel(label); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getLabel() { + return Optional.ofNullable(label); + } + + /** + * Sets the label + * + * @param label the label, can be null + * @return this, the BreakStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BreakStmt setLabel(final SimpleName label) { + if (label == this.label) { + return (BreakStmt) this; + } + notifyPropertyChange(ObservableProperty.LABEL, this.label, label); + if (this.label != null) + this.label.setParentNode(null); + this.label = label; + setAsParentNodeOf(label); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + removeLabel(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public BreakStmt removeLabel() { + return setLabel((SimpleName) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public BreakStmt clone() { + return (BreakStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public BreakStmtMetaModel getMetaModel() { + return JavaParserMetaModel.breakStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + setLabel((SimpleName) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBreakStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BreakStmt asBreakStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBreakStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBreakStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/CatchClause.java b/JavaParser/src/com/github/javaparser/ast/stmt/CatchClause.java index e5cdb50..9eaa30e 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/CatchClause.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/CatchClause.java @@ -1,87 +1,169 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.MultiTypeParameter; -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; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class CatchClause extends Node { - - private MultiTypeParameter except; - - private BlockStmt catchBlock; - - public CatchClause() { - } - - public CatchClause(final MultiTypeParameter except, final BlockStmt catchBlock) { - setExcept(except); - setCatchBlock(catchBlock); - } - - public CatchClause(int exceptModifier, List exceptAnnotations, List exceptTypes, VariableDeclaratorId exceptId, BlockStmt catchBlock) { - this(new MultiTypeParameter(exceptModifier, exceptAnnotations, exceptTypes, exceptId), catchBlock); - } - - public CatchClause(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final int exceptModifier, final List exceptAnnotations, final List exceptTypes, - final VariableDeclaratorId exceptId, final BlockStmt catchBlock) { - super(beginLine, beginColumn, endLine, endColumn); - setExcept(new MultiTypeParameter(beginLine, beginColumn, endLine, endColumn, exceptModifier, exceptAnnotations, exceptTypes, exceptId)); - setCatchBlock(catchBlock); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public BlockStmt getCatchBlock() { - return catchBlock; - } - - public MultiTypeParameter getExcept() { - return except; - } - - public void setCatchBlock(final BlockStmt catchBlock) { - this.catchBlock = catchBlock; - setAsParentNodeOf(this.catchBlock); - } - - public void setExcept(final MultiTypeParameter except) { - this.except = except; - setAsParentNodeOf(this.except); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.EnumSet; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.CatchClauseMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; + +/** + * The catch part of a try-catch-finally.
In try { ... } catch (Exception e) { ... } the CatchClause + * is catch (Exception e) { ... }. Exception e is the parameter. The { ... } is the body. + * + * @author Julio Vilmar Gesser + */ +public final class CatchClause extends Node implements NodeWithBlockStmt { + + private Parameter parameter; + + private BlockStmt body; + + public CatchClause() { + this(null, new Parameter(), new BlockStmt()); + } + + public CatchClause(final EnumSet exceptModifier, final NodeList exceptAnnotations, final ClassOrInterfaceType exceptType, final SimpleName exceptName, final BlockStmt body) { + this(null, new Parameter(null, exceptModifier, exceptAnnotations, exceptType, false, new NodeList<>(), exceptName), body); + } + + @AllFieldsConstructor + public CatchClause(final Parameter parameter, final BlockStmt body) { + this(null, parameter, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public CatchClause(TokenRange tokenRange, Parameter parameter, BlockStmt body) { + super(tokenRange); + setParameter(parameter); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Note that the type of the Parameter can be a UnionType. In this case, any annotations found at the start of the + * catch(@X A a |...) are found directly in the Parameter. Annotations that are on the second or later type - + * catch(A a | @X B b ...) are found on those types. + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter getParameter() { + return parameter; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CatchClause setParameter(final Parameter parameter) { + assertNotNull(parameter); + if (parameter == this.parameter) { + return (CatchClause) this; + } + notifyPropertyChange(ObservableProperty.PARAMETER, this.parameter, parameter); + if (this.parameter != null) + this.parameter.setParentNode(null); + this.parameter = parameter; + setAsParentNodeOf(parameter); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CatchClause setBody(final BlockStmt body) { + assertNotNull(body); + if (body == this.body) { + return (CatchClause) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public CatchClause clone() { + return (CatchClause) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public CatchClauseMetaModel getMetaModel() { + return JavaParserMetaModel.catchClauseMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((BlockStmt) replacementNode); + return true; + } + if (node == parameter) { + setParameter((Parameter) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ContinueStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ContinueStmt.java index 85a1bc8..b829950 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ContinueStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ContinueStmt.java @@ -1,61 +1,177 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String id) { - super(beginLine, beginColumn, endLine, endColumn); - this.id = id; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithOptionalLabel; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ContinueStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * A continue statement with an optional label; + *
continue brains; + *
continue; + * + * @author Julio Vilmar Gesser + */ +public final class ContinueStmt extends Statement implements NodeWithOptionalLabel { + + @OptionalProperty + private SimpleName label; + + public ContinueStmt() { + this(null, null); + } + + public ContinueStmt(final String label) { + this(null, new SimpleName(label)); + } + + @AllFieldsConstructor + public ContinueStmt(final SimpleName label) { + this(null, label); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ContinueStmt(TokenRange tokenRange, SimpleName label) { + super(tokenRange); + setLabel(label); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getLabel() { + return Optional.ofNullable(label); + } + + /** + * Sets the label + * + * @param label the label, can be null + * @return this, the ContinueStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ContinueStmt setLabel(final SimpleName label) { + if (label == this.label) { + return (ContinueStmt) this; + } + notifyPropertyChange(ObservableProperty.LABEL, this.label, label); + if (this.label != null) + this.label.setParentNode(null); + this.label = label; + setAsParentNodeOf(label); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + removeLabel(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ContinueStmt removeLabel() { + return setLabel((SimpleName) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ContinueStmt clone() { + return (ContinueStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ContinueStmtMetaModel getMetaModel() { + return JavaParserMetaModel.continueStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + setLabel((SimpleName) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isContinueStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ContinueStmt asContinueStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifContinueStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toContinueStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/DoStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/DoStmt.java index 5281da7..7c161ff 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/DoStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/DoStmt.java @@ -1,76 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Statement body, final Expression condition) { - super(beginLine, beginColumn, endLine, endColumn); - setBody(body); - setCondition(condition); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.nodeTypes.NodeWithCondition; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.DoStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A do-while. + *
do { ... } while ( a==0 ); + * + * @author Julio Vilmar Gesser + */ +public final class DoStmt extends Statement implements NodeWithBody, NodeWithCondition { + + private Statement body; + + private Expression condition; + + public DoStmt() { + this(null, new ReturnStmt(), new BooleanLiteralExpr()); + } + + @AllFieldsConstructor + public DoStmt(final Statement body, final Expression condition) { + this(null, body, condition); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public DoStmt(TokenRange tokenRange, Statement body, Expression condition) { + super(tokenRange); + setBody(body); + setCondition(condition); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCondition() { + return condition; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public DoStmt setBody(final Statement body) { + assertNotNull(body); + if (body == this.body) { + return (DoStmt) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public DoStmt setCondition(final Expression condition) { + assertNotNull(condition); + if (condition == this.condition) { + return (DoStmt) this; + } + notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition); + if (this.condition != null) + this.condition.setParentNode(null); + this.condition = condition; + setAsParentNodeOf(condition); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public DoStmt clone() { + return (DoStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public DoStmtMetaModel getMetaModel() { + return JavaParserMetaModel.doStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((Statement) replacementNode); + return true; + } + if (node == condition) { + setCondition((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isDoStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public DoStmt asDoStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toDoStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/EmptyStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/EmptyStmt.java index 313f368..d73ede6 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/EmptyStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/EmptyStmt.java @@ -1,45 +1,117 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.EmptyStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An empty statement is a ";" where a statement is expected. + * @author Julio Vilmar Gesser + */ +public final class EmptyStmt extends Statement { + + @AllFieldsConstructor + public EmptyStmt() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public EmptyStmt(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public EmptyStmt clone() { + return (EmptyStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public EmptyStmtMetaModel getMetaModel() { + return JavaParserMetaModel.emptyStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEmptyStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EmptyStmt asEmptyStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEmptyStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEmptyStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java index d151745..2b9b9c2 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java @@ -1,108 +1,299 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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; - -/** - * @author Julio Vilmar Gesser - */ -public final class ExplicitConstructorInvocationStmt extends Statement { - - private List typeArgs; - - private boolean isThis; - - private Expression expr; - - private List args; - - public ExplicitConstructorInvocationStmt() { - } - - public ExplicitConstructorInvocationStmt(final boolean isThis, - final Expression expr, final List args) { - setThis(isThis); - setExpr(expr); - setArgs(args); - } - - public ExplicitConstructorInvocationStmt(final int beginLine, - final int beginColumn, final int endLine, final int endColumn, - final List typeArgs, final boolean isThis, - final Expression expr, final List args) { - super(beginLine, beginColumn, endLine, endColumn); - setTypeArgs(typeArgs); - setThis(isThis); - setExpr(expr); - setArgs(args); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getArgs() { - return args; - } - - public Expression getExpr() { - return expr; - } - - public List getTypeArgs() { - return typeArgs; - } - - public boolean isThis() { - return isThis; - } - - public void setArgs(final List 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 typeArgs) { - this.typeArgs = typeArgs; - setAsParentNodeOf(this.typeArgs); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ExplicitConstructorInvocationStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import java.util.function.Consumer; + +/** + * A call to super or this in a constructor or initializer. + *
class X { X() { super(15); } } + *
class X { X() { this(1, 2); } } + * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.expr.SuperExpr + * @see com.github.javaparser.ast.expr.ThisExpr + */ +public final class ExplicitConstructorInvocationStmt extends Statement implements NodeWithTypeArguments { + + @OptionalProperty + private NodeList typeArguments; + + private boolean isThis; + + @OptionalProperty + private Expression expression; + + private NodeList arguments; + + public ExplicitConstructorInvocationStmt() { + this(null, new NodeList<>(), true, null, new NodeList<>()); + } + + public ExplicitConstructorInvocationStmt(final boolean isThis, final Expression expression, final NodeList arguments) { + this(null, new NodeList<>(), isThis, expression, arguments); + } + + @AllFieldsConstructor + public ExplicitConstructorInvocationStmt(final NodeList typeArguments, final boolean isThis, final Expression expression, final NodeList arguments) { + this(null, typeArguments, isThis, expression, arguments); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ExplicitConstructorInvocationStmt(TokenRange tokenRange, NodeList typeArguments, boolean isThis, Expression expression, NodeList arguments) { + super(tokenRange); + setTypeArguments(typeArguments); + setThis(isThis); + setExpression(expression); + setArguments(arguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getArguments() { + return arguments; + } + + public Expression getArgument(int i) { + return getArguments().get(i); + } + + public ExplicitConstructorInvocationStmt setArgument(int i, Expression argument) { + getArguments().set(i, argument); + return this; + } + + public ExplicitConstructorInvocationStmt addArgument(Expression argument) { + getArguments().add(argument); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getExpression() { + return Optional.ofNullable(expression); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public boolean isThis() { + return isThis; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ExplicitConstructorInvocationStmt setArguments(final NodeList arguments) { + assertNotNull(arguments); + if (arguments == this.arguments) { + return (ExplicitConstructorInvocationStmt) this; + } + notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments); + if (this.arguments != null) + this.arguments.setParentNode(null); + this.arguments = arguments; + setAsParentNodeOf(arguments); + return this; + } + + /** + * Sets the expression + * + * @param expression the expression, can be null + * @return this, the ExplicitConstructorInvocationStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ExplicitConstructorInvocationStmt setExpression(final Expression expression) { + if (expression == this.expression) { + return (ExplicitConstructorInvocationStmt) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ExplicitConstructorInvocationStmt setThis(final boolean isThis) { + if (isThis == this.isThis) { + return (ExplicitConstructorInvocationStmt) this; + } + notifyPropertyChange(ObservableProperty.THIS, this.isThis, isThis); + this.isThis = isThis; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ExplicitConstructorInvocationStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ExplicitConstructorInvocationStmt setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (ExplicitConstructorInvocationStmt) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.remove(i); + return true; + } + } + if (expression != null) { + if (node == expression) { + removeExpression(); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ExplicitConstructorInvocationStmt removeExpression() { + return setExpression((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ExplicitConstructorInvocationStmt clone() { + return (ExplicitConstructorInvocationStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ExplicitConstructorInvocationStmtMetaModel getMetaModel() { + return JavaParserMetaModel.explicitConstructorInvocationStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i) == node) { + arguments.set(i, (Expression) replacementNode); + return true; + } + } + if (expression != null) { + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isExplicitConstructorInvocationStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ExplicitConstructorInvocationStmt asExplicitConstructorInvocationStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExplicitConstructorInvocationStmt(Consumer action) { + action.accept(this); + } + + public ResolvedConstructorDeclaration resolveInvokedConstructor() { + return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toExplicitConstructorInvocationStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ExpressionStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ExpressionStmt.java index 42c7148..483c45d 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ExpressionStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ExpressionStmt.java @@ -1,63 +1,153 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression expr) { - super(beginLine, beginColumn, endLine, endColumn); - setExpression(expr); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ExpressionStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Used to wrap an expression so that it can take the place of a statement. + * + * @author Julio Vilmar Gesser + */ +public final class ExpressionStmt extends Statement implements NodeWithExpression { + + private Expression expression; + + public ExpressionStmt() { + this(null, new BooleanLiteralExpr()); + } + + @AllFieldsConstructor + public ExpressionStmt(final Expression expression) { + this(null, expression); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ExpressionStmt(TokenRange tokenRange, Expression expression) { + super(tokenRange); + setExpression(expression); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ExpressionStmt setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (ExpressionStmt) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ExpressionStmt clone() { + return (ExpressionStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ExpressionStmtMetaModel getMetaModel() { + return JavaParserMetaModel.expressionStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isExpressionStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ExpressionStmt asExpressionStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExpressionStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toExpressionStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ForStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ForStmt.java index b48ecbd..d288991 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ForStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ForStmt.java @@ -1,109 +1,290 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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; - -/** - * @author Julio Vilmar Gesser - */ -public final class ForStmt extends Statement { - - private List init; - - private Expression compare; - - private List update; - - private Statement body; - - public ForStmt() { - } - - public ForStmt(final List init, final Expression compare, - final List update, final Statement body) { - setCompare(compare); - setInit(init); - setUpdate(update); - setBody(body); - } - - public ForStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, - final List init, final Expression compare, - final List update, final Statement body) { - super(beginLine, beginColumn, endLine, endColumn); - setCompare(compare); - setInit(init); - setUpdate(update); - setBody(body); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public Statement getBody() { - return body; - } - - public Expression getCompare() { - return compare; - } - - public List getInit() { - return init; - } - - public List getUpdate() { - 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 init) { - this.init = init; - setAsParentNodeOf(this.init); - } - - public void setUpdate(final List update) { - this.update = update; - setAsParentNodeOf(this.update); - } -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.ForStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import javax.annotation.Generated; +import java.util.Optional; +import java.util.function.Consumer; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + *

The classic for statement

+ * Examples: + *
    + *
  1. for(int a=3, b=5; a<99; a++, b++) hello();
  2. + *
  3. for(a=3, b=5; a<99; a++) { hello(); }
  4. + *
  5. for(a(),b();;) hello();
  6. + *
+ *
    + *
  • initialization is a list of expressions. + * These can be any kind of expression as can be seen in example 3, + * but the common ones are a single VariableDeclarationExpr (which declares multiple variables) in example 1, + * or a list of AssignExpr's in example 2.
  • + *
  • compare is an expression, + * in example 1 and 2 it is a BinaryExpr. + * In example 3 there is no expression, it is empty.
  • + *
  • update is a list of expressions, + * in example 1 and 2 they are UnaryExpr's. + * In example 3 there is no expression, the list empty.
  • + *
  • body is a statement, + * in example 1 and 3 it is an ExpressionStmt. + * in example 2 it is a BlockStmt.
  • + *
+ * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.expr.VariableDeclarationExpr + */ +public final class ForStmt extends Statement implements NodeWithBody { + + private NodeList initialization; + + @OptionalProperty + private Expression compare; + + private NodeList update; + + private Statement body; + + public ForStmt() { + this(null, new NodeList<>(), new BooleanLiteralExpr(), new NodeList<>(), new ReturnStmt()); + } + + @AllFieldsConstructor + public ForStmt(final NodeList initialization, final Expression compare, final NodeList update, final Statement body) { + this(null, initialization, compare, update, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ForStmt(TokenRange tokenRange, NodeList initialization, Expression compare, NodeList update, Statement body) { + super(tokenRange); + setInitialization(initialization); + setCompare(compare); + setUpdate(update); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getCompare() { + return Optional.ofNullable(compare); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getInitialization() { + return initialization; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getUpdate() { + return update; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForStmt setBody(final Statement body) { + assertNotNull(body); + if (body == this.body) { + return (ForStmt) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + /** + * Sets the compare + * + * @param compare the compare, can be null + * @return this, the ForStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForStmt setCompare(final Expression compare) { + if (compare == this.compare) { + return (ForStmt) this; + } + notifyPropertyChange(ObservableProperty.COMPARE, this.compare, compare); + if (this.compare != null) + this.compare.setParentNode(null); + this.compare = compare; + setAsParentNodeOf(compare); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForStmt setInitialization(final NodeList initialization) { + assertNotNull(initialization); + if (initialization == this.initialization) { + return (ForStmt) this; + } + notifyPropertyChange(ObservableProperty.INITIALIZATION, this.initialization, initialization); + if (this.initialization != null) + this.initialization.setParentNode(null); + this.initialization = initialization; + setAsParentNodeOf(initialization); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForStmt setUpdate(final NodeList update) { + assertNotNull(update); + if (update == this.update) { + return (ForStmt) this; + } + notifyPropertyChange(ObservableProperty.UPDATE, this.update, update); + if (this.update != null) + this.update.setParentNode(null); + this.update = update; + setAsParentNodeOf(update); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (compare != null) { + if (node == compare) { + removeCompare(); + return true; + } + } + for (int i = 0; i < initialization.size(); i++) { + if (initialization.get(i) == node) { + initialization.remove(i); + return true; + } + } + for (int i = 0; i < update.size(); i++) { + if (update.get(i) == node) { + update.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ForStmt removeCompare() { + return setCompare((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ForStmt clone() { + return (ForStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ForStmtMetaModel getMetaModel() { + return JavaParserMetaModel.forStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((Statement) replacementNode); + return true; + } + if (compare != null) { + if (node == compare) { + setCompare((Expression) replacementNode); + return true; + } + } + for (int i = 0; i < initialization.size(); i++) { + if (initialization.get(i) == node) { + initialization.set(i, (Expression) replacementNode); + return true; + } + } + for (int i = 0; i < update.size(); i++) { + if (update.get(i) == node) { + update.set(i, (Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isForStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ForStmt asForStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toForStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ForeachStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ForeachStmt.java index 030b1ad..7a04e5b 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ForeachStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ForeachStmt.java @@ -1,95 +1,211 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, - final VariableDeclarationExpr var, final Expression iterable, - final Statement body) { - super(beginLine, beginColumn, endLine, endColumn); - setVariable(var); - setIterable(iterable); - setBody(body); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ForeachStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A for-each statement. + *
for(Object o: objects) { ... } + * + * @author Julio Vilmar Gesser + */ +public final class ForeachStmt extends Statement implements NodeWithBody { + + private VariableDeclarationExpr variable; + + private Expression iterable; + + private Statement body; + + public ForeachStmt() { + this(null, new VariableDeclarationExpr(), new NameExpr(), new ReturnStmt()); + } + + @AllFieldsConstructor + public ForeachStmt(final VariableDeclarationExpr variable, final Expression iterable, final Statement body) { + this(null, variable, iterable, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ForeachStmt(TokenRange tokenRange, VariableDeclarationExpr variable, Expression iterable, Statement body) { + super(tokenRange); + setVariable(variable); + setIterable(iterable); + setBody(body); + customInitialization(); + } + + public ForeachStmt(VariableDeclarationExpr variable, String iterable, BlockStmt body) { + this(null, variable, new NameExpr(iterable), body); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getIterable() { + return iterable; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarationExpr getVariable() { + return variable; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForeachStmt setBody(final Statement body) { + assertNotNull(body); + if (body == this.body) { + return (ForeachStmt) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForeachStmt setIterable(final Expression iterable) { + assertNotNull(iterable); + if (iterable == this.iterable) { + return (ForeachStmt) this; + } + notifyPropertyChange(ObservableProperty.ITERABLE, this.iterable, iterable); + if (this.iterable != null) + this.iterable.setParentNode(null); + this.iterable = iterable; + setAsParentNodeOf(iterable); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ForeachStmt setVariable(final VariableDeclarationExpr variable) { + assertNotNull(variable); + if (variable == this.variable) { + return (ForeachStmt) this; + } + notifyPropertyChange(ObservableProperty.VARIABLE, this.variable, variable); + if (this.variable != null) + this.variable.setParentNode(null); + this.variable = variable; + setAsParentNodeOf(variable); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ForeachStmt clone() { + return (ForeachStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ForeachStmtMetaModel getMetaModel() { + return JavaParserMetaModel.foreachStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((Statement) replacementNode); + return true; + } + if (node == iterable) { + setIterable((Expression) replacementNode); + return true; + } + if (node == variable) { + setVariable((VariableDeclarationExpr) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isForeachStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ForeachStmt asForeachStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForeachStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toForeachStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/IfStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/IfStmt.java index 35c54e3..f873ff8 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/IfStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/IfStmt.java @@ -1,89 +1,260 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression condition, final Statement thenStmt, final Statement elseStmt) { - super(beginLine, beginColumn, endLine, endColumn); - setCondition(condition); - setThenStmt(thenStmt); - setElseStmt(elseStmt); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithCondition; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.DerivedProperty; +import com.github.javaparser.metamodel.IfStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import java.util.function.Consumer; + +/** + * An if-then-else statement. The else is optional. + *
In if(a==5) hurray() else boo(); the condition is a==5, + * hurray() is the thenStmt, and boo() is the elseStmt. + * + * @author Julio Vilmar Gesser + */ +public final class IfStmt extends Statement implements NodeWithCondition { + + private Expression condition; + + private Statement thenStmt; + + @OptionalProperty + private Statement elseStmt; + + public IfStmt() { + this(null, new BooleanLiteralExpr(), new ReturnStmt(), null); + } + + @AllFieldsConstructor + public IfStmt(final Expression condition, final Statement thenStmt, final Statement elseStmt) { + this(null, condition, thenStmt, elseStmt); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public IfStmt(TokenRange tokenRange, Expression condition, Statement thenStmt, Statement elseStmt) { + super(tokenRange); + setCondition(condition); + setThenStmt(thenStmt); + setElseStmt(elseStmt); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCondition() { + return condition; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getElseStmt() { + return Optional.ofNullable(elseStmt); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getThenStmt() { + return thenStmt; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public IfStmt setCondition(final Expression condition) { + assertNotNull(condition); + if (condition == this.condition) { + return (IfStmt) this; + } + notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition); + if (this.condition != null) + this.condition.setParentNode(null); + this.condition = condition; + setAsParentNodeOf(condition); + return this; + } + + /** + * Sets the elseStmt + * + * @param elseStmt the elseStmt, can be null + * @return this, the IfStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public IfStmt setElseStmt(final Statement elseStmt) { + if (elseStmt == this.elseStmt) { + return (IfStmt) this; + } + notifyPropertyChange(ObservableProperty.ELSE_STMT, this.elseStmt, elseStmt); + if (this.elseStmt != null) + this.elseStmt.setParentNode(null); + this.elseStmt = elseStmt; + setAsParentNodeOf(elseStmt); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public IfStmt setThenStmt(final Statement thenStmt) { + assertNotNull(thenStmt); + if (thenStmt == this.thenStmt) { + return (IfStmt) this; + } + notifyPropertyChange(ObservableProperty.THEN_STMT, this.thenStmt, thenStmt); + if (this.thenStmt != null) + this.thenStmt.setParentNode(null); + this.thenStmt = thenStmt; + setAsParentNodeOf(thenStmt); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (elseStmt != null) { + if (node == elseStmt) { + removeElseStmt(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public IfStmt removeElseStmt() { + return setElseStmt((Statement) null); + } + + /** + * This method returns true if the then branch (which should be always present) is a block statement. + */ + @DerivedProperty + public boolean hasThenBlock() { + return thenStmt instanceof BlockStmt; + } + + /** + * This method returns true if the If Statement has an else branch and that branch is a block statement. + */ + @DerivedProperty + public boolean hasElseBlock() { + return elseStmt instanceof BlockStmt; + } + + /** + * This method returns true if the If Statement has an else branch and that branch is another If Statement. + */ + @DerivedProperty + public boolean hasCascadingIfStmt() { + return elseStmt instanceof IfStmt; + } + + /** + * This method returns true if the If Statement has an else branch. + */ + @DerivedProperty + public boolean hasElseBranch() { + return elseStmt != null; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public IfStmt clone() { + return (IfStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public IfStmtMetaModel getMetaModel() { + return JavaParserMetaModel.ifStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == condition) { + setCondition((Expression) replacementNode); + return true; + } + if (elseStmt != null) { + if (node == elseStmt) { + setElseStmt((Statement) replacementNode); + return true; + } + } + if (node == thenStmt) { + setThenStmt((Statement) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIfStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IfStmt asIfStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIfStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIfStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/LabeledStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/LabeledStmt.java index 91be40f..7906d0c 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/LabeledStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/LabeledStmt.java @@ -1,74 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final String label, final Statement stmt) { - super(beginLine, beginColumn, endLine, endColumn); - setLabel(label); - setStmt(stmt); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.LabeledStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A statement that is labeled, like label123: println("continuing"); + * + * @author Julio Vilmar Gesser + */ +public final class LabeledStmt extends Statement { + + private SimpleName label; + + private Statement statement; + + public LabeledStmt() { + this(null, new SimpleName(), new ReturnStmt()); + } + + public LabeledStmt(final String label, final Statement statement) { + this(null, new SimpleName(label), statement); + } + + @AllFieldsConstructor + public LabeledStmt(final SimpleName label, final Statement statement) { + this(null, label, statement); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LabeledStmt(TokenRange tokenRange, SimpleName label, Statement statement) { + super(tokenRange); + setLabel(label); + setStatement(statement); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getStatement() { + return statement; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LabeledStmt setStatement(final Statement statement) { + assertNotNull(statement); + if (statement == this.statement) { + return (LabeledStmt) this; + } + notifyPropertyChange(ObservableProperty.STATEMENT, this.statement, statement); + if (this.statement != null) + this.statement.setParentNode(null); + this.statement = statement; + setAsParentNodeOf(statement); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getLabel() { + return label; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LabeledStmt setLabel(final SimpleName label) { + assertNotNull(label); + if (label == this.label) { + return (LabeledStmt) this; + } + notifyPropertyChange(ObservableProperty.LABEL, this.label, label); + if (this.label != null) + this.label.setParentNode(null); + this.label = label; + setAsParentNodeOf(label); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LabeledStmt clone() { + return (LabeledStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LabeledStmtMetaModel getMetaModel() { + return JavaParserMetaModel.labeledStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == label) { + setLabel((SimpleName) replacementNode); + return true; + } + if (node == statement) { + setStatement((Statement) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLabeledStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LabeledStmt asLabeledStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLabeledStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLabeledStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java new file mode 100644 index 0000000..f78eebc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java @@ -0,0 +1,157 @@ +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.LocalClassDeclarationStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + *

A class declaration inside a method.

+ *

Java 1.0

+ * Not available. + *

Java 1.1+

+ * A statement consisting of a class declaration. + *
class X { void m() { class Y { } } } + * + * @see ClassOrInterfaceDeclaration + * @author Julio Vilmar Gesser + */ +public final class LocalClassDeclarationStmt extends Statement { + + private ClassOrInterfaceDeclaration classDeclaration; + + public LocalClassDeclarationStmt() { + this(null, new ClassOrInterfaceDeclaration()); + } + + @AllFieldsConstructor + public LocalClassDeclarationStmt(final ClassOrInterfaceDeclaration classDeclaration) { + this(null, classDeclaration); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public LocalClassDeclarationStmt(TokenRange tokenRange, ClassOrInterfaceDeclaration classDeclaration) { + super(tokenRange); + setClassDeclaration(classDeclaration); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceDeclaration getClassDeclaration() { + return classDeclaration; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LocalClassDeclarationStmt setClassDeclaration(final ClassOrInterfaceDeclaration classDeclaration) { + assertNotNull(classDeclaration); + if (classDeclaration == this.classDeclaration) { + return (LocalClassDeclarationStmt) this; + } + notifyPropertyChange(ObservableProperty.CLASS_DECLARATION, this.classDeclaration, classDeclaration); + if (this.classDeclaration != null) + this.classDeclaration.setParentNode(null); + this.classDeclaration = classDeclaration; + setAsParentNodeOf(classDeclaration); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public LocalClassDeclarationStmt clone() { + return (LocalClassDeclarationStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public LocalClassDeclarationStmtMetaModel getMetaModel() { + return JavaParserMetaModel.localClassDeclarationStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == classDeclaration) { + setClassDeclaration((ClassOrInterfaceDeclaration) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLocalClassDeclarationStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LocalClassDeclarationStmt asLocalClassDeclarationStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLocalClassDeclarationStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLocalClassDeclarationStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ReturnStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ReturnStmt.java index b46c648..c9bdb45 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ReturnStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ReturnStmt.java @@ -1,63 +1,178 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression expr) { - super(beginLine, beginColumn, endLine, endColumn); - setExpr(expr); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.ReturnStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; + +/** + * The return statement, with an optional expression to return. + *
return 5 * 5; + * @author Julio Vilmar Gesser + */ +public final class ReturnStmt extends Statement { + + @OptionalProperty + private Expression expression; + + public ReturnStmt() { + this(null, null); + } + + @AllFieldsConstructor + public ReturnStmt(final Expression expression) { + this(null, expression); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ReturnStmt(TokenRange tokenRange, Expression expression) { + super(tokenRange); + setExpression(expression); + customInitialization(); + } + + /** + * Will create a NameExpr with the string param + */ + public ReturnStmt(String expression) { + this(null, new NameExpr(expression)); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getExpression() { + return Optional.ofNullable(expression); + } + + /** + * Sets the expression + * + * @param expression the expression, can be null + * @return this, the ReturnStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ReturnStmt setExpression(final Expression expression) { + if (expression == this.expression) { + return (ReturnStmt) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (expression != null) { + if (node == expression) { + removeExpression(); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ReturnStmt removeExpression() { + return setExpression((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ReturnStmt clone() { + return (ReturnStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ReturnStmtMetaModel getMetaModel() { + return JavaParserMetaModel.returnStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (expression != null) { + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isReturnStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ReturnStmt asReturnStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReturnStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toReturnStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/Statement.java b/JavaParser/src/com/github/javaparser/ast/stmt/Statement.java index 1bb7491..75100e8 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/Statement.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/Statement.java @@ -1,37 +1,481 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.Node; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class Statement extends Node { - - public Statement() { - } - - public Statement(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.StatementMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import java.util.Optional; + +/** + * A base class for all statements. + * + * @author Julio Vilmar Gesser + */ +public abstract class Statement extends Node { + + @AllFieldsConstructor + public Statement() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Statement(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Statement clone() { + return (Statement) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public StatementMetaModel getMetaModel() { + return JavaParserMetaModel.statementMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isAssertStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public AssertStmt asAssertStmt() { + throw new IllegalStateException(f("%s is not an AssertStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBlockStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BlockStmt asBlockStmt() { + throw new IllegalStateException(f("%s is not an BlockStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isBreakStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public BreakStmt asBreakStmt() { + throw new IllegalStateException(f("%s is not an BreakStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isContinueStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ContinueStmt asContinueStmt() { + throw new IllegalStateException(f("%s is not an ContinueStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isDoStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public DoStmt asDoStmt() { + throw new IllegalStateException(f("%s is not an DoStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isEmptyStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public EmptyStmt asEmptyStmt() { + throw new IllegalStateException(f("%s is not an EmptyStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isExplicitConstructorInvocationStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ExplicitConstructorInvocationStmt asExplicitConstructorInvocationStmt() { + throw new IllegalStateException(f("%s is not an ExplicitConstructorInvocationStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isExpressionStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ExpressionStmt asExpressionStmt() { + throw new IllegalStateException(f("%s is not an ExpressionStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isForStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ForStmt asForStmt() { + throw new IllegalStateException(f("%s is not an ForStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isForeachStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ForeachStmt asForeachStmt() { + throw new IllegalStateException(f("%s is not an ForeachStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIfStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IfStmt asIfStmt() { + throw new IllegalStateException(f("%s is not an IfStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLabeledStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LabeledStmt asLabeledStmt() { + throw new IllegalStateException(f("%s is not an LabeledStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isLocalClassDeclarationStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public LocalClassDeclarationStmt asLocalClassDeclarationStmt() { + throw new IllegalStateException(f("%s is not an LocalClassDeclarationStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isReturnStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ReturnStmt asReturnStmt() { + throw new IllegalStateException(f("%s is not an ReturnStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSwitchEntryStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SwitchEntryStmt asSwitchEntryStmt() { + throw new IllegalStateException(f("%s is not an SwitchEntryStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSwitchStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SwitchStmt asSwitchStmt() { + throw new IllegalStateException(f("%s is not an SwitchStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSynchronizedStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SynchronizedStmt asSynchronizedStmt() { + throw new IllegalStateException(f("%s is not an SynchronizedStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isThrowStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ThrowStmt asThrowStmt() { + throw new IllegalStateException(f("%s is not an ThrowStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTryStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TryStmt asTryStmt() { + throw new IllegalStateException(f("%s is not an TryStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnparsableStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnparsableStmt asUnparsableStmt() { + throw new IllegalStateException(f("%s is not an UnparsableStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isWhileStmt() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public WhileStmt asWhileStmt() { + throw new IllegalStateException(f("%s is not an WhileStmt", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAssertStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBlockStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBreakStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifContinueStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEmptyStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExplicitConstructorInvocationStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExpressionStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForeachStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIfStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLabeledStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLocalClassDeclarationStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReturnStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchEntryStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSynchronizedStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThrowStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTryStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnparsableStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWhileStmt(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toAssertStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBlockStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toBreakStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toContinueStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toDoStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toEmptyStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toExplicitConstructorInvocationStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toExpressionStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toForStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toForeachStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIfStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLabeledStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toLocalClassDeclarationStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toReturnStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSwitchEntryStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSwitchStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSynchronizedStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toThrowStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTryStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnparsableStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toWhileStmt() { + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/SwitchEntryStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/SwitchEntryStmt.java index 6f27ab3..afa8fce 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/SwitchEntryStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/SwitchEntryStmt.java @@ -1,81 +1,224 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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; - -/** - * @author Julio Vilmar Gesser - */ -public final class SwitchEntryStmt extends Statement { - - private Expression label; - - private List stmts; - - public SwitchEntryStmt() { - } - - public SwitchEntryStmt(final Expression label, final List stmts) { - setLabel(label); - setStmts(stmts); - } - - public SwitchEntryStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, final Expression label, - final List stmts) { - super(beginLine, beginColumn, endLine, endColumn); - setLabel(label); - setStmts(stmts); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public Expression getLabel() { - return label; - } - - public List getStmts() { - return stmts; - } - - public void setLabel(final Expression label) { - this.label = label; - setAsParentNodeOf(this.label); - } - - public void setStmts(final List stmts) { - this.stmts = stmts; - setAsParentNodeOf(this.stmts); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithStatements; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.SwitchEntryStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; + +/** + * One case in a switch statement. + *
+ * switch (i) {
+ * case 1:
+ * case 2:
+ * System.out.println(444);
+ * break;
+ * default:
+ * System.out.println(0);
+ * }
+ * 
+ * This contains three SwitchEntryStmts. + *
The first one has label 1 and no statements. + *
The second has label 2 and two statements (the println and the break). + *
The third, the default, has no label and one statement. + * + * @author Julio Vilmar Gesser + * @see SwitchStmt + */ +public final class SwitchEntryStmt extends Statement implements NodeWithStatements { + + @OptionalProperty + private Expression label; + + private NodeList statements; + + public SwitchEntryStmt() { + this(null, null, new NodeList<>()); + } + + @AllFieldsConstructor + public SwitchEntryStmt(final Expression label, final NodeList statements) { + this(null, label, statements); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SwitchEntryStmt(TokenRange tokenRange, Expression label, NodeList statements) { + super(tokenRange); + setLabel(label); + setStatements(statements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getLabel() { + return Optional.ofNullable(label); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getStatements() { + return statements; + } + + /** + * Sets the label + * + * @param label the label, can be null + * @return this, the SwitchEntryStmt + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SwitchEntryStmt setLabel(final Expression label) { + if (label == this.label) { + return (SwitchEntryStmt) this; + } + notifyPropertyChange(ObservableProperty.LABEL, this.label, label); + if (this.label != null) + this.label.setParentNode(null); + this.label = label; + setAsParentNodeOf(label); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SwitchEntryStmt setStatements(final NodeList statements) { + assertNotNull(statements); + if (statements == this.statements) { + return (SwitchEntryStmt) this; + } + notifyPropertyChange(ObservableProperty.STATEMENTS, this.statements, statements); + if (this.statements != null) + this.statements.setParentNode(null); + this.statements = statements; + setAsParentNodeOf(statements); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + removeLabel(); + return true; + } + } + for (int i = 0; i < statements.size(); i++) { + if (statements.get(i) == node) { + statements.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public SwitchEntryStmt removeLabel() { + return setLabel((Expression) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SwitchEntryStmt clone() { + return (SwitchEntryStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SwitchEntryStmtMetaModel getMetaModel() { + return JavaParserMetaModel.switchEntryStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (label != null) { + if (node == label) { + setLabel((Expression) replacementNode); + return true; + } + } + for (int i = 0; i < statements.size(); i++) { + if (statements.get(i) == node) { + statements.set(i, (Statement) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSwitchEntryStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SwitchEntryStmt asSwitchEntryStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchEntryStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSwitchEntryStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/SwitchStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/SwitchStmt.java index 712521e..36e88b2 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/SwitchStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/SwitchStmt.java @@ -1,82 +1,214 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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; - -/** - * @author Julio Vilmar Gesser - */ -public final class SwitchStmt extends Statement { - - private Expression selector; - - private List entries; - - public SwitchStmt() { - } - - public SwitchStmt(final Expression selector, - final List entries) { - setSelector(selector); - setEntries(entries); - } - - public SwitchStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, final Expression selector, - final List entries) { - super(beginLine, beginColumn, endLine, endColumn); - setSelector(selector); - setEntries(entries); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getEntries() { - return entries; - } - - public Expression getSelector() { - return selector; - } - - public void setEntries(final List entries) { - this.entries = entries; - setAsParentNodeOf(this.entries); - } - - public void setSelector(final Expression selector) { - this.selector = selector; - setAsParentNodeOf(this.selector); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.SwitchStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A switch statement. + *
In switch(a) { ... } the selector is "a", + * and the contents of the { ... } are the entries. + * + * @author Julio Vilmar Gesser + * @see SwitchEntryStmt + */ +public final class SwitchStmt extends Statement { + + private Expression selector; + + private NodeList entries; + + public SwitchStmt() { + this(null, new NameExpr(), new NodeList<>()); + } + + @AllFieldsConstructor + public SwitchStmt(final Expression selector, final NodeList entries) { + this(null, selector, entries); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SwitchStmt(TokenRange tokenRange, Expression selector, NodeList entries) { + super(tokenRange); + setSelector(selector); + setEntries(entries); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getEntries() { + return entries; + } + + public SwitchEntryStmt getEntry(int i) { + return getEntries().get(i); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getSelector() { + return selector; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SwitchStmt setEntries(final NodeList entries) { + assertNotNull(entries); + if (entries == this.entries) { + return (SwitchStmt) this; + } + notifyPropertyChange(ObservableProperty.ENTRIES, this.entries, entries); + if (this.entries != null) + this.entries.setParentNode(null); + this.entries = entries; + setAsParentNodeOf(entries); + return this; + } + + /** + * @deprecated use a method on getEntries instead + */ + @Deprecated + public SwitchStmt setEntry(int i, SwitchEntryStmt entry) { + getEntries().set(i, entry); + return this; + } + + /** + * @deprecated use a method on getEntries instead + */ + @Deprecated + public SwitchStmt addEntry(SwitchEntryStmt entry) { + getEntries().add(entry); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SwitchStmt setSelector(final Expression selector) { + assertNotNull(selector); + if (selector == this.selector) { + return (SwitchStmt) this; + } + notifyPropertyChange(ObservableProperty.SELECTOR, this.selector, selector); + if (this.selector != null) + this.selector.setParentNode(null); + this.selector = selector; + setAsParentNodeOf(selector); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i) == node) { + entries.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SwitchStmt clone() { + return (SwitchStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SwitchStmtMetaModel getMetaModel() { + return JavaParserMetaModel.switchStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i) == node) { + entries.set(i, (SwitchEntryStmt) replacementNode); + return true; + } + } + if (node == selector) { + setSelector((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSwitchStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SwitchStmt asSwitchStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSwitchStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/SynchronizedStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/SynchronizedStmt.java index 6128c4b..376d525 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/SynchronizedStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/SynchronizedStmt.java @@ -1,79 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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 SynchronizedStmt extends Statement { - - private Expression expr; - - private BlockStmt block; - - public SynchronizedStmt() { - } - - public SynchronizedStmt(final Expression expr, final BlockStmt block) { - setExpr(expr); - setBlock(block); - } - - public SynchronizedStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, final Expression expr, - final BlockStmt block) { - super(beginLine, beginColumn, endLine, endColumn); - setExpr(expr); - setBlock(block); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public BlockStmt getBlock() { - return block; - } - - public Expression getExpr() { - return expr; - } - - public void setBlock(final BlockStmt block) { - this.block = block; - setAsParentNodeOf(this.block); - } - - public void setExpr(final Expression expr) { - this.expr = expr; - setAsParentNodeOf(this.expr); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.SynchronizedStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Usage of the synchronized keyword. + *
In synchronized (a123) { ... } the expression is a123 and { ... } is the body + * + * @author Julio Vilmar Gesser + */ +public final class SynchronizedStmt extends Statement implements NodeWithBlockStmt, NodeWithExpression { + + private Expression expression; + + private BlockStmt body; + + public SynchronizedStmt() { + this(null, new NameExpr(), new BlockStmt()); + } + + @AllFieldsConstructor + public SynchronizedStmt(final Expression expression, final BlockStmt body) { + this(null, expression, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public SynchronizedStmt(TokenRange tokenRange, Expression expression, BlockStmt body) { + super(tokenRange); + setExpression(expression); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SynchronizedStmt setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (SynchronizedStmt) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SynchronizedStmt setBody(final BlockStmt body) { + assertNotNull(body); + if (body == this.body) { + return (SynchronizedStmt) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public SynchronizedStmt clone() { + return (SynchronizedStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public SynchronizedStmtMetaModel getMetaModel() { + return JavaParserMetaModel.synchronizedStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((BlockStmt) replacementNode); + return true; + } + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isSynchronizedStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public SynchronizedStmt asSynchronizedStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSynchronizedStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toSynchronizedStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/ThrowStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/ThrowStmt.java index c7c26e7..736b835 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/ThrowStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/ThrowStmt.java @@ -1,63 +1,154 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class ThrowStmt extends Statement { - - private Expression expr; - - public ThrowStmt() { - } - - public ThrowStmt(final Expression expr) { - setExpr(expr); - } - - public ThrowStmt(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression expr) { - super(beginLine, beginColumn, endLine, endColumn); - setExpr(expr); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithExpression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.ThrowStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Usage of the throw statement. + *
throw new Exception() + * + * @author Julio Vilmar Gesser + */ +public final class ThrowStmt extends Statement implements NodeWithExpression { + + private Expression expression; + + public ThrowStmt() { + this(null, new NameExpr()); + } + + @AllFieldsConstructor + public ThrowStmt(final Expression expression) { + this(null, expression); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ThrowStmt(TokenRange tokenRange, Expression expression) { + super(tokenRange); + setExpression(expression); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getExpression() { + return expression; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ThrowStmt setExpression(final Expression expression) { + assertNotNull(expression); + if (expression == this.expression) { + return (ThrowStmt) this; + } + notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression); + if (this.expression != null) + this.expression.setParentNode(null); + this.expression = expression; + setAsParentNodeOf(expression); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ThrowStmt clone() { + return (ThrowStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ThrowStmtMetaModel getMetaModel() { + return JavaParserMetaModel.throwStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == expression) { + setExpression((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isThrowStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ThrowStmt asThrowStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThrowStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toThrowStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/TryStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/TryStmt.java index 3bc80a2..6e4a81a 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/TryStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/TryStmt.java @@ -1,107 +1,321 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class TryStmt extends Statement { - - private List resources; - - private BlockStmt tryBlock; - - private List catchs; - - private BlockStmt finallyBlock; - - public TryStmt() { - } - - public TryStmt(final BlockStmt tryBlock, final List catchs, - final BlockStmt finallyBlock) { - setTryBlock(tryBlock); - setCatchs(catchs); - setFinallyBlock(finallyBlock); - } - - public TryStmt(final int beginLine, final int beginColumn, - final int endLine, final int endColumn, List resources, - final BlockStmt tryBlock, final List catchs, final BlockStmt finallyBlock) { - super(beginLine, beginColumn, endLine, endColumn); - setResources(resources); - setTryBlock(tryBlock); - setCatchs(catchs); - setFinallyBlock(finallyBlock); - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public List getCatchs() { - return catchs; - } - - public BlockStmt getFinallyBlock() { - return finallyBlock; - } - - public BlockStmt getTryBlock() { - return tryBlock; - } - - public List getResources() { - return resources; - } - - public void setCatchs(final List catchs) { - this.catchs = catchs; - setAsParentNodeOf(this.catchs); - } - - public void setFinallyBlock(final BlockStmt finallyBlock) { - this.finallyBlock = finallyBlock; - setAsParentNodeOf(this.finallyBlock); - } - - public void setTryBlock(final BlockStmt tryBlock) { - this.tryBlock = tryBlock; - setAsParentNodeOf(this.tryBlock); - } - - public void setResources(List resources) { - this.resources = resources; - setAsParentNodeOf(this.resources); - } -} +/* + * 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.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.TryStmtMetaModel; +import javax.annotation.Generated; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.function.Consumer; + +/** + *

The try statement

+ *

Java 1.0-6

+ *
+ * try {
+ * // ...
+ * } catch (IOException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * 
+ * In this code, "// do things" is the content of the tryBlock, there is one catch clause that catches IOException e, + * and there is a finally block. + *

+ * The catch and finally blocks are optional, but they should not be empty at the same time. + *

Java 7-8

+ *
+ * try (InputStream i = new FileInputStream("file")) {
+ * // ...
+ * } catch (IOException|NullPointerException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * 
+ * Java 7 introduced two things: + *
    + *
  • Resources can be specified after "try", but only variable declarations (VariableDeclarationExpr.)
  • + *
  • A single catch can catch multiple exception types. This uses the IntersectionType.
  • + *
+ *

Java 9+

+ *
+ * try (r) {
+ * // ...
+ * } catch (IOException|NullPointerException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * 
+ * Java 9 finishes resources: you can now refer to a resource that was declared somewhere else. + * The following types are allowed: + *
    + *
  • VariableDeclarationExpr: "X x = new X()" like in Java 7-8.
  • + *
  • NameExpr: "a".
  • + *
  • FieldAccessExpr: "x.y.z", "super.test" etc.
  • + *
+ * + * @author Julio Vilmar Gesser + * @see CatchClause + * @see com.github.javaparser.ast.type.IntersectionType + * @see com.github.javaparser.ast.expr.FieldAccessExpr + * @see com.github.javaparser.ast.expr.NameExpr + */ +public final class TryStmt extends Statement { + + private NodeList resources; + + private BlockStmt tryBlock; + + private NodeList catchClauses; + + @OptionalProperty + private BlockStmt finallyBlock; + + public TryStmt() { + this(null, new NodeList<>(), new BlockStmt(), new NodeList<>(), null); + } + + public TryStmt(final BlockStmt tryBlock, final NodeList catchClauses, final BlockStmt finallyBlock) { + this(null, new NodeList<>(), tryBlock, catchClauses, finallyBlock); + } + + @AllFieldsConstructor + public TryStmt(NodeList resources, final BlockStmt tryBlock, final NodeList catchClauses, final BlockStmt finallyBlock) { + this(null, resources, tryBlock, catchClauses, finallyBlock); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public TryStmt(TokenRange tokenRange, NodeList resources, BlockStmt tryBlock, NodeList catchClauses, BlockStmt finallyBlock) { + super(tokenRange); + setResources(resources); + setTryBlock(tryBlock); + setCatchClauses(catchClauses); + setFinallyBlock(finallyBlock); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getCatchClauses() { + return catchClauses; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getFinallyBlock() { + return Optional.ofNullable(finallyBlock); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt getTryBlock() { + return tryBlock; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getResources() { + return resources; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TryStmt setCatchClauses(final NodeList catchClauses) { + assertNotNull(catchClauses); + if (catchClauses == this.catchClauses) { + return (TryStmt) this; + } + notifyPropertyChange(ObservableProperty.CATCH_CLAUSES, this.catchClauses, catchClauses); + if (this.catchClauses != null) + this.catchClauses.setParentNode(null); + this.catchClauses = catchClauses; + setAsParentNodeOf(catchClauses); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TryStmt setFinallyBlock(final BlockStmt finallyBlock) { + if (finallyBlock == this.finallyBlock) { + return (TryStmt) this; + } + notifyPropertyChange(ObservableProperty.FINALLY_BLOCK, this.finallyBlock, finallyBlock); + if (this.finallyBlock != null) + this.finallyBlock.setParentNode(null); + this.finallyBlock = finallyBlock; + setAsParentNodeOf(finallyBlock); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TryStmt setTryBlock(final BlockStmt tryBlock) { + assertNotNull(tryBlock); + if (tryBlock == this.tryBlock) { + return (TryStmt) this; + } + notifyPropertyChange(ObservableProperty.TRY_BLOCK, this.tryBlock, tryBlock); + if (this.tryBlock != null) + this.tryBlock.setParentNode(null); + this.tryBlock = tryBlock; + setAsParentNodeOf(tryBlock); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TryStmt setResources(final NodeList resources) { + assertNotNull(resources); + if (resources == this.resources) { + return (TryStmt) this; + } + notifyPropertyChange(ObservableProperty.RESOURCES, this.resources, resources); + if (this.resources != null) + this.resources.setParentNode(null); + this.resources = resources; + setAsParentNodeOf(resources); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < catchClauses.size(); i++) { + if (catchClauses.get(i) == node) { + catchClauses.remove(i); + return true; + } + } + if (finallyBlock != null) { + if (node == finallyBlock) { + removeFinallyBlock(); + return true; + } + } + for (int i = 0; i < resources.size(); i++) { + if (resources.get(i) == node) { + resources.remove(i); + return true; + } + } + return super.remove(node); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public TryStmt removeFinallyBlock() { + return setFinallyBlock((BlockStmt) null); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public TryStmt removeTryBlock() { + return setTryBlock((BlockStmt) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public TryStmt clone() { + return (TryStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public TryStmtMetaModel getMetaModel() { + return JavaParserMetaModel.tryStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < catchClauses.size(); i++) { + if (catchClauses.get(i) == node) { + catchClauses.set(i, (CatchClause) replacementNode); + return true; + } + } + if (finallyBlock != null) { + if (node == finallyBlock) { + setFinallyBlock((BlockStmt) replacementNode); + return true; + } + } + for (int i = 0; i < resources.size(); i++) { + if (resources.get(i) == node) { + resources.set(i, (Expression) replacementNode); + return true; + } + } + if (node == tryBlock) { + setTryBlock((BlockStmt) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTryStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TryStmt asTryStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTryStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTryStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java deleted file mode 100644 index 92988de..0000000 --- a/JavaParser/src/com/github/javaparser/ast/stmt/TypeDeclarationStmt.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class TypeDeclarationStmt extends Statement { - - private TypeDeclaration typeDecl; - - public TypeDeclarationStmt() { - } - - public TypeDeclarationStmt(final TypeDeclaration typeDecl) { - setTypeDeclaration(typeDecl); - } - - public TypeDeclarationStmt(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final TypeDeclaration typeDecl) { - super(beginLine, beginColumn, endLine, endColumn); - setTypeDeclaration(typeDecl); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public TypeDeclaration getTypeDeclaration() { - return typeDecl; - } - - public void setTypeDeclaration(final TypeDeclaration typeDecl) { - this.typeDecl = typeDecl; - setAsParentNodeOf(this.typeDecl); - } -} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/UnparsableStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/UnparsableStmt.java new file mode 100644 index 0000000..2a7fc01 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/stmt/UnparsableStmt.java @@ -0,0 +1,103 @@ +package com.github.javaparser.ast.stmt; + +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.ast.Node; +import javax.annotation.Generated; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.UnparsableStmtMetaModel; +import static com.github.javaparser.ast.Node.Parsedness.*; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A statement that had parse errors. + * Nothing is known about it except the tokens it covers. + */ +public final class UnparsableStmt extends Statement { + + @AllFieldsConstructor + public UnparsableStmt() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public UnparsableStmt(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public UnparsableStmt clone() { + return (UnparsableStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public UnparsableStmtMetaModel getMetaModel() { + return JavaParserMetaModel.unparsableStmtMetaModel; + } + + @Override + public Parsedness getParsed() { + return UNPARSABLE; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnparsableStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnparsableStmt asUnparsableStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnparsableStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnparsableStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/stmt/WhileStmt.java b/JavaParser/src/com/github/javaparser/ast/stmt/WhileStmt.java index 4e86e6a..5fb1f99 100644 --- a/JavaParser/src/com/github/javaparser/ast/stmt/WhileStmt.java +++ b/JavaParser/src/com/github/javaparser/ast/stmt/WhileStmt.java @@ -1,76 +1,181 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.stmt; - -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 WhileStmt extends Statement { - - private Expression condition; - - private Statement body; - - public WhileStmt() { - } - - public WhileStmt(final Expression condition, final Statement body) { - setCondition(condition); - setBody(body); - } - - public WhileStmt(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Expression condition, final Statement body) { - super(beginLine, beginColumn, endLine, endColumn); - setCondition(condition); - setBody(body); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor 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); - } -} +/* + * 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.ast.AllFieldsConstructor; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.nodeTypes.NodeWithBody; +import com.github.javaparser.ast.nodeTypes.NodeWithCondition; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.WhileStmtMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A while statement. + *
while(true) { ... } + * + * @author Julio Vilmar Gesser + */ +public final class WhileStmt extends Statement implements NodeWithBody, NodeWithCondition { + + private Expression condition; + + private Statement body; + + public WhileStmt() { + this(null, new BooleanLiteralExpr(), new ReturnStmt()); + } + + @AllFieldsConstructor + public WhileStmt(final Expression condition, final Statement body) { + this(null, condition, body); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public WhileStmt(TokenRange tokenRange, Expression condition, Statement body) { + super(tokenRange); + setCondition(condition); + setBody(body); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Statement getBody() { + return body; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCondition() { + return condition; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public WhileStmt setBody(final Statement body) { + assertNotNull(body); + if (body == this.body) { + return (WhileStmt) this; + } + notifyPropertyChange(ObservableProperty.BODY, this.body, body); + if (this.body != null) + this.body.setParentNode(null); + this.body = body; + setAsParentNodeOf(body); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public WhileStmt setCondition(final Expression condition) { + assertNotNull(condition); + if (condition == this.condition) { + return (WhileStmt) this; + } + notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition); + if (this.condition != null) + this.condition.setParentNode(null); + this.condition = condition; + setAsParentNodeOf(condition); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public WhileStmt clone() { + return (WhileStmt) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public WhileStmtMetaModel getMetaModel() { + return JavaParserMetaModel.whileStmtMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == body) { + setBody((Statement) replacementNode); + return true; + } + if (node == condition) { + setCondition((Expression) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isWhileStmt() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public WhileStmt asWhileStmt() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWhileStmt(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toWhileStmt() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/ArrayType.java b/JavaParser/src/com/github/javaparser/ast/type/ArrayType.java new file mode 100644 index 0000000..76dba1f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/type/ArrayType.java @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.ArrayTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.resolution.types.ResolvedArrayType; +import com.github.javaparser.utils.Pair; +import javax.annotation.Generated; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.ast.NodeList.nodeList; +import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.function.Consumer; + +/** + * To indicate that a type is an array, it gets wrapped in an ArrayType for every array level it has. + * So, int[][] becomes ArrayType(ArrayType(int)). + */ +public final class ArrayType extends ReferenceType implements NodeWithAnnotations { + + @Override + public ResolvedArrayType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedArrayType.class); + } + + /** + * The origin of a pair of array brackets []. + */ + public enum Origin { + + /** + * The [] were found on the name, like "int a[]" or "String abc()[][]" + */ + NAME, + /** + * The [] were found on the type, like "int[] a" or "String[][] abc()" + */ + TYPE + } + + private Type componentType; + + private Origin origin; + + @AllFieldsConstructor + public ArrayType(Type componentType, Origin origin, NodeList annotations) { + this(null, componentType, origin, annotations); + } + + public ArrayType(Type type, AnnotationExpr... annotations) { + this(type, Origin.TYPE, nodeList(annotations)); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ArrayType(TokenRange tokenRange, Type componentType, Origin origin, NodeList annotations) { + super(tokenRange, annotations); + setComponentType(componentType); + setOrigin(origin); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type getComponentType() { + return componentType; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayType setComponentType(final Type componentType) { + assertNotNull(componentType); + if (componentType == this.componentType) { + return (ArrayType) this; + } + notifyPropertyChange(ObservableProperty.COMPONENT_TYPE, this.componentType, componentType); + if (this.componentType != null) + this.componentType.setParentNode(null); + this.componentType = componentType; + setAsParentNodeOf(componentType); + return this; + } + + /** + * Takes lists of arrayBracketPairs, assumes the lists are ordered left to right and the pairs are ordered left to + * right, mirroring the actual code. The type gets wrapped in ArrayTypes so that the outermost ArrayType corresponds + * to the rightmost ArrayBracketPair. + */ + @SafeVarargs + public static Type wrapInArrayTypes(Type type, List... arrayBracketPairLists) { + for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) { + final List arrayBracketPairList = arrayBracketPairLists[i]; + if (arrayBracketPairList != null) { + for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) { + ArrayBracketPair pair = arrayBracketPairList.get(j); + TokenRange tokenRange = null; + if (type.getTokenRange().isPresent() && pair.getTokenRange().isPresent()) { + tokenRange = new TokenRange(type.getTokenRange().get().getBegin(), pair.getTokenRange().get().getEnd()); + } + type = new ArrayType(tokenRange, type, pair.getOrigin(), pair.getAnnotations()); + if (tokenRange != null) { + type.setRange(tokenRange.toRange().get()); + } + } + } + } + return type; + } + + /** + * Takes a type that may be an ArrayType. Unwraps ArrayTypes until the element type is found. + * + * @return a pair of the element type, and the unwrapped ArrayTypes, if any. + */ + public static Pair> unwrapArrayTypes(Type type) { + final List arrayBracketPairs = new ArrayList<>(0); + while (type instanceof ArrayType) { + ArrayType arrayType = (ArrayType) type; + arrayBracketPairs.add(new ArrayBracketPair(type.getTokenRange().orElse(null), arrayType.getOrigin(), arrayType.getAnnotations())); + type = arrayType.getComponentType(); + } + return new Pair<>(type, arrayBracketPairs); + } + + /** + * Helper class that stores information about a pair of brackets in a non-recursive way + * (unlike ArrayType.) + */ + public static class ArrayBracketPair { + + private TokenRange tokenRange; + + private NodeList annotations = new NodeList<>(); + + private Origin origin; + + public ArrayBracketPair(TokenRange tokenRange, Origin origin, NodeList annotations) { + setTokenRange(tokenRange); + setAnnotations(annotations); + setOrigin(origin); + } + + public NodeList getAnnotations() { + return annotations; + } + + public ArrayBracketPair setAnnotations(NodeList annotations) { + this.annotations = assertNotNull(annotations); + return this; + } + + public ArrayBracketPair setTokenRange(TokenRange range) { + this.tokenRange = range; + return this; + } + + public Optional getTokenRange() { + return Optional.ofNullable(tokenRange); + } + + public Origin getOrigin() { + return origin; + } + + public ArrayBracketPair setOrigin(Origin origin) { + this.origin = assertNotNull(origin); + return this; + } + } + + @Override + public ArrayType setAnnotations(NodeList annotations) { + return (ArrayType) super.setAnnotations(annotations); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Origin getOrigin() { + return origin; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayType setOrigin(final Origin origin) { + assertNotNull(origin); + if (origin == this.origin) { + return (ArrayType) this; + } + notifyPropertyChange(ObservableProperty.ORIGIN, this.origin, origin); + this.origin = origin; + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + public String asString() { + return componentType.asString() + "[]"; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ArrayType clone() { + return (ArrayType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ArrayTypeMetaModel getMetaModel() { + return JavaParserMetaModel.arrayTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == componentType) { + setComponentType((Type) replacementNode); + return true; + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayType asArrayType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayType(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/JavaParser/src/com/github/javaparser/ast/type/ClassOrInterfaceType.java index 853e559..f3b6846 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/ClassOrInterfaceType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -1,93 +1,302 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.NamedNode; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ClassOrInterfaceType extends Type { - - private ClassOrInterfaceType scope; - - private String name; - - private List typeArgs; - - public ClassOrInterfaceType() { - } - - public ClassOrInterfaceType(final String name) { - setName(name); - } - - public ClassOrInterfaceType(final ClassOrInterfaceType scope, final String name) { - setScope(scope); - setName(name); - } - - public ClassOrInterfaceType(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final ClassOrInterfaceType scope, final String name, final List typeArgs) { - super(beginLine, beginColumn, endLine, endColumn); - setScope(scope); - setName(name); - setTypeArgs(typeArgs); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public String getName() { - return name; - } - - public ClassOrInterfaceType getScope() { - return scope; - } - - public List getTypeArgs() { - return typeArgs; - } - - public void setName(final String name) { - this.name = name; - } - - public void setScope(final ClassOrInterfaceType scope) { - this.scope = scope; - setAsParentNodeOf(this.scope); - } - - public void setTypeArgs(final List typeArgs) { - this.typeArgs = typeArgs; - setAsParentNodeOf(this.typeArgs); - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.ClassOrInterfaceTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import java.util.function.Consumer; + +/** + * A class or an interface type.
Object
HashMap<String, String> + *
java.util.Punchcard + *

+ *

Note that the syntax is ambiguous here, and JavaParser does not know what is to the left of the class. It assumes + * cases like Map.Entry where Map is the scope of Entry. In java.util.Punchcard, it will not + * recognize that java and util are parts of the package name. Instead, it will set util as the scope of Punchcard, as a + * ClassOrInterfaceType (which it is not.) In turn, util will have java as its scope, also as a + * ClassOrInterfaceType

+ * + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceType extends ReferenceType implements NodeWithSimpleName, NodeWithAnnotations, NodeWithTypeArguments { + + @OptionalProperty + private ClassOrInterfaceType scope; + + private SimpleName name; + + @OptionalProperty + private NodeList typeArguments; + + public ClassOrInterfaceType() { + this(null, null, new SimpleName(), null, new NodeList<>()); + } + + /** + * @deprecated use JavaParser.parseClassOrInterfaceType instead. This constructor does not understand generics. + */ + public ClassOrInterfaceType(final String name) { + this(null, null, new SimpleName(name), null, new NodeList<>()); + } + + public ClassOrInterfaceType(final ClassOrInterfaceType scope, final String name) { + this(null, scope, new SimpleName(name), null, new NodeList<>()); + } + + public ClassOrInterfaceType(final ClassOrInterfaceType scope, final SimpleName name, final NodeList typeArguments) { + this(null, scope, name, typeArguments, new NodeList<>()); + } + + @AllFieldsConstructor + public ClassOrInterfaceType(final ClassOrInterfaceType scope, final SimpleName name, final NodeList typeArguments, final NodeList annotations) { + this(null, scope, name, typeArguments, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ClassOrInterfaceType(TokenRange tokenRange, ClassOrInterfaceType scope, SimpleName name, NodeList typeArguments, NodeList annotations) { + super(tokenRange, annotations); + setScope(scope); + setName(name); + setTypeArguments(typeArguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getScope() { + return Optional.ofNullable(scope); + } + + public boolean isBoxedType() { + return PrimitiveType.unboxMap.containsKey(name.getIdentifier()); + } + + public PrimitiveType toUnboxedType() throws UnsupportedOperationException { + if (!isBoxedType()) { + throw new UnsupportedOperationException(name + " isn't a boxed type."); + } + return new PrimitiveType(PrimitiveType.unboxMap.get(name.getIdentifier())); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceType setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (ClassOrInterfaceType) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + /** + * Sets the scope + * + * @param scope the scope, can be null + * @return this, the ClassOrInterfaceType + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceType setScope(final ClassOrInterfaceType scope) { + if (scope == this.scope) { + return (ClassOrInterfaceType) this; + } + notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope); + if (this.scope != null) + this.scope.setParentNode(null); + this.scope = scope; + setAsParentNodeOf(scope); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional> getTypeArguments() { + return Optional.ofNullable(typeArguments); + } + + /** + * Sets the typeArguments + * + * @param typeArguments the typeArguments, can be null + * @return this, the ClassOrInterfaceType + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceType setTypeArguments(final NodeList typeArguments) { + if (typeArguments == this.typeArguments) { + return (ClassOrInterfaceType) this; + } + notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments); + if (this.typeArguments != null) + this.typeArguments.setParentNode(null); + this.typeArguments = typeArguments; + setAsParentNodeOf(typeArguments); + return this; + } + + @Override + public ClassOrInterfaceType setAnnotations(NodeList annotations) { + return (ClassOrInterfaceType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (scope != null) { + if (node == scope) { + removeScope(); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.remove(i); + return true; + } + } + } + return super.remove(node); + } + + @Override + public String asString() { + StringBuilder str = new StringBuilder(); + getScope().ifPresent(s -> str.append(s.asString()).append(".")); + str.append(name.asString()); + getTypeArguments().ifPresent(ta -> str.append(ta.stream().map(Type::asString).collect(joining(",", "<", ">")))); + return str.toString(); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public ClassOrInterfaceType removeScope() { + return setScope((ClassOrInterfaceType) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ClassOrInterfaceType clone() { + return (ClassOrInterfaceType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ClassOrInterfaceTypeMetaModel getMetaModel() { + return JavaParserMetaModel.classOrInterfaceTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (scope != null) { + if (node == scope) { + setScope((ClassOrInterfaceType) replacementNode); + return true; + } + } + if (typeArguments != null) { + for (int i = 0; i < typeArguments.size(); i++) { + if (typeArguments.get(i) == node) { + typeArguments.set(i, (Type) replacementNode); + return true; + } + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassOrInterfaceType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassOrInterfaceType asClassOrInterfaceType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedReferenceType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedReferenceType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassOrInterfaceType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/IntersectionType.java b/JavaParser/src/com/github/javaparser/ast/type/IntersectionType.java new file mode 100644 index 0000000..6b1056b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/type/IntersectionType.java @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.IntersectionTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.NonEmptyProperty; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedIntersectionType; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Represents a set of types. A given value of this type has to be assignable to at all of the element types. + * As of Java 8 it is used in casts or while expressing bounds for generic types. + *

+ * For example: + * public class A<T extends Serializable & Cloneable> { } + *

+ * Or: + * void foo((Serializable & Cloneable)myObject); + * + * @since 3.0.0 + */ +public final class IntersectionType extends Type implements NodeWithAnnotations { + + @NonEmptyProperty + private NodeList elements; + + @AllFieldsConstructor + public IntersectionType(NodeList elements) { + this(null, elements); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public IntersectionType(TokenRange tokenRange, NodeList elements) { + super(tokenRange); + setElements(elements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getElements() { + return elements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public IntersectionType setElements(final NodeList elements) { + assertNotNull(elements); + if (elements == this.elements) { + return (IntersectionType) this; + } + notifyPropertyChange(ObservableProperty.ELEMENTS, this.elements, elements); + if (this.elements != null) + this.elements.setParentNode(null); + this.elements = elements; + setAsParentNodeOf(elements); + return this; + } + + @Override + public IntersectionType setAnnotations(NodeList annotations) { + return (IntersectionType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < elements.size(); i++) { + if (elements.get(i) == node) { + elements.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + public String asString() { + return elements.stream().map(Type::asString).collect(joining("&")); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public IntersectionType clone() { + return (IntersectionType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public IntersectionTypeMetaModel getMetaModel() { + return JavaParserMetaModel.intersectionTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < elements.size(); i++) { + if (elements.get(i) == node) { + elements.set(i, (ReferenceType) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIntersectionType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IntersectionType asIntersectionType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntersectionType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedIntersectionType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedIntersectionType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIntersectionType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/PrimitiveType.java b/JavaParser/src/com/github/javaparser/ast/type/PrimitiveType.java index 397b363..e359b7f 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/PrimitiveType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/PrimitiveType.java @@ -1,66 +1,247 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class PrimitiveType extends Type { - - public enum Primitive { - Boolean, Char, Byte, Short, Int, Long, Float, Double - } - - private Primitive type; - - public PrimitiveType() { - } - - public PrimitiveType(final Primitive type) { - this.type = type; - } - - public PrimitiveType(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Primitive type) { - super(beginLine, beginColumn, endLine, endColumn); - this.type = type; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public Primitive getType() { - return type; - } - - public void setType(final Primitive type) { - this.type = type; - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import static com.github.javaparser.JavaParser.parseClassOrInterfaceType; +import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.PrimitiveTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedPrimitiveType; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A primitive type. + *
int + *
boolean + *
short + * + * @author Julio Vilmar Gesser + */ +public final class PrimitiveType extends Type implements NodeWithAnnotations { + + public static PrimitiveType booleanType() { + return new PrimitiveType(Primitive.BOOLEAN); + } + + public static PrimitiveType charType() { + return new PrimitiveType(Primitive.CHAR); + } + + public static PrimitiveType byteType() { + return new PrimitiveType(Primitive.BYTE); + } + + public static PrimitiveType shortType() { + return new PrimitiveType(Primitive.SHORT); + } + + public static PrimitiveType intType() { + return new PrimitiveType(Primitive.INT); + } + + public static PrimitiveType longType() { + return new PrimitiveType(Primitive.LONG); + } + + public static PrimitiveType floatType() { + return new PrimitiveType(Primitive.FLOAT); + } + + public static PrimitiveType doubleType() { + return new PrimitiveType(Primitive.DOUBLE); + } + + public enum Primitive { + + BOOLEAN("Boolean"), + CHAR("Character"), + BYTE("Byte"), + SHORT("Short"), + INT("Integer"), + LONG("Long"), + FLOAT("Float"), + DOUBLE("Double"); + + final String nameOfBoxedType; + + private String codeRepresentation; + + public ClassOrInterfaceType toBoxedType() { + return parseClassOrInterfaceType(nameOfBoxedType); + } + + public String asString() { + return codeRepresentation; + } + + Primitive(String nameOfBoxedType) { + this.nameOfBoxedType = nameOfBoxedType; + this.codeRepresentation = name().toLowerCase(); + } + } + + static final HashMap unboxMap = new HashMap<>(); + + static { + for (Primitive unboxedType : Primitive.values()) { + unboxMap.put(unboxedType.nameOfBoxedType, unboxedType); + } + } + + private Primitive type; + + public PrimitiveType() { + this(null, Primitive.INT, new NodeList<>()); + } + + public PrimitiveType(final Primitive type) { + this(null, type, new NodeList<>()); + } + + @AllFieldsConstructor + public PrimitiveType(final Primitive type, NodeList annotations) { + this(null, type, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public PrimitiveType(TokenRange tokenRange, Primitive type, NodeList annotations) { + super(tokenRange, annotations); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Primitive getType() { + return type; + } + + public ClassOrInterfaceType toBoxedType() { + return type.toBoxedType(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public PrimitiveType setType(final Primitive type) { + assertNotNull(type); + if (type == this.type) { + return (PrimitiveType) this; + } + notifyPropertyChange(ObservableProperty.TYPE, this.type, type); + this.type = type; + return this; + } + + @Override + public String asString() { + return type.asString(); + } + + @Override + public PrimitiveType setAnnotations(NodeList annotations) { + return (PrimitiveType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public PrimitiveType clone() { + return (PrimitiveType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public PrimitiveTypeMetaModel getMetaModel() { + return JavaParserMetaModel.primitiveTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isPrimitiveType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public PrimitiveType asPrimitiveType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifPrimitiveType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedPrimitiveType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedPrimitiveType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toPrimitiveType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/ReferenceType.java b/JavaParser/src/com/github/javaparser/ast/type/ReferenceType.java index 19a11dd..f39ee0e 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/ReferenceType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/ReferenceType.java @@ -1,124 +1,110 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public final class ReferenceType extends Type { - - private Type type; - - private int arrayCount; - - private List> arraysAnnotations; - - public ReferenceType() { - } - - public ReferenceType(final Type type) { - setType(type); - } - - public ReferenceType(final Type type, final int arrayCount) { - setType(type); - setArrayCount(arrayCount); - } - - public ReferenceType(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final Type type, final int arrayCount) { - super(beginLine, beginColumn, endLine, endColumn); - setType(type); - setArrayCount(arrayCount); - } - - public ReferenceType(int beginLine, int beginColumn, int endLine, - int endColumn, Type type, int arrayCount, - List annotations, - List> arraysAnnotations) { - super(beginLine, beginColumn, endLine, endColumn, annotations); - setType(type); - setArrayCount(arrayCount); - this.arraysAnnotations = arraysAnnotations; - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public int getArrayCount() { - return arrayCount; - } - - public Type getType() { - return type; - } - - public void setArrayCount(final int arrayCount) { - this.arrayCount = arrayCount; - } - - public void setType(final Type type) { - this.type = type; - setAsParentNodeOf(this.type); - } - - /** - *

Arrays annotations are annotations on the arrays modifiers of the type. - * Consider this example:

- * - *

-	 * {@code
-	 * int @Ann1 [] @Ann2 [] array;
-	 * }

- * - *

in this this method will return a list with the annotation expressions

@Ann1
- * and
@Ann2

- * - *

Note that the first list element of arraysAnnotations will refer to the first array modifier encountered. - * Considering the example the first element will be a list containing just @Ann1 while the second element will - * be a list containing just @Ann2. - *

- * - *

This property is guaranteed to hold:

{@code getArraysAnnotations().size() == getArrayCount()}
- * If a certain array modifier has no annotation the corresponding entry of arraysAnnotations will be null

- */ - public List> getArraysAnnotations() { - return arraysAnnotations; - } - - /** - * For a description of the arrayAnnotations field refer to {@link #getArraysAnnotations()} - */ - public void setArraysAnnotations(List> arraysAnnotations) { - this.arraysAnnotations = arraysAnnotations; - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ReferenceTypeMetaModel; +import javax.annotation.Generated; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * Base class for reference types. + * + * @author Julio Vilmar Gesser + */ +public abstract class ReferenceType extends Type { + + public ReferenceType() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public ReferenceType(NodeList annotations) { + this(null, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public ReferenceType(TokenRange tokenRange, NodeList annotations) { + super(tokenRange, annotations); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public ReferenceType clone() { + return (ReferenceType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public ReferenceTypeMetaModel getMetaModel() { + return JavaParserMetaModel.referenceTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isReferenceType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ReferenceType asReferenceType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReferenceType(Consumer action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toReferenceType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/Type.java b/JavaParser/src/com/github/javaparser/ast/type/Type.java index e03a945..acaf5a9 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/Type.java +++ b/JavaParser/src/com/github/javaparser/ast/type/Type.java @@ -1,59 +1,371 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.AnnotationExpr; - -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class Type extends Node { - - private List annotations; - - public Type() { - } - - public Type(List annotation){ - this.annotations = annotation; - } - - public Type(int beginLine, int beginColumn, int endLine, int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - - public Type(int beginLine, int beginColumn, int endLine, int endColumn, List annotations) { - super(beginLine, beginColumn, endLine, endColumn); - this.annotations = annotations; - } - - public List getAnnotations() { - return annotations; - } - - public void setAnnotations(List annotations) { - this.annotations = annotations; - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.DataKey; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.TypeMetaModel; +import static com.github.javaparser.utils.Utils.assertNotNull; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.Resolvable; +import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.resolution.types.ResolvedType; +import java.util.function.Consumer; +import java.util.function.Supplier; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import java.util.Optional; + +/** + * Base class for types. + * + * @author Julio Vilmar Gesser + */ +public abstract class Type extends Node implements Resolvable { + + private NodeList annotations; + + /** + * Several sub classes do not support annotations. + * This is a support constructor for them. + */ + protected Type(TokenRange range) { + this(range, new NodeList<>()); + } + + @AllFieldsConstructor + public Type(NodeList annotations) { + this(null, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public Type(TokenRange tokenRange, NodeList annotations) { + super(tokenRange); + setAnnotations(annotations); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getAnnotations() { + return annotations; + } + + public AnnotationExpr getAnnotation(int i) { + return getAnnotations().get(i); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Type setAnnotations(final NodeList annotations) { + assertNotNull(annotations); + if (annotations == this.annotations) { + return (Type) this; + } + notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations); + if (this.annotations != null) + this.annotations.setParentNode(null); + this.annotations = annotations; + setAsParentNodeOf(annotations); + return this; + } + + /** + * Finds the element type, meaning: the type without ArrayTypes around it. + *

+ * In "int[] a[];", the element type is int. + */ + public Type getElementType() { + if (this instanceof ArrayType) { + return ((ArrayType) this).getComponentType().getElementType(); + } + return this; + } + + public int getArrayLevel() { + if (this instanceof ArrayType) { + return 1 + ((ArrayType) this).getComponentType().getArrayLevel(); + } else { + return 0; + } + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.remove(i); + return true; + } + } + return super.remove(node); + } + + public abstract String asString(); + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public Type clone() { + return (Type) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public TypeMetaModel getMetaModel() { + return JavaParserMetaModel.typeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < annotations.size(); i++) { + if (annotations.get(i) == node) { + annotations.set(i, (AnnotationExpr) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isArrayType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ArrayType asArrayType() { + throw new IllegalStateException(f("%s is not an ArrayType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isClassOrInterfaceType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ClassOrInterfaceType asClassOrInterfaceType() { + throw new IllegalStateException(f("%s is not an ClassOrInterfaceType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isIntersectionType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public IntersectionType asIntersectionType() { + throw new IllegalStateException(f("%s is not an IntersectionType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isPrimitiveType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public PrimitiveType asPrimitiveType() { + throw new IllegalStateException(f("%s is not an PrimitiveType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isReferenceType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public ReferenceType asReferenceType() { + throw new IllegalStateException(f("%s is not an ReferenceType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeParameter() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeParameter asTypeParameter() { + throw new IllegalStateException(f("%s is not an TypeParameter", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnionType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnionType asUnionType() { + throw new IllegalStateException(f("%s is not an UnionType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnknownType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnknownType asUnknownType() { + throw new IllegalStateException(f("%s is not an UnknownType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVoidType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VoidType asVoidType() { + throw new IllegalStateException(f("%s is not an VoidType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isWildcardType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public WildcardType asWildcardType() { + throw new IllegalStateException(f("%s is not an WildcardType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntersectionType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifPrimitiveType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReferenceType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeParameter(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnionType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnknownType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVoidType(Consumer action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWildcardType(Consumer action) { + } + + @Override + public abstract ResolvedType resolve(); + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toArrayType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toClassOrInterfaceType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toIntersectionType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toPrimitiveType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toReferenceType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeParameter() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnionType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnknownType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVoidType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toWildcardType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVarType() { + return false; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VarType asVarType() { + throw new IllegalStateException(f("%s is not an VarType", this)); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVarType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVarType(Consumer action) { + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/TypeParameter.java b/JavaParser/src/com/github/javaparser/ast/type/TypeParameter.java new file mode 100644 index 0000000..c3f8ced --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/type/TypeParameter.java @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.Range; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.TypeParameterMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.ResolvedTypeVariable; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * A type parameter. + *
<U> U getU() { ... } + *
class D <@Brain T extends B & A & @Tripe C> { ... } + *

U and T are type parameter names. + *
B, A, and C are type parameter bounds. + *
Tripe is an annotation on type parameter bound C. + *
Brain is an annotation on type parameter T. + * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters + */ +public final class TypeParameter extends ReferenceType implements NodeWithSimpleName, NodeWithAnnotations { + + private SimpleName name; + + private NodeList typeBound; + + public TypeParameter() { + this(null, new SimpleName(), new NodeList<>(), new NodeList<>()); + } + + public TypeParameter(final String name) { + this(null, new SimpleName(name), new NodeList<>(), new NodeList<>()); + } + + public TypeParameter(final String name, final NodeList typeBound) { + this(null, new SimpleName(name), typeBound, new NodeList<>()); + } + + /** + * @deprecated range shouldn't be in utility constructors. + */ + @Deprecated + public TypeParameter(Range range, final SimpleName name, final NodeList typeBound) { + this(null, name, typeBound, new NodeList<>()); + setRange(range); + } + + @AllFieldsConstructor + public TypeParameter(SimpleName name, NodeList typeBound, NodeList annotations) { + this(null, name, typeBound, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public TypeParameter(TokenRange tokenRange, SimpleName name, NodeList typeBound, NodeList annotations) { + super(tokenRange, annotations); + setName(name); + setTypeBound(typeBound); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + /** + * Return the name of the paramenter. + * + * @return the name of the paramenter + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + /** + * Return the list of {@link ClassOrInterfaceType} that this parameter + * extends. Return null null if there are no type. + * + * @return list of types that this paramente extends or null + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getTypeBound() { + return typeBound; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TypeParameter setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return (TypeParameter) this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TypeParameter setTypeBound(final NodeList typeBound) { + assertNotNull(typeBound); + if (typeBound == this.typeBound) { + return (TypeParameter) this; + } + notifyPropertyChange(ObservableProperty.TYPE_BOUND, this.typeBound, typeBound); + if (this.typeBound != null) + this.typeBound.setParentNode(null); + this.typeBound = typeBound; + setAsParentNodeOf(typeBound); + return this; + } + + @Override + public TypeParameter setAnnotations(NodeList annotations) { + super.setAnnotations(annotations); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < typeBound.size(); i++) { + if (typeBound.get(i) == node) { + typeBound.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + public String asString() { + StringBuilder str = new StringBuilder(getNameAsString()); + getTypeBound().ifNonEmpty(l -> str.append(l.stream().map(ClassOrInterfaceType::asString).collect(joining("&", " extends ", "")))); + return str.toString(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public TypeParameter clone() { + return (TypeParameter) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public TypeParameterMetaModel getMetaModel() { + return JavaParserMetaModel.typeParameterMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + for (int i = 0; i < typeBound.size(); i++) { + if (typeBound.get(i) == node) { + typeBound.set(i, (ClassOrInterfaceType) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isTypeParameter() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public TypeParameter asTypeParameter() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeParameter(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedTypeVariable resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedTypeVariable.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toTypeParameter() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/UnionType.java b/JavaParser/src/com/github/javaparser/ast/type/UnionType.java new file mode 100644 index 0000000..5fa78f1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/type/UnionType.java @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.NonEmptyProperty; +import com.github.javaparser.metamodel.UnionTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import com.github.javaparser.resolution.types.ResolvedUnionType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + *

The union type

+ * Represents a set of types. A given value of this type has to be assignable to at least one of the element types. + *

Java 1-6

+ * Does not exist. + *

Java 7+

+ * As of Java 7 it is used in catch clauses. + *

+ * try {
+ * ...
+ * } catch(IOException | NullPointerException ex) {
+ * ...
+ * }
+ * 
+ * + * The types that make up the union type are its "elements" + */ +public final class UnionType extends Type implements NodeWithAnnotations { + + @NonEmptyProperty + private NodeList elements; + + public UnionType() { + this(null, new NodeList<>()); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public UnionType(TokenRange tokenRange, NodeList elements) { + super(tokenRange); + setElements(elements); + customInitialization(); + } + + @AllFieldsConstructor + public UnionType(NodeList elements) { + this(null, elements); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getElements() { + return elements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public UnionType setElements(final NodeList elements) { + assertNotNull(elements); + if (elements == this.elements) { + return (UnionType) this; + } + notifyPropertyChange(ObservableProperty.ELEMENTS, this.elements, elements); + if (this.elements != null) + this.elements.setParentNode(null); + this.elements = elements; + setAsParentNodeOf(elements); + return this; + } + + @Override + public UnionType setAnnotations(NodeList annotations) { + return (UnionType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + for (int i = 0; i < elements.size(); i++) { + if (elements.get(i) == node) { + elements.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + public String asString() { + return elements.stream().map(Type::asString).collect(joining("|")); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public UnionType clone() { + return (UnionType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public UnionTypeMetaModel getMetaModel() { + return JavaParserMetaModel.unionTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + for (int i = 0; i < elements.size(); i++) { + if (elements.get(i) == node) { + elements.set(i, (ReferenceType) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnionType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnionType asUnionType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnionType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedUnionType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedUnionType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnionType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/UnknownType.java b/JavaParser/src/com/github/javaparser/ast/type/UnknownType.java index dbab89e..d415214 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/UnknownType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/UnknownType.java @@ -1,47 +1,147 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * An unknown parameter type object. It plays the role of a null object for - * lambda parameters that have no explicit type declared. As such, it has no - * lexical representation and hence gets no comment attributed. - * - * @author Didier Villevalois - */ -public final class UnknownType extends Type { - - public UnknownType() { - } - - @Override - public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override - public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.UnknownTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.ResolvedUnionType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * An unknown parameter type object. It plays the role of a null object for + * lambda parameters that have no explicit type declared. As such, it has no + * lexical representation and hence gets no comment attributed. + *

+ *
In DoubleToIntFunction d = x -> (int)x + 1; the x parameter in bold has type UnknownType. + * + * @author Didier Villevalois + */ +public final class UnknownType extends Type { + + @AllFieldsConstructor + public UnknownType() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public UnknownType(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + public UnknownType setAnnotations(NodeList annotations) { + if (annotations.size() > 0) { + throw new IllegalStateException("Inferred lambda types cannot be annotated."); + } + return (UnknownType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + public String asString() { + return ""; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public UnknownType clone() { + return (UnknownType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public UnknownTypeMetaModel getMetaModel() { + return JavaParserMetaModel.unknownTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isUnknownType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public UnknownType asUnknownType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnknownType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedReferenceType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toUnknownType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/VarType.java b/JavaParser/src/com/github/javaparser/ast/type/VarType.java new file mode 100644 index 0000000..3755c2f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/type/VarType.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.VoidTypeMetaModel; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.ResolvedVoidType; +import javax.annotation.Generated; +import java.util.Optional; +import java.util.function.Consumer; +import com.github.javaparser.metamodel.VarTypeMetaModel; + +public final class VarType extends Type { + + @AllFieldsConstructor + public VarType() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public VarType(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + public VarType setAnnotations(NodeList annotations) { + return (VarType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + public String asString() { + return "var"; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public VarType clone() { + return (VarType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public VarTypeMetaModel getMetaModel() { + return JavaParserMetaModel.varTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + public ResolvedType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVarType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VarType asVarType() { + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVarType() { + return Optional.of(this); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVarType(Consumer action) { + action.accept(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/VoidType.java b/JavaParser/src/com/github/javaparser/ast/type/VoidType.java index 61a5c01..860a9d6 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/VoidType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/VoidType.java @@ -1,46 +1,142 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class VoidType extends Type { - - public VoidType() { - } - - public VoidType(final int beginLine, final int beginColumn, final int endLine, final int endColumn) { - super(beginLine, beginColumn, endLine, endColumn); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Arrays; +import java.util.List; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.VoidTypeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedUnionType; +import com.github.javaparser.resolution.types.ResolvedVoidType; +import java.util.function.Consumer; +import java.util.Optional; + +/** + * The return type of a {@link com.github.javaparser.ast.body.MethodDeclaration} + * when it returns void. + *
void helloWorld() { ... } + * + * @author Julio Vilmar Gesser + */ +public final class VoidType extends Type implements NodeWithAnnotations { + + @AllFieldsConstructor + public VoidType() { + this(null); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public VoidType(TokenRange tokenRange) { + super(tokenRange); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Override + public VoidType setAnnotations(NodeList annotations) { + return (VoidType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + return super.remove(node); + } + + @Override + public String asString() { + return "void"; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public VoidType clone() { + return (VoidType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public VoidTypeMetaModel getMetaModel() { + return JavaParserMetaModel.voidTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isVoidType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public VoidType asVoidType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVoidType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedVoidType resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedVoidType.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toVoidType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/type/WildcardType.java b/JavaParser/src/com/github/javaparser/ast/type/WildcardType.java index 8f8a65d..e37842e 100644 --- a/JavaParser/src/com/github/javaparser/ast/type/WildcardType.java +++ b/JavaParser/src/com/github/javaparser/ast/type/WildcardType.java @@ -1,80 +1,307 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.type; - -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; - -/** - * @author Julio Vilmar Gesser - */ -public final class WildcardType extends Type { - - private ReferenceType ext; - - private ReferenceType sup; - - public WildcardType() { - } - - public WildcardType(final ReferenceType ext) { - setExtends(ext); - } - - public WildcardType(final ReferenceType ext, final ReferenceType sup) { - setExtends(ext); - setSuper(sup); - } - - public WildcardType(final int beginLine, final int beginColumn, final int endLine, final int endColumn, - final ReferenceType ext, final ReferenceType sup) { - super(beginLine, beginColumn, endLine, endColumn); - setExtends(ext); - setSuper(sup); - } - - @Override public R accept(final GenericVisitor v, final A arg) { - return v.visit(this, arg); - } - - @Override public void accept(final VoidVisitor v, final A arg) { - v.visit(this, arg); - } - - public ReferenceType getExtends() { - return ext; - } - - public ReferenceType getSuper() { - return sup; - } - - public void setExtends(final ReferenceType ext) { - this.ext = ext; - setAsParentNodeOf(this.ext); - } - - public void setSuper(final ReferenceType sup) { - this.sup = sup; - setAsParentNodeOf(this.sup); - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.type; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.metamodel.WildcardTypeMetaModel; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import com.github.javaparser.TokenRange; +import com.github.javaparser.resolution.types.ResolvedUnionType; +import com.github.javaparser.resolution.types.ResolvedWildcard; +import java.util.function.Consumer; + +/** + * A wildcard type argument. + *
void printCollection(Collection<?> c) { ... } + *
boolean addAll(Collection<? extends E> c) + *
Reference(T referent, ReferenceQueue<? super T> queue) + * + * @author Julio Vilmar Gesser + */ +public final class WildcardType extends Type implements NodeWithAnnotations { + + @OptionalProperty + private ReferenceType extendedType; + + @OptionalProperty + private ReferenceType superType; + + public WildcardType() { + this(null, null, null, new NodeList<>()); + } + + public WildcardType(final ReferenceType extendedType) { + this(null, extendedType, null, new NodeList<>()); + } + + @AllFieldsConstructor + public WildcardType(final ReferenceType extendedType, final ReferenceType superType, final NodeList annotations) { + this(null, extendedType, superType, annotations); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public WildcardType(TokenRange tokenRange, ReferenceType extendedType, ReferenceType superType, NodeList annotations) { + super(tokenRange, annotations); + setExtendedType(extendedType); + setSuperType(superType); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public
void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getExtendedType() { + return Optional.ofNullable(extendedType); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getSuperType() { + return Optional.ofNullable(superType); + } + + /** + * @deprecated use getExtendedType instead. + */ + @Deprecated + public Optional getExtendedTypes() { + return getExtendedType(); + } + + /** + * @deprecated use getSuperType instead. + */ + @Deprecated + public Optional getSuperTypes() { + return getSuperType(); + } + + /** + * Sets the extended type + * + * @param extendedType the extends, can be null + * @return this, the WildcardType + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public WildcardType setExtendedType(final ReferenceType extendedType) { + if (extendedType == this.extendedType) { + return (WildcardType) this; + } + notifyPropertyChange(ObservableProperty.EXTENDED_TYPE, this.extendedType, extendedType); + if (this.extendedType != null) + this.extendedType.setParentNode(null); + this.extendedType = extendedType; + setAsParentNodeOf(extendedType); + return this; + } + + /** + * Sets the extended type + * + * @param extendedType the extends, can be null + * @return this, the WildcardType + * @deprecated use setExtendedType instead, + */ + @Deprecated + public WildcardType setExtendedTypes(final ReferenceType extendedType) { + return setExtendedType(extendedType); + } + + /** + * Sets the supertype + * + * @param superType the super, can be null + * @return this, the WildcardType + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public WildcardType setSuperType(final ReferenceType superType) { + if (superType == this.superType) { + return (WildcardType) this; + } + notifyPropertyChange(ObservableProperty.SUPER_TYPE, this.superType, superType); + if (this.superType != null) + this.superType.setParentNode(null); + this.superType = superType; + setAsParentNodeOf(superType); + return this; + } + + /** + * Sets the supertype + * + * @param superType the super, can be null + * @return this, the WildcardType + * @deprecated use setSuperType instead + */ + @Deprecated + public WildcardType setSuperTypes(final ReferenceType superType) { + return setSuperType(superType); + } + + @Override + public WildcardType setAnnotations(NodeList annotations) { + return (WildcardType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) + return false; + if (extendedType != null) { + if (node == extendedType) { + removeExtendedType(); + return true; + } + } + if (superType != null) { + if (node == superType) { + removeSuperType(); + return true; + } + } + return super.remove(node); + } + + @Override + public String asString() { + StringBuilder str = new StringBuilder("?"); + getExtendedType().ifPresent(t -> str.append(" extends ").append(t.asString())); + getSuperType().ifPresent(t -> str.append(" super ").append(t.asString())); + return str.toString(); + } + + @Deprecated + public WildcardType removeExtendedTypes() { + return removeExtendedType(); + } + + @Deprecated + public WildcardType removeSuperTypes() { + return removeSuperType(); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public WildcardType removeExtendedType() { + return setExtendedType((ReferenceType) null); + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public WildcardType removeSuperType() { + return setSuperType((ReferenceType) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public WildcardType clone() { + return (WildcardType) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public WildcardTypeMetaModel getMetaModel() { + return JavaParserMetaModel.wildcardTypeMetaModel; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) + return false; + if (extendedType != null) { + if (node == extendedType) { + setExtendedType((ReferenceType) replacementNode); + return true; + } + } + if (superType != null) { + if (node == superType) { + setSuperType((ReferenceType) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public WildcardType(TokenRange tokenRange, ReferenceType extendedType, ReferenceType superType) { + super(tokenRange); + setExtendedType(extendedType); + setSuperType(superType); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public boolean isWildcardType() { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public WildcardType asWildcardType() { + return this; + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWildcardType(Consumer action) { + action.accept(this); + } + + @Override + public ResolvedWildcard resolve() { + return getSymbolResolver().toResolvedType(this, ResolvedWildcard.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional toWildcardType() { + return Optional.of(this); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java10Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java10Validator.java new file mode 100644 index 0000000..c7fda2f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java10Validator.java @@ -0,0 +1,19 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.validator.chunks.VarValidator; + +/** + * This validator validates according to Java 10 syntax rules. + */ +public class Java10Validator extends Java9Validator { + + protected final Validator varOnlyOnLocalVariableDefinitionAndFor = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(false)); + + public Java10Validator() { + super(); + add(varOnlyOnLocalVariableDefinitionAndFor); + /* There is no validator that validates that "var" is not used in Java 9 and lower, since the parser will never create a VarType node, + because that is done by the Java10 postprocessor. You can add it by hand, but that is obscure enough to ignore. */ + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java11Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java11Validator.java new file mode 100644 index 0000000..0eb879a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java11Validator.java @@ -0,0 +1,16 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.validator.chunks.VarValidator; + +/** + * This validator validates according to Java 11 syntax rules. + */ +public class Java11Validator extends Java10Validator { + protected final Validator varAlsoInLambdaParameters = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(true)); + + public Java11Validator() { + super(); + replace(varOnlyOnLocalVariableDefinitionAndFor, varAlsoInLambdaParameters); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java1_0Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java1_0Validator.java new file mode 100644 index 0000000..0d1051d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java1_0Validator.java @@ -0,0 +1,121 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.stmt.SwitchEntryStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.validator.chunks.CommonValidators; +import com.github.javaparser.ast.validator.chunks.ModifierValidator; +import com.github.javaparser.ast.validator.chunks.NoBinaryIntegerLiteralsValidator; +import com.github.javaparser.ast.validator.chunks.NoUnderscoresInIntegerLiteralsValidator; + +/** + * This validator validates according to Java 1.0 syntax rules. + */ +public class Java1_0Validator extends Validators { + protected final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods + = new ModifierValidator(false, false, false); + protected final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, + n -> true, + (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.") + ); + protected final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, + n -> !n.isTopLevelType(), + (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.") + ); + protected final Validator noReflection = new SimpleValidator<>(ClassExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Reflection is not supported.") + ); + protected final Validator noGenerics = new TreeVisitorValidator((node, reporter) -> { + if (node instanceof NodeWithTypeArguments) { + if (((NodeWithTypeArguments) node).getTypeArguments().isPresent()) { + reporter.report(node, "Generics are not supported."); + } + } + if (node instanceof NodeWithTypeParameters) { + if (((NodeWithTypeParameters) node).getTypeParameters().isNonEmpty()) { + reporter.report(node, "Generics are not supported."); + } + } + }); + protected final SingleNodeTypeValidator tryWithoutResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { + if (n.getCatchClauses().isEmpty() && !n.getFinallyBlock().isPresent()) { + reporter.report(n, "Try has no finally and no catch."); + } + if (n.getResources().isNonEmpty()) { + reporter.report(n, "Catch with resource is not supported."); + } + }); + protected final Validator noAnnotations = new TreeVisitorValidator((node, reporter) -> { + if (node instanceof AnnotationExpr || node instanceof AnnotationDeclaration) { + reporter.report(node, "Annotations are not supported."); + } + }); + protected final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, + n -> true, + (n, reporter) -> reporter.report(n, "Enumerations are not supported.") + ); + protected final Validator noVarargs = new SimpleValidator<>(Parameter.class, + Parameter::isVarArgs, + (n, reporter) -> reporter.report(n, "Varargs are not supported.") + ); + protected final Validator noForEach = new SimpleValidator<>(ForeachStmt.class, + n -> true, + (n, reporter) -> reporter.report(n, "For-each loops are not supported.") + ); + protected final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, + ImportDeclaration::isStatic, + (n, reporter) -> reporter.report(n, "Static imports are not supported.") + ); + protected final Validator noStringsInSwitch = new SimpleValidator<>(SwitchEntryStmt.class, + n -> n.getLabel().map(l -> l instanceof StringLiteralExpr).orElse(false), + (n, reporter) -> reporter.report(n.getLabel().get(), "Strings in switch statements are not supported.") + ); + protected final Validator noBinaryIntegerLiterals = new NoBinaryIntegerLiteralsValidator(); + protected final Validator noUnderscoresInIntegerLiterals = new NoUnderscoresInIntegerLiteralsValidator(); + protected final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, + n -> true, + (n, reporter) -> reporter.report(n, "Multi-catch is not supported.") + ); + protected final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Lambdas are not supported.") + ); + protected final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, + n -> true, + (n, reporter) -> reporter.report(n, "Modules are not supported.") + ); + + public Java1_0Validator() { + super(new CommonValidators()); + add(modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods); + add(noAssertKeyword); + add(noInnerClasses); + add(noReflection); + add(noGenerics); + add(tryWithoutResources); + add(noAnnotations); + add(noEnums); + add(noVarargs); + add(noForEach); + add(noStaticImports); + add(noStringsInSwitch); + add(noBinaryIntegerLiterals); + add(noUnderscoresInIntegerLiterals); + add(noMultiCatch); + add(noLambdas); + add(noModules); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java1_1Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java1_1Validator.java new file mode 100644 index 0000000..5279b7f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java1_1Validator.java @@ -0,0 +1,22 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; + +/** + * This validator validates according to Java 1.1 syntax rules. + */ +public class Java1_1Validator extends Java1_0Validator { + protected final Validator innerClasses = new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class, + (n, reporter) -> n.getParentNode().ifPresent(p -> { + if (p instanceof LocalClassDeclarationStmt && n.isInterface()) + reporter.report(n, "There is no such thing as a local interface."); + }) + ); + + public Java1_1Validator() { + super(); + replace(noInnerClasses, innerClasses); + remove(noReflection); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java1_2Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java1_2Validator.java new file mode 100644 index 0000000..4ac7565 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java1_2Validator.java @@ -0,0 +1,17 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.validator.chunks.ModifierValidator; + +/** + * This validator validates according to Java 1.2 syntax rules. + */ +public class Java1_2Validator extends Java1_1Validator { + protected final Validator modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(true, false, false); + protected final Validator strictfpNotAllowed = new ReservedKeywordValidator("strictfp"); + + public Java1_2Validator() { + super(); + replace(modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods, modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods); + add(strictfpNotAllowed); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java1_3Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java1_3Validator.java new file mode 100644 index 0000000..72830a1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java1_3Validator.java @@ -0,0 +1,10 @@ +package com.github.javaparser.ast.validator; + +/** + * This validator validates according to Java 1.3 syntax rules. + */ +public class Java1_3Validator extends Java1_2Validator { + public Java1_3Validator() { + super(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java1_4Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java1_4Validator.java new file mode 100644 index 0000000..2d4ad5e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java1_4Validator.java @@ -0,0 +1,11 @@ +package com.github.javaparser.ast.validator; + +/** + * This validator validates according to Java 1.4 syntax rules. + */ +public class Java1_4Validator extends Java1_3Validator { + public Java1_4Validator() { + super(); + remove(noAssertKeyword); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java5Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java5Validator.java new file mode 100644 index 0000000..d8b1aab --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java5Validator.java @@ -0,0 +1,52 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.Type; + +import java.util.Optional; + +/** + * This validator validates according to Java 5 syntax rules. + */ +public class Java5Validator extends Java1_4Validator { + Validator genericsWithoutDiamondOperator = new TreeVisitorValidator((node, reporter) -> { + if (node instanceof NodeWithTypeArguments) { + Optional> typeArguments = ((NodeWithTypeArguments) node).getTypeArguments(); + if (typeArguments.isPresent() && typeArguments.get().isEmpty()) { + reporter.report(node, "The diamond operator is not supported."); + } + } + }); + + protected Validator noPrimitiveGenericArguments = new TreeVisitorValidator((node, reporter) -> { + if (node instanceof NodeWithTypeArguments) { + Optional> typeArguments = ((NodeWithTypeArguments) node).getTypeArguments(); + typeArguments.ifPresent(types -> types.forEach(ty -> { + if (ty instanceof PrimitiveType) { + reporter.report(node, "Type arguments may not be primitive."); + } + })); + } + }); + + protected final Validator enumNotAllowed = new ReservedKeywordValidator("enum"); + + public Java5Validator() { + super(); + replace(noGenerics, genericsWithoutDiamondOperator); + add(noPrimitiveGenericArguments); + add(enumNotAllowed); + + // TODO validate annotations on classes, fields and methods but nowhere else + // The following is probably too simple. + remove(noAnnotations); + + remove(noEnums); + remove(noVarargs); + remove(noForEach); + remove(noStaticImports); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java6Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java6Validator.java new file mode 100644 index 0000000..7054003 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java6Validator.java @@ -0,0 +1,10 @@ +package com.github.javaparser.ast.validator; + +/** + * This validator validates according to Java 6 syntax rules. + */ +public class Java6Validator extends Java5Validator{ + public Java6Validator() { + super(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java7Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java7Validator.java new file mode 100644 index 0000000..995e836 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java7Validator.java @@ -0,0 +1,39 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.type.UnionType; + +/** + * This validator validates according to Java 7 syntax rules. + */ +public class Java7Validator extends Java6Validator { + protected final SingleNodeTypeValidator tryWithLimitedResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { + if (n.getCatchClauses().isEmpty() + && n.getResources().isEmpty() + && !n.getFinallyBlock().isPresent()) { + reporter.report(n, "Try has no finally, no catch, and no resources."); + } + for (Expression resource : n.getResources()) { + if (!resource.isVariableDeclarationExpr()) { + reporter.report(n, "Try with resources only supports variable declarations."); + } + } + }); + protected final SingleNodeTypeValidator multiCatch = new SingleNodeTypeValidator<>(UnionType.class, (n, reporter) -> { + // Case "0 elements" is caught elsewhere. + if (n.getElements().size() == 1) { + reporter.report(n, "Union type (multi catch) must have at least two elements."); + } + }); + + public Java7Validator() { + super(); + remove(genericsWithoutDiamondOperator); + replace(tryWithoutResources, tryWithLimitedResources); + remove(noStringsInSwitch); + remove(noBinaryIntegerLiterals); + remove(noUnderscoresInIntegerLiterals); + replace(noMultiCatch, multiCatch); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java8Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java8Validator.java new file mode 100644 index 0000000..e6aca92 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java8Validator.java @@ -0,0 +1,32 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.validator.chunks.ModifierValidator; + +/** + * This validator validates according to Java 7 syntax rules. + */ +public class Java8Validator extends Java7Validator { + protected final Validator modifiersWithoutPrivateInterfaceMethods = new ModifierValidator(true, true, false); + protected final Validator defaultMethodsInInterface = new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class, + (n, reporter) -> { + if (n.isInterface()) { + n.getMethods().forEach(m -> { + if (m.isDefault() && !m.getBody().isPresent()) { + reporter.report(m, "'default' methods must have a body."); + } + }); + } + } + ); + + public Java8Validator() { + super(); + replace(modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods, modifiersWithoutPrivateInterfaceMethods); + add(defaultMethodsInInterface); + remove(noLambdas); + + // TODO validate more annotation locations http://openjdk.java.net/jeps/104 + // TODO validate repeating annotations http://openjdk.java.net/jeps/120 + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Java9Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Java9Validator.java new file mode 100644 index 0000000..2175c9a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Java9Validator.java @@ -0,0 +1,30 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.validator.chunks.ModifierValidator; +import com.github.javaparser.ast.validator.chunks.UnderscoreKeywordValidator; + +/** + * This validator validates according to Java 9 syntax rules. + */ +public class Java9Validator extends Java8Validator { + protected final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator(); + protected final Validator modifiers = new ModifierValidator(true, true, true); + protected final SingleNodeTypeValidator tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { + if (n.getCatchClauses().isEmpty() + && n.getResources().isEmpty() + && !n.getFinallyBlock().isPresent()) { + reporter.report(n, "Try has no finally, no catch, and no resources."); + } + }); + + public Java9Validator() { + super(); + add(underscoreKeywordValidator); + remove(noModules); + replace(modifiersWithoutPrivateInterfaceMethods, modifiers); + replace(tryWithLimitedResources, tryWithResources); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/NoProblemsValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/NoProblemsValidator.java new file mode 100644 index 0000000..0026688 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/NoProblemsValidator.java @@ -0,0 +1,16 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.Node; + +/** + * Stub validator for when no validation is wanted. + * + * @deprecated when setting a language validator, try {@link com.github.javaparser.ParserConfiguration#setLanguageLevel(ParserConfiguration.LanguageLevel)} with RAW. + */ +@Deprecated +public final class NoProblemsValidator implements Validator { + @Override + public void accept(Node node, ProblemReporter problemReporter) { + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/ProblemReporter.java b/JavaParser/src/com/github/javaparser/ast/validator/ProblemReporter.java new file mode 100644 index 0000000..eb54810 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/ProblemReporter.java @@ -0,0 +1,34 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.Problem; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange; + +import java.util.function.Consumer; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * A simple interface where validators can report found problems. + */ +public class ProblemReporter { + private final Consumer problemConsumer; + + public ProblemReporter(Consumer problemConsumer) { + this.problemConsumer = problemConsumer; + } + + /** + * Report a problem. + * + * @param message description of the problem + * @param node the node in which the problem occurred, used to find the Range of the problem. + */ + public void report(NodeWithTokenRange node, String message, Object... args) { + report(node.getTokenRange().orElse(null), message, args); + } + + public void report(TokenRange range, String message, Object... args) { + problemConsumer.accept(new Problem(f(message, args), range, null)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/ReservedKeywordValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/ReservedKeywordValidator.java new file mode 100644 index 0000000..51a08bd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/ReservedKeywordValidator.java @@ -0,0 +1,36 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.SimpleName; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * Validates that identifiers are not keywords - this for the few keywords that the parser + * accepts because they were added after Java 1.0. + */ +public class ReservedKeywordValidator extends VisitorValidator { + private final String keyword; + private final String error; + + public ReservedKeywordValidator(String keyword) { + this.keyword = keyword; + error = f("'%s' cannot be used as an identifier as it is a keyword.", keyword); + } + + @Override + public void visit(Name n, ProblemReporter arg) { + if (n.getIdentifier().equals(keyword)) { + arg.report(n, error); + } + super.visit(n, arg); + } + + @Override + public void visit(SimpleName n, ProblemReporter arg) { + if (n.getIdentifier().equals(keyword)) { + arg.report(n, error); + } + super.visit(n, arg); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/SimpleValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/SimpleValidator.java new file mode 100644 index 0000000..b705b91 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/SimpleValidator.java @@ -0,0 +1,20 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; + +import java.util.function.BiConsumer; +import java.util.function.Predicate; + +/** + * Runs a validator on all nodes of a certain type, + * and adds a problem for all nodes that pass a condition. + */ +public class SimpleValidator extends SingleNodeTypeValidator { + public SimpleValidator(Class type, Predicate condition, BiConsumer problemSupplier) { + super(type, (node, problemReporter) -> { + if (condition.test(node)) { + problemSupplier.accept(node, problemReporter); + } + }); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java new file mode 100644 index 0000000..1698494 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java @@ -0,0 +1,24 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; + +/** + * Runs a validator on all nodes of a certain type. + */ +public class SingleNodeTypeValidator implements Validator { + private final Class type; + private final TypedValidator validator; + + public SingleNodeTypeValidator(Class type, TypedValidator validator) { + this.type = type; + this.validator = validator; + } + + @Override + public void accept(Node node, ProblemReporter problemReporter) { + if (type.isInstance(node)) { + validator.accept(type.cast(node), problemReporter); + } + node.findAll(type).forEach(n -> validator.accept(n, problemReporter)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/TreeVisitorValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/TreeVisitorValidator.java new file mode 100644 index 0000000..ae8e049 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/TreeVisitorValidator.java @@ -0,0 +1,22 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; + +/** + * A validator that walks the whole tree, visiting every node. + */ +public class TreeVisitorValidator implements Validator { + private final Validator validator; + + public TreeVisitorValidator(Validator validator) { + this.validator = validator; + } + + @Override + public final void accept(Node node, ProblemReporter reporter) { + validator.accept(node, reporter); + for (Node child : node.getChildNodes()) { + accept(child, reporter); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/TypedValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/TypedValidator.java new file mode 100644 index 0000000..588c53f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/TypedValidator.java @@ -0,0 +1,24 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ParseResult; +import com.github.javaparser.ast.Node; + +import java.util.function.BiConsumer; + +/** + * A validator that validates a known node type. + */ +public interface TypedValidator extends BiConsumer { + /** + * @param node the node that wants to be validated + * @param problemReporter when found, validation errors can be reported here + */ + void accept(N node, ProblemReporter problemReporter); + + @SuppressWarnings("unchecked") + default ParseResult.PostProcessor postProcessor() { + return (result, configuration) -> + result.getResult().ifPresent(node -> + accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem)))); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Validator.java b/JavaParser/src/com/github/javaparser/ast/validator/Validator.java new file mode 100644 index 0000000..0d5752a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Validator.java @@ -0,0 +1,15 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; + +/** + * A validator that can be run on a node to check for semantic errors. + * It is fully up to the implementor how to do this. + */ +public interface Validator extends TypedValidator { + /** + * @param node the node that wants to be validated + * @param problemReporter when found, validation errors can be reported here + */ + void accept(Node node, ProblemReporter problemReporter); +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/Validators.java b/JavaParser/src/com/github/javaparser/ast/validator/Validators.java new file mode 100644 index 0000000..dd6926a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/Validators.java @@ -0,0 +1,45 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A validator that will call a collection of validators. + */ +public class Validators implements Validator { + private final List validators = new ArrayList<>(); + + public Validators(Validator... validators) { + this.validators.addAll(Arrays.asList(validators)); + } + + public List getValidators() { + return validators; + } + + public Validators remove(Validator validator) { + if (!validators.remove(validator)) { + throw new AssertionError("Trying to remove a validator that isn't there."); + } + return this; + } + + public Validators replace(Validator oldValidator, Validator newValidator) { + remove(oldValidator); + add(newValidator); + return this; + } + + public Validators add(Validator newValidator) { + validators.add(newValidator); + return this; + } + + @Override + public void accept(Node node, ProblemReporter problemReporter) { + validators.forEach(v -> v.accept(node, problemReporter)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/VisitorValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/VisitorValidator.java new file mode 100644 index 0000000..547092d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/VisitorValidator.java @@ -0,0 +1,16 @@ +package com.github.javaparser.ast.validator; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; + +/** + * A validator that uses a visitor for validation. + * This class is the visitor too. + * Implement the "visit" methods you want to use for validation. + */ +public abstract class VisitorValidator extends VoidVisitorAdapter implements Validator { + @Override + public void accept(Node node, ProblemReporter problemReporter) { + node.accept(this, problemReporter); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/CommonValidators.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/CommonValidators.java new file mode 100644 index 0000000..5e5b791 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/CommonValidators.java @@ -0,0 +1,70 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.validator.SimpleValidator; +import com.github.javaparser.ast.validator.SingleNodeTypeValidator; +import com.github.javaparser.ast.validator.TreeVisitorValidator; +import com.github.javaparser.ast.validator.Validators; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; + +import java.util.Optional; + +/** + * Contains validations that are valid for every Java version. + */ +public class CommonValidators extends Validators { + public CommonValidators() { + super( + new SimpleValidator<>(ClassOrInterfaceDeclaration.class, + n -> !n.isInterface() && n.getExtendedTypes().size() > 1, + (n, reporter) -> reporter.report(n.getExtendedTypes(1), "A class cannot extend more than one other class.") + ), + new SimpleValidator<>(ClassOrInterfaceDeclaration.class, + n -> n.isInterface() && !n.getImplementedTypes().isEmpty(), + (n, reporter) -> reporter.report(n.getImplementedTypes(0), "An interface cannot implement other interfaces.") + ), + new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class, (n, reporter) -> { + if (n.isInterface()) { + n.getMembers().forEach(mem -> { + if (mem instanceof InitializerDeclaration) { + reporter.report(mem, "An interface cannot have initializers."); + } + }); + } + } + ), + new SingleNodeTypeValidator<>(AssignExpr.class, (n, reporter) -> { + // https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26 + Expression target = n.getTarget(); + while (target instanceof EnclosedExpr) { + target = ((EnclosedExpr) target).getInner(); + } + if (target instanceof NameExpr + || target instanceof ArrayAccessExpr + || target instanceof FieldAccessExpr) { + return; + } + reporter.report(n.getTarget(), "Illegal left hand side of an assignment."); + } + ), + new TreeVisitorValidator((node, problemReporter) -> { + NodeMetaModel mm = node.getMetaModel(); + for (PropertyMetaModel ppm : mm.getAllPropertyMetaModels()) { + if (ppm.isNonEmpty()) { + if (ppm.isNodeList()) { + NodeList value = (NodeList) ppm.getValue(node); + if (value.isEmpty()) { + problemReporter.report(node, "%s.%s can not be empty.", mm.getTypeName(), ppm.getName()); + } + } + // No need to check empty strings, it should be impossible to set them to "" + } + } + }) + ); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/ModifierValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/ModifierValidator.java new file mode 100644 index 0000000..0a01c33 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/ModifierValidator.java @@ -0,0 +1,211 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.modules.ModuleRequiresStmt; +import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; +import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.VisitorValidator; +import com.github.javaparser.utils.SeparatedItemStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +import static com.github.javaparser.ast.Modifier.*; +import static java.util.Arrays.asList; + + +/** + * Verifies that only allowed modifiers are used where modifiers are expected. + */ +public class ModifierValidator extends VisitorValidator { + private final Modifier[] interfaceWithNothingSpecial = new Modifier[]{PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP}; + private final Modifier[] interfaceWithStaticAndDefault = new Modifier[]{PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; + private final Modifier[] interfaceWithStaticAndDefaultAndPrivate = new Modifier[]{PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; + + private final boolean hasStrictfp; + private final boolean hasDefaultAndStaticInterfaceMethods; + private final boolean hasPrivateInterfaceMethods; + + public ModifierValidator(boolean hasStrictfp, boolean hasDefaultAndStaticInterfaceMethods, boolean hasPrivateInterfaceMethods) { + this.hasStrictfp = hasStrictfp; + this.hasDefaultAndStaticInterfaceMethods = hasDefaultAndStaticInterfaceMethods; + this.hasPrivateInterfaceMethods = hasPrivateInterfaceMethods; + } + + @Override + public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) { + if (n.isInterface()) { + validateInterfaceModifiers(n, reporter); + } else { + validateClassModifiers(n, reporter); + } + super.visit(n, reporter); + } + + private void validateClassModifiers(ClassOrInterfaceDeclaration n, ProblemReporter reporter) { + if (n.isTopLevelType()) { + validateModifiers(n, reporter, PUBLIC, ABSTRACT, FINAL, STRICTFP); + } else if (n.isNestedType()) { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, STRICTFP); + } else if (n.isLocalClassDeclaration()) { + validateModifiers(n, reporter, ABSTRACT, FINAL, STRICTFP); + } + } + + private void validateInterfaceModifiers(TypeDeclaration n, ProblemReporter reporter) { + if (n.isTopLevelType()) { + validateModifiers(n, reporter, PUBLIC, ABSTRACT, STRICTFP); + } else if (n.isNestedType()) { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, STRICTFP); + } + } + + @Override + public void visit(EnumDeclaration n, ProblemReporter reporter) { + if (n.isTopLevelType()) { + validateModifiers(n, reporter, PUBLIC, STRICTFP); + } else if (n.isNestedType()) { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, STATIC, STRICTFP); + } + super.visit(n, reporter); + } + + @Override + public void visit(AnnotationDeclaration n, ProblemReporter reporter) { + validateInterfaceModifiers(n, reporter); + super.visit(n, reporter); + } + + @Override + public void visit(AnnotationMemberDeclaration n, ProblemReporter reporter) { + validateModifiers(n, reporter, PUBLIC, ABSTRACT); + super.visit(n, reporter); + } + + @Override + public void visit(ConstructorDeclaration n, ProblemReporter reporter) { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE); + n.getParameters().forEach(p -> validateModifiers(p, reporter, FINAL)); + super.visit(n, reporter); + } + + @Override + public void visit(FieldDeclaration n, ProblemReporter reporter) { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, STATIC, FINAL, TRANSIENT, VOLATILE); + super.visit(n, reporter); + } + + @Override + public void visit(MethodDeclaration n, ProblemReporter reporter) { + if (n.isAbstract()) { + final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("Cannot be 'abstract' and also '", "', '", "'."); + for (Modifier m : asList(PRIVATE, STATIC, FINAL, NATIVE, STRICTFP, SYNCHRONIZED)) { + if (n.getModifiers().contains(m)) { + builder.append(m.asString()); + } + } + if (builder.hasItems()) { + reporter.report(n, builder.toString()); + } + } + if (n.getParentNode().isPresent()) { + if (n.getParentNode().get() instanceof ClassOrInterfaceDeclaration) { + if (((ClassOrInterfaceDeclaration) n.getParentNode().get()).isInterface()) { + if (hasDefaultAndStaticInterfaceMethods) { + if (hasPrivateInterfaceMethods) { + validateModifiers(n, reporter, interfaceWithStaticAndDefaultAndPrivate); + } else { + validateModifiers(n, reporter, interfaceWithStaticAndDefault); + } + } else { + validateModifiers(n, reporter, interfaceWithNothingSpecial); + } + } else { + validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP); + } + } + } + n.getParameters().forEach(p -> validateModifiers(p, reporter, FINAL)); + super.visit(n, reporter); + } + + @Override + public void visit(LambdaExpr n, ProblemReporter reporter) { + n.getParameters().forEach(p -> { + // Final is not allowed on inferred parameters, but those get caught by the parser. + validateModifiers(p, reporter, FINAL); + }); + super.visit(n, reporter); + } + + @Override + public void visit(CatchClause n, ProblemReporter reporter) { + validateModifiers(n.getParameter(), reporter, FINAL); + super.visit(n, reporter); + } + + @Override + public void visit(VariableDeclarationExpr n, ProblemReporter reporter) { + validateModifiers(n, reporter, FINAL); + super.visit(n, reporter); + } + + @Override + public void visit(ModuleRequiresStmt n, ProblemReporter reporter) { + validateModifiers(n, reporter, TRANSITIVE, STATIC); + super.visit(n, reporter); + } + + private & NodeWithTokenRange> void validateModifiers(T n, ProblemReporter reporter, Modifier... allowedModifiers) { + validateAtMostOneOf(n, reporter, PUBLIC, PROTECTED, PRIVATE); + validateAtMostOneOf(n, reporter, FINAL, ABSTRACT); + if (hasStrictfp) { + validateAtMostOneOf(n, reporter, NATIVE, STRICTFP); + } else { + allowedModifiers = removeModifierFromArray(STRICTFP, allowedModifiers); + } + for (Modifier m : n.getModifiers()) { + if (!arrayContains(allowedModifiers, m)) { + reporter.report(n, "'%s' is not allowed here.", m.asString()); + } + } + } + + private Modifier[] removeModifierFromArray(Modifier m, Modifier[] allowedModifiers) { + final List newModifiers = new ArrayList<>(asList(allowedModifiers)); + newModifiers.remove(m); + allowedModifiers = newModifiers.toArray(new Modifier[0]); + return allowedModifiers; + } + + private boolean arrayContains(Object[] items, Object searchItem) { + for (Object o : items) { + if (o == searchItem) { + return true; + } + } + return false; + } + + private & NodeWithTokenRange> void validateAtMostOneOf(T t, ProblemReporter reporter, Modifier... modifiers) { + List foundModifiers = new ArrayList<>(); + for (Modifier m : modifiers) { + if (t.getModifiers().contains(m)) { + foundModifiers.add(m); + } + } + if (foundModifiers.size() > 1) { + SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("Can have only one of '", "', '", "'."); + for (Modifier m : foundModifiers) { + builder.append(m.asString()); + } + reporter.report(t, builder.toString()); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java new file mode 100644 index 0000000..82e8dd7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java @@ -0,0 +1,27 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.LiteralStringValueExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.VisitorValidator; + +public class NoBinaryIntegerLiteralsValidator extends VisitorValidator { + @Override + public void visit(IntegerLiteralExpr n, ProblemReporter arg) { + validate(n, arg); + super.visit(n, arg); + } + + @Override + public void visit(LongLiteralExpr n, ProblemReporter arg) { + validate(n, arg); + super.visit(n, arg); + } + + private static void validate(LiteralStringValueExpr n, ProblemReporter arg) { + if (n.getValue().toUpperCase().startsWith("0B")) { + arg.report(n, "Binary literal values are not supported."); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java new file mode 100644 index 0000000..901b734 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java @@ -0,0 +1,27 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.LiteralStringValueExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.VisitorValidator; + +public class NoUnderscoresInIntegerLiteralsValidator extends VisitorValidator { + @Override + public void visit(IntegerLiteralExpr n, ProblemReporter arg) { + validate(n, arg); + super.visit(n, arg); + } + + @Override + public void visit(LongLiteralExpr n, ProblemReporter arg) { + validate(n, arg); + super.visit(n, arg); + } + + private static void validate(LiteralStringValueExpr n, ProblemReporter arg) { + if (n.getValue().contains("_")) { + arg.report(n, "Underscores in literal values are not supported."); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java new file mode 100644 index 0000000..e812597 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java @@ -0,0 +1,27 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.VisitorValidator; + +public class UnderscoreKeywordValidator extends VisitorValidator { + @Override + public void visit(Name n, ProblemReporter arg) { + validateIdentifier(n, n.getIdentifier(), arg); + super.visit(n, arg); + } + + @Override + public void visit(SimpleName n, ProblemReporter arg) { + validateIdentifier(n, n.getIdentifier(), arg); + super.visit(n, arg); + } + + private static void validateIdentifier(Node n, String id, ProblemReporter arg) { + if (id.equals("_")) { + arg.report(n, "'_' is a reserved keyword."); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/validator/chunks/VarValidator.java b/JavaParser/src/com/github/javaparser/ast/validator/chunks/VarValidator.java new file mode 100644 index 0000000..19357e8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/validator/chunks/VarValidator.java @@ -0,0 +1,93 @@ +package com.github.javaparser.ast.validator.chunks; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForeachStmt; +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.TypedValidator; + +import java.util.Optional; + +public class VarValidator implements TypedValidator { + private boolean varAllowedInLambdaParameters; + + public VarValidator(boolean varAllowedInLambdaParameters) { + this.varAllowedInLambdaParameters = varAllowedInLambdaParameters; + } + + @Override + public void accept(VarType node, ProblemReporter reporter) { + // All allowed locations are within a VariableDeclaration inside a VariableDeclarationExpr inside something else. + Optional variableDeclarator = node.findParent(VariableDeclarator.class); + if (!variableDeclarator.isPresent()) { + // Java 11's var in lambda's + if (varAllowedInLambdaParameters) { + boolean valid = node + .findParent(Parameter.class) + .flatMap(Node::getParentNode) + .map((Node p) -> p instanceof LambdaExpr).orElse(false); + if (valid) { + return; + } + } + reportIllegalPosition(node, reporter); + return; + } + variableDeclarator.ifPresent(vd -> { + Optional variableDeclarationExpr = vd.getParentNode(); + if (!variableDeclarationExpr.isPresent()) { + reportIllegalPosition(node, reporter); + return; + } + variableDeclarationExpr.ifPresent(vdeNode -> { + if (!(vdeNode instanceof VariableDeclarationExpr)) { + reportIllegalPosition(node, reporter); + return; + } + VariableDeclarationExpr vde = (VariableDeclarationExpr) vdeNode; + if (vde.getVariables().size() > 1) { + reporter.report(vde, "\"var\" only takes a single variable."); + } + Optional container = vdeNode.getParentNode(); + if (!container.isPresent()) { + reportIllegalPosition(node, reporter); + return; + } + container.ifPresent(c -> { + boolean positionIsFine = c instanceof ForStmt || c instanceof ForeachStmt || c instanceof ExpressionStmt; + if (!positionIsFine) { + reportIllegalPosition(node, reporter); + } + // A local variable declaration ends up inside an ExpressionStmt. + if (c instanceof ExpressionStmt) { + if (!vd.getInitializer().isPresent()) { + reporter.report(node, "\"var\" needs an initializer."); + } + vd.getInitializer().ifPresent(initializer -> { + if (initializer instanceof NullLiteralExpr) { + reporter.report(node, "\"var\" cannot infer type from just null."); + } + if (initializer instanceof ArrayCreationExpr) { + reporter.report(node, "\"var\" cannot infer array types."); + } + }); + + } + }); + }); + }); + + } + + private void reportIllegalPosition(VarType n, ProblemReporter reporter) { + reporter.report(n, "\"var\" is not allowed here."); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/CloneVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/CloneVisitor.java index 3ab2e55..4ae343a 100644 --- a/JavaParser/src/com/github/javaparser/ast/visitor/CloneVisitor.java +++ b/JavaParser/src/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -1,1210 +1,1080 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -public class CloneVisitor implements GenericVisitor { - - @Override - public Node visit(CompilationUnit _n, Object _arg) { - PackageDeclaration package_ = cloneNodes(_n.getPackage(), _arg); - List imports = visit(_n.getImports(), _arg); - List types = visit(_n.getTypes(), _arg); - - return new CompilationUnit( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - package_, imports, types - ); - } - - @Override - public Node visit(PackageDeclaration _n, Object _arg) { - List annotations = visit(_n.getAnnotations(), _arg); - NameExpr name = cloneNodes(_n.getName(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - PackageDeclaration r = new PackageDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - annotations, name - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ImportDeclaration _n, Object _arg) { - NameExpr name = cloneNodes(_n.getName(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ImportDeclaration r = new ImportDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - name, _n.isStatic(), _n.isAsterisk() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(TypeParameter _n, Object _arg) { - List typeBound = visit(_n.getTypeBound(), _arg); - - List annotations = visit(_n.getAnnotations(), _arg); - TypeParameter r = new TypeParameter(_n.getBeginLine(), - _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getName(), typeBound, annotations); - - Comment comment = cloneNodes(_n.getComment(), _arg); - r.setComment(comment); - return r; - } - - @Override - public Node visit(LineComment _n, Object _arg) { - return new LineComment(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getContent()); - } - - @Override - public Node visit(BlockComment _n, Object _arg) { - return new BlockComment(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getContent()); - } - - @Override - public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List typeParameters = visit(_n.getTypeParameters(), _arg); - List extendsList = visit(_n.getExtends(), _arg); - List implementsList = visit(_n.getImplements(), _arg); - List members = visit(_n.getMembers(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EnumDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List implementsList = visit(_n.getImplements(), _arg); - List entries = visit(_n.getEntries(), _arg); - List members = visit(_n.getMembers(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - EnumDeclaration r = new EnumDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, _n.getName(), implementsList, entries, members - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EmptyTypeDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - EmptyTypeDeclaration r = new EmptyTypeDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EnumConstantDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List args = visit(_n.getArgs(), _arg); - List classBody = visit(_n.getClassBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - EnumConstantDeclaration r = new EnumConstantDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - annotations, _n.getName(), args, classBody - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(AnnotationDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List members = visit(_n.getMembers(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - AnnotationDeclaration r = new AnnotationDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, _n.getName(), members - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(AnnotationMemberDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - Expression defaultValue = cloneNodes(_n.getDefaultValue(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - AnnotationMemberDeclaration r = new AnnotationMemberDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, type_, _n.getName(), defaultValue - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(FieldDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - List variables = visit(_n.getVariables(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - FieldDeclaration r = new FieldDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, type_, variables - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(VariableDeclarator _n, Object _arg) { - VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); - Expression init = cloneNodes(_n.getInit(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - VariableDeclarator r = new VariableDeclarator( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - id, init - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(VariableDeclaratorId _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - VariableDeclaratorId r = new VariableDeclaratorId( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getName(), _n.getArrayCount() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ConstructorDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List typeParameters = visit(_n.getTypeParameters(), _arg); - List parameters = visit(_n.getParameters(), _arg); - List throws_ = visit(_n.getThrows(), _arg); - BlockStmt block = cloneNodes(_n.getBlock(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ConstructorDeclaration r = new ConstructorDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, typeParameters, _n.getName(), parameters, throws_, block - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(MethodDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - List annotations = visit(_n.getAnnotations(), _arg); - List typeParameters = visit(_n.getTypeParameters(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - List parameters = visit(_n.getParameters(), _arg); - List throws_ = visit(_n.getThrows(), _arg); - BlockStmt block = cloneNodes(_n.getBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - MethodDeclaration r = new MethodDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, typeParameters, type_, _n.getName(), parameters, _n.getArrayCount(), throws_, block - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(Parameter _n, Object _arg) { - List annotations = visit(_n.getAnnotations(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - Parameter r = new Parameter( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, type_, _n.isVarArgs(), id - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(MultiTypeParameter _n, Object _arg) { - List annotations = visit(_n.getAnnotations(), _arg); - List types = visit(_n.getTypes(), _arg); - VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - MultiTypeParameter r = new MultiTypeParameter( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, types, id - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EmptyMemberDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - EmptyMemberDeclaration r = new EmptyMemberDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(InitializerDeclaration _n, Object _arg) { - JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); - BlockStmt block = cloneNodes(_n.getBlock(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - InitializerDeclaration r = new InitializerDeclaration( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.isStatic(), block - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(JavadocComment _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - JavadocComment r = new JavadocComment( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getContent() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ClassOrInterfaceType _n, Object _arg) { - ClassOrInterfaceType scope = cloneNodes(_n.getScope(), _arg); - List typeArgs = visit(_n.getTypeArgs(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ClassOrInterfaceType r = new ClassOrInterfaceType( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - scope, _n.getName(), typeArgs - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(PrimitiveType _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - PrimitiveType r = new PrimitiveType( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getType() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ReferenceType _n, Object _arg) { - List ann = visit(_n.getAnnotations(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - List> arraysAnnotations = _n.getArraysAnnotations(); - List> _arraysAnnotations = null; - if(arraysAnnotations != null){ - _arraysAnnotations = new LinkedList>(); - for(List aux: arraysAnnotations){ - _arraysAnnotations.add(visit(aux, _arg)); - } - } - - ReferenceType r = new ReferenceType(_n.getBeginLine(), - _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), type_, - _n.getArrayCount(), ann, _arraysAnnotations); - Comment comment = cloneNodes(_n.getComment(), _arg); - r.setComment(comment); - return r; - } - - @Override - public Node visit(VoidType _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - VoidType r = new VoidType(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(WildcardType _n, Object _arg) { - ReferenceType ext = cloneNodes(_n.getExtends(), _arg); - ReferenceType sup = cloneNodes(_n.getSuper(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - WildcardType r = new WildcardType( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - ext, sup - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(UnknownType _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - UnknownType r = new UnknownType(); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ArrayAccessExpr _n, Object _arg) { - Expression name = cloneNodes(_n.getName(), _arg); - Expression index = cloneNodes(_n.getIndex(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ArrayAccessExpr r = new ArrayAccessExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - name, index - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ArrayCreationExpr _n, Object _arg) { - Type type_ = cloneNodes(_n.getType(), _arg); - List dimensions = visit(_n.getDimensions(), _arg); - ArrayCreationExpr r = new ArrayCreationExpr(_n.getBeginLine(), - _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), type_, - dimensions, _n.getArrayCount()); - if (_n.getInitializer() != null) {// ArrayCreationExpr has two mutually - // exclusive constructors - r.setInitializer(cloneNodes(_n.getInitializer(), _arg)); - } - List> arraysAnnotations = _n.getArraysAnnotations(); - List> _arraysAnnotations = null; - if(arraysAnnotations != null){ - _arraysAnnotations = new LinkedList>(); - for(List aux: arraysAnnotations){ - _arraysAnnotations.add(visit(aux, _arg)); - } - } - r.setArraysAnnotations(_arraysAnnotations); - Comment comment = cloneNodes(_n.getComment(), _arg); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ArrayInitializerExpr _n, Object _arg) { - List values = visit(_n.getValues(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ArrayInitializerExpr r = new ArrayInitializerExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - values - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(AssignExpr _n, Object _arg) { - Expression target = cloneNodes(_n.getTarget(), _arg); - Expression value = cloneNodes(_n.getValue(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - AssignExpr r = new AssignExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - target, value, _n.getOperator()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(BinaryExpr _n, Object _arg) { - Expression left = cloneNodes(_n.getLeft(), _arg); - Expression right = cloneNodes(_n.getRight(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - BinaryExpr r = new BinaryExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - left, right, _n.getOperator() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(CastExpr _n, Object _arg) { - Type type_ = cloneNodes(_n.getType(), _arg); - Expression expr = cloneNodes(_n.getExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - CastExpr r = new CastExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - type_, expr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ClassExpr _n, Object _arg) { - Type type_ = cloneNodes(_n.getType(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ClassExpr r = new ClassExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - type_ - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ConditionalExpr _n, Object _arg) { - Expression condition = cloneNodes(_n.getCondition(), _arg); - Expression thenExpr = cloneNodes(_n.getThenExpr(), _arg); - Expression elseExpr = cloneNodes(_n.getElseExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ConditionalExpr r = new ConditionalExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - condition, thenExpr, elseExpr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EnclosedExpr _n, Object _arg) { - Expression inner = cloneNodes(_n.getInner(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - EnclosedExpr r = new EnclosedExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - inner - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(FieldAccessExpr _n, Object _arg) { - Expression scope = cloneNodes(_n.getScope(), _arg); - List typeArgs = visit(_n.getTypeArgs(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - FieldAccessExpr r = new FieldAccessExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - scope, typeArgs, _n.getField() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(InstanceOfExpr _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpr(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - InstanceOfExpr r = new InstanceOfExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr, type_ - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(StringLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - StringLiteralExpr r = new StringLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(IntegerLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - IntegerLiteralExpr r = new IntegerLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(LongLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - LongLiteralExpr r = new LongLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(IntegerLiteralMinValueExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - IntegerLiteralMinValueExpr r = new IntegerLiteralMinValueExpr(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(LongLiteralMinValueExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - LongLiteralMinValueExpr r = new LongLiteralMinValueExpr(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(CharLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - CharLiteralExpr r = new CharLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(DoubleLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - DoubleLiteralExpr r = new DoubleLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(BooleanLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - BooleanLiteralExpr r = new BooleanLiteralExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getValue() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(NullLiteralExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - NullLiteralExpr r = new NullLiteralExpr(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(MethodCallExpr _n, Object _arg) { - Expression scope = cloneNodes(_n.getScope(), _arg); - List typeArgs = visit(_n.getTypeArgs(), _arg); - List args = visit(_n.getArgs(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - MethodCallExpr r = new MethodCallExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - scope, typeArgs, _n.getName(), args - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(NameExpr _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - NameExpr r = new NameExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getName() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ObjectCreationExpr _n, Object _arg) { - Expression scope = cloneNodes(_n.getScope(), _arg); - ClassOrInterfaceType type_ = cloneNodes(_n.getType(), _arg); - List typeArgs = visit(_n.getTypeArgs(), _arg); - List args = visit(_n.getArgs(), _arg); - List anonymousBody = visit(_n.getAnonymousClassBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ObjectCreationExpr r = new ObjectCreationExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - scope, type_, typeArgs, args, anonymousBody - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(QualifiedNameExpr _n, Object _arg) { - NameExpr scope = cloneNodes(_n.getQualifier(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - QualifiedNameExpr r = new QualifiedNameExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - scope, _n.getName() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ThisExpr _n, Object _arg) { - Expression classExpr = cloneNodes(_n.getClassExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ThisExpr r = new ThisExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - classExpr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(SuperExpr _n, Object _arg) { - Expression classExpr = cloneNodes(_n.getClassExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - SuperExpr r = new SuperExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - classExpr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(UnaryExpr _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - UnaryExpr r = new UnaryExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr, _n.getOperator() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(VariableDeclarationExpr _n, Object _arg) { - List annotations = visit(_n.getAnnotations(), _arg); - Type type_ = cloneNodes(_n.getType(), _arg); - List vars = visit(_n.getVars(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - VariableDeclarationExpr r = new VariableDeclarationExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getModifiers(), annotations, type_, vars - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(MarkerAnnotationExpr _n, Object _arg) { - NameExpr name = cloneNodes(_n.getName(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - MarkerAnnotationExpr r = new MarkerAnnotationExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - name - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(SingleMemberAnnotationExpr _n, Object _arg) { - NameExpr name = cloneNodes(_n.getName(), _arg); - Expression memberValue = cloneNodes(_n.getMemberValue(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - SingleMemberAnnotationExpr r = new SingleMemberAnnotationExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - name, memberValue - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(NormalAnnotationExpr _n, Object _arg) { - NameExpr name = cloneNodes(_n.getName(), _arg); - List pairs = visit(_n.getPairs(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - NormalAnnotationExpr r = new NormalAnnotationExpr( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - name, pairs - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(MemberValuePair _n, Object _arg) { - Expression value = cloneNodes(_n.getValue(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - MemberValuePair r = new MemberValuePair( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getName(), value - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ExplicitConstructorInvocationStmt _n, Object _arg) { - List typeArgs = visit(_n.getTypeArgs(), _arg); - Expression expr = cloneNodes(_n.getExpr(), _arg); - List args = visit(_n.getArgs(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - typeArgs, _n.isThis(), expr, args - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(TypeDeclarationStmt _n, Object _arg) { - TypeDeclaration typeDecl = cloneNodes(_n.getTypeDeclaration(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - TypeDeclarationStmt r = new TypeDeclarationStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - typeDecl - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(AssertStmt _n, Object _arg) { - Expression check = cloneNodes(_n.getCheck(), _arg); - Expression message = cloneNodes(_n.getMessage(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - AssertStmt r = new AssertStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - check, message - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(BlockStmt _n, Object _arg) { - List stmts = visit(_n.getStmts(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - BlockStmt r = new BlockStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - stmts - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(LabeledStmt _n, Object _arg) { - Statement stmt = cloneNodes(_n.getStmt(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - LabeledStmt r = new LabeledStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getLabel(), stmt - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(EmptyStmt _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - EmptyStmt r = new EmptyStmt(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn()); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ExpressionStmt _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpression(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ExpressionStmt r = new ExpressionStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(SwitchStmt _n, Object _arg) { - Expression selector = cloneNodes(_n.getSelector(), _arg); - List entries = visit(_n.getEntries(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - SwitchStmt r = new SwitchStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - selector, entries - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(SwitchEntryStmt _n, Object _arg) { - Expression label = cloneNodes(_n.getLabel(), _arg); - List stmts = visit(_n.getStmts(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - SwitchEntryStmt r = new SwitchEntryStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - label, stmts - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(BreakStmt _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - BreakStmt r = new BreakStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getId() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ReturnStmt _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ReturnStmt r = new ReturnStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(IfStmt _n, Object _arg) { - Expression condition = cloneNodes(_n.getCondition(), _arg); - Statement thenStmt = cloneNodes(_n.getThenStmt(), _arg); - Statement elseStmt = cloneNodes(_n.getElseStmt(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - IfStmt r = new IfStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - condition, thenStmt, elseStmt - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(WhileStmt _n, Object _arg) { - Expression condition = cloneNodes(_n.getCondition(), _arg); - Statement body = cloneNodes(_n.getBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - WhileStmt r = new WhileStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - condition, body - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ContinueStmt _n, Object _arg) { - Comment comment = cloneNodes(_n.getComment(), _arg); - - ContinueStmt r = new ContinueStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - _n.getId() - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(DoStmt _n, Object _arg) { - Statement body = cloneNodes(_n.getBody(), _arg); - Expression condition = cloneNodes(_n.getCondition(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - DoStmt r = new DoStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - body, condition - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ForeachStmt _n, Object _arg) { - VariableDeclarationExpr var = cloneNodes(_n.getVariable(), _arg); - Expression iterable = cloneNodes(_n.getIterable(), _arg); - Statement body = cloneNodes(_n.getBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ForeachStmt r = new ForeachStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - var, iterable, body - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ForStmt _n, Object _arg) { - List init = visit(_n.getInit(), _arg); - Expression compare = cloneNodes(_n.getCompare(), _arg); - List update = visit(_n.getUpdate(), _arg); - Statement body = cloneNodes(_n.getBody(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ForStmt r = new ForStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - init, compare, update, body - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(ThrowStmt _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpr(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - ThrowStmt r = new ThrowStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(SynchronizedStmt _n, Object _arg) { - Expression expr = cloneNodes(_n.getExpr(), _arg); - BlockStmt block = cloneNodes(_n.getBlock(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - SynchronizedStmt r = new SynchronizedStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - expr, block - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(TryStmt _n, Object _arg) { - List resources = visit(_n.getResources(),_arg); - BlockStmt tryBlock = cloneNodes(_n.getTryBlock(), _arg); - List catchs = visit(_n.getCatchs(), _arg); - BlockStmt finallyBlock = cloneNodes(_n.getFinallyBlock(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - TryStmt r = new TryStmt( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - resources, tryBlock, catchs, finallyBlock - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(CatchClause _n, Object _arg) { - MultiTypeParameter except = cloneNodes(_n.getExcept(), _arg); - BlockStmt catchBlock = cloneNodes(_n.getCatchBlock(), _arg); - Comment comment = cloneNodes(_n.getComment(), _arg); - - CatchClause r = new CatchClause( - _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), - except.getModifiers(), except.getAnnotations(), except.getTypes(), except.getId(), catchBlock - ); - r.setComment(comment); - return r; - } - - @Override - public Node visit(LambdaExpr _n, Object _arg) { - - List lambdaParameters = visit(_n.getParameters(), _arg); - - Statement body = cloneNodes(_n.getBody(), _arg); - - LambdaExpr r = new LambdaExpr(_n.getBeginLine(), _n.getBeginColumn(), - _n.getEndLine(), _n.getEndColumn(), lambdaParameters, body, - _n.isParametersEnclosed()); - - return r; - } - - @Override - public Node visit(MethodReferenceExpr _n, Object arg) { - - List typeParams = visit(_n.getTypeParameters(), arg); - Expression scope = cloneNodes(_n.getScope(), arg); - - MethodReferenceExpr r = new MethodReferenceExpr(_n.getBeginLine(), - _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), scope, - typeParams, _n.getIdentifier()); - return r; - } - - @Override - public Node visit(TypeExpr n, Object arg) { - - Type t = cloneNodes(n.getType(), arg); - - TypeExpr r = new TypeExpr(n.getBeginLine(), n.getBeginColumn(), - n.getEndLine(), n.getEndColumn(), t); - - return r; - } - - public List visit(List _nodes, Object _arg) { - if (_nodes == null) - return null; - List r = new ArrayList(_nodes.size()); - for (T n : _nodes) { - T rN = cloneNodes(n, _arg); - if (rN != null) - r.add(rN); - } - return r; - } - - protected T cloneNodes(T _node, Object _arg) { - if (_node == null) - return null; - Node r = _node.accept(this, _arg); - if (r == null) - return null; - return (T) r; - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.*; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import java.util.Optional; +import javax.annotation.Generated; + +/** + * A visitor that clones (copies) a node and all its children. + */ +public class CloneVisitor implements GenericVisitor { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final CompilationUnit n, final Object arg) { + NodeList imports = cloneList(n.getImports(), arg); + ModuleDeclaration module = cloneNode(n.getModule(), arg); + PackageDeclaration packageDeclaration = cloneNode(n.getPackageDeclaration(), arg); + NodeList> types = cloneList(n.getTypes(), arg); + Comment comment = cloneNode(n.getComment(), arg); + CompilationUnit r = new CompilationUnit(n.getTokenRange().orElse(null), packageDeclaration, imports, types, module); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final PackageDeclaration n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + PackageDeclaration r = new PackageDeclaration(n.getTokenRange().orElse(null), annotations, name); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final TypeParameter n, final Object arg) { + SimpleName name = cloneNode(n.getName(), arg); + NodeList typeBound = cloneList(n.getTypeBound(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + TypeParameter r = new TypeParameter(n.getTokenRange().orElse(null), name, typeBound, annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final LineComment n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + LineComment r = new LineComment(n.getTokenRange().orElse(null), n.getContent()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final BlockComment n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + BlockComment r = new BlockComment(n.getTokenRange().orElse(null), n.getContent()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ClassOrInterfaceDeclaration n, final Object arg) { + NodeList extendedTypes = cloneList(n.getExtendedTypes(), arg); + NodeList implementedTypes = cloneList(n.getImplementedTypes(), arg); + NodeList typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, n.isInterface(), name, typeParameters, extendedTypes, implementedTypes, members); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final EnumDeclaration n, final Object arg) { + NodeList entries = cloneList(n.getEntries(), arg); + NodeList implementedTypes = cloneList(n.getImplementedTypes(), arg); + NodeList> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + EnumDeclaration r = new EnumDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, name, implementedTypes, entries, members); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final EnumConstantDeclaration n, final Object arg) { + NodeList arguments = cloneList(n.getArguments(), arg); + NodeList> classBody = cloneList(n.getClassBody(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + EnumConstantDeclaration r = new EnumConstantDeclaration(n.getTokenRange().orElse(null), annotations, name, arguments, classBody); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final AnnotationDeclaration n, final Object arg) { + NodeList> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + AnnotationDeclaration r = new AnnotationDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, name, members); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final AnnotationMemberDeclaration n, final Object arg) { + Expression defaultValue = cloneNode(n.getDefaultValue(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Type type = cloneNode(n.getType(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + AnnotationMemberDeclaration r = new AnnotationMemberDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, type, name, defaultValue); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final FieldDeclaration n, final Object arg) { + NodeList variables = cloneList(n.getVariables(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + FieldDeclaration r = new FieldDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, variables); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final VariableDeclarator n, final Object arg) { + Expression initializer = cloneNode(n.getInitializer(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + VariableDeclarator r = new VariableDeclarator(n.getTokenRange().orElse(null), type, name, initializer); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ConstructorDeclaration n, final Object arg) { + BlockStmt body = cloneNode(n.getBody(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList parameters = cloneList(n.getParameters(), arg); + ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); + NodeList thrownExceptions = cloneList(n.getThrownExceptions(), arg); + NodeList typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ConstructorDeclaration r = new ConstructorDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final MethodDeclaration n, final Object arg) { + BlockStmt body = cloneNode(n.getBody(), arg); + Type type = cloneNode(n.getType(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList parameters = cloneList(n.getParameters(), arg); + ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); + NodeList thrownExceptions = cloneList(n.getThrownExceptions(), arg); + NodeList typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + MethodDeclaration r = new MethodDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, type, name, parameters, thrownExceptions, body, receiverParameter); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final Parameter n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Type type = cloneNode(n.getType(), arg); + NodeList varArgsAnnotations = cloneList(n.getVarArgsAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + Parameter r = new Parameter(n.getTokenRange().orElse(null), n.getModifiers(), annotations, type, n.isVarArgs(), varArgsAnnotations, name); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final InitializerDeclaration n, final Object arg) { + BlockStmt body = cloneNode(n.getBody(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final JavadocComment n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + JavadocComment r = new JavadocComment(n.getTokenRange().orElse(null), n.getContent()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ClassOrInterfaceType n, final Object arg) { + SimpleName name = cloneNode(n.getName(), arg); + ClassOrInterfaceType scope = cloneNode(n.getScope(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ClassOrInterfaceType r = new ClassOrInterfaceType(n.getTokenRange().orElse(null), scope, name, typeArguments, annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final PrimitiveType n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + PrimitiveType r = new PrimitiveType(n.getTokenRange().orElse(null), n.getType(), annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ArrayType n, final Object arg) { + Type componentType = cloneNode(n.getComponentType(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ArrayType r = new ArrayType(n.getTokenRange().orElse(null), componentType, n.getOrigin(), annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ArrayCreationLevel n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Expression dimension = cloneNode(n.getDimension(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ArrayCreationLevel r = new ArrayCreationLevel(n.getTokenRange().orElse(null), dimension, annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final IntersectionType n, final Object arg) { + NodeList elements = cloneList(n.getElements(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final UnionType n, final Object arg) { + NodeList elements = cloneList(n.getElements(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + UnionType r = new UnionType(n.getTokenRange().orElse(null), elements); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final VoidType n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + VoidType r = new VoidType(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final WildcardType n, final Object arg) { + ReferenceType extendedType = cloneNode(n.getExtendedType(), arg); + ReferenceType superType = cloneNode(n.getSuperType(), arg); + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + WildcardType r = new WildcardType(n.getTokenRange().orElse(null), extendedType, superType, annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final UnknownType n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + UnknownType r = new UnknownType(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ArrayAccessExpr n, final Object arg) { + Expression index = cloneNode(n.getIndex(), arg); + Expression name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ArrayAccessExpr r = new ArrayAccessExpr(n.getTokenRange().orElse(null), name, index); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ArrayCreationExpr n, final Object arg) { + Type elementType = cloneNode(n.getElementType(), arg); + ArrayInitializerExpr initializer = cloneNode(n.getInitializer(), arg); + NodeList levels = cloneList(n.getLevels(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ArrayCreationExpr r = new ArrayCreationExpr(n.getTokenRange().orElse(null), elementType, levels, initializer); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ArrayInitializerExpr n, final Object arg) { + NodeList values = cloneList(n.getValues(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ArrayInitializerExpr r = new ArrayInitializerExpr(n.getTokenRange().orElse(null), values); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final AssignExpr n, final Object arg) { + Expression target = cloneNode(n.getTarget(), arg); + Expression value = cloneNode(n.getValue(), arg); + Comment comment = cloneNode(n.getComment(), arg); + AssignExpr r = new AssignExpr(n.getTokenRange().orElse(null), target, value, n.getOperator()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final BinaryExpr n, final Object arg) { + Expression left = cloneNode(n.getLeft(), arg); + Expression right = cloneNode(n.getRight(), arg); + Comment comment = cloneNode(n.getComment(), arg); + BinaryExpr r = new BinaryExpr(n.getTokenRange().orElse(null), left, right, n.getOperator()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final CastExpr n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + CastExpr r = new CastExpr(n.getTokenRange().orElse(null), type, expression); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ClassExpr n, final Object arg) { + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ClassExpr r = new ClassExpr(n.getTokenRange().orElse(null), type); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ConditionalExpr n, final Object arg) { + Expression condition = cloneNode(n.getCondition(), arg); + Expression elseExpr = cloneNode(n.getElseExpr(), arg); + Expression thenExpr = cloneNode(n.getThenExpr(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ConditionalExpr r = new ConditionalExpr(n.getTokenRange().orElse(null), condition, thenExpr, elseExpr); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final EnclosedExpr n, final Object arg) { + Expression inner = cloneNode(n.getInner(), arg); + Comment comment = cloneNode(n.getComment(), arg); + EnclosedExpr r = new EnclosedExpr(n.getTokenRange().orElse(null), inner); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final FieldAccessExpr n, final Object arg) { + SimpleName name = cloneNode(n.getName(), arg); + Expression scope = cloneNode(n.getScope(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + Comment comment = cloneNode(n.getComment(), arg); + FieldAccessExpr r = new FieldAccessExpr(n.getTokenRange().orElse(null), scope, typeArguments, name); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final InstanceOfExpr n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + ReferenceType type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + InstanceOfExpr r = new InstanceOfExpr(n.getTokenRange().orElse(null), expression, type); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final StringLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + StringLiteralExpr r = new StringLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final IntegerLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + IntegerLiteralExpr r = new IntegerLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final LongLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + LongLiteralExpr r = new LongLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final CharLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + CharLiteralExpr r = new CharLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final DoubleLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + DoubleLiteralExpr r = new DoubleLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final BooleanLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + BooleanLiteralExpr r = new BooleanLiteralExpr(n.getTokenRange().orElse(null), n.getValue()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final NullLiteralExpr n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + NullLiteralExpr r = new NullLiteralExpr(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final MethodCallExpr n, final Object arg) { + NodeList arguments = cloneList(n.getArguments(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Expression scope = cloneNode(n.getScope(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + Comment comment = cloneNode(n.getComment(), arg); + MethodCallExpr r = new MethodCallExpr(n.getTokenRange().orElse(null), scope, typeArguments, name, arguments); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final NameExpr n, final Object arg) { + SimpleName name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + NameExpr r = new NameExpr(n.getTokenRange().orElse(null), name); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ObjectCreationExpr n, final Object arg) { + NodeList> anonymousClassBody = cloneList(n.getAnonymousClassBody().orElse(null), arg); + NodeList arguments = cloneList(n.getArguments(), arg); + Expression scope = cloneNode(n.getScope(), arg); + ClassOrInterfaceType type = cloneNode(n.getType(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + Comment comment = cloneNode(n.getComment(), arg); + ObjectCreationExpr r = new ObjectCreationExpr(n.getTokenRange().orElse(null), scope, type, typeArguments, arguments, anonymousClassBody); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final Name n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Name qualifier = cloneNode(n.getQualifier(), arg); + Comment comment = cloneNode(n.getComment(), arg); + Name r = new Name(n.getTokenRange().orElse(null), qualifier, n.getIdentifier(), annotations); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SimpleName n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + SimpleName r = new SimpleName(n.getTokenRange().orElse(null), n.getIdentifier()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ThisExpr n, final Object arg) { + Expression classExpr = cloneNode(n.getClassExpr(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ThisExpr r = new ThisExpr(n.getTokenRange().orElse(null), classExpr); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SuperExpr n, final Object arg) { + Expression classExpr = cloneNode(n.getClassExpr(), arg); + Comment comment = cloneNode(n.getComment(), arg); + SuperExpr r = new SuperExpr(n.getTokenRange().orElse(null), classExpr); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final UnaryExpr n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + Comment comment = cloneNode(n.getComment(), arg); + UnaryExpr r = new UnaryExpr(n.getTokenRange().orElse(null), expression, n.getOperator()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final VariableDeclarationExpr n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + NodeList variables = cloneList(n.getVariables(), arg); + Comment comment = cloneNode(n.getComment(), arg); + VariableDeclarationExpr r = new VariableDeclarationExpr(n.getTokenRange().orElse(null), n.getModifiers(), annotations, variables); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final MarkerAnnotationExpr n, final Object arg) { + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + MarkerAnnotationExpr r = new MarkerAnnotationExpr(n.getTokenRange().orElse(null), name); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SingleMemberAnnotationExpr n, final Object arg) { + Expression memberValue = cloneNode(n.getMemberValue(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + SingleMemberAnnotationExpr r = new SingleMemberAnnotationExpr(n.getTokenRange().orElse(null), name, memberValue); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final NormalAnnotationExpr n, final Object arg) { + NodeList pairs = cloneList(n.getPairs(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + NormalAnnotationExpr r = new NormalAnnotationExpr(n.getTokenRange().orElse(null), name, pairs); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final MemberValuePair n, final Object arg) { + SimpleName name = cloneNode(n.getName(), arg); + Expression value = cloneNode(n.getValue(), arg); + Comment comment = cloneNode(n.getComment(), arg); + MemberValuePair r = new MemberValuePair(n.getTokenRange().orElse(null), name, value); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ExplicitConstructorInvocationStmt n, final Object arg) { + NodeList arguments = cloneList(n.getArguments(), arg); + Expression expression = cloneNode(n.getExpression(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + Comment comment = cloneNode(n.getComment(), arg); + ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt(n.getTokenRange().orElse(null), typeArguments, n.isThis(), expression, arguments); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final LocalClassDeclarationStmt n, final Object arg) { + ClassOrInterfaceDeclaration classDeclaration = cloneNode(n.getClassDeclaration(), arg); + Comment comment = cloneNode(n.getComment(), arg); + LocalClassDeclarationStmt r = new LocalClassDeclarationStmt(n.getTokenRange().orElse(null), classDeclaration); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final AssertStmt n, final Object arg) { + Expression check = cloneNode(n.getCheck(), arg); + Expression message = cloneNode(n.getMessage(), arg); + Comment comment = cloneNode(n.getComment(), arg); + AssertStmt r = new AssertStmt(n.getTokenRange().orElse(null), check, message); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final BlockStmt n, final Object arg) { + NodeList statements = cloneList(n.getStatements(), arg); + Comment comment = cloneNode(n.getComment(), arg); + BlockStmt r = new BlockStmt(n.getTokenRange().orElse(null), statements); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final LabeledStmt n, final Object arg) { + SimpleName label = cloneNode(n.getLabel(), arg); + Statement statement = cloneNode(n.getStatement(), arg); + Comment comment = cloneNode(n.getComment(), arg); + LabeledStmt r = new LabeledStmt(n.getTokenRange().orElse(null), label, statement); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final EmptyStmt n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + EmptyStmt r = new EmptyStmt(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ExpressionStmt n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ExpressionStmt r = new ExpressionStmt(n.getTokenRange().orElse(null), expression); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SwitchStmt n, final Object arg) { + NodeList entries = cloneList(n.getEntries(), arg); + Expression selector = cloneNode(n.getSelector(), arg); + Comment comment = cloneNode(n.getComment(), arg); + SwitchStmt r = new SwitchStmt(n.getTokenRange().orElse(null), selector, entries); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SwitchEntryStmt n, final Object arg) { + Expression label = cloneNode(n.getLabel(), arg); + NodeList statements = cloneList(n.getStatements(), arg); + Comment comment = cloneNode(n.getComment(), arg); + SwitchEntryStmt r = new SwitchEntryStmt(n.getTokenRange().orElse(null), label, statements); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final BreakStmt n, final Object arg) { + SimpleName label = cloneNode(n.getLabel(), arg); + Comment comment = cloneNode(n.getComment(), arg); + BreakStmt r = new BreakStmt(n.getTokenRange().orElse(null), label); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ReturnStmt n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ReturnStmt r = new ReturnStmt(n.getTokenRange().orElse(null), expression); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final IfStmt n, final Object arg) { + Expression condition = cloneNode(n.getCondition(), arg); + Statement elseStmt = cloneNode(n.getElseStmt(), arg); + Statement thenStmt = cloneNode(n.getThenStmt(), arg); + Comment comment = cloneNode(n.getComment(), arg); + IfStmt r = new IfStmt(n.getTokenRange().orElse(null), condition, thenStmt, elseStmt); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final WhileStmt n, final Object arg) { + Statement body = cloneNode(n.getBody(), arg); + Expression condition = cloneNode(n.getCondition(), arg); + Comment comment = cloneNode(n.getComment(), arg); + WhileStmt r = new WhileStmt(n.getTokenRange().orElse(null), condition, body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ContinueStmt n, final Object arg) { + SimpleName label = cloneNode(n.getLabel(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ContinueStmt r = new ContinueStmt(n.getTokenRange().orElse(null), label); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final DoStmt n, final Object arg) { + Statement body = cloneNode(n.getBody(), arg); + Expression condition = cloneNode(n.getCondition(), arg); + Comment comment = cloneNode(n.getComment(), arg); + DoStmt r = new DoStmt(n.getTokenRange().orElse(null), body, condition); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ForeachStmt n, final Object arg) { + Statement body = cloneNode(n.getBody(), arg); + Expression iterable = cloneNode(n.getIterable(), arg); + VariableDeclarationExpr variable = cloneNode(n.getVariable(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ForeachStmt r = new ForeachStmt(n.getTokenRange().orElse(null), variable, iterable, body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ForStmt n, final Object arg) { + Statement body = cloneNode(n.getBody(), arg); + Expression compare = cloneNode(n.getCompare(), arg); + NodeList initialization = cloneList(n.getInitialization(), arg); + NodeList update = cloneList(n.getUpdate(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ForStmt r = new ForStmt(n.getTokenRange().orElse(null), initialization, compare, update, body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ThrowStmt n, final Object arg) { + Expression expression = cloneNode(n.getExpression(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ThrowStmt r = new ThrowStmt(n.getTokenRange().orElse(null), expression); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final SynchronizedStmt n, final Object arg) { + BlockStmt body = cloneNode(n.getBody(), arg); + Expression expression = cloneNode(n.getExpression(), arg); + Comment comment = cloneNode(n.getComment(), arg); + SynchronizedStmt r = new SynchronizedStmt(n.getTokenRange().orElse(null), expression, body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final TryStmt n, final Object arg) { + NodeList catchClauses = cloneList(n.getCatchClauses(), arg); + BlockStmt finallyBlock = cloneNode(n.getFinallyBlock(), arg); + NodeList resources = cloneList(n.getResources(), arg); + BlockStmt tryBlock = cloneNode(n.getTryBlock(), arg); + Comment comment = cloneNode(n.getComment(), arg); + TryStmt r = new TryStmt(n.getTokenRange().orElse(null), resources, tryBlock, catchClauses, finallyBlock); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final CatchClause n, final Object arg) { + BlockStmt body = cloneNode(n.getBody(), arg); + Parameter parameter = cloneNode(n.getParameter(), arg); + Comment comment = cloneNode(n.getComment(), arg); + CatchClause r = new CatchClause(n.getTokenRange().orElse(null), parameter, body); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final LambdaExpr n, final Object arg) { + Statement body = cloneNode(n.getBody(), arg); + NodeList parameters = cloneList(n.getParameters(), arg); + Comment comment = cloneNode(n.getComment(), arg); + LambdaExpr r = new LambdaExpr(n.getTokenRange().orElse(null), parameters, body, n.isEnclosingParameters()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final MethodReferenceExpr n, final Object arg) { + Expression scope = cloneNode(n.getScope(), arg); + NodeList typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + Comment comment = cloneNode(n.getComment(), arg); + MethodReferenceExpr r = new MethodReferenceExpr(n.getTokenRange().orElse(null), scope, typeArguments, n.getIdentifier()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final TypeExpr n, final Object arg) { + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + TypeExpr r = new TypeExpr(n.getTokenRange().orElse(null), type); + r.setComment(comment); + return r; + } + + @Override + public Visitable visit(NodeList n, Object arg) { + NodeList newNodes = new NodeList<>(); + for (Object node : n) { + Node resultNode = (Node) ((Node) node).accept(this, arg); + if (resultNode != null) { + newNodes.add(resultNode); + } + } + return newNodes; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Node visit(final ImportDeclaration n, final Object arg) { + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ImportDeclaration r = new ImportDeclaration(n.getTokenRange().orElse(null), name, n.isStatic(), n.isAsterisk()); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleDeclaration n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + NodeList moduleStmts = cloneList(n.getModuleStmts(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleDeclaration r = new ModuleDeclaration(n.getTokenRange().orElse(null), annotations, name, n.isOpen(), moduleStmts); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleRequiresStmt n, final Object arg) { + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleRequiresStmt r = new ModuleRequiresStmt(n.getTokenRange().orElse(null), n.getModifiers(), name); + r.setComment(comment); + return r; + } + + @SuppressWarnings("unchecked") + protected T cloneNode(Optional node, Object arg) { + if (!node.isPresent()) { + return null; + } + Node r = (Node) node.get().accept(this, arg); + if (r == null) { + return null; + } + return (T) r; + } + + @SuppressWarnings("unchecked") + protected T cloneNode(T node, Object arg) { + if (node == null) { + return null; + } + Node r = (Node) node.accept(this, arg); + if (r == null) { + return null; + } + return (T) r; + } + + private NodeList cloneList(NodeList list, Object arg) { + if (list == null) { + return null; + } + return (NodeList) list.accept(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleExportsStmt n, final Object arg) { + NodeList moduleNames = cloneList(n.getModuleNames(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleExportsStmt r = new ModuleExportsStmt(n.getTokenRange().orElse(null), name, moduleNames); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleProvidesStmt n, final Object arg) { + Type type = cloneNode(n.getType(), arg); + NodeList withTypes = cloneList(n.getWithTypes(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleProvidesStmt r = new ModuleProvidesStmt(n.getTokenRange().orElse(null), type, withTypes); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleUsesStmt n, final Object arg) { + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleUsesStmt r = new ModuleUsesStmt(n.getTokenRange().orElse(null), type); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleOpensStmt n, final Object arg) { + NodeList moduleNames = cloneList(n.getModuleNames(), arg); + Name name = cloneNode(n.getName(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ModuleOpensStmt r = new ModuleOpensStmt(n.getTokenRange().orElse(null), name, moduleNames); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final UnparsableStmt n, final Object arg) { + Comment comment = cloneNode(n.getComment(), arg); + UnparsableStmt r = new UnparsableStmt(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ReceiverParameter n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Name name = cloneNode(n.getName(), arg); + Type type = cloneNode(n.getType(), arg); + Comment comment = cloneNode(n.getComment(), arg); + ReceiverParameter r = new ReceiverParameter(n.getTokenRange().orElse(null), annotations, type, name); + r.setComment(comment); + return r; + } + + @Override + public Visitable visit(final VarType n, final Object arg) { + NodeList annotations = cloneList(n.getAnnotations(), arg); + Comment comment = cloneNode(n.getComment(), arg); + VarType r = new VarType(n.getTokenRange().orElse(null)); + r.setComment(comment); + return r; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/DumpVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/DumpVisitor.java deleted file mode 100644 index 49d3c4d..0000000 --- a/JavaParser/src/com/github/javaparser/ast/visitor/DumpVisitor.java +++ /dev/null @@ -1,1656 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import static com.github.javaparser.PositionUtils.sortByBeginPosition; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.ModifierSet; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static com.github.javaparser.ast.internal.Utils.isNullOrEmpty; - -/** - * Dumps the AST to formatted Java source code. - * - * @author Julio Vilmar Gesser - */ -public final class DumpVisitor implements VoidVisitor { - - private boolean printComments; - - public DumpVisitor() { - this(true); - } - - public DumpVisitor(boolean printComments) { - this.printComments = printComments; - } - - private static class SourcePrinter { - - private int level = 0; - - private boolean indented = false; - - private final StringBuilder buf = new StringBuilder(); - - public void indent() { - level++; - } - - public void unindent() { - level--; - } - - private void makeIndent() { - for (int i = 0; i < level; i++) { - buf.append(" "); - } - } - - public void print(final String arg) { - if (!indented) { - makeIndent(); - indented = true; - } - buf.append(arg); - } - - public void printLn(final String arg) { - print(arg); - printLn(); - } - - public void printLn() { - buf.append("\n"); - indented = false; - } - - public String getSource() { - return buf.toString(); - } - - @Override public String toString() { - return getSource(); - } - } - - private final SourcePrinter printer = new SourcePrinter(); - - public String getSource() { - return printer.getSource(); - } - - private void printModifiers(final int modifiers) { - if (ModifierSet.isPrivate(modifiers)) { - printer.print("private "); - } - if (ModifierSet.isProtected(modifiers)) { - printer.print("protected "); - } - if (ModifierSet.isPublic(modifiers)) { - printer.print("public "); - } - if (ModifierSet.isAbstract(modifiers)) { - printer.print("abstract "); - } - if (ModifierSet.isStatic(modifiers)) { - printer.print("static "); - } - if (ModifierSet.isFinal(modifiers)) { - printer.print("final "); - } - if (ModifierSet.isNative(modifiers)) { - printer.print("native "); - } - if (ModifierSet.isStrictfp(modifiers)) { - printer.print("strictfp "); - } - if (ModifierSet.isSynchronized(modifiers)) { - printer.print("synchronized "); - } - if (ModifierSet.isTransient(modifiers)) { - printer.print("transient "); - } - if (ModifierSet.isVolatile(modifiers)) { - printer.print("volatile "); - } - } - - private void printMembers(final List members, final Object arg) { - for (final BodyDeclaration member : members) { - printer.printLn(); - member.accept(this, arg); - printer.printLn(); - } - } - - private void printMemberAnnotations(final List annotations, final Object arg) { - if (!isNullOrEmpty(annotations)) { - for (final AnnotationExpr a : annotations) { - a.accept(this, arg); - printer.printLn(); - } - } - } - - private void printAnnotations(final List annotations, final Object arg) { - if (!isNullOrEmpty(annotations)) { - for (final AnnotationExpr a : annotations) { - a.accept(this, arg); - printer.print(" "); - } - } - } - - private void printTypeArgs(final List args, final Object arg) { - if (!isNullOrEmpty(args)) { - printer.print("<"); - for (final Iterator i = args.iterator(); i.hasNext();) { - final Type t = i.next(); - t.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - printer.print(">"); - } - } - - private void printTypeParameters(final List args, final Object arg) { - if (!isNullOrEmpty(args)) { - printer.print("<"); - for (final Iterator i = args.iterator(); i.hasNext();) { - final TypeParameter t = i.next(); - t.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - printer.print(">"); - } - } - - private void printArguments(final List args, final Object arg) { - printer.print("("); - if (!isNullOrEmpty(args)) { - for (final Iterator i = args.iterator(); i.hasNext();) { - final Expression e = i.next(); - e.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(")"); - } - - private void printJavadoc(final JavadocComment javadoc, final Object arg) { - if (javadoc != null) { - javadoc.accept(this, arg); - } - } - - private void printJavaComment(final Comment javacomment, final Object arg) { - if (javacomment != null) { - javacomment.accept(this, arg); - } - } - - @Override public void visit(final CompilationUnit n, final Object arg) { - printJavaComment(n.getComment(), arg); - - if (n.getPackage() != null) { - n.getPackage().accept(this, arg); - } - - if (n.getImports() != null) { - for (final ImportDeclaration i : n.getImports()) { - i.accept(this, arg); - } - printer.printLn(); - } - - if (n.getTypes() != null) { - for (final Iterator i = n.getTypes().iterator(); i.hasNext();) { - i.next().accept(this, arg); - printer.printLn(); - if (i.hasNext()) { - printer.printLn(); - } - } - } - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final PackageDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printAnnotations(n.getAnnotations(), arg); - printer.print("package "); - n.getName().accept(this, arg); - printer.printLn(";"); - printer.printLn(); - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final NameExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getName()); - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final QualifiedNameExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getQualifier().accept(this, arg); - printer.print("."); - printer.print(n.getName()); - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final ImportDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("import "); - if (n.isStatic()) { - printer.print("static "); - } - n.getName().accept(this, arg); - if (n.isAsterisk()) { - printer.print(".*"); - } - printer.printLn(";"); - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final ClassOrInterfaceDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - if (n.isInterface()) { - printer.print("interface "); - } else { - printer.print("class "); - } - - printer.print(n.getName()); - - printTypeParameters(n.getTypeParameters(), arg); - - if (!isNullOrEmpty(n.getExtends())) { - printer.print(" extends "); - for (final Iterator i = n.getExtends().iterator(); i.hasNext();) { - final ClassOrInterfaceType c = i.next(); - c.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - - if (!isNullOrEmpty(n.getImplements())) { - printer.print(" implements "); - for (final Iterator i = n.getImplements().iterator(); i.hasNext();) { - final ClassOrInterfaceType c = i.next(); - c.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - - printer.printLn(" {"); - printer.indent(); - if (!isNullOrEmpty(n.getMembers())) { - printMembers(n.getMembers(), arg); - } - - printOrphanCommentsEnding(n); - - printer.unindent(); - printer.print("}"); - } - - @Override public void visit(final EmptyTypeDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printer.print(";"); - - printOrphanCommentsEnding(n); - } - - @Override public void visit(final JavadocComment n, final Object arg) { - printer.print("/**"); - printer.print(n.getContent()); - printer.printLn("*/"); - } - - @Override public void visit(final ClassOrInterfaceType n, final Object arg) { - printJavaComment(n.getComment(), arg); - - if (n.getAnnotations() != null) { - for (AnnotationExpr ae : n.getAnnotations()) { - ae.accept(this, arg); - printer.print(" "); - } - } - - if (n.getScope() != null) { - n.getScope().accept(this, arg); - printer.print("."); - } - printer.print(n.getName()); - printTypeArgs(n.getTypeArgs(), arg); - } - - @Override public void visit(final TypeParameter n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (AnnotationExpr ann : n.getAnnotations()) { - ann.accept(this, arg); - printer.print(" "); - } - } - printer.print(n.getName()); - if (n.getTypeBound() != null) { - printer.print(" extends "); - for (final Iterator i = n.getTypeBound().iterator(); i.hasNext();) { - final ClassOrInterfaceType c = i.next(); - c.accept(this, arg); - if (i.hasNext()) { - printer.print(" & "); - } - } - } - } - - @Override public void visit(final PrimitiveType n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (AnnotationExpr ae : n.getAnnotations()) { - ae.accept(this, arg); - printer.print(" "); - } - } - switch (n.getType()) { - case Boolean: - printer.print("boolean"); - break; - case Byte: - printer.print("byte"); - break; - case Char: - printer.print("char"); - break; - case Double: - printer.print("double"); - break; - case Float: - printer.print("float"); - break; - case Int: - printer.print("int"); - break; - case Long: - printer.print("long"); - break; - case Short: - printer.print("short"); - break; - } - } - - @Override public void visit(final ReferenceType n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (AnnotationExpr ae : n.getAnnotations()) { - ae.accept(this, arg); - printer.print(" "); - } - } - n.getType().accept(this, arg); - List> arraysAnnotations = n.getArraysAnnotations(); - for (int i = 0; i < n.getArrayCount(); i++) { - if (arraysAnnotations != null && i < arraysAnnotations.size()) { - List annotations = arraysAnnotations.get(i); - if (annotations != null) { - for (AnnotationExpr ae : annotations) { - printer.print(" "); - ae.accept(this, arg); - - } - } - } - printer.print("[]"); - } - } - - @Override public void visit(final WildcardType n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (AnnotationExpr ae : n.getAnnotations()) { - printer.print(" "); - ae.accept(this, arg); - } - } - printer.print("?"); - if (n.getExtends() != null) { - printer.print(" extends "); - n.getExtends().accept(this, arg); - } - if (n.getSuper() != null) { - printer.print(" super "); - n.getSuper().accept(this, arg); - } - } - - @Override public void visit(final UnknownType n, final Object arg) { - // Nothing to dump - } - - @Override public void visit(final FieldDeclaration n, final Object arg) { - printOrphanCommentsBeforeThisChildNode(n); - - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - n.getType().accept(this, arg); - - printer.print(" "); - for (final Iterator i = n.getVariables().iterator(); i.hasNext();) { - final VariableDeclarator var = i.next(); - var.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - - printer.print(";"); - } - - @Override public void visit(final VariableDeclarator n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getId().accept(this, arg); - if (n.getInit() != null) { - printer.print(" = "); - n.getInit().accept(this, arg); - } - } - - @Override public void visit(final VariableDeclaratorId n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getName()); - for (int i = 0; i < n.getArrayCount(); i++) { - printer.print("[]"); - } - } - - @Override public void visit(final ArrayInitializerExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("{"); - if (n.getValues() != null) { - printer.print(" "); - for (final Iterator i = n.getValues().iterator(); i.hasNext();) { - final Expression expr = i.next(); - expr.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - printer.print(" "); - } - printer.print("}"); - } - - @Override public void visit(final VoidType n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("void"); - } - - @Override public void visit(final ArrayAccessExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getName().accept(this, arg); - printer.print("["); - n.getIndex().accept(this, arg); - printer.print("]"); - } - - @Override public void visit(final ArrayCreationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("new "); - n.getType().accept(this, arg); - List> arraysAnnotations = n.getArraysAnnotations(); - if (n.getDimensions() != null) { - int j = 0; - for (final Expression dim : n.getDimensions()) { - - if (arraysAnnotations != null && j < arraysAnnotations.size()) { - List annotations = arraysAnnotations.get(j); - if (annotations != null) { - for (AnnotationExpr ae : annotations) { - printer.print(" "); - ae.accept(this, arg); - } - } - } - printer.print("["); - dim.accept(this, arg); - printer.print("]"); - j++; - } - for (int i = 0; i < n.getArrayCount(); i++) { - if (arraysAnnotations != null && i < arraysAnnotations.size()) { - - List annotations = arraysAnnotations.get(i); - if (annotations != null) { - for (AnnotationExpr ae : annotations) { - printer.print(" "); - ae.accept(this, arg); - - } - } - } - printer.print("[]"); - } - - } else { - for (int i = 0; i < n.getArrayCount(); i++) { - if (arraysAnnotations != null && i < arraysAnnotations.size()) { - List annotations = arraysAnnotations.get(i); - if (annotations != null) { - for (AnnotationExpr ae : annotations) { - ae.accept(this, arg); - printer.print(" "); - } - } - } - printer.print("[]"); - } - printer.print(" "); - n.getInitializer().accept(this, arg); - } - } - - @Override public void visit(final AssignExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getTarget().accept(this, arg); - printer.print(" "); - switch (n.getOperator()) { - case assign: - printer.print("="); - break; - case and: - printer.print("&="); - break; - case or: - printer.print("|="); - break; - case xor: - printer.print("^="); - break; - case plus: - printer.print("+="); - break; - case minus: - printer.print("-="); - break; - case rem: - printer.print("%="); - break; - case slash: - printer.print("/="); - break; - case star: - printer.print("*="); - break; - case lShift: - printer.print("<<="); - break; - case rSignedShift: - printer.print(">>="); - break; - case rUnsignedShift: - printer.print(">>>="); - break; - } - printer.print(" "); - n.getValue().accept(this, arg); - } - - @Override public void visit(final BinaryExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getLeft().accept(this, arg); - printer.print(" "); - switch (n.getOperator()) { - case or: - printer.print("||"); - break; - case and: - printer.print("&&"); - break; - case binOr: - printer.print("|"); - break; - case binAnd: - printer.print("&"); - break; - case xor: - printer.print("^"); - break; - case equals: - printer.print("=="); - break; - case notEquals: - printer.print("!="); - break; - case less: - printer.print("<"); - break; - case greater: - printer.print(">"); - break; - case lessEquals: - printer.print("<="); - break; - case greaterEquals: - printer.print(">="); - break; - case lShift: - printer.print("<<"); - break; - case rSignedShift: - printer.print(">>"); - break; - case rUnsignedShift: - printer.print(">>>"); - break; - case plus: - printer.print("+"); - break; - case minus: - printer.print("-"); - break; - case times: - printer.print("*"); - break; - case divide: - printer.print("/"); - break; - case remainder: - printer.print("%"); - break; - } - printer.print(" "); - n.getRight().accept(this, arg); - } - - @Override public void visit(final CastExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("("); - n.getType().accept(this, arg); - printer.print(") "); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final ClassExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getType().accept(this, arg); - printer.print(".class"); - } - - @Override public void visit(final ConditionalExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - printer.print(" ? "); - n.getThenExpr().accept(this, arg); - printer.print(" : "); - n.getElseExpr().accept(this, arg); - } - - @Override public void visit(final EnclosedExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("("); - if (n.getInner() != null) { - n.getInner().accept(this, arg); - } - printer.print(")"); - } - - @Override public void visit(final FieldAccessExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getScope().accept(this, arg); - printer.print("."); - printer.print(n.getField()); - } - - @Override public void visit(final InstanceOfExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - printer.print(" instanceof "); - n.getType().accept(this, arg); - } - - @Override public void visit(final CharLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("'"); - printer.print(n.getValue()); - printer.print("'"); - } - - @Override public void visit(final DoubleLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getValue()); - } - - @Override public void visit(final IntegerLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getValue()); - } - - @Override public void visit(final LongLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getValue()); - } - - @Override public void visit(final IntegerLiteralMinValueExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getValue()); - } - - @Override public void visit(final LongLiteralMinValueExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getValue()); - } - - @Override public void visit(final StringLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("\""); - printer.print(n.getValue()); - printer.print("\""); - } - - @Override public void visit(final BooleanLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(String.valueOf(n.getValue())); - } - - @Override public void visit(final NullLiteralExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("null"); - } - - @Override public void visit(final ThisExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - printer.print("."); - } - printer.print("this"); - } - - @Override public void visit(final SuperExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - printer.print("."); - } - printer.print("super"); - } - - @Override public void visit(final MethodCallExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - printer.print("."); - } - printTypeArgs(n.getTypeArgs(), arg); - printer.print(n.getName()); - printArguments(n.getArgs(), arg); - } - - @Override public void visit(final ObjectCreationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - printer.print("."); - } - - printer.print("new "); - - printTypeArgs(n.getTypeArgs(), arg); - if (!isNullOrEmpty(n.getTypeArgs())) { - printer.print(" "); - } - - n.getType().accept(this, arg); - - printArguments(n.getArgs(), arg); - - if (n.getAnonymousClassBody() != null) { - printer.printLn(" {"); - printer.indent(); - printMembers(n.getAnonymousClassBody(), arg); - printer.unindent(); - printer.print("}"); - } - } - - @Override public void visit(final UnaryExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - switch (n.getOperator()) { - case positive: - printer.print("+"); - break; - case negative: - printer.print("-"); - break; - case inverse: - printer.print("~"); - break; - case not: - printer.print("!"); - break; - case preIncrement: - printer.print("++"); - break; - case preDecrement: - printer.print("--"); - break; - default: - } - - n.getExpr().accept(this, arg); - - switch (n.getOperator()) { - case posIncrement: - printer.print("++"); - break; - case posDecrement: - printer.print("--"); - break; - default: - } - } - - @Override public void visit(final ConstructorDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - printTypeParameters(n.getTypeParameters(), arg); - if (n.getTypeParameters() != null) { - printer.print(" "); - } - printer.print(n.getName()); - - printer.print("("); - if (n.getParameters() != null) { - for (final Iterator i = n.getParameters().iterator(); i.hasNext();) { - final Parameter p = i.next(); - p.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(")"); - - if (!isNullOrEmpty(n.getThrows())) { - printer.print(" throws "); - for (final Iterator i = n.getThrows().iterator(); i.hasNext();) { - final NameExpr name = i.next(); - name.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(" "); - n.getBlock().accept(this, arg); - } - - @Override public void visit(final MethodDeclaration n, final Object arg) { - printOrphanCommentsBeforeThisChildNode(n); - - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - if (n.isDefault()) { - printer.print("default "); - } - printTypeParameters(n.getTypeParameters(), arg); - if (n.getTypeParameters() != null) { - printer.print(" "); - } - - n.getType().accept(this, arg); - printer.print(" "); - printer.print(n.getName()); - - printer.print("("); - if (n.getParameters() != null) { - for (final Iterator i = n.getParameters().iterator(); i.hasNext();) { - final Parameter p = i.next(); - p.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(")"); - - for (int i = 0; i < n.getArrayCount(); i++) { - printer.print("[]"); - } - - if (!isNullOrEmpty(n.getThrows())) { - printer.print(" throws "); - for (final Iterator i = n.getThrows().iterator(); i.hasNext();) { - final NameExpr name = i.next(); - name.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - if (n.getBody() == null) { - printer.print(";"); - } else { - printer.print(" "); - n.getBody().accept(this, arg); - } - } - - @Override public void visit(final Parameter n, final Object arg) { - printJavaComment(n.getComment(), arg); - printAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - if (n.getType() != null) { - n.getType().accept(this, arg); - } - if (n.isVarArgs()) { - printer.print("..."); - } - printer.print(" "); - n.getId().accept(this, arg); - } - - @Override public void visit(MultiTypeParameter n, Object arg) { - printAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - Iterator types = n.getTypes().iterator(); - types.next().accept(this, arg); - while (types.hasNext()) { - printer.print(" | "); - types.next().accept(this, arg); - } - - printer.print(" "); - n.getId().accept(this, arg); - } - - @Override public void visit(final ExplicitConstructorInvocationStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.isThis()) { - printTypeArgs(n.getTypeArgs(), arg); - printer.print("this"); - } else { - if (n.getExpr() != null) { - n.getExpr().accept(this, arg); - printer.print("."); - } - printTypeArgs(n.getTypeArgs(), arg); - printer.print("super"); - } - printArguments(n.getArgs(), arg); - printer.print(";"); - } - - @Override public void visit(final VariableDeclarationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - n.getType().accept(this, arg); - printer.print(" "); - - for (final Iterator i = n.getVars().iterator(); i.hasNext();) { - final VariableDeclarator v = i.next(); - v.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - - @Override public void visit(final TypeDeclarationStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - n.getTypeDeclaration().accept(this, arg); - } - - @Override public void visit(final AssertStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("assert "); - n.getCheck().accept(this, arg); - if (n.getMessage() != null) { - printer.print(" : "); - n.getMessage().accept(this, arg); - } - printer.print(";"); - } - - @Override public void visit(final BlockStmt n, final Object arg) { - printOrphanCommentsBeforeThisChildNode(n); - printJavaComment(n.getComment(), arg); - printer.printLn("{"); - if (n.getStmts() != null) { - printer.indent(); - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - printer.printLn(); - } - printer.unindent(); - } - printer.print("}"); - - } - - @Override public void visit(final LabeledStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getLabel()); - printer.print(": "); - n.getStmt().accept(this, arg); - } - - @Override public void visit(final EmptyStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(";"); - } - - @Override public void visit(final ExpressionStmt n, final Object arg) { - printOrphanCommentsBeforeThisChildNode(n); - printJavaComment(n.getComment(), arg); - n.getExpression().accept(this, arg); - printer.print(";"); - } - - @Override public void visit(final SwitchStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("switch("); - n.getSelector().accept(this, arg); - printer.printLn(") {"); - if (n.getEntries() != null) { - printer.indent(); - for (final SwitchEntryStmt e : n.getEntries()) { - e.accept(this, arg); - } - printer.unindent(); - } - printer.print("}"); - - } - - @Override public void visit(final SwitchEntryStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getLabel() != null) { - printer.print("case "); - n.getLabel().accept(this, arg); - printer.print(":"); - } else { - printer.print("default:"); - } - printer.printLn(); - printer.indent(); - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - printer.printLn(); - } - } - printer.unindent(); - } - - @Override public void visit(final BreakStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("break"); - if (n.getId() != null) { - printer.print(" "); - printer.print(n.getId()); - } - printer.print(";"); - } - - @Override public void visit(final ReturnStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("return"); - if (n.getExpr() != null) { - printer.print(" "); - n.getExpr().accept(this, arg); - } - printer.print(";"); - } - - @Override public void visit(final EnumDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - printer.print("enum "); - printer.print(n.getName()); - - if (n.getImplements() != null) { - printer.print(" implements "); - for (final Iterator i = n.getImplements().iterator(); i.hasNext();) { - final ClassOrInterfaceType c = i.next(); - c.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - - printer.printLn(" {"); - printer.indent(); - if (n.getEntries() != null) { - printer.printLn(); - for (final Iterator i = n.getEntries().iterator(); i.hasNext();) { - final EnumConstantDeclaration e = i.next(); - e.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - if (n.getMembers() != null) { - printer.printLn(";"); - printMembers(n.getMembers(), arg); - } else { - if (n.getEntries() != null) { - printer.printLn(); - } - } - printer.unindent(); - printer.print("}"); - } - - @Override public void visit(final EnumConstantDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printer.print(n.getName()); - - if (n.getArgs() != null) { - printArguments(n.getArgs(), arg); - } - - if (n.getClassBody() != null) { - printer.printLn(" {"); - printer.indent(); - printMembers(n.getClassBody(), arg); - printer.unindent(); - printer.printLn("}"); - } - } - - @Override public void visit(final EmptyMemberDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printer.print(";"); - } - - @Override public void visit(final InitializerDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - if (n.isStatic()) { - printer.print("static "); - } - n.getBlock().accept(this, arg); - } - - @Override public void visit(final IfStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("if ("); - n.getCondition().accept(this, arg); - final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (thenBlock) // block statement should start on the same line - printer.print(") "); - else { - printer.printLn(")"); - printer.indent(); - } - n.getThenStmt().accept(this, arg); - if (!thenBlock) - printer.unindent(); - if (n.getElseStmt() != null) { - if (thenBlock) - printer.print(" "); - else - printer.printLn(); - final boolean elseIf = n.getElseStmt() instanceof IfStmt; - final boolean elseBlock = n.getElseStmt() instanceof BlockStmt; - if (elseIf || elseBlock) // put chained if and start of block statement on a same level - printer.print("else "); - else { - printer.printLn("else"); - printer.indent(); - } - n.getElseStmt().accept(this, arg); - if (!(elseIf || elseBlock)) - printer.unindent(); - } - } - - @Override public void visit(final WhileStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("while ("); - n.getCondition().accept(this, arg); - printer.print(") "); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ContinueStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("continue"); - if (n.getId() != null) { - printer.print(" "); - printer.print(n.getId()); - } - printer.print(";"); - } - - @Override public void visit(final DoStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("do "); - n.getBody().accept(this, arg); - printer.print(" while ("); - n.getCondition().accept(this, arg); - printer.print(");"); - } - - @Override public void visit(final ForeachStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("for ("); - n.getVariable().accept(this, arg); - printer.print(" : "); - n.getIterable().accept(this, arg); - printer.print(") "); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ForStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("for ("); - if (n.getInit() != null) { - for (final Iterator i = n.getInit().iterator(); i.hasNext();) { - final Expression e = i.next(); - e.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print("; "); - if (n.getCompare() != null) { - n.getCompare().accept(this, arg); - } - printer.print("; "); - if (n.getUpdate() != null) { - for (final Iterator i = n.getUpdate().iterator(); i.hasNext();) { - final Expression e = i.next(); - e.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(") "); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ThrowStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("throw "); - n.getExpr().accept(this, arg); - printer.print(";"); - } - - @Override public void visit(final SynchronizedStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("synchronized ("); - n.getExpr().accept(this, arg); - printer.print(") "); - n.getBlock().accept(this, arg); - } - - @Override public void visit(final TryStmt n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("try "); - if (!n.getResources().isEmpty()) { - printer.print("("); - Iterator resources = n.getResources().iterator(); - boolean first = true; - while (resources.hasNext()) { - visit(resources.next(), arg); - if (resources.hasNext()) { - printer.print(";"); - printer.printLn(); - if (first) { - printer.indent(); - } - } - first = false; - } - if (n.getResources().size() > 1) { - printer.unindent(); - } - printer.print(") "); - } - n.getTryBlock().accept(this, arg); - if (n.getCatchs() != null) { - for (final CatchClause c : n.getCatchs()) { - c.accept(this, arg); - } - } - if (n.getFinallyBlock() != null) { - printer.print(" finally "); - n.getFinallyBlock().accept(this, arg); - } - } - - @Override public void visit(final CatchClause n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(" catch ("); - n.getExcept().accept(this, arg); - printer.print(") "); - n.getCatchBlock().accept(this, arg); - - } - - @Override public void visit(final AnnotationDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - printer.print("@interface "); - printer.print(n.getName()); - printer.printLn(" {"); - printer.indent(); - if (n.getMembers() != null) { - printMembers(n.getMembers(), arg); - } - printer.unindent(); - printer.print("}"); - } - - @Override public void visit(final AnnotationMemberDeclaration n, final Object arg) { - printJavaComment(n.getComment(), arg); - printJavadoc(n.getJavaDoc(), arg); - printMemberAnnotations(n.getAnnotations(), arg); - printModifiers(n.getModifiers()); - - n.getType().accept(this, arg); - printer.print(" "); - printer.print(n.getName()); - printer.print("()"); - if (n.getDefaultValue() != null) { - printer.print(" default "); - n.getDefaultValue().accept(this, arg); - } - printer.print(";"); - } - - @Override public void visit(final MarkerAnnotationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("@"); - n.getName().accept(this, arg); - } - - @Override public void visit(final SingleMemberAnnotationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("@"); - n.getName().accept(this, arg); - printer.print("("); - n.getMemberValue().accept(this, arg); - printer.print(")"); - } - - @Override public void visit(final NormalAnnotationExpr n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print("@"); - n.getName().accept(this, arg); - printer.print("("); - if (n.getPairs() != null) { - for (final Iterator i = n.getPairs().iterator(); i.hasNext();) { - final MemberValuePair m = i.next(); - m.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - printer.print(")"); - } - - @Override public void visit(final MemberValuePair n, final Object arg) { - printJavaComment(n.getComment(), arg); - printer.print(n.getName()); - printer.print(" = "); - n.getValue().accept(this, arg); - } - - @Override public void visit(final LineComment n, final Object arg) { - if (!this.printComments) { - return; - } - printer.print("//"); - String tmp = n.getContent(); - tmp = tmp.replace('\r', ' '); - tmp = tmp.replace('\n', ' '); - printer.printLn(tmp); - } - - @Override public void visit(final BlockComment n, final Object arg) { - if (!this.printComments) { - return; - } - printer.print("/*"); - printer.print(n.getContent()); - printer.printLn("*/"); - } - - @Override - public void visit(LambdaExpr n, Object arg) { - printJavaComment(n.getComment(), arg); - - List parameters = n.getParameters(); - boolean printPar = false; - printPar = n.isParametersEnclosed(); - - if (printPar) { - printer.print("("); - } - if (parameters != null) { - for (Iterator i = parameters.iterator(); i.hasNext();) { - Parameter p = i.next(); - p.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - } - if (printPar) { - printer.print(")"); - } - - printer.print("->"); - Statement body = n.getBody(); - String bodyStr = body.toString(); - if (body instanceof ExpressionStmt) { - // removing ';' - bodyStr = bodyStr.substring(0, bodyStr.length() - 1); - } - printer.print(bodyStr); - - } - - - @Override - public void visit(MethodReferenceExpr n, Object arg) { - printJavaComment(n.getComment(), arg); - Expression scope = n.getScope(); - String identifier = n.getIdentifier(); - if (scope != null) { - n.getScope().accept(this, arg); - } - - printer.print("::"); - if (n.getTypeParameters() != null) { - printer.print("<"); - for (Iterator i = n.getTypeParameters().iterator(); i - .hasNext();) { - TypeParameter p = i.next(); - p.accept(this, arg); - if (i.hasNext()) { - printer.print(", "); - } - } - printer.print(">"); - } - if (identifier != null) { - printer.print(identifier); - } - - } - - @Override - public void visit(TypeExpr n, Object arg) { - printJavaComment(n.getComment(), arg); - if (n.getType() != null) { - n.getType().accept(this, arg); - } - } - - private void printOrphanCommentsBeforeThisChildNode(final Node node){ - if (node instanceof Comment) return; - - Node parent = node.getParentNode(); - if (parent==null) return; - List everything = new LinkedList(); - everything.addAll(parent.getChildrenNodes()); - sortByBeginPosition(everything); - int positionOfTheChild = -1; - for (int i=0;i=0 && positionOfPreviousChild==-1;i--){ - if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; - } - for (int i=positionOfPreviousChild+1;i everything = new LinkedList(); - everything.addAll(node.getChildrenNodes()); - sortByBeginPosition(everything); - if (everything.size()==0) return; - - int commentsAtEnd = 0; - boolean findingComments = true; - while (findingComments&&commentsAtEnd. - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BaseParameter; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -import java.util.Iterator; -import java.util.List; - -/** - * @author Julio Vilmar Gesser - */ -public class EqualsVisitor implements GenericVisitor { - - private static final EqualsVisitor SINGLETON = new EqualsVisitor(); - - public static boolean equals(final Node n1, final Node n2) { - return SINGLETON.nodeEquals(n1, n2); - } - - private EqualsVisitor() { - // hide constructor - } - - /** - * Check for equality that can be applied to each kind of node, - * to not repeat it in every method we store that here. - */ - private boolean commonNodeEquality(Node n1, Node n2) { - if (!nodeEquals(n1.getComment(), n2.getComment())) { - return false; - } - if (!nodesEquals(n1.getOrphanComments(), n2.getOrphanComments())){ - return false; - } - return true; - } - - private boolean nodesEquals(final List nodes1, final List nodes2) { - if (nodes1 == null) { - if (nodes2 == null) { - return true; - } - return false; - } else if (nodes2 == null) { - return false; - } - if (nodes1.size() != nodes2.size()) { - return false; - } - for (int i = 0; i < nodes1.size(); i++) { - if (!nodeEquals(nodes1.get(i), nodes2.get(i))) { - return false; - } - } - return true; - } - - private boolean nodeEquals(final T n1, final T n2) { - if (n1 == n2) { - return true; - } - if (n1 == null) { - if (n2 == null) { - return true; - } - return false; - } else if (n2 == null) { - return false; - } - if (n1.getClass() != n2.getClass()) { - return false; - } - if (!commonNodeEquality(n1, n2)){ - return false; - } - return n1.accept(this, n2).booleanValue(); - } - - private boolean objEquals(final Object n1, final Object n2) { - if (n1 == n2) { - return true; - } - if (n1 == null) { - if (n2 == null) { - return true; - } - return false; - } else if (n2 == null) { - return false; - } - return n1.equals(n2); - } - - @Override public Boolean visit(final CompilationUnit n1, final Node arg) { - final CompilationUnit n2 = (CompilationUnit) arg; - - if (!nodeEquals(n1.getPackage(), n2.getPackage())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getImports(), n2.getImports())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypes(), n2.getTypes())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getComments(), n2.getComments())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final PackageDeclaration n1, final Node arg) { - final PackageDeclaration n2 = (PackageDeclaration) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ImportDeclaration n1, final Node arg) { - final ImportDeclaration n2 = (ImportDeclaration) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final TypeParameter n1, final Node arg) { - final TypeParameter n2 = (TypeParameter) arg; - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeBound(), n2.getTypeBound())) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final LineComment n1, final Node arg) { - final LineComment n2 = (LineComment) arg; - - if (!objEquals(n1.getContent(), n2.getContent())) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getBeginLine(), n2.getBeginLine())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final BlockComment n1, final Node arg) { - final BlockComment n2 = (BlockComment) arg; - - if (!objEquals(n1.getContent(), n2.getContent())) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getBeginLine(), n2.getBeginLine())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ClassOrInterfaceDeclaration n1, final Node arg) { - final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (n1.isInterface() != n2.isInterface()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getExtends(), n2.getExtends())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getImplements(), n2.getImplements())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getMembers(), n2.getMembers())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final EnumDeclaration n1, final Node arg) { - final EnumDeclaration n2 = (EnumDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getImplements(), n2.getImplements())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getEntries(), n2.getEntries())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getMembers(), n2.getMembers())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final EmptyTypeDeclaration n1, final Node arg) { - return Boolean.TRUE; - } - - @Override public Boolean visit(final EnumConstantDeclaration n1, final Node arg) { - final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getArgs(), n2.getArgs())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getClassBody(), n2.getClassBody())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final AnnotationDeclaration n1, final Node arg) { - final AnnotationDeclaration n2 = (AnnotationDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getMembers(), n2.getMembers())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final AnnotationMemberDeclaration n1, final Node arg) { - final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getDefaultValue(), n2.getDefaultValue())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final FieldDeclaration n1, final Node arg) { - final FieldDeclaration n2 = (FieldDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getVariables(), n2.getVariables())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final VariableDeclarator n1, final Node arg) { - final VariableDeclarator n2 = (VariableDeclarator) arg; - - if (!nodeEquals(n1.getId(), n2.getId())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getInit(), n2.getInit())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final VariableDeclaratorId n1, final Node arg) { - final VariableDeclaratorId n2 = (VariableDeclaratorId) arg; - - if (n1.getArrayCount() != n2.getArrayCount()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ConstructorDeclaration n1, final Node arg) { - final ConstructorDeclaration n2 = (ConstructorDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBlock(), n2.getBlock())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getParameters(), n2.getParameters())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getThrows(), n2.getThrows())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final MethodDeclaration n1, final Node arg) { - final MethodDeclaration n2 = (MethodDeclaration) arg; - - // javadoc are checked at CompilationUnit - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (n1.getArrayCount() != n2.getArrayCount()) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getParameters(), n2.getParameters())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getThrows(), n2.getThrows())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { - return Boolean.FALSE; - } - if(n1.isDefault() != n2.isDefault()){ - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final Parameter n1, final Node arg) { - final Parameter n2 = (Parameter) arg; - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - return visit((BaseParameter) n1, arg); - } - - @Override public Boolean visit(MultiTypeParameter n1, Node arg) { - MultiTypeParameter n2 = (MultiTypeParameter) arg; - if (n1.getTypes().size() != n2.getTypes().size()) { - return Boolean.FALSE; - } - Iterator n1types = n1.getTypes().iterator(); - Iterator n2types = n2.getTypes().iterator(); - while (n1types.hasNext() && n2types.hasNext()) { - if (!nodeEquals(n1types.next(), n2types.next())) { - return Boolean.FALSE; - } - } - return visit((BaseParameter) n1, arg); - } - - protected Boolean visit(final BaseParameter n1, final Node arg) { - final BaseParameter n2 = (BaseParameter) arg; - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getId(), n2.getId())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final EmptyMemberDeclaration n1, final Node arg) { - return Boolean.TRUE; - } - - @Override public Boolean visit(final InitializerDeclaration n1, final Node arg) { - final InitializerDeclaration n2 = (InitializerDeclaration) arg; - - if (!nodeEquals(n1.getBlock(), n2.getBlock())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final JavadocComment n1, final Node arg) { - final JavadocComment n2 = (JavadocComment) arg; - - if (!objEquals(n1.getContent(), n2.getContent())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ClassOrInterfaceType n1, final Node arg) { - final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg; - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getScope(), n2.getScope())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final PrimitiveType n1, final Node arg) { - final PrimitiveType n2 = (PrimitiveType) arg; - - if (n1.getType() != n2.getType()) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final ReferenceType n1, final Node arg) { - final ReferenceType n2 = (ReferenceType) arg; - - if (n1.getArrayCount() != n2.getArrayCount()) { - return Boolean.FALSE; - } - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - List> n1a = n1.getArraysAnnotations(); - List> n2a = n2.getArraysAnnotations(); - - if (n1a !=null && n2a!= null) { - if(n1a.size() != n2a.size()){ - return Boolean.FALSE; - } - else{ - int i = 0; - for(List aux: n1a){ - if(!nodesEquals(aux, n2a.get(i))){ - return Boolean.FALSE; - } - i++; - } - } - } - else if (n1a != n2a){ - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - public Boolean visit(VoidType n1, Node arg) { - VoidType n2 = (VoidType) arg; - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final WildcardType n1, final Node arg) { - final WildcardType n2 = (WildcardType) arg; - - if (!nodeEquals(n1.getExtends(), n2.getExtends())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getSuper(), n2.getSuper())) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final UnknownType n1, final Node arg) { - final WildcardType n2 = (WildcardType) arg; - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final ArrayAccessExpr n1, final Node arg) { - final ArrayAccessExpr n2 = (ArrayAccessExpr) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getIndex(), n2.getIndex())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ArrayCreationExpr n1, final Node arg) { - final ArrayCreationExpr n2 = (ArrayCreationExpr) arg; - - if (n1.getArrayCount() != n2.getArrayCount()) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getInitializer(), n2.getInitializer())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getDimensions(), n2.getDimensions())) { - return Boolean.FALSE; - } - List> n1a = n1.getArraysAnnotations(); - List> n2a = n2.getArraysAnnotations(); - - if (n1a !=null && n2a!= null) { - if(n1a.size() != n2a.size()){ - return Boolean.FALSE; - } - else{ - int i = 0; - for(List aux: n1a){ - if(!nodesEquals(aux, n2a.get(i))){ - return Boolean.FALSE; - } - i++; - } - } - } - else if (n1a != n2a){ - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override public Boolean visit(final ArrayInitializerExpr n1, final Node arg) { - final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg; - - if (!nodesEquals(n1.getValues(), n2.getValues())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final AssignExpr n1, final Node arg) { - final AssignExpr n2 = (AssignExpr) arg; - - if (n1.getOperator() != n2.getOperator()) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getTarget(), n2.getTarget())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final BinaryExpr n1, final Node arg) { - final BinaryExpr n2 = (BinaryExpr) arg; - - if (n1.getOperator() != n2.getOperator()) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getLeft(), n2.getLeft())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getRight(), n2.getRight())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final CastExpr n1, final Node arg) { - final CastExpr n2 = (CastExpr) arg; - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ClassExpr n1, final Node arg) { - final ClassExpr n2 = (ClassExpr) arg; - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ConditionalExpr n1, final Node arg) { - final ConditionalExpr n2 = (ConditionalExpr) arg; - - if (!nodeEquals(n1.getCondition(), n2.getCondition())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getThenExpr(), n2.getThenExpr())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getElseExpr(), n2.getElseExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final EnclosedExpr n1, final Node arg) { - final EnclosedExpr n2 = (EnclosedExpr) arg; - - if (!nodeEquals(n1.getInner(), n2.getInner())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final FieldAccessExpr n1, final Node arg) { - final FieldAccessExpr n2 = (FieldAccessExpr) arg; - - if (!nodeEquals(n1.getScope(), n2.getScope())) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getField(), n2.getField())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final InstanceOfExpr n1, final Node arg) { - final InstanceOfExpr n2 = (InstanceOfExpr) arg; - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final StringLiteralExpr n1, final Node arg) { - final StringLiteralExpr n2 = (StringLiteralExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final IntegerLiteralExpr n1, final Node arg) { - final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final LongLiteralExpr n1, final Node arg) { - final LongLiteralExpr n2 = (LongLiteralExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final IntegerLiteralMinValueExpr n1, final Node arg) { - final IntegerLiteralMinValueExpr n2 = (IntegerLiteralMinValueExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final LongLiteralMinValueExpr n1, final Node arg) { - final LongLiteralMinValueExpr n2 = (LongLiteralMinValueExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final CharLiteralExpr n1, final Node arg) { - final CharLiteralExpr n2 = (CharLiteralExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final DoubleLiteralExpr n1, final Node arg) { - final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg; - - if (!objEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final BooleanLiteralExpr n1, final Node arg) { - final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg; - - if (n1.getValue() != n2.getValue()) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final NullLiteralExpr n1, final Node arg) { - return Boolean.TRUE; - } - - @Override public Boolean visit(final MethodCallExpr n1, final Node arg) { - final MethodCallExpr n2 = (MethodCallExpr) arg; - - if (!nodeEquals(n1.getScope(), n2.getScope())) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getArgs(), n2.getArgs())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final NameExpr n1, final Node arg) { - final NameExpr n2 = (NameExpr) arg; - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ObjectCreationExpr n1, final Node arg) { - final ObjectCreationExpr n2 = (ObjectCreationExpr) arg; - - if (!nodeEquals(n1.getScope(), n2.getScope())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnonymousClassBody(), n2.getAnonymousClassBody())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getArgs(), n2.getArgs())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final QualifiedNameExpr n1, final Node arg) { - final QualifiedNameExpr n2 = (QualifiedNameExpr) arg; - - if (!nodeEquals(n1.getQualifier(), n2.getQualifier())) { - return Boolean.FALSE; - } - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ThisExpr n1, final Node arg) { - final ThisExpr n2 = (ThisExpr) arg; - - if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final SuperExpr n1, final Node arg) { - final SuperExpr n2 = (SuperExpr) arg; - - if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final UnaryExpr n1, final Node arg) { - final UnaryExpr n2 = (UnaryExpr) arg; - - if (n1.getOperator() != n2.getOperator()) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final VariableDeclarationExpr n1, final Node arg) { - final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg; - - if (n1.getModifiers() != n2.getModifiers()) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getType(), n2.getType())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getVars(), n2.getVars())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final MarkerAnnotationExpr n1, final Node arg) { - final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final SingleMemberAnnotationExpr n1, final Node arg) { - final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getMemberValue(), n2.getMemberValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final NormalAnnotationExpr n1, final Node arg) { - final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg; - - if (!nodeEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getPairs(), n2.getPairs())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final MemberValuePair n1, final Node arg) { - final MemberValuePair n2 = (MemberValuePair) arg; - - if (!objEquals(n1.getName(), n2.getName())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getValue(), n2.getValue())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ExplicitConstructorInvocationStmt n1, final Node arg) { - final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg; - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getArgs(), n2.getArgs())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final TypeDeclarationStmt n1, final Node arg) { - final TypeDeclarationStmt n2 = (TypeDeclarationStmt) arg; - - if (!nodeEquals(n1.getTypeDeclaration(), n2.getTypeDeclaration())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final AssertStmt n1, final Node arg) { - final AssertStmt n2 = (AssertStmt) arg; - - if (!nodeEquals(n1.getCheck(), n2.getCheck())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getMessage(), n2.getMessage())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final BlockStmt n1, final Node arg) { - final BlockStmt n2 = (BlockStmt) arg; - - if (!nodesEquals(n1.getStmts(), n2.getStmts())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final LabeledStmt n1, final Node arg) { - final LabeledStmt n2 = (LabeledStmt) arg; - - if (!nodeEquals(n1.getStmt(), n2.getStmt())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final EmptyStmt n1, final Node arg) { - return Boolean.TRUE; - } - - @Override public Boolean visit(final ExpressionStmt n1, final Node arg) { - final ExpressionStmt n2 = (ExpressionStmt) arg; - - if (!nodeEquals(n1.getExpression(), n2.getExpression())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final SwitchStmt n1, final Node arg) { - final SwitchStmt n2 = (SwitchStmt) arg; - - if (!nodeEquals(n1.getSelector(), n2.getSelector())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getEntries(), n2.getEntries())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final SwitchEntryStmt n1, final Node arg) { - final SwitchEntryStmt n2 = (SwitchEntryStmt) arg; - - if (!nodeEquals(n1.getLabel(), n2.getLabel())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getStmts(), n2.getStmts())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final BreakStmt n1, final Node arg) { - final BreakStmt n2 = (BreakStmt) arg; - - if (!objEquals(n1.getId(), n2.getId())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ReturnStmt n1, final Node arg) { - final ReturnStmt n2 = (ReturnStmt) arg; - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final IfStmt n1, final Node arg) { - final IfStmt n2 = (IfStmt) arg; - - if (!nodeEquals(n1.getCondition(), n2.getCondition())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getThenStmt(), n2.getThenStmt())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final WhileStmt n1, final Node arg) { - final WhileStmt n2 = (WhileStmt) arg; - - if (!nodeEquals(n1.getCondition(), n2.getCondition())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ContinueStmt n1, final Node arg) { - final ContinueStmt n2 = (ContinueStmt) arg; - - if (!objEquals(n1.getId(), n2.getId())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final DoStmt n1, final Node arg) { - final DoStmt n2 = (DoStmt) arg; - - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getCondition(), n2.getCondition())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ForeachStmt n1, final Node arg) { - final ForeachStmt n2 = (ForeachStmt) arg; - - if (!nodeEquals(n1.getVariable(), n2.getVariable())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getIterable(), n2.getIterable())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ForStmt n1, final Node arg) { - final ForStmt n2 = (ForStmt) arg; - - if (!nodesEquals(n1.getInit(), n2.getInit())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getCompare(), n2.getCompare())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getUpdate(), n2.getUpdate())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final ThrowStmt n1, final Node arg) { - final ThrowStmt n2 = (ThrowStmt) arg; - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final SynchronizedStmt n1, final Node arg) { - final SynchronizedStmt n2 = (SynchronizedStmt) arg; - - if (!nodeEquals(n1.getExpr(), n2.getExpr())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getBlock(), n2.getBlock())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final TryStmt n1, final Node arg) { - final TryStmt n2 = (TryStmt) arg; - - if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) { - return Boolean.FALSE; - } - - if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override public Boolean visit(final CatchClause n1, final Node arg) { - final CatchClause n2 = (CatchClause) arg; - - if (!nodeEquals(n1.getExcept(), n2.getExcept())) { - return Boolean.FALSE; - } - - if (!nodeEquals(n1.getCatchBlock(), n2.getCatchBlock())) { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - @Override - public Boolean visit(LambdaExpr n1, Node arg) { - LambdaExpr n2 = (LambdaExpr) arg; - if (!nodesEquals(n1.getParameters(), n2.getParameters())) { - return Boolean.FALSE; - } - if(n1.isParametersEnclosed() != n2.isParametersEnclosed()){ - return Boolean.FALSE; - } - if (!nodeEquals(n1.getBody(), n2.getBody())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override - public Boolean visit(MethodReferenceExpr n1, Node arg) { - MethodReferenceExpr n2 = (MethodReferenceExpr) arg; - if (!nodeEquals(n1.getScope(), n2.getScope())) { - return Boolean.FALSE; - } - if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { - return Boolean.FALSE; - } - if (!objEquals(n1.getIdentifier(), n2.getIdentifier())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - @Override - public Boolean visit(TypeExpr n, Node arg) { - TypeExpr n2 = (TypeExpr) arg; - if (!nodeEquals(n.getType(), n2.getType())) { - return Boolean.FALSE; - } - return Boolean.TRUE; - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; + +/** + * A visitor that calculates deep node equality by comparing all properties and child nodes of the node. + * + * @author Julio Vilmar Gesser + */ +public class EqualsVisitor implements GenericVisitor { + + private static final EqualsVisitor SINGLETON = new EqualsVisitor(); + + public static boolean equals(final Node n, final Node n2) { + return SINGLETON.nodeEquals(n, n2); + } + + private EqualsVisitor() { + // hide constructor + } + + /** + * Check for equality that can be applied to each kind of node, + * to not repeat it in every method we store that here. + */ + private boolean commonNodeEquality(Node n, Node n2) { + if (!nodeEquals(n.getComment(), n2.getComment())) { + return false; + } + return nodesEquals(n.getOrphanComments(), n2.getOrphanComments()); + } + + private boolean nodesEquals(final List nodes1, final List nodes2) { + if (nodes1 == null) { + return nodes2 == null; + } else if (nodes2 == null) { + return false; + } + if (nodes1.size() != nodes2.size()) { + return false; + } + for (int i = 0; i < nodes1.size(); i++) { + if (!nodeEquals(nodes1.get(i), nodes2.get(i))) { + return false; + } + } + return true; + } + + private boolean nodesEquals(NodeList n, NodeList n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + if (n.size() != n2.size()) { + return false; + } + for (int i = 0; i < n.size(); i++) { + if (!nodeEquals(n.get(i), n2.get(i))) { + return false; + } + } + return true; + } + + private boolean nodeEquals(final T n, final T n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + if (n.getClass() != n2.getClass()) { + return false; + } + if (!commonNodeEquality(n, n2)) { + return false; + } + return n.accept(this, n2); + } + + private boolean nodeEquals(final Optional n, final Optional n2) { + return nodeEquals(n.orElse(null), n2.orElse(null)); + } + + private boolean nodesEquals(final Optional> n, final Optional> n2) { + return nodesEquals(n.orElse(null), n2.orElse(null)); + } + + private boolean objEquals(final Object n, final Object n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + return n.equals(n2); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final CompilationUnit n, final Visitable arg) { + final CompilationUnit n2 = (CompilationUnit) arg; + if (!nodesEquals(n.getImports(), n2.getImports())) + return false; + if (!nodeEquals(n.getModule(), n2.getModule())) + return false; + if (!nodeEquals(n.getPackageDeclaration(), n2.getPackageDeclaration())) + return false; + if (!nodesEquals(n.getTypes(), n2.getTypes())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final PackageDeclaration n, final Visitable arg) { + final PackageDeclaration n2 = (PackageDeclaration) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final TypeParameter n, final Visitable arg) { + final TypeParameter n2 = (TypeParameter) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getTypeBound(), n2.getTypeBound())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final LineComment n, final Visitable arg) { + final LineComment n2 = (LineComment) arg; + if (!objEquals(n.getContent(), n2.getContent())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final BlockComment n, final Visitable arg) { + final BlockComment n2 = (BlockComment) arg; + if (!objEquals(n.getContent(), n2.getContent())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) { + final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg; + if (!nodesEquals(n.getExtendedTypes(), n2.getExtendedTypes())) + return false; + if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes())) + return false; + if (!objEquals(n.isInterface(), n2.isInterface())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final EnumDeclaration n, final Visitable arg) { + final EnumDeclaration n2 = (EnumDeclaration) arg; + if (!nodesEquals(n.getEntries(), n2.getEntries())) + return false; + if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes())) + return false; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) { + final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodesEquals(n.getClassBody(), n2.getClassBody())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final AnnotationDeclaration n, final Visitable arg) { + final AnnotationDeclaration n2 = (AnnotationDeclaration) arg; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) { + final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg; + if (!nodeEquals(n.getDefaultValue(), n2.getDefaultValue())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final FieldDeclaration n, final Visitable arg) { + final FieldDeclaration n2 = (FieldDeclaration) arg; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodesEquals(n.getVariables(), n2.getVariables())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final VariableDeclarator n, final Visitable arg) { + final VariableDeclarator n2 = (VariableDeclarator) arg; + if (!nodeEquals(n.getInitializer(), n2.getInitializer())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ConstructorDeclaration n, final Visitable arg) { + final ConstructorDeclaration n2 = (ConstructorDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter())) + return false; + if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final MethodDeclaration n, final Visitable arg) { + final MethodDeclaration n2 = (MethodDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter())) + return false; + if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final Parameter n, final Visitable arg) { + final Parameter n2 = (Parameter) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.isVarArgs(), n2.isVarArgs())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getVarArgsAnnotations(), n2.getVarArgsAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final InitializerDeclaration n, final Visitable arg) { + final InitializerDeclaration n2 = (InitializerDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.isStatic(), n2.isStatic())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final JavadocComment n, final Visitable arg) { + final JavadocComment n2 = (JavadocComment) arg; + if (!objEquals(n.getContent(), n2.getContent())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) { + final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final PrimitiveType n, final Visitable arg) { + final PrimitiveType n2 = (PrimitiveType) arg; + if (!objEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ArrayType n, final Visitable arg) { + final ArrayType n2 = (ArrayType) arg; + if (!nodeEquals(n.getComponentType(), n2.getComponentType())) + return false; + if (!objEquals(n.getOrigin(), n2.getOrigin())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ArrayCreationLevel n, final Visitable arg) { + final ArrayCreationLevel n2 = (ArrayCreationLevel) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getDimension(), n2.getDimension())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final IntersectionType n, final Visitable arg) { + final IntersectionType n2 = (IntersectionType) arg; + if (!nodesEquals(n.getElements(), n2.getElements())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final UnionType n, final Visitable arg) { + final UnionType n2 = (UnionType) arg; + if (!nodesEquals(n.getElements(), n2.getElements())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final VoidType n, final Visitable arg) { + final VoidType n2 = (VoidType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final WildcardType n, final Visitable arg) { + final WildcardType n2 = (WildcardType) arg; + if (!nodeEquals(n.getExtendedType(), n2.getExtendedType())) + return false; + if (!nodeEquals(n.getSuperType(), n2.getSuperType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final UnknownType n, final Visitable arg) { + final UnknownType n2 = (UnknownType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ArrayAccessExpr n, final Visitable arg) { + final ArrayAccessExpr n2 = (ArrayAccessExpr) arg; + if (!nodeEquals(n.getIndex(), n2.getIndex())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ArrayCreationExpr n, final Visitable arg) { + final ArrayCreationExpr n2 = (ArrayCreationExpr) arg; + if (!nodeEquals(n.getElementType(), n2.getElementType())) + return false; + if (!nodeEquals(n.getInitializer(), n2.getInitializer())) + return false; + if (!nodesEquals(n.getLevels(), n2.getLevels())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) { + final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg; + if (!nodesEquals(n.getValues(), n2.getValues())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final AssignExpr n, final Visitable arg) { + final AssignExpr n2 = (AssignExpr) arg; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + if (!nodeEquals(n.getTarget(), n2.getTarget())) + return false; + if (!nodeEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final BinaryExpr n, final Visitable arg) { + final BinaryExpr n2 = (BinaryExpr) arg; + if (!nodeEquals(n.getLeft(), n2.getLeft())) + return false; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + if (!nodeEquals(n.getRight(), n2.getRight())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final CastExpr n, final Visitable arg) { + final CastExpr n2 = (CastExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ClassExpr n, final Visitable arg) { + final ClassExpr n2 = (ClassExpr) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ConditionalExpr n, final Visitable arg) { + final ConditionalExpr n2 = (ConditionalExpr) arg; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getElseExpr(), n2.getElseExpr())) + return false; + if (!nodeEquals(n.getThenExpr(), n2.getThenExpr())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final EnclosedExpr n, final Visitable arg) { + final EnclosedExpr n2 = (EnclosedExpr) arg; + if (!nodeEquals(n.getInner(), n2.getInner())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final FieldAccessExpr n, final Visitable arg) { + final FieldAccessExpr n2 = (FieldAccessExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final InstanceOfExpr n, final Visitable arg) { + final InstanceOfExpr n2 = (InstanceOfExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final StringLiteralExpr n, final Visitable arg) { + final StringLiteralExpr n2 = (StringLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) { + final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final LongLiteralExpr n, final Visitable arg) { + final LongLiteralExpr n2 = (LongLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final CharLiteralExpr n, final Visitable arg) { + final CharLiteralExpr n2 = (CharLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) { + final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) { + final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final NullLiteralExpr n, final Visitable arg) { + final NullLiteralExpr n2 = (NullLiteralExpr) arg; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final MethodCallExpr n, final Visitable arg) { + final MethodCallExpr n2 = (MethodCallExpr) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final NameExpr n, final Visitable arg) { + final NameExpr n2 = (NameExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ObjectCreationExpr n, final Visitable arg) { + final ObjectCreationExpr n2 = (ObjectCreationExpr) arg; + if (!nodesEquals(n.getAnonymousClassBody(), n2.getAnonymousClassBody())) + return false; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final Name n, final Visitable arg) { + final Name n2 = (Name) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + if (!nodeEquals(n.getQualifier(), n2.getQualifier())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SimpleName n, final Visitable arg) { + final SimpleName n2 = (SimpleName) arg; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ThisExpr n, final Visitable arg) { + final ThisExpr n2 = (ThisExpr) arg; + if (!nodeEquals(n.getClassExpr(), n2.getClassExpr())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SuperExpr n, final Visitable arg) { + final SuperExpr n2 = (SuperExpr) arg; + if (!nodeEquals(n.getClassExpr(), n2.getClassExpr())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final UnaryExpr n, final Visitable arg) { + final UnaryExpr n2 = (UnaryExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) { + final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodesEquals(n.getVariables(), n2.getVariables())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) { + final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) { + final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg; + if (!nodeEquals(n.getMemberValue(), n2.getMemberValue())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) { + final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg; + if (!nodesEquals(n.getPairs(), n2.getPairs())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final MemberValuePair n, final Visitable arg) { + final MemberValuePair n2 = (MemberValuePair) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getValue(), n2.getValue())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) { + final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!objEquals(n.isThis(), n2.isThis())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) { + final LocalClassDeclarationStmt n2 = (LocalClassDeclarationStmt) arg; + if (!nodeEquals(n.getClassDeclaration(), n2.getClassDeclaration())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final AssertStmt n, final Visitable arg) { + final AssertStmt n2 = (AssertStmt) arg; + if (!nodeEquals(n.getCheck(), n2.getCheck())) + return false; + if (!nodeEquals(n.getMessage(), n2.getMessage())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final BlockStmt n, final Visitable arg) { + final BlockStmt n2 = (BlockStmt) arg; + if (!nodesEquals(n.getStatements(), n2.getStatements())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final LabeledStmt n, final Visitable arg) { + final LabeledStmt n2 = (LabeledStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodeEquals(n.getStatement(), n2.getStatement())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final EmptyStmt n, final Visitable arg) { + final EmptyStmt n2 = (EmptyStmt) arg; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ExpressionStmt n, final Visitable arg) { + final ExpressionStmt n2 = (ExpressionStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SwitchStmt n, final Visitable arg) { + final SwitchStmt n2 = (SwitchStmt) arg; + if (!nodesEquals(n.getEntries(), n2.getEntries())) + return false; + if (!nodeEquals(n.getSelector(), n2.getSelector())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SwitchEntryStmt n, final Visitable arg) { + final SwitchEntryStmt n2 = (SwitchEntryStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodesEquals(n.getStatements(), n2.getStatements())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final BreakStmt n, final Visitable arg) { + final BreakStmt n2 = (BreakStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ReturnStmt n, final Visitable arg) { + final ReturnStmt n2 = (ReturnStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final IfStmt n, final Visitable arg) { + final IfStmt n2 = (IfStmt) arg; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getElseStmt(), n2.getElseStmt())) + return false; + if (!nodeEquals(n.getThenStmt(), n2.getThenStmt())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final WhileStmt n, final Visitable arg) { + final WhileStmt n2 = (WhileStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ContinueStmt n, final Visitable arg) { + final ContinueStmt n2 = (ContinueStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final DoStmt n, final Visitable arg) { + final DoStmt n2 = (DoStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ForeachStmt n, final Visitable arg) { + final ForeachStmt n2 = (ForeachStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getIterable(), n2.getIterable())) + return false; + if (!nodeEquals(n.getVariable(), n2.getVariable())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ForStmt n, final Visitable arg) { + final ForStmt n2 = (ForStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCompare(), n2.getCompare())) + return false; + if (!nodesEquals(n.getInitialization(), n2.getInitialization())) + return false; + if (!nodesEquals(n.getUpdate(), n2.getUpdate())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ThrowStmt n, final Visitable arg) { + final ThrowStmt n2 = (ThrowStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final SynchronizedStmt n, final Visitable arg) { + final SynchronizedStmt n2 = (SynchronizedStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final TryStmt n, final Visitable arg) { + final TryStmt n2 = (TryStmt) arg; + if (!nodesEquals(n.getCatchClauses(), n2.getCatchClauses())) + return false; + if (!nodeEquals(n.getFinallyBlock(), n2.getFinallyBlock())) + return false; + if (!nodesEquals(n.getResources(), n2.getResources())) + return false; + if (!nodeEquals(n.getTryBlock(), n2.getTryBlock())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final CatchClause n, final Visitable arg) { + final CatchClause n2 = (CatchClause) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getParameter(), n2.getParameter())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final LambdaExpr n, final Visitable arg) { + final LambdaExpr n2 = (LambdaExpr) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final MethodReferenceExpr n, final Visitable arg) { + final MethodReferenceExpr n2 = (MethodReferenceExpr) arg; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final TypeExpr n, final Visitable arg) { + final TypeExpr n2 = (TypeExpr) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ImportDeclaration n, final Visitable arg) { + final ImportDeclaration n2 = (ImportDeclaration) arg; + if (!objEquals(n.isAsterisk(), n2.isAsterisk())) + return false; + if (!objEquals(n.isStatic(), n2.isStatic())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + public Boolean visit(NodeList n, Visitable arg) { + return nodesEquals((NodeList) n, (NodeList) arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleDeclaration n, final Visitable arg) { + final ModuleDeclaration n2 = (ModuleDeclaration) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.isOpen(), n2.isOpen())) + return false; + if (!nodesEquals(n.getModuleStmts(), n2.getModuleStmts())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) { + final ModuleRequiresStmt n2 = (ModuleRequiresStmt) arg; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleExportsStmt n, final Visitable arg) { + final ModuleExportsStmt n2 = (ModuleExportsStmt) arg; + if (!nodesEquals(n.getModuleNames(), n2.getModuleNames())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) { + final ModuleProvidesStmt n2 = (ModuleProvidesStmt) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getWithTypes(), n2.getWithTypes())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleUsesStmt n, final Visitable arg) { + final ModuleUsesStmt n2 = (ModuleUsesStmt) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ModuleOpensStmt n, final Visitable arg) { + final ModuleOpensStmt n2 = (ModuleOpensStmt) arg; + if (!nodesEquals(n.getModuleNames(), n2.getModuleNames())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final UnparsableStmt n, final Visitable arg) { + final UnparsableStmt n2 = (UnparsableStmt) arg; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator") + public Boolean visit(final ReceiverParameter n, final Visitable arg) { + final ReceiverParameter n2 = (ReceiverParameter) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } + + @Override + public Boolean visit(final VarType n, final Visitable arg) { + final VarType n2 = (VarType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java b/JavaParser/src/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java new file mode 100644 index 0000000..2defdfa --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java @@ -0,0 +1,2061 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * A visitor that has a return value of ({@link List List}), and has a default implementation for all its visit + * methods that visits their children in an unspecified order, and all visit methods + * that returns a value be added to a flattened {@link List List}. + * + * @author Enno Boland + */ +public abstract class GenericListVisitorAdapter implements GenericVisitor, A> { + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final AnnotationDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getMembers().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final AnnotationMemberDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getDefaultValue().isPresent()) { + tmp = n.getDefaultValue().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ArrayAccessExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getIndex().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ArrayCreationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getElementType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getInitializer().isPresent()) { + tmp = n.getInitializer().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getLevels().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ArrayCreationLevel n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getDimension().isPresent()) { + tmp = n.getDimension().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ArrayInitializerExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getValues().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ArrayType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getComponentType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final AssertStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getCheck().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getMessage().isPresent()) { + tmp = n.getMessage().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final AssignExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getTarget().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getValue().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final BinaryExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getLeft().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getRight().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final BlockComment n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final BlockStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getStatements().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final BooleanLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final BreakStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getLabel().isPresent()) { + tmp = n.getLabel().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final CastExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final CatchClause n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getParameter().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final CharLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ClassExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ClassOrInterfaceDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExtendedTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getImplementedTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTypeParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getMembers().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ClassOrInterfaceType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getScope().isPresent()) { + tmp = n.getScope().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final CompilationUnit n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getImports().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getModule().isPresent()) { + tmp = n.getModule().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getPackageDeclaration().isPresent()) { + tmp = n.getPackageDeclaration().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ConditionalExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getCondition().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getElseExpr().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getThenExpr().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ConstructorDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getReceiverParameter().isPresent()) { + tmp = n.getReceiverParameter().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getThrownExceptions().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTypeParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ContinueStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getLabel().isPresent()) { + tmp = n.getLabel().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final DoStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getCondition().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final DoubleLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final EmptyStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final EnclosedExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getInner().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final EnumConstantDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getArguments().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getClassBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final EnumDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getEntries().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getImplementedTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getMembers().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ExplicitConstructorInvocationStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getArguments().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getExpression().isPresent()) { + tmp = n.getExpression().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ExpressionStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final FieldAccessExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getScope().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final FieldDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getVariables().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ForStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getCompare().isPresent()) { + tmp = n.getCompare().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getInitialization().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getUpdate().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ForeachStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getIterable().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getVariable().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final IfStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getCondition().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getElseStmt().isPresent()) { + tmp = n.getElseStmt().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getThenStmt().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ImportDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final InitializerDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final InstanceOfExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final IntegerLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final IntersectionType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getElements().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final JavadocComment n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final LabeledStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getLabel().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getStatement().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final LambdaExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final LineComment n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final LocalClassDeclarationStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getClassDeclaration().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final LongLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final MarkerAnnotationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final MemberValuePair n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getValue().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final MethodCallExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getArguments().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getScope().isPresent()) { + tmp = n.getScope().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final MethodDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getBody().isPresent()) { + tmp = n.getBody().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getReceiverParameter().isPresent()) { + tmp = n.getReceiverParameter().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getThrownExceptions().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTypeParameters().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final MethodReferenceExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getScope().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final NameExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final Name n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getQualifier().isPresent()) { + tmp = n.getQualifier().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final NormalAnnotationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getPairs().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final NullLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ObjectCreationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getAnonymousClassBody().isPresent()) { + tmp = n.getAnonymousClassBody().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getArguments().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getScope().isPresent()) { + tmp = n.getScope().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getTypeArguments().isPresent()) { + tmp = n.getTypeArguments().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final PackageDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final Parameter n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getVarArgsAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final PrimitiveType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ReturnStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getExpression().isPresent()) { + tmp = n.getExpression().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SimpleName n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SingleMemberAnnotationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getMemberValue().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final StringLiteralExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SuperExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getClassExpr().isPresent()) { + tmp = n.getClassExpr().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SwitchEntryStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getLabel().isPresent()) { + tmp = n.getLabel().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getStatements().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SwitchStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getEntries().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getSelector().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final SynchronizedStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ThisExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getClassExpr().isPresent()) { + tmp = n.getClassExpr().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ThrowStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final TryStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getCatchClauses().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getFinallyBlock().isPresent()) { + tmp = n.getFinallyBlock().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getResources().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTryBlock().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final TypeExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final TypeParameter n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getTypeBound().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final UnaryExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getExpression().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final UnionType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getElements().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final UnknownType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final VariableDeclarationExpr n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getVariables().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final VariableDeclarator n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getInitializer().isPresent()) { + tmp = n.getInitializer().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final VoidType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final WhileStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getBody().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getCondition().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final WildcardType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getExtendedType().isPresent()) { + tmp = n.getExtendedType().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getSuperType().isPresent()) { + tmp = n.getSuperType().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + public List visit(NodeList n, A arg) { + return ((NodeList) n).stream().filter(Objects::nonNull).flatMap(v -> v.accept(this, arg).stream()).collect(Collectors.toList()); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleDeclaration n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getModuleStmts().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleExportsStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getModuleNames().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleOpensStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getModuleNames().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleProvidesStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getWithTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleRequiresStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ModuleUsesStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final UnparsableStmt n, final A arg) { + List result = new ArrayList<>(); + List tmp; + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List visit(final ReceiverParameter n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getType().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } + + @Override + public List visit(final VarType n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getAnnotations().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitor.java index 661f39a..494013c 100644 --- a/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitor.java +++ b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitor.java @@ -1,253 +1,319 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -/** - * A visitor that has a return value. - * - * @author Julio Vilmar Gesser - */ -public interface GenericVisitor { - - //- Compilation Unit ---------------------------------- - - public R visit(CompilationUnit n, A arg); - - public R visit(PackageDeclaration n, A arg); - - public R visit(ImportDeclaration n, A arg); - - public R visit(TypeParameter n, A arg); - - public R visit(LineComment n, A arg); - - public R visit(BlockComment n, A arg); - - //- Body ---------------------------------------------- - - public R visit(ClassOrInterfaceDeclaration n, A arg); - - public R visit(EnumDeclaration n, A arg); - - public R visit(EmptyTypeDeclaration n, A arg); - - public R visit(EnumConstantDeclaration n, A arg); - - public R visit(AnnotationDeclaration n, A arg); - - public R visit(AnnotationMemberDeclaration n, A arg); - - public R visit(FieldDeclaration n, A arg); - - public R visit(VariableDeclarator n, A arg); - - public R visit(VariableDeclaratorId n, A arg); - - public R visit(ConstructorDeclaration n, A arg); - - public R visit(MethodDeclaration n, A arg); - - public R visit(Parameter n, A arg); - - public R visit(MultiTypeParameter n, A arg); - - public R visit(EmptyMemberDeclaration n, A arg); - - public R visit(InitializerDeclaration n, A arg); - - public R visit(JavadocComment n, A arg); - - //- Type ---------------------------------------------- - - public R visit(ClassOrInterfaceType n, A arg); - - public R visit(PrimitiveType n, A arg); - - public R visit(ReferenceType n, A arg); - - public R visit(VoidType n, A arg); - - public R visit(WildcardType n, A arg); - - public R visit(UnknownType n, A arg); - - //- Expression ---------------------------------------- - - public R visit(ArrayAccessExpr n, A arg); - - public R visit(ArrayCreationExpr n, A arg); - - public R visit(ArrayInitializerExpr n, A arg); - - public R visit(AssignExpr n, A arg); - - public R visit(BinaryExpr n, A arg); - - public R visit(CastExpr n, A arg); - - public R visit(ClassExpr n, A arg); - - public R visit(ConditionalExpr n, A arg); - - public R visit(EnclosedExpr n, A arg); - - public R visit(FieldAccessExpr n, A arg); - - public R visit(InstanceOfExpr n, A arg); - - public R visit(StringLiteralExpr n, A arg); - - public R visit(IntegerLiteralExpr n, A arg); - - public R visit(LongLiteralExpr n, A arg); - - public R visit(IntegerLiteralMinValueExpr n, A arg); - - public R visit(LongLiteralMinValueExpr n, A arg); - - public R visit(CharLiteralExpr n, A arg); - - public R visit(DoubleLiteralExpr n, A arg); - - public R visit(BooleanLiteralExpr n, A arg); - - public R visit(NullLiteralExpr n, A arg); - - public R visit(MethodCallExpr n, A arg); - - public R visit(NameExpr n, A arg); - - public R visit(ObjectCreationExpr n, A arg); - - public R visit(QualifiedNameExpr n, A arg); - - public R visit(ThisExpr n, A arg); - - public R visit(SuperExpr n, A arg); - - public R visit(UnaryExpr n, A arg); - - public R visit(VariableDeclarationExpr n, A arg); - - public R visit(MarkerAnnotationExpr n, A arg); - - public R visit(SingleMemberAnnotationExpr n, A arg); - - public R visit(NormalAnnotationExpr n, A arg); - - public R visit(MemberValuePair n, A arg); - - //- Statements ---------------------------------------- - - public R visit(ExplicitConstructorInvocationStmt n, A arg); - - public R visit(TypeDeclarationStmt n, A arg); - - public R visit(AssertStmt n, A arg); - - public R visit(BlockStmt n, A arg); - - public R visit(LabeledStmt n, A arg); - - public R visit(EmptyStmt n, A arg); - - public R visit(ExpressionStmt n, A arg); - - public R visit(SwitchStmt n, A arg); - - public R visit(SwitchEntryStmt n, A arg); - - public R visit(BreakStmt n, A arg); - - public R visit(ReturnStmt n, A arg); - - public R visit(IfStmt n, A arg); - - public R visit(WhileStmt n, A arg); - - public R visit(ContinueStmt n, A arg); - - public R visit(DoStmt n, A arg); - - public R visit(ForeachStmt n, A arg); - - public R visit(ForStmt n, A arg); - - public R visit(ThrowStmt n, A arg); - - public R visit(SynchronizedStmt n, A arg); - - public R visit(TryStmt n, A arg); - - public R visit(CatchClause n, A arg); - - public R visit(LambdaExpr n, A arg); - - public R visit(MethodReferenceExpr n, A arg); - - public R visit(TypeExpr n, A arg); -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that has a return value. + * + * @author Julio Vilmar Gesser + */ +public interface GenericVisitor { + + // - Compilation Unit ---------------------------------- + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(CompilationUnit n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(PackageDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(TypeParameter n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(LineComment n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(BlockComment n, A arg); + + // - Body ---------------------------------------------- + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ClassOrInterfaceDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(EnumDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(EnumConstantDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(AnnotationDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(AnnotationMemberDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(FieldDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(VariableDeclarator n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ConstructorDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(MethodDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(Parameter n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(InitializerDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(JavadocComment n, A arg); + + // - Type ---------------------------------------------- + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ClassOrInterfaceType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(PrimitiveType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ArrayType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ArrayCreationLevel n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(IntersectionType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(UnionType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(VoidType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(WildcardType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(UnknownType n, A arg); + + // - Expression ---------------------------------------- + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ArrayAccessExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ArrayCreationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ArrayInitializerExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(AssignExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(BinaryExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(CastExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ClassExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ConditionalExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(EnclosedExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(FieldAccessExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(InstanceOfExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(StringLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(IntegerLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(LongLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(CharLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(DoubleLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(BooleanLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(NullLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(MethodCallExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(NameExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ObjectCreationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ThisExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SuperExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(UnaryExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(VariableDeclarationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(MarkerAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SingleMemberAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(NormalAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(MemberValuePair n, A arg); + + // - Statements ---------------------------------------- + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ExplicitConstructorInvocationStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(LocalClassDeclarationStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(AssertStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(BlockStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(LabeledStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(EmptyStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ExpressionStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SwitchStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SwitchEntryStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(BreakStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ReturnStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(IfStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(WhileStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ContinueStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(DoStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ForeachStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ForStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ThrowStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SynchronizedStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(TryStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(CatchClause n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(LambdaExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(MethodReferenceExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(TypeExpr n, A arg); + + R visit(NodeList n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(Name n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(SimpleName n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ImportDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleRequiresStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleExportsStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleProvidesStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleUsesStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ModuleOpensStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(UnparsableStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator") + R visit(ReceiverParameter n, A arg); + + R visit(VarType n, A arg); +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java index d84426f..3d5de4f 100644 --- a/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java +++ b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java @@ -1,1612 +1,2054 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class GenericVisitorAdapter implements GenericVisitor { - - @Override - public R visit(final AnnotationDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final AnnotationMemberDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getDefaultValue() != null) { - { - R result = n.getDefaultValue().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ArrayAccessExpr n, final A arg) { - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getIndex().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ArrayCreationExpr n, final A arg) { - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getDimensions() != null) { - for (final Expression dim : n.getDimensions()) { - { - R result = dim.accept(this, arg); - if (result != null) { - return result; - } - } - } - } else { - { - R result = n.getInitializer().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ArrayInitializerExpr n, final A arg) { - if (n.getValues() != null) { - for (final Expression expr : n.getValues()) { - { - R result = expr.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final AssertStmt n, final A arg) { - { - R result = n.getCheck().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getMessage() != null) { - { - R result = n.getMessage().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final AssignExpr n, final A arg) { - { - R result = n.getTarget().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final BinaryExpr n, final A arg) { - { - R result = n.getLeft().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getRight().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final BlockStmt n, final A arg) { - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - { - R result = s.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - - } - - @Override - public R visit(final BooleanLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final BreakStmt n, final A arg) { - return null; - } - - @Override - public R visit(final CastExpr n, final A arg) { - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final CatchClause n, final A arg) { - { - R result = n.getExcept().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getCatchBlock().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - - } - - @Override - public R visit(final CharLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final ClassExpr n, final A arg) { - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ClassOrInterfaceDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getExtends() != null) { - for (final ClassOrInterfaceType c : n.getExtends()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ClassOrInterfaceType n, final A arg) { - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final CompilationUnit n, final A arg) { - if (n.getPackage() != null) { - { - R result = n.getPackage().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getImports() != null) { - for (final ImportDeclaration i : n.getImports()) { - { - R result = i.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypes() != null) { - for (final TypeDeclaration typeDeclaration : n.getTypes()) { - { - R result = typeDeclaration.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ConditionalExpr n, final A arg) { - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getThenExpr().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getElseExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ConstructorDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - { - R result = p.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getThrows() != null) { - for (final NameExpr name : n.getThrows()) { - { - R result = name.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getBlock().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ContinueStmt n, final A arg) { - return null; - } - - @Override - public R visit(final DoStmt n, final A arg) { - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final DoubleLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final EmptyMemberDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final EmptyStmt n, final A arg) { - return null; - } - - @Override - public R visit(final EmptyTypeDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final EnclosedExpr n, final A arg) { - { - R result = n.getInner().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final EnumConstantDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getClassBody() != null) { - for (final BodyDeclaration member : n.getClassBody()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final EnumDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getEntries() != null) { - for (final EnumConstantDeclaration e : n.getEntries()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ExplicitConstructorInvocationStmt n, final A arg) { - if (!n.isThis()) { - if (n.getExpr() != null) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final ExpressionStmt n, final A arg) { - { - R result = n.getExpression().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final FieldAccessExpr n, final A arg) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final FieldDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - for (final VariableDeclarator var : n.getVariables()) { - { - R result = var.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ForeachStmt n, final A arg) { - { - R result = n.getVariable().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getIterable().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ForStmt n, final A arg) { - if (n.getInit() != null) { - for (final Expression e : n.getInit()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getCompare() != null) { - { - R result = n.getCompare().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getUpdate() != null) { - for (final Expression e : n.getUpdate()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final IfStmt n, final A arg) { - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getThenStmt().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getElseStmt() != null) { - { - R result = n.getElseStmt().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ImportDeclaration n, final A arg) { - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final InitializerDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - { - R result = n.getBlock().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final InstanceOfExpr n, final A arg) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final IntegerLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final IntegerLiteralMinValueExpr n, final A arg) { - return null; - } - - @Override - public R visit(final JavadocComment n, final A arg) { - return null; - } - - @Override - public R visit(final LabeledStmt n, final A arg) { - { - R result = n.getStmt().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final LongLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final LongLiteralMinValueExpr n, final A arg) { - return null; - } - - @Override - public R visit(final MarkerAnnotationExpr n, final A arg) { - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final MemberValuePair n, final A arg) { - { - R result = n.getValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final MethodCallExpr n, final A arg) { - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final MethodDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - { - R result = n.getJavaDoc().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - { - R result = p.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getThrows() != null) { - for (final NameExpr name : n.getThrows()) { - { - R result = name.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getBody() != null) { - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final NameExpr n, final A arg) { - return null; - } - - @Override - public R visit(final NormalAnnotationExpr n, final A arg) { - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getPairs() != null) { - for (final MemberValuePair m : n.getPairs()) { - { - R result = m.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final NullLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final ObjectCreationExpr n, final A arg) { - if (n.getScope() != null) { - { - R result = n.getScope().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - { - R result = t.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getAnonymousClassBody() != null) { - for (final BodyDeclaration member : n.getAnonymousClassBody()) { - { - R result = member.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final PackageDeclaration n, final A arg) { - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final Parameter n, final A arg) { - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getId().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final MultiTypeParameter n, final A arg) { - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - for (final Type type : n.getTypes()) { - R result = type.accept(this, arg); - if (result != null) { - return result; - } - } - } - { - R result = n.getId().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final PrimitiveType n, final A arg) { - return null; - } - - @Override - public R visit(final QualifiedNameExpr n, final A arg) { - { - R result = n.getQualifier().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ReferenceType n, final A arg) { - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ReturnStmt n, final A arg) { - if (n.getExpr() != null) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final SingleMemberAnnotationExpr n, final A arg) { - { - R result = n.getName().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getMemberValue().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final StringLiteralExpr n, final A arg) { - return null; - } - - @Override - public R visit(final SuperExpr n, final A arg) { - if (n.getClassExpr() != null) { - { - R result = n.getClassExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final SwitchEntryStmt n, final A arg) { - if (n.getLabel() != null) { - { - R result = n.getLabel().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - { - R result = s.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final SwitchStmt n, final A arg) { - { - R result = n.getSelector().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getEntries() != null) { - for (final SwitchEntryStmt e : n.getEntries()) { - { - R result = e.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - - } - - @Override - public R visit(final SynchronizedStmt n, final A arg) { - { - if (n.getExpr() != null) { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - { - R result = n.getBlock().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final ThisExpr n, final A arg) { - if (n.getClassExpr() != null) { - { - R result = n.getClassExpr().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final ThrowStmt n, final A arg) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final TryStmt n, final A arg) { - if (n.getResources() != null) { - for (final VariableDeclarationExpr v : n.getResources()) { - { - R result = v.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getTryBlock().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getCatchs() != null) { - for (final CatchClause c : n.getCatchs()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - if (n.getFinallyBlock() != null) { - { - R result = n.getFinallyBlock().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final TypeDeclarationStmt n, final A arg) { - { - R result = n.getTypeDeclaration().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final TypeParameter n, final A arg) { - if (n.getTypeBound() != null) { - for (final ClassOrInterfaceType c : n.getTypeBound()) { - { - R result = c.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Override - public R visit(final UnaryExpr n, final A arg) { - { - R result = n.getExpr().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final UnknownType n, final A arg) { - return null; - } - - @Override - public R visit(final VariableDeclarationExpr n, final A arg) { - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - { - R result = a.accept(this, arg); - if (result != null) { - return result; - } - } - } - } - { - R result = n.getType().accept(this, arg); - if (result != null) { - return result; - } - } - for (final VariableDeclarator v : n.getVars()) { - { - R result = v.accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final VariableDeclarator n, final A arg) { - { - R result = n.getId().accept(this, arg); - if (result != null) { - return result; - } - } - if (n.getInit() != null) { - { - R result = n.getInit().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(final VariableDeclaratorId n, final A arg) { - return null; - } - - @Override - public R visit(final VoidType n, final A arg) { - return null; - } - - @Override - public R visit(final WhileStmt n, final A arg) { - { - R result = n.getCondition().accept(this, arg); - if (result != null) { - return result; - } - } - { - R result = n.getBody().accept(this, arg); - if (result != null) { - return result; - } - } - return null; - } - - @Override - public R visit(final WildcardType n, final A arg) { - if (n.getExtends() != null) { - { - R result = n.getExtends().accept(this, arg); - if (result != null) { - return result; - } - } - } - if (n.getSuper() != null) { - { - R result = n.getSuper().accept(this, arg); - if (result != null) { - return result; - } - } - } - return null; - } - - @Override - public R visit(LambdaExpr n, A arg) { - return null; - } - - @Override - public R visit(MethodReferenceExpr n, A arg){ - return null; - } - - @Override - public R visit(TypeExpr n, A arg){ - return null; - } - - @Override - public R visit(final BlockComment n, final A arg) { - return null; - } - - @Override - public R visit(final LineComment n, final A arg) { - return null; - } - -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that has a return value (R), and has a default implementation for all its visit + * methods that visits their children in an unspecified order, and the first visit method + * that returns a value will stop the visitation and be the end result. + * + * @author Julio Vilmar Gesser + */ +public abstract class GenericVisitorAdapter implements GenericVisitor { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final AnnotationDeclaration n, final A arg) { + R result; + { + result = n.getMembers().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final AnnotationMemberDeclaration n, final A arg) { + R result; + if (n.getDefaultValue().isPresent()) { + result = n.getDefaultValue().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ArrayAccessExpr n, final A arg) { + R result; + { + result = n.getIndex().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ArrayCreationExpr n, final A arg) { + R result; + { + result = n.getElementType().accept(this, arg); + if (result != null) + return result; + } + if (n.getInitializer().isPresent()) { + result = n.getInitializer().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getLevels().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ArrayInitializerExpr n, final A arg) { + R result; + { + result = n.getValues().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final AssertStmt n, final A arg) { + R result; + { + result = n.getCheck().accept(this, arg); + if (result != null) + return result; + } + if (n.getMessage().isPresent()) { + result = n.getMessage().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final AssignExpr n, final A arg) { + R result; + { + result = n.getTarget().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getValue().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final BinaryExpr n, final A arg) { + R result; + { + result = n.getLeft().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getRight().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final BlockStmt n, final A arg) { + R result; + { + result = n.getStatements().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final BooleanLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final BreakStmt n, final A arg) { + R result; + if (n.getLabel().isPresent()) { + result = n.getLabel().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final CastExpr n, final A arg) { + R result; + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final CatchClause n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getParameter().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final CharLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ClassExpr n, final A arg) { + R result; + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ClassOrInterfaceDeclaration n, final A arg) { + R result; + { + result = n.getExtendedTypes().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getImplementedTypes().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTypeParameters().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getMembers().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ClassOrInterfaceType n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getScope().isPresent()) { + result = n.getScope().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final CompilationUnit n, final A arg) { + R result; + { + result = n.getImports().accept(this, arg); + if (result != null) + return result; + } + if (n.getModule().isPresent()) { + result = n.getModule().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getPackageDeclaration().isPresent()) { + result = n.getPackageDeclaration().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTypes().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ConditionalExpr n, final A arg) { + R result; + { + result = n.getCondition().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getElseExpr().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getThenExpr().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ConstructorDeclaration n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getParameters().accept(this, arg); + if (result != null) + return result; + } + if (n.getReceiverParameter().isPresent()) { + result = n.getReceiverParameter().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getThrownExceptions().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTypeParameters().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ContinueStmt n, final A arg) { + R result; + if (n.getLabel().isPresent()) { + result = n.getLabel().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final DoStmt n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getCondition().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final DoubleLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final EmptyStmt n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final EnclosedExpr n, final A arg) { + R result; + { + result = n.getInner().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final EnumConstantDeclaration n, final A arg) { + R result; + { + result = n.getArguments().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getClassBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final EnumDeclaration n, final A arg) { + R result; + { + result = n.getEntries().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getImplementedTypes().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getMembers().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ExplicitConstructorInvocationStmt n, final A arg) { + R result; + { + result = n.getArguments().accept(this, arg); + if (result != null) + return result; + } + if (n.getExpression().isPresent()) { + result = n.getExpression().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ExpressionStmt n, final A arg) { + R result; + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final FieldAccessExpr n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getScope().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final FieldDeclaration n, final A arg) { + R result; + { + result = n.getVariables().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ForeachStmt n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getIterable().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getVariable().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ForStmt n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + if (n.getCompare().isPresent()) { + result = n.getCompare().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getInitialization().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getUpdate().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final IfStmt n, final A arg) { + R result; + { + result = n.getCondition().accept(this, arg); + if (result != null) + return result; + } + if (n.getElseStmt().isPresent()) { + result = n.getElseStmt().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getThenStmt().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final InitializerDeclaration n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final InstanceOfExpr n, final A arg) { + R result; + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final IntegerLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final JavadocComment n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final LabeledStmt n, final A arg) { + R result; + { + result = n.getLabel().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getStatement().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final LongLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final MarkerAnnotationExpr n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final MemberValuePair n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getValue().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final MethodCallExpr n, final A arg) { + R result; + { + result = n.getArguments().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getScope().isPresent()) { + result = n.getScope().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final MethodDeclaration n, final A arg) { + R result; + if (n.getBody().isPresent()) { + result = n.getBody().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getParameters().accept(this, arg); + if (result != null) + return result; + } + if (n.getReceiverParameter().isPresent()) { + result = n.getReceiverParameter().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getThrownExceptions().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTypeParameters().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final NameExpr n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final NormalAnnotationExpr n, final A arg) { + R result; + { + result = n.getPairs().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final NullLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ObjectCreationExpr n, final A arg) { + R result; + if (n.getAnonymousClassBody().isPresent()) { + result = n.getAnonymousClassBody().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getArguments().accept(this, arg); + if (result != null) + return result; + } + if (n.getScope().isPresent()) { + result = n.getScope().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final PackageDeclaration n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final Parameter n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getVarArgsAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final PrimitiveType n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final Name n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getQualifier().isPresent()) { + result = n.getQualifier().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SimpleName n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ArrayType n, final A arg) { + R result; + { + result = n.getComponentType().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ArrayCreationLevel n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getDimension().isPresent()) { + result = n.getDimension().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final IntersectionType n, final A arg) { + R result; + { + result = n.getElements().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final UnionType n, final A arg) { + R result; + { + result = n.getElements().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ReturnStmt n, final A arg) { + R result; + if (n.getExpression().isPresent()) { + result = n.getExpression().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SingleMemberAnnotationExpr n, final A arg) { + R result; + { + result = n.getMemberValue().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final StringLiteralExpr n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SuperExpr n, final A arg) { + R result; + if (n.getClassExpr().isPresent()) { + result = n.getClassExpr().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SwitchEntryStmt n, final A arg) { + R result; + if (n.getLabel().isPresent()) { + result = n.getLabel().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getStatements().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SwitchStmt n, final A arg) { + R result; + { + result = n.getEntries().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getSelector().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final SynchronizedStmt n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ThisExpr n, final A arg) { + R result; + if (n.getClassExpr().isPresent()) { + result = n.getClassExpr().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ThrowStmt n, final A arg) { + R result; + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final TryStmt n, final A arg) { + R result; + { + result = n.getCatchClauses().accept(this, arg); + if (result != null) + return result; + } + if (n.getFinallyBlock().isPresent()) { + result = n.getFinallyBlock().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getResources().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTryBlock().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final LocalClassDeclarationStmt n, final A arg) { + R result; + { + result = n.getClassDeclaration().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final TypeParameter n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getTypeBound().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final UnaryExpr n, final A arg) { + R result; + { + result = n.getExpression().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final UnknownType n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final VariableDeclarationExpr n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getVariables().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final VariableDeclarator n, final A arg) { + R result; + if (n.getInitializer().isPresent()) { + result = n.getInitializer().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final VoidType n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final WhileStmt n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getCondition().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final WildcardType n, final A arg) { + R result; + if (n.getExtendedType().isPresent()) { + result = n.getExtendedType().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getSuperType().isPresent()) { + result = n.getSuperType().get().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final LambdaExpr n, final A arg) { + R result; + { + result = n.getBody().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getParameters().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final MethodReferenceExpr n, final A arg) { + R result; + { + result = n.getScope().accept(this, arg); + if (result != null) + return result; + } + if (n.getTypeArguments().isPresent()) { + result = n.getTypeArguments().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final TypeExpr n, final A arg) { + R result; + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ImportDeclaration n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final BlockComment n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final LineComment n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + public R visit(NodeList n, A arg) { + for (final Object v : n) { + R result = ((Node) v).accept(this, arg); + if (result != null) { + return result; + } + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleDeclaration n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getModuleStmts().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleRequiresStmt n, final A arg) { + R result; + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleExportsStmt n, final A arg) { + R result; + { + result = n.getModuleNames().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleProvidesStmt n, final A arg) { + R result; + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getWithTypes().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleUsesStmt n, final A arg) { + R result; + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ModuleOpensStmt n, final A arg) { + R result; + { + result = n.getModuleNames().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final UnparsableStmt n, final A arg) { + R result; + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator") + public R visit(final ReceiverParameter n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getType().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } + + @Override + public R visit(final VarType n, final A arg) { + R result; + { + result = n.getAnnotations().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java new file mode 100644 index 0000000..2cd9a0f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java @@ -0,0 +1,603 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that has a return value (R), and has default methods that are used when a specific visit method is not + * overridden. + */ +public abstract class GenericVisitorWithDefaults implements GenericVisitor { + + /** + * This will be called by every node visit method that is not overridden. + */ + public R defaultAction(Node n, A arg) { + return null; + } + + /** + * This will be called by the NodeList visit method when it is not overridden. + */ + public R defaultAction(NodeList n, A arg) { + return null; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final AnnotationDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final AnnotationMemberDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ArrayAccessExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ArrayCreationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ArrayInitializerExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final AssertStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final AssignExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final BinaryExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final BlockStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final BooleanLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final BreakStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final CastExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final CatchClause n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final CharLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ClassExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ClassOrInterfaceDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ClassOrInterfaceType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final CompilationUnit n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ConditionalExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ConstructorDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ContinueStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final DoStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final DoubleLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final EmptyStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final EnclosedExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final EnumConstantDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final EnumDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ExplicitConstructorInvocationStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ExpressionStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final FieldAccessExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final FieldDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ForeachStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ForStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final IfStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final InitializerDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final InstanceOfExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final IntegerLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final JavadocComment n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final LabeledStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final LongLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final MarkerAnnotationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final MemberValuePair n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final MethodCallExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final MethodDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final NameExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final NormalAnnotationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final NullLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ObjectCreationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final PackageDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final Parameter n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final PrimitiveType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final Name n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SimpleName n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ArrayType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ArrayCreationLevel n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final IntersectionType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final UnionType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ReturnStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SingleMemberAnnotationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final StringLiteralExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SuperExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SwitchEntryStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SwitchStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final SynchronizedStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ThisExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ThrowStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final TryStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final LocalClassDeclarationStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final TypeParameter n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final UnaryExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final UnknownType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final VariableDeclarationExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final VariableDeclarator n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final VoidType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final WhileStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final WildcardType n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final LambdaExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final MethodReferenceExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final TypeExpr n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ImportDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final BlockComment n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final LineComment n, final A arg) { + return defaultAction(n, arg); + } + + @Override + public R visit(NodeList n, A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleDeclaration n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleRequiresStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleExportsStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleProvidesStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleUsesStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ModuleOpensStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final UnparsableStmt n, final A arg) { + return defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator") + public R visit(final ReceiverParameter n, final A arg) { + return defaultAction(n, arg); + } + + @Override + public R visit(final VarType n, final A arg) { + return defaultAction(n, arg); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/HashCodeVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/HashCodeVisitor.java new file mode 100644 index 0000000..92da13e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/HashCodeVisitor.java @@ -0,0 +1,518 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that calculates a deep hash code for a node by using the hash codes of all its properties, + * and the hash codes of all its child nodes (by visiting those too.) + */ +public class HashCodeVisitor implements GenericVisitor { + + private static final HashCodeVisitor SINGLETON = new HashCodeVisitor(); + + private HashCodeVisitor() { + // hide constructor + } + + public static int hashCode(final Node node) { + return node.accept(SINGLETON, null); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final AnnotationDeclaration n, final Void arg) { + return (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final AnnotationMemberDeclaration n, final Void arg) { + return (n.getDefaultValue().isPresent() ? n.getDefaultValue().get().accept(this, arg) : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ArrayAccessExpr n, final Void arg) { + return (n.getIndex().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ArrayCreationExpr n, final Void arg) { + return (n.getElementType().accept(this, arg)) * 31 + (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getLevels().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ArrayCreationLevel n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDimension().isPresent() ? n.getDimension().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ArrayInitializerExpr n, final Void arg) { + return (n.getValues().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ArrayType n, final Void arg) { + return (n.getComponentType().accept(this, arg)) * 31 + (n.getOrigin().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final AssertStmt n, final Void arg) { + return (n.getCheck().accept(this, arg)) * 31 + (n.getMessage().isPresent() ? n.getMessage().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final AssignExpr n, final Void arg) { + return (n.getOperator().hashCode()) * 31 + (n.getTarget().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final BinaryExpr n, final Void arg) { + return (n.getLeft().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getRight().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final BlockComment n, final Void arg) { + return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final BlockStmt n, final Void arg) { + return (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final BooleanLiteralExpr n, final Void arg) { + return (n.getValue() ? 1 : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final BreakStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final CastExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final CatchClause n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getParameter().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final CharLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ClassExpr n, final Void arg) { + return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) { + return (n.getExtendedTypes().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.isInterface() ? 1 : 0) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceType n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final CompilationUnit n, final Void arg) { + return (n.getImports().accept(this, arg)) * 31 + (n.getModule().isPresent() ? n.getModule().get().accept(this, arg) : 0) * 31 + (n.getPackageDeclaration().isPresent() ? n.getPackageDeclaration().get().accept(this, arg) : 0) * 31 + (n.getTypes().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ConditionalExpr n, final Void arg) { + return (n.getCondition().accept(this, arg)) * 31 + (n.getElseExpr().accept(this, arg)) * 31 + (n.getThenExpr().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ConstructorDeclaration n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ContinueStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final DoStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final DoubleLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final EmptyStmt n, final Void arg) { + return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final EnclosedExpr n, final Void arg) { + return (n.getInner().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final EnumConstantDeclaration n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getClassBody().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final EnumDeclaration n, final Void arg) { + return (n.getEntries().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0) * 31 + (n.isThis() ? 1 : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ExpressionStmt n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final FieldAccessExpr n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final FieldDeclaration n, final Void arg) { + return (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ForStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ForeachStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final IfStmt n, final Void arg) { + return (n.getCondition().accept(this, arg)) * 31 + (n.getElseStmt().isPresent() ? n.getElseStmt().get().accept(this, arg) : 0) * 31 + (n.getThenStmt().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ImportDeclaration n, final Void arg) { + return (n.isAsterisk() ? 1 : 0) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final InitializerDeclaration n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final InstanceOfExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final IntegerLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final IntersectionType n, final Void arg) { + return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final JavadocComment n, final Void arg) { + return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final LabeledStmt n, final Void arg) { + return (n.getLabel().accept(this, arg)) * 31 + (n.getStatement().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final LambdaExpr n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final LineComment n, final Void arg) { + return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final LocalClassDeclarationStmt n, final Void arg) { + return (n.getClassDeclaration().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final LongLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final MarkerAnnotationExpr n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final MemberValuePair n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final MethodCallExpr n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final MethodDeclaration n, final Void arg) { + return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final MethodReferenceExpr n, final Void arg) { + return (n.getIdentifier().hashCode()) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final NameExpr n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final Name n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getIdentifier().hashCode()) * 31 + (n.getQualifier().isPresent() ? n.getQualifier().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + public Integer visit(NodeList n, Void arg) { + int result = 0; + for (Object node : n) { + result += 31 * ((Visitable) node).accept(this, arg); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final NormalAnnotationExpr n, final Void arg) { + return (n.getPairs().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final NullLiteralExpr n, final Void arg) { + return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ObjectCreationExpr n, final Void arg) { + return (n.getAnonymousClassBody().isPresent() ? n.getAnonymousClassBody().get().accept(this, arg) : 0) * 31 + (n.getArguments().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final PackageDeclaration n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final Parameter n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.isVarArgs() ? 1 : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getVarArgsAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final PrimitiveType n, final Void arg) { + return (n.getType().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ReturnStmt n, final Void arg) { + return (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SimpleName n, final Void arg) { + return (n.getIdentifier().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) { + return (n.getMemberValue().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final StringLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SuperExpr n, final Void arg) { + return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SwitchEntryStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SwitchStmt n, final Void arg) { + return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final SynchronizedStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ThisExpr n, final Void arg) { + return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ThrowStmt n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final TryStmt n, final Void arg) { + return (n.getCatchClauses().accept(this, arg)) * 31 + (n.getFinallyBlock().isPresent() ? n.getFinallyBlock().get().accept(this, arg) : 0) * 31 + (n.getResources().accept(this, arg)) * 31 + (n.getTryBlock().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final TypeExpr n, final Void arg) { + return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final TypeParameter n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getTypeBound().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final UnaryExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final UnionType n, final Void arg) { + return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final UnknownType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final VariableDeclarationExpr n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final VariableDeclarator n, final Void arg) { + return (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final VoidType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final WhileStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final WildcardType n, final Void arg) { + return (n.getExtendedType().isPresent() ? n.getExtendedType().get().accept(this, arg) : 0) * 31 + (n.getSuperType().isPresent() ? n.getSuperType().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleDeclaration n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.isOpen() ? 1 : 0) * 31 + (n.getModuleStmts().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleRequiresStmt n, final Void arg) { + return (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleExportsStmt n, final Void arg) { + return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleProvidesStmt n, final Void arg) { + return (n.getType().accept(this, arg)) * 31 + (n.getWithTypes().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleUsesStmt n, final Void arg) { + return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ModuleOpensStmt n, final Void arg) { + return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final UnparsableStmt n, final Void arg) { + return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator") + public Integer visit(final ReceiverParameter n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } + + @Override + public Integer visit(final VarType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitor.java new file mode 100644 index 0000000..c780864 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitor.java @@ -0,0 +1,1297 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import com.github.javaparser.utils.Pair; +import javax.annotation.Generated; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * This visitor can be used to save time when some specific nodes needs + * to be changed. To do that just extend this class and override the methods + * from the nodes who needs to be changed, returning the changed node. + * Returning null will remove the node. + * + * If a node is removed that was required in its parent node, + * the parent node will be removed too. + * + * @author Julio Vilmar Gesser + */ +public class ModifierVisitor implements GenericVisitor { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final AnnotationDeclaration n, final A arg) { + NodeList> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setMembers(members); + n.setName(name); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { + Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || type == null) + return null; + n.setDefaultValue(defaultValue); + n.setName(name); + n.setType(type); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ArrayAccessExpr n, final A arg) { + Expression index = (Expression) n.getIndex().accept(this, arg); + Expression name = (Expression) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (index == null || name == null) + return null; + n.setIndex(index); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ArrayCreationExpr n, final A arg) { + Type elementType = (Type) n.getElementType().accept(this, arg); + ArrayInitializerExpr initializer = n.getInitializer().map(s -> (ArrayInitializerExpr) s.accept(this, arg)).orElse(null); + NodeList levels = modifyList(n.getLevels(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (elementType == null || levels.isEmpty()) + return null; + n.setElementType(elementType); + n.setInitializer(initializer); + n.setLevels(levels); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ArrayInitializerExpr n, final A arg) { + NodeList values = modifyList(n.getValues(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setValues(values); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final AssertStmt n, final A arg) { + Expression check = (Expression) n.getCheck().accept(this, arg); + Expression message = n.getMessage().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (check == null) + return null; + n.setCheck(check); + n.setMessage(message); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final AssignExpr n, final A arg) { + Expression target = (Expression) n.getTarget().accept(this, arg); + Expression value = (Expression) n.getValue().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (target == null || value == null) + return null; + n.setTarget(target); + n.setValue(value); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final BinaryExpr n, final A arg) { + Expression left = (Expression) n.getLeft().accept(this, arg); + Expression right = (Expression) n.getRight().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (left == null) + return right; + if (right == null) + return left; + n.setLeft(left); + n.setRight(right); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final BlockStmt n, final A arg) { + NodeList statements = modifyList(n.getStatements(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setStatements(statements); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final BooleanLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final BreakStmt n, final A arg) { + SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setLabel(label); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final CastExpr n, final A arg) { + Expression expression = (Expression) n.getExpression().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (expression == null || type == null) + return null; + n.setExpression(expression); + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final CatchClause n, final A arg) { + BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + Parameter parameter = (Parameter) n.getParameter().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || parameter == null) + return null; + n.setBody(body); + n.setParameter(parameter); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final CharLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ClassExpr n, final A arg) { + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null) + return null; + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) { + NodeList extendedTypes = modifyList(n.getExtendedTypes(), arg); + NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); + NodeList typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setExtendedTypes(extendedTypes); + n.setImplementedTypes(implementedTypes); + n.setTypeParameters(typeParameters); + n.setMembers(members); + n.setName(name); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ClassOrInterfaceType n, final A arg) { + SimpleName name = (SimpleName) n.getName().accept(this, arg); + ClassOrInterfaceType scope = n.getScope().map(s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setScope(scope); + n.setTypeArguments(typeArguments); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final CompilationUnit n, final A arg) { + NodeList imports = modifyList(n.getImports(), arg); + ModuleDeclaration module = n.getModule().map(s -> (ModuleDeclaration) s.accept(this, arg)).orElse(null); + PackageDeclaration packageDeclaration = n.getPackageDeclaration().map(s -> (PackageDeclaration) s.accept(this, arg)).orElse(null); + NodeList> types = modifyList(n.getTypes(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setImports(imports); + n.setModule(module); + n.setPackageDeclaration(packageDeclaration); + n.setTypes(types); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ConditionalExpr n, final A arg) { + Expression condition = (Expression) n.getCondition().accept(this, arg); + Expression elseExpr = (Expression) n.getElseExpr().accept(this, arg); + Expression thenExpr = (Expression) n.getThenExpr().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (condition == null || elseExpr == null || thenExpr == null) + return null; + n.setCondition(condition); + n.setElseExpr(elseExpr); + n.setThenExpr(thenExpr); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ConstructorDeclaration n, final A arg) { + BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList parameters = modifyList(n.getParameters(), arg); + ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); + NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); + NodeList typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || name == null) + return null; + n.setBody(body); + n.setName(name); + n.setParameters(parameters); + n.setReceiverParameter(receiverParameter); + n.setThrownExceptions(thrownExceptions); + n.setTypeParameters(typeParameters); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ContinueStmt n, final A arg) { + SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setLabel(label); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final DoStmt n, final A arg) { + Statement body = (Statement) n.getBody().accept(this, arg); + Expression condition = (Expression) n.getCondition().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || condition == null) + return null; + n.setBody(body); + n.setCondition(condition); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final DoubleLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final EmptyStmt n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final EnclosedExpr n, final A arg) { + Expression inner = (Expression) n.getInner().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (inner == null) + return null; + n.setInner(inner); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final EnumConstantDeclaration n, final A arg) { + NodeList arguments = modifyList(n.getArguments(), arg); + NodeList> classBody = modifyList(n.getClassBody(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setArguments(arguments); + n.setClassBody(classBody); + n.setName(name); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final EnumDeclaration n, final A arg) { + NodeList entries = modifyList(n.getEntries(), arg); + NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); + NodeList> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setEntries(entries); + n.setImplementedTypes(implementedTypes); + n.setMembers(members); + n.setName(name); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ExplicitConstructorInvocationStmt n, final A arg) { + NodeList arguments = modifyList(n.getArguments(), arg); + Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setArguments(arguments); + n.setExpression(expression); + n.setTypeArguments(typeArguments); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ExpressionStmt n, final A arg) { + Expression expression = (Expression) n.getExpression().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (expression == null) + return null; + n.setExpression(expression); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final FieldAccessExpr n, final A arg) { + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Expression scope = (Expression) n.getScope().accept(this, arg); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || scope == null) + return null; + n.setName(name); + n.setScope(scope); + n.setTypeArguments(typeArguments); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final FieldDeclaration n, final A arg) { + NodeList variables = modifyList(n.getVariables(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (variables.isEmpty()) + return null; + n.setVariables(variables); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ForeachStmt n, final A arg) { + Statement body = (Statement) n.getBody().accept(this, arg); + Expression iterable = (Expression) n.getIterable().accept(this, arg); + VariableDeclarationExpr variable = (VariableDeclarationExpr) n.getVariable().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || iterable == null || variable == null) + return null; + n.setBody(body); + n.setIterable(iterable); + n.setVariable(variable); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ForStmt n, final A arg) { + Statement body = (Statement) n.getBody().accept(this, arg); + Expression compare = n.getCompare().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList initialization = modifyList(n.getInitialization(), arg); + NodeList update = modifyList(n.getUpdate(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null) + return null; + n.setBody(body); + n.setCompare(compare); + n.setInitialization(initialization); + n.setUpdate(update); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final IfStmt n, final A arg) { + Expression condition = (Expression) n.getCondition().accept(this, arg); + Statement elseStmt = n.getElseStmt().map(s -> (Statement) s.accept(this, arg)).orElse(null); + Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (condition == null || thenStmt == null) + return null; + n.setCondition(condition); + n.setElseStmt(elseStmt); + n.setThenStmt(thenStmt); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final InitializerDeclaration n, final A arg) { + BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null) + return null; + n.setBody(body); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final InstanceOfExpr n, final A arg) { + Expression expression = (Expression) n.getExpression().accept(this, arg); + ReferenceType type = (ReferenceType) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (expression == null || type == null) + return null; + n.setExpression(expression); + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final IntegerLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final JavadocComment n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final LabeledStmt n, final A arg) { + SimpleName label = (SimpleName) n.getLabel().accept(this, arg); + Statement statement = (Statement) n.getStatement().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (label == null || statement == null) + return null; + n.setLabel(label); + n.setStatement(statement); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final LongLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final MarkerAnnotationExpr n, final A arg) { + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final MemberValuePair n, final A arg) { + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Expression value = (Expression) n.getValue().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || value == null) + return null; + n.setName(name); + n.setValue(value); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final MethodCallExpr n, final A arg) { + NodeList arguments = modifyList(n.getArguments(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setArguments(arguments); + n.setName(name); + n.setScope(scope); + n.setTypeArguments(typeArguments); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final MethodDeclaration n, final A arg) { + BlockStmt body = n.getBody().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); + Type type = (Type) n.getType().accept(this, arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList parameters = modifyList(n.getParameters(), arg); + ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); + NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); + NodeList typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null || name == null) + return null; + n.setBody(body); + n.setType(type); + n.setName(name); + n.setParameters(parameters); + n.setReceiverParameter(receiverParameter); + n.setThrownExceptions(thrownExceptions); + n.setTypeParameters(typeParameters); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final NameExpr n, final A arg) { + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final NormalAnnotationExpr n, final A arg) { + NodeList pairs = modifyList(n.getPairs(), arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setPairs(pairs); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final NullLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ObjectCreationExpr n, final A arg) { + NodeList> anonymousClassBody = modifyList(n.getAnonymousClassBody(), arg); + NodeList arguments = modifyList(n.getArguments(), arg); + Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null); + ClassOrInterfaceType type = (ClassOrInterfaceType) n.getType().accept(this, arg); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null) + return null; + n.setAnonymousClassBody(anonymousClassBody); + n.setArguments(arguments); + n.setScope(scope); + n.setType(type); + n.setTypeArguments(typeArguments); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final PackageDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setAnnotations(annotations); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final Parameter n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + NodeList varArgsAnnotations = modifyList(n.getVarArgsAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || type == null) + return null; + n.setAnnotations(annotations); + n.setName(name); + n.setType(type); + n.setVarArgsAnnotations(varArgsAnnotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final Name n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Name qualifier = n.getQualifier().map(s -> (Name) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setQualifier(qualifier); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final PrimitiveType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SimpleName n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ArrayType n, final A arg) { + Type componentType = (Type) n.getComponentType().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (componentType == null) + return null; + n.setComponentType(componentType); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ArrayCreationLevel n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Expression dimension = n.getDimension().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setDimension(dimension); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final IntersectionType n, final A arg) { + NodeList elements = modifyList(n.getElements(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (elements.isEmpty()) + return null; + n.setElements(elements); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final UnionType n, final A arg) { + NodeList elements = modifyList(n.getElements(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (elements.isEmpty()) + return null; + n.setElements(elements); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ReturnStmt n, final A arg) { + Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setExpression(expression); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SingleMemberAnnotationExpr n, final A arg) { + Expression memberValue = (Expression) n.getMemberValue().accept(this, arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (memberValue == null || name == null) + return null; + n.setMemberValue(memberValue); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final StringLiteralExpr n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SuperExpr n, final A arg) { + Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setClassExpr(classExpr); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SwitchEntryStmt n, final A arg) { + Expression label = n.getLabel().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList statements = modifyList(n.getStatements(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setLabel(label); + n.setStatements(statements); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SwitchStmt n, final A arg) { + NodeList entries = modifyList(n.getEntries(), arg); + Expression selector = (Expression) n.getSelector().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (selector == null) + return null; + n.setEntries(entries); + n.setSelector(selector); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final SynchronizedStmt n, final A arg) { + BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + Expression expression = (Expression) n.getExpression().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || expression == null) + return null; + n.setBody(body); + n.setExpression(expression); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ThisExpr n, final A arg) { + Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setClassExpr(classExpr); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ThrowStmt n, final A arg) { + Expression expression = (Expression) n.getExpression().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (expression == null) + return null; + n.setExpression(expression); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final TryStmt n, final A arg) { + NodeList catchClauses = modifyList(n.getCatchClauses(), arg); + BlockStmt finallyBlock = n.getFinallyBlock().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); + NodeList resources = modifyList(n.getResources(), arg); + BlockStmt tryBlock = (BlockStmt) n.getTryBlock().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (tryBlock == null) + return null; + n.setCatchClauses(catchClauses); + n.setFinallyBlock(finallyBlock); + n.setResources(resources); + n.setTryBlock(tryBlock); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final LocalClassDeclarationStmt n, final A arg) { + ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) n.getClassDeclaration().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (classDeclaration == null) + return null; + n.setClassDeclaration(classDeclaration); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final TypeParameter n, final A arg) { + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList typeBound = modifyList(n.getTypeBound(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setTypeBound(typeBound); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final UnaryExpr n, final A arg) { + Expression expression = (Expression) n.getExpression().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (expression == null) + return null; + n.setExpression(expression); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final UnknownType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final VariableDeclarationExpr n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList variables = modifyList(n.getVariables(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (variables.isEmpty()) + return null; + n.setAnnotations(annotations); + n.setVariables(variables); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final VariableDeclarator n, final A arg) { + Expression initializer = n.getInitializer().map(s -> (Expression) s.accept(this, arg)).orElse(null); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || type == null) + return null; + n.setInitializer(initializer); + n.setName(name); + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final VoidType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final WhileStmt n, final A arg) { + Statement body = (Statement) n.getBody().accept(this, arg); + Expression condition = (Expression) n.getCondition().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null || condition == null) + return null; + n.setBody(body); + n.setCondition(condition); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final WildcardType n, final A arg) { + ReferenceType extendedType = n.getExtendedType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); + ReferenceType superType = n.getSuperType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setExtendedType(extendedType); + n.setSuperType(superType); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final LambdaExpr n, final A arg) { + Statement body = (Statement) n.getBody().accept(this, arg); + NodeList parameters = modifyList(n.getParameters(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (body == null) + return null; + n.setBody(body); + n.setParameters(parameters); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final MethodReferenceExpr n, final A arg) { + Expression scope = (Expression) n.getScope().accept(this, arg); + NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (scope == null) + return null; + n.setScope(scope); + n.setTypeArguments(typeArguments); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final TypeExpr n, final A arg) { + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null) + return null; + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + public Visitable visit(NodeList n, A arg) { + if (n.isEmpty()) { + return n; + } + final List> changeList = new ArrayList<>(); + final List listCopy = new ArrayList<>(n); + for (Node node : listCopy) { + final Node newNode = (Node) node.accept(this, arg); + changeList.add(new Pair<>(node, newNode)); + } + for (Pair change : changeList) { + if (change.b == null) { + n.remove(change.a); + } else { + final int i = n.indexOf(change.a); + // If the user removed this item by hand, ignore the change. + if (i != -1) { + n.set(i, change.b); + } + } + } + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Node visit(final ImportDeclaration n, final A arg) { + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final BlockComment n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final LineComment n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + private NodeList modifyList(NodeList list, A arg) { + return (NodeList) list.accept(this, arg); + } + + private NodeList modifyList(Optional> list, A arg) { + return list.map(ns -> modifyList(ns, arg)).orElse(null); + } + + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList moduleStmts = modifyList(n.getModuleStmts(), arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setAnnotations(annotations); + n.setModuleStmts(moduleStmts); + n.setName(name); + n.setComment(comment); + return n; + } + + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleRequiresStmt n, final A arg) { + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setName(name); + n.setComment(comment); + return n; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleExportsStmt n, final A arg) { + NodeList moduleNames = modifyList(n.getModuleNames(), arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setModuleNames(moduleNames); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleProvidesStmt n, final A arg) { + Type type = (Type) n.getType().accept(this, arg); + NodeList withTypes = modifyList(n.getWithTypes(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null) + return null; + n.setType(type); + n.setWithTypes(withTypes); + n.setComment(comment); + return n; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleUsesStmt n, final A arg) { + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (type == null) + return null; + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ModuleOpensStmt n, final A arg) { + NodeList moduleNames = modifyList(n.getModuleNames(), arg); + Name name = (Name) n.getName().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setModuleNames(moduleNames); + n.setName(name); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final UnparsableStmt n, final A arg) { + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setComment(comment); + return n; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final ReceiverParameter n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Name name = (Name) n.getName().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null || type == null) + return null; + n.setAnnotations(annotations); + n.setName(name); + n.setType(type); + n.setComment(comment); + return n; + } + + @Override + public Visitable visit(final VarType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); + n.setComment(comment); + return n; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java b/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java deleted file mode 100644 index e834c5e..0000000 --- a/JavaParser/src/com/github/javaparser/ast/visitor/ModifierVisitorAdapter.java +++ /dev/null @@ -1,972 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BaseParameter; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.expr.ArrayAccessExpr; -import com.github.javaparser.ast.expr.ArrayCreationExpr; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.IntegerLiteralMinValueExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.LongLiteralMinValueExpr; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.QualifiedNameExpr; -import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.SuperExpr; -import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.ast.expr.TypeExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -import java.util.LinkedList; -import java.util.List; - -/** - * This visitor adapter can be used to save time when some specific nodes needs - * to be changed. To do that just extend this class and override the methods - * from the nodes who needs to be changed, returning the changed node. - * - * @author Julio Vilmar Gesser - */ -public abstract class ModifierVisitorAdapter implements GenericVisitor { - - private void removeNulls(final List list) { - for (int i = list.size() - 1; i >= 0; i--) { - if (list.get(i) == null) { - list.remove(i); - } - } - } - - @Override public Node visit(final AnnotationDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List members = n.getMembers(); - if (members != null) { - for (int i = 0; i < members.size(); i++) { - members.set(i, (BodyDeclaration) members.get(i).accept(this, arg)); - } - removeNulls(members); - } - return n; - } - - @Override public Node visit(final AnnotationMemberDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - n.setType((Type) n.getType().accept(this, arg)); - if (n.getDefaultValue() != null) { - n.setDefaultValue((Expression) n.getDefaultValue().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final ArrayAccessExpr n, final A arg) { - n.setName((Expression) n.getName().accept(this, arg)); - n.setIndex((Expression) n.getIndex().accept(this, arg)); - return n; - } - - @Override public Node visit(final ArrayCreationExpr n, final A arg) { - n.setType((Type) n.getType().accept(this, arg)); - if (n.getDimensions() != null) { - final List dimensions = n.getDimensions(); - if (dimensions != null) { - for (int i = 0; i < dimensions.size(); i++) { - dimensions.set(i, (Expression) dimensions.get(i).accept(this, arg)); - } - removeNulls(dimensions); - } - } else { - n.setInitializer((ArrayInitializerExpr) n.getInitializer().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final ArrayInitializerExpr n, final A arg) { - if (n.getValues() != null) { - final List values = n.getValues(); - if (values != null) { - for (int i = 0; i < values.size(); i++) { - values.set(i, (Expression) values.get(i).accept(this, arg)); - } - removeNulls(values); - } - } - return n; - } - - @Override public Node visit(final AssertStmt n, final A arg) { - n.setCheck((Expression) n.getCheck().accept(this, arg)); - if (n.getMessage() != null) { - n.setMessage((Expression) n.getMessage().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final AssignExpr n, final A arg) { - n.setTarget((Expression) n.getTarget().accept(this, arg)); - n.setValue((Expression) n.getValue().accept(this, arg)); - return n; - } - - @Override public Node visit(final BinaryExpr n, final A arg) { - n.setLeft((Expression) n.getLeft().accept(this, arg)); - n.setRight((Expression) n.getRight().accept(this, arg)); - return n; - } - - @Override public Node visit(final BlockStmt n, final A arg) { - final List stmts = n.getStmts(); - if (stmts != null) { - for (int i = 0; i < stmts.size(); i++) { - stmts.set(i, (Statement) stmts.get(i).accept(this, arg)); - } - removeNulls(stmts); - } - return n; - } - - @Override public Node visit(final BooleanLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final BreakStmt n, final A arg) { - return n; - } - - @Override public Node visit(final CastExpr n, final A arg) { - n.setType((Type) n.getType().accept(this, arg)); - n.setExpr((Expression) n.getExpr().accept(this, arg)); - return n; - } - - @Override public Node visit(final CatchClause n, final A arg) { - n.setExcept((MultiTypeParameter) n.getExcept().accept(this, arg)); - n.setCatchBlock((BlockStmt) n.getCatchBlock().accept(this, arg)); - return n; - - } - - @Override public Node visit(final CharLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final ClassExpr n, final A arg) { - n.setType((Type) n.getType().accept(this, arg)); - return n; - } - - @Override public Node visit(final ClassOrInterfaceDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List typeParameters = n.getTypeParameters(); - if (typeParameters != null) { - for (int i = 0; i < typeParameters.size(); i++) { - typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); - } - removeNulls(typeParameters); - } - final List extendz = n.getExtends(); - if (extendz != null) { - for (int i = 0; i < extendz.size(); i++) { - extendz.set(i, (ClassOrInterfaceType) extendz.get(i).accept(this, arg)); - } - removeNulls(extendz); - } - final List implementz = n.getImplements(); - if (implementz != null) { - for (int i = 0; i < implementz.size(); i++) { - implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg)); - } - removeNulls(implementz); - } - final List members = n.getMembers(); - if (members != null) { - for (int i = 0; i < members.size(); i++) { - members.set(i, (BodyDeclaration) members.get(i).accept(this, arg)); - } - removeNulls(members); - } - return n; - } - - @Override public Node visit(final ClassOrInterfaceType n, final A arg) { - if (n.getScope() != null) { - n.setScope((ClassOrInterfaceType) n.getScope().accept(this, arg)); - } - final List typeArgs = n.getTypeArgs(); - if (typeArgs != null) { - for (int i = 0; i < typeArgs.size(); i++) { - typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg)); - } - removeNulls(typeArgs); - } - return n; - } - - @Override public Node visit(final CompilationUnit n, final A arg) { - if (n.getPackage() != null) { - n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg)); - } - final List imports = n.getImports(); - if (imports != null) { - for (int i = 0; i < imports.size(); i++) { - imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg)); - } - removeNulls(imports); - } - final List types = n.getTypes(); - if (types != null) { - for (int i = 0; i < types.size(); i++) { - types.set(i, (TypeDeclaration) types.get(i).accept(this, arg)); - } - removeNulls(types); - } - return n; - } - - @Override public Node visit(final ConditionalExpr n, final A arg) { - n.setCondition((Expression) n.getCondition().accept(this, arg)); - n.setThenExpr((Expression) n.getThenExpr().accept(this, arg)); - n.setElseExpr((Expression) n.getElseExpr().accept(this, arg)); - return n; - } - - @Override public Node visit(final ConstructorDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List typeParameters = n.getTypeParameters(); - if (typeParameters != null) { - for (int i = 0; i < typeParameters.size(); i++) { - typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); - } - removeNulls(typeParameters); - } - final List parameters = n.getParameters(); - if (parameters != null) { - for (int i = 0; i < parameters.size(); i++) { - parameters.set(i, (Parameter) parameters.get(i).accept(this, arg)); - } - removeNulls(parameters); - } - final List throwz = n.getThrows(); - if (throwz != null) { - for (int i = 0; i < throwz.size(); i++) { - throwz.set(i, (NameExpr) throwz.get(i).accept(this, arg)); - } - removeNulls(throwz); - } - n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); - return n; - } - - @Override public Node visit(final ContinueStmt n, final A arg) { - return n; - } - - @Override public Node visit(final DoStmt n, final A arg) { - n.setBody((Statement) n.getBody().accept(this, arg)); - n.setCondition((Expression) n.getCondition().accept(this, arg)); - return n; - } - - @Override public Node visit(final DoubleLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final EmptyMemberDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final EmptyStmt n, final A arg) { - return n; - } - - @Override public Node visit(final EmptyTypeDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final EnclosedExpr n, final A arg) { - n.setInner((Expression) n.getInner().accept(this, arg)); - return n; - } - - @Override public Node visit(final EnumConstantDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List args = n.getArgs(); - if (args != null) { - for (int i = 0; i < args.size(); i++) { - args.set(i, (Expression) args.get(i).accept(this, arg)); - } - removeNulls(args); - } - final List classBody = n.getClassBody(); - if (classBody != null) { - for (int i = 0; i < classBody.size(); i++) { - classBody.set(i, (BodyDeclaration) classBody.get(i).accept(this, arg)); - } - removeNulls(classBody); - } - return n; - } - - @Override public Node visit(final EnumDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List implementz = n.getImplements(); - if (implementz != null) { - for (int i = 0; i < implementz.size(); i++) { - implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg)); - } - removeNulls(implementz); - } - final List entries = n.getEntries(); - if (entries != null) { - for (int i = 0; i < entries.size(); i++) { - entries.set(i, (EnumConstantDeclaration) entries.get(i).accept(this, arg)); - } - removeNulls(entries); - } - final List members = n.getMembers(); - if (members != null) { - for (int i = 0; i < members.size(); i++) { - members.set(i, (BodyDeclaration) members.get(i).accept(this, arg)); - } - removeNulls(members); - } - return n; - } - - @Override public Node visit(final ExplicitConstructorInvocationStmt n, final A arg) { - if (!n.isThis()) { - if (n.getExpr() != null) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - } - } - final List typeArgs = n.getTypeArgs(); - if (typeArgs != null) { - for (int i = 0; i < typeArgs.size(); i++) { - typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg)); - } - removeNulls(typeArgs); - } - final List args = n.getArgs(); - if (args != null) { - for (int i = 0; i < args.size(); i++) { - args.set(i, (Expression) args.get(i).accept(this, arg)); - } - removeNulls(args); - } - return n; - } - - @Override public Node visit(final ExpressionStmt n, final A arg) { - n.setExpression((Expression) n.getExpression().accept(this, arg)); - return n; - } - - @Override public Node visit(final FieldAccessExpr n, final A arg) { - n.setScope((Expression) n.getScope().accept(this, arg)); - return n; - } - - @Override public Node visit(final FieldDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - n.setType((Type) n.getType().accept(this, arg)); - final List variables = n.getVariables(); - for (int i = 0; i < variables.size(); i++) { - variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg)); - } - removeNulls(variables); - return n; - } - - @Override public Node visit(final ForeachStmt n, final A arg) { - n.setVariable((VariableDeclarationExpr) n.getVariable().accept(this, arg)); - n.setIterable((Expression) n.getIterable().accept(this, arg)); - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Node visit(final ForStmt n, final A arg) { - final List init = n.getInit(); - if (init != null) { - for (int i = 0; i < init.size(); i++) { - init.set(i, (Expression) init.get(i).accept(this, arg)); - } - removeNulls(init); - } - if (n.getCompare() != null) { - n.setCompare((Expression) n.getCompare().accept(this, arg)); - } - final List update = n.getUpdate(); - if (update != null) { - for (int i = 0; i < update.size(); i++) { - update.set(i, (Expression) update.get(i).accept(this, arg)); - } - removeNulls(update); - } - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Node visit(final IfStmt n, final A arg) { - n.setCondition((Expression) n.getCondition().accept(this, arg)); - n.setThenStmt((Statement) n.getThenStmt().accept(this, arg)); - if (n.getElseStmt() != null) { - n.setElseStmt((Statement) n.getElseStmt().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final ImportDeclaration n, final A arg) { - n.setName((NameExpr) n.getName().accept(this, arg)); - return n; - } - - @Override public Node visit(final InitializerDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); - return n; - } - - @Override public Node visit(final InstanceOfExpr n, final A arg) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - n.setType((Type) n.getType().accept(this, arg)); - return n; - } - - @Override public Node visit(final IntegerLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final IntegerLiteralMinValueExpr n, final A arg) { - return n; - } - - @Override public Node visit(final JavadocComment n, final A arg) { - return n; - } - - @Override public Node visit(final LabeledStmt n, final A arg) { - n.setStmt((Statement) n.getStmt().accept(this, arg)); - return n; - } - - @Override public Node visit(final LongLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final LongLiteralMinValueExpr n, final A arg) { - return n; - } - - @Override public Node visit(final MarkerAnnotationExpr n, final A arg) { - n.setName((NameExpr) n.getName().accept(this, arg)); - return n; - } - - @Override public Node visit(final MemberValuePair n, final A arg) { - n.setValue((Expression) n.getValue().accept(this, arg)); - return n; - } - - @Override public Node visit(final MethodCallExpr n, final A arg) { - if (n.getScope() != null) { - n.setScope((Expression) n.getScope().accept(this, arg)); - } - final List typeArgs = n.getTypeArgs(); - if (typeArgs != null) { - for (int i = 0; i < typeArgs.size(); i++) { - typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg)); - } - removeNulls(typeArgs); - } - final List args = n.getArgs(); - if (args != null) { - for (int i = 0; i < args.size(); i++) { - args.set(i, (Expression) args.get(i).accept(this, arg)); - } - removeNulls(args); - } - return n; - } - - @Override public Node visit(final MethodDeclaration n, final A arg) { - if (n.getJavaDoc() != null) { - n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); - } - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - final List typeParameters = n.getTypeParameters(); - if (typeParameters != null) { - for (int i = 0; i < typeParameters.size(); i++) { - typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg)); - } - removeNulls(typeParameters); - } - n.setType((Type) n.getType().accept(this, arg)); - final List parameters = n.getParameters(); - if (parameters != null) { - for (int i = 0; i < parameters.size(); i++) { - parameters.set(i, (Parameter) parameters.get(i).accept(this, arg)); - } - removeNulls(parameters); - } - final List throwz = n.getThrows(); - if (throwz != null) { - for (int i = 0; i < throwz.size(); i++) { - throwz.set(i, (NameExpr) throwz.get(i).accept(this, arg)); - } - removeNulls(throwz); - } - if (n.getBody() != null) { - n.setBody((BlockStmt) n.getBody().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final NameExpr n, final A arg) { - return n; - } - - @Override public Node visit(final NormalAnnotationExpr n, final A arg) { - n.setName((NameExpr) n.getName().accept(this, arg)); - final List pairs = n.getPairs(); - if (pairs != null) { - for (int i = 0; i < pairs.size(); i++) { - pairs.set(i, (MemberValuePair) pairs.get(i).accept(this, arg)); - } - removeNulls(pairs); - } - return n; - } - - @Override public Node visit(final NullLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final ObjectCreationExpr n, final A arg) { - if (n.getScope() != null) { - n.setScope((Expression) n.getScope().accept(this, arg)); - } - final List typeArgs = n.getTypeArgs(); - if (typeArgs != null) { - for (int i = 0; i < typeArgs.size(); i++) { - typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg)); - } - removeNulls(typeArgs); - } - n.setType((ClassOrInterfaceType) n.getType().accept(this, arg)); - final List args = n.getArgs(); - if (args != null) { - for (int i = 0; i < args.size(); i++) { - args.set(i, (Expression) args.get(i).accept(this, arg)); - } - removeNulls(args); - } - final List anonymousClassBody = n.getAnonymousClassBody(); - if (anonymousClassBody != null) { - for (int i = 0; i < anonymousClassBody.size(); i++) { - anonymousClassBody.set(i, (BodyDeclaration) anonymousClassBody.get(i).accept(this, arg)); - } - removeNulls(anonymousClassBody); - } - return n; - } - - @Override public Node visit(final PackageDeclaration n, final A arg) { - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - n.setName((NameExpr) n.getName().accept(this, arg)); - return n; - } - - @Override public Node visit(final Parameter n, final A arg) { - visit((BaseParameter) n, arg); - n.setType((Type) n.getType().accept(this, arg)); - return n; - } - - @Override public Node visit(MultiTypeParameter n, A arg) { - visit((BaseParameter) n, arg); - List types = new LinkedList(); - for (Type type : n.getTypes()) { - types.add((Type) type.accept(this, arg)); - } - n.setTypes(types); - return n; - } - - protected Node visit(final BaseParameter n, final A arg) { - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - - n.setId((VariableDeclaratorId) n.getId().accept(this, arg)); - return n; - } - - @Override public Node visit(final PrimitiveType n, final A arg) { - return n; - } - - @Override public Node visit(final QualifiedNameExpr n, final A arg) { - n.setQualifier((NameExpr) n.getQualifier().accept(this, arg)); - return n; - } - - @Override public Node visit(final ReferenceType n, final A arg) { - n.setType((Type) n.getType().accept(this, arg)); - return n; - } - - @Override public Node visit(final ReturnStmt n, final A arg) { - if (n.getExpr() != null) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final SingleMemberAnnotationExpr n, final A arg) { - n.setName((NameExpr) n.getName().accept(this, arg)); - n.setMemberValue((Expression) n.getMemberValue().accept(this, arg)); - return n; - } - - @Override public Node visit(final StringLiteralExpr n, final A arg) { - return n; - } - - @Override public Node visit(final SuperExpr n, final A arg) { - if (n.getClassExpr() != null) { - n.setClassExpr((Expression) n.getClassExpr().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final SwitchEntryStmt n, final A arg) { - if (n.getLabel() != null) { - n.setLabel((Expression) n.getLabel().accept(this, arg)); - } - final List stmts = n.getStmts(); - if (stmts != null) { - for (int i = 0; i < stmts.size(); i++) { - stmts.set(i, (Statement) stmts.get(i).accept(this, arg)); - } - removeNulls(stmts); - } - return n; - } - - @Override public Node visit(final SwitchStmt n, final A arg) { - n.setSelector((Expression) n.getSelector().accept(this, arg)); - final List entries = n.getEntries(); - if (entries != null) { - for (int i = 0; i < entries.size(); i++) { - entries.set(i, (SwitchEntryStmt) entries.get(i).accept(this, arg)); - } - removeNulls(entries); - } - return n; - - } - - @Override public Node visit(final SynchronizedStmt n, final A arg) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - n.setBlock((BlockStmt) n.getBlock().accept(this, arg)); - return n; - } - - @Override public Node visit(final ThisExpr n, final A arg) { - if (n.getClassExpr() != null) { - n.setClassExpr((Expression) n.getClassExpr().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final ThrowStmt n, final A arg) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - return n; - } - - @Override public Node visit(final TryStmt n, final A arg) { - n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg)); - final List catchs = n.getCatchs(); - if (catchs != null) { - for (int i = 0; i < catchs.size(); i++) { - catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg)); - } - removeNulls(catchs); - } - if (n.getFinallyBlock() != null) { - n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final TypeDeclarationStmt n, final A arg) { - n.setTypeDeclaration((TypeDeclaration) n.getTypeDeclaration().accept(this, arg)); - return n; - } - - @Override public Node visit(final TypeParameter n, final A arg) { - final List typeBound = n.getTypeBound(); - if (typeBound != null) { - for (int i = 0; i < typeBound.size(); i++) { - typeBound.set(i, (ClassOrInterfaceType) typeBound.get(i).accept(this, arg)); - } - removeNulls(typeBound); - } - return n; - } - - @Override public Node visit(final UnaryExpr n, final A arg) { - n.setExpr((Expression) n.getExpr().accept(this, arg)); - return n; - } - - @Override public Node visit(final UnknownType n, final A arg) { - return n; - } - - @Override public Node visit(final VariableDeclarationExpr n, final A arg) { - final List annotations = n.getAnnotations(); - if (annotations != null) { - for (int i = 0; i < annotations.size(); i++) { - annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); - } - removeNulls(annotations); - } - n.setType((Type) n.getType().accept(this, arg)); - final List vars = n.getVars(); - for (int i = 0; i < vars.size(); i++) { - vars.set(i, (VariableDeclarator) vars.get(i).accept(this, arg)); - } - removeNulls(vars); - return n; - } - - @Override public Node visit(final VariableDeclarator n, final A arg) { - n.setId((VariableDeclaratorId) n.getId().accept(this, arg)); - if (n.getInit() != null) { - n.setInit((Expression) n.getInit().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final VariableDeclaratorId n, final A arg) { - return n; - } - - @Override public Node visit(final VoidType n, final A arg) { - return n; - } - - @Override public Node visit(final WhileStmt n, final A arg) { - n.setCondition((Expression) n.getCondition().accept(this, arg)); - n.setBody((Statement) n.getBody().accept(this, arg)); - return n; - } - - @Override public Node visit(final WildcardType n, final A arg) { - if (n.getExtends() != null) { - n.setExtends((ReferenceType) n.getExtends().accept(this, arg)); - } - if (n.getSuper() != null) { - n.setSuper((ReferenceType) n.getSuper().accept(this, arg)); - } - return n; - } - - @Override public Node visit(final LambdaExpr n, final A arg) { - return n; - } - - @Override public Node visit(final MethodReferenceExpr n, final A arg){ - return n; - } - - @Override public Node visit(final TypeExpr n, final A arg){ - return n; - } - - @Override public Node visit(final BlockComment n, final A arg) { - return n; - } - - @Override public Node visit(final LineComment n, final A arg) { - return n; - } - -} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java new file mode 100644 index 0000000..b3c1dce --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java @@ -0,0 +1,1154 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; +import java.util.Optional; + +public class NoCommentEqualsVisitor implements GenericVisitor { + + private static final NoCommentEqualsVisitor SINGLETON = new NoCommentEqualsVisitor(); + + public static boolean equals(final Node n, final Node n2) { + return SINGLETON.nodeEquals(n, n2); + } + + private boolean nodesEquals(NodeList n, NodeList n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + if (n.size() != n2.size()) { + return false; + } + for (int i = 0; i < n.size(); i++) { + if (!nodeEquals(n.get(i), n2.get(i))) { + return false; + } + } + return true; + } + + private boolean nodeEquals(final T n, final T n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + if (n.getClass() != n2.getClass()) { + return false; + } + return n.accept(this, n2); + } + + private boolean nodeEquals(final Optional n, final Optional n2) { + return nodeEquals(n.orElse(null), n2.orElse(null)); + } + + private boolean nodesEquals(final Optional> n, final Optional> n2) { + return nodesEquals(n.orElse(null), n2.orElse(null)); + } + + private boolean objEquals(final Object n, final Object n2) { + if (n == n2) { + return true; + } + if (n == null || n2 == null) { + return false; + } + return n.equals(n2); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final CompilationUnit n, final Visitable arg) { + final CompilationUnit n2 = (CompilationUnit) arg; + if (!nodesEquals(n.getImports(), n2.getImports())) + return false; + if (!nodeEquals(n.getModule(), n2.getModule())) + return false; + if (!nodeEquals(n.getPackageDeclaration(), n2.getPackageDeclaration())) + return false; + if (!nodesEquals(n.getTypes(), n2.getTypes())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final PackageDeclaration n, final Visitable arg) { + final PackageDeclaration n2 = (PackageDeclaration) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final TypeParameter n, final Visitable arg) { + final TypeParameter n2 = (TypeParameter) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getTypeBound(), n2.getTypeBound())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final LineComment n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final BlockComment n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) { + final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg; + if (!nodesEquals(n.getExtendedTypes(), n2.getExtendedTypes())) + return false; + if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes())) + return false; + if (!objEquals(n.isInterface(), n2.isInterface())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final EnumDeclaration n, final Visitable arg) { + final EnumDeclaration n2 = (EnumDeclaration) arg; + if (!nodesEquals(n.getEntries(), n2.getEntries())) + return false; + if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes())) + return false; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) { + final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodesEquals(n.getClassBody(), n2.getClassBody())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final AnnotationDeclaration n, final Visitable arg) { + final AnnotationDeclaration n2 = (AnnotationDeclaration) arg; + if (!nodesEquals(n.getMembers(), n2.getMembers())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) { + final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg; + if (!nodeEquals(n.getDefaultValue(), n2.getDefaultValue())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final FieldDeclaration n, final Visitable arg) { + final FieldDeclaration n2 = (FieldDeclaration) arg; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodesEquals(n.getVariables(), n2.getVariables())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final VariableDeclarator n, final Visitable arg) { + final VariableDeclarator n2 = (VariableDeclarator) arg; + if (!nodeEquals(n.getInitializer(), n2.getInitializer())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ConstructorDeclaration n, final Visitable arg) { + final ConstructorDeclaration n2 = (ConstructorDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter())) + return false; + if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final MethodDeclaration n, final Visitable arg) { + final MethodDeclaration n2 = (MethodDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter())) + return false; + if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) + return false; + if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final Parameter n, final Visitable arg) { + final Parameter n2 = (Parameter) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.isVarArgs(), n2.isVarArgs())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getVarArgsAnnotations(), n2.getVarArgsAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final InitializerDeclaration n, final Visitable arg) { + final InitializerDeclaration n2 = (InitializerDeclaration) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.isStatic(), n2.isStatic())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final JavadocComment n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) { + final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final PrimitiveType n, final Visitable arg) { + final PrimitiveType n2 = (PrimitiveType) arg; + if (!objEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ArrayType n, final Visitable arg) { + final ArrayType n2 = (ArrayType) arg; + if (!nodeEquals(n.getComponentType(), n2.getComponentType())) + return false; + if (!objEquals(n.getOrigin(), n2.getOrigin())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ArrayCreationLevel n, final Visitable arg) { + final ArrayCreationLevel n2 = (ArrayCreationLevel) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getDimension(), n2.getDimension())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final IntersectionType n, final Visitable arg) { + final IntersectionType n2 = (IntersectionType) arg; + if (!nodesEquals(n.getElements(), n2.getElements())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final UnionType n, final Visitable arg) { + final UnionType n2 = (UnionType) arg; + if (!nodesEquals(n.getElements(), n2.getElements())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final VoidType n, final Visitable arg) { + final VoidType n2 = (VoidType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final WildcardType n, final Visitable arg) { + final WildcardType n2 = (WildcardType) arg; + if (!nodeEquals(n.getExtendedType(), n2.getExtendedType())) + return false; + if (!nodeEquals(n.getSuperType(), n2.getSuperType())) + return false; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final UnknownType n, final Visitable arg) { + final UnknownType n2 = (UnknownType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ArrayAccessExpr n, final Visitable arg) { + final ArrayAccessExpr n2 = (ArrayAccessExpr) arg; + if (!nodeEquals(n.getIndex(), n2.getIndex())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ArrayCreationExpr n, final Visitable arg) { + final ArrayCreationExpr n2 = (ArrayCreationExpr) arg; + if (!nodeEquals(n.getElementType(), n2.getElementType())) + return false; + if (!nodeEquals(n.getInitializer(), n2.getInitializer())) + return false; + if (!nodesEquals(n.getLevels(), n2.getLevels())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) { + final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg; + if (!nodesEquals(n.getValues(), n2.getValues())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final AssignExpr n, final Visitable arg) { + final AssignExpr n2 = (AssignExpr) arg; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + if (!nodeEquals(n.getTarget(), n2.getTarget())) + return false; + if (!nodeEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final BinaryExpr n, final Visitable arg) { + final BinaryExpr n2 = (BinaryExpr) arg; + if (!nodeEquals(n.getLeft(), n2.getLeft())) + return false; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + if (!nodeEquals(n.getRight(), n2.getRight())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final CastExpr n, final Visitable arg) { + final CastExpr n2 = (CastExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ClassExpr n, final Visitable arg) { + final ClassExpr n2 = (ClassExpr) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ConditionalExpr n, final Visitable arg) { + final ConditionalExpr n2 = (ConditionalExpr) arg; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getElseExpr(), n2.getElseExpr())) + return false; + if (!nodeEquals(n.getThenExpr(), n2.getThenExpr())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final EnclosedExpr n, final Visitable arg) { + final EnclosedExpr n2 = (EnclosedExpr) arg; + if (!nodeEquals(n.getInner(), n2.getInner())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final FieldAccessExpr n, final Visitable arg) { + final FieldAccessExpr n2 = (FieldAccessExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final InstanceOfExpr n, final Visitable arg) { + final InstanceOfExpr n2 = (InstanceOfExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final StringLiteralExpr n, final Visitable arg) { + final StringLiteralExpr n2 = (StringLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) { + final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final LongLiteralExpr n, final Visitable arg) { + final LongLiteralExpr n2 = (LongLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final CharLiteralExpr n, final Visitable arg) { + final CharLiteralExpr n2 = (CharLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) { + final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) { + final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg; + if (!objEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final NullLiteralExpr n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final MethodCallExpr n, final Visitable arg) { + final MethodCallExpr n2 = (MethodCallExpr) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final NameExpr n, final Visitable arg) { + final NameExpr n2 = (NameExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ObjectCreationExpr n, final Visitable arg) { + final ObjectCreationExpr n2 = (ObjectCreationExpr) arg; + if (!nodesEquals(n.getAnonymousClassBody(), n2.getAnonymousClassBody())) + return false; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final Name n, final Visitable arg) { + final Name n2 = (Name) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + if (!nodeEquals(n.getQualifier(), n2.getQualifier())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SimpleName n, final Visitable arg) { + final SimpleName n2 = (SimpleName) arg; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ThisExpr n, final Visitable arg) { + final ThisExpr n2 = (ThisExpr) arg; + if (!nodeEquals(n.getClassExpr(), n2.getClassExpr())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SuperExpr n, final Visitable arg) { + final SuperExpr n2 = (SuperExpr) arg; + if (!nodeEquals(n.getClassExpr(), n2.getClassExpr())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final UnaryExpr n, final Visitable arg) { + final UnaryExpr n2 = (UnaryExpr) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!objEquals(n.getOperator(), n2.getOperator())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) { + final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodesEquals(n.getVariables(), n2.getVariables())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) { + final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) { + final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg; + if (!nodeEquals(n.getMemberValue(), n2.getMemberValue())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) { + final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg; + if (!nodesEquals(n.getPairs(), n2.getPairs())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final MemberValuePair n, final Visitable arg) { + final MemberValuePair n2 = (MemberValuePair) arg; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getValue(), n2.getValue())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) { + final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg; + if (!nodesEquals(n.getArguments(), n2.getArguments())) + return false; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + if (!objEquals(n.isThis(), n2.isThis())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) { + final LocalClassDeclarationStmt n2 = (LocalClassDeclarationStmt) arg; + if (!nodeEquals(n.getClassDeclaration(), n2.getClassDeclaration())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final AssertStmt n, final Visitable arg) { + final AssertStmt n2 = (AssertStmt) arg; + if (!nodeEquals(n.getCheck(), n2.getCheck())) + return false; + if (!nodeEquals(n.getMessage(), n2.getMessage())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final BlockStmt n, final Visitable arg) { + final BlockStmt n2 = (BlockStmt) arg; + if (!nodesEquals(n.getStatements(), n2.getStatements())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final LabeledStmt n, final Visitable arg) { + final LabeledStmt n2 = (LabeledStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodeEquals(n.getStatement(), n2.getStatement())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final EmptyStmt n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ExpressionStmt n, final Visitable arg) { + final ExpressionStmt n2 = (ExpressionStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SwitchStmt n, final Visitable arg) { + final SwitchStmt n2 = (SwitchStmt) arg; + if (!nodesEquals(n.getEntries(), n2.getEntries())) + return false; + if (!nodeEquals(n.getSelector(), n2.getSelector())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SwitchEntryStmt n, final Visitable arg) { + final SwitchEntryStmt n2 = (SwitchEntryStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + if (!nodesEquals(n.getStatements(), n2.getStatements())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final BreakStmt n, final Visitable arg) { + final BreakStmt n2 = (BreakStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ReturnStmt n, final Visitable arg) { + final ReturnStmt n2 = (ReturnStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final IfStmt n, final Visitable arg) { + final IfStmt n2 = (IfStmt) arg; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!nodeEquals(n.getElseStmt(), n2.getElseStmt())) + return false; + if (!nodeEquals(n.getThenStmt(), n2.getThenStmt())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final WhileStmt n, final Visitable arg) { + final WhileStmt n2 = (WhileStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ContinueStmt n, final Visitable arg) { + final ContinueStmt n2 = (ContinueStmt) arg; + if (!nodeEquals(n.getLabel(), n2.getLabel())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final DoStmt n, final Visitable arg) { + final DoStmt n2 = (DoStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ForeachStmt n, final Visitable arg) { + final ForeachStmt n2 = (ForeachStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getIterable(), n2.getIterable())) + return false; + if (!nodeEquals(n.getVariable(), n2.getVariable())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ForStmt n, final Visitable arg) { + final ForStmt n2 = (ForStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getCompare(), n2.getCompare())) + return false; + if (!nodesEquals(n.getInitialization(), n2.getInitialization())) + return false; + if (!nodesEquals(n.getUpdate(), n2.getUpdate())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ThrowStmt n, final Visitable arg) { + final ThrowStmt n2 = (ThrowStmt) arg; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final SynchronizedStmt n, final Visitable arg) { + final SynchronizedStmt n2 = (SynchronizedStmt) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getExpression(), n2.getExpression())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final TryStmt n, final Visitable arg) { + final TryStmt n2 = (TryStmt) arg; + if (!nodesEquals(n.getCatchClauses(), n2.getCatchClauses())) + return false; + if (!nodeEquals(n.getFinallyBlock(), n2.getFinallyBlock())) + return false; + if (!nodesEquals(n.getResources(), n2.getResources())) + return false; + if (!nodeEquals(n.getTryBlock(), n2.getTryBlock())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final CatchClause n, final Visitable arg) { + final CatchClause n2 = (CatchClause) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!nodeEquals(n.getParameter(), n2.getParameter())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final LambdaExpr n, final Visitable arg) { + final LambdaExpr n2 = (LambdaExpr) arg; + if (!nodeEquals(n.getBody(), n2.getBody())) + return false; + if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters())) + return false; + if (!nodesEquals(n.getParameters(), n2.getParameters())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final MethodReferenceExpr n, final Visitable arg) { + final MethodReferenceExpr n2 = (MethodReferenceExpr) arg; + if (!objEquals(n.getIdentifier(), n2.getIdentifier())) + return false; + if (!nodeEquals(n.getScope(), n2.getScope())) + return false; + if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final TypeExpr n, final Visitable arg) { + final TypeExpr n2 = (TypeExpr) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ImportDeclaration n, final Visitable arg) { + final ImportDeclaration n2 = (ImportDeclaration) arg; + if (!objEquals(n.isAsterisk(), n2.isAsterisk())) + return false; + if (!objEquals(n.isStatic(), n2.isStatic())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + public Boolean visit(NodeList n, Visitable arg) { + return nodesEquals((NodeList) n, (NodeList) arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleDeclaration n, final Visitable arg) { + final ModuleDeclaration n2 = (ModuleDeclaration) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!objEquals(n.isOpen(), n2.isOpen())) + return false; + if (!nodesEquals(n.getModuleStmts(), n2.getModuleStmts())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) { + final ModuleRequiresStmt n2 = (ModuleRequiresStmt) arg; + if (!objEquals(n.getModifiers(), n2.getModifiers())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleExportsStmt n, final Visitable arg) { + final ModuleExportsStmt n2 = (ModuleExportsStmt) arg; + if (!nodesEquals(n.getModuleNames(), n2.getModuleNames())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) { + final ModuleProvidesStmt n2 = (ModuleProvidesStmt) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + if (!nodesEquals(n.getWithTypes(), n2.getWithTypes())) + return false; + return true; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleUsesStmt n, final Visitable arg) { + final ModuleUsesStmt n2 = (ModuleUsesStmt) arg; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ModuleOpensStmt n, final Visitable arg) { + final ModuleOpensStmt n2 = (ModuleOpensStmt) arg; + if (!nodesEquals(n.getModuleNames(), n2.getModuleNames())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final UnparsableStmt n, final Visitable arg) { + return true; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator") + public Boolean visit(final ReceiverParameter n, final Visitable arg) { + final ReceiverParameter n2 = (ReceiverParameter) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getType(), n2.getType())) + return false; + return true; + } + + @Override + public Boolean visit(final VarType n, final Visitable arg) { + final VarType n2 = (VarType) arg; + if (!nodesEquals(n.getAnnotations(), n2.getAnnotations())) + return false; + return true; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java new file mode 100644 index 0000000..774e5d9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java @@ -0,0 +1,510 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +public class NoCommentHashCodeVisitor implements GenericVisitor { + + private static final NoCommentHashCodeVisitor SINGLETON = new NoCommentHashCodeVisitor(); + + public static int hashCode(final Node node) { + return node.accept(SINGLETON, null); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final AnnotationDeclaration n, final Void arg) { + return (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final AnnotationMemberDeclaration n, final Void arg) { + return (n.getDefaultValue().isPresent() ? n.getDefaultValue().get().accept(this, arg) : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ArrayAccessExpr n, final Void arg) { + return (n.getIndex().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ArrayCreationExpr n, final Void arg) { + return (n.getElementType().accept(this, arg)) * 31 + (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getLevels().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ArrayCreationLevel n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDimension().isPresent() ? n.getDimension().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ArrayInitializerExpr n, final Void arg) { + return (n.getValues().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ArrayType n, final Void arg) { + return (n.getComponentType().accept(this, arg)) * 31 + (n.getOrigin().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final AssertStmt n, final Void arg) { + return (n.getCheck().accept(this, arg)) * 31 + (n.getMessage().isPresent() ? n.getMessage().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final AssignExpr n, final Void arg) { + return (n.getOperator().hashCode()) * 31 + (n.getTarget().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final BinaryExpr n, final Void arg) { + return (n.getLeft().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getRight().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final BlockComment n, final Void arg) { + return 0; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final BlockStmt n, final Void arg) { + return (n.getStatements().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final BooleanLiteralExpr n, final Void arg) { + return (n.getValue() ? 1 : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final BreakStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final CastExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final CatchClause n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getParameter().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final CharLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ClassExpr n, final Void arg) { + return (n.getType().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) { + return (n.getExtendedTypes().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.isInterface() ? 1 : 0) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceType n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final CompilationUnit n, final Void arg) { + return (n.getImports().accept(this, arg)) * 31 + (n.getModule().isPresent() ? n.getModule().get().accept(this, arg) : 0) * 31 + (n.getPackageDeclaration().isPresent() ? n.getPackageDeclaration().get().accept(this, arg) : 0) * 31 + (n.getTypes().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ConditionalExpr n, final Void arg) { + return (n.getCondition().accept(this, arg)) * 31 + (n.getElseExpr().accept(this, arg)) * 31 + (n.getThenExpr().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ConstructorDeclaration n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ContinueStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final DoStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final DoubleLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final EmptyStmt n, final Void arg) { + return 0; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final EnclosedExpr n, final Void arg) { + return (n.getInner().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final EnumConstantDeclaration n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getClassBody().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final EnumDeclaration n, final Void arg) { + return (n.getEntries().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0) * 31 + (n.isThis() ? 1 : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ExpressionStmt n, final Void arg) { + return (n.getExpression().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final FieldAccessExpr n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final FieldDeclaration n, final Void arg) { + return (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ForStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ForeachStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final IfStmt n, final Void arg) { + return (n.getCondition().accept(this, arg)) * 31 + (n.getElseStmt().isPresent() ? n.getElseStmt().get().accept(this, arg) : 0) * 31 + (n.getThenStmt().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ImportDeclaration n, final Void arg) { + return (n.isAsterisk() ? 1 : 0) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final InitializerDeclaration n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final InstanceOfExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final IntegerLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final IntersectionType n, final Void arg) { + return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final JavadocComment n, final Void arg) { + return 0; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final LabeledStmt n, final Void arg) { + return (n.getLabel().accept(this, arg)) * 31 + (n.getStatement().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final LambdaExpr n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final LineComment n, final Void arg) { + return 0; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final LocalClassDeclarationStmt n, final Void arg) { + return (n.getClassDeclaration().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final LongLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final MarkerAnnotationExpr n, final Void arg) { + return (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final MemberValuePair n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final MethodCallExpr n, final Void arg) { + return (n.getArguments().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final MethodDeclaration n, final Void arg) { + return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final MethodReferenceExpr n, final Void arg) { + return (n.getIdentifier().hashCode()) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final NameExpr n, final Void arg) { + return (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final Name n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getIdentifier().hashCode()) * 31 + (n.getQualifier().isPresent() ? n.getQualifier().get().accept(this, arg) : 0); + } + + public Integer visit(NodeList n, Void arg) { + int result = 0; + for (Object node : n) { + result += 31 * ((Visitable) node).accept(this, arg); + } + return result; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final NormalAnnotationExpr n, final Void arg) { + return (n.getPairs().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final NullLiteralExpr n, final Void arg) { + return 0; + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ObjectCreationExpr n, final Void arg) { + return (n.getAnonymousClassBody().isPresent() ? n.getAnonymousClassBody().get().accept(this, arg) : 0) * 31 + (n.getArguments().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final PackageDeclaration n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final Parameter n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.isVarArgs() ? 1 : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getVarArgsAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final PrimitiveType n, final Void arg) { + return (n.getType().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ReturnStmt n, final Void arg) { + return (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SimpleName n, final Void arg) { + return (n.getIdentifier().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) { + return (n.getMemberValue().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final StringLiteralExpr n, final Void arg) { + return (n.getValue().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SuperExpr n, final Void arg) { + return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SwitchEntryStmt n, final Void arg) { + return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getStatements().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SwitchStmt n, final Void arg) { + return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final SynchronizedStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getExpression().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ThisExpr n, final Void arg) { + return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ThrowStmt n, final Void arg) { + return (n.getExpression().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final TryStmt n, final Void arg) { + return (n.getCatchClauses().accept(this, arg)) * 31 + (n.getFinallyBlock().isPresent() ? n.getFinallyBlock().get().accept(this, arg) : 0) * 31 + (n.getResources().accept(this, arg)) * 31 + (n.getTryBlock().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final TypeExpr n, final Void arg) { + return (n.getType().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final TypeParameter n, final Void arg) { + return (n.getName().accept(this, arg)) * 31 + (n.getTypeBound().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final UnaryExpr n, final Void arg) { + return (n.getExpression().accept(this, arg)) * 31 + (n.getOperator().hashCode()); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final UnionType n, final Void arg) { + return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final UnknownType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final VariableDeclarationExpr n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final VariableDeclarator n, final Void arg) { + return (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final VoidType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final WhileStmt n, final Void arg) { + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final WildcardType n, final Void arg) { + return (n.getExtendedType().isPresent() ? n.getExtendedType().get().accept(this, arg) : 0) * 31 + (n.getSuperType().isPresent() ? n.getSuperType().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleDeclaration n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.isOpen() ? 1 : 0) * 31 + (n.getModuleStmts().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleRequiresStmt n, final Void arg) { + return (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleExportsStmt n, final Void arg) { + return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleProvidesStmt n, final Void arg) { + return (n.getType().accept(this, arg)) * 31 + (n.getWithTypes().accept(this, arg)); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleUsesStmt n, final Void arg) { + return (n.getType().accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ModuleOpensStmt n, final Void arg) { + return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final UnparsableStmt n, final Void arg) { + return 0; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator") + public Integer visit(final ReceiverParameter n, final Void arg) { + return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)); + } + + @Override + public Integer visit(final VarType n, final Void arg) { + return (n.getAnnotations().accept(this, arg)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java new file mode 100644 index 0000000..7c642bb --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java @@ -0,0 +1,596 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that calculates deep node equality by comparing all properties and child nodes of the node. + * + * @author Julio Vilmar Gesser + */ +public class ObjectIdentityEqualsVisitor implements GenericVisitor { + + private static final ObjectIdentityEqualsVisitor SINGLETON = new ObjectIdentityEqualsVisitor(); + + public static boolean equals(final Node n, final Node n2) { + return n.accept(SINGLETON, n2); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final CompilationUnit n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final PackageDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final TypeParameter n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final LineComment n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final BlockComment n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final EnumDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final AnnotationDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final FieldDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final VariableDeclarator n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ConstructorDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final MethodDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final Parameter n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final InitializerDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final JavadocComment n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final PrimitiveType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ArrayType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ArrayCreationLevel n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final IntersectionType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final UnionType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final VoidType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final WildcardType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final UnknownType n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ArrayAccessExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ArrayCreationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final AssignExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final BinaryExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final CastExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ClassExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ConditionalExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final EnclosedExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final FieldAccessExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final InstanceOfExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final StringLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final LongLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final CharLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final NullLiteralExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final MethodCallExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final NameExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ObjectCreationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final Name n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SimpleName n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ThisExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SuperExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final UnaryExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final MemberValuePair n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final AssertStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final BlockStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final LabeledStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final EmptyStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ExpressionStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SwitchStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SwitchEntryStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final BreakStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ReturnStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final IfStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final WhileStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ContinueStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final DoStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ForeachStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ForStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ThrowStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final SynchronizedStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final TryStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final CatchClause n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final LambdaExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final MethodReferenceExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final TypeExpr n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ImportDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + public Boolean visit(NodeList n, Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleDeclaration n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) { + return n == arg; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleExportsStmt n, final Visitable arg) { + return n == arg; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) { + return n == arg; + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleUsesStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ModuleOpensStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final UnparsableStmt n, final Visitable arg) { + return n == arg; + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator") + public Boolean visit(final ReceiverParameter n, final Visitable arg) { + return n == arg; + } + + @Override + public Boolean visit(final VarType n, final Visitable arg) { + return n == arg; + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java new file mode 100644 index 0000000..c53cf79 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java @@ -0,0 +1,510 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that calculates a deep hash code for a node by using the hash codes of all its properties, + * and the hash codes of all its child nodes (by visiting those too.) + */ +public class ObjectIdentityHashCodeVisitor implements GenericVisitor { + + private static final ObjectIdentityHashCodeVisitor SINGLETON = new ObjectIdentityHashCodeVisitor(); + + public static int hashCode(final Node node) { + return node.accept(SINGLETON, null); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final AnnotationDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final AnnotationMemberDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ArrayAccessExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ArrayCreationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ArrayCreationLevel n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ArrayInitializerExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ArrayType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final AssertStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final AssignExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final BinaryExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final BlockComment n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final BlockStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final BooleanLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final BreakStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final CastExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final CatchClause n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final CharLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ClassExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ClassOrInterfaceType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final CompilationUnit n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ConditionalExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ConstructorDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ContinueStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final DoStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final DoubleLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final EmptyStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final EnclosedExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final EnumConstantDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final EnumDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ExpressionStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final FieldAccessExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final FieldDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ForStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ForeachStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final IfStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ImportDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final InitializerDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final InstanceOfExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final IntegerLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final IntersectionType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final JavadocComment n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final LabeledStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final LambdaExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final LineComment n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final LocalClassDeclarationStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final LongLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final MarkerAnnotationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final MemberValuePair n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final MethodCallExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final MethodDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final MethodReferenceExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final NameExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final Name n, final Void arg) { + return n.hashCode(); + } + + public Integer visit(NodeList n, Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final NormalAnnotationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final NullLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ObjectCreationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final PackageDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final Parameter n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final PrimitiveType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ReturnStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SimpleName n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final StringLiteralExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SuperExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SwitchEntryStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SwitchStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final SynchronizedStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ThisExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ThrowStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final TryStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final TypeExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final TypeParameter n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final UnaryExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final UnionType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final UnknownType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final VariableDeclarationExpr n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final VariableDeclarator n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final VoidType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final WhileStmt n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final WildcardType n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleDeclaration n, final Void arg) { + return n.hashCode(); + } + + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleRequiresStmt n, final Void arg) { + return n.hashCode(); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleExportsStmt n, final Void arg) { + return n.hashCode(); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleProvidesStmt n, final Void arg) { + return n.hashCode(); + } + + @Override() + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleUsesStmt n, final Void arg) { + return n.hashCode(); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ModuleOpensStmt n, final Void arg) { + return n.hashCode(); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final UnparsableStmt n, final Void arg) { + return n.hashCode(); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator") + public Integer visit(final ReceiverParameter n, final Void arg) { + return n.hashCode(); + } + + @Override + public Integer visit(final VarType n, final Void arg) { + return n.hashCode(); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/TreeVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/TreeVisitor.java new file mode 100644 index 0000000..3c4aecd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/TreeVisitor.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.Node; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; + +/** + * Iterate over all the nodes in (a part of) the AST. In contrast to the visit methods in Node, these methods are + * implemented in a simple recursive way which should be more efficient. A disadvantage is that they cannot be quit in + * the middle of their traversal. + */ +public abstract class TreeVisitor { + + public void visitLeavesFirst(Node node) { + for (Node child : node.getChildNodes()) { + visitLeavesFirst(child); + } + process(node); + } + + /** + * Performs a pre-order node traversal starting with a given node. When each node is visited, {@link #process(Node)} + * is called for further processing. + * + * @param node The node at which the traversal begins. + * @see Pre-order traversal + */ + public void visitPreOrder(Node node) { + process(node); + new ArrayList<>(node.getChildNodes()).forEach(this::visitPreOrder); + } + + /** + * Performs a post-order node traversal starting with a given node. When each node is visited, {@link + * #process(Node)} is called for further processing. + * + * @param node The node at which the traversal begins. + * @see Post-order traversal + */ + public void visitPostOrder(Node node) { + new ArrayList<>(node.getChildNodes()).forEach(this::visitPostOrder); + process(node); + } + + /** + * Performs a pre-order node traversal starting with a given node. When each node is visited, {@link #process(Node)} + * is called for further processing. + * + * @param node The node at which the traversal begins. + * @see Pre-order traversal + * @deprecated As of release 3.1.0, replaced by {@link #visitPreOrder(Node)} + */ + @Deprecated + public void visitDepthFirst(Node node) { + visitPreOrder(node); + } + + /** + * https://en.wikipedia.org/wiki/Breadth-first_search + * + * @param node the start node, and the first one that is passed to process(node). + */ + public void visitBreadthFirst(Node node) { + final Queue queue = new LinkedList<>(); + queue.offer(node); + while (queue.size() > 0) { + final Node head = queue.peek(); + for (Node child : head.getChildNodes()) { + queue.offer(child); + } + process(queue.poll()); + } + } + + /** + * Process the given node. + * + * @param node The current node to process. + */ + public abstract void process(Node node); + + /** + * Performs a simple traversal over all nodes that have the passed node as their parent. + */ + public void visitDirectChildren(Node node) { + new ArrayList<>(node.getChildNodes()).forEach(this::process); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/Visitable.java b/JavaParser/src/com/github/javaparser/ast/visitor/Visitable.java new file mode 100644 index 0000000..32c01a1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/Visitable.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.visitor; + +public interface Visitable { + /** + * Accept method for visitor support. + * + * @param the type of the return value of the visitor + * @param the type the user argument passed to the visitor + * @param v the visitor implementation + * @param arg the argument passed to the visitor (of type A) + * @return the result of the visit (of type R) + */ + R accept(GenericVisitor v, A arg); + + /** + * Accept method for visitor support. + * + * @param the type the argument passed for the visitor + * @param v the visitor implementation + * @param arg any value relevant for the visitor (of type A) + */ + void accept(VoidVisitor v, A arg); +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitor.java b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitor.java index 0bad515..37c9c1c 100644 --- a/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitor.java +++ b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitor.java @@ -1,253 +1,314 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -/** - * A visitor that does not return anything. - * - * @author Julio Vilmar Gesser - */ -public interface VoidVisitor { - - //- Compilation Unit ---------------------------------- - - void visit(CompilationUnit n, A arg); - - void visit(PackageDeclaration n, A arg); - - void visit(ImportDeclaration n, A arg); - - void visit(TypeParameter n, A arg); - - void visit(LineComment n, A arg); - - void visit(BlockComment n, A arg); - - //- Body ---------------------------------------------- - - void visit(ClassOrInterfaceDeclaration n, A arg); - - void visit(EnumDeclaration n, A arg); - - void visit(EmptyTypeDeclaration n, A arg); - - void visit(EnumConstantDeclaration n, A arg); - - void visit(AnnotationDeclaration n, A arg); - - void visit(AnnotationMemberDeclaration n, A arg); - - void visit(FieldDeclaration n, A arg); - - void visit(VariableDeclarator n, A arg); - - void visit(VariableDeclaratorId n, A arg); - - void visit(ConstructorDeclaration n, A arg); - - void visit(MethodDeclaration n, A arg); - - void visit(Parameter n, A arg); - - void visit(MultiTypeParameter n, A arg); - - void visit(EmptyMemberDeclaration n, A arg); - - void visit(InitializerDeclaration n, A arg); - - void visit(JavadocComment n, A arg); - - //- Type ---------------------------------------------- - - void visit(ClassOrInterfaceType n, A arg); - - void visit(PrimitiveType n, A arg); - - void visit(ReferenceType n, A arg); - - void visit(VoidType n, A arg); - - void visit(WildcardType n, A arg); - - void visit(UnknownType n, A arg); - - //- Expression ---------------------------------------- - - void visit(ArrayAccessExpr n, A arg); - - void visit(ArrayCreationExpr n, A arg); - - void visit(ArrayInitializerExpr n, A arg); - - void visit(AssignExpr n, A arg); - - void visit(BinaryExpr n, A arg); - - void visit(CastExpr n, A arg); - - void visit(ClassExpr n, A arg); - - void visit(ConditionalExpr n, A arg); - - void visit(EnclosedExpr n, A arg); - - void visit(FieldAccessExpr n, A arg); - - void visit(InstanceOfExpr n, A arg); - - void visit(StringLiteralExpr n, A arg); - - void visit(IntegerLiteralExpr n, A arg); - - void visit(LongLiteralExpr n, A arg); - - void visit(IntegerLiteralMinValueExpr n, A arg); - - void visit(LongLiteralMinValueExpr n, A arg); - - void visit(CharLiteralExpr n, A arg); - - void visit(DoubleLiteralExpr n, A arg); - - void visit(BooleanLiteralExpr n, A arg); - - void visit(NullLiteralExpr n, A arg); - - void visit(MethodCallExpr n, A arg); - - void visit(NameExpr n, A arg); - - void visit(ObjectCreationExpr n, A arg); - - void visit(QualifiedNameExpr n, A arg); - - void visit(ThisExpr n, A arg); - - void visit(SuperExpr n, A arg); - - void visit(UnaryExpr n, A arg); - - void visit(VariableDeclarationExpr n, A arg); - - void visit(MarkerAnnotationExpr n, A arg); - - void visit(SingleMemberAnnotationExpr n, A arg); - - void visit(NormalAnnotationExpr n, A arg); - - void visit(MemberValuePair n, A arg); - - //- Statements ---------------------------------------- - - void visit(ExplicitConstructorInvocationStmt n, A arg); - - void visit(TypeDeclarationStmt n, A arg); - - void visit(AssertStmt n, A arg); - - void visit(BlockStmt n, A arg); - - void visit(LabeledStmt n, A arg); - - void visit(EmptyStmt n, A arg); - - void visit(ExpressionStmt n, A arg); - - void visit(SwitchStmt n, A arg); - - void visit(SwitchEntryStmt n, A arg); - - void visit(BreakStmt n, A arg); - - void visit(ReturnStmt n, A arg); - - void visit(IfStmt n, A arg); - - void visit(WhileStmt n, A arg); - - void visit(ContinueStmt n, A arg); - - void visit(DoStmt n, A arg); - - void visit(ForeachStmt n, A arg); - - void visit(ForStmt n, A arg); - - void visit(ThrowStmt n, A arg); - - void visit(SynchronizedStmt n, A arg); - - void visit(TryStmt n, A arg); - - void visit(CatchClause n, A arg); - - void visit(LambdaExpr n, A arg); - - void visit(MethodReferenceExpr n, A arg); - - void visit(TypeExpr n, A arg); -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that does not return anything. + * + * @author Julio Vilmar Gesser + */ +public interface VoidVisitor { + + void visit(NodeList n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(AnnotationDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(AnnotationMemberDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ArrayAccessExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ArrayCreationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ArrayCreationLevel n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ArrayInitializerExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ArrayType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(AssertStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(AssignExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(BinaryExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(BlockComment n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(BlockStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(BooleanLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(BreakStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(CastExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(CatchClause n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(CharLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ClassExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ClassOrInterfaceDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ClassOrInterfaceType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(CompilationUnit n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ConditionalExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ConstructorDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ContinueStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(DoStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(DoubleLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(EmptyStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(EnclosedExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(EnumConstantDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(EnumDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ExplicitConstructorInvocationStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ExpressionStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(FieldAccessExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(FieldDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ForStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ForeachStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(IfStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ImportDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(InitializerDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(InstanceOfExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(IntegerLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(IntersectionType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(JavadocComment n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(LabeledStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(LambdaExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(LineComment n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(LocalClassDeclarationStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(LongLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(MarkerAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(MemberValuePair n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(MethodCallExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(MethodDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(MethodReferenceExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(NameExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(Name n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(NormalAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(NullLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ObjectCreationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(PackageDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(Parameter n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(PrimitiveType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ReturnStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SimpleName n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SingleMemberAnnotationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(StringLiteralExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SuperExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SwitchEntryStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SwitchStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(SynchronizedStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ThisExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ThrowStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(TryStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(TypeExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(TypeParameter n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(UnaryExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(UnionType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(UnknownType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(VariableDeclarationExpr n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(VariableDeclarator n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(VoidType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(WhileStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(WildcardType n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleDeclaration n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleRequiresStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleExportsStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleProvidesStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleUsesStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ModuleOpensStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(UnparsableStmt n, A arg); + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator") + void visit(ReceiverParameter n, A arg); + + void visit(VarType n, A arg); +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java index 5c9f40f..1ee8266 100644 --- a/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java +++ b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -1,845 +1,773 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2015 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser is free software: you can redistribute it and/or modify - * it under the terms of 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. - * - * 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JavaParser. If not, see . - */ - -package com.github.javaparser.ast.visitor; - -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EmptyMemberDeclaration; -import com.github.javaparser.ast.body.EmptyTypeDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.MultiTypeParameter; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.ForeachStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntryStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.TypeDeclarationStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.type.*; - -import static com.github.javaparser.ast.internal.Utils.isNullOrEmpty; - -/** - * @author Julio Vilmar Gesser - */ -public abstract class VoidVisitorAdapter implements VoidVisitor { - - @Override public void visit(final AnnotationDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final AnnotationMemberDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - n.getType().accept(this, arg); - if (n.getDefaultValue() != null) { - n.getDefaultValue().accept(this, arg); - } - } - - @Override public void visit(final ArrayAccessExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - n.getIndex().accept(this, arg); - } - - @Override public void visit(final ArrayCreationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - if (!isNullOrEmpty(n.getDimensions())) { - for (final Expression dim : n.getDimensions()) { - dim.accept(this, arg); - } - } else { - n.getInitializer().accept(this, arg); - } - } - - @Override public void visit(final ArrayInitializerExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getValues() != null) { - for (final Expression expr : n.getValues()) { - expr.accept(this, arg); - } - } - } - - @Override public void visit(final AssertStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCheck().accept(this, arg); - if (n.getMessage() != null) { - n.getMessage().accept(this, arg); - } - } - - @Override public void visit(final AssignExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getTarget().accept(this, arg); - n.getValue().accept(this, arg); - } - - @Override public void visit(final BinaryExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getLeft().accept(this, arg); - n.getRight().accept(this, arg); - } - - @Override public void visit(final BlockComment n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final BlockStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - } - } - } - - @Override public void visit(final BooleanLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final BreakStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final CastExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final CatchClause n, final A arg) { - visitComment(n.getComment(), arg); - n.getExcept().accept(this, arg); - n.getCatchBlock().accept(this, arg); - } - - @Override public void visit(final CharLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final ClassExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override public void visit(final ClassOrInterfaceDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - } - if (n.getExtends() != null) { - for (final ClassOrInterfaceType c : n.getExtends()) { - c.accept(this, arg); - } - } - - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - c.accept(this, arg); - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final ClassOrInterfaceType n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - t.accept(this, arg); - } - } - } - - @Override public void visit(final CompilationUnit n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getPackage() != null) { - n.getPackage().accept(this, arg); - } - if (n.getImports() != null) { - for (final ImportDeclaration i : n.getImports()) { - i.accept(this, arg); - } - } - if (n.getTypes() != null) { - for (final TypeDeclaration typeDeclaration : n.getTypes()) { - typeDeclaration.accept(this, arg); - } - } - } - - @Override public void visit(final ConditionalExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getThenExpr().accept(this, arg); - n.getElseExpr().accept(this, arg); - } - - @Override public void visit(final ConstructorDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - } - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - p.accept(this, arg); - } - } - if (n.getThrows() != null) { - for (final NameExpr name : n.getThrows()) { - name.accept(this, arg); - } - } - n.getBlock().accept(this, arg); - } - - @Override public void visit(final ContinueStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final DoStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getBody().accept(this, arg); - n.getCondition().accept(this, arg); - } - - @Override public void visit(final DoubleLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final EmptyMemberDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - } - - @Override public void visit(final EmptyStmt n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final EmptyTypeDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - } - - @Override public void visit(final EnclosedExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getInner().accept(this, arg); - } - - @Override public void visit(final EnumConstantDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - if (n.getClassBody() != null) { - for (final BodyDeclaration member : n.getClassBody()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final EnumDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getImplements() != null) { - for (final ClassOrInterfaceType c : n.getImplements()) { - c.accept(this, arg); - } - } - if (n.getEntries() != null) { - for (final EnumConstantDeclaration e : n.getEntries()) { - e.accept(this, arg); - } - } - if (n.getMembers() != null) { - for (final BodyDeclaration member : n.getMembers()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (!n.isThis()) { - if (n.getExpr() != null) { - n.getExpr().accept(this, arg); - } - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - t.accept(this, arg); - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final ExpressionStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpression().accept(this, arg); - } - - @Override public void visit(final FieldAccessExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getScope().accept(this, arg); - } - - @Override public void visit(final FieldDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - n.getType().accept(this, arg); - for (final VariableDeclarator var : n.getVariables()) { - var.accept(this, arg); - } - } - - @Override public void visit(final ForeachStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getVariable().accept(this, arg); - n.getIterable().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final ForStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getInit() != null) { - for (final Expression e : n.getInit()) { - e.accept(this, arg); - } - } - if (n.getCompare() != null) { - n.getCompare().accept(this, arg); - } - if (n.getUpdate() != null) { - for (final Expression e : n.getUpdate()) { - e.accept(this, arg); - } - } - n.getBody().accept(this, arg); - } - - @Override public void visit(final IfStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getThenStmt().accept(this, arg); - if (n.getElseStmt() != null) { - n.getElseStmt().accept(this, arg); - } - } - - @Override public void visit(final ImportDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - } - - @Override public void visit(final InitializerDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - n.getBlock().accept(this, arg); - } - - @Override public void visit(final InstanceOfExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - n.getType().accept(this, arg); - } - - @Override public void visit(final IntegerLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final IntegerLiteralMinValueExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final JavadocComment n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final LabeledStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getStmt().accept(this, arg); - } - - @Override public void visit(final LineComment n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final LongLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final LongLiteralMinValueExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final MarkerAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - } - - @Override public void visit(final MemberValuePair n, final A arg) { - visitComment(n.getComment(), arg); - n.getValue().accept(this, arg); - } - - @Override public void visit(final MethodCallExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - t.accept(this, arg); - } - } - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final MethodDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getJavaDoc() != null) { - n.getJavaDoc().accept(this, arg); - } - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - if (n.getTypeParameters() != null) { - for (final TypeParameter t : n.getTypeParameters()) { - t.accept(this, arg); - } - } - n.getType().accept(this, arg); - if (n.getParameters() != null) { - for (final Parameter p : n.getParameters()) { - p.accept(this, arg); - } - } - if (n.getThrows() != null) { - for (final NameExpr name : n.getThrows()) { - name.accept(this, arg); - } - } - if (n.getBody() != null) { - n.getBody().accept(this, arg); - } - } - - @Override public void visit(final NameExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final NormalAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - if (n.getPairs() != null) { - for (final MemberValuePair m : n.getPairs()) { - m.accept(this, arg); - } - } - } - - @Override public void visit(final NullLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final ObjectCreationExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - if (n.getTypeArgs() != null) { - for (final Type t : n.getTypeArgs()) { - t.accept(this, arg); - } - } - n.getType().accept(this, arg); - if (n.getArgs() != null) { - for (final Expression e : n.getArgs()) { - e.accept(this, arg); - } - } - if (n.getAnonymousClassBody() != null) { - for (final BodyDeclaration member : n.getAnonymousClassBody()) { - member.accept(this, arg); - } - } - } - - @Override public void visit(final PackageDeclaration n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - n.getName().accept(this, arg); - } - - @Override public void visit(final Parameter n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - n.getType().accept(this, arg); - n.getId().accept(this, arg); - } - - @Override public void visit(final MultiTypeParameter n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - for (final Type type : n.getTypes()) { - type.accept(this, arg); - } - n.getId().accept(this, arg); - } - - @Override public void visit(final PrimitiveType n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final QualifiedNameExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getQualifier().accept(this, arg); - } - - @Override public void visit(final ReferenceType n, final A arg) { - visitComment(n.getComment(), arg); - n.getType().accept(this, arg); - } - - @Override public void visit(final ReturnStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getExpr() != null) { - n.getExpr().accept(this, arg); - } - } - - @Override public void visit(final SingleMemberAnnotationExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getName().accept(this, arg); - n.getMemberValue().accept(this, arg); - } - - @Override public void visit(final StringLiteralExpr n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final SuperExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - } - } - - @Override public void visit(final SwitchEntryStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getLabel() != null) { - n.getLabel().accept(this, arg); - } - if (n.getStmts() != null) { - for (final Statement s : n.getStmts()) { - s.accept(this, arg); - } - } - } - - @Override public void visit(final SwitchStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getSelector().accept(this, arg); - if (n.getEntries() != null) { - for (final SwitchEntryStmt e : n.getEntries()) { - e.accept(this, arg); - } - } - } - - @Override public void visit(final SynchronizedStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - n.getBlock().accept(this, arg); - } - - @Override public void visit(final ThisExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getClassExpr() != null) { - n.getClassExpr().accept(this, arg); - } - } - - @Override public void visit(final ThrowStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final TryStmt n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getResources() != null) { - for (final VariableDeclarationExpr v : n.getResources()) { - v.accept(this, arg); - } - } - n.getTryBlock().accept(this, arg); - if (n.getCatchs() != null) { - for (final CatchClause c : n.getCatchs()) { - c.accept(this, arg); - } - } - if (n.getFinallyBlock() != null) { - n.getFinallyBlock().accept(this, arg); - } - } - - @Override public void visit(final TypeDeclarationStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getTypeDeclaration().accept(this, arg); - } - - @Override public void visit(final TypeParameter n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getTypeBound() != null) { - for (final ClassOrInterfaceType c : n.getTypeBound()) { - c.accept(this, arg); - } - } - } - - @Override public void visit(final UnaryExpr n, final A arg) { - visitComment(n.getComment(), arg); - n.getExpr().accept(this, arg); - } - - @Override public void visit(final UnknownType n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final VariableDeclarationExpr n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getAnnotations() != null) { - for (final AnnotationExpr a : n.getAnnotations()) { - a.accept(this, arg); - } - } - n.getType().accept(this, arg); - for (final VariableDeclarator v : n.getVars()) { - v.accept(this, arg); - } - } - - @Override public void visit(final VariableDeclarator n, final A arg) { - visitComment(n.getComment(), arg); - n.getId().accept(this, arg); - if (n.getInit() != null) { - n.getInit().accept(this, arg); - } - } - - @Override public void visit(final VariableDeclaratorId n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final VoidType n, final A arg) { - visitComment(n.getComment(), arg); - } - - @Override public void visit(final WhileStmt n, final A arg) { - visitComment(n.getComment(), arg); - n.getCondition().accept(this, arg); - n.getBody().accept(this, arg); - } - - @Override public void visit(final WildcardType n, final A arg) { - visitComment(n.getComment(), arg); - if (n.getExtends() != null) { - n.getExtends().accept(this, arg); - } - if (n.getSuper() != null) { - n.getSuper().accept(this, arg); - } - } - - @Override - public void visit(LambdaExpr n, final A arg) { - if (n.getParameters() != null) { - for (final Parameter a : n.getParameters()) { - a.accept(this, arg); - } - } - if (n.getBody() != null) { - n.getBody().accept(this, arg); - } - } - - @Override - public void visit(MethodReferenceExpr n, final A arg) { - if (n.getTypeParameters() != null) { - for (final TypeParameter a : n.getTypeParameters()) { - a.accept(this, arg); - } - } - if (n.getScope() != null) { - n.getScope().accept(this, arg); - } - } - - @Override - public void visit(TypeExpr n, final A arg) { - if (n.getType() != null) { - n.getType().accept(this, arg); - } - } - - private void visitComment(final Comment n, final A arg) { - if (n != null) { - n.accept(this, arg); - } - } -} +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that returns nothing, and has a default implementation for all its visit + * methods that simply visit their children in an unspecified order. + * + * @author Julio Vilmar Gesser + */ +public abstract class VoidVisitorAdapter implements VoidVisitor { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final AnnotationDeclaration n, final A arg) { + n.getMembers().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final AnnotationMemberDeclaration n, final A arg) { + n.getDefaultValue().ifPresent(l -> l.accept(this, arg)); + n.getName().accept(this, arg); + n.getType().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ArrayAccessExpr n, final A arg) { + n.getIndex().accept(this, arg); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ArrayCreationExpr n, final A arg) { + n.getElementType().accept(this, arg); + n.getInitializer().ifPresent(l -> l.accept(this, arg)); + n.getLevels().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ArrayInitializerExpr n, final A arg) { + n.getValues().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final AssertStmt n, final A arg) { + n.getCheck().accept(this, arg); + n.getMessage().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final AssignExpr n, final A arg) { + n.getTarget().accept(this, arg); + n.getValue().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final BinaryExpr n, final A arg) { + n.getLeft().accept(this, arg); + n.getRight().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final BlockComment n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final BlockStmt n, final A arg) { + n.getStatements().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final BooleanLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final BreakStmt n, final A arg) { + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final CastExpr n, final A arg) { + n.getExpression().accept(this, arg); + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final CatchClause n, final A arg) { + n.getBody().accept(this, arg); + n.getParameter().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final CharLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ClassExpr n, final A arg) { + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ClassOrInterfaceDeclaration n, final A arg) { + n.getExtendedTypes().forEach(p -> p.accept(this, arg)); + n.getImplementedTypes().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getMembers().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ClassOrInterfaceType n, final A arg) { + n.getName().accept(this, arg); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final CompilationUnit n, final A arg) { + n.getImports().forEach(p -> p.accept(this, arg)); + n.getModule().ifPresent(l -> l.accept(this, arg)); + n.getPackageDeclaration().ifPresent(l -> l.accept(this, arg)); + n.getTypes().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ConditionalExpr n, final A arg) { + n.getCondition().accept(this, arg); + n.getElseExpr().accept(this, arg); + n.getThenExpr().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ConstructorDeclaration n, final A arg) { + n.getBody().accept(this, arg); + n.getName().accept(this, arg); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getReceiverParameter().ifPresent(l -> l.accept(this, arg)); + n.getThrownExceptions().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ContinueStmt n, final A arg) { + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final DoStmt n, final A arg) { + n.getBody().accept(this, arg); + n.getCondition().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final DoubleLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final EmptyStmt n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final EnclosedExpr n, final A arg) { + n.getInner().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final EnumConstantDeclaration n, final A arg) { + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getClassBody().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final EnumDeclaration n, final A arg) { + n.getEntries().forEach(p -> p.accept(this, arg)); + n.getImplementedTypes().forEach(p -> p.accept(this, arg)); + n.getMembers().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getExpression().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ExpressionStmt n, final A arg) { + n.getExpression().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final FieldAccessExpr n, final A arg) { + n.getName().accept(this, arg); + n.getScope().accept(this, arg); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final FieldDeclaration n, final A arg) { + n.getVariables().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ForeachStmt n, final A arg) { + n.getBody().accept(this, arg); + n.getIterable().accept(this, arg); + n.getVariable().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ForStmt n, final A arg) { + n.getBody().accept(this, arg); + n.getCompare().ifPresent(l -> l.accept(this, arg)); + n.getInitialization().forEach(p -> p.accept(this, arg)); + n.getUpdate().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final IfStmt n, final A arg) { + n.getCondition().accept(this, arg); + n.getElseStmt().ifPresent(l -> l.accept(this, arg)); + n.getThenStmt().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final InitializerDeclaration n, final A arg) { + n.getBody().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final InstanceOfExpr n, final A arg) { + n.getExpression().accept(this, arg); + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final IntegerLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final JavadocComment n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final LabeledStmt n, final A arg) { + n.getLabel().accept(this, arg); + n.getStatement().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final LineComment n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final LongLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final MarkerAnnotationExpr n, final A arg) { + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final MemberValuePair n, final A arg) { + n.getName().accept(this, arg); + n.getValue().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final MethodCallExpr n, final A arg) { + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final MethodDeclaration n, final A arg) { + n.getBody().ifPresent(l -> l.accept(this, arg)); + n.getType().accept(this, arg); + n.getName().accept(this, arg); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getReceiverParameter().ifPresent(l -> l.accept(this, arg)); + n.getThrownExceptions().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final NameExpr n, final A arg) { + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final NormalAnnotationExpr n, final A arg) { + n.getPairs().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final NullLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ObjectCreationExpr n, final A arg) { + n.getAnonymousClassBody().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getType().accept(this, arg); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final PackageDeclaration n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final Parameter n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getType().accept(this, arg); + n.getVarArgsAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final PrimitiveType n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final Name n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getQualifier().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SimpleName n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ArrayType n, final A arg) { + n.getComponentType().accept(this, arg); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ArrayCreationLevel n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getDimension().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final IntersectionType n, final A arg) { + n.getElements().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final UnionType n, final A arg) { + n.getElements().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ReturnStmt n, final A arg) { + n.getExpression().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SingleMemberAnnotationExpr n, final A arg) { + n.getMemberValue().accept(this, arg); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final StringLiteralExpr n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SuperExpr n, final A arg) { + n.getClassExpr().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SwitchEntryStmt n, final A arg) { + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getStatements().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SwitchStmt n, final A arg) { + n.getEntries().forEach(p -> p.accept(this, arg)); + n.getSelector().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final SynchronizedStmt n, final A arg) { + n.getBody().accept(this, arg); + n.getExpression().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ThisExpr n, final A arg) { + n.getClassExpr().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ThrowStmt n, final A arg) { + n.getExpression().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final TryStmt n, final A arg) { + n.getCatchClauses().forEach(p -> p.accept(this, arg)); + n.getFinallyBlock().ifPresent(l -> l.accept(this, arg)); + n.getResources().forEach(p -> p.accept(this, arg)); + n.getTryBlock().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final LocalClassDeclarationStmt n, final A arg) { + n.getClassDeclaration().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final TypeParameter n, final A arg) { + n.getName().accept(this, arg); + n.getTypeBound().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final UnaryExpr n, final A arg) { + n.getExpression().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final UnknownType n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final VariableDeclarationExpr n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getVariables().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final VariableDeclarator n, final A arg) { + n.getInitializer().ifPresent(l -> l.accept(this, arg)); + n.getName().accept(this, arg); + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final VoidType n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final WhileStmt n, final A arg) { + n.getBody().accept(this, arg); + n.getCondition().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final WildcardType n, final A arg) { + n.getExtendedType().ifPresent(l -> l.accept(this, arg)); + n.getSuperType().ifPresent(l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final LambdaExpr n, final A arg) { + n.getBody().accept(this, arg); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final MethodReferenceExpr n, final A arg) { + n.getScope().accept(this, arg); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final TypeExpr n, final A arg) { + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + public void visit(NodeList n, A arg) { + for (Object node : n) { + ((Node) node).accept(this, arg); + } + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ImportDeclaration n, final A arg) { + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleDeclaration n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getModuleStmts().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleRequiresStmt n, final A arg) { + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleExportsStmt n, final A arg) { + n.getModuleNames().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleProvidesStmt n, final A arg) { + n.getType().accept(this, arg); + n.getWithTypes().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleUsesStmt n, final A arg) { + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ModuleOpensStmt n, final A arg) { + n.getModuleNames().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final UnparsableStmt n, final A arg) { + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator") + public void visit(final ReceiverParameter n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getType().accept(this, arg); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } + + @Override + public void visit(final VarType n, final A arg) { + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } +} diff --git a/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java new file mode 100644 index 0000000..6622567 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java @@ -0,0 +1,599 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.visitor; + +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import javax.annotation.Generated; + +/** + * A visitor that returns nothing, and has default methods that are used when a specific visit method is not + * overridden. + */ +public abstract class VoidVisitorWithDefaults implements VoidVisitor { + + /** + * This will be called by every node visit method that is not overridden. + */ + public void defaultAction(Node n, A arg) { + } + + /** + * This will be called by the NodeList visit method when it is not overridden. + */ + public void defaultAction(NodeList n, A arg) { + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final AnnotationDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final AnnotationMemberDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ArrayAccessExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ArrayCreationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ArrayInitializerExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final AssertStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final AssignExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final BinaryExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final BlockComment n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final BlockStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final BooleanLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final BreakStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final CastExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final CatchClause n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final CharLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ClassExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ClassOrInterfaceDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ClassOrInterfaceType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final CompilationUnit n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ConditionalExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ConstructorDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ContinueStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final DoStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final DoubleLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final EmptyStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final EnclosedExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final EnumConstantDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final EnumDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ExpressionStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final FieldAccessExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final FieldDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ForeachStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ForStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final IfStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final InitializerDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final InstanceOfExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final IntegerLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final JavadocComment n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final LabeledStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final LineComment n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final LongLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final MarkerAnnotationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final MemberValuePair n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final MethodCallExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final MethodDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final NameExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final NormalAnnotationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final NullLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ObjectCreationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final PackageDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final Parameter n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final PrimitiveType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final Name n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SimpleName n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ArrayType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ArrayCreationLevel n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final IntersectionType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final UnionType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ReturnStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SingleMemberAnnotationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final StringLiteralExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SuperExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SwitchEntryStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SwitchStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final SynchronizedStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ThisExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ThrowStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final TryStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final LocalClassDeclarationStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final TypeParameter n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final UnaryExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final UnknownType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final VariableDeclarationExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final VariableDeclarator n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final VoidType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final WhileStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final WildcardType n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final LambdaExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final MethodReferenceExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final TypeExpr n, final A arg) { + defaultAction(n, arg); + } + + @Override + public void visit(NodeList n, A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ImportDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleDeclaration n, final A arg) { + defaultAction(n, arg); + } + + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleRequiresStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleExportsStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleProvidesStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleUsesStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ModuleOpensStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final UnparsableStmt n, final A arg) { + defaultAction(n, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator") + public void visit(final ReceiverParameter n, final A arg) { + defaultAction(n, arg); + } + + @Override + public void visit(final VarType n, final A arg) { + defaultAction(n, arg); + } +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/Javadoc.java b/JavaParser/src/com/github/javaparser/javadoc/Javadoc.java new file mode 100644 index 0000000..ba606c2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/Javadoc.java @@ -0,0 +1,167 @@ +/* + * 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.javadoc; + +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.javadoc.description.JavadocDescription; + +import java.util.LinkedList; +import java.util.List; + +import static com.github.javaparser.utils.Utils.*; + +/** + * The structured content of a single Javadoc comment. + *

+ * It is composed by a description and a list of block tags. + *

+ * An example would be the text contained in this very Javadoc comment. At the moment + * of this writing this comment does not contain any block tags (such as @see AnotherClass) + */ +public class Javadoc { + + private JavadocDescription description; + private List blockTags; + + public Javadoc(JavadocDescription description) { + this.description = description; + this.blockTags = new LinkedList<>(); + } + + public Javadoc addBlockTag(JavadocBlockTag blockTag) { + this.blockTags.add(blockTag); + return this; + } + + /** + * For tags like "@return good things" where + * tagName is "return", + * and the rest is content. + */ + public Javadoc addBlockTag(String tagName, String content) { + return addBlockTag(new JavadocBlockTag(tagName, content)); + } + + /** + * For tags like "@param abc this is a parameter" where + * tagName is "param", + * parameter is "abc" + * and the rest is content. + */ + public Javadoc addBlockTag(String tagName, String parameter, String content) { + return addBlockTag(tagName, parameter + " " + content); + } + + public Javadoc addBlockTag(String tagName) { + return addBlockTag(tagName, ""); + } + + /** + * Return the text content of the document. It does not containing trailing spaces and asterisks + * at the start of the line. + */ + public String toText() { + StringBuilder sb = new StringBuilder(); + if (!description.isEmpty()) { + sb.append(description.toText()); + sb.append(EOL); + } + if (!blockTags.isEmpty()) { + sb.append(EOL); + } + blockTags.forEach(bt -> { + sb.append(bt.toText()); + sb.append(EOL); + }); + return sb.toString(); + } + + /** + * Create a JavadocComment, by formatting the text of the Javadoc using no indentation (expecting the pretty printer to do the formatting.) + */ + public JavadocComment toComment() { + return toComment(""); + } + + /** + * Create a JavadocComment, by formatting the text of the Javadoc using the given indentation. + */ + public JavadocComment toComment(String indentation) { + for (char c : indentation.toCharArray()) { + if (!Character.isWhitespace(c)) { + throw new IllegalArgumentException("The indentation string should be composed only by whitespace characters"); + } + } + StringBuilder sb = new StringBuilder(); + sb.append(EOL); + final String text = toText(); + if (!text.isEmpty()) { + for (String line : text.split(EOL)) { + sb.append(indentation); + sb.append(" * "); + sb.append(line); + sb.append(EOL); + } + } + sb.append(indentation); + sb.append(" "); + return new JavadocComment(sb.toString()); + } + + public JavadocDescription getDescription() { + return description; + } + + /** + * @return the current List of associated JavadocBlockTags + */ + public List getBlockTags() { + return this.blockTags; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Javadoc document = (Javadoc) o; + + return description.equals(document.description) && blockTags.equals(document.blockTags); + + } + + @Override + public int hashCode() { + int result = description.hashCode(); + result = 31 * result + blockTags.hashCode(); + return result; + } + + @Override + public String toString() { + return "Javadoc{" + + "description=" + description + + ", blockTags=" + blockTags + + '}'; + } + +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/JavadocBlockTag.java b/JavaParser/src/com/github/javaparser/javadoc/JavadocBlockTag.java new file mode 100644 index 0000000..f339931 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/JavadocBlockTag.java @@ -0,0 +1,163 @@ +/* + * 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.javadoc; + +import com.github.javaparser.javadoc.description.JavadocDescription; + +import java.util.Optional; + +import static com.github.javaparser.utils.Utils.nextWord; +import static com.github.javaparser.utils.Utils.screamingToCamelCase; + +/** + * A block tag. + *

+ * Typically they are found at the end of Javadoc comments. + *

+ * Examples: + * @see AnotherClass + * @since v0.0.1 + * @author Jim O'Java + */ +public class JavadocBlockTag { + + /** + * The type of tag: it could either correspond to a known tag (param, return, etc.) or represent + * an unknown tag. + */ + public enum Type { + AUTHOR, + DEPRECATED, + EXCEPTION, + PARAM, + RETURN, + SEE, + SERIAL, + SERIAL_DATA, + SERIAL_FIELD, + SINCE, + THROWS, + VERSION, + UNKNOWN; + + Type() { + this.keyword = screamingToCamelCase(name()); + } + + private String keyword; + + boolean hasName() { + return this == PARAM; + } + + static Type fromName(String tagName) { + for (Type t : Type.values()) { + if (t.keyword.equals(tagName)) { + return t; + } + } + return UNKNOWN; + } + + } + + private Type type; + private JavadocDescription content; + private Optional name = Optional.empty(); + private String tagName; + + public JavadocBlockTag(Type type, String content) { + this.type = type; + this.tagName = type.keyword; + if (type.hasName()) { + this.name = Optional.of(nextWord(content)); + content = content.substring(this.name.get().length()).trim(); + } + this.content = JavadocDescription.parseText(content); + } + + public JavadocBlockTag(String tagName, String content) { + this(Type.fromName(tagName), content); + this.tagName = tagName; + } + + public static JavadocBlockTag createParamBlockTag(String paramName, String content) { + return new JavadocBlockTag(Type.PARAM, paramName + " " + content); + } + + public Type getType() { + return type; + } + + public JavadocDescription getContent() { + return content; + } + + public Optional getName() { + return name; + } + + public String getTagName() { + return tagName; + } + + public String toText() { + StringBuilder sb = new StringBuilder(); + sb.append("@"); + sb.append(tagName); + name.ifPresent(s -> sb.append(" ").append(s)); + if (!content.isEmpty()) { + sb.append(" "); + sb.append(content.toText()); + } + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JavadocBlockTag that = (JavadocBlockTag) o; + + if (type != that.type) return false; + if (!content.equals(that.content)) return false; + return name.equals(that.name); + } + + @Override + public int hashCode() { + int result = type.hashCode(); + result = 31 * result + content.hashCode(); + result = 31 * result + name.hashCode(); + return result; + } + + @Override + public String toString() { + return "JavadocBlockTag{" + + "type=" + type + + ", content='" + content + '\'' + + ", name=" + name + + '}'; + } +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescription.java b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescription.java new file mode 100644 index 0000000..82f818a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescription.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.javadoc.description; + +import com.github.javaparser.utils.Pair; + +import java.util.LinkedList; +import java.util.List; + +/** + * A javadoc text, potentially containing inline tags. + * + * For example This class is totally unrelated to {@link com.github.javaparser.Range} + */ +public class JavadocDescription { + + private List elements; + + public static JavadocDescription parseText(String text) { + JavadocDescription instance = new JavadocDescription(); + int index = 0; + Pair nextInlineTagPos; + while ((nextInlineTagPos = indexOfNextInlineTag(text, index)) != null) { + if (nextInlineTagPos.a != index) { + instance.addElement(new JavadocSnippet(text.substring(index, nextInlineTagPos.a + 1))); + } + instance.addElement(JavadocInlineTag.fromText(text.substring(nextInlineTagPos.a, nextInlineTagPos.b + 1))); + index = nextInlineTagPos.b; + } + if (index < text.length()) { + instance.addElement(new JavadocSnippet(text.substring(index))); + } + return instance; + } + + private static Pair indexOfNextInlineTag(String text, int start) { + int index = text.indexOf("{@", start); + if (index == -1) { + return null; + } + // we are interested only in complete inline tags + int closeIndex = text.indexOf("}", index); + if (closeIndex == -1) { + return null; + } + return new Pair<>(index, closeIndex); + } + + public JavadocDescription() { + elements = new LinkedList<>(); + } + + public JavadocDescription(List elements) { + this(); + + this.elements.addAll(elements); + } + + public boolean addElement(JavadocDescriptionElement element) { + return this.elements.add(element); + } + + public List getElements() { + return this.elements; + } + + public String toText() { + StringBuilder sb = new StringBuilder(); + elements.forEach(e -> sb.append(e.toText())); + return sb.toString(); + } + + public boolean isEmpty() { + return toText().isEmpty(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JavadocDescription that = (JavadocDescription) o; + + return elements.equals(that.elements); + + } + + @Override + public int hashCode() { + return elements.hashCode(); + } + + @Override + public String toString() { + return "JavadocDescription{" + + "elements=" + elements + + '}'; + } + +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java new file mode 100644 index 0000000..3d75b6c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java @@ -0,0 +1,31 @@ +/* + * 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.javadoc.description; + +/** + * An element of a description: either an inline tag or a piece of text. + *

+ * So for example a text or {@link String} could be valid description elements. + */ +public interface JavadocDescriptionElement { + String toText(); +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/description/JavadocInlineTag.java b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocInlineTag.java new file mode 100644 index 0000000..8125bd5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocInlineTag.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2017 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.javadoc.description; + +import static com.github.javaparser.utils.Utils.nextWord; +import static com.github.javaparser.utils.Utils.screamingToCamelCase; + +/** + * An inline tag contained in a Javadoc description. + *

+ * For example {@link String} + */ +public class JavadocInlineTag implements JavadocDescriptionElement { + + public static JavadocDescriptionElement fromText(String text) { + if (!text.startsWith("{@")) { + throw new IllegalArgumentException(String.format("Expected to start with '{@'. Text '%s'", text)); + } + if (!text.endsWith("}")) { + throw new IllegalArgumentException(String.format("Expected to end with '}'. Text '%s'", text)); + } + text = text.substring(2, text.length() - 1); + String tagName = nextWord(text); + Type type = Type.fromName(tagName); + String content = text.substring(tagName.length()); + return new JavadocInlineTag(tagName, type, content); + } + + /** + * The type of tag: it could either correspond to a known tag (code, docRoot, etc.) or represent + * an unknown tag. + */ + public enum Type { + CODE, + DOC_ROOT, + INHERIT_DOC, + LINK, + LINKPLAIN, + LITERAL, + VALUE, + UNKNOWN; + + Type() { + this.keyword = screamingToCamelCase(name()); + } + + private String keyword; + + static JavadocInlineTag.Type fromName(String tagName) { + for (JavadocInlineTag.Type t : JavadocInlineTag.Type.values()) { + if (t.keyword.equals(tagName)) { + return t; + } + } + return UNKNOWN; + } + + } + + private String tagName; + private Type type; + private String content; + + public JavadocInlineTag(String tagName, Type type, String content) { + this.tagName = tagName; + this.type = type; + this.content = content; + } + + @Override + public String toText() { + return "@" + tagName + this.content; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JavadocInlineTag that = (JavadocInlineTag) o; + + if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false; + if (type != that.type) return false; + return content != null ? content.equals(that.content) : that.content == null; + } + + @Override + public int hashCode() { + int result = tagName != null ? tagName.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (content != null ? content.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "JavadocInlineTag{" + + "tagName='" + tagName + '\'' + + ", type=" + type + + ", content='" + content + '\'' + + '}'; + } +} diff --git a/JavaParser/src/com/github/javaparser/javadoc/description/JavadocSnippet.java b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocSnippet.java new file mode 100644 index 0000000..50b32cb --- /dev/null +++ b/JavaParser/src/com/github/javaparser/javadoc/description/JavadocSnippet.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.javadoc.description; + +/** + * A piece of text inside a Javadoc description. + *

+ * For example in A class totally unrelated to {@link String}, I swear! we would have two snippets: one + * before and one after the inline tag ({@link String}). + */ +public class JavadocSnippet implements JavadocDescriptionElement { + private String text; + + public JavadocSnippet(String text) { + if (text == null) { + throw new NullPointerException(); + } + this.text = text; + } + + @Override + public String toText() { + return this.text; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JavadocSnippet that = (JavadocSnippet) o; + + return text.equals(that.text); + + } + + @Override + public int hashCode() { + return text.hashCode(); + } + + @Override + public String toString() { + return "JavadocSnippet{" + + "text='" + text + '\'' + + '}'; + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java new file mode 100644 index 0000000..e4a7fdc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class AnnotationDeclarationMetaModel extends TypeDeclarationMetaModel { + + AnnotationDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.AnnotationDeclaration.class, "AnnotationDeclaration", "com.github.javaparser.ast.body", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/AnnotationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/AnnotationExprMetaModel.java new file mode 100644 index 0000000..f4e892a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/AnnotationExprMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class AnnotationExprMetaModel extends ExpressionMetaModel { + + AnnotationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.AnnotationExpr.class, "AnnotationExpr", "com.github.javaparser.ast.expr", true, false); + } + + protected AnnotationExprMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java new file mode 100644 index 0000000..d15b967 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class AnnotationMemberDeclarationMetaModel extends BodyDeclarationMetaModel { + + AnnotationMemberDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.AnnotationMemberDeclaration.class, "AnnotationMemberDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel defaultValuePropertyMetaModel; + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java new file mode 100644 index 0000000..b6dd157 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ArrayAccessExprMetaModel extends ExpressionMetaModel { + + ArrayAccessExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayAccessExpr.class, "ArrayAccessExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel indexPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java new file mode 100644 index 0000000..a120f34 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ArrayCreationExprMetaModel extends ExpressionMetaModel { + + ArrayCreationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayCreationExpr.class, "ArrayCreationExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel elementTypePropertyMetaModel; + + public PropertyMetaModel initializerPropertyMetaModel; + + public PropertyMetaModel levelsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java new file mode 100644 index 0000000..b99f92e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ArrayCreationLevelMetaModel extends NodeMetaModel { + + ArrayCreationLevelMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.ArrayCreationLevel.class, "ArrayCreationLevel", "com.github.javaparser.ast", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel dimensionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java new file mode 100644 index 0000000..685910f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ArrayInitializerExprMetaModel extends ExpressionMetaModel { + + ArrayInitializerExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayInitializerExpr.class, "ArrayInitializerExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel valuesPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ArrayTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ArrayTypeMetaModel.java new file mode 100644 index 0000000..58f3f62 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ArrayTypeMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ArrayTypeMetaModel extends ReferenceTypeMetaModel { + + ArrayTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ArrayType.class, "ArrayType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel componentTypePropertyMetaModel; + + public PropertyMetaModel originPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/AssertStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/AssertStmtMetaModel.java new file mode 100644 index 0000000..c250832 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/AssertStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class AssertStmtMetaModel extends StatementMetaModel { + + AssertStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.AssertStmt.class, "AssertStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel checkPropertyMetaModel; + + public PropertyMetaModel messagePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/AssignExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/AssignExprMetaModel.java new file mode 100644 index 0000000..8a0de9a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/AssignExprMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class AssignExprMetaModel extends ExpressionMetaModel { + + AssignExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.AssignExpr.class, "AssignExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel operatorPropertyMetaModel; + + public PropertyMetaModel targetPropertyMetaModel; + + public PropertyMetaModel valuePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BaseNodeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BaseNodeMetaModel.java new file mode 100644 index 0000000..86e53fd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BaseNodeMetaModel.java @@ -0,0 +1,180 @@ +package com.github.javaparser.metamodel; + +import com.github.javaparser.ast.Node; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static com.github.javaparser.utils.Utils.decapitalize; + +/** + * Meta-data about all classes in the AST. These are all Nodes, except NodeList. + */ +public abstract class BaseNodeMetaModel { + private final Optional superNodeMetaModel; + private final List declaredPropertyMetaModels = new ArrayList<>(); + private final List derivedPropertyMetaModels = new ArrayList<>(); + private final List constructorParameters = new ArrayList<>(); + private final Class type; + private final String name; + private final String packageName; + private final boolean isAbstract; + private final boolean hasWildcard; + + public BaseNodeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + this.superNodeMetaModel = superNodeMetaModel; + this.type = type; + this.name = name; + this.packageName = packageName; + this.isAbstract = isAbstract; + this.hasWildcard = hasWildcard; + } + + /** + * @return is this the meta model for this node class? + */ + public boolean is(Class c) { + return type.equals(c); + } + + /** + * @return package name + class name + */ + public String getQualifiedClassName() { + return packageName + "." + name; + } + + /** + * @return the meta model for the node that this node extends. Note that this is to be used to find properties + * defined in superclasses of a Node. + */ + public Optional getSuperNodeMetaModel() { + return superNodeMetaModel; + } + + /** + * @return a list of all properties declared directly in this node (not its parent nodes.) These are also available + * as fields. + */ + public List getDeclaredPropertyMetaModels() { + return declaredPropertyMetaModels; + } + + public List getDerivedPropertyMetaModels() { + return derivedPropertyMetaModels; + } + + /** + * @return a list of all properties that describe the parameters to the all-fields (but not "range" and "comment") + * constructor, in the order of appearance in the constructor parameter list. + */ + public List getConstructorParameters() { + return constructorParameters; + } + + /** + * @return a list of all properties in this node and its parents. Note that a new list is created every time this + * method is called. + */ + public List getAllPropertyMetaModels() { + List allPropertyMetaModels = new ArrayList<>(getDeclaredPropertyMetaModels()); + BaseNodeMetaModel walkNode = this; + while (walkNode.getSuperNodeMetaModel().isPresent()) { + walkNode = walkNode.getSuperNodeMetaModel().get(); + allPropertyMetaModels.addAll(walkNode.getDeclaredPropertyMetaModels()); + } + return allPropertyMetaModels; + } + + public boolean isInstanceOfMetaModel(BaseNodeMetaModel baseMetaModel) { + if (this == baseMetaModel) { + return true; + } + if (isRootNode()) { + return false; + } + return getSuperNodeMetaModel().get().isInstanceOfMetaModel(baseMetaModel); + } + + /** + * @return the class for this AST node type. + */ + public Class getType() { + return type; + } + + /** + * @return the package containing this AST node class. + */ + public String getPackageName() { + return packageName; + } + + /** + * @return whether this AST node is abstract. + */ + public boolean isAbstract() { + return isAbstract; + } + + /** + * @return whether this AST node has a <?> at the end of its type. + */ + public boolean hasWildcard() { + return hasWildcard; + } + + /** + * @return whether this AST node is the root node, meaning that it is the meta model for "Node": "NodeMetaModel". + */ + public boolean isRootNode() { + return !superNodeMetaModel.isPresent(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + BaseNodeMetaModel classMetaModel = (BaseNodeMetaModel) o; + + if (!type.equals(classMetaModel.type)) return false; + + return true; + } + + @Override + public int hashCode() { + return type.hashCode(); + } + + @Override + public String toString() { + return name; + } + + /** + * @return the type name, with generics. + */ + public String getTypeNameGenerified() { + if (hasWildcard) { + return getTypeName() + ""; + } + return getTypeName(); + } + + /** + * @return the raw type name, so nothing but the name. + */ + public String getTypeName() { + return type.getSimpleName(); + } + + /** + * The name of the field in JavaParserMetaModel for this node meta model. + */ + public String getMetaModelFieldName() { + return decapitalize(getClass().getSimpleName()); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BinaryExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BinaryExprMetaModel.java new file mode 100644 index 0000000..f160ac8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BinaryExprMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class BinaryExprMetaModel extends ExpressionMetaModel { + + BinaryExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.BinaryExpr.class, "BinaryExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel leftPropertyMetaModel; + + public PropertyMetaModel operatorPropertyMetaModel; + + public PropertyMetaModel rightPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BlockCommentMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BlockCommentMetaModel.java new file mode 100644 index 0000000..166397d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BlockCommentMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class BlockCommentMetaModel extends CommentMetaModel { + + BlockCommentMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.BlockComment.class, "BlockComment", "com.github.javaparser.ast.comments", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BlockStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BlockStmtMetaModel.java new file mode 100644 index 0000000..847809d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BlockStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class BlockStmtMetaModel extends StatementMetaModel { + + BlockStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.BlockStmt.class, "BlockStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel statementsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java new file mode 100644 index 0000000..c45d595 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class BodyDeclarationMetaModel extends NodeMetaModel { + + BodyDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.BodyDeclaration.class, "BodyDeclaration", "com.github.javaparser.ast.body", true, true); + } + + protected BodyDeclarationMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel annotationsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java new file mode 100644 index 0000000..eff913d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class BooleanLiteralExprMetaModel extends LiteralExprMetaModel { + + BooleanLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.BooleanLiteralExpr.class, "BooleanLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel valuePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/BreakStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/BreakStmtMetaModel.java new file mode 100644 index 0000000..39f7232 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/BreakStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class BreakStmtMetaModel extends StatementMetaModel { + + BreakStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.BreakStmt.class, "BreakStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel labelPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java new file mode 100644 index 0000000..040762f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java @@ -0,0 +1,27 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class CallableDeclarationMetaModel extends BodyDeclarationMetaModel { + + CallableDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.CallableDeclaration.class, "CallableDeclaration", "com.github.javaparser.ast.body", true, true); + } + + protected CallableDeclarationMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel parametersPropertyMetaModel; + + public PropertyMetaModel receiverParameterPropertyMetaModel; + + public PropertyMetaModel thrownExceptionsPropertyMetaModel; + + public PropertyMetaModel typeParametersPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CastExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CastExprMetaModel.java new file mode 100644 index 0000000..9671d9b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CastExprMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class CastExprMetaModel extends ExpressionMetaModel { + + CastExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.CastExpr.class, "CastExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CatchClauseMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CatchClauseMetaModel.java new file mode 100644 index 0000000..34cd102 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CatchClauseMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class CatchClauseMetaModel extends NodeMetaModel { + + CatchClauseMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.CatchClause.class, "CatchClause", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel parameterPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java new file mode 100644 index 0000000..d88595b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class CharLiteralExprMetaModel extends LiteralStringValueExprMetaModel { + + CharLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.CharLiteralExpr.class, "CharLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ClassExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ClassExprMetaModel.java new file mode 100644 index 0000000..fea3a12 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ClassExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ClassExprMetaModel extends ExpressionMetaModel { + + ClassExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ClassExpr.class, "ClassExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java new file mode 100644 index 0000000..7f0eff9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ClassOrInterfaceDeclarationMetaModel extends TypeDeclarationMetaModel { + + ClassOrInterfaceDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class, "ClassOrInterfaceDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel extendedTypesPropertyMetaModel; + + public PropertyMetaModel implementedTypesPropertyMetaModel; + + public PropertyMetaModel isInterfacePropertyMetaModel; + + public PropertyMetaModel typeParametersPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java new file mode 100644 index 0000000..b2747ed --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ClassOrInterfaceTypeMetaModel extends ReferenceTypeMetaModel { + + ClassOrInterfaceTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ClassOrInterfaceType.class, "ClassOrInterfaceType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel scopePropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CommentMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CommentMetaModel.java new file mode 100644 index 0000000..8cdd7a9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CommentMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class CommentMetaModel extends NodeMetaModel { + + CommentMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.Comment.class, "Comment", "com.github.javaparser.ast.comments", true, false); + } + + protected CommentMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel contentPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/CompilationUnitMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/CompilationUnitMetaModel.java new file mode 100644 index 0000000..34eacb7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/CompilationUnitMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class CompilationUnitMetaModel extends NodeMetaModel { + + CompilationUnitMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.CompilationUnit.class, "CompilationUnit", "com.github.javaparser.ast", false, false); + } + + public PropertyMetaModel importsPropertyMetaModel; + + public PropertyMetaModel modulePropertyMetaModel; + + public PropertyMetaModel packageDeclarationPropertyMetaModel; + + public PropertyMetaModel typesPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ConditionalExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ConditionalExprMetaModel.java new file mode 100644 index 0000000..dbc9119 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ConditionalExprMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ConditionalExprMetaModel extends ExpressionMetaModel { + + ConditionalExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ConditionalExpr.class, "ConditionalExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel conditionPropertyMetaModel; + + public PropertyMetaModel elseExprPropertyMetaModel; + + public PropertyMetaModel thenExprPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java new file mode 100644 index 0000000..4d0b9f3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ConstructorDeclarationMetaModel extends CallableDeclarationMetaModel { + + ConstructorDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ConstructorDeclaration.class, "ConstructorDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ContinueStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ContinueStmtMetaModel.java new file mode 100644 index 0000000..d07db70 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ContinueStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ContinueStmtMetaModel extends StatementMetaModel { + + ContinueStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ContinueStmt.class, "ContinueStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel labelPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/DerivedProperty.java b/JavaParser/src/com/github/javaparser/metamodel/DerivedProperty.java new file mode 100644 index 0000000..3a29d78 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/DerivedProperty.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicate a derived property of a Node, + * meaning it does supply useful information, + * but it does so by taking information from other properties. + * (Used during generation of the meta model.) + */ +@Retention(RUNTIME) +@Target(METHOD) +public @interface DerivedProperty { +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/DoStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/DoStmtMetaModel.java new file mode 100644 index 0000000..45451c7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/DoStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class DoStmtMetaModel extends StatementMetaModel { + + DoStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.DoStmt.class, "DoStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel conditionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java new file mode 100644 index 0000000..2b77273 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class DoubleLiteralExprMetaModel extends LiteralStringValueExprMetaModel { + + DoubleLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.DoubleLiteralExpr.class, "DoubleLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/EmptyStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/EmptyStmtMetaModel.java new file mode 100644 index 0000000..0943326 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/EmptyStmtMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class EmptyStmtMetaModel extends StatementMetaModel { + + EmptyStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.EmptyStmt.class, "EmptyStmt", "com.github.javaparser.ast.stmt", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/EnclosedExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/EnclosedExprMetaModel.java new file mode 100644 index 0000000..4dd99b8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/EnclosedExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class EnclosedExprMetaModel extends ExpressionMetaModel { + + EnclosedExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.EnclosedExpr.class, "EnclosedExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel innerPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java new file mode 100644 index 0000000..2067e6d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class EnumConstantDeclarationMetaModel extends BodyDeclarationMetaModel { + + EnumConstantDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.EnumConstantDeclaration.class, "EnumConstantDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel argumentsPropertyMetaModel; + + public PropertyMetaModel classBodyPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java new file mode 100644 index 0000000..d4ed813 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class EnumDeclarationMetaModel extends TypeDeclarationMetaModel { + + EnumDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.EnumDeclaration.class, "EnumDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel entriesPropertyMetaModel; + + public PropertyMetaModel implementedTypesPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java new file mode 100644 index 0000000..9d47b43 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java @@ -0,0 +1,20 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ExplicitConstructorInvocationStmtMetaModel extends StatementMetaModel { + + ExplicitConstructorInvocationStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt.class, "ExplicitConstructorInvocationStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel argumentsPropertyMetaModel; + + public PropertyMetaModel expressionPropertyMetaModel; + + public PropertyMetaModel isThisPropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ExpressionMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ExpressionMetaModel.java new file mode 100644 index 0000000..dc77368 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ExpressionMetaModel.java @@ -0,0 +1,15 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class ExpressionMetaModel extends NodeMetaModel { + + ExpressionMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.Expression.class, "Expression", "com.github.javaparser.ast.expr", true, false); + } + + protected ExpressionMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java new file mode 100644 index 0000000..69d7a59 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ExpressionStmtMetaModel extends StatementMetaModel { + + ExpressionStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ExpressionStmt.class, "ExpressionStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java new file mode 100644 index 0000000..b9e820e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class FieldAccessExprMetaModel extends ExpressionMetaModel { + + FieldAccessExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.FieldAccessExpr.class, "FieldAccessExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel scopePropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java new file mode 100644 index 0000000..9f12fae --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class FieldDeclarationMetaModel extends BodyDeclarationMetaModel { + + FieldDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.FieldDeclaration.class, "FieldDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel variablesPropertyMetaModel; + + public PropertyMetaModel maximumCommonTypePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ForStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ForStmtMetaModel.java new file mode 100644 index 0000000..c63039e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ForStmtMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ForStmtMetaModel extends StatementMetaModel { + + ForStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ForStmt.class, "ForStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel comparePropertyMetaModel; + + public PropertyMetaModel initializationPropertyMetaModel; + + public PropertyMetaModel updatePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ForeachStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ForeachStmtMetaModel.java new file mode 100644 index 0000000..8a8dc4e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ForeachStmtMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ForeachStmtMetaModel extends StatementMetaModel { + + ForeachStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ForeachStmt.class, "ForeachStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel iterablePropertyMetaModel; + + public PropertyMetaModel variablePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/IfStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/IfStmtMetaModel.java new file mode 100644 index 0000000..91f4027 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/IfStmtMetaModel.java @@ -0,0 +1,24 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class IfStmtMetaModel extends StatementMetaModel { + + IfStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.IfStmt.class, "IfStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel conditionPropertyMetaModel; + + public PropertyMetaModel elseStmtPropertyMetaModel; + + public PropertyMetaModel thenStmtPropertyMetaModel; + + public PropertyMetaModel cascadingIfStmtPropertyMetaModel; + + public PropertyMetaModel elseBlockPropertyMetaModel; + + public PropertyMetaModel elseBranchPropertyMetaModel; + + public PropertyMetaModel thenBlockPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java new file mode 100644 index 0000000..3c1e4f8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ImportDeclarationMetaModel extends NodeMetaModel { + + ImportDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.ImportDeclaration.class, "ImportDeclaration", "com.github.javaparser.ast", false, false); + } + + public PropertyMetaModel isAsteriskPropertyMetaModel; + + public PropertyMetaModel isStaticPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java new file mode 100644 index 0000000..035038c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class InitializerDeclarationMetaModel extends BodyDeclarationMetaModel { + + InitializerDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.InitializerDeclaration.class, "InitializerDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel isStaticPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java new file mode 100644 index 0000000..9b4534c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class InstanceOfExprMetaModel extends ExpressionMetaModel { + + InstanceOfExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.InstanceOfExpr.class, "InstanceOfExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java new file mode 100644 index 0000000..b793217 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class IntegerLiteralExprMetaModel extends LiteralStringValueExprMetaModel { + + IntegerLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.IntegerLiteralExpr.class, "IntegerLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/InternalProperty.java b/JavaParser/src/com/github/javaparser/metamodel/InternalProperty.java new file mode 100644 index 0000000..83c5970 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/InternalProperty.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicate an internal property of a Node, + * meaning it is not part of the meta model. + * (Used during generation of the meta model.) + */ +@Retention(RUNTIME) +@Target(FIELD) +public @interface InternalProperty { +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java new file mode 100644 index 0000000..73ad36f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class IntersectionTypeMetaModel extends TypeMetaModel { + + IntersectionTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.IntersectionType.class, "IntersectionType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel elementsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/JavaParserMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/JavaParserMetaModel.java new file mode 100644 index 0000000..bffbd37 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/JavaParserMetaModel.java @@ -0,0 +1,977 @@ +package com.github.javaparser.metamodel; + +import com.github.javaparser.ast.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * The model contains meta-data about all nodes in the AST. + */ +public final class JavaParserMetaModel { + + private JavaParserMetaModel() { + } + + private static final List nodeMetaModels = new ArrayList<>(); + + private static void initializeConstructorParameters() { + bodyDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel); + callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel); + typeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + annotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel); + typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel); + typeDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel); + typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel); + referenceTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + literalStringValueExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + stringLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.annotationsPropertyMetaModel); + moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.namePropertyMetaModel); + moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.isOpenPropertyMetaModel); + moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel); + arrayCreationLevelMetaModel.getConstructorParameters().add(arrayCreationLevelMetaModel.dimensionPropertyMetaModel); + arrayCreationLevelMetaModel.getConstructorParameters().add(arrayCreationLevelMetaModel.annotationsPropertyMetaModel); + compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.packageDeclarationPropertyMetaModel); + compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.importsPropertyMetaModel); + compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.typesPropertyMetaModel); + compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.modulePropertyMetaModel); + packageDeclarationMetaModel.getConstructorParameters().add(packageDeclarationMetaModel.annotationsPropertyMetaModel); + packageDeclarationMetaModel.getConstructorParameters().add(packageDeclarationMetaModel.namePropertyMetaModel); + annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel); + annotationDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel); + annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel); + annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel); + annotationMemberDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.typePropertyMetaModel); + annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.namePropertyMetaModel); + annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(constructorDeclarationMetaModel.bodyPropertyMetaModel); + constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel); + enumConstantDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.namePropertyMetaModel); + enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.argumentsPropertyMetaModel); + enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.classBodyPropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(enumDeclarationMetaModel.implementedTypesPropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(enumDeclarationMetaModel.entriesPropertyMetaModel); + enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel); + fieldDeclarationMetaModel.getConstructorParameters().add(fieldDeclarationMetaModel.modifiersPropertyMetaModel); + fieldDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + fieldDeclarationMetaModel.getConstructorParameters().add(fieldDeclarationMetaModel.variablesPropertyMetaModel); + initializerDeclarationMetaModel.getConstructorParameters().add(initializerDeclarationMetaModel.isStaticPropertyMetaModel); + initializerDeclarationMetaModel.getConstructorParameters().add(initializerDeclarationMetaModel.bodyPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(methodDeclarationMetaModel.typePropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(methodDeclarationMetaModel.bodyPropertyMetaModel); + methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.modifiersPropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.annotationsPropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.typePropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.isVarArgsPropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.varArgsAnnotationsPropertyMetaModel); + parameterMetaModel.getConstructorParameters().add(parameterMetaModel.namePropertyMetaModel); + receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.annotationsPropertyMetaModel); + receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.typePropertyMetaModel); + receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.namePropertyMetaModel); + variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.typePropertyMetaModel); + variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.namePropertyMetaModel); + variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.initializerPropertyMetaModel); + commentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel); + blockCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel); + javadocCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel); + lineCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel); + arrayAccessExprMetaModel.getConstructorParameters().add(arrayAccessExprMetaModel.namePropertyMetaModel); + arrayAccessExprMetaModel.getConstructorParameters().add(arrayAccessExprMetaModel.indexPropertyMetaModel); + arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.elementTypePropertyMetaModel); + arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.levelsPropertyMetaModel); + arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.initializerPropertyMetaModel); + arrayInitializerExprMetaModel.getConstructorParameters().add(arrayInitializerExprMetaModel.valuesPropertyMetaModel); + assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.targetPropertyMetaModel); + assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.valuePropertyMetaModel); + assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.operatorPropertyMetaModel); + binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.leftPropertyMetaModel); + binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.rightPropertyMetaModel); + binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.operatorPropertyMetaModel); + booleanLiteralExprMetaModel.getConstructorParameters().add(booleanLiteralExprMetaModel.valuePropertyMetaModel); + castExprMetaModel.getConstructorParameters().add(castExprMetaModel.typePropertyMetaModel); + castExprMetaModel.getConstructorParameters().add(castExprMetaModel.expressionPropertyMetaModel); + charLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + classExprMetaModel.getConstructorParameters().add(classExprMetaModel.typePropertyMetaModel); + conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.conditionPropertyMetaModel); + conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.thenExprPropertyMetaModel); + conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.elseExprPropertyMetaModel); + doubleLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + enclosedExprMetaModel.getConstructorParameters().add(enclosedExprMetaModel.innerPropertyMetaModel); + fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.scopePropertyMetaModel); + fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel); + fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.namePropertyMetaModel); + instanceOfExprMetaModel.getConstructorParameters().add(instanceOfExprMetaModel.expressionPropertyMetaModel); + instanceOfExprMetaModel.getConstructorParameters().add(instanceOfExprMetaModel.typePropertyMetaModel); + integerLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.parametersPropertyMetaModel); + lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.bodyPropertyMetaModel); + lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel); + longLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + markerAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel); + memberValuePairMetaModel.getConstructorParameters().add(memberValuePairMetaModel.namePropertyMetaModel); + memberValuePairMetaModel.getConstructorParameters().add(memberValuePairMetaModel.valuePropertyMetaModel); + methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.scopePropertyMetaModel); + methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.typeArgumentsPropertyMetaModel); + methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.namePropertyMetaModel); + methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.argumentsPropertyMetaModel); + methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.scopePropertyMetaModel); + methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel); + methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.identifierPropertyMetaModel); + nameExprMetaModel.getConstructorParameters().add(nameExprMetaModel.namePropertyMetaModel); + nameMetaModel.getConstructorParameters().add(nameMetaModel.qualifierPropertyMetaModel); + nameMetaModel.getConstructorParameters().add(nameMetaModel.identifierPropertyMetaModel); + nameMetaModel.getConstructorParameters().add(nameMetaModel.annotationsPropertyMetaModel); + normalAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel); + normalAnnotationExprMetaModel.getConstructorParameters().add(normalAnnotationExprMetaModel.pairsPropertyMetaModel); + objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.scopePropertyMetaModel); + objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.typePropertyMetaModel); + objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.typeArgumentsPropertyMetaModel); + objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.argumentsPropertyMetaModel); + objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel); + simpleNameMetaModel.getConstructorParameters().add(simpleNameMetaModel.identifierPropertyMetaModel); + singleMemberAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel); + singleMemberAnnotationExprMetaModel.getConstructorParameters().add(singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel); + superExprMetaModel.getConstructorParameters().add(superExprMetaModel.classExprPropertyMetaModel); + thisExprMetaModel.getConstructorParameters().add(thisExprMetaModel.classExprPropertyMetaModel); + typeExprMetaModel.getConstructorParameters().add(typeExprMetaModel.typePropertyMetaModel); + unaryExprMetaModel.getConstructorParameters().add(unaryExprMetaModel.expressionPropertyMetaModel); + unaryExprMetaModel.getConstructorParameters().add(unaryExprMetaModel.operatorPropertyMetaModel); + variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.modifiersPropertyMetaModel); + variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.annotationsPropertyMetaModel); + variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.variablesPropertyMetaModel); + importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.namePropertyMetaModel); + importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.isStaticPropertyMetaModel); + importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.isAsteriskPropertyMetaModel); + assertStmtMetaModel.getConstructorParameters().add(assertStmtMetaModel.checkPropertyMetaModel); + assertStmtMetaModel.getConstructorParameters().add(assertStmtMetaModel.messagePropertyMetaModel); + blockStmtMetaModel.getConstructorParameters().add(blockStmtMetaModel.statementsPropertyMetaModel); + breakStmtMetaModel.getConstructorParameters().add(breakStmtMetaModel.labelPropertyMetaModel); + catchClauseMetaModel.getConstructorParameters().add(catchClauseMetaModel.parameterPropertyMetaModel); + catchClauseMetaModel.getConstructorParameters().add(catchClauseMetaModel.bodyPropertyMetaModel); + continueStmtMetaModel.getConstructorParameters().add(continueStmtMetaModel.labelPropertyMetaModel); + doStmtMetaModel.getConstructorParameters().add(doStmtMetaModel.bodyPropertyMetaModel); + doStmtMetaModel.getConstructorParameters().add(doStmtMetaModel.conditionPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel); + expressionStmtMetaModel.getConstructorParameters().add(expressionStmtMetaModel.expressionPropertyMetaModel); + foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.variablePropertyMetaModel); + foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.iterablePropertyMetaModel); + foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.bodyPropertyMetaModel); + forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.initializationPropertyMetaModel); + forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.comparePropertyMetaModel); + forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.updatePropertyMetaModel); + forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.bodyPropertyMetaModel); + ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.conditionPropertyMetaModel); + ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.thenStmtPropertyMetaModel); + ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.elseStmtPropertyMetaModel); + labeledStmtMetaModel.getConstructorParameters().add(labeledStmtMetaModel.labelPropertyMetaModel); + labeledStmtMetaModel.getConstructorParameters().add(labeledStmtMetaModel.statementPropertyMetaModel); + returnStmtMetaModel.getConstructorParameters().add(returnStmtMetaModel.expressionPropertyMetaModel); + switchEntryStmtMetaModel.getConstructorParameters().add(switchEntryStmtMetaModel.labelPropertyMetaModel); + switchEntryStmtMetaModel.getConstructorParameters().add(switchEntryStmtMetaModel.statementsPropertyMetaModel); + switchStmtMetaModel.getConstructorParameters().add(switchStmtMetaModel.selectorPropertyMetaModel); + switchStmtMetaModel.getConstructorParameters().add(switchStmtMetaModel.entriesPropertyMetaModel); + synchronizedStmtMetaModel.getConstructorParameters().add(synchronizedStmtMetaModel.expressionPropertyMetaModel); + synchronizedStmtMetaModel.getConstructorParameters().add(synchronizedStmtMetaModel.bodyPropertyMetaModel); + throwStmtMetaModel.getConstructorParameters().add(throwStmtMetaModel.expressionPropertyMetaModel); + tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.resourcesPropertyMetaModel); + tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.tryBlockPropertyMetaModel); + tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.catchClausesPropertyMetaModel); + tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.finallyBlockPropertyMetaModel); + localClassDeclarationStmtMetaModel.getConstructorParameters().add(localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel); + whileStmtMetaModel.getConstructorParameters().add(whileStmtMetaModel.conditionPropertyMetaModel); + whileStmtMetaModel.getConstructorParameters().add(whileStmtMetaModel.bodyPropertyMetaModel); + arrayTypeMetaModel.getConstructorParameters().add(arrayTypeMetaModel.componentTypePropertyMetaModel); + arrayTypeMetaModel.getConstructorParameters().add(arrayTypeMetaModel.originPropertyMetaModel); + arrayTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.scopePropertyMetaModel); + classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.namePropertyMetaModel); + classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel); + classOrInterfaceTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + intersectionTypeMetaModel.getConstructorParameters().add(intersectionTypeMetaModel.elementsPropertyMetaModel); + primitiveTypeMetaModel.getConstructorParameters().add(primitiveTypeMetaModel.typePropertyMetaModel); + primitiveTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + typeParameterMetaModel.getConstructorParameters().add(typeParameterMetaModel.namePropertyMetaModel); + typeParameterMetaModel.getConstructorParameters().add(typeParameterMetaModel.typeBoundPropertyMetaModel); + typeParameterMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + unionTypeMetaModel.getConstructorParameters().add(unionTypeMetaModel.elementsPropertyMetaModel); + wildcardTypeMetaModel.getConstructorParameters().add(wildcardTypeMetaModel.extendedTypePropertyMetaModel); + wildcardTypeMetaModel.getConstructorParameters().add(wildcardTypeMetaModel.superTypePropertyMetaModel); + wildcardTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel); + moduleRequiresStmtMetaModel.getConstructorParameters().add(moduleRequiresStmtMetaModel.modifiersPropertyMetaModel); + moduleRequiresStmtMetaModel.getConstructorParameters().add(moduleRequiresStmtMetaModel.namePropertyMetaModel); + moduleExportsStmtMetaModel.getConstructorParameters().add(moduleExportsStmtMetaModel.namePropertyMetaModel); + moduleExportsStmtMetaModel.getConstructorParameters().add(moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel); + moduleProvidesStmtMetaModel.getConstructorParameters().add(moduleProvidesStmtMetaModel.typePropertyMetaModel); + moduleProvidesStmtMetaModel.getConstructorParameters().add(moduleProvidesStmtMetaModel.withTypesPropertyMetaModel); + moduleUsesStmtMetaModel.getConstructorParameters().add(moduleUsesStmtMetaModel.typePropertyMetaModel); + moduleOpensStmtMetaModel.getConstructorParameters().add(moduleOpensStmtMetaModel.namePropertyMetaModel); + moduleOpensStmtMetaModel.getConstructorParameters().add(moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel); + } + + public static List getNodeMetaModels() { + return nodeMetaModels; + } + + private static void initializeNodeMetaModels() { + nodeMetaModels.add(annotationDeclarationMetaModel); + nodeMetaModels.add(annotationExprMetaModel); + nodeMetaModels.add(annotationMemberDeclarationMetaModel); + nodeMetaModels.add(arrayAccessExprMetaModel); + nodeMetaModels.add(arrayCreationExprMetaModel); + nodeMetaModels.add(arrayCreationLevelMetaModel); + nodeMetaModels.add(arrayInitializerExprMetaModel); + nodeMetaModels.add(arrayTypeMetaModel); + nodeMetaModels.add(assertStmtMetaModel); + nodeMetaModels.add(assignExprMetaModel); + nodeMetaModels.add(binaryExprMetaModel); + nodeMetaModels.add(blockCommentMetaModel); + nodeMetaModels.add(blockStmtMetaModel); + nodeMetaModels.add(bodyDeclarationMetaModel); + nodeMetaModels.add(booleanLiteralExprMetaModel); + nodeMetaModels.add(breakStmtMetaModel); + nodeMetaModels.add(callableDeclarationMetaModel); + nodeMetaModels.add(castExprMetaModel); + nodeMetaModels.add(catchClauseMetaModel); + nodeMetaModels.add(charLiteralExprMetaModel); + nodeMetaModels.add(classExprMetaModel); + nodeMetaModels.add(classOrInterfaceDeclarationMetaModel); + nodeMetaModels.add(classOrInterfaceTypeMetaModel); + nodeMetaModels.add(commentMetaModel); + nodeMetaModels.add(compilationUnitMetaModel); + nodeMetaModels.add(conditionalExprMetaModel); + nodeMetaModels.add(constructorDeclarationMetaModel); + nodeMetaModels.add(continueStmtMetaModel); + nodeMetaModels.add(doStmtMetaModel); + nodeMetaModels.add(doubleLiteralExprMetaModel); + nodeMetaModels.add(emptyStmtMetaModel); + nodeMetaModels.add(enclosedExprMetaModel); + nodeMetaModels.add(enumConstantDeclarationMetaModel); + nodeMetaModels.add(enumDeclarationMetaModel); + nodeMetaModels.add(explicitConstructorInvocationStmtMetaModel); + nodeMetaModels.add(expressionMetaModel); + nodeMetaModels.add(expressionStmtMetaModel); + nodeMetaModels.add(fieldAccessExprMetaModel); + nodeMetaModels.add(fieldDeclarationMetaModel); + nodeMetaModels.add(forStmtMetaModel); + nodeMetaModels.add(foreachStmtMetaModel); + nodeMetaModels.add(ifStmtMetaModel); + nodeMetaModels.add(importDeclarationMetaModel); + nodeMetaModels.add(initializerDeclarationMetaModel); + nodeMetaModels.add(instanceOfExprMetaModel); + nodeMetaModels.add(integerLiteralExprMetaModel); + nodeMetaModels.add(intersectionTypeMetaModel); + nodeMetaModels.add(javadocCommentMetaModel); + nodeMetaModels.add(labeledStmtMetaModel); + nodeMetaModels.add(lambdaExprMetaModel); + nodeMetaModels.add(lineCommentMetaModel); + nodeMetaModels.add(literalExprMetaModel); + nodeMetaModels.add(literalStringValueExprMetaModel); + nodeMetaModels.add(localClassDeclarationStmtMetaModel); + nodeMetaModels.add(longLiteralExprMetaModel); + nodeMetaModels.add(markerAnnotationExprMetaModel); + nodeMetaModels.add(memberValuePairMetaModel); + nodeMetaModels.add(methodCallExprMetaModel); + nodeMetaModels.add(methodDeclarationMetaModel); + nodeMetaModels.add(methodReferenceExprMetaModel); + nodeMetaModels.add(moduleDeclarationMetaModel); + nodeMetaModels.add(moduleExportsStmtMetaModel); + nodeMetaModels.add(moduleOpensStmtMetaModel); + nodeMetaModels.add(moduleProvidesStmtMetaModel); + nodeMetaModels.add(moduleRequiresStmtMetaModel); + nodeMetaModels.add(moduleStmtMetaModel); + nodeMetaModels.add(moduleUsesStmtMetaModel); + nodeMetaModels.add(nameExprMetaModel); + nodeMetaModels.add(nameMetaModel); + nodeMetaModels.add(nodeMetaModel); + nodeMetaModels.add(normalAnnotationExprMetaModel); + nodeMetaModels.add(nullLiteralExprMetaModel); + nodeMetaModels.add(objectCreationExprMetaModel); + nodeMetaModels.add(packageDeclarationMetaModel); + nodeMetaModels.add(parameterMetaModel); + nodeMetaModels.add(primitiveTypeMetaModel); + nodeMetaModels.add(receiverParameterMetaModel); + nodeMetaModels.add(referenceTypeMetaModel); + nodeMetaModels.add(returnStmtMetaModel); + nodeMetaModels.add(simpleNameMetaModel); + nodeMetaModels.add(singleMemberAnnotationExprMetaModel); + nodeMetaModels.add(statementMetaModel); + nodeMetaModels.add(stringLiteralExprMetaModel); + nodeMetaModels.add(superExprMetaModel); + nodeMetaModels.add(switchEntryStmtMetaModel); + nodeMetaModels.add(switchStmtMetaModel); + nodeMetaModels.add(synchronizedStmtMetaModel); + nodeMetaModels.add(thisExprMetaModel); + nodeMetaModels.add(throwStmtMetaModel); + nodeMetaModels.add(tryStmtMetaModel); + nodeMetaModels.add(typeDeclarationMetaModel); + nodeMetaModels.add(typeExprMetaModel); + nodeMetaModels.add(typeMetaModel); + nodeMetaModels.add(typeParameterMetaModel); + nodeMetaModels.add(unaryExprMetaModel); + nodeMetaModels.add(unionTypeMetaModel); + nodeMetaModels.add(unknownTypeMetaModel); + nodeMetaModels.add(unparsableStmtMetaModel); + nodeMetaModels.add(varTypeMetaModel); + nodeMetaModels.add(variableDeclarationExprMetaModel); + nodeMetaModels.add(variableDeclaratorMetaModel); + nodeMetaModels.add(voidTypeMetaModel); + nodeMetaModels.add(whileStmtMetaModel); + nodeMetaModels.add(wildcardTypeMetaModel); + } + + private static void initializePropertyMetaModels() { + nodeMetaModel.commentPropertyMetaModel = new PropertyMetaModel(nodeMetaModel, "comment", com.github.javaparser.ast.comments.Comment.class, Optional.of(commentMetaModel), true, false, false, false, false); + nodeMetaModel.getDeclaredPropertyMetaModels().add(nodeMetaModel.commentPropertyMetaModel); + bodyDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(bodyDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + bodyDeclarationMetaModel.getDeclaredPropertyMetaModels().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); + callableDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.modifiersPropertyMetaModel); + callableDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.namePropertyMetaModel); + callableDeclarationMetaModel.parametersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "parameters", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, true, false, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.parametersPropertyMetaModel); + callableDeclarationMetaModel.receiverParameterPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "receiverParameter", com.github.javaparser.ast.body.ReceiverParameter.class, Optional.of(receiverParameterMetaModel), true, false, false, false, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel); + callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "thrownExceptions", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, false, true, false, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel); + callableDeclarationMetaModel.typeParametersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "typeParameters", com.github.javaparser.ast.type.TypeParameter.class, Optional.of(typeParameterMetaModel), false, false, true, false, false); + callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel); + typeMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(typeMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + typeMetaModel.getDeclaredPropertyMetaModels().add(typeMetaModel.annotationsPropertyMetaModel); + annotationExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(annotationExprMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + annotationExprMetaModel.getDeclaredPropertyMetaModels().add(annotationExprMetaModel.namePropertyMetaModel); + typeDeclarationMetaModel.membersPropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "members", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), false, false, true, false, true); + typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.membersPropertyMetaModel); + typeDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.modifiersPropertyMetaModel); + typeDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.namePropertyMetaModel); + literalStringValueExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(literalStringValueExprMetaModel, "value", java.lang.String.class, Optional.empty(), false, false, false, false, false); + literalStringValueExprMetaModel.getDeclaredPropertyMetaModels().add(literalStringValueExprMetaModel.valuePropertyMetaModel); + moduleDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.annotationsPropertyMetaModel); + moduleDeclarationMetaModel.isOpenPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "isOpen", boolean.class, Optional.empty(), false, false, false, false, false); + moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.isOpenPropertyMetaModel); + moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "moduleStmts", com.github.javaparser.ast.modules.ModuleStmt.class, Optional.of(moduleStmtMetaModel), false, false, true, false, false); + moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel); + moduleDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.namePropertyMetaModel); + arrayCreationLevelMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(arrayCreationLevelMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + arrayCreationLevelMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationLevelMetaModel.annotationsPropertyMetaModel); + arrayCreationLevelMetaModel.dimensionPropertyMetaModel = new PropertyMetaModel(arrayCreationLevelMetaModel, "dimension", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + arrayCreationLevelMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationLevelMetaModel.dimensionPropertyMetaModel); + compilationUnitMetaModel.importsPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "imports", com.github.javaparser.ast.ImportDeclaration.class, Optional.of(importDeclarationMetaModel), false, false, true, false, false); + compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.importsPropertyMetaModel); + compilationUnitMetaModel.modulePropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "module", com.github.javaparser.ast.modules.ModuleDeclaration.class, Optional.of(moduleDeclarationMetaModel), true, false, false, false, false); + compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.modulePropertyMetaModel); + compilationUnitMetaModel.packageDeclarationPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "packageDeclaration", com.github.javaparser.ast.PackageDeclaration.class, Optional.of(packageDeclarationMetaModel), true, false, false, false, false); + compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.packageDeclarationPropertyMetaModel); + compilationUnitMetaModel.typesPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "types", com.github.javaparser.ast.body.TypeDeclaration.class, Optional.of(typeDeclarationMetaModel), false, false, true, false, true); + compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.typesPropertyMetaModel); + packageDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(packageDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + packageDeclarationMetaModel.getDeclaredPropertyMetaModels().add(packageDeclarationMetaModel.annotationsPropertyMetaModel); + packageDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(packageDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + packageDeclarationMetaModel.getDeclaredPropertyMetaModels().add(packageDeclarationMetaModel.namePropertyMetaModel); + annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "defaultValue", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel); + annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel); + annotationMemberDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.namePropertyMetaModel); + annotationMemberDeclarationMetaModel.typePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.typePropertyMetaModel); + classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "extendedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false); + classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "implementedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false); + classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel); + classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "isInterface", boolean.class, Optional.empty(), false, false, false, false, false); + classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel); + classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "typeParameters", com.github.javaparser.ast.type.TypeParameter.class, Optional.of(typeParameterMetaModel), false, false, true, false, false); + classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel); + constructorDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(constructorDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false); + constructorDeclarationMetaModel.getDeclaredPropertyMetaModels().add(constructorDeclarationMetaModel.bodyPropertyMetaModel); + enumConstantDeclarationMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.argumentsPropertyMetaModel); + enumConstantDeclarationMetaModel.classBodyPropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "classBody", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), false, false, true, false, true); + enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.classBodyPropertyMetaModel); + enumConstantDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.namePropertyMetaModel); + enumDeclarationMetaModel.entriesPropertyMetaModel = new PropertyMetaModel(enumDeclarationMetaModel, "entries", com.github.javaparser.ast.body.EnumConstantDeclaration.class, Optional.of(enumConstantDeclarationMetaModel), false, false, true, false, false); + enumDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumDeclarationMetaModel.entriesPropertyMetaModel); + enumDeclarationMetaModel.implementedTypesPropertyMetaModel = new PropertyMetaModel(enumDeclarationMetaModel, "implementedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false); + enumDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumDeclarationMetaModel.implementedTypesPropertyMetaModel); + fieldDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + fieldDeclarationMetaModel.getDeclaredPropertyMetaModels().add(fieldDeclarationMetaModel.modifiersPropertyMetaModel); + fieldDeclarationMetaModel.variablesPropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "variables", com.github.javaparser.ast.body.VariableDeclarator.class, Optional.of(variableDeclaratorMetaModel), false, true, true, false, false); + fieldDeclarationMetaModel.getDeclaredPropertyMetaModels().add(fieldDeclarationMetaModel.variablesPropertyMetaModel); + fieldDeclarationMetaModel.maximumCommonTypePropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "maximumCommonType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, false, false, false); + fieldDeclarationMetaModel.getDerivedPropertyMetaModels().add(fieldDeclarationMetaModel.maximumCommonTypePropertyMetaModel); + initializerDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(initializerDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false); + initializerDeclarationMetaModel.getDeclaredPropertyMetaModels().add(initializerDeclarationMetaModel.bodyPropertyMetaModel); + initializerDeclarationMetaModel.isStaticPropertyMetaModel = new PropertyMetaModel(initializerDeclarationMetaModel, "isStatic", boolean.class, Optional.empty(), false, false, false, false, false); + initializerDeclarationMetaModel.getDeclaredPropertyMetaModels().add(initializerDeclarationMetaModel.isStaticPropertyMetaModel); + methodDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(methodDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), true, false, false, false, false); + methodDeclarationMetaModel.getDeclaredPropertyMetaModels().add(methodDeclarationMetaModel.bodyPropertyMetaModel); + methodDeclarationMetaModel.typePropertyMetaModel = new PropertyMetaModel(methodDeclarationMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + methodDeclarationMetaModel.getDeclaredPropertyMetaModels().add(methodDeclarationMetaModel.typePropertyMetaModel); + parameterMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.annotationsPropertyMetaModel); + parameterMetaModel.isVarArgsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "isVarArgs", boolean.class, Optional.empty(), false, false, false, false, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.isVarArgsPropertyMetaModel); + parameterMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.modifiersPropertyMetaModel); + parameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.namePropertyMetaModel); + parameterMetaModel.typePropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.typePropertyMetaModel); + parameterMetaModel.varArgsAnnotationsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "varArgsAnnotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.varArgsAnnotationsPropertyMetaModel); + receiverParameterMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.annotationsPropertyMetaModel); + receiverParameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.namePropertyMetaModel); + receiverParameterMetaModel.typePropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.typePropertyMetaModel); + variableDeclaratorMetaModel.initializerPropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "initializer", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, true, false, false, false); + variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.initializerPropertyMetaModel); + variableDeclaratorMetaModel.namePropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.namePropertyMetaModel); + variableDeclaratorMetaModel.typePropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.typePropertyMetaModel); + commentMetaModel.contentPropertyMetaModel = new PropertyMetaModel(commentMetaModel, "content", java.lang.String.class, Optional.empty(), false, false, false, false, false); + commentMetaModel.getDeclaredPropertyMetaModels().add(commentMetaModel.contentPropertyMetaModel); + arrayAccessExprMetaModel.indexPropertyMetaModel = new PropertyMetaModel(arrayAccessExprMetaModel, "index", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + arrayAccessExprMetaModel.getDeclaredPropertyMetaModels().add(arrayAccessExprMetaModel.indexPropertyMetaModel); + arrayAccessExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(arrayAccessExprMetaModel, "name", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + arrayAccessExprMetaModel.getDeclaredPropertyMetaModels().add(arrayAccessExprMetaModel.namePropertyMetaModel); + arrayCreationExprMetaModel.elementTypePropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "elementType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.elementTypePropertyMetaModel); + arrayCreationExprMetaModel.initializerPropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "initializer", com.github.javaparser.ast.expr.ArrayInitializerExpr.class, Optional.of(arrayInitializerExprMetaModel), true, false, false, false, false); + arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.initializerPropertyMetaModel); + arrayCreationExprMetaModel.levelsPropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "levels", com.github.javaparser.ast.ArrayCreationLevel.class, Optional.of(arrayCreationLevelMetaModel), false, true, true, false, false); + arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.levelsPropertyMetaModel); + arrayInitializerExprMetaModel.valuesPropertyMetaModel = new PropertyMetaModel(arrayInitializerExprMetaModel, "values", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + arrayInitializerExprMetaModel.getDeclaredPropertyMetaModels().add(arrayInitializerExprMetaModel.valuesPropertyMetaModel); + assignExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "operator", com.github.javaparser.ast.expr.AssignExpr.Operator.class, Optional.empty(), false, false, false, false, false); + assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.operatorPropertyMetaModel); + assignExprMetaModel.targetPropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "target", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.targetPropertyMetaModel); + assignExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "value", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.valuePropertyMetaModel); + binaryExprMetaModel.leftPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "left", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.leftPropertyMetaModel); + binaryExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "operator", com.github.javaparser.ast.expr.BinaryExpr.Operator.class, Optional.empty(), false, false, false, false, false); + binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.operatorPropertyMetaModel); + binaryExprMetaModel.rightPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "right", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.rightPropertyMetaModel); + booleanLiteralExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(booleanLiteralExprMetaModel, "value", boolean.class, Optional.empty(), false, false, false, false, false); + booleanLiteralExprMetaModel.getDeclaredPropertyMetaModels().add(booleanLiteralExprMetaModel.valuePropertyMetaModel); + castExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(castExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + castExprMetaModel.getDeclaredPropertyMetaModels().add(castExprMetaModel.expressionPropertyMetaModel); + castExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(castExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + castExprMetaModel.getDeclaredPropertyMetaModels().add(castExprMetaModel.typePropertyMetaModel); + classExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(classExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + classExprMetaModel.getDeclaredPropertyMetaModels().add(classExprMetaModel.typePropertyMetaModel); + conditionalExprMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.conditionPropertyMetaModel); + conditionalExprMetaModel.elseExprPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "elseExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.elseExprPropertyMetaModel); + conditionalExprMetaModel.thenExprPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "thenExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.thenExprPropertyMetaModel); + enclosedExprMetaModel.innerPropertyMetaModel = new PropertyMetaModel(enclosedExprMetaModel, "inner", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + enclosedExprMetaModel.getDeclaredPropertyMetaModels().add(enclosedExprMetaModel.innerPropertyMetaModel); + fieldAccessExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.namePropertyMetaModel); + fieldAccessExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.scopePropertyMetaModel); + fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel); + fieldAccessExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + fieldAccessExprMetaModel.getDerivedPropertyMetaModels().add(fieldAccessExprMetaModel.usingDiamondOperatorPropertyMetaModel); + instanceOfExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(instanceOfExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + instanceOfExprMetaModel.getDeclaredPropertyMetaModels().add(instanceOfExprMetaModel.expressionPropertyMetaModel); + instanceOfExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(instanceOfExprMetaModel, "type", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, false, false, false, false); + instanceOfExprMetaModel.getDeclaredPropertyMetaModels().add(instanceOfExprMetaModel.typePropertyMetaModel); + lambdaExprMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.bodyPropertyMetaModel); + lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "isEnclosingParameters", boolean.class, Optional.empty(), false, false, false, false, false); + lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel); + lambdaExprMetaModel.parametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "parameters", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, true, false, false); + lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.parametersPropertyMetaModel); + lambdaExprMetaModel.expressionBodyPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "expressionBody", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + lambdaExprMetaModel.getDerivedPropertyMetaModels().add(lambdaExprMetaModel.expressionBodyPropertyMetaModel); + memberValuePairMetaModel.namePropertyMetaModel = new PropertyMetaModel(memberValuePairMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + memberValuePairMetaModel.getDeclaredPropertyMetaModels().add(memberValuePairMetaModel.namePropertyMetaModel); + memberValuePairMetaModel.valuePropertyMetaModel = new PropertyMetaModel(memberValuePairMetaModel, "value", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + memberValuePairMetaModel.getDeclaredPropertyMetaModels().add(memberValuePairMetaModel.valuePropertyMetaModel); + methodCallExprMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.argumentsPropertyMetaModel); + methodCallExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.namePropertyMetaModel); + methodCallExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.scopePropertyMetaModel); + methodCallExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.typeArgumentsPropertyMetaModel); + methodCallExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + methodCallExprMetaModel.getDerivedPropertyMetaModels().add(methodCallExprMetaModel.usingDiamondOperatorPropertyMetaModel); + methodReferenceExprMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false); + methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.identifierPropertyMetaModel); + methodReferenceExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.scopePropertyMetaModel); + methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel); + methodReferenceExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + methodReferenceExprMetaModel.getDerivedPropertyMetaModels().add(methodReferenceExprMetaModel.usingDiamondOperatorPropertyMetaModel); + nameExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(nameExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + nameExprMetaModel.getDeclaredPropertyMetaModels().add(nameExprMetaModel.namePropertyMetaModel); + nameMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.annotationsPropertyMetaModel); + nameMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false); + nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.identifierPropertyMetaModel); + nameMetaModel.qualifierPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "qualifier", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), true, false, false, false, false); + nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.qualifierPropertyMetaModel); + normalAnnotationExprMetaModel.pairsPropertyMetaModel = new PropertyMetaModel(normalAnnotationExprMetaModel, "pairs", com.github.javaparser.ast.expr.MemberValuePair.class, Optional.of(memberValuePairMetaModel), false, false, true, false, false); + normalAnnotationExprMetaModel.getDeclaredPropertyMetaModels().add(normalAnnotationExprMetaModel.pairsPropertyMetaModel); + objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "anonymousClassBody", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), true, false, true, false, true); + objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel); + objectCreationExprMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.argumentsPropertyMetaModel); + objectCreationExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.scopePropertyMetaModel); + objectCreationExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "type", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, false, false, false); + objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.typePropertyMetaModel); + objectCreationExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.typeArgumentsPropertyMetaModel); + objectCreationExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + objectCreationExprMetaModel.getDerivedPropertyMetaModels().add(objectCreationExprMetaModel.usingDiamondOperatorPropertyMetaModel); + simpleNameMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(simpleNameMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false); + simpleNameMetaModel.getDeclaredPropertyMetaModels().add(simpleNameMetaModel.identifierPropertyMetaModel); + singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel = new PropertyMetaModel(singleMemberAnnotationExprMetaModel, "memberValue", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + singleMemberAnnotationExprMetaModel.getDeclaredPropertyMetaModels().add(singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel); + superExprMetaModel.classExprPropertyMetaModel = new PropertyMetaModel(superExprMetaModel, "classExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + superExprMetaModel.getDeclaredPropertyMetaModels().add(superExprMetaModel.classExprPropertyMetaModel); + thisExprMetaModel.classExprPropertyMetaModel = new PropertyMetaModel(thisExprMetaModel, "classExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + thisExprMetaModel.getDeclaredPropertyMetaModels().add(thisExprMetaModel.classExprPropertyMetaModel); + typeExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(typeExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + typeExprMetaModel.getDeclaredPropertyMetaModels().add(typeExprMetaModel.typePropertyMetaModel); + unaryExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + unaryExprMetaModel.getDeclaredPropertyMetaModels().add(unaryExprMetaModel.expressionPropertyMetaModel); + unaryExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "operator", com.github.javaparser.ast.expr.UnaryExpr.Operator.class, Optional.empty(), false, false, false, false, false); + unaryExprMetaModel.getDeclaredPropertyMetaModels().add(unaryExprMetaModel.operatorPropertyMetaModel); + unaryExprMetaModel.postfixPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "postfix", boolean.class, Optional.empty(), false, false, false, false, false); + unaryExprMetaModel.getDerivedPropertyMetaModels().add(unaryExprMetaModel.postfixPropertyMetaModel); + unaryExprMetaModel.prefixPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "prefix", boolean.class, Optional.empty(), false, false, false, false, false); + unaryExprMetaModel.getDerivedPropertyMetaModels().add(unaryExprMetaModel.prefixPropertyMetaModel); + variableDeclarationExprMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false); + variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.annotationsPropertyMetaModel); + variableDeclarationExprMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.modifiersPropertyMetaModel); + variableDeclarationExprMetaModel.variablesPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "variables", com.github.javaparser.ast.body.VariableDeclarator.class, Optional.of(variableDeclaratorMetaModel), false, true, true, false, false); + variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.variablesPropertyMetaModel); + variableDeclarationExprMetaModel.maximumCommonTypePropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "maximumCommonType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, false, false, false); + variableDeclarationExprMetaModel.getDerivedPropertyMetaModels().add(variableDeclarationExprMetaModel.maximumCommonTypePropertyMetaModel); + importDeclarationMetaModel.isAsteriskPropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "isAsterisk", boolean.class, Optional.empty(), false, false, false, false, false); + importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.isAsteriskPropertyMetaModel); + importDeclarationMetaModel.isStaticPropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "isStatic", boolean.class, Optional.empty(), false, false, false, false, false); + importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.isStaticPropertyMetaModel); + importDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.namePropertyMetaModel); + assertStmtMetaModel.checkPropertyMetaModel = new PropertyMetaModel(assertStmtMetaModel, "check", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.checkPropertyMetaModel); + assertStmtMetaModel.messagePropertyMetaModel = new PropertyMetaModel(assertStmtMetaModel, "message", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.messagePropertyMetaModel); + blockStmtMetaModel.statementsPropertyMetaModel = new PropertyMetaModel(blockStmtMetaModel, "statements", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, true, false, false); + blockStmtMetaModel.getDeclaredPropertyMetaModels().add(blockStmtMetaModel.statementsPropertyMetaModel); + breakStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(breakStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), true, false, false, false, false); + breakStmtMetaModel.getDeclaredPropertyMetaModels().add(breakStmtMetaModel.labelPropertyMetaModel); + catchClauseMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(catchClauseMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false); + catchClauseMetaModel.getDeclaredPropertyMetaModels().add(catchClauseMetaModel.bodyPropertyMetaModel); + catchClauseMetaModel.parameterPropertyMetaModel = new PropertyMetaModel(catchClauseMetaModel, "parameter", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, false, false, false); + catchClauseMetaModel.getDeclaredPropertyMetaModels().add(catchClauseMetaModel.parameterPropertyMetaModel); + continueStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(continueStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), true, false, false, false, false); + continueStmtMetaModel.getDeclaredPropertyMetaModels().add(continueStmtMetaModel.labelPropertyMetaModel); + doStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.bodyPropertyMetaModel); + doStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.conditionPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "isThis", boolean.class, Optional.empty(), false, false, false, false, false); + explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel); + explicitConstructorInvocationStmtMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + explicitConstructorInvocationStmtMetaModel.getDerivedPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.usingDiamondOperatorPropertyMetaModel); + expressionStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(expressionStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + expressionStmtMetaModel.getDeclaredPropertyMetaModels().add(expressionStmtMetaModel.expressionPropertyMetaModel); + foreachStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.bodyPropertyMetaModel); + foreachStmtMetaModel.iterablePropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "iterable", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.iterablePropertyMetaModel); + foreachStmtMetaModel.variablePropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "variable", com.github.javaparser.ast.expr.VariableDeclarationExpr.class, Optional.of(variableDeclarationExprMetaModel), false, false, false, false, false); + foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.variablePropertyMetaModel); + forStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.bodyPropertyMetaModel); + forStmtMetaModel.comparePropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "compare", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.comparePropertyMetaModel); + forStmtMetaModel.initializationPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "initialization", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.initializationPropertyMetaModel); + forStmtMetaModel.updatePropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "update", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.updatePropertyMetaModel); + ifStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.conditionPropertyMetaModel); + ifStmtMetaModel.elseStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseStmt", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), true, false, false, false, false); + ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.elseStmtPropertyMetaModel); + ifStmtMetaModel.thenStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "thenStmt", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.thenStmtPropertyMetaModel); + ifStmtMetaModel.cascadingIfStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "cascadingIfStmt", boolean.class, Optional.empty(), false, false, false, false, false); + ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.cascadingIfStmtPropertyMetaModel); + ifStmtMetaModel.elseBlockPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseBlock", boolean.class, Optional.empty(), false, false, false, false, false); + ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.elseBlockPropertyMetaModel); + ifStmtMetaModel.elseBranchPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseBranch", boolean.class, Optional.empty(), false, false, false, false, false); + ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.elseBranchPropertyMetaModel); + ifStmtMetaModel.thenBlockPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "thenBlock", boolean.class, Optional.empty(), false, false, false, false, false); + ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.thenBlockPropertyMetaModel); + labeledStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(labeledStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + labeledStmtMetaModel.getDeclaredPropertyMetaModels().add(labeledStmtMetaModel.labelPropertyMetaModel); + labeledStmtMetaModel.statementPropertyMetaModel = new PropertyMetaModel(labeledStmtMetaModel, "statement", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + labeledStmtMetaModel.getDeclaredPropertyMetaModels().add(labeledStmtMetaModel.statementPropertyMetaModel); + returnStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(returnStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + returnStmtMetaModel.getDeclaredPropertyMetaModels().add(returnStmtMetaModel.expressionPropertyMetaModel); + switchEntryStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(switchEntryStmtMetaModel, "label", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false); + switchEntryStmtMetaModel.getDeclaredPropertyMetaModels().add(switchEntryStmtMetaModel.labelPropertyMetaModel); + switchEntryStmtMetaModel.statementsPropertyMetaModel = new PropertyMetaModel(switchEntryStmtMetaModel, "statements", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, true, false, false); + switchEntryStmtMetaModel.getDeclaredPropertyMetaModels().add(switchEntryStmtMetaModel.statementsPropertyMetaModel); + switchStmtMetaModel.entriesPropertyMetaModel = new PropertyMetaModel(switchStmtMetaModel, "entries", com.github.javaparser.ast.stmt.SwitchEntryStmt.class, Optional.of(switchEntryStmtMetaModel), false, false, true, false, false); + switchStmtMetaModel.getDeclaredPropertyMetaModels().add(switchStmtMetaModel.entriesPropertyMetaModel); + switchStmtMetaModel.selectorPropertyMetaModel = new PropertyMetaModel(switchStmtMetaModel, "selector", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + switchStmtMetaModel.getDeclaredPropertyMetaModels().add(switchStmtMetaModel.selectorPropertyMetaModel); + synchronizedStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(synchronizedStmtMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false); + synchronizedStmtMetaModel.getDeclaredPropertyMetaModels().add(synchronizedStmtMetaModel.bodyPropertyMetaModel); + synchronizedStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(synchronizedStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + synchronizedStmtMetaModel.getDeclaredPropertyMetaModels().add(synchronizedStmtMetaModel.expressionPropertyMetaModel); + throwStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(throwStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + throwStmtMetaModel.getDeclaredPropertyMetaModels().add(throwStmtMetaModel.expressionPropertyMetaModel); + tryStmtMetaModel.catchClausesPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "catchClauses", com.github.javaparser.ast.stmt.CatchClause.class, Optional.of(catchClauseMetaModel), false, false, true, false, false); + tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.catchClausesPropertyMetaModel); + tryStmtMetaModel.finallyBlockPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "finallyBlock", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), true, false, false, false, false); + tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.finallyBlockPropertyMetaModel); + tryStmtMetaModel.resourcesPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "resources", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false); + tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.resourcesPropertyMetaModel); + tryStmtMetaModel.tryBlockPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "tryBlock", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false); + tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.tryBlockPropertyMetaModel); + localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel = new PropertyMetaModel(localClassDeclarationStmtMetaModel, "classDeclaration", com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class, Optional.of(classOrInterfaceDeclarationMetaModel), false, false, false, false, false); + localClassDeclarationStmtMetaModel.getDeclaredPropertyMetaModels().add(localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel); + whileStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false); + whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.bodyPropertyMetaModel); + whileStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false); + whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.conditionPropertyMetaModel); + arrayTypeMetaModel.componentTypePropertyMetaModel = new PropertyMetaModel(arrayTypeMetaModel, "componentType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + arrayTypeMetaModel.getDeclaredPropertyMetaModels().add(arrayTypeMetaModel.componentTypePropertyMetaModel); + arrayTypeMetaModel.originPropertyMetaModel = new PropertyMetaModel(arrayTypeMetaModel, "origin", com.github.javaparser.ast.type.ArrayType.Origin.class, Optional.empty(), false, false, false, false, false); + arrayTypeMetaModel.getDeclaredPropertyMetaModels().add(arrayTypeMetaModel.originPropertyMetaModel); + classOrInterfaceTypeMetaModel.namePropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.namePropertyMetaModel); + classOrInterfaceTypeMetaModel.scopePropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "scope", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), true, false, false, false, false); + classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.scopePropertyMetaModel); + classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false); + classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel); + classOrInterfaceTypeMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false); + classOrInterfaceTypeMetaModel.getDerivedPropertyMetaModels().add(classOrInterfaceTypeMetaModel.usingDiamondOperatorPropertyMetaModel); + intersectionTypeMetaModel.elementsPropertyMetaModel = new PropertyMetaModel(intersectionTypeMetaModel, "elements", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, true, true, false, false); + intersectionTypeMetaModel.getDeclaredPropertyMetaModels().add(intersectionTypeMetaModel.elementsPropertyMetaModel); + primitiveTypeMetaModel.typePropertyMetaModel = new PropertyMetaModel(primitiveTypeMetaModel, "type", com.github.javaparser.ast.type.PrimitiveType.Primitive.class, Optional.empty(), false, false, false, false, false); + primitiveTypeMetaModel.getDeclaredPropertyMetaModels().add(primitiveTypeMetaModel.typePropertyMetaModel); + typeParameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(typeParameterMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false); + typeParameterMetaModel.getDeclaredPropertyMetaModels().add(typeParameterMetaModel.namePropertyMetaModel); + typeParameterMetaModel.typeBoundPropertyMetaModel = new PropertyMetaModel(typeParameterMetaModel, "typeBound", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false); + typeParameterMetaModel.getDeclaredPropertyMetaModels().add(typeParameterMetaModel.typeBoundPropertyMetaModel); + unionTypeMetaModel.elementsPropertyMetaModel = new PropertyMetaModel(unionTypeMetaModel, "elements", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, true, true, false, false); + unionTypeMetaModel.getDeclaredPropertyMetaModels().add(unionTypeMetaModel.elementsPropertyMetaModel); + wildcardTypeMetaModel.extendedTypePropertyMetaModel = new PropertyMetaModel(wildcardTypeMetaModel, "extendedType", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), true, false, false, false, false); + wildcardTypeMetaModel.getDeclaredPropertyMetaModels().add(wildcardTypeMetaModel.extendedTypePropertyMetaModel); + wildcardTypeMetaModel.superTypePropertyMetaModel = new PropertyMetaModel(wildcardTypeMetaModel, "superType", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), true, false, false, false, false); + wildcardTypeMetaModel.getDeclaredPropertyMetaModels().add(wildcardTypeMetaModel.superTypePropertyMetaModel); + moduleRequiresStmtMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(moduleRequiresStmtMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false); + moduleRequiresStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleRequiresStmtMetaModel.modifiersPropertyMetaModel); + moduleRequiresStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleRequiresStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + moduleRequiresStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleRequiresStmtMetaModel.namePropertyMetaModel); + moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel = new PropertyMetaModel(moduleExportsStmtMetaModel, "moduleNames", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, true, false, false); + moduleExportsStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel); + moduleExportsStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleExportsStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + moduleExportsStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleExportsStmtMetaModel.namePropertyMetaModel); + moduleProvidesStmtMetaModel.typePropertyMetaModel = new PropertyMetaModel(moduleProvidesStmtMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + moduleProvidesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleProvidesStmtMetaModel.typePropertyMetaModel); + moduleProvidesStmtMetaModel.withTypesPropertyMetaModel = new PropertyMetaModel(moduleProvidesStmtMetaModel, "withTypes", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, true, false, false); + moduleProvidesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleProvidesStmtMetaModel.withTypesPropertyMetaModel); + moduleUsesStmtMetaModel.typePropertyMetaModel = new PropertyMetaModel(moduleUsesStmtMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false); + moduleUsesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleUsesStmtMetaModel.typePropertyMetaModel); + moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel = new PropertyMetaModel(moduleOpensStmtMetaModel, "moduleNames", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, true, false, false); + moduleOpensStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel); + moduleOpensStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleOpensStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false); + moduleOpensStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleOpensStmtMetaModel.namePropertyMetaModel); + } + + public static Optional getNodeMetaModel(Class c) { + for (BaseNodeMetaModel nodeMetaModel : nodeMetaModels) { + if (nodeMetaModel.getTypeNameGenerified().equals(c.getSimpleName())) { + return Optional.of(nodeMetaModel); + } + } + return Optional.empty(); + } + + public static final NodeMetaModel nodeMetaModel = new NodeMetaModel(Optional.empty()); + + public static final BodyDeclarationMetaModel bodyDeclarationMetaModel = new BodyDeclarationMetaModel(Optional.of(nodeMetaModel)); + + public static final CallableDeclarationMetaModel callableDeclarationMetaModel = new CallableDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final StatementMetaModel statementMetaModel = new StatementMetaModel(Optional.of(nodeMetaModel)); + + public static final ExpressionMetaModel expressionMetaModel = new ExpressionMetaModel(Optional.of(nodeMetaModel)); + + public static final TypeMetaModel typeMetaModel = new TypeMetaModel(Optional.of(nodeMetaModel)); + + public static final AnnotationExprMetaModel annotationExprMetaModel = new AnnotationExprMetaModel(Optional.of(expressionMetaModel)); + + public static final TypeDeclarationMetaModel typeDeclarationMetaModel = new TypeDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final ReferenceTypeMetaModel referenceTypeMetaModel = new ReferenceTypeMetaModel(Optional.of(typeMetaModel)); + + public static final LiteralExprMetaModel literalExprMetaModel = new LiteralExprMetaModel(Optional.of(expressionMetaModel)); + + public static final LiteralStringValueExprMetaModel literalStringValueExprMetaModel = new LiteralStringValueExprMetaModel(Optional.of(literalExprMetaModel)); + + public static final StringLiteralExprMetaModel stringLiteralExprMetaModel = new StringLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel)); + + public static final ModuleDeclarationMetaModel moduleDeclarationMetaModel = new ModuleDeclarationMetaModel(Optional.of(nodeMetaModel)); + + public static final ModuleStmtMetaModel moduleStmtMetaModel = new ModuleStmtMetaModel(Optional.of(nodeMetaModel)); + + public static final ArrayCreationLevelMetaModel arrayCreationLevelMetaModel = new ArrayCreationLevelMetaModel(Optional.of(nodeMetaModel)); + + public static final CompilationUnitMetaModel compilationUnitMetaModel = new CompilationUnitMetaModel(Optional.of(nodeMetaModel)); + + public static final PackageDeclarationMetaModel packageDeclarationMetaModel = new PackageDeclarationMetaModel(Optional.of(nodeMetaModel)); + + public static final AnnotationDeclarationMetaModel annotationDeclarationMetaModel = new AnnotationDeclarationMetaModel(Optional.of(typeDeclarationMetaModel)); + + public static final AnnotationMemberDeclarationMetaModel annotationMemberDeclarationMetaModel = new AnnotationMemberDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final ClassOrInterfaceDeclarationMetaModel classOrInterfaceDeclarationMetaModel = new ClassOrInterfaceDeclarationMetaModel(Optional.of(typeDeclarationMetaModel)); + + public static final ConstructorDeclarationMetaModel constructorDeclarationMetaModel = new ConstructorDeclarationMetaModel(Optional.of(callableDeclarationMetaModel)); + + public static final EnumConstantDeclarationMetaModel enumConstantDeclarationMetaModel = new EnumConstantDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final EnumDeclarationMetaModel enumDeclarationMetaModel = new EnumDeclarationMetaModel(Optional.of(typeDeclarationMetaModel)); + + public static final FieldDeclarationMetaModel fieldDeclarationMetaModel = new FieldDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final InitializerDeclarationMetaModel initializerDeclarationMetaModel = new InitializerDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel)); + + public static final MethodDeclarationMetaModel methodDeclarationMetaModel = new MethodDeclarationMetaModel(Optional.of(callableDeclarationMetaModel)); + + public static final ParameterMetaModel parameterMetaModel = new ParameterMetaModel(Optional.of(nodeMetaModel)); + + public static final ReceiverParameterMetaModel receiverParameterMetaModel = new ReceiverParameterMetaModel(Optional.of(nodeMetaModel)); + + public static final VariableDeclaratorMetaModel variableDeclaratorMetaModel = new VariableDeclaratorMetaModel(Optional.of(nodeMetaModel)); + + public static final CommentMetaModel commentMetaModel = new CommentMetaModel(Optional.of(nodeMetaModel)); + + public static final BlockCommentMetaModel blockCommentMetaModel = new BlockCommentMetaModel(Optional.of(commentMetaModel)); + + public static final JavadocCommentMetaModel javadocCommentMetaModel = new JavadocCommentMetaModel(Optional.of(commentMetaModel)); + + public static final LineCommentMetaModel lineCommentMetaModel = new LineCommentMetaModel(Optional.of(commentMetaModel)); + + public static final ArrayAccessExprMetaModel arrayAccessExprMetaModel = new ArrayAccessExprMetaModel(Optional.of(expressionMetaModel)); + + public static final ArrayCreationExprMetaModel arrayCreationExprMetaModel = new ArrayCreationExprMetaModel(Optional.of(expressionMetaModel)); + + public static final ArrayInitializerExprMetaModel arrayInitializerExprMetaModel = new ArrayInitializerExprMetaModel(Optional.of(expressionMetaModel)); + + public static final AssignExprMetaModel assignExprMetaModel = new AssignExprMetaModel(Optional.of(expressionMetaModel)); + + public static final BinaryExprMetaModel binaryExprMetaModel = new BinaryExprMetaModel(Optional.of(expressionMetaModel)); + + public static final BooleanLiteralExprMetaModel booleanLiteralExprMetaModel = new BooleanLiteralExprMetaModel(Optional.of(literalExprMetaModel)); + + public static final CastExprMetaModel castExprMetaModel = new CastExprMetaModel(Optional.of(expressionMetaModel)); + + public static final CharLiteralExprMetaModel charLiteralExprMetaModel = new CharLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel)); + + public static final ClassExprMetaModel classExprMetaModel = new ClassExprMetaModel(Optional.of(expressionMetaModel)); + + public static final ConditionalExprMetaModel conditionalExprMetaModel = new ConditionalExprMetaModel(Optional.of(expressionMetaModel)); + + public static final DoubleLiteralExprMetaModel doubleLiteralExprMetaModel = new DoubleLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel)); + + public static final EnclosedExprMetaModel enclosedExprMetaModel = new EnclosedExprMetaModel(Optional.of(expressionMetaModel)); + + public static final FieldAccessExprMetaModel fieldAccessExprMetaModel = new FieldAccessExprMetaModel(Optional.of(expressionMetaModel)); + + public static final InstanceOfExprMetaModel instanceOfExprMetaModel = new InstanceOfExprMetaModel(Optional.of(expressionMetaModel)); + + public static final IntegerLiteralExprMetaModel integerLiteralExprMetaModel = new IntegerLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel)); + + public static final LambdaExprMetaModel lambdaExprMetaModel = new LambdaExprMetaModel(Optional.of(expressionMetaModel)); + + public static final LongLiteralExprMetaModel longLiteralExprMetaModel = new LongLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel)); + + public static final MarkerAnnotationExprMetaModel markerAnnotationExprMetaModel = new MarkerAnnotationExprMetaModel(Optional.of(annotationExprMetaModel)); + + public static final MemberValuePairMetaModel memberValuePairMetaModel = new MemberValuePairMetaModel(Optional.of(nodeMetaModel)); + + public static final MethodCallExprMetaModel methodCallExprMetaModel = new MethodCallExprMetaModel(Optional.of(expressionMetaModel)); + + public static final MethodReferenceExprMetaModel methodReferenceExprMetaModel = new MethodReferenceExprMetaModel(Optional.of(expressionMetaModel)); + + public static final NameExprMetaModel nameExprMetaModel = new NameExprMetaModel(Optional.of(expressionMetaModel)); + + public static final NameMetaModel nameMetaModel = new NameMetaModel(Optional.of(nodeMetaModel)); + + public static final NormalAnnotationExprMetaModel normalAnnotationExprMetaModel = new NormalAnnotationExprMetaModel(Optional.of(annotationExprMetaModel)); + + public static final NullLiteralExprMetaModel nullLiteralExprMetaModel = new NullLiteralExprMetaModel(Optional.of(literalExprMetaModel)); + + public static final ObjectCreationExprMetaModel objectCreationExprMetaModel = new ObjectCreationExprMetaModel(Optional.of(expressionMetaModel)); + + public static final SimpleNameMetaModel simpleNameMetaModel = new SimpleNameMetaModel(Optional.of(nodeMetaModel)); + + public static final SingleMemberAnnotationExprMetaModel singleMemberAnnotationExprMetaModel = new SingleMemberAnnotationExprMetaModel(Optional.of(annotationExprMetaModel)); + + public static final SuperExprMetaModel superExprMetaModel = new SuperExprMetaModel(Optional.of(expressionMetaModel)); + + public static final ThisExprMetaModel thisExprMetaModel = new ThisExprMetaModel(Optional.of(expressionMetaModel)); + + public static final TypeExprMetaModel typeExprMetaModel = new TypeExprMetaModel(Optional.of(expressionMetaModel)); + + public static final UnaryExprMetaModel unaryExprMetaModel = new UnaryExprMetaModel(Optional.of(expressionMetaModel)); + + public static final VariableDeclarationExprMetaModel variableDeclarationExprMetaModel = new VariableDeclarationExprMetaModel(Optional.of(expressionMetaModel)); + + public static final ImportDeclarationMetaModel importDeclarationMetaModel = new ImportDeclarationMetaModel(Optional.of(nodeMetaModel)); + + public static final AssertStmtMetaModel assertStmtMetaModel = new AssertStmtMetaModel(Optional.of(statementMetaModel)); + + public static final BlockStmtMetaModel blockStmtMetaModel = new BlockStmtMetaModel(Optional.of(statementMetaModel)); + + public static final BreakStmtMetaModel breakStmtMetaModel = new BreakStmtMetaModel(Optional.of(statementMetaModel)); + + public static final CatchClauseMetaModel catchClauseMetaModel = new CatchClauseMetaModel(Optional.of(nodeMetaModel)); + + public static final ContinueStmtMetaModel continueStmtMetaModel = new ContinueStmtMetaModel(Optional.of(statementMetaModel)); + + public static final DoStmtMetaModel doStmtMetaModel = new DoStmtMetaModel(Optional.of(statementMetaModel)); + + public static final EmptyStmtMetaModel emptyStmtMetaModel = new EmptyStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ExplicitConstructorInvocationStmtMetaModel explicitConstructorInvocationStmtMetaModel = new ExplicitConstructorInvocationStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ExpressionStmtMetaModel expressionStmtMetaModel = new ExpressionStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ForeachStmtMetaModel foreachStmtMetaModel = new ForeachStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ForStmtMetaModel forStmtMetaModel = new ForStmtMetaModel(Optional.of(statementMetaModel)); + + public static final IfStmtMetaModel ifStmtMetaModel = new IfStmtMetaModel(Optional.of(statementMetaModel)); + + public static final LabeledStmtMetaModel labeledStmtMetaModel = new LabeledStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ReturnStmtMetaModel returnStmtMetaModel = new ReturnStmtMetaModel(Optional.of(statementMetaModel)); + + public static final SwitchEntryStmtMetaModel switchEntryStmtMetaModel = new SwitchEntryStmtMetaModel(Optional.of(statementMetaModel)); + + public static final SwitchStmtMetaModel switchStmtMetaModel = new SwitchStmtMetaModel(Optional.of(statementMetaModel)); + + public static final SynchronizedStmtMetaModel synchronizedStmtMetaModel = new SynchronizedStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ThrowStmtMetaModel throwStmtMetaModel = new ThrowStmtMetaModel(Optional.of(statementMetaModel)); + + public static final TryStmtMetaModel tryStmtMetaModel = new TryStmtMetaModel(Optional.of(statementMetaModel)); + + public static final LocalClassDeclarationStmtMetaModel localClassDeclarationStmtMetaModel = new LocalClassDeclarationStmtMetaModel(Optional.of(statementMetaModel)); + + public static final WhileStmtMetaModel whileStmtMetaModel = new WhileStmtMetaModel(Optional.of(statementMetaModel)); + + public static final UnparsableStmtMetaModel unparsableStmtMetaModel = new UnparsableStmtMetaModel(Optional.of(statementMetaModel)); + + public static final ArrayTypeMetaModel arrayTypeMetaModel = new ArrayTypeMetaModel(Optional.of(referenceTypeMetaModel)); + + public static final ClassOrInterfaceTypeMetaModel classOrInterfaceTypeMetaModel = new ClassOrInterfaceTypeMetaModel(Optional.of(referenceTypeMetaModel)); + + public static final IntersectionTypeMetaModel intersectionTypeMetaModel = new IntersectionTypeMetaModel(Optional.of(typeMetaModel)); + + public static final PrimitiveTypeMetaModel primitiveTypeMetaModel = new PrimitiveTypeMetaModel(Optional.of(typeMetaModel)); + + public static final TypeParameterMetaModel typeParameterMetaModel = new TypeParameterMetaModel(Optional.of(referenceTypeMetaModel)); + + public static final UnionTypeMetaModel unionTypeMetaModel = new UnionTypeMetaModel(Optional.of(typeMetaModel)); + + public static final UnknownTypeMetaModel unknownTypeMetaModel = new UnknownTypeMetaModel(Optional.of(typeMetaModel)); + + public static final VoidTypeMetaModel voidTypeMetaModel = new VoidTypeMetaModel(Optional.of(typeMetaModel)); + + public static final WildcardTypeMetaModel wildcardTypeMetaModel = new WildcardTypeMetaModel(Optional.of(typeMetaModel)); + + public static final VarTypeMetaModel varTypeMetaModel = new VarTypeMetaModel(Optional.of(typeMetaModel)); + + public static final ModuleRequiresStmtMetaModel moduleRequiresStmtMetaModel = new ModuleRequiresStmtMetaModel(Optional.of(moduleStmtMetaModel)); + + public static final ModuleExportsStmtMetaModel moduleExportsStmtMetaModel = new ModuleExportsStmtMetaModel(Optional.of(moduleStmtMetaModel)); + + public static final ModuleProvidesStmtMetaModel moduleProvidesStmtMetaModel = new ModuleProvidesStmtMetaModel(Optional.of(moduleStmtMetaModel)); + + public static final ModuleUsesStmtMetaModel moduleUsesStmtMetaModel = new ModuleUsesStmtMetaModel(Optional.of(moduleStmtMetaModel)); + + public static final ModuleOpensStmtMetaModel moduleOpensStmtMetaModel = new ModuleOpensStmtMetaModel(Optional.of(moduleStmtMetaModel)); + + static { + initializeNodeMetaModels(); + initializePropertyMetaModels(); + initializeConstructorParameters(); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/JavadocCommentMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/JavadocCommentMetaModel.java new file mode 100644 index 0000000..4da2007 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/JavadocCommentMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class JavadocCommentMetaModel extends CommentMetaModel { + + JavadocCommentMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.JavadocComment.class, "JavadocComment", "com.github.javaparser.ast.comments", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LabeledStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LabeledStmtMetaModel.java new file mode 100644 index 0000000..d8532ef --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LabeledStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class LabeledStmtMetaModel extends StatementMetaModel { + + LabeledStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.LabeledStmt.class, "LabeledStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel labelPropertyMetaModel; + + public PropertyMetaModel statementPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LambdaExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LambdaExprMetaModel.java new file mode 100644 index 0000000..ad50a65 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LambdaExprMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class LambdaExprMetaModel extends ExpressionMetaModel { + + LambdaExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LambdaExpr.class, "LambdaExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel isEnclosingParametersPropertyMetaModel; + + public PropertyMetaModel parametersPropertyMetaModel; + + public PropertyMetaModel expressionBodyPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LineCommentMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LineCommentMetaModel.java new file mode 100644 index 0000000..dfc8bbd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LineCommentMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class LineCommentMetaModel extends CommentMetaModel { + + LineCommentMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.LineComment.class, "LineComment", "com.github.javaparser.ast.comments", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LiteralExprMetaModel.java new file mode 100644 index 0000000..47f9fcd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LiteralExprMetaModel.java @@ -0,0 +1,15 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class LiteralExprMetaModel extends ExpressionMetaModel { + + LiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LiteralExpr.class, "LiteralExpr", "com.github.javaparser.ast.expr", true, false); + } + + protected LiteralExprMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java new file mode 100644 index 0000000..6ed8578 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class LiteralStringValueExprMetaModel extends LiteralExprMetaModel { + + LiteralStringValueExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LiteralStringValueExpr.class, "LiteralStringValueExpr", "com.github.javaparser.ast.expr", true, false); + } + + protected LiteralStringValueExprMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel valuePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java new file mode 100644 index 0000000..d936eb0 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class LocalClassDeclarationStmtMetaModel extends StatementMetaModel { + + LocalClassDeclarationStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.LocalClassDeclarationStmt.class, "LocalClassDeclarationStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel classDeclarationPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java new file mode 100644 index 0000000..42006b5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class LongLiteralExprMetaModel extends LiteralStringValueExprMetaModel { + + LongLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LongLiteralExpr.class, "LongLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java new file mode 100644 index 0000000..0371b51 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class MarkerAnnotationExprMetaModel extends AnnotationExprMetaModel { + + MarkerAnnotationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MarkerAnnotationExpr.class, "MarkerAnnotationExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/MemberValuePairMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/MemberValuePairMetaModel.java new file mode 100644 index 0000000..6521818 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/MemberValuePairMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class MemberValuePairMetaModel extends NodeMetaModel { + + MemberValuePairMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MemberValuePair.class, "MemberValuePair", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel valuePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/MethodCallExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/MethodCallExprMetaModel.java new file mode 100644 index 0000000..728407c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/MethodCallExprMetaModel.java @@ -0,0 +1,20 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class MethodCallExprMetaModel extends ExpressionMetaModel { + + MethodCallExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MethodCallExpr.class, "MethodCallExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel argumentsPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel scopePropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java new file mode 100644 index 0000000..74aaeae --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class MethodDeclarationMetaModel extends CallableDeclarationMetaModel { + + MethodDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.MethodDeclaration.class, "MethodDeclaration", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java new file mode 100644 index 0000000..4968046 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class MethodReferenceExprMetaModel extends ExpressionMetaModel { + + MethodReferenceExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MethodReferenceExpr.class, "MethodReferenceExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel identifierPropertyMetaModel; + + public PropertyMetaModel scopePropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java new file mode 100644 index 0000000..0cf3c3e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleDeclarationMetaModel extends NodeMetaModel { + + ModuleDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleDeclaration.class, "ModuleDeclaration", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel isOpenPropertyMetaModel; + + public PropertyMetaModel moduleStmtsPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java new file mode 100644 index 0000000..7b6af7e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleExportsStmtMetaModel extends ModuleStmtMetaModel { + + ModuleExportsStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleExportsStmt.class, "ModuleExportsStmt", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel moduleNamesPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java new file mode 100644 index 0000000..16a5a48 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleOpensStmtMetaModel extends ModuleStmtMetaModel { + + ModuleOpensStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleOpensStmt.class, "ModuleOpensStmt", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel moduleNamesPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java new file mode 100644 index 0000000..2c3bffc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleProvidesStmtMetaModel extends ModuleStmtMetaModel { + + ModuleProvidesStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleProvidesStmt.class, "ModuleProvidesStmt", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel typePropertyMetaModel; + + public PropertyMetaModel withTypesPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java new file mode 100644 index 0000000..320a811 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleRequiresStmtMetaModel extends ModuleStmtMetaModel { + + ModuleRequiresStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleRequiresStmt.class, "ModuleRequiresStmt", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleStmtMetaModel.java new file mode 100644 index 0000000..63ca214 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleStmtMetaModel.java @@ -0,0 +1,15 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class ModuleStmtMetaModel extends NodeMetaModel { + + ModuleStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleStmt.class, "ModuleStmt", "com.github.javaparser.ast.modules", true, false); + } + + protected ModuleStmtMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java new file mode 100644 index 0000000..bac9043 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ModuleUsesStmtMetaModel extends ModuleStmtMetaModel { + + ModuleUsesStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleUsesStmt.class, "ModuleUsesStmt", "com.github.javaparser.ast.modules", false, false); + } + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NameExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/NameExprMetaModel.java new file mode 100644 index 0000000..bed2961 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NameExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class NameExprMetaModel extends ExpressionMetaModel { + + NameExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NameExpr.class, "NameExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NameMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/NameMetaModel.java new file mode 100644 index 0000000..cd54085 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NameMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class NameMetaModel extends NodeMetaModel { + + NameMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.Name.class, "Name", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel identifierPropertyMetaModel; + + public PropertyMetaModel qualifierPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NodeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/NodeMetaModel.java new file mode 100644 index 0000000..332dfd4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NodeMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class NodeMetaModel extends BaseNodeMetaModel { + + NodeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.Node.class, "Node", "com.github.javaparser.ast", true, false); + } + + protected NodeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel commentPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NonEmptyProperty.java b/JavaParser/src/com/github/javaparser/metamodel/NonEmptyProperty.java new file mode 100644 index 0000000..7be7fdc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NonEmptyProperty.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicate that leaving this property empty does not lead to a correct AST. + * Empty means either empty string or empty collection. + * (Used during generation of the meta model.) + */ +@Retention(RUNTIME) +@Target({FIELD, METHOD}) +public @interface NonEmptyProperty { +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java new file mode 100644 index 0000000..a88a777 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class NormalAnnotationExprMetaModel extends AnnotationExprMetaModel { + + NormalAnnotationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NormalAnnotationExpr.class, "NormalAnnotationExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel pairsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java new file mode 100644 index 0000000..698fb30 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class NullLiteralExprMetaModel extends LiteralExprMetaModel { + + NullLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NullLiteralExpr.class, "NullLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java new file mode 100644 index 0000000..4149d1d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java @@ -0,0 +1,22 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ObjectCreationExprMetaModel extends ExpressionMetaModel { + + ObjectCreationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ObjectCreationExpr.class, "ObjectCreationExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel anonymousClassBodyPropertyMetaModel; + + public PropertyMetaModel argumentsPropertyMetaModel; + + public PropertyMetaModel scopePropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; + + public PropertyMetaModel typeArgumentsPropertyMetaModel; + + public PropertyMetaModel usingDiamondOperatorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/OptionalProperty.java b/JavaParser/src/com/github/javaparser/metamodel/OptionalProperty.java new file mode 100644 index 0000000..5052e3b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/OptionalProperty.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicate an optional property of a Node. + * (Used during generation of the meta model.) + */ +@Retention(RUNTIME) +@Target(FIELD) +public @interface OptionalProperty { +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java new file mode 100644 index 0000000..3ae52b4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class PackageDeclarationMetaModel extends NodeMetaModel { + + PackageDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.PackageDeclaration.class, "PackageDeclaration", "com.github.javaparser.ast", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ParameterMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ParameterMetaModel.java new file mode 100644 index 0000000..034b5c7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ParameterMetaModel.java @@ -0,0 +1,22 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ParameterMetaModel extends NodeMetaModel { + + ParameterMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.Parameter.class, "Parameter", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel isVarArgsPropertyMetaModel; + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; + + public PropertyMetaModel varArgsAnnotationsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java new file mode 100644 index 0000000..71ee28c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class PrimitiveTypeMetaModel extends TypeMetaModel { + + PrimitiveTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.PrimitiveType.class, "PrimitiveType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/PropertyMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/PropertyMetaModel.java new file mode 100644 index 0000000..5dcf4af --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/PropertyMetaModel.java @@ -0,0 +1,248 @@ +package com.github.javaparser.metamodel; + +import com.github.javaparser.ast.Node; + +import java.lang.reflect.Field; +import java.util.Optional; + +import static com.github.javaparser.utils.CodeGenerationUtils.getterName; +import static com.github.javaparser.utils.CodeGenerationUtils.setterName; + +/** + * Meta-data about a property of a node in the AST. + */ +public class PropertyMetaModel { + private final BaseNodeMetaModel containingNodeMetaModel; + private final String name; + private final Class type; + private final Optional nodeReference; + private final boolean isOptional; + private final boolean isNonEmpty; + private final boolean isNodeList; + private final boolean isEnumSet; + private final boolean hasWildcard; + + public PropertyMetaModel(BaseNodeMetaModel containingNodeMetaModel, String name, Class type, Optional nodeReference, boolean isOptional, boolean isNonEmpty, boolean isNodeList, boolean isEnumSet, boolean hasWildcard) { + this.containingNodeMetaModel = containingNodeMetaModel; + this.name = name; + this.type = type; + this.nodeReference = nodeReference; + this.isOptional = isOptional; + this.isNonEmpty = isNonEmpty; + this.isNodeList = isNodeList; + this.isEnumSet = isEnumSet; + this.hasWildcard = hasWildcard; + } + + /** + * @return is this the field fieldName on class c? + */ + public boolean is(Class c, String fieldName) { + return containingNodeMetaModel.is(c) && name.equals(fieldName); + } + + /** + * @return is this fields called fieldName? + */ + public boolean is(String fieldName) { + return name.equals(fieldName); + } + + /** + * @return the name used in the AST for the setter + */ + public String getSetterMethodName() { + return setterName(name); + } + + /** + * @return the name used in the AST for the getter + */ + public String getGetterMethodName() { + return getterName(type, name); + } + + /** + * @return the NodeMetaModel that "has" this property. + */ + public BaseNodeMetaModel getContainingNodeMetaModel() { + return containingNodeMetaModel; + } + + /** + * @return the name of the property. This is equal to the name of the field in the AST. + */ + public String getName() { + return name; + } + + /** + * @return if this property is a String or a NodeList: whether it may be empty. + */ + public boolean isNonEmpty() { + return isNonEmpty; + } + + /** + * @return the class of the field. + */ + public Class getType() { + return type; + } + + /** + * @return if this property is a Node, this will get the node meta model. + */ + public Optional getNodeReference() { + return nodeReference; + } + + /** + * @return whether this property is optional. + */ + public boolean isOptional() { + return isOptional; + } + + /** + * @return whether this property is not optional. + */ + public boolean isRequired() { + return !isOptional; + } + + /** + * @return whether this property is contained in a NodeList. + */ + public boolean isNodeList() { + return isNodeList; + } + + /** + * @return whether this property is contained in an EnumSet. + */ + public boolean isEnumSet() { + return isEnumSet; + } + + /** + * @return whether this property has a wildcard following it, like BodyDeclaration<?>. + */ + public boolean hasWildcard() { + return hasWildcard; + } + + /** + * @return whether this property is not a list or set. + */ + public boolean isSingular() { + return !(isNodeList || isEnumSet); + } + + @Override + public String toString() { + return "(" + getTypeName() + ")\t" + containingNodeMetaModel + "#" + name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PropertyMetaModel that = (PropertyMetaModel) o; + + if (!name.equals(that.name)) return false; + if (!type.equals(that.type)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + type.hashCode(); + return result; + } + + /** + * @return the type of a single element of this property, so no Optional or NodeList or EnumSet. + */ + public String getTypeNameGenerified() { + if (hasWildcard) { + return getTypeName() + ""; + } + return getTypeName(); + } + + /** + * @return the raw type of a single element of this property, so nothing but the name. + */ + public String getTypeName() { + return type.getSimpleName(); + } + + /** + * @return the type that is returned from getters in the AST. + */ + public String getTypeNameForGetter() { + if (isOptional) { + return "Optional<" + getTypeNameForSetter() + ">"; + } + return getTypeNameForSetter(); + } + + /** + * @return the type that is passed to setters in the AST. + */ + public String getTypeNameForSetter() { + if (isNodeList) { + return "NodeList<" + getTypeNameGenerified() + ">"; + } + if (isEnumSet) { + return "EnumSet<" + getTypeNameGenerified() + ">"; + } + return getTypeNameGenerified(); + } + + /** + * @return is this property an AST Node? + */ + public boolean isNode() { + return getNodeReference().isPresent(); + } + + /** + * The name of the field in the containing BaseNodeMetaModel for this property meta model. + */ + public String getMetaModelFieldName() { + return getName() + "PropertyMetaModel"; + } + + /** + * @return is this property an attribute, meaning: not a node? + */ + public boolean isAttribute() { + return !isNode(); + } + + /** + * Introspects the node to get the value from this field. + * Note that an optional empty field will return null here. + */ + public Object getValue(Node node) { + try { + for (Class c = node.getClass(); c != null; c = c.getSuperclass()) { + Field[] fields = c.getDeclaredFields(); + for (Field classField : fields) { + if (classField.getName().equals(getName())) { + classField.setAccessible(true); + return classField.get(node); + } + } + } + throw new NoSuchFieldError(getName()); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java new file mode 100644 index 0000000..e0fb463 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ReceiverParameterMetaModel extends NodeMetaModel { + + ReceiverParameterMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ReceiverParameter.class, "ReceiverParameter", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java new file mode 100644 index 0000000..fa0361b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java @@ -0,0 +1,15 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class ReferenceTypeMetaModel extends TypeMetaModel { + + ReferenceTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ReferenceType.class, "ReferenceType", "com.github.javaparser.ast.type", true, false); + } + + protected ReferenceTypeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ReturnStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ReturnStmtMetaModel.java new file mode 100644 index 0000000..27af5ec --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ReturnStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ReturnStmtMetaModel extends StatementMetaModel { + + ReturnStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ReturnStmt.class, "ReturnStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SimpleNameMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SimpleNameMetaModel.java new file mode 100644 index 0000000..1c04296 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SimpleNameMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SimpleNameMetaModel extends NodeMetaModel { + + SimpleNameMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SimpleName.class, "SimpleName", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel identifierPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java new file mode 100644 index 0000000..a5223cd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SingleMemberAnnotationExprMetaModel extends AnnotationExprMetaModel { + + SingleMemberAnnotationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SingleMemberAnnotationExpr.class, "SingleMemberAnnotationExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel memberValuePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/StatementMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/StatementMetaModel.java new file mode 100644 index 0000000..8433ab0 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/StatementMetaModel.java @@ -0,0 +1,15 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class StatementMetaModel extends NodeMetaModel { + + StatementMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.Statement.class, "Statement", "com.github.javaparser.ast.stmt", true, false); + } + + protected StatementMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java new file mode 100644 index 0000000..1dc0acf --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class StringLiteralExprMetaModel extends LiteralStringValueExprMetaModel { + + StringLiteralExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.StringLiteralExpr.class, "StringLiteralExpr", "com.github.javaparser.ast.expr", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SuperExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SuperExprMetaModel.java new file mode 100644 index 0000000..745df8b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SuperExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SuperExprMetaModel extends ExpressionMetaModel { + + SuperExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SuperExpr.class, "SuperExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel classExprPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java new file mode 100644 index 0000000..b8e6252 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SwitchEntryStmtMetaModel extends StatementMetaModel { + + SwitchEntryStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SwitchEntryStmt.class, "SwitchEntryStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel labelPropertyMetaModel; + + public PropertyMetaModel statementsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SwitchStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SwitchStmtMetaModel.java new file mode 100644 index 0000000..dc9df0e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SwitchStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SwitchStmtMetaModel extends StatementMetaModel { + + SwitchStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SwitchStmt.class, "SwitchStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel entriesPropertyMetaModel; + + public PropertyMetaModel selectorPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java new file mode 100644 index 0000000..01a8709 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class SynchronizedStmtMetaModel extends StatementMetaModel { + + SynchronizedStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SynchronizedStmt.class, "SynchronizedStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel expressionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ThisExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ThisExprMetaModel.java new file mode 100644 index 0000000..fbfd5a5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ThisExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ThisExprMetaModel extends ExpressionMetaModel { + + ThisExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ThisExpr.class, "ThisExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel classExprPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/ThrowStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/ThrowStmtMetaModel.java new file mode 100644 index 0000000..c5bd2e1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/ThrowStmtMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class ThrowStmtMetaModel extends StatementMetaModel { + + ThrowStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ThrowStmt.class, "ThrowStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/TryStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/TryStmtMetaModel.java new file mode 100644 index 0000000..28756db --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/TryStmtMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class TryStmtMetaModel extends StatementMetaModel { + + TryStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.TryStmt.class, "TryStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel catchClausesPropertyMetaModel; + + public PropertyMetaModel finallyBlockPropertyMetaModel; + + public PropertyMetaModel resourcesPropertyMetaModel; + + public PropertyMetaModel tryBlockPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java new file mode 100644 index 0000000..f7f0d00 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java @@ -0,0 +1,21 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class TypeDeclarationMetaModel extends BodyDeclarationMetaModel { + + TypeDeclarationMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.TypeDeclaration.class, "TypeDeclaration", "com.github.javaparser.ast.body", true, true); + } + + protected TypeDeclarationMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel membersPropertyMetaModel; + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/TypeExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/TypeExprMetaModel.java new file mode 100644 index 0000000..8d0b90d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/TypeExprMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class TypeExprMetaModel extends ExpressionMetaModel { + + TypeExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.TypeExpr.class, "TypeExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/TypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/TypeMetaModel.java new file mode 100644 index 0000000..76b084b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/TypeMetaModel.java @@ -0,0 +1,17 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; +import com.github.javaparser.ast.Node; + +public class TypeMetaModel extends NodeMetaModel { + + TypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.Type.class, "Type", "com.github.javaparser.ast.type", true, false); + } + + protected TypeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { + super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard); + } + + public PropertyMetaModel annotationsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/TypeParameterMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/TypeParameterMetaModel.java new file mode 100644 index 0000000..2e87402 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/TypeParameterMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class TypeParameterMetaModel extends ReferenceTypeMetaModel { + + TypeParameterMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.TypeParameter.class, "TypeParameter", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel typeBoundPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/UnaryExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/UnaryExprMetaModel.java new file mode 100644 index 0000000..309af9a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/UnaryExprMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class UnaryExprMetaModel extends ExpressionMetaModel { + + UnaryExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.UnaryExpr.class, "UnaryExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel expressionPropertyMetaModel; + + public PropertyMetaModel operatorPropertyMetaModel; + + public PropertyMetaModel postfixPropertyMetaModel; + + public PropertyMetaModel prefixPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/UnionTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/UnionTypeMetaModel.java new file mode 100644 index 0000000..14e81be --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/UnionTypeMetaModel.java @@ -0,0 +1,12 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class UnionTypeMetaModel extends TypeMetaModel { + + UnionTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.UnionType.class, "UnionType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel elementsPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/UnknownTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/UnknownTypeMetaModel.java new file mode 100644 index 0000000..d83518b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/UnknownTypeMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class UnknownTypeMetaModel extends TypeMetaModel { + + UnknownTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.UnknownType.class, "UnknownType", "com.github.javaparser.ast.type", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java new file mode 100644 index 0000000..7d18f74 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class UnparsableStmtMetaModel extends StatementMetaModel { + + UnparsableStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.UnparsableStmt.class, "UnparsableStmt", "com.github.javaparser.ast.stmt", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/VarTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/VarTypeMetaModel.java new file mode 100644 index 0000000..1ada830 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/VarTypeMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class VarTypeMetaModel extends TypeMetaModel { + + VarTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.VarType.class, "VarType", "com.github.javaparser.ast.type", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java new file mode 100644 index 0000000..c9c30c0 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java @@ -0,0 +1,18 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class VariableDeclarationExprMetaModel extends ExpressionMetaModel { + + VariableDeclarationExprMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.VariableDeclarationExpr.class, "VariableDeclarationExpr", "com.github.javaparser.ast.expr", false, false); + } + + public PropertyMetaModel annotationsPropertyMetaModel; + + public PropertyMetaModel modifiersPropertyMetaModel; + + public PropertyMetaModel variablesPropertyMetaModel; + + public PropertyMetaModel maximumCommonTypePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java new file mode 100644 index 0000000..83f12ac --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java @@ -0,0 +1,16 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class VariableDeclaratorMetaModel extends NodeMetaModel { + + VariableDeclaratorMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.body.VariableDeclarator.class, "VariableDeclarator", "com.github.javaparser.ast.body", false, false); + } + + public PropertyMetaModel initializerPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel typePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/VoidTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/VoidTypeMetaModel.java new file mode 100644 index 0000000..bb92f56 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/VoidTypeMetaModel.java @@ -0,0 +1,10 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class VoidTypeMetaModel extends TypeMetaModel { + + VoidTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.VoidType.class, "VoidType", "com.github.javaparser.ast.type", false, false); + } +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/WhileStmtMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/WhileStmtMetaModel.java new file mode 100644 index 0000000..83a122d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/WhileStmtMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class WhileStmtMetaModel extends StatementMetaModel { + + WhileStmtMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.WhileStmt.class, "WhileStmt", "com.github.javaparser.ast.stmt", false, false); + } + + public PropertyMetaModel bodyPropertyMetaModel; + + public PropertyMetaModel conditionPropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/metamodel/WildcardTypeMetaModel.java b/JavaParser/src/com/github/javaparser/metamodel/WildcardTypeMetaModel.java new file mode 100644 index 0000000..0d4b9fc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/metamodel/WildcardTypeMetaModel.java @@ -0,0 +1,14 @@ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +public class WildcardTypeMetaModel extends TypeMetaModel { + + WildcardTypeMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, com.github.javaparser.ast.type.WildcardType.class, "WildcardType", "com.github.javaparser.ast.type", false, false); + } + + public PropertyMetaModel extendedTypePropertyMetaModel; + + public PropertyMetaModel superTypePropertyMetaModel; +} diff --git a/JavaParser/src/com/github/javaparser/printer/ConcreteSyntaxModel.java b/JavaParser/src/com/github/javaparser/printer/ConcreteSyntaxModel.java new file mode 100644 index 0000000..e45ed75 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/ConcreteSyntaxModel.java @@ -0,0 +1,953 @@ +/* + * 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.printer; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.printer.concretesyntaxmodel.CsmConditional; +import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; +import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.ast.observer.ObservableProperty.*; +import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.*; +import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.*; +import static com.github.javaparser.utils.Utils.EOL; + +/** + * The Concrete Syntax Model for a single node type. It knows the syntax used to represent a certain element in Java + * code. + */ +public class ConcreteSyntaxModel { + + private static final Map concreteSyntaxModelByClass = new HashMap<>(); + private static Optional initializationError; + + private static CsmElement modifiers() { + return list(ObservableProperty.MODIFIERS, space(), none(), space()); + } + + /** + * Build a mix collecting all the elements specified. + */ + private static CsmElement mix(CsmElement... elements) { + return new CsmMix(Arrays.asList(elements)); + } + + private static CsmElement memberAnnotations() { + return list(ObservableProperty.ANNOTATIONS, newline(), none(), newline()); + } + + private static CsmElement annotations() { + return list(ObservableProperty.ANNOTATIONS, space(), none(), newline()); + } + + private static CsmElement typeParameters() { + return list(ObservableProperty.TYPE_PARAMETERS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(GeneratedJavaParserConstants.LT), + CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.GT), CsmElement.space())); + } + + private static CsmElement typeArguments() { + return list(ObservableProperty.TYPE_ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(GeneratedJavaParserConstants.LT), + CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.GT))); + } + + static { + + /// + /// Body + /// + + concreteSyntaxModelByClass.put(AnnotationDeclaration.class, CsmElement.sequence( + CsmElement.comment(), + memberAnnotations(), + modifiers(), + CsmElement.token(GeneratedJavaParserConstants.AT), + CsmElement.token(GeneratedJavaParserConstants.INTERFACE), + CsmElement.space(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.space(), + CsmElement.token(LBRACE), + CsmElement.newline(), + CsmElement.indent(), + CsmElement.list(ObservableProperty.MEMBERS, CsmElement.newline(), CsmElement.none(), CsmElement.none(), CsmElement.newline()), + CsmElement.unindent(), + CsmElement.token(RBRACE) + )); + + concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, CsmElement.sequence( + CsmElement.comment(), + memberAnnotations(), + modifiers(), + CsmElement.child(ObservableProperty.TYPE), + CsmElement.space(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.token(LPAREN), + CsmElement.token(RPAREN), + CsmElement.conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants._DEFAULT), CsmElement.space(), CsmElement.child(DEFAULT_VALUE))), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, newline(), none(), newline()), + modifiers(), + conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), + space(), + child(ObservableProperty.NAME), + list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), + list(ObservableProperty.EXTENDED_TYPES, + sequence(string(GeneratedJavaParserConstants.COMMA), space()), + sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), + none()), + list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence( + space(), + token(GeneratedJavaParserConstants.IMPLEMENTS), + space()), none()), + space(), + block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), CsmElement.newline(), newline()))) + )); + + concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence( + comment(), + memberAnnotations(), + modifiers(), + typeParameters(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence( + comment(), + memberAnnotations(), + child(ObservableProperty.NAME), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), + conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), CsmElement.newline(), CsmElement.indent(), CsmElement.newline(), + list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), CsmElement.newline()), + unindent(), + token(RBRACE), CsmElement.newline())) + )); + + concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence( + comment(), + annotations(), + modifiers(), + token(GeneratedJavaParserConstants.ENUM), + space(), + child(ObservableProperty.NAME), + list(ObservableProperty.IMPLEMENTED_TYPES, + sequence(comma(), space()), + sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), + none()), + space(), + token(GeneratedJavaParserConstants.LBRACE), + CsmElement.newline(), + CsmElement.indent(), + CsmElement.newline(), + list(ObservableProperty.ENTRIES, + sequence(comma(), space()), + CsmElement.none(), + none()), + conditional(ObservableProperty.MEMBERS, IS_EMPTY, + conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), + sequence(CsmElement.semicolon(), newline(), CsmElement.newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), CsmElement.newline()))), + unindent(), + token(RBRACE) + )); + + concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence( + orphanCommentsBeforeThis(), + comment(), + annotations(), + modifiers(), + conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), + space(), + list(ObservableProperty.VARIABLES, sequence(comma(), space())), + semicolon())); + + concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence( + comment(), + conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), + child(ObservableProperty.BODY))); + + concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence( + orphanCommentsBeforeThis(), + comment(), + mix(memberAnnotations(), modifiers()), + typeParameters(), + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), + list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), + conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()) + )); + + concreteSyntaxModelByClass.put(Parameter.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()), + modifiers(), + child(ObservableProperty.TYPE), + conditional(ObservableProperty.VAR_ARGS, FLAG, CsmElement.sequence( + list(ObservableProperty.VAR_ARGS_ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.none()), + token(GeneratedJavaParserConstants.ELLIPSIS))), + space(), + child(ObservableProperty.NAME))); + + concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()), + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME))); + + concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence( + comment(), + child(ObservableProperty.NAME), + // FIXME: we should introduce a derived property + // list(ObservableProperty.EXTRA_ARRAY_LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), + child(ObservableProperty.INITIALIZER))) + )); + + /// + /// Expressions + /// + + concreteSyntaxModelByClass.put(ArrayAccessExpr.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.token(GeneratedJavaParserConstants.LBRACKET), + CsmElement.child(ObservableProperty.INDEX), + CsmElement.token(GeneratedJavaParserConstants.RBRACKET) + )); + + concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.NEW), + space(), + CsmElement.child(ObservableProperty.ELEMENT_TYPE), + list(ObservableProperty.LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))) + )); + + concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LBRACE), + list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), + orphanCommentsEnding(), + token(RBRACE))); + + concreteSyntaxModelByClass.put(AssignExpr.class, sequence( + comment(), + child(ObservableProperty.TARGET), + space(), + attribute(ObservableProperty.OPERATOR), + space(), + child(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(BinaryExpr.class, sequence( + comment(), + child(ObservableProperty.LEFT), + space(), + attribute(ObservableProperty.OPERATOR), + space(), + child(ObservableProperty.RIGHT) + )); + + concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence( + comment(), attribute(VALUE) + )); + + concreteSyntaxModelByClass.put(CastExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.TYPE), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.EXPRESSION) + )); + + concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence( + comment(), + charToken(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(ClassExpr.class, sequence( + comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); + + concreteSyntaxModelByClass.put(ConditionalExpr.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.child(ObservableProperty.CONDITION), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.HOOK), + CsmElement.space(), + CsmElement.child(ObservableProperty.THEN_EXPR), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.COLON), + CsmElement.space(), + CsmElement.child(ObservableProperty.ELSE_EXPR) + )); + + concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.INNER), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(FieldAccessExpr.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.child(SCOPE), + CsmElement.token(GeneratedJavaParserConstants.DOT), + child(ObservableProperty.NAME) + )); + + concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence( + comment(), + child(ObservableProperty.EXPRESSION), + space(), + token(GeneratedJavaParserConstants.INSTANCEOF), + space(), + child(ObservableProperty.TYPE) + )); + + concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(LambdaExpr.class, sequence( + comment(), + conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), + list(ObservableProperty.PARAMETERS, sequence(comma(), space())), + conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), + space(), + token(GeneratedJavaParserConstants.ARROW), + space(), + conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)) + )); + + concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(MarkerAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), attribute(ObservableProperty.NAME))); + + concreteSyntaxModelByClass.put(MemberValuePair.class, CsmElement.sequence(CsmElement.comment(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.ASSIGN), + CsmElement.space(), + CsmElement.child(ObservableProperty.VALUE))); + + concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence( + comment(), + conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), + typeArguments(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence( + comment(), + child(ObservableProperty.SCOPE), + token(GeneratedJavaParserConstants.DOUBLECOLON), + typeArguments(), + attribute(ObservableProperty.IDENTIFIER) + )); + + concreteSyntaxModelByClass.put(Name.class, sequence( + comment(), + conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), + list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()), + attribute(ObservableProperty.IDENTIFIER), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(NameExpr.class, sequence( + comment(), + child(ObservableProperty.NAME), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.AT), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.PAIRS, sequence(comma(), space())), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.NULL) + )); + + concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence( + comment(), + conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), + token(GeneratedJavaParserConstants.NEW), + space(), + list(ObservableProperty.TYPE_ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(LT), CsmElement.token(GT)), + conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), + child(ObservableProperty.TYPE), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, + CsmElement.sequence( + CsmElement.space(), CsmElement.token(LBRACE), CsmElement.newline(), CsmElement.indent(), + CsmElement.list(ObservableProperty.ANONYMOUS_CLASS_BODY, + CsmElement.newline(), + CsmElement.newline(), + CsmElement.newline(), + CsmElement.newline()), + CsmElement.unindent(), + CsmElement.token(RBRACE) + )) + )); + + concreteSyntaxModelByClass.put(SimpleName.class, attribute(ObservableProperty.IDENTIFIER)); + + concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.AT), + CsmElement.child(ObservableProperty.NAME), + CsmElement.token(GeneratedJavaParserConstants.LPAREN), + CsmElement.child(ObservableProperty.MEMBER_VALUE), + CsmElement.token(GeneratedJavaParserConstants.RPAREN))); + + concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence( + comment(), + stringToken(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(SuperExpr.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.conditional(ObservableProperty.CLASS_EXPR, IS_PRESENT, CsmElement.sequence(CsmElement.child(ObservableProperty.CLASS_EXPR), CsmElement.token(GeneratedJavaParserConstants.DOT))), + CsmElement.token(GeneratedJavaParserConstants.SUPER) + )); + + concreteSyntaxModelByClass.put(ThisExpr.class, sequence( + comment(), + conditional(ObservableProperty.CLASS_EXPR, IS_PRESENT, sequence(child(CLASS_EXPR), token(GeneratedJavaParserConstants.DOT))), + token(GeneratedJavaParserConstants.THIS) + )); + + concreteSyntaxModelByClass.put(TypeExpr.class, sequence( + comment(), + child(ObservableProperty.TYPE) + )); + + concreteSyntaxModelByClass.put(UnaryExpr.class, sequence( + conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), + child(ObservableProperty.EXPRESSION), + conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)) + )); + + concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()), + modifiers(), + child(ObservableProperty.MAXIMUM_COMMON_TYPE), + space(), + list(ObservableProperty.VARIABLES, sequence(comma(), space())) + )); + + /// + /// Statements + /// + + concreteSyntaxModelByClass.put(AssertStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.ASSERT), + CsmElement.space(), + CsmElement.child(ObservableProperty.CHECK), + CsmElement.conditional(ObservableProperty.MESSAGE, IS_PRESENT, CsmElement.sequence( + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.COLON), + CsmElement.space(), + CsmElement.child(ObservableProperty.MESSAGE) + )), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(BlockStmt.class, sequence( + orphanCommentsBeforeThis(), + comment(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), + orphanCommentsEnding(), + token(RBRACE) + )); + + concreteSyntaxModelByClass.put(BreakStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.BREAK), + CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.child(ObservableProperty.LABEL))), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(CatchClause.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.CATCH), + CsmElement.space(), + CsmElement.token(LPAREN), + CsmElement.child(ObservableProperty.PARAMETER), + CsmElement.token(RPAREN), + CsmElement.space(), + CsmElement.child(BODY) + )); + + concreteSyntaxModelByClass.put(ContinueStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.CONTINUE), + CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.child(ObservableProperty.LABEL))), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(DoStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.DO), + CsmElement.space(), + CsmElement.child(ObservableProperty.BODY), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.WHILE), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + CsmElement.token(GeneratedJavaParserConstants.RPAREN), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(EmptyStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.SEMICOLON) + )); + + concreteSyntaxModelByClass.put(UnparsableStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.SEMICOLON) + )); + + concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.conditional(ObservableProperty.THIS, FLAG, + CsmElement.sequence(typeArguments(), CsmElement.token(GeneratedJavaParserConstants.THIS)), + CsmElement.sequence( + CsmElement.conditional(ObservableProperty.EXPRESSION, IS_PRESENT, CsmElement.sequence(CsmElement.child(ObservableProperty.EXPRESSION), CsmElement.token(GeneratedJavaParserConstants.DOT))), + typeArguments(), + CsmElement.token(GeneratedJavaParserConstants.SUPER) + )), + CsmElement.token(GeneratedJavaParserConstants.LPAREN), + CsmElement.list(ObservableProperty.ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space())), + CsmElement.token(GeneratedJavaParserConstants.RPAREN), + CsmElement.semicolon() + )); + + concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence( + orphanCommentsBeforeThis(), + comment(), + child(ObservableProperty.EXPRESSION), + semicolon() + )); + + concreteSyntaxModelByClass.put(ForeachStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.FOR), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.VARIABLE), + space(), + token(GeneratedJavaParserConstants.COLON), + space(), + child(ObservableProperty.ITERABLE), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(ForStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.FOR), + space(), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), + semicolon(), + space(), + child(ObservableProperty.COMPARE), + semicolon(), + space(), + list(ObservableProperty.UPDATE, sequence(comma(), space())), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(IfStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.IF), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + token(GeneratedJavaParserConstants.RPAREN), + conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, + sequence(space(), child(ObservableProperty.THEN_STMT), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), + sequence(newline(), CsmElement.indent(), child(ObservableProperty.THEN_STMT), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), + unindent())), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, + sequence(token(GeneratedJavaParserConstants.ELSE), + conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, + sequence(space(), child(ObservableProperty.ELSE_STMT)), + sequence(newline(), CsmElement.indent(), child(ObservableProperty.ELSE_STMT), unindent())))) + )); + + concreteSyntaxModelByClass.put(LabeledStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.child(ObservableProperty.LABEL), + CsmElement.token(GeneratedJavaParserConstants.COLON), + CsmElement.space(), + child(ObservableProperty.STATEMENT) + )); + + concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.child(ObservableProperty.CLASS_DECLARATION) + )); + + concreteSyntaxModelByClass.put(ReturnStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.RETURN), + conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), + semicolon())); + + concreteSyntaxModelByClass.put(SwitchEntryStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT, + CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.CASE), CsmElement.space(), CsmElement.child(ObservableProperty.LABEL), CsmElement.token(GeneratedJavaParserConstants.COLON)), + CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants._DEFAULT), CsmElement.token(GeneratedJavaParserConstants.COLON))), + CsmElement.newline(), + CsmElement.indent(), + CsmElement.list(ObservableProperty.STATEMENTS, CsmElement.newline(), CsmElement.none(), CsmElement.newline()), + CsmElement.unindent() + )); + + concreteSyntaxModelByClass.put(SwitchStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.SWITCH), + CsmElement.token(GeneratedJavaParserConstants.LPAREN), + CsmElement.child(ObservableProperty.SELECTOR), + CsmElement.token(GeneratedJavaParserConstants.RPAREN), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.LBRACE), + CsmElement.newline(), + CsmElement.list(ObservableProperty.ENTRIES, CsmElement.none(), CsmElement.indent(), CsmElement.unindent()), + CsmElement.token(GeneratedJavaParserConstants.RBRACE) + )); + + concreteSyntaxModelByClass.put(SynchronizedStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.SYNCHRONIZED), + CsmElement.space(), + CsmElement.token(LPAREN), + CsmElement.child(EXPRESSION), + CsmElement.token(RPAREN), + CsmElement.space(), + CsmElement.child(BODY) + )); + + concreteSyntaxModelByClass.put(ThrowStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.THROW), + space(), + child(ObservableProperty.EXPRESSION), + semicolon() + )); + + concreteSyntaxModelByClass.put(TryStmt.class, CsmElement.sequence( + CsmElement.comment(), + CsmElement.token(GeneratedJavaParserConstants.TRY), + CsmElement.space(), + CsmElement.conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, CsmElement.sequence( + CsmElement.token(LPAREN), + list(ObservableProperty.RESOURCES, CsmElement.sequence(CsmElement.semicolon(), CsmElement.newline()), CsmElement.indent(), CsmElement.unindent()), + CsmElement.token(RPAREN), + CsmElement.space())), + CsmElement.child(ObservableProperty.TRY_BLOCK), + CsmElement.list(ObservableProperty.CATCH_CLAUSES), + CsmElement.conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.FINALLY), CsmElement.space(), CsmElement.child(ObservableProperty.FINALLY_BLOCK))) + )); + + concreteSyntaxModelByClass.put(WhileStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.WHILE), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + /// + /// Types + /// + + concreteSyntaxModelByClass.put(ArrayType.class, sequence( + child(ObservableProperty.COMPONENT_TYPE), + list(ObservableProperty.ANNOTATIONS), + string(GeneratedJavaParserConstants.LBRACKET), + string(GeneratedJavaParserConstants.RBRACKET))); + + concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), + conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), + list(ANNOTATIONS, space()), + child(NAME), + conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, + sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), + list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); + + concreteSyntaxModelByClass.put(IntersectionType.class, CsmElement.sequence( + CsmElement.comment(), + annotations(), + CsmElement.list(ObservableProperty.ELEMENTS, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.BIT_AND), CsmElement.space())))); + + concreteSyntaxModelByClass.put(PrimitiveType.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS), + attribute(ObservableProperty.TYPE))); + + concreteSyntaxModelByClass.put(TypeParameter.class, sequence( + comment(), + annotations(), + child(ObservableProperty.NAME), + list(ObservableProperty.TYPE_BOUND, + sequence( + space(), + token(GeneratedJavaParserConstants.BIT_AND), + space()), + sequence( + space(), + token(GeneratedJavaParserConstants.EXTENDS), + space()), + none()) + )); + + concreteSyntaxModelByClass.put(UnionType.class, CsmElement.sequence( + CsmElement.comment(), + annotations(), + CsmElement.list(ObservableProperty.ELEMENTS, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.BIT_OR), CsmElement.space())) + )); + + concreteSyntaxModelByClass.put(UnknownType.class, none()); + + concreteSyntaxModelByClass.put(VoidType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.VOID))); + + concreteSyntaxModelByClass.put(VarType.class, sequence(comment(), annotations(), string(GeneratedJavaParserConstants.IDENTIFIER, "var"))); + + concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), + CsmElement.conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, CsmElement.sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), CsmElement.child(EXTENDED_TYPE))), + CsmElement.conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, CsmElement.sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), CsmElement.child(SUPER_TYPE))))); + + /// + /// Top Level + /// + + concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence( + annotations(), + token(GeneratedJavaParserConstants.LBRACKET), + child(ObservableProperty.DIMENSION), + token(GeneratedJavaParserConstants.RBRACKET) + )); + + concreteSyntaxModelByClass.put(CompilationUnit.class, sequence( + comment(), + child(ObservableProperty.PACKAGE_DECLARATION), + list(ObservableProperty.IMPORTS, none(), none(), newline()), + list(TYPES, newline(), CsmElement.newline(), CsmElement.none(), CsmElement.newline()), + child(ObservableProperty.MODULE), + orphanCommentsEnding())); + + concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence( + comment(), + token(GeneratedJavaParserConstants.IMPORT), + space(), + conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), + child(ObservableProperty.NAME), + conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), + semicolon(), + newline(), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS), + token(GeneratedJavaParserConstants.PACKAGE), + space(), + child(ObservableProperty.NAME), + semicolon(), + newline(), + newline(), + orphanCommentsEnding())); + + /// + /// Module info + /// + + concreteSyntaxModelByClass.put(ModuleDeclaration.class, CsmElement.sequence( + annotations(), + CsmElement.conditional(ObservableProperty.OPEN, FLAG, CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.OPEN), CsmElement.space())), + CsmElement.token(GeneratedJavaParserConstants.MODULE), + CsmElement.space(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.space(), + CsmElement.token(GeneratedJavaParserConstants.LBRACE), + CsmElement.newline(), + CsmElement.indent(), + CsmElement.list(ObservableProperty.MODULE_STMTS), + CsmElement.unindent(), + CsmElement.token(GeneratedJavaParserConstants.RBRACE), + CsmElement.newline() + )); + + concreteSyntaxModelByClass.put(ModuleExportsStmt.class, CsmElement.sequence( + CsmElement.token(GeneratedJavaParserConstants.EXPORTS), + CsmElement.space(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.list(ObservableProperty.MODULE_NAMES, + CsmElement.sequence(CsmElement.comma(), CsmElement.space()), + CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.TO), CsmElement.space()), + CsmElement.none()), + CsmElement.semicolon(), + CsmElement.newline() + )); + + concreteSyntaxModelByClass.put(ModuleOpensStmt.class, CsmElement.sequence( + CsmElement.token(GeneratedJavaParserConstants.OPENS), + CsmElement.space(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.list(ObservableProperty.MODULE_NAMES, + CsmElement.sequence(CsmElement.comma(), CsmElement.space()), + CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.TO), CsmElement.space()), + CsmElement.none()), + CsmElement.semicolon(), + CsmElement.newline() + )); + + concreteSyntaxModelByClass.put(ModuleProvidesStmt.class, CsmElement.sequence( + CsmElement.token(GeneratedJavaParserConstants.PROVIDES), + CsmElement.space(), + CsmElement.child(ObservableProperty.TYPE), + CsmElement.list(ObservableProperty.WITH_TYPES, + CsmElement.sequence(CsmElement.comma(), CsmElement.space()), + CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.WITH), CsmElement.space()), + CsmElement.none()), + CsmElement.semicolon(), + CsmElement.newline() + )); + + concreteSyntaxModelByClass.put(ModuleRequiresStmt.class, CsmElement.sequence( + CsmElement.token(GeneratedJavaParserConstants.REQUIRES), + CsmElement.space(), + modifiers(), + CsmElement.child(ObservableProperty.NAME), + CsmElement.semicolon(), + CsmElement.newline() + )); + + concreteSyntaxModelByClass.put(ModuleUsesStmt.class, CsmElement.sequence( + CsmElement.token(GeneratedJavaParserConstants.USES), + CsmElement.space(), + CsmElement.child(ObservableProperty.TYPE), + CsmElement.semicolon(), + CsmElement.newline() + )); + + List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream() + .filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())) + .map(nm -> nm.getType().getSimpleName()) + .collect(Collectors.toList()); + if (unsupportedNodeClassNames.isEmpty()) { + initializationError = Optional.empty(); + } else { + initializationError = Optional.of("The CSM should include support for these classes: " + String.join(", ", unsupportedNodeClassNames)); + } + } + + private ConcreteSyntaxModel() { + + } + + public static void genericPrettyPrint(Node node, SourcePrinter printer) { + forClass(node.getClass()).prettyPrint(node, printer); + } + + public static String genericPrettyPrint(Node node) { + SourcePrinter sourcePrinter = new SourcePrinter(" ", EOL); + forClass(node.getClass()).prettyPrint(node, sourcePrinter); + return sourcePrinter.getSource(); + } + + public static CsmElement forClass(Class nodeClazz) { + initializationError.ifPresent(s -> { + throw new IllegalStateException(s); + }); + if (!concreteSyntaxModelByClass.containsKey(nodeClazz)) { + throw new UnsupportedOperationException(nodeClazz.getSimpleName()); + } + return concreteSyntaxModelByClass.get(nodeClazz); + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/DotPrinter.java b/JavaParser/src/com/github/javaparser/printer/DotPrinter.java new file mode 100644 index 0000000..2e190c9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/DotPrinter.java @@ -0,0 +1,106 @@ +/* + * 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.printer; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; + +/** + * Outputs a Graphviz diagram of the AST. + */ +public class DotPrinter { + + private int nodeCount; + private final boolean outputNodeType; + + public DotPrinter(boolean outputNodeType) { + this.outputNodeType = outputNodeType; + } + + public String output(Node node) { + nodeCount = 0; + StringBuilder output = new StringBuilder(); + output.append("digraph {"); + output(node, null, "root", output); + output.append(System.lineSeparator() + "}"); + return output.toString(); + } + + public void output(Node node, String parentNodeName, String name, StringBuilder builder) { + assertNotNull(node); + NodeMetaModel metaModel = node.getMetaModel(); + List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) + .collect(toList()); + + String ndName = nextNodeName(); + if (outputNodeType) + builder.append(System.lineSeparator() + ndName + " [label=\"" + name + " (" + metaModel.getTypeName() + + ")\"];"); + else + builder.append(System.lineSeparator() + ndName + " [label=\"" + name + "\"];"); + + if (parentNodeName != null) + builder.append(System.lineSeparator() + parentNodeName + " -> " + ndName + ";"); + + for (PropertyMetaModel a : attributes) { + String attrName = nextNodeName(); + builder.append(System.lineSeparator() + attrName + " [label=\"" + a.getName() + "='" + + a.getValue(node).toString() + "'\"];"); + builder.append(System.lineSeparator() + ndName + " -> " + attrName + ";"); + + } + + for (PropertyMetaModel sn : subNodes) { + Node nd = (Node) sn.getValue(node); + if (nd != null) + output(nd, ndName, sn.getName(), builder); + } + + for (PropertyMetaModel sl : subLists) { + NodeList nl = (NodeList) sl.getValue(node); + if (nl != null && nl.isNonEmpty()) { + String ndLstName = nextNodeName(); + builder.append(System.lineSeparator() + ndLstName + " [label=\"" + sl.getName() + "\"];"); + builder.append(System.lineSeparator() + ndName + " -> " + ndLstName + ";"); + String slName = sl.getName().substring(0, sl.getName().length() - 1); + for (Node nd : nl) + output(nd, ndLstName, slName, builder); + } + } + } + + private String nextNodeName() { + return "n" + (nodeCount++); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/JsonPrinter.java b/JavaParser/src/com/github/javaparser/printer/JsonPrinter.java new file mode 100644 index 0000000..2370512 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/JsonPrinter.java @@ -0,0 +1,74 @@ +package com.github.javaparser.printer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +/** + * Outputs a JSON file containing the AST meant for inspecting it. + */ +public class JsonPrinter { + private final boolean outputNodeType; + + public JsonPrinter(boolean outputNodeType) { + this.outputNodeType = outputNodeType; + } + + public String output(Node node) { + return output(node, null, 0); + } + + public String output(Node node, String name, int level) { + assertNotNull(node); + NodeMetaModel metaModel = node.getMetaModel(); + List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); + + final List content = new ArrayList<>(); + + if (outputNodeType) { + content.add(q("type") + ":" + q(metaModel.getTypeName())); + } + + for (PropertyMetaModel attributeMetaModel : attributes) { + content.add(q(attributeMetaModel.getName()) + ":" + q(attributeMetaModel.getValue(node).toString())); + } + + for (PropertyMetaModel subNodeMetaModel : subNodes) { + Node value = (Node) subNodeMetaModel.getValue(node); + if (value != null) { + content.add(output(value, subNodeMetaModel.getName(), level + 1)); + } + } + + for (PropertyMetaModel subListMetaModel : subLists) { + NodeList subList = (NodeList) subListMetaModel.getValue(node); + if (subList != null && !subList.isEmpty()) { + final List listContent = new ArrayList<>(); + for (Node subListNode : subList) { + listContent.add(output(subListNode, null, level + 1)); + } + content.add(listContent.stream().collect(Collectors.joining(",", q(subListMetaModel.getName()) + ":[", "]"))); + } + } + + if (name == null) { + return content.stream().collect(Collectors.joining(",", "{", "}")); + } + return content.stream().collect(Collectors.joining(",", q(name) + ":{", "}")); + } + + private static String q(String value) { + return "\"" + value.replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r") + "\""; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/PrettyPrintVisitor.java b/JavaParser/src/com/github/javaparser/printer/PrettyPrintVisitor.java new file mode 100644 index 0000000..8a1d6b5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -0,0 +1,1609 @@ +/* + * 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.printer; + +import com.github.javaparser.Position; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; +import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; +import static com.github.javaparser.utils.Utils.trimTrailingSpaces; + +/** + * Outputs the AST as formatted Java source code. + * + * @author Julio Vilmar Gesser + */ +public class PrettyPrintVisitor implements VoidVisitor { + protected final PrettyPrinterConfiguration configuration; + protected final SourcePrinter printer; + private Deque methodChainPositions = new LinkedList<>(); + + public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) { + configuration = prettyPrinterConfiguration; + printer = new SourcePrinter(configuration.getIndent(), configuration.getEndOfLineCharacter()); + pushMethodChainPosition(printer.getCursor()); // initialize a default position for methodChainPositions, it is expected by method #resetMethodChainPosition() + } + + public String getSource() { + return printer.getSource(); + } + + public void resetMethodChainPosition(Position position) { + this.methodChainPositions.pop(); + this.methodChainPositions.push(position); + } + + public void pushMethodChainPosition(Position position) { + this.methodChainPositions.push(position); + } + + public Position peekMethodChainPosition() { + return this.methodChainPositions.peek(); + } + + public Position popMethodChainPosition() { + return this.methodChainPositions.pop(); + } + + private void printModifiers(final EnumSet modifiers) { + if (modifiers.size() > 0) { + printer.print(modifiers.stream().map(Modifier::asString).collect(Collectors.joining(" ")) + " "); + } + } + + private void printMembers(final NodeList> members, final Void arg) { + for (final BodyDeclaration member : members) { + printer.println(); + member.accept(this, arg); + printer.println(); + } + } + + private void printMemberAnnotations(final NodeList annotations, final Void arg) { + if (annotations.isEmpty()) { + return; + } + for (final AnnotationExpr a : annotations) { + a.accept(this, arg); + printer.println(); + } + } + + private void printAnnotations(final NodeList annotations, boolean prefixWithASpace, + final Void arg) { + if (annotations.isEmpty()) { + return; + } + if (prefixWithASpace) { + printer.print(" "); + } + for (AnnotationExpr annotation : annotations) { + annotation.accept(this, arg); + printer.print(" "); + } + } + + private void printTypeArgs(final NodeWithTypeArguments nodeWithTypeArguments, final Void arg) { + NodeList typeArguments = nodeWithTypeArguments.getTypeArguments().orElse(null); + if (!isNullOrEmpty(typeArguments)) { + printer.print("<"); + for (final Iterator i = typeArguments.iterator(); i.hasNext(); ) { + final Type t = i.next(); + t.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(">"); + } + } + + private void printTypeParameters(final NodeList args, final Void arg) { + if (!isNullOrEmpty(args)) { + printer.print("<"); + for (final Iterator i = args.iterator(); i.hasNext(); ) { + final TypeParameter t = i.next(); + t.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(">"); + } + } + + private void printArguments(final NodeList args, final Void arg) { + printer.print("("); + Position cursorRef = printer.getCursor(); + if (!isNullOrEmpty(args)) { + for (final Iterator i = args.iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(","); + if (configuration.isColumnAlignParameters()) { + printer.wrapToColumn(cursorRef.column); + } else { + printer.print(" "); + } + } + } + } + printer.print(")"); + } + + private void printPrePostFixOptionalList(final NodeList args, final Void arg, String prefix, String separator, String postfix) { + if (!args.isEmpty()) { + printer.print(prefix); + for (final Iterator i = args.iterator(); i.hasNext(); ) { + final Visitable v = i.next(); + v.accept(this, arg); + if (i.hasNext()) { + printer.print(separator); + } + } + printer.print(postfix); + } + } + + private void printPrePostFixRequiredList(final NodeList args, final Void arg, String prefix, String separator, String postfix) { + printer.print(prefix); + if (!args.isEmpty()) { + for (final Iterator i = args.iterator(); i.hasNext(); ) { + final Visitable v = i.next(); + v.accept(this, arg); + if (i.hasNext()) { + printer.print(separator); + } + } + } + printer.print(postfix); + } + + private void printComment(final Optional comment, final Void arg) { + comment.ifPresent(c -> c.accept(this, arg)); + } + + @Override + public void visit(final CompilationUnit n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getParsed() == UNPARSABLE) { + printer.println("???"); + return; + } + + if (n.getPackageDeclaration().isPresent()) { + n.getPackageDeclaration().get().accept(this, arg); + } + + n.getImports().accept(this, arg); + if (!n.getImports().isEmpty()) { + printer.println(); + } + + for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { + i.next().accept(this, arg); + printer.println(); + if (i.hasNext()) { + printer.println(); + } + } + + n.getModule().ifPresent(m -> m.accept(this, arg)); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final PackageDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("package "); + n.getName().accept(this, arg); + printer.println(";"); + printer.println(); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final NameExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getName().accept(this, arg); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(final Name n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getQualifier().isPresent()) { + n.getQualifier().get().accept(this, arg); + printer.print("."); + } + printAnnotations(n.getAnnotations(), false, arg); + printer.print(n.getIdentifier()); + + printOrphanCommentsEnding(n); + } + + @Override + public void visit(SimpleName n, Void arg) { + printer.print(n.getIdentifier()); + } + + @Override + public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + if (n.isInterface()) { + printer.print("interface "); + } else { + printer.print("class "); + } + + n.getName().accept(this, arg); + + printTypeParameters(n.getTypeParameters(), arg); + + if (!n.getExtendedTypes().isEmpty()) { + printer.print(" extends "); + for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + if (!n.getImplementedTypes().isEmpty()) { + printer.print(" implements "); + for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + printer.println(" {"); + printer.indent(); + if (!isNullOrEmpty(n.getMembers())) { + printMembers(n.getMembers(), arg); + } + + printOrphanCommentsEnding(n); + + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final JavadocComment n, final Void arg) { + if (configuration.isPrintComments() && configuration.isPrintJavadoc()) { + printer.println("/**"); + final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter()); + String[] lines = commentContent.split("\\R"); + boolean skippingLeadingEmptyLines = true; + boolean prependEmptyLine = false; + for (String line : lines) { + final String trimmedLine = line.trim(); + if (trimmedLine.startsWith("*")) { + line = trimmedLine.substring(1); + } + line = trimTrailingSpaces(line); + if (line.isEmpty()) { + if (!skippingLeadingEmptyLines) { + prependEmptyLine = true; + } + } else { + skippingLeadingEmptyLines = false; + if (prependEmptyLine) { + printer.println(" *"); + prependEmptyLine = false; + } + printer.println(" *" + line); + } + } + printer.println(" */"); + } + } + + @Override + public void visit(final ClassOrInterfaceType n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); + printer.print("."); + } + for (AnnotationExpr ae : n.getAnnotations()) { + ae.accept(this, arg); + printer.print(" "); + } + + n.getName().accept(this, arg); + + if (n.isUsingDiamondOperator()) { + printer.print("<>"); + } else { + printTypeArgs(n, arg); + } + } + + @Override + public void visit(final TypeParameter n, final Void arg) { + printComment(n.getComment(), arg); + for (AnnotationExpr ann : n.getAnnotations()) { + ann.accept(this, arg); + printer.print(" "); + } + n.getName().accept(this, arg); + if (!isNullOrEmpty(n.getTypeBound())) { + printer.print(" extends "); + for (final Iterator i = n.getTypeBound().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(" & "); + } + } + } + } + + @Override + public void visit(final PrimitiveType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), true, arg); + printer.print(n.getType().asString()); + } + + @Override + public void visit(final ArrayType n, final Void arg) { + final List arrayTypeBuffer = new LinkedList<>(); + Type type = n; + while (type instanceof ArrayType) { + final ArrayType arrayType = (ArrayType) type; + arrayTypeBuffer.add(arrayType); + type = arrayType.getComponentType(); + } + + type.accept(this, arg); + for (ArrayType arrayType : arrayTypeBuffer) { + printAnnotations(arrayType.getAnnotations(), true, arg); + printer.print("[]"); + } + } + + @Override + public void visit(final ArrayCreationLevel n, final Void arg) { + printAnnotations(n.getAnnotations(), true, arg); + printer.print("["); + if (n.getDimension().isPresent()) { + n.getDimension().get().accept(this, arg); + } + printer.print("]"); + } + + @Override + public void visit(final IntersectionType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + boolean isFirst = true; + for (ReferenceType element : n.getElements()) { + if (isFirst) { + isFirst = false; + } else { + printer.print(" & "); + } + element.accept(this, arg); + } + } + + @Override + public void visit(final UnionType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), true, arg); + boolean isFirst = true; + for (ReferenceType element : n.getElements()) { + if (isFirst) { + isFirst = false; + } else { + printer.print(" | "); + } + element.accept(this, arg); + } + } + + @Override + public void visit(final WildcardType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("?"); + if (n.getExtendedType().isPresent()) { + printer.print(" extends "); + n.getExtendedType().get().accept(this, arg); + } + if (n.getSuperType().isPresent()) { + printer.print(" super "); + n.getSuperType().get().accept(this, arg); + } + } + + @Override + public void visit(final UnknownType n, final Void arg) { + // Nothing to print + } + + @Override + public void visit(final FieldDeclaration n, final Void arg) { + printOrphanCommentsBeforeThisChildNode(n); + + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + if (!n.getVariables().isEmpty()) { + Optional maximumCommonType = n.getMaximumCommonType(); + maximumCommonType.ifPresent(t -> t.accept(this, arg)); + if (!maximumCommonType.isPresent()) { + printer.print("???"); + } + } + + printer.print(" "); + for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { + final VariableDeclarator var = i.next(); + var.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + + printer.print(";"); + } + + @Override + public void visit(final VariableDeclarator n, final Void arg) { + printComment(n.getComment(), arg); + n.getName().accept(this, arg); + + n.getAncestorOfType(NodeWithVariables.class).ifPresent(ancestor -> { + ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { + + final Type type = n.getType(); + + ArrayType arrayType = null; + + for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { + if (arrayType == null) { + arrayType = (ArrayType) type; + } else { + arrayType = (ArrayType) arrayType.getComponentType(); + } + printAnnotations(arrayType.getAnnotations(), true, arg); + printer.print("[]"); + } + }); + }); + + if (n.getInitializer().isPresent()) { + printer.print(" = "); + n.getInitializer().get().accept(this, arg); + } + } + + @Override + public void visit(final ArrayInitializerExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("{"); + if (!isNullOrEmpty(n.getValues())) { + printer.print(" "); + for (final Iterator i = n.getValues().iterator(); i.hasNext(); ) { + final Expression expr = i.next(); + expr.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + printer.print(" "); + } + printOrphanCommentsEnding(n); + printer.print("}"); + } + + @Override + public void visit(final VoidType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("void"); + } + + @Override + public void visit(final VarType n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printer.print("var"); + } + + @Override + public void visit(final ArrayAccessExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getName().accept(this, arg); + printer.print("["); + n.getIndex().accept(this, arg); + printer.print("]"); + } + + @Override + public void visit(final ArrayCreationExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("new "); + n.getElementType().accept(this, arg); + for (ArrayCreationLevel level : n.getLevels()) { + level.accept(this, arg); + } + if (n.getInitializer().isPresent()) { + printer.print(" "); + n.getInitializer().get().accept(this, arg); + } + } + + @Override + public void visit(final AssignExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getTarget().accept(this, arg); + printer.print(" "); + printer.print(n.getOperator().asString()); + printer.print(" "); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final BinaryExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getLeft().accept(this, arg); + printer.print(" "); + printer.print(n.getOperator().asString()); + printer.print(" "); + n.getRight().accept(this, arg); + } + + @Override + public void visit(final CastExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("("); + n.getType().accept(this, arg); + printer.print(") "); + n.getExpression().accept(this, arg); + } + + @Override + public void visit(final ClassExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getType().accept(this, arg); + printer.print(".class"); + } + + @Override + public void visit(final ConditionalExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getCondition().accept(this, arg); + printer.print(" ? "); + n.getThenExpr().accept(this, arg); + printer.print(" : "); + n.getElseExpr().accept(this, arg); + } + + @Override + public void visit(final EnclosedExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("("); + n.getInner().accept(this, arg); + printer.print(")"); + } + + @Override + public void visit(final FieldAccessExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getScope().accept(this, arg); + printer.print("."); + n.getName().accept(this, arg); + } + + @Override + public void visit(final InstanceOfExpr n, final Void arg) { + printComment(n.getComment(), arg); + n.getExpression().accept(this, arg); + printer.print(" instanceof "); + n.getType().accept(this, arg); + } + + @Override + public void visit(final CharLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("'"); + printer.print(n.getValue()); + printer.print("'"); + } + + @Override + public void visit(final DoubleLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final IntegerLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final LongLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(n.getValue()); + } + + @Override + public void visit(final StringLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("\""); + printer.print(n.getValue()); + printer.print("\""); + } + + @Override + public void visit(final BooleanLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(String.valueOf(n.getValue())); + } + + @Override + public void visit(final NullLiteralExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("null"); + } + + @Override + public void visit(final ThisExpr n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getClassExpr().isPresent()) { + n.getClassExpr().get().accept(this, arg); + printer.print("."); + } + printer.print("this"); + } + + @Override + public void visit(final SuperExpr n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getClassExpr().isPresent()) { + n.getClassExpr().get().accept(this, arg); + printer.print("."); + } + printer.print("super"); + } + + @Override + public void visit(final MethodCallExpr n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); + if (configuration.isColumnAlignFirstMethodChain()) { + if (!(n.getScope().get() instanceof MethodCallExpr) || (!((MethodCallExpr) n.getScope().get()).getScope().isPresent())) { + resetMethodChainPosition(printer.getCursor()); + } else { + printer.wrapToColumn(peekMethodChainPosition().column); + } + } + printer.print("."); + } + printTypeArgs(n, arg); + n.getName().accept(this, arg); + pushMethodChainPosition(printer.getCursor()); + printArguments(n.getArguments(), arg); + popMethodChainPosition(); + } + + @Override + public void visit(final ObjectCreationExpr n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getScope().isPresent()) { + n.getScope().get().accept(this, arg); + printer.print("."); + } + + printer.print("new "); + + printTypeArgs(n, arg); + if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { + printer.print(" "); + } + + n.getType().accept(this, arg); + + printArguments(n.getArguments(), arg); + + if (n.getAnonymousClassBody().isPresent()) { + printer.println(" {"); + printer.indent(); + printMembers(n.getAnonymousClassBody().get(), arg); + printer.unindent(); + printer.print("}"); + } + } + + @Override + public void visit(final UnaryExpr n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getOperator().isPrefix()) { + printer.print(n.getOperator().asString()); + } + + n.getExpression().accept(this, arg); + + if (n.getOperator().isPostfix()) { + printer.print(n.getOperator().asString()); + } + } + + @Override + public void visit(final ConstructorDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printTypeParameters(n.getTypeParameters(), arg); + if (n.isGeneric()) { + printer.print(" "); + } + n.getName().accept(this, arg); + + printer.print("("); + if (!n.getParameters().isEmpty()) { + for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { + final Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + + if (!isNullOrEmpty(n.getThrownExceptions())) { + printer.print(" throws "); + for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { + final ReferenceType name = i.next(); + name.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(" "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final MethodDeclaration n, final Void arg) { + printOrphanCommentsBeforeThisChildNode(n); + + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + printTypeParameters(n.getTypeParameters(), arg); + if (!isNullOrEmpty(n.getTypeParameters())) { + printer.print(" "); + } + + n.getType().accept(this, arg); + printer.print(" "); + n.getName().accept(this, arg); + + printer.print("("); + n.getReceiverParameter().ifPresent(rp -> { + rp.accept(this, arg); + printer.print(", "); + }); + if (!isNullOrEmpty(n.getParameters())) { + for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { + final Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + + if (!isNullOrEmpty(n.getThrownExceptions())) { + printer.print(" throws "); + for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { + final ReferenceType name = i.next(); + name.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + if (!n.getBody().isPresent()) { + printer.print(";"); + } else { + printer.print(" "); + n.getBody().get().accept(this, arg); + } + } + + @Override + public void visit(final Parameter n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printModifiers(n.getModifiers()); + n.getType().accept(this, arg); + if (n.isVarArgs()) { + printAnnotations(n.getVarArgsAnnotations(), false, arg); + printer.print("..."); + } + if (!(n.getType() instanceof UnknownType)) { + printer.print(" "); + } + n.getName().accept(this, arg); + } + + @Override + public void visit(final ReceiverParameter n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + n.getType().accept(this, arg); + printer.print(" "); + n.getName().accept(this, arg); + } + + @Override + public void visit(final ExplicitConstructorInvocationStmt n, final Void arg) { + printComment(n.getComment(), arg); + if (n.isThis()) { + printTypeArgs(n, arg); + printer.print("this"); + } else { + if (n.getExpression().isPresent()) { + n.getExpression().get().accept(this, arg); + printer.print("."); + } + printTypeArgs(n, arg); + printer.print("super"); + } + printArguments(n.getArguments(), arg); + printer.print(";"); + } + + @Override + public void visit(final VariableDeclarationExpr n, final Void arg) { + printComment(n.getComment(), arg); + printAnnotations(n.getAnnotations(), false, arg); + printModifiers(n.getModifiers()); + + if (!n.getVariables().isEmpty()) { + n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); + } + printer.print(" "); + + for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { + final VariableDeclarator v = i.next(); + v.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + @Override + public void visit(final LocalClassDeclarationStmt n, final Void arg) { + printComment(n.getComment(), arg); + n.getClassDeclaration().accept(this, arg); + } + + @Override + public void visit(final AssertStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("assert "); + n.getCheck().accept(this, arg); + if (n.getMessage().isPresent()) { + printer.print(" : "); + n.getMessage().get().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final BlockStmt n, final Void arg) { + printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); + printer.println("{"); + if (n.getStatements() != null) { + printer.indent(); + for (final Statement s : n.getStatements()) { + s.accept(this, arg); + printer.println(); + } + printer.unindent(); + } + printOrphanCommentsEnding(n); + printer.print("}"); + } + + @Override + public void visit(final LabeledStmt n, final Void arg) { + printComment(n.getComment(), arg); + n.getLabel().accept(this, arg); + printer.print(": "); + n.getStatement().accept(this, arg); + } + + @Override + public void visit(final EmptyStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(";"); + } + + @Override + public void visit(final ExpressionStmt n, final Void arg) { + printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); + n.getExpression().accept(this, arg); + printer.print(";"); + } + + @Override + public void visit(final SwitchStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("switch("); + n.getSelector().accept(this, arg); + printer.println(") {"); + if (n.getEntries() != null) { + printer.indent(); + for (final SwitchEntryStmt e : n.getEntries()) { + e.accept(this, arg); + } + printer.unindent(); + } + printer.print("}"); + } + + @Override + public void visit(final SwitchEntryStmt n, final Void arg) { + printComment(n.getComment(), arg); + if (n.getLabel().isPresent()) { + printer.print("case "); + n.getLabel().get().accept(this, arg); + printer.print(":"); + } else { + printer.print("default:"); + } + printer.println(); + printer.indent(); + if (n.getStatements() != null) { + for (final Statement s : n.getStatements()) { + s.accept(this, arg); + printer.println(); + } + } + printer.unindent(); + } + + @Override + public void visit(final BreakStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("break"); + n.getLabel().ifPresent(l -> printer.print(" ").print(l.getIdentifier())); + printer.print(";"); + } + + @Override + public void visit(final ReturnStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("return"); + if (n.getExpression().isPresent()) { + printer.print(" "); + n.getExpression().get().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final EnumDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printer.print("enum "); + n.getName().accept(this, arg); + + if (!n.getImplementedTypes().isEmpty()) { + printer.print(" implements "); + for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + + printer.println(" {"); + printer.indent(); + if (n.getEntries().isNonEmpty()) { + final boolean alignVertically = + // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || + // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + printer.println(); + for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { + final EnumConstantDeclaration e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + if (alignVertically) { + printer.println(","); + } else { + printer.print(", "); + } + } + } + } + if (!n.getMembers().isEmpty()) { + printer.println(";"); + printMembers(n.getMembers(), arg); + } else { + if (!n.getEntries().isEmpty()) { + printer.println(); + } + } + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final EnumConstantDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + n.getName().accept(this, arg); + + if (!n.getArguments().isEmpty()) { + printArguments(n.getArguments(), arg); + } + + if (!n.getClassBody().isEmpty()) { + printer.println(" {"); + printer.indent(); + printMembers(n.getClassBody(), arg); + printer.unindent(); + printer.println("}"); + } + } + + @Override + public void visit(final InitializerDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + if (n.isStatic()) { + printer.print("static "); + } + n.getBody().accept(this, arg); + } + + @Override + public void visit(final IfStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("if ("); + n.getCondition().accept(this, arg); + final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; + if (thenBlock) // block statement should start on the same line + printer.print(") "); + else { + printer.println(")"); + printer.indent(); + } + n.getThenStmt().accept(this, arg); + if (!thenBlock) + printer.unindent(); + if (n.getElseStmt().isPresent()) { + if (thenBlock) + printer.print(" "); + else + printer.println(); + final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; + final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; + if (elseIf || elseBlock) // put chained if and start of block statement on a same level + printer.print("else "); + else { + printer.println("else"); + printer.indent(); + } + if (n.getElseStmt().isPresent()) + n.getElseStmt().get().accept(this, arg); + if (!(elseIf || elseBlock)) + printer.unindent(); + } + } + + @Override + public void visit(final WhileStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("while ("); + n.getCondition().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ContinueStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("continue"); + n.getLabel().ifPresent(l -> printer.print(" ").print(l.getIdentifier())); + printer.print(";"); + } + + @Override + public void visit(final DoStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("do "); + n.getBody().accept(this, arg); + printer.print(" while ("); + n.getCondition().accept(this, arg); + printer.print(");"); + } + + @Override + public void visit(final ForeachStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("for ("); + n.getVariable().accept(this, arg); + printer.print(" : "); + n.getIterable().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ForStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("for ("); + if (n.getInitialization() != null) { + for (final Iterator i = n.getInitialization().iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print("; "); + if (n.getCompare().isPresent()) { + n.getCompare().get().accept(this, arg); + } + printer.print("; "); + if (n.getUpdate() != null) { + for (final Iterator i = n.getUpdate().iterator(); i.hasNext(); ) { + final Expression e = i.next(); + e.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final ThrowStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("throw "); + n.getExpression().accept(this, arg); + printer.print(";"); + } + + @Override + public void visit(final SynchronizedStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("synchronized ("); + n.getExpression().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final TryStmt n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("try "); + if (!n.getResources().isEmpty()) { + printer.print("("); + Iterator resources = n.getResources().iterator(); + boolean first = true; + while (resources.hasNext()) { + resources.next().accept(this, arg); + if (resources.hasNext()) { + printer.print(";"); + printer.println(); + if (first) { + printer.indent(); + } + } + first = false; + } + if (n.getResources().size() > 1) { + printer.unindent(); + } + printer.print(") "); + } + n.getTryBlock().accept(this, arg); + for (final CatchClause c : n.getCatchClauses()) { + c.accept(this, arg); + } + if (n.getFinallyBlock().isPresent()) { + printer.print(" finally "); + n.getFinallyBlock().get().accept(this, arg); + } + } + + @Override + public void visit(final CatchClause n, final Void arg) { + printComment(n.getComment(), arg); + printer.print(" catch ("); + n.getParameter().accept(this, arg); + printer.print(") "); + n.getBody().accept(this, arg); + } + + @Override + public void visit(final AnnotationDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + printer.print("@interface "); + n.getName().accept(this, arg); + printer.println(" {"); + printer.indent(); + if (n.getMembers() != null) { + printMembers(n.getMembers(), arg); + } + printer.unindent(); + printer.print("}"); + } + + @Override + public void visit(final AnnotationMemberDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printMemberAnnotations(n.getAnnotations(), arg); + printModifiers(n.getModifiers()); + + n.getType().accept(this, arg); + printer.print(" "); + n.getName().accept(this, arg); + printer.print("()"); + if (n.getDefaultValue().isPresent()) { + printer.print(" default "); + n.getDefaultValue().get().accept(this, arg); + } + printer.print(";"); + } + + @Override + public void visit(final MarkerAnnotationExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + } + + @Override + public void visit(final SingleMemberAnnotationExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + printer.print("("); + n.getMemberValue().accept(this, arg); + printer.print(")"); + } + + @Override + public void visit(final NormalAnnotationExpr n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("@"); + n.getName().accept(this, arg); + printer.print("("); + if (n.getPairs() != null) { + for (final Iterator i = n.getPairs().iterator(); i.hasNext(); ) { + final MemberValuePair m = i.next(); + m.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.print(")"); + } + + @Override + public void visit(final MemberValuePair n, final Void arg) { + printComment(n.getComment(), arg); + n.getName().accept(this, arg); + printer.print(" = "); + n.getValue().accept(this, arg); + } + + @Override + public void visit(final LineComment n, final Void arg) { + if (configuration.isIgnoreComments()) { + return; + } + printer + .print("// ") + .println(normalizeEolInTextBlock(n.getContent(), "").trim()); + } + + @Override + public void visit(final BlockComment n, final Void arg) { + if (configuration.isIgnoreComments()) { + return; + } + final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter()); + String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + printer.print("/*"); + for (int i = 0; i < (lines.length - 1); i++) { + printer.print(lines[i]); + printer.print(configuration.getEndOfLineCharacter()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + } + printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` + printer.println("*/"); + } + + @Override + public void visit(LambdaExpr n, Void arg) { + printComment(n.getComment(), arg); + + final NodeList parameters = n.getParameters(); + final boolean printPar = n.isEnclosingParameters(); + + if (printPar) { + printer.print("("); + } + for (Iterator i = parameters.iterator(); i.hasNext(); ) { + Parameter p = i.next(); + p.accept(this, arg); + if (i.hasNext()) { + printer.print(", "); + } + } + if (printPar) { + printer.print(")"); + } + + printer.print(" -> "); + final Statement body = n.getBody(); + if (body instanceof ExpressionStmt) { + // Print the expression directly + ((ExpressionStmt) body).getExpression().accept(this, arg); + } else { + body.accept(this, arg); + } + } + + @Override + public void visit(MethodReferenceExpr n, Void arg) { + printComment(n.getComment(), arg); + Expression scope = n.getScope(); + String identifier = n.getIdentifier(); + if (scope != null) { + n.getScope().accept(this, arg); + } + + printer.print("::"); + printTypeArgs(n, arg); + if (identifier != null) { + printer.print(identifier); + } + } + + @Override + public void visit(TypeExpr n, Void arg) { + printComment(n.getComment(), arg); + if (n.getType() != null) { + n.getType().accept(this, arg); + } + } + + @Override + public void visit(NodeList n, Void arg) { + if (configuration.isOrderImports() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { + //noinspection unchecked + NodeList modifiableList = new NodeList<>(n); + modifiableList.sort((left, right) -> { + int sort = Integer.compare(left.isStatic() ? 0 : 1, right.isStatic() ? 0 : 1); + if (sort == 0) { + sort = left.getNameAsString().compareTo(right.getNameAsString()); + } + return sort; + }); + for (Object node : modifiableList) { + ((Node) node).accept(this, arg); + } + } else { + for (Object node : n) { + ((Node) node).accept(this, arg); + } + } + } + + @Override + public void visit(final ImportDeclaration n, final Void arg) { + printComment(n.getComment(), arg); + printer.print("import "); + if (n.isStatic()) { + printer.print("static "); + } + n.getName().accept(this, arg); + if (n.isAsterisk()) { + printer.print(".*"); + } + printer.println(";"); + + printOrphanCommentsEnding(n); + } + + + @Override + public void visit(ModuleDeclaration n, Void arg) { + printAnnotations(n.getAnnotations(), false, arg); + printer.println(); + if (n.isOpen()) { + printer.print("open "); + } + printer.print("module "); + n.getName().accept(this, arg); + printer.println(" {").indent(); + n.getModuleStmts().accept(this, arg); + printer.unindent().println("}"); + } + + @Override + public void visit(ModuleRequiresStmt n, Void arg) { + printer.print("requires "); + printModifiers(n.getModifiers()); + n.getName().accept(this, arg); + printer.println(";"); + } + + @Override + public void visit(ModuleExportsStmt n, Void arg) { + printer.print("exports "); + n.getName().accept(this, arg); + printPrePostFixOptionalList(n.getModuleNames(), arg, " to ", ", ", ""); + printer.println(";"); + } + + @Override + public void visit(ModuleProvidesStmt n, Void arg) { + printer.print("provides "); + n.getType().accept(this, arg); + printPrePostFixRequiredList(n.getWithTypes(), arg, " with ", ", ", ""); + printer.println(";"); + } + + @Override + public void visit(ModuleUsesStmt n, Void arg) { + printer.print("uses "); + n.getType().accept(this, arg); + printer.println(";"); + } + + @Override + public void visit(ModuleOpensStmt n, Void arg) { + printer.print("opens "); + n.getName().accept(this, arg); + printPrePostFixOptionalList(n.getModuleNames(), arg, " to ", ", ", ""); + printer.println(";"); + } + + @Override + public void visit(UnparsableStmt n, Void arg) { + printer.print("???;"); + } + + private void printOrphanCommentsBeforeThisChildNode(final Node node) { + if (configuration.isIgnoreComments()) return; + if (node instanceof Comment) return; + + Node parent = node.getParentNode().orElse(null); + if (parent == null) return; + List everything = new LinkedList<>(); + everything.addAll(parent.getChildNodes()); + sortByBeginPosition(everything); + int positionOfTheChild = -1; + for (int i = 0; i < everything.size(); i++) { + if (everything.get(i) == node) positionOfTheChild = i; + } + if (positionOfTheChild == -1) { + throw new AssertionError("I am not a child of my parent."); + } + int positionOfPreviousChild = -1; + for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { + if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + } + for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { + Node nodeToPrint = everything.get(i); + if (!(nodeToPrint instanceof Comment)) + throw new RuntimeException( + "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + + positionOfPreviousChild + ", position of child " + positionOfTheChild); + nodeToPrint.accept(this, null); + } + } + + private void printOrphanCommentsEnding(final Node node) { + if (configuration.isIgnoreComments()) return; + + List everything = new LinkedList<>(); + everything.addAll(node.getChildNodes()); + sortByBeginPosition(everything); + if (everything.isEmpty()) { + return; + } + + int commentsAtEnd = 0; + boolean findingComments = true; + while (findingComments && commentsAtEnd < everything.size()) { + Node last = everything.get(everything.size() - 1 - commentsAtEnd); + findingComments = (last instanceof Comment); + if (findingComments) { + commentsAtEnd++; + } + } + for (int i = 0; i < commentsAtEnd; i++) { + everything.get(everything.size() - commentsAtEnd + i).accept(this, null); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/PrettyPrinter.java b/JavaParser/src/com/github/javaparser/printer/PrettyPrinter.java new file mode 100644 index 0000000..510457c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/PrettyPrinter.java @@ -0,0 +1,45 @@ +/* + * 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.printer; + +import com.github.javaparser.ast.Node; + +/** + * Pretty printer for AST nodes. + */ +public class PrettyPrinter { + private final PrettyPrinterConfiguration configuration; + + public PrettyPrinter() { + this(new PrettyPrinterConfiguration()); + } + + public PrettyPrinter(PrettyPrinterConfiguration configuration) { + this.configuration = configuration; + } + + public String print(Node node) { + final PrettyPrintVisitor visitor = configuration.getVisitorFactory().apply(configuration); + node.accept(visitor, null); + return visitor.getSource(); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/PrettyPrinterConfiguration.java b/JavaParser/src/com/github/javaparser/printer/PrettyPrinterConfiguration.java new file mode 100644 index 0000000..1c650d2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/PrettyPrinterConfiguration.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer; + +import java.util.function.Function; + +import static com.github.javaparser.utils.Utils.EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * Configuration options for the {@link PrettyPrinter}. + */ +public class PrettyPrinterConfiguration { + public static final int DEFAULT_MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY = 5; + + private boolean orderImports = false; + private boolean printComments = true; + private boolean printJavadoc = true; + private boolean columnAlignParameters = false; + private boolean columnAlignFirstMethodChain = false; + private String indent = " "; + private String endOfLineCharacter = EOL; + private Function visitorFactory = PrettyPrintVisitor::new; + private int maxEnumConstantsToAlignHorizontally = DEFAULT_MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY; + + public String getIndent() { + return indent; + } + + /** + * Set the string to use for indenting. For example: "\t", " ", "". + */ + public PrettyPrinterConfiguration setIndent(String indent) { + this.indent = assertNotNull(indent); + return this; + } + + public boolean isOrderImports() { + return orderImports; + } + + /** + * @deprecated this is always on. + */ + @Deprecated + public boolean isNormalizeEolInComment() { + return true; + } + + /** + * @deprecated this is always on. + */ + @Deprecated + public PrettyPrinterConfiguration setNormalizeEolInComment(boolean normalizeEolInComment) { + return this; + } + + public boolean isPrintComments() { + return printComments; + } + + public boolean isIgnoreComments() { + return !printComments; + } + + public boolean isPrintJavadoc() { + return printJavadoc; + } + + public boolean isColumnAlignParameters() { + return columnAlignParameters; + } + + public boolean isColumnAlignFirstMethodChain() { + return columnAlignFirstMethodChain; + } + + /** + * When true, all comments will be printed, unless printJavadoc is false, then only line and block comments will be + * printed. + */ + public PrettyPrinterConfiguration setPrintComments(boolean printComments) { + this.printComments = printComments; + return this; + } + + /** + * When true, Javadoc will be printed. + */ + public PrettyPrinterConfiguration setPrintJavadoc(boolean printJavadoc) { + this.printJavadoc = printJavadoc; + return this; + } + + public PrettyPrinterConfiguration setColumnAlignParameters(boolean columnAlignParameters) { + this.columnAlignParameters = columnAlignParameters; + return this; + } + + public PrettyPrinterConfiguration setColumnAlignFirstMethodChain(boolean columnAlignFirstMethodChain) { + this.columnAlignFirstMethodChain = columnAlignFirstMethodChain; + return this; + } + + public Function getVisitorFactory() { + return visitorFactory; + } + + /** + * Set the factory that creates the PrettyPrintVisitor. By changing this you can make the PrettyPrinter use a custom + * PrettyPrinterVisitor. + */ + public PrettyPrinterConfiguration setVisitorFactory(Function visitorFactory) { + this.visitorFactory = assertNotNull(visitorFactory); + return this; + } + + public String getEndOfLineCharacter() { + return endOfLineCharacter; + } + + /** + * Set the character to append when a line should end. Example values: "\n", "\r\n", "". + */ + public PrettyPrinterConfiguration setEndOfLineCharacter(String endOfLineCharacter) { + this.endOfLineCharacter = assertNotNull(endOfLineCharacter); + return this; + } + + /** + * When true, orders imports by alphabetically. + */ + public PrettyPrinterConfiguration setOrderImports(boolean orderImports) { + this.orderImports = orderImports; + return this; + } + + public int getMaxEnumConstantsToAlignHorizontally() { + return maxEnumConstantsToAlignHorizontally; + } + + /** + * By default enum constants get aligned like this: + *

+     *     enum X {
+     *        A, B, C, D
+     *     }
+     * 
+ * until the amount of constants passes this value (5 by default). + * Then they get aligned like this: + *
+     *     enum X {
+     *        A,
+     *        B,
+     *        C,
+     *        D,
+     *        E,
+     *        F,
+     *        G
+     *     }
+     * 
+ * Set it to a large number to always align horizontally. + * Set it to 1 or less to always align vertically. + */ + public PrettyPrinterConfiguration setMaxEnumConstantsToAlignHorizontally(int maxEnumConstantsToAlignHorizontally) { + this.maxEnumConstantsToAlignHorizontally = maxEnumConstantsToAlignHorizontally; + return this; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/Printable.java b/JavaParser/src/com/github/javaparser/printer/Printable.java new file mode 100644 index 0000000..390baa7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/Printable.java @@ -0,0 +1,28 @@ +/* + * 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.printer; + +/** + * Something that has a printable form. I.e., it can be converted to a user-facing String. + */ +public interface Printable { + String asString(); +} diff --git a/JavaParser/src/com/github/javaparser/printer/SourcePrinter.java b/JavaParser/src/com/github/javaparser/printer/SourcePrinter.java new file mode 100644 index 0000000..a53d907 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/SourcePrinter.java @@ -0,0 +1,153 @@ +/* + * 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.printer; + +import com.github.javaparser.Position; +import com.github.javaparser.utils.Utils; + +public class SourcePrinter { + + private final String indentation; + private final int indentationLength; + private final String endOfLineCharacter; + private int level = 0; + private boolean indented = false; + private final StringBuilder buf = new StringBuilder(); + private Position cursor = new Position(1, 0); + + SourcePrinter(final String indentation, final String endOfLineCharacter) { + this.indentation = indentation; + this.indentationLength = indentation.length(); + this.endOfLineCharacter = endOfLineCharacter; + } + + public SourcePrinter indent() { + level++; + return this; + } + + public SourcePrinter unindent() { + level--; + return this; + } + + private void makeIndent() { + for (int i = 0; i < level; i++) { + buf.append(indentation); + cursor = Position.pos(cursor.line, cursor.column + indentationLength); + } + } + + /** + * Append the source string passed as argument to the buffer. + * If this is being appended at the beginning of a line, performs indentation first. + *

+ * The source line to be printed should not contain newline/carriage-return characters; + * use {@link #println(String)} to automatically append a newline at the end of the source string. + * If the source line passed as argument contains newline/carriage-return characters would + * impredictably affect a correct computation of the current {@link #getCursor()} position. + * + * @see SourcePrinter#println(String) + * @param arg source line to be printed (should not contain newline/carriage-return characters) + * @return this instance, for nesting calls to method as fluent interface + */ + public SourcePrinter print(final String arg) { + if (!indented) { + makeIndent(); + indented = true; + } + buf.append(arg); + cursor = Position.pos(cursor.line, cursor.column + arg.length()); + return this; + } + + /** + * Append the source string passed as argument to the buffer, then append a newline. + * If this is being appended at the beginning of a line, performs indentation first. + *

+ * The source line to be printed should not contain newline/carriage-return characters. + * If the source line passed as argument contains newline/carriage-return characters would + * impredictably affect a correct computation of the current {@link #getCursor()} position. + * + * @param arg source line to be printed (should not contain newline/carriage-return characters) + * @return this instance, for nesting calls to method as fluent interface + */ + public SourcePrinter println(final String arg) { + print(arg); + println(); + return this; + } + + /** + * Append a newline to the buffer. + * + * @return this instance, for nesting calls to method as fluent interface + */ + public SourcePrinter println() { + buf.append(endOfLineCharacter); + cursor = Position.pos(cursor.line + 1, 0); + indented = false; + return this; + } + + /** + * Return the current cursor position (line, column) in the source printer buffer. + *

+ * Please notice in order to guarantee a correct computation of the cursor position, + * this printer expect the contracts of the methods {@link #print(String)} and {@link #println(String)} + * has been respected through all method calls, meaning the source string passed as argument to those method + * calls did not contain newline/carriage-return characters. + * + * @return the current cursor position (line, column). + */ + public Position getCursor() { + return cursor; + } + + /** + * Performs a new line and indent, then prints enough space characters until aligned to the specified column. + * @param column the column to align to + */ + public void wrapToColumn(int column) { + println(); + if (!indented) { + makeIndent(); + indented = true; + } + while ( cursor.column < column ) { + print(" "); + } + } + + public String getSource() { + return buf.toString(); + } + + @Override + public String toString() { + return getSource(); + } + + public String normalizeEolInTextBlock(String content) { + return Utils.normalizeEolInTextBlock(content, endOfLineCharacter); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/XmlPrinter.java b/JavaParser/src/com/github/javaparser/printer/XmlPrinter.java new file mode 100644 index 0000000..ea69c9e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/XmlPrinter.java @@ -0,0 +1,77 @@ +package com.github.javaparser.printer; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; + +import java.util.List; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +/** + * Outputs an XML file containing the AST meant for inspecting it. + */ +public class XmlPrinter { + private final boolean outputNodeType; + + public XmlPrinter(boolean outputNodeType) { + this.outputNodeType = outputNodeType; + } + + public String output(Node node) { + StringBuilder output = new StringBuilder(); + output(node, "root", 0, output); + return output.toString(); + } + + public void output(Node node, String name, int level, StringBuilder builder) { + assertNotNull(node); + NodeMetaModel metaModel = node.getMetaModel(); + List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); + + builder.append("<").append(name); + if (outputNodeType) { + builder.append(attribute("type", metaModel.getTypeName())); + } + + for (PropertyMetaModel attributeMetaModel : attributes) { + builder.append(attribute(attributeMetaModel.getName(), attributeMetaModel.getValue(node).toString())); + } + builder.append(">"); + + for (PropertyMetaModel subNodeMetaModel : subNodes) { + Node value = (Node) subNodeMetaModel.getValue(node); + if (value != null) { + output(value, subNodeMetaModel.getName(), level + 1, builder); + } + } + + for (PropertyMetaModel subListMetaModel : subLists) { + NodeList subList = (NodeList) subListMetaModel.getValue(node); + if (subList != null && !subList.isEmpty()) { + String listName = subListMetaModel.getName(); + builder.append("<").append(listName).append(">"); + String singular = listName.substring(0, listName.length() - 1); + for (Node subListNode : subList) { + output(subListNode, singular, level + 1, builder); + } + builder.append(close(listName)); + } + } + builder.append(close(name)); + } + + private static String close(String name) { + return ""; + } + + private static String attribute(String name, String value) { + return " " + name + "='" + value + "'"; + } +} + diff --git a/JavaParser/src/com/github/javaparser/printer/YamlPrinter.java b/JavaParser/src/com/github/javaparser/printer/YamlPrinter.java new file mode 100644 index 0000000..1e418f5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/YamlPrinter.java @@ -0,0 +1,101 @@ +/* + * 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.printer; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +import java.util.List; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; + +/** + * Outputs a YAML file containing the AST meant for inspecting it. + */ +public class YamlPrinter { + + private static final int NUM_SPACES_FOR_INDENT = 4; + private final boolean outputNodeType; + + public YamlPrinter(boolean outputNodeType) { + this.outputNodeType = outputNodeType; + } + + public String output(Node node) { + StringBuilder output = new StringBuilder(); + output.append("---"); + output(node, "root", 0, output); + output.append(System.lineSeparator() + "..."); + return output.toString(); + } + + public void output(Node node, String name, int level, StringBuilder builder) { + assertNotNull(node); + NodeMetaModel metaModel = node.getMetaModel(); + List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) + .collect(toList()); + + if (outputNodeType) + builder.append(System.lineSeparator() + indent(level) + name + "(Type=" + metaModel.getTypeName() + "): "); + else + builder.append(System.lineSeparator() + indent(level) + name + ": "); + + level++; + for (PropertyMetaModel a : attributes) { + builder.append(System.lineSeparator() + indent(level) + a.getName() + ": \"" + + a.getValue(node).toString() + "\""); + } + + for (PropertyMetaModel sn : subNodes) { + Node nd = (Node) sn.getValue(node); + if (nd != null) + output(nd, sn.getName(), level, builder); + } + + for (PropertyMetaModel sl : subLists) { + NodeList nl = (NodeList) sl.getValue(node); + if (nl != null && nl.isNonEmpty()) { + builder.append(System.lineSeparator() + indent(level) + sl.getName() + ": "); + String slName = sl.getName(); + slName = slName.endsWith("s") ? slName.substring(0, sl.getName().length() - 1) : slName; + for (Node nd : nl) + output(nd, "- " + slName, level + 1, builder); + } + } + } + + private String indent(int level) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < level; i++) + for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) + sb.append(" "); + return sb.toString(); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java new file mode 100644 index 0000000..b44672d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java @@ -0,0 +1,79 @@ +/* + * 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.printer.concretesyntaxmodel; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmAttribute implements CsmElement { + public ObservableProperty getProperty() { + return property; + } + + private final ObservableProperty property; + + public CsmAttribute(ObservableProperty property) { + this.property = property; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + Object value = property.getRawValue(node); + printer.print(PrintingHelper.printToString(value)); + } + + /** + * Obtain the token type corresponding to the specific value of the attribute. + * For example, to the attribute "Operator" different token could correspond like PLUS or MINUS. + */ + public int getTokenType(Node node, String text) { + switch (property) { + case IDENTIFIER: + return GeneratedJavaParserConstants.IDENTIFIER; + case TYPE: + String expectedImage = "\"" + text.toLowerCase() + "\""; + for (int i=0;i process(c, printer)); + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java new file mode 100644 index 0000000..a2ca7cd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.Arrays; +import java.util.List; + +public class CsmConditional implements CsmElement { + private final Condition condition; + private final List properties; + private final CsmElement thenElement; + private final CsmElement elseElement; + + public Condition getCondition() { + return condition; + } + + public ObservableProperty getProperty() { + if (properties.size() > 1) { + throw new IllegalStateException(); + } + return properties.get(0); + } + + public CsmElement getThenElement() { + return thenElement; + } + + public CsmElement getElseElement() { + return elseElement; + } + + public enum Condition { + IS_EMPTY, + IS_NOT_EMPTY, + IS_PRESENT, + FLAG; + + boolean evaluate(Node node, ObservableProperty property){ + if (this == IS_PRESENT) { + return !property.isNullOrNotPresent(node); + } + if (this == FLAG) { + return property.getValueAsBooleanAttribute(node); + } + if (this == IS_EMPTY) { + NodeList value = property.getValueAsMultipleReference(node); + return value == null || value.isEmpty(); + } + if (this == IS_NOT_EMPTY) { + NodeList value = property.getValueAsMultipleReference(node); + return value != null && !value.isEmpty(); + } + throw new UnsupportedOperationException(name()); + } + } + + public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement, CsmElement elseElement) { + this.properties = Arrays.asList(property); + this.condition = condition; + this.thenElement = thenElement; + this.elseElement = elseElement; + } + + public CsmConditional(List properties, Condition condition, CsmElement thenElement, CsmElement elseElement) { + if (properties.size() < 1) { + throw new IllegalArgumentException(); + } + this.properties = properties; + this.condition = condition; + this.thenElement = thenElement; + this.elseElement = elseElement; + } + + public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement) { + this(property, condition, thenElement, new CsmNone()); + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + boolean test = false; + for (ObservableProperty prop : properties) { + test = test || condition.evaluate(node, prop); + } + if (test) { + thenElement.prettyPrint(node, printer); + } else { + elseElement.prettyPrint(node, printer); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java new file mode 100644 index 0000000..61566d1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.Arrays; +import java.util.List; + +import static com.github.javaparser.TokenTypes.*; +import static com.github.javaparser.utils.Utils.EOL; + +public interface CsmElement { + + void prettyPrint(Node node, SourcePrinter printer); + + static CsmElement child(ObservableProperty property) { + return new CsmSingleReference(property); + } + + static CsmElement attribute(ObservableProperty property) { + return new CsmAttribute(property); + } + + static CsmElement sequence(CsmElement... elements) { + return new CsmSequence(Arrays.asList(elements)); + } + + static CsmElement string(int tokenType, String content) { + return new CsmToken(tokenType, content); + } + + static CsmElement string(int tokenType) { + return new CsmToken(tokenType); + } + + static CsmElement stringToken(ObservableProperty property) { + return new CsmString(property); + } + + static CsmElement charToken(ObservableProperty property) { + return new CsmChar(property); + } + + static CsmElement token(int tokenType) { + return new CsmToken(tokenType); + } + + static CsmElement token(int tokenType, CsmToken.TokenContentCalculator tokenContentCalculator) { + return new CsmToken(tokenType, tokenContentCalculator); + } + + static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement) { + return new CsmConditional(property, condition, thenElement); + } + + static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) { + return new CsmConditional(property, condition, thenElement, elseElement); + } + + static CsmElement conditional(List properties, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) { + return new CsmConditional(properties, condition, thenElement, elseElement); + } + + static CsmElement space() { + return new CsmToken(spaceTokenKind(), " "); + } + + static CsmElement semicolon() { + return new CsmToken(GeneratedJavaParserConstants.SEMICOLON); + } + + static CsmElement comment() { return new CsmComment(); } + + static CsmElement newline() { + return new CsmToken(eolTokenKind(), EOL); + } + + static CsmElement none() { + return new CsmNone(); + } + + static CsmElement comma() { + return new CsmToken(GeneratedJavaParserConstants.COMMA); + } + + static CsmElement list(ObservableProperty property) { + return new CsmList(property); + } + + static CsmElement list(ObservableProperty property, CsmElement separator) { + return new CsmList(property, CsmElement.none(), separator, new CsmNone(), new CsmNone()); + } + + static CsmElement list(ObservableProperty property, CsmElement separator, CsmElement preceeding, CsmElement following) { + return new CsmList(property, none(), separator, preceeding, following); + } + + static CsmElement list(ObservableProperty property, CsmElement separatorPre, CsmElement separatorPost, CsmElement preceeding, CsmElement following) { + return new CsmList(property, separatorPre, separatorPost, preceeding, following); + } + + static CsmElement orphanCommentsEnding() { + return new CsmOrphanCommentsEnding(); + } + + static CsmElement orphanCommentsBeforeThis() { + // FIXME + return new CsmNone(); + } + + static CsmElement indent() { + return new CsmIndent(); + } + + static CsmElement unindent() { + return new CsmUnindent(); + } + + static CsmElement block(CsmElement content) { + return sequence(token(GeneratedJavaParserConstants.LBRACE), indent(), content, unindent(), token(GeneratedJavaParserConstants.RBRACE)); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java new file mode 100644 index 0000000..69be97f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java @@ -0,0 +1,43 @@ +/* + * 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.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmIndent implements CsmElement { + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + printer.indent(); + } + + @Override + public int hashCode() { + return 1; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof CsmIndent; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java new file mode 100644 index 0000000..30fae7e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.ConcreteSyntaxModel; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.Collection; +import java.util.Iterator; + +public class CsmList implements CsmElement { + private final ObservableProperty property; + private final CsmElement separatorPost; + private final CsmElement separatorPre; + private final CsmElement preceeding; + private final CsmElement following; + + public ObservableProperty getProperty() { + return property; + } + + public CsmElement getSeparatorPost() { + return separatorPost; + } + + public CsmElement getSeparatorPre() { + return separatorPre; + } + + public CsmElement getPreceeding() { + return preceeding; + } + + public CsmElement getFollowing() { + return following; + } + + public CsmList(ObservableProperty property, CsmElement separator) { + this(property, new CsmNone(), separator, new CsmNone(), new CsmNone()); + } + + public CsmList(ObservableProperty property) { + this(property, new CsmNone(), new CsmNone(), new CsmNone(), new CsmNone()); + } + + public CsmList(ObservableProperty property, CsmElement separatorPre, CsmElement separatorPost, CsmElement preceeding, CsmElement following) { + this.property = property; + this.separatorPre = separatorPre; + this.separatorPost = separatorPost; + this.preceeding = preceeding; + this.following = following; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + if (property.isAboutNodes()) { + NodeList nodeList = property.getValueAsMultipleReference(node); + if (nodeList == null) { + return; + } + if (!nodeList.isEmpty() && preceeding != null) { + preceeding.prettyPrint(node, printer); + } + for (int i = 0; i < nodeList.size(); i++) { + if (separatorPre != null && i != 0) { + separatorPre.prettyPrint(node, printer); + } + ConcreteSyntaxModel.genericPrettyPrint(nodeList.get(i), printer); + if (separatorPost != null && i != (nodeList.size() - 1)) { + separatorPost.prettyPrint(node, printer); + } + } + if (!nodeList.isEmpty() && following != null) { + following.prettyPrint(node, printer); + } + } else { + Collection values = property.getValueAsCollection(node); + if (values == null) { + return; + } + if (!values.isEmpty() && preceeding != null) { + preceeding.prettyPrint(node, printer); + } + for (Iterator it = values.iterator(); it.hasNext(); ) { + if (separatorPre != null && it.hasNext()) { + separatorPre.prettyPrint(node, printer); + } + printer.print(PrintingHelper.printToString(it.next())); + if (separatorPost != null && it.hasNext()) { + separatorPost.prettyPrint(node, printer); + } + } + if (!values.isEmpty() && following != null) { + following.prettyPrint(node, printer); + } + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java new file mode 100644 index 0000000..9ce5461 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java @@ -0,0 +1,54 @@ +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * A group of elements that could be in any order. + */ +public class CsmMix implements CsmElement { + private List elements; + + public CsmMix(List elements) { + if (elements == null) { + throw new NullPointerException(); + } + if (elements.stream().anyMatch(Objects::isNull)) { + throw new IllegalArgumentException("Null element in the mix"); + } + this.elements = elements; + } + + public List getElements() { + return elements; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + elements.forEach(e -> e.prettyPrint(node, printer)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CsmMix csmMix = (CsmMix) o; + + return elements != null ? elements.equals(csmMix.elements) : csmMix.elements == null; + } + + @Override + public int hashCode() { + return elements != null ? elements.hashCode() : 0; + } + + @Override + public String toString() { + return "CsmMix[" + String.join(", ", elements.stream().map(e -> elements.toString()).collect(Collectors.toList())) + "]"; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java new file mode 100644 index 0000000..372bf8f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java @@ -0,0 +1,34 @@ +/* + * 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.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmNone implements CsmElement { + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java new file mode 100644 index 0000000..dc04e16 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.LinkedList; +import java.util.List; + +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; + +public class CsmOrphanCommentsEnding implements CsmElement { + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + List everything = new LinkedList<>(); + everything.addAll(node.getChildNodes()); + sortByBeginPosition(everything); + if (everything.isEmpty()) { + return; + } + + int commentsAtEnd = 0; + boolean findingComments = true; + while (findingComments && commentsAtEnd < everything.size()) { + Node last = everything.get(everything.size() - 1 - commentsAtEnd); + findingComments = (last instanceof Comment); + if (findingComments) { + commentsAtEnd++; + } + } + for (int i = 0; i < commentsAtEnd; i++) { + Comment c = (Comment)everything.get(everything.size() - commentsAtEnd + i); + CsmComment.process(c, printer); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java new file mode 100644 index 0000000..fcfd9ad --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + +import java.util.List; +import java.util.Objects; + +public class CsmSequence implements CsmElement { + private List elements; + + public CsmSequence(List elements) { + if (elements == null) { + throw new NullPointerException(); + } + if (elements.stream().anyMatch(Objects::isNull)) { + throw new IllegalArgumentException("Null element in the sequence"); + } + this.elements = elements; + } + + public List getElements() { + return elements; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + elements.forEach(e -> e.prettyPrint(node, printer)); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java new file mode 100644 index 0000000..36211a1 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.ConcreteSyntaxModel; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmSingleReference implements CsmElement { + private final ObservableProperty property; + + public ObservableProperty getProperty() { + return property; + } + + public CsmSingleReference(ObservableProperty property) { + this.property = property; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + Node child = property.getValueAsSingleReference(node); + if (child != null) { + ConcreteSyntaxModel.genericPrettyPrint(child, printer); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java new file mode 100644 index 0000000..2fa0178 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmString implements CsmElement { + private final ObservableProperty property; + + public CsmString(ObservableProperty property) { + this.property = property; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + printer.print("\""); + printer.print(property.getValueAsStringAttribute(node)); + printer.print("\""); + } + + @Override + public String toString() { + return String.format("CsmString(property:%s)", property); + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java new file mode 100644 index 0000000..d0745f7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.concretesyntaxmodel; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; +import com.github.javaparser.TokenTypes; +import com.github.javaparser.utils.Utils; + +import static com.github.javaparser.TokenTypes.isEndOfLineToken; +import static com.github.javaparser.TokenTypes.isSpaceOrTab; + +public class CsmToken implements CsmElement { + private final int tokenType; + private String content; + private TokenContentCalculator tokenContentCalculator; + + public interface TokenContentCalculator { + String calculate(Node node); + } + + public int getTokenType() { + return tokenType; + } + + public String getContent(Node node) { + if (tokenContentCalculator != null) { + return tokenContentCalculator.calculate(node); + } + return content; + } + + public CsmToken(int tokenType) { + this.tokenType = tokenType; + this.content = GeneratedJavaParserConstants.tokenImage[tokenType]; + if (content.startsWith("\"")) { + content = content.substring(1, content.length() - 1); + } + if (isEndOfLineToken(tokenType)) { + content = Utils.EOL; + } else if (isSpaceOrTab(tokenType)) { + content = " "; + } + } + + public CsmToken(int tokenType, String content) { + this.tokenType = tokenType; + this.content = content; + } + + public CsmToken(int tokenType, TokenContentCalculator tokenContentCalculator) { + this.tokenType = tokenType; + this.tokenContentCalculator = tokenContentCalculator; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + if (isEndOfLineToken(tokenType)) { + printer.println(); + } else { + printer.print(getContent(node)); + } + } + + @Override + public String toString() { + return "token(" + content + ")"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CsmToken csmToken = (CsmToken) o; + + if (tokenType != csmToken.tokenType) return false; + if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) return false; + return tokenContentCalculator != null ? tokenContentCalculator.equals(csmToken.tokenContentCalculator) : csmToken.tokenContentCalculator == null; + } + + @Override + public int hashCode() { + int result = tokenType; + result = 31 * result + (content != null ? content.hashCode() : 0); + result = 31 * result + (tokenContentCalculator != null ? tokenContentCalculator.hashCode() : 0); + return result; + } + + public boolean isWhiteSpace() { + return TokenTypes.isWhitespace(tokenType); + } + + public boolean isNewLine() { + return TokenTypes.isEndOfLineToken(tokenType); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java new file mode 100644 index 0000000..bc4a001 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java @@ -0,0 +1,43 @@ +/* + * 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.printer.concretesyntaxmodel; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + +public class CsmUnindent implements CsmElement { + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + printer.unindent(); + } + + @Override + public int hashCode() { + return 2; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof CsmUnindent; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java new file mode 100644 index 0000000..626b0b8 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java @@ -0,0 +1,41 @@ +/* + * 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.printer.concretesyntaxmodel; + +import com.github.javaparser.printer.Printable; + +class PrintingHelper { + + static String printToString(Object value) { + if (value instanceof Printable) { + return ((Printable)value).asString(); + } + if (value instanceof Enum) { + return ((Enum) value).name().toLowerCase(); + } else { + if (value != null) { + return value.toString(); + } + } + return ""; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java new file mode 100644 index 0000000..ad890c4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java @@ -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.printer.lexicalpreservation; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.Comment; + +/** + * Represent the position of a child node in the NodeText of its parent. + */ +class ChildTextElement extends TextElement { + private final Node child; + + ChildTextElement(Node child) { + this.child = child; + } + + String expand() { + return LexicalPreservingPrinter.print(child); + } + + Node getChild() { + return child; + } + + @Override + boolean isToken(int tokenKind) { + return false; + } + + @Override + boolean isNode(Node node) { + return node == child; + } + + NodeText getNodeTextForWrappedNode() { + return LexicalPreservingPrinter.getOrCreateNodeText(child); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ChildTextElement that = (ChildTextElement) o; + + return child.equals(that.child); + + } + + @Override + public int hashCode() { + return child.hashCode(); + } + + @Override + public String toString() { + return "ChildTextElement{" + child + '}'; + } + + @Override + public boolean isWhiteSpace() { + return false; + } + + @Override + public boolean isSpaceOrTab() { + return false; + } + + @Override + public boolean isNewline() { + return false; + } + + @Override + public boolean isComment() { + return child instanceof Comment; + } + + @Override + public boolean isChildOfClass(Class nodeClass) { + return nodeClass.isInstance(child); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/Difference.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/Difference.java new file mode 100644 index 0000000..610f916 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -0,0 +1,885 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.TokenTypes; +import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; + +/** + * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements + * to remove or to add and follow by another sequence of elements. + * + * I should later be able to apply such difference to a nodeText. + */ +public class Difference { + + private static final int STANDARD_INDENTATION_SIZE = 4; + + private final List elements; + + private Difference(List elements) { + this.elements = elements; + } + + interface DifferenceElement { + static DifferenceElement added(CsmElement element) { + return new Added(element); + } + + static DifferenceElement removed(CsmElement element) { + return new Removed(element); + } + + static DifferenceElement kept(CsmElement element) { + return new Kept(element); + } + + /** + * Return the CsmElement considered in this DifferenceElement. + */ + CsmElement getElement(); + + boolean isAdded(); + } + + private static class Added implements DifferenceElement { + final CsmElement element; + + public Added(CsmElement element) { + this.element = element; + } + + @Override + public String toString() { + return "Added{" + element + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Added added = (Added) o; + + return element.equals(added.element); + } + + @Override + public int hashCode() { + return element.hashCode(); + } + + @Override + public CsmElement getElement() { + return element; + } + + @Override + public boolean isAdded() { + return true; + } + } + + /** + * Elements in a CsmMix have been reshuffled. It could also mean that + * some new elements have been added or removed to the mix. + */ + private static class Reshuffled implements DifferenceElement { + final CsmMix previousOrder; + final CsmMix element; + + public Reshuffled(CsmMix previousOrder, CsmMix element) { + this.previousOrder = previousOrder; + this.element = element; + } + + @Override + public String toString() { + return "Reshuffled{" + element + ", previous="+ previousOrder+ '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Reshuffled that = (Reshuffled) o; + + if (!previousOrder.equals(that.previousOrder)) return false; + return element.equals(that.element); + } + + @Override + public int hashCode() { + int result = previousOrder.hashCode(); + result = 31 * result + element.hashCode(); + return result; + } + + @Override + public CsmMix getElement() { + return element; + } + + @Override + public boolean isAdded() { + return false; + } + } + + private static class Kept implements DifferenceElement { + final CsmElement element; + + public Kept(CsmElement element) { + this.element = element; + } + + @Override + public String toString() { + return "Kept{" + element + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Kept kept = (Kept) o; + + return element.equals(kept.element); + } + + @Override + public int hashCode() { + return element.hashCode(); + } + + @Override + public CsmElement getElement() { + return element; + } + + @Override + public boolean isAdded() { + return false; + } + } + + private static class Removed implements DifferenceElement { + final CsmElement element; + + public Removed(CsmElement element) { + this.element = element; + } + + @Override + public String toString() { + return "Removed{" + element + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Removed removed = (Removed) o; + + return element.equals(removed.element); + } + + @Override + public int hashCode() { + return element.hashCode(); + } + + @Override + public CsmElement getElement() { + return element; + } + + @Override + public boolean isAdded() { + return false; + } + } + + private static boolean matching(CsmElement a, CsmElement b) { + if (a instanceof CsmChild) { + if (b instanceof CsmChild) { + CsmChild childA = (CsmChild) a; + CsmChild childB = (CsmChild) b; + return childA.getChild().equals(childB.getChild()); + } else if (b instanceof CsmToken) { + return false; + } else if (b instanceof CsmIndent) { + return false; + } else if (b instanceof CsmUnindent) { + return false; + } else { + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + } + } else if (a instanceof CsmToken) { + if (b instanceof CsmToken) { + CsmToken childA = (CsmToken)a; + CsmToken childB = (CsmToken)b; + return childA.getTokenType() == childB.getTokenType(); + } else if (b instanceof CsmChild) { + return false; + } else if (b instanceof CsmIndent) { + return false; + } else if (b instanceof CsmUnindent) { + return false; + } else { + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + } + } else if (a instanceof CsmIndent) { + return b instanceof CsmIndent; + } else if (a instanceof CsmUnindent) { + return b instanceof CsmUnindent; + } + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + } + + private static boolean replacement(CsmElement a, CsmElement b) { + if (a instanceof CsmIndent || b instanceof CsmIndent || a instanceof CsmUnindent || b instanceof CsmUnindent) { + return false; + } + if (a instanceof CsmChild) { + if (b instanceof CsmChild) { + CsmChild childA = (CsmChild) a; + CsmChild childB = (CsmChild) b; + return childA.getChild().getClass().equals(childB.getChild().getClass()); + } else if (b instanceof CsmToken) { + return false; + } else { + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + } + } else if (a instanceof CsmToken) { + if (b instanceof CsmToken) { + CsmToken childA = (CsmToken)a; + CsmToken childB = (CsmToken)b; + return childA.getTokenType() == childB.getTokenType(); + } else if (b instanceof CsmChild) { + return false; + } + } + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + } + + /** + * Find the positions of all the given children. + */ + private static Map findChildrenPositions(LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel) { + Map positions = new HashMap<>(); + for (int i=0;i childrenInOriginal = findChildrenPositions(original); + Map childrenInAfter = findChildrenPositions(after); + + List commonChildren = new LinkedList<>(childrenInOriginal.keySet()); + commonChildren.retainAll(childrenInAfter.keySet()); + commonChildren.sort(Comparator.comparingInt(childrenInOriginal::get)); + + List elements = new LinkedList<>(); + + int originalIndex = 0; + int afterIndex = 0; + int commonChildrenIndex = 0; + while (commonChildrenIndex < commonChildren.size()) { + Node child = commonChildren.get(commonChildrenIndex++); + int posOfNextChildInOriginal = childrenInOriginal.get(child); + int posOfNextChildInAfter = childrenInAfter.get(child); + if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) { + elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter)).elements); + } + elements.add(new Kept(new CsmChild(child))); + originalIndex = posOfNextChildInOriginal + 1; + afterIndex = posOfNextChildInAfter + 1; + } + + if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) { + elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size())).elements); + } + return new Difference(elements); + } + + private static Difference calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { + List elements = new LinkedList<>(); + + int originalIndex = 0; + int afterIndex = 0; + + // We move through the two CalculatedSyntaxModel, moving both forward when we have a match + // and moving just one side forward when we have an element kept or removed + + do { + if (originalIndex < original.elements.size() && afterIndex >= after.elements.size()) { + elements.add(new Removed(original.elements.get(originalIndex))); + originalIndex++; + } else if (originalIndex >= original.elements.size() && afterIndex < after.elements.size()) { + elements.add(new Added(after.elements.get(afterIndex))); + afterIndex++; + } else { + CsmElement nextOriginal = original.elements.get(originalIndex); + CsmElement nextAfter = after.elements.get(afterIndex); + + if ((nextOriginal instanceof CsmMix) && (nextAfter instanceof CsmMix)) { + if (((CsmMix) nextAfter).getElements().equals(((CsmMix) nextOriginal).getElements())) { + // No reason to deal with a reshuffled, we are just going to keep everything as it is + ((CsmMix) nextAfter).getElements().forEach(el -> elements.add(new Kept(el))); + } else { + elements.add(new Reshuffled((CsmMix)nextOriginal, (CsmMix)nextAfter)); + } + originalIndex++; + afterIndex++; + } else if (matching(nextOriginal, nextAfter)) { + elements.add(new Kept(nextOriginal)); + originalIndex++; + afterIndex++; + } else if (replacement(nextOriginal, nextAfter)) { + elements.add(new Removed(nextOriginal)); + elements.add(new Added(nextAfter)); + originalIndex++; + afterIndex++; + } else { + // We can try to remove the element or add it and look which one leads to the lower difference + Difference adding = calculate(original.from(originalIndex), after.from(afterIndex + 1)); + Difference removing = null; + if (adding.cost() > 0) { + removing = calculate(original.from(originalIndex + 1), after.from(afterIndex)); + } + + if (removing == null || removing.cost() > adding.cost()) { + elements.add(new Added(nextAfter)); + afterIndex++; + } else { + elements.add(new Removed(nextOriginal)); + originalIndex++; + } + } + } + } while (originalIndex < original.elements.size() || afterIndex < after.elements.size()); + + return new Difference(elements); + } + + private TextElement toTextElement(CsmElement csmElement) { + if (csmElement instanceof CsmChild) { + return new ChildTextElement(((CsmChild) csmElement).getChild()); + } else if (csmElement instanceof CsmToken) { + return new TokenTextElement(((CsmToken) csmElement).getTokenType(), ((CsmToken) csmElement).getContent(null)); + } else { + throw new UnsupportedOperationException(csmElement.getClass().getSimpleName()); + } + } + + private List processIndentation(List indentation, List prevElements) { + List res = new LinkedList<>(); + res.addAll(indentation); + boolean afterNl = false; + for (TextElement e : prevElements) { + if (e.isNewline() || e.isToken(SINGLE_LINE_COMMENT)) { + res.clear(); + afterNl = true; + } else { + if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement)e).getTokenKind())) { + res.add(e); + } else { + afterNl = false; + } + } + } + return res; + } + + private List indentationBlock() { + List res = new LinkedList<>(); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); + return res; + } + + private int considerCleaningTheLine(NodeText nodeText, int nodeTextIndex) { + while (nodeTextIndex >=1 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { + nodeText.removeElement(nodeTextIndex - 1); + nodeTextIndex--; + } + return nodeTextIndex; + } + + private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) { + if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isToken(LBRACE)) { + return true; + } + if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { + return isAfterLBrace(nodeText, nodeTextIndex - 1); + } + return false; + } + + /** + * If we are at the beginning of a line, with just spaces or tabs before us we should force the space to be + * the same as the indentation. + */ + private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { + boolean hasOnlyWsBefore = true; + for (int i=nodeTextIndex; i >= 0 && hasOnlyWsBefore && i < nodeText.getElements().size(); i--) { + if (nodeText.getElements().get(i).isNewline()) { + break; + } + if (!nodeText.getElements().get(i).isSpaceOrTab()) { + hasOnlyWsBefore = false; + } + } + if (hasOnlyWsBefore) { + for (int i=nodeTextIndex; i >= 0 && i < nodeText.getElements().size(); i--) { + if (nodeText.getElements().get(i).isNewline()) { + break; + } + nodeText.removeElement(i); + } + } + return nodeTextIndex; + } + + /** + * Node that we have calculate the Difference we can apply to a concrete NodeText, modifying it according + * to the difference (adding and removing the elements provided). + */ + void apply(NodeText nodeText, Node node) { + if (nodeText == null) { + throw new NullPointerException(); + } + boolean addedIndentation = false; + List indentation = LexicalPreservingPrinter.findIndentation(node); + int diffIndex = 0; + int nodeTextIndex = 0; + do { + if (diffIndex < this.elements.size() && nodeTextIndex >= nodeText.getElements().size()) { + DifferenceElement diffEl = elements.get(diffIndex); + if (diffEl instanceof Kept) { + Kept kept = (Kept) diffEl; + if (kept.element instanceof CsmToken) { + CsmToken csmToken = (CsmToken) kept.element; + if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) { + diffIndex++; + } else { + throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " + + nodeText + ". Difference: " + this); + } + } else { + throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " + + nodeText + ". Difference: " + this); + } + } else if (diffEl instanceof Added) { + nodeText.addElement(nodeTextIndex, toTextElement(((Added) diffEl).element)); + nodeTextIndex++; + diffIndex++; + } else { + throw new UnsupportedOperationException(diffEl.getClass().getSimpleName()); + } + } else if (diffIndex >= this.elements.size() && nodeTextIndex < nodeText.getElements().size()) { + TextElement nodeTextEl = nodeText.getElements().get(nodeTextIndex); + if (nodeTextEl.isWhiteSpaceOrComment()) { + nodeTextIndex++; + } else { + throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " + + this + " " + nodeTextEl); + } + } else { + DifferenceElement diffEl = elements.get(diffIndex); + TextElement nodeTextEl = nodeText.getElements().get(nodeTextIndex); + if (diffEl instanceof Added) { + CsmElement addedElement = ((Added) diffEl).element; + if (addedElement instanceof CsmIndent) { + for (int i=0;i 0 && nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { + for (TextElement e : processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1))) { + nodeText.addElement(nodeTextIndex++, e); + } + } else if (isAfterLBrace(nodeText, nodeTextIndex) && !isAReplacement(diffIndex)) { + if (textElement.isNewline()) { + used = true; + } + nodeText.addElement(nodeTextIndex++, new TokenTextElement(TokenTypes.eolTokenKind())); + // This remove the space in "{ }" when adding a new line + while (nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { + nodeText.getElements().remove(nodeTextIndex); + } + for (TextElement e : processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1))) { + nodeText.addElement(nodeTextIndex++, e); + } + // Indentation is painful... + // Sometimes we want to force indentation: this is the case when indentation was expected but + // was actually not there. For example if we have "{ }" we would expect indentation but it is + // not there, so when adding new elements we force it. However if the indentation has been + // inserted by us in this transformation we do not want to insert it again + if (!addedIndentation) { + for (TextElement e : indentationBlock()) { + nodeText.addElement(nodeTextIndex++, e); + } + } + } + if (!used) { + nodeText.addElement(nodeTextIndex, textElement); + nodeTextIndex++; + } + if (textElement.isNewline()) { + boolean followedByUnindent = (diffIndex + 1) < elements.size() + && elements.get(diffIndex + 1).isAdded() + && elements.get(diffIndex + 1).getElement() instanceof CsmUnindent; + nodeTextIndex = adjustIndentation(indentation, nodeText, nodeTextIndex, followedByUnindent/* && !addedIndentation*/); + } + diffIndex++; + } else if (diffEl instanceof Kept) { + Kept kept = (Kept)diffEl; + if (nodeTextEl.isComment()) { + nodeTextIndex++; + } else if ((kept.element instanceof CsmChild) && nodeTextEl instanceof ChildTextElement) { + diffIndex++; + nodeTextIndex++; + } else if ((kept.element instanceof CsmChild) && nodeTextEl instanceof TokenTextElement) { + if (nodeTextEl.isWhiteSpaceOrComment()) { + nodeTextIndex++; + } else { + if (kept.element instanceof CsmChild) { + CsmChild keptChild = (CsmChild)kept.element; + if (keptChild.getChild() instanceof PrimitiveType) { + nodeTextIndex++; + diffIndex++; + } else { + throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl); + } + } else { + throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl); + } + } + } else if ((kept.element instanceof CsmToken) && nodeTextEl instanceof TokenTextElement) { + CsmToken csmToken = (CsmToken) kept.element; + TokenTextElement nodeTextToken = (TokenTextElement) nodeTextEl; + if (csmToken.getTokenType() == nodeTextToken.getTokenKind()) { + nodeTextIndex++; + diffIndex++; + } else if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) { + diffIndex++; + } else if (nodeTextToken.isWhiteSpaceOrComment()) { + nodeTextIndex++; + } else { + throw new UnsupportedOperationException("Csm token " + csmToken + " NodeText TOKEN " + nodeTextToken); + } + } else if ((kept.element instanceof CsmToken) && ((CsmToken) kept.element).isWhiteSpace()) { + diffIndex++; + } else if (kept.element instanceof CsmIndent) { + // Nothing to do + diffIndex++; + } else if (kept.element instanceof CsmUnindent) { + // Nothing to do, beside considering indentation + diffIndex++; + for (int i = 0; i < STANDARD_INDENTATION_SIZE && nodeTextIndex >= 1 && nodeText.getTextElement(nodeTextIndex - 1).isSpaceOrTab(); i++) { + nodeText.removeElement(--nodeTextIndex); + } + } else { + throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl); + } + } else if (diffEl instanceof Removed) { + Removed removed = (Removed)diffEl; + if ((removed.element instanceof CsmChild) && nodeTextEl instanceof ChildTextElement) { + ChildTextElement actualChild = (ChildTextElement)nodeTextEl; + if (actualChild.isComment()) { + CsmChild csmChild = (CsmChild)removed.element; + // We expected to remove a proper node but we found a comment in between. + // If the comment is associated to the node we want to remove we remove it as well, otherwise we keep it + Comment comment = (Comment)actualChild.getChild(); + if (!comment.isOrphan() && comment.getCommentedNode().isPresent() && comment.getCommentedNode().get().equals(csmChild.getChild())) { + nodeText.removeElement(nodeTextIndex); + } else { + nodeTextIndex++; + } + } else { + nodeText.removeElement(nodeTextIndex); + if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isNewline()) { + nodeTextIndex = considerCleaningTheLine(nodeText, nodeTextIndex); + } else { + if (diffIndex + 1 >= this.getElements().size() || !(this.getElements().get(diffIndex + 1) instanceof Added)) { + nodeTextIndex = considerEnforcingIndentation(nodeText, nodeTextIndex); + } + // If in front we have one space and before also we had space let's drop one space + if (nodeText.getElements().size() > nodeTextIndex && nodeTextIndex > 0) { + if (nodeText.getElements().get(nodeTextIndex).isWhiteSpace() + && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace()) { + // However we do not want to do that when we are about to adding or removing elements + if ((diffIndex + 1) == this.elements.size() || (elements.get(diffIndex + 1) instanceof Kept)) { + nodeText.getElements().remove(nodeTextIndex--); + } + } + } + } + diffIndex++; + } + } else if ((removed.element instanceof CsmToken) && nodeTextEl instanceof TokenTextElement + && ((CsmToken)removed.element).getTokenType() == ((TokenTextElement)nodeTextEl).getTokenKind()) { + nodeText.removeElement(nodeTextIndex); + diffIndex++; + } else if (nodeTextEl instanceof TokenTextElement + && nodeTextEl.isWhiteSpaceOrComment()) { + nodeTextIndex++; + } else if (removed.element instanceof CsmChild + && ((CsmChild)removed.element).getChild() instanceof PrimitiveType) { + if (isPrimitiveType(nodeTextEl)) { + nodeText.removeElement(nodeTextIndex); + diffIndex++; + } else { + throw new UnsupportedOperationException("removed " + removed.element + " vs " + nodeTextEl); + } + } else if (removed.element instanceof CsmToken && ((CsmToken)removed.element).isWhiteSpace()) { + diffIndex++; + } else if (nodeTextEl.isWhiteSpace()) { + nodeTextIndex++; + } else { + throw new UnsupportedOperationException("removed " + removed.element + " vs " + nodeTextEl); + } + } else if (diffEl instanceof Reshuffled) { + + // First, let's see how many tokens we need to attribute to the previous version of the of the CsmMix + Reshuffled reshuffled = (Reshuffled)diffEl; + CsmMix elementsFromPreviousOrder = reshuffled.previousOrder; + CsmMix elementsFromNextOrder = reshuffled.element; + + // This contains indexes from elementsFromNextOrder to indexes from elementsFromPreviousOrder + Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); + for (int ni=0;ni usedIndexes = new HashSet<>(); + List nodeTextIndexOfPreviousElements = elementsFromPreviousOrder.getElements().stream() + .map(it -> findIndexOfCorrespondingNodeTextElement(it, nodeText, startNodeTextIndex, usedIndexes, node)) + .collect(Collectors.toList()); + Map nodeTextIndexToPreviousCSMIndex = new HashMap<>(); + for (int i=0;i elementsToBeAddedAtTheEnd = new LinkedList<>(); + Map> elementsToAddBeforeGivenOriginalCSMElement = new HashMap<>(); + for (int ni=0;ni()); + } + elementsToAddBeforeGivenOriginalCSMElement.get(originalCsmIndex).add(elementsFromNextOrder.getElements().get(ni)); + } + } + // it does not preceed anything, so it goes at the end + if (originalCsmIndex == -1) { + elementsToBeAddedAtTheEnd.add(elementsFromNextOrder.getElements().get(ni)); + } + } + } + + // We go over the original node text elements, in the order they appear in the NodeText. + // Considering an original node text element (ONE) + // * we verify if it corresponds to a CSM element. If it does not we just move on, otherwise + // we find the correspond OCE (Original CSM Element) + // * we first add new elements that are marked to be added before OCE + // * if OCE is marked to be present also in the "after" CSM we add a kept element, + // otherwise we add a removed element + + this.getElements().remove(diffIndex); + int diffElIterator = diffIndex; + if (lastNodeTextIndex != -1) { + for (int ntIndex = startNodeTextIndex; ntIndex<=lastNodeTextIndex; ntIndex++) { + + if (nodeTextIndexToPreviousCSMIndex.containsKey(ntIndex)) { + int indexOfOriginalCSMElement = nodeTextIndexToPreviousCSMIndex.get(ntIndex); + if (elementsToAddBeforeGivenOriginalCSMElement.containsKey(indexOfOriginalCSMElement)) { + for (CsmElement elementToAdd : elementsToAddBeforeGivenOriginalCSMElement.get(indexOfOriginalCSMElement)) { + elements.add(diffElIterator++, new Added(elementToAdd)); + } + } + + CsmElement originalCSMElement = elementsFromPreviousOrder.getElements().get(indexOfOriginalCSMElement); + boolean toBeKept = correspondanceBetweenNextOrderAndPreviousOrder.containsValue(indexOfOriginalCSMElement); + if (toBeKept) { + elements.add(diffElIterator++, new Kept(originalCSMElement)); + } else { + elements.add(diffElIterator++, new Removed(originalCSMElement)); + } + } + // else we have a simple node text element, without associated csm element, just keep ignore it + } + } + + // Finally we look for the remaining new elements that were not yet added and + // add all of them + for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) { + elements.add(diffElIterator++, new Added(elementToAdd)); + } + } else { + throw new UnsupportedOperationException("" + diffEl + " vs " + nodeTextEl); + } + } + } while (diffIndex < this.elements.size() || nodeTextIndex < nodeText.getElements().size()); + } + + private int findIndexOfCorrespondingNodeTextElement(CsmElement csmElement, NodeText nodeText, int startIndex, Set usedIndexes, Node node) { + for (int i=startIndex;i indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) { + List indentationAdj = processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1)); + if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isToken(RBRACE)) { + indentationAdj = indentationAdj.subList(0, indentationAdj.size() - Math.min(STANDARD_INDENTATION_SIZE, indentationAdj.size())); + } else if (followedByUnindent) { + indentationAdj = indentationAdj.subList(0, Math.max(0, indentationAdj.size() - STANDARD_INDENTATION_SIZE)); + } + for (TextElement e : indentationAdj) { + if ((nodeTextIndex 0) && getElements().get(diffIndex) instanceof Added && getElements().get(diffIndex - 1) instanceof Removed; + } + + private boolean isPrimitiveType(TextElement textElement) { + if (textElement instanceof TokenTextElement) { + TokenTextElement tokenTextElement = (TokenTextElement)textElement; + int tokenKind = tokenTextElement.getTokenKind(); + return tokenKind == BYTE + || tokenKind == CHAR + || tokenKind == SHORT + || tokenKind == INT + || tokenKind == LONG + || tokenKind == FLOAT + || tokenKind == DOUBLE; + } else { + return false; + } + } + + private long cost() { + return elements.stream().filter(e -> !(e instanceof Kept)).count(); + } + + @Override + public String toString() { + return "Difference{" + elements + '}'; + } + + public List getElements() { + return elements; + } + + /** + * Remove from the difference all the elements related to indentation. + * This is mainly intended for test purposes. + */ + void removeIndentationElements() { + elements.removeIf(el -> el.getElement() instanceof CsmIndent || el.getElement() instanceof CsmUnindent); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java new file mode 100644 index 0000000..9263dfd --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java @@ -0,0 +1,332 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.ConcreteSyntaxModel; +import com.github.javaparser.printer.Printable; +import com.github.javaparser.printer.SourcePrinter; +import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.lexicalpreservation.changes.*; + +import java.util.*; + +class LexicalDifferenceCalculator { + + /** + * The ConcreteSyntaxModel represents the general format. This model is a calculated version of the ConcreteSyntaxModel, + * with no condition, no lists, just tokens and node children. + */ + static class CalculatedSyntaxModel { + final List elements; + + CalculatedSyntaxModel(List elements) { + this.elements = elements; + } + + public CalculatedSyntaxModel from(int index) { + List newList = new LinkedList<>(); + newList.addAll(elements.subList(index, elements.size())); + return new CalculatedSyntaxModel(newList); + } + + @Override + public String toString() { + return "CalculatedSyntaxModel{" + + "elements=" + elements + + '}'; + } + + CalculatedSyntaxModel sub(int start, int end) { + return new CalculatedSyntaxModel(elements.subList(start, end)); + } + + void removeIndentationElements() { + elements.removeIf(el -> el instanceof CsmIndent || el instanceof CsmUnindent); + } + } + + static class CsmChild implements CsmElement { + private final Node child; + + public Node getChild() { + return child; + } + + CsmChild(Node child) { + this.child = child; + } + + @Override + public void prettyPrint(Node node, SourcePrinter printer) { + throw new UnsupportedOperationException(); + } + + @Override + public String toString() { + return "child(" + child.getClass().getSimpleName()+")"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CsmChild csmChild = (CsmChild) o; + + return child.equals(csmChild.child); + } + + @Override + public int hashCode() { + return child.hashCode(); + } + } + + Difference calculateListRemovalDifference(ObservableProperty observableProperty, NodeList nodeList, int index) { + Node container = nodeList.getParentNodeForChildren(); + CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); + CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); + CalculatedSyntaxModel after = calculatedSyntaxModelAfterListRemoval(element, observableProperty, nodeList, index); + return Difference.calculate(original, after); + } + + Difference calculateListAdditionDifference(ObservableProperty observableProperty, NodeList nodeList, int index, Node nodeAdded) { + Node container = nodeList.getParentNodeForChildren(); + CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); + CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); + CalculatedSyntaxModel after = calculatedSyntaxModelAfterListAddition(element, observableProperty, nodeList, index, nodeAdded); + return Difference.calculate(original, after); + } + + Difference calculateListReplacementDifference(ObservableProperty observableProperty, NodeList nodeList, int index, Node newValue) { + Node container = nodeList.getParentNodeForChildren(); + CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); + CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); + CalculatedSyntaxModel after = calculatedSyntaxModelAfterListReplacement(element, observableProperty, nodeList, index, newValue); + return Difference.calculate(original, after); + } + + public void calculatePropertyChange(NodeText nodeText, Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + if (nodeText == null) { + throw new NullPointerException(); + } + CsmElement element = ConcreteSyntaxModel.forClass(observedNode.getClass()); + CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, observedNode); + CalculatedSyntaxModel after = calculatedSyntaxModelAfterPropertyChange(element, observedNode, property, oldValue, newValue); + Difference difference = Difference.calculate(original, after); + difference.apply(nodeText, observedNode); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelForNode(CsmElement csm, Node node) { + List elements = new LinkedList<>(); + calculatedSyntaxModelForNode(csm, node, elements, new NoChange()); + return new CalculatedSyntaxModel(elements); + } + + CalculatedSyntaxModel calculatedSyntaxModelForNode(Node node) { + return calculatedSyntaxModelForNode(ConcreteSyntaxModel.forClass(node.getClass()), node); + } + + private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List elements, Change change) { + if (csm instanceof CsmSequence) { + CsmSequence csmSequence = (CsmSequence) csm; + csmSequence.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, elements, change)); + } else if (csm instanceof CsmComment) { + // nothing to do + } else if (csm instanceof CsmSingleReference) { + CsmSingleReference csmSingleReference = (CsmSingleReference)csm; + Node child; + if (change instanceof PropertyChange && ((PropertyChange)change).getProperty() == csmSingleReference.getProperty()) { + child = (Node)((PropertyChange)change).getNewValue(); + } else { + child = csmSingleReference.getProperty().getValueAsSingleReference(node); + } + if (child != null) { + elements.add(new CsmChild(child)); + } + } else if (csm instanceof CsmNone) { + // nothing to do + } else if (csm instanceof CsmToken) { + elements.add(csm); + } else if (csm instanceof CsmOrphanCommentsEnding) { + // nothing to do + } else if (csm instanceof CsmList) { + CsmList csmList = (CsmList) csm; + if (csmList.getProperty().isAboutNodes()) { + Object rawValue = change.getValue(csmList.getProperty(), node); + NodeList nodeList; + if (rawValue instanceof Optional) { + Optional optional = (Optional)rawValue; + if (optional.isPresent()) { + if (!(optional.get() instanceof NodeList)) { + throw new IllegalStateException("Expected NodeList, found " + optional.get().getClass().getCanonicalName()); + } + nodeList = (NodeList) optional.get(); + } else { + nodeList = new NodeList(); + } + } else { + if (!(rawValue instanceof NodeList)) { + throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); + } + nodeList = (NodeList) rawValue; + } + if (!nodeList.isEmpty()) { + calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change); + for (int i = 0; i < nodeList.size(); i++) { + if (i != 0) { + calculatedSyntaxModelForNode(csmList.getSeparatorPre(), node, elements, change); + } + elements.add(new CsmChild(nodeList.get(i))); + if (i != (nodeList.size() - 1)) { + calculatedSyntaxModelForNode(csmList.getSeparatorPost(), node, elements, change); + } + + } + calculatedSyntaxModelForNode(csmList.getFollowing(), node, elements, change); + } + } else { + Collection collection = (Collection) change.getValue(csmList.getProperty(), node); + if (!collection.isEmpty()) { + calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change); + + boolean first = true; + for (Iterator it = collection.iterator(); it.hasNext(); ) { + if (!first) { + calculatedSyntaxModelForNode(csmList.getSeparatorPre(), node, elements, change); + } + Object value = it.next(); + if (value instanceof Modifier) { + Modifier modifier = (Modifier)value; + elements.add(new CsmToken(toToken(modifier))); + } else { + throw new UnsupportedOperationException(it.next().getClass().getSimpleName()); + } + if (it.hasNext()) { + calculatedSyntaxModelForNode(csmList.getSeparatorPost(), node, elements, change); + } + first = false; + } + calculatedSyntaxModelForNode(csmList.getFollowing(), node, elements, change); + } + } + } else if (csm instanceof CsmConditional) { + CsmConditional csmConditional = (CsmConditional) csm; + boolean satisfied = change.evaluate(csmConditional, node); + if (satisfied) { + calculatedSyntaxModelForNode(csmConditional.getThenElement(), node, elements, change); + } else { + calculatedSyntaxModelForNode(csmConditional.getElseElement(), node, elements, change); + } + } else if (csm instanceof CsmIndent) { + elements.add(csm); + } else if (csm instanceof CsmUnindent) { + elements.add(csm); + } else if (csm instanceof CsmAttribute) { + CsmAttribute csmAttribute = (CsmAttribute) csm; + Object value = change.getValue(csmAttribute.getProperty(), node); + String text = value.toString(); + if (value instanceof Printable) { + text = ((Printable) value).asString(); + } + elements.add(new CsmToken(csmAttribute.getTokenType(node, value.toString()), text)); + } else if ((csm instanceof CsmString) && (node instanceof StringLiteralExpr)) { + elements.add(new CsmToken(GeneratedJavaParserConstants.STRING_LITERAL, + "\"" + ((StringLiteralExpr) node).getValue() + "\"")); + } else if (csm instanceof CsmMix) { + CsmMix csmMix = (CsmMix)csm; + List mixElements = new LinkedList<>(); + csmMix.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, mixElements, change)); + elements.add(new CsmMix(mixElements)); + } else { + throw new UnsupportedOperationException(csm.getClass().getSimpleName()+ " " + csm); + } + } + + private int toToken(Modifier modifier) { + switch (modifier) { + case PUBLIC: + return GeneratedJavaParserConstants.PUBLIC; + case PRIVATE: + return GeneratedJavaParserConstants.PRIVATE; + case PROTECTED: + return GeneratedJavaParserConstants.PROTECTED; + case STATIC: + return GeneratedJavaParserConstants.STATIC; + case FINAL: + return GeneratedJavaParserConstants.FINAL; + case ABSTRACT: + return GeneratedJavaParserConstants.ABSTRACT; + default: + throw new UnsupportedOperationException(modifier.name()); + } + } + + /// + /// Methods that calculate CalculatedSyntaxModel + /// + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(Node node, ObservableProperty property, Object oldValue, Object newValue) { + return calculatedSyntaxModelAfterPropertyChange(ConcreteSyntaxModel.forClass(node.getClass()), node, property, oldValue, newValue); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(CsmElement csm, Node node, ObservableProperty property, Object oldValue, Object newValue) { + List elements = new LinkedList<>(); + calculatedSyntaxModelForNode(csm, node, elements, new PropertyChange(property, oldValue, newValue)); + return new CalculatedSyntaxModel(elements); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index) { + List elements = new LinkedList<>(); + Node container = nodeList.getParentNodeForChildren(); + calculatedSyntaxModelForNode(csm, container, elements, new ListRemovalChange(observableProperty, index)); + return new CalculatedSyntaxModel(elements); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index, Node nodeAdded) { + List elements = new LinkedList<>(); + Node container = nodeList.getParentNodeForChildren(); + calculatedSyntaxModelForNode(csm, container, elements, new ListAdditionChange(observableProperty, index, nodeAdded)); + return new CalculatedSyntaxModel(elements); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(Node container, ObservableProperty observableProperty, int index, Node nodeAdded) { + CsmElement csm = ConcreteSyntaxModel.forClass(container.getClass()); + Object rawValue = observableProperty.getRawValue(container); + if (!(rawValue instanceof NodeList)) { + throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); + } + NodeList nodeList = (NodeList)rawValue; + return calculatedSyntaxModelAfterListAddition(csm, observableProperty, nodeList, index, nodeAdded); + } + + // Visible for testing + CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(Node container, ObservableProperty observableProperty, int index) { + CsmElement csm = ConcreteSyntaxModel.forClass(container.getClass()); + Object rawValue = observableProperty.getRawValue(container); + if (!(rawValue instanceof NodeList)) { + throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); + } + NodeList nodeList = (NodeList)rawValue; + return calculatedSyntaxModelAfterListRemoval(csm, observableProperty, nodeList, index); + } + + // Visible for testing + private CalculatedSyntaxModel calculatedSyntaxModelAfterListReplacement(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index, Node newValue) { + List elements = new LinkedList<>(); + Node container = nodeList.getParentNodeForChildren(); + calculatedSyntaxModelForNode(csm, container, elements, new ListReplacementChange(observableProperty, index, newValue)); + return new CalculatedSyntaxModel(elements); + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java new file mode 100644 index 0000000..67f047f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -0,0 +1,513 @@ +/* + * 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.printer.lexicalpreservation; + +import com.github.javaparser.*; +import com.github.javaparser.ast.DataKey; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.observer.AstObserver; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.ast.observer.PropagatingAstObserver; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.visitor.TreeVisitor; +import com.github.javaparser.printer.ConcreteSyntaxModel; +import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; +import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; +import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; +import com.github.javaparser.utils.Pair; +import com.github.javaparser.utils.Utils; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; +import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static com.github.javaparser.utils.Utils.decapitalize; +import static java.util.Comparator.*; + +/** + * A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when + * operating on the AST and then used them to reproduce the source code + * in its original formatting including the AST changes. + */ +public class LexicalPreservingPrinter { + + /** + * The nodetext for a node is stored in the node's data field. This is the key to set and retrieve it. + */ + public static final DataKey NODE_TEXT_DATA = new DataKey() { + }; + + // + // Factory methods + // + + /** + * Parse the code and setup the LexicalPreservingPrinter. + * + * @deprecated use setup(Node) and the static methods on this class. + */ + public static Pair, LexicalPreservingPrinter> setup(ParseStart parseStart, + Provider provider) { + ParseResult parseResult = new JavaParser().parse(parseStart, provider); + if (!parseResult.isSuccessful()) { + throw new RuntimeException("Parsing failed, unable to setup the lexical preservation printer: " + + parseResult.getProblems()); + } + LexicalPreservingPrinter lexicalPreservingPrinter = new LexicalPreservingPrinter(parseResult.getResult().get()); + return new Pair<>(parseResult, lexicalPreservingPrinter); + } + + /** + * Prepares the node so it can be used in the print methods. + * The correct order is: + *

    + *
  1. Parse some code
  2. + *
  3. Call this setup method on the result
  4. + *
  5. Make changes to the AST as desired
  6. + *
  7. Use one of the print methods on this class to print out the original source code with your changes added
  8. + *
+ * + * @return the node passed as a parameter for your convenience. + */ + public static N setup(N node) { + assertNotNull(node); + + node.getTokenRange().ifPresent(r -> { + storeInitialText(node); + + // Setup observer + AstObserver observer = createObserver(); + + node.registerForSubtree(observer); + }); + return node; + } + + // + // Constructor and setup + // + + /** + * @deprecated use setup(Node) to prepare a node for lexical preservation, + * then use the static methods on this class to print it. + */ + @Deprecated + public LexicalPreservingPrinter(Node node) { + setup(node); + } + + private static AstObserver createObserver() { + return new PropagatingAstObserver() { + @Override + public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { + // Not really a change, ignoring + if ((oldValue != null && oldValue.equals(newValue)) || (oldValue == null && newValue == null)) { + return; + } + if (property == ObservableProperty.RANGE || property == ObservableProperty.COMMENTED_NODE) { + return; + } + if (property == ObservableProperty.COMMENT) { + if (!observedNode.getParentNode().isPresent()) { + throw new IllegalStateException(); + } + NodeText nodeText = getOrCreateNodeText(observedNode.getParentNode().get()); + if (oldValue == null) { + // Find the position of the comment node and put in front of it the comment and a newline + int index = nodeText.findChild(observedNode); + nodeText.addChild(index, (Comment) newValue); + nodeText.addToken(index + 1, eolTokenKind(), Utils.EOL); + } else if (newValue == null) { + if (oldValue instanceof JavadocComment) { + JavadocComment javadocComment = (JavadocComment) oldValue; + List matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT) + && ((TokenTextElement) e).getText().equals("/**" + javadocComment.getContent() + "*/")).map(e -> (TokenTextElement) e).collect(Collectors.toList()); + if (matchingTokens.size() != 1) { + throw new IllegalStateException(); + } + int index = nodeText.findElement(matchingTokens.get(0)); + nodeText.removeElement(index); + if (nodeText.getElements().get(index).isNewline()) { + nodeText.removeElement(index); + } + } else { + throw new UnsupportedOperationException(); + } + } else { + if (oldValue instanceof JavadocComment) { + JavadocComment oldJavadocComment = (JavadocComment) oldValue; + List matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT) + && ((TokenTextElement) e).getText().equals("/**" + oldJavadocComment.getContent() + "*/")).map(e -> (TokenTextElement) e).collect(Collectors.toList()); + if (matchingTokens.size() != 1) { + throw new IllegalStateException(); + } + JavadocComment newJavadocComment = (JavadocComment) newValue; + nodeText.replace(matchingTokens.get(0), new TokenTextElement(JAVADOC_COMMENT, "/**" + newJavadocComment.getContent() + "*/")); + } else { + throw new UnsupportedOperationException(); + } + } + } + NodeText nodeText = getOrCreateNodeText(observedNode); + + if (nodeText == null) { + throw new NullPointerException(observedNode.getClass().getSimpleName()); + } + + new LexicalDifferenceCalculator().calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue); + } + + @Override + public void concreteListChange(NodeList changedList, ListChangeType type, int index, Node nodeAddedOrRemoved) { + NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren()); + if (type == ListChangeType.REMOVAL) { + new LexicalDifferenceCalculator().calculateListRemovalDifference(findNodeListName(changedList), changedList, index).apply(nodeText, changedList.getParentNodeForChildren()); + } else if (type == ListChangeType.ADDITION) { + new LexicalDifferenceCalculator().calculateListAdditionDifference(findNodeListName(changedList), changedList, index, nodeAddedOrRemoved).apply(nodeText, changedList.getParentNodeForChildren()); + } else { + throw new UnsupportedOperationException(); + } + } + + @Override + public void concreteListReplacement(NodeList changedList, int index, Node oldValue, Node newValue) { + NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren()); + new LexicalDifferenceCalculator().calculateListReplacementDifference(findNodeListName(changedList), changedList, index, newValue).apply(nodeText, changedList.getParentNodeForChildren()); + } + }; + } + + private static void storeInitialText(Node root) { + Map> tokensByNode = new IdentityHashMap<>(); + + // We go over tokens and find to which nodes they belong. Note that we do not traverse the tokens as they were + // on a list but as they were organized in a tree. At each time we select only the branch corresponding to the + // range of interest and ignore all other branches + for (JavaToken token : root.getTokenRange().get()) { + Range tokenRange = token.getRange().orElseThrow(() -> new RuntimeException("Token without range: " + token)); + Node owner = findNodeForToken(root, tokenRange); + if (owner == null) { + throw new RuntimeException("Token without node owning it: " + token); + } + if (!tokensByNode.containsKey(owner)) { + tokensByNode.put(owner, new LinkedList<>()); + } + tokensByNode.get(owner).add(token); + } + + // Now that we know the tokens we use them to create the initial NodeText for each node + new TreeVisitor() { + @Override + public void process(Node node) { + if (!PhantomNodeLogic.isPhantomNode(node)) { + LexicalPreservingPrinter.storeInitialTextForOneNode(node, tokensByNode.get(node)); + } + } + }.visitBreadthFirst(root); + } + + private static Node findNodeForToken(Node node, Range tokenRange) { + if (PhantomNodeLogic.isPhantomNode(node)) { + return null; + } + if (node.getRange().get().contains(tokenRange)) { + for (Node child : node.getChildNodes()) { + Node found = findNodeForToken(child, tokenRange); + if (found != null) { + return found; + } + } + return node; + } else { + return null; + } + } + + private static void storeInitialTextForOneNode(Node node, List nodeTokens) { + if (nodeTokens == null) { + nodeTokens = Collections.emptyList(); + } + List> elements = new LinkedList<>(); + for (Node child : node.getChildNodes()) { + if (!PhantomNodeLogic.isPhantomNode(child)) { + if (!child.getRange().isPresent()) { + throw new RuntimeException("Range not present on node " + child); + } + elements.add(new Pair<>(child.getRange().get(), new ChildTextElement(child))); + } + } + for (JavaToken token : nodeTokens) { + elements.add(new Pair<>(token.getRange().get(), new TokenTextElement(token))); + } + elements.sort(comparing(e -> e.a.begin)); + node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(Collectors.toList()))); + } + + // + // Iterators + // + + private static Iterator tokensPreceeding(final Node node) { + if (!node.getParentNode().isPresent()) { + return new TextElementIteratorsFactory.EmptyIterator<>(); + } + // There is the awfully painful case of the fake types involved in variable declarators and + // fields or variable declaration that are, of course, an exception... + + NodeText parentNodeText = getOrCreateNodeText(node.getParentNode().get()); + int index = parentNodeText.tryToFindChild(node); + if (index == NodeText.NOT_FOUND) { + if (node.getParentNode().get() instanceof VariableDeclarator) { + return tokensPreceeding(node.getParentNode().get()); + } else { + throw new IllegalArgumentException( + String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", + node, node.getParentNode().get(), parentNodeText)); + } + } + + return new TextElementIteratorsFactory.CascadingIterator<>( + TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), + () -> tokensPreceeding(node.getParentNode().get())); + } + + // + // Printing methods + // + + /** + * Print a Node into a String, preserving the lexical information. + */ + public static String print(Node node) { + StringWriter writer = new StringWriter(); + try { + print(node, writer); + } catch (IOException e) { + throw new RuntimeException("Unexpected IOException on a StringWriter", e); + } + return writer.toString(); + } + + /** + * Print a Node into a Writer, preserving the lexical information. + */ + public static void print(Node node, Writer writer) throws IOException { + if (!node.containsData(NODE_TEXT_DATA)) { + getOrCreateNodeText(node); + } + final NodeText text = node.getData(NODE_TEXT_DATA); + writer.append(text.expand()); + } + + // + // Methods to handle transformations + // + + private static void prettyPrintingTextNode(Node node, NodeText nodeText) { + if (node instanceof PrimitiveType) { + PrimitiveType primitiveType = (PrimitiveType) node; + switch (primitiveType.getType()) { + case BOOLEAN: + nodeText.addToken(BOOLEAN, node.toString()); + break; + case CHAR: + nodeText.addToken(CHAR, node.toString()); + break; + case BYTE: + nodeText.addToken(BYTE, node.toString()); + break; + case SHORT: + nodeText.addToken(SHORT, node.toString()); + break; + case INT: + nodeText.addToken(INT, node.toString()); + break; + case LONG: + nodeText.addToken(LONG, node.toString()); + break; + case FLOAT: + nodeText.addToken(FLOAT, node.toString()); + break; + case DOUBLE: + nodeText.addToken(DOUBLE, node.toString()); + break; + default: + throw new IllegalArgumentException(); + } + return; + } + if (node instanceof JavadocComment) { + nodeText.addToken(JAVADOC_COMMENT, "/**" + ((JavadocComment) node).getContent() + "*/"); + return; + } + + interpret(node, ConcreteSyntaxModel.forClass(node.getClass()), nodeText); + } + + private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) { + LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(csm, node); + + List indentation = findIndentation(node); + + boolean pendingIndentation = false; + for (CsmElement element : calculatedSyntaxModel.elements) { + if (pendingIndentation && !(element instanceof CsmToken && ((CsmToken) element).isNewLine())) { + indentation.forEach(nodeText::addElement); + } + pendingIndentation = false; + if (element instanceof LexicalDifferenceCalculator.CsmChild) { + nodeText.addChild(((LexicalDifferenceCalculator.CsmChild) element).getChild()); + } else if (element instanceof CsmToken) { + CsmToken csmToken = (CsmToken) element; + nodeText.addToken(csmToken.getTokenType(), csmToken.getContent(node)); + if (csmToken.isNewLine()) { + pendingIndentation = true; + } + } else if (element instanceof CsmMix) { + CsmMix csmMix = (CsmMix) element; + csmMix.getElements().forEach(e -> interpret(node, e, nodeText)); + } else if (element instanceof CsmIndent) { + System.out.println("Warning: CsmIndent in lexical parser"); + } else if (element instanceof CsmUnindent) { + System.out.println("Warning: CsmUnindent in lexical parser"); + } else { + throw new UnsupportedOperationException(element.getClass().getSimpleName()); + } + } + // Array brackets are a pain... we do not have a way to represent them explicitly in the AST + // so they have to be handled in a special way + if (node instanceof VariableDeclarator) { + VariableDeclarator variableDeclarator = (VariableDeclarator) node; + variableDeclarator.getParentNode().ifPresent(parent -> + ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { + int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); + for (int i = 0; i < extraArrayLevels; i++) { + nodeText.addElement(new TokenTextElement(LBRACKET)); + nodeText.addElement(new TokenTextElement(RBRACKET)); + } + }) + ); + } + return nodeText; + } + + // Visible for testing + static NodeText getOrCreateNodeText(Node node) { + if (!node.containsData(NODE_TEXT_DATA)) { + NodeText nodeText = new NodeText(); + node.setData(NODE_TEXT_DATA, nodeText); + prettyPrintingTextNode(node, nodeText); + } + return node.getData(NODE_TEXT_DATA); + } + + // Visible for testing + static List findIndentation(Node node) { + List followingNewlines = new LinkedList<>(); + Iterator it = tokensPreceeding(node); + while (it.hasNext()) { + TokenTextElement tte = it.next(); + if (tte.getTokenKind() == SINGLE_LINE_COMMENT + || tte.isNewline()) { + break; + } else { + followingNewlines.add(tte); + } + } + Collections.reverse(followingNewlines); + for (int i = 0; i < followingNewlines.size(); i++) { + if (!followingNewlines.get(i).isSpaceOrTab()) { + return followingNewlines.subList(0, i); + } + } + return followingNewlines; + } + + // + // Helper methods + // + + private static boolean isReturningOptionalNodeList(Method m) { + if (!m.getReturnType().getCanonicalName().equals(Optional.class.getCanonicalName())) { + return false; + } + if (!(m.getGenericReturnType() instanceof ParameterizedType)) { + return false; + } + ParameterizedType parameterizedType = (ParameterizedType) m.getGenericReturnType(); + java.lang.reflect.Type optionalArgument = parameterizedType.getActualTypeArguments()[0]; + return (optionalArgument.getTypeName().startsWith(NodeList.class.getCanonicalName())); + } + + private static ObservableProperty findNodeListName(NodeList nodeList) { + Node parent = nodeList.getParentNodeForChildren(); + for (Method m : parent.getClass().getMethods()) { + if (m.getParameterCount() == 0 && m.getReturnType().getCanonicalName().equals(NodeList.class.getCanonicalName())) { + try { + Object raw = m.invoke(parent); + if (!(raw instanceof NodeList)) { + throw new IllegalStateException("Expected NodeList, found " + raw.getClass().getCanonicalName()); + } + NodeList result = (NodeList) raw; + if (result == nodeList) { + String name = m.getName(); + if (name.startsWith("get")) { + name = name.substring("get".length()); + } + return ObservableProperty.fromCamelCaseName(decapitalize(name)); + } + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } else if (m.getParameterCount() == 0 && isReturningOptionalNodeList(m)) { + try { + Optional> raw = (Optional>) m.invoke(parent); + if (raw.isPresent() && raw.get() == nodeList) { + String name = m.getName(); + if (name.startsWith("get")) { + name = name.substring("get".length()); + } + return ObservableProperty.fromCamelCaseName(decapitalize(name)); + } + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + } + throw new IllegalArgumentException("Cannot find list name of NodeList of size " + nodeList.size()); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/NodeText.java new file mode 100644 index 0000000..1be264e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/NodeText.java @@ -0,0 +1,217 @@ +/* + * 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.printer.lexicalpreservation; + +import com.github.javaparser.ast.Node; + +import java.util.LinkedList; +import java.util.List; + +/** + * This contains the lexical information for a single node. + * It is basically a list of tokens and children. + */ +class NodeText { + private final List elements; + + public static final int NOT_FOUND = -1; + + enum Option { + REMOVE_SPACE_IMMEDIATELY_AFTER, + EXCLUDE_START, + EXCLUDE_END + } + + // + // Constructors + // + + NodeText(List elements) { + this.elements = elements; + } + + /** + * Initialize with an empty list of elements. + */ + NodeText() { + this(new LinkedList<>()); + } + + // + // Adding elements + // + + /** + * Add an element at the end. + */ + void addElement(TextElement nodeTextElement) { + this.elements.add(nodeTextElement); + } + + /** + * Add an element at the given position. + */ + void addElement(int index, TextElement nodeTextElement) { + this.elements.add(index, nodeTextElement); + } + + void addChild(Node child) { + addElement(new ChildTextElement(child)); + } + + void addChild(int index, Node child) { + addElement(index, new ChildTextElement(child)); + } + + void addToken(int tokenKind, String text) { + elements.add(new TokenTextElement(tokenKind, text)); + } + + void addToken(int index, int tokenKind, String text) { + elements.add(index, new TokenTextElement(tokenKind, text)); + } + + // + // Finding elements + // + + int findElement(TextElementMatcher matcher) { + return findElement(matcher, 0); + } + + int findElement(TextElementMatcher matcher, int from) { + int res = tryToFindElement(matcher, from); + if (res == NOT_FOUND) { + throw new IllegalArgumentException( + String.format("I could not find child '%s' from position %d. Elements: %s", + matcher, from, elements)); + } else { + return res; + } + } + + int tryToFindElement(TextElementMatcher matcher, int from) { + for (int i=from; i sb.append(e.expand())); + return sb.toString(); + } + + // Visible for testing + int numberOfElements() { + return elements.size(); + } + + // Visible for testing + TextElement getTextElement(int index) { + return elements.get(index); + } + + // Visible for testing + List getElements() { + return elements; + } + + @Override + public String toString() { + return "NodeText{" + elements + '}'; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java new file mode 100644 index 0000000..d17f768 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java @@ -0,0 +1,74 @@ +/* + * 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.printer.lexicalpreservation; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.AstObserver; +import com.github.javaparser.ast.observer.AstObserverAdapter; +import com.github.javaparser.ast.type.UnknownType; + +import java.util.IdentityHashMap; +import java.util.Map; + +import static java.util.Collections.synchronizedMap; + +/** + * We want to recognize and ignore "phantom" nodes, like the fake type of variable in FieldDeclaration + */ +class PhantomNodeLogic { + + private static final int LEVELS_TO_EXPLORE = 3; + + private static final Map isPhantomNodeCache = synchronizedMap(new IdentityHashMap<>()); + + private static final AstObserver cacheCleaner = new AstObserverAdapter() { + @Override + public void parentChange(Node observedNode, Node previousParent, Node newParent) { + isPhantomNodeCache.remove(observedNode); + } + }; + + static boolean isPhantomNode(Node node) { + if (isPhantomNodeCache.containsKey(node)) { + return isPhantomNodeCache.get(node); + } else { + if (node instanceof UnknownType) { + return true; + } + boolean res = (node.getParentNode().isPresent() && + !node.getParentNode().get().getRange().get().contains(node.getRange().get()) + || inPhantomNode(node, LEVELS_TO_EXPLORE)); + isPhantomNodeCache.put(node, res); + node.register(cacheCleaner); + return res; + } + } + + /** + * A node contained in a phantom node is also a phantom node. We limit how many levels up we check just for performance reasons. + */ + private static boolean inPhantomNode(Node node, int levels) { + return node.getParentNode().isPresent() && + (isPhantomNode(node.getParentNode().get()) + || inPhantomNode(node.getParentNode().get(), levels - 1)); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElement.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElement.java new file mode 100644 index 0000000..987b8f2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElement.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import com.github.javaparser.GeneratedJavaParserConstants; +import com.github.javaparser.ast.Node; + +public abstract class TextElement implements TextElementMatcher { + + abstract String expand(); + + abstract boolean isToken(int tokenKind); + + final boolean isCommentToken() { + return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) + || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) + || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); + } + + @Override + public boolean match(TextElement textElement) { + return this.equals(textElement); + } + + abstract boolean isNode(Node node); + + public abstract boolean isWhiteSpace(); + + public abstract boolean isSpaceOrTab(); + + public abstract boolean isNewline(); + + public abstract boolean isComment(); + + public final boolean isWhiteSpaceOrComment() { + return isWhiteSpace() || isComment(); + } + + /** + * Is this TextElement representing a child of the given class? + */ + public abstract boolean isChildOfClass(Class nodeClass); +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java new file mode 100644 index 0000000..b2e29b4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java @@ -0,0 +1,189 @@ +/* + * 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.printer.lexicalpreservation; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +class TextElementIteratorsFactory { + + static class CascadingIterator implements Iterator { + interface Provider { + Iterator provide(); + } + + private final Provider nextProvider; + private Iterator current; + private Iterator next; + private boolean lastReturnedFromCurrent = false; + private boolean lastReturnedFromNext = false; + + public CascadingIterator(Iterator current, Provider nextProvider) { + this.nextProvider = nextProvider; + this.current = current; + } + + + @Override + public boolean hasNext() { + if (current.hasNext()) { + return true; + } + if (next == null) { + next = nextProvider.provide(); + } + return next.hasNext(); + } + + @Override + public E next() { + if (current.hasNext()) { + lastReturnedFromCurrent = true; + lastReturnedFromNext = false; + return current.next(); + } + if (next == null) { + next = nextProvider.provide(); + } + lastReturnedFromCurrent = false; + lastReturnedFromNext = true; + return next.next(); + } + + @Override + public void remove() { + if (lastReturnedFromCurrent) { + current.remove(); + return; + } + if (lastReturnedFromNext) { + next.remove(); + return; + } + throw new IllegalArgumentException(); + } + } + + static class EmptyIterator implements Iterator { + @Override + public boolean hasNext() { + return false; + } + + @Override + public E next() { + throw new IllegalArgumentException(); + } + } + + private static class SingleElementIterator implements Iterator { + private final E element; + private boolean returned; + + SingleElementIterator(E element) { + this.element = element; + } + + @Override + public boolean hasNext() { + return !returned; + } + + @Override + public E next() { + returned = true; + return element; + } + + @Override + public void remove() { + + } + } + + static class ComposedIterator implements Iterator { + private final List> elements; + private int currIndex; + + ComposedIterator(List> elements) { + this.elements = elements; + currIndex = 0; + } + + @Override + public boolean hasNext() { + if (currIndex >= elements.size()) { + return false; + } + if (elements.get(currIndex).hasNext()){ + return true; + } + currIndex++; + return hasNext(); + } + + @Override + public E next() { + if (!hasNext()) { + throw new IllegalArgumentException(); + } + return elements.get(currIndex).next(); + } + + @Override + public void remove() { + elements.get(currIndex).remove(); + } + } + + private static Iterator reverseIterator(NodeText nodeText, int index) { + TextElement textElement = nodeText.getTextElement(index); + if (textElement instanceof TokenTextElement) { + return new SingleElementIterator((TokenTextElement)textElement) { + @Override + public void remove() { + nodeText.removeElement(index); + } + }; + } else if (textElement instanceof ChildTextElement) { + ChildTextElement childTextElement = (ChildTextElement)textElement; + NodeText textForChild = childTextElement.getNodeTextForWrappedNode(); + return reverseIterator(textForChild); + } else { + throw new IllegalArgumentException(); + } + } + + public static Iterator reverseIterator(NodeText nodeText) { + return partialReverseIterator(nodeText, nodeText.numberOfElements() - 1); + } + + public static Iterator partialReverseIterator(NodeText nodeText, int fromIndex) { + List> elements = new LinkedList<>(); + for (int i=fromIndex;i>=0;i--) { + elements.add(reverseIterator(nodeText, i)); + } + return new ComposedIterator<>(elements); + } + +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java new file mode 100644 index 0000000..e522008 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java @@ -0,0 +1,28 @@ +/* + * 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.printer.lexicalpreservation; + +public interface TextElementMatcher { + + boolean match(TextElement textElement); + +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java new file mode 100644 index 0000000..f3e95b7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java @@ -0,0 +1,45 @@ +/* + * 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.printer.lexicalpreservation; + +import com.github.javaparser.ast.Node; + +class TextElementMatchers { + + static TextElementMatcher byTokenType(int tokenType) { + return textElement -> textElement.isToken(tokenType); + } + + static TextElementMatcher byNode(final Node node) { + return new TextElementMatcher() { + @Override + public boolean match(TextElement textElement) { + return textElement.isNode(node); + } + + @Override + public String toString() { + return "match node " + node; + } + }; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java new file mode 100644 index 0000000..e57b214 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import com.github.javaparser.JavaToken; +import com.github.javaparser.TokenTypes; +import com.github.javaparser.ast.Node; + +class TokenTextElement extends TextElement { + private final JavaToken token; + + TokenTextElement(JavaToken token) { + this.token = token; + } + + TokenTextElement(int tokenKind, String text) { + this(new JavaToken(tokenKind, text)); + } + + TokenTextElement(int tokenKind) { + this(new JavaToken(tokenKind)); + } + + @Override + String expand() { + return token.getText(); + } + + // Visible for testing + String getText() { + return token.getText(); + } + + public int getTokenKind() { + return token.getKind(); + } + + public JavaToken getToken() { + return token; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TokenTextElement that = (TokenTextElement) o; + + return token.equals(that.token); + } + + @Override + public int hashCode() { + return token.hashCode(); + } + + @Override + public String toString() { + return token.toString(); + } + + @Override + boolean isToken(int tokenKind) { + return token.getKind() == tokenKind; + } + + @Override + boolean isNode(Node node) { + return false; + } + + @Override + public boolean isWhiteSpace() { + return token.getCategory().isWhitespace(); + } + + @Override + public boolean isSpaceOrTab() { + return token.getCategory().isWhitespaceButNotEndOfLine(); + } + + @Override + public boolean isComment() { + return token.getCategory().isComment(); + } + + @Override + public boolean isNewline() { + return token.getCategory().isEndOfLine(); + } + + @Override + public boolean isChildOfClass(Class nodeClass) { + return false; + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/Change.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/Change.java new file mode 100644 index 0000000..23fe09d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/Change.java @@ -0,0 +1,29 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.concretesyntaxmodel.CsmConditional; +import com.github.javaparser.utils.Utils; + +/** + * This represent a change happened to a specific Node. + */ +public interface Change { + + default boolean evaluate(CsmConditional csmConditional, Node node) { + switch (csmConditional.getCondition()) { + case FLAG: + return (Boolean) getValue(csmConditional.getProperty(), node); + case IS_NOT_EMPTY: + return !Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node)); + case IS_EMPTY: + return Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node)); + case IS_PRESENT: + return !Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node)); + default: + throw new UnsupportedOperationException("" + csmConditional.getProperty() + " " + csmConditional.getCondition()); + } + } + + Object getValue(ObservableProperty property, Node node); +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java new file mode 100644 index 0000000..ab15cc5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java @@ -0,0 +1,37 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; + +/** + * The Addition of an element to a list. + */ +public class ListAdditionChange implements Change { + private final ObservableProperty observableProperty; + private final int index; + private final Node nodeAdded; + + public ListAdditionChange(ObservableProperty observableProperty, int index, Node nodeAdded) { + this.observableProperty = observableProperty; + this.index = index; + this.nodeAdded = nodeAdded; + } + + @Override + public Object getValue(ObservableProperty property, Node node) { + if (property == observableProperty) { + NodeList nodeList = new NodeList<>(); + Object currentRawValue = new NoChange().getValue(property, node); + if (!(currentRawValue instanceof NodeList)){ + throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); + } + NodeList currentNodeList = (NodeList)(currentRawValue); + nodeList.addAll(currentNodeList); + nodeList.add(index, nodeAdded); + return nodeList; + } else { + return new NoChange().getValue(property, node); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java new file mode 100644 index 0000000..c99efd2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java @@ -0,0 +1,35 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; + +/** + * The removal of an element in a list. + */ +public class ListRemovalChange implements Change { + private final ObservableProperty observableProperty; + private final int index; + + public ListRemovalChange(ObservableProperty observableProperty, int index) { + this.observableProperty = observableProperty; + this.index = index; + } + + @Override + public Object getValue(ObservableProperty property, Node node) { + if (property == observableProperty) { + NodeList nodeList = new NodeList<>(); + Object currentRawValue = new NoChange().getValue(property, node); + if (!(currentRawValue instanceof NodeList)){ + throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); + } + NodeList currentNodeList = (NodeList)currentRawValue; + nodeList.addAll(currentNodeList); + nodeList.remove(index); + return nodeList; + } else { + return new NoChange().getValue(property, node); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java new file mode 100644 index 0000000..ccb0ead --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java @@ -0,0 +1,44 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.utils.Pair; + +import java.util.Optional; + +/** + * The replacement of an element in a list. + */ +public class ListReplacementChange implements Change { + private final ObservableProperty observableProperty; + private final int index; + private final Node newValue; + + public ListReplacementChange(ObservableProperty observableProperty, int index, Node newValue) { + this.observableProperty = observableProperty; + this.index = index; + this.newValue = newValue; + } + + @Override + public Object getValue(ObservableProperty property, Node node) { + if (property == observableProperty) { + NodeList nodeList = new NodeList(); + Object currentRawValue = new NoChange().getValue(property, node); + if (currentRawValue instanceof Optional) { + Optional optional = (Optional)currentRawValue; + currentRawValue = optional.orElseGet(null); + } + if (!(currentRawValue instanceof NodeList)){ + throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); + } + NodeList currentNodeList = (NodeList)currentRawValue; + nodeList.addAll(currentNodeList); + nodeList.set(index, newValue); + return nodeList; + } else { + return new NoChange().getValue(property, node); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java new file mode 100644 index 0000000..6b29e3e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java @@ -0,0 +1,15 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; + +/** + * No change. The Node is not mutated. + */ +public class NoChange implements Change { + + @Override + public Object getValue(ObservableProperty property, Node node) { + return property.getRawValue(node); + } +} diff --git a/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java new file mode 100644 index 0000000..37b3a6f --- /dev/null +++ b/JavaParser/src/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java @@ -0,0 +1,40 @@ +package com.github.javaparser.printer.lexicalpreservation.changes; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.ObservableProperty; + +/** + * The change in value of a property. + */ +public class PropertyChange implements Change { + private final ObservableProperty property; + private final Object oldValue; + private final Object newValue; + + public ObservableProperty getProperty() { + return property; + } + + public Object getOldValue() { + return oldValue; + } + + public Object getNewValue() { + return newValue; + } + + public PropertyChange(ObservableProperty property, Object oldValue, Object newValue) { + this.property = property; + this.oldValue = oldValue; + this.newValue = newValue; + } + + @Override + public Object getValue(ObservableProperty property, Node node) { + if (property == this.property) { + return newValue; + } else { + return property.getRawValue(node); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/MethodAmbiguityException.java b/JavaParser/src/com/github/javaparser/resolution/MethodAmbiguityException.java new file mode 100644 index 0000000..76632c5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/MethodAmbiguityException.java @@ -0,0 +1,38 @@ +/* + * 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.resolution; + +/** + * It is not possible to decide how to resolve a method invocation. + * + * @author Federico Tomassetti + */ +public class MethodAmbiguityException extends RuntimeException { + + /** + * Create an instance from a description of the reason why there is ambiguity in this particular case. + */ + public MethodAmbiguityException(String description) { + super(description); + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/MethodUsage.java b/JavaParser/src/com/github/javaparser/resolution/MethodUsage.java new file mode 100644 index 0000000..ec3a06b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/MethodUsage.java @@ -0,0 +1,192 @@ +/* + * 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.resolution; + +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; + + +import java.util.*; + +/** + * This is basically a MethodDeclaration with some TypeParameters defined. + * The defined TypeParameters can comes from the Method itself or from the surrounding types. + * + * @author Federico Tomassetti + */ +public class MethodUsage implements ResolvedTypeParametrized { + private ResolvedMethodDeclaration declaration; + private List paramTypes = new ArrayList<>(); + private List exceptionTypes = new ArrayList<>(); + private ResolvedType returnType; + private ResolvedTypeParametersMap typeParametersMap; + + public MethodUsage(ResolvedMethodDeclaration declaration) { + this.typeParametersMap = ResolvedTypeParametersMap.empty(); + this.declaration = declaration; + for (int i = 0; i < declaration.getNumberOfParams(); i++) { + paramTypes.add(declaration.getParam(i).getType()); + } + for (int i = 0; i < declaration.getNumberOfSpecifiedExceptions(); i++) { + exceptionTypes.add(declaration.getSpecifiedException(i)); + } + returnType = declaration.getReturnType(); + } + + public MethodUsage(ResolvedMethodDeclaration declaration, + List paramTypes, ResolvedType returnType) { + this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), + ResolvedTypeParametersMap.empty()); + } + + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, + List exceptionTypes) { + this(declaration, paramTypes, returnType, exceptionTypes, ResolvedTypeParametersMap.empty()); + } + + private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, + List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { + this.declaration = declaration; + this.paramTypes = paramTypes; + this.returnType = returnType; + this.exceptionTypes = exceptionTypes; + this.typeParametersMap = typeParametersMap; + } + + @Override + public String toString() { + return "MethodUsage{" + + "declaration=" + declaration + + ", paramTypes=" + paramTypes + + '}'; + } + + public ResolvedMethodDeclaration getDeclaration() { + return declaration; + } + + public String getName() { + return declaration.getName(); + } + + public ResolvedReferenceTypeDeclaration declaringType() { + return declaration.declaringType(); + } + + public ResolvedType returnType() { + return returnType; + } + + public List getParamTypes() { + return paramTypes; + } + + public MethodUsage replaceParamType(int i, ResolvedType replaced) { + if (i < 0 || i >= getNoParams()) { + throw new IllegalArgumentException(); + } + if (paramTypes.get(i) == replaced) { + return this; + } + List newParams = new LinkedList<>(paramTypes); + newParams.set(i, replaced); + return new MethodUsage(declaration, newParams, returnType, exceptionTypes, typeParametersMap); + } + + public MethodUsage replaceExceptionType(int i, ResolvedType replaced) { + if (i < 0 || i >= exceptionTypes.size()) { + throw new IllegalArgumentException(); + } + if (exceptionTypes.get(i) == replaced) { + return this; + } + List newTypes = new LinkedList<>(exceptionTypes); + newTypes.set(i, replaced); + return new MethodUsage(declaration, paramTypes, returnType, newTypes, typeParametersMap); + } + + public MethodUsage replaceReturnType(ResolvedType returnType) { + if (returnType == this.returnType) { + return this; + } else { + return new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, typeParametersMap); + } + } + + /** + * Return the number of formal arguments accepted by this method. + */ + public int getNoParams() { + return paramTypes.size(); + } + + /** + * Return the type of the formal argument at the given position. + */ + public ResolvedType getParamType(int i) { + return paramTypes.get(i); + } + + public MethodUsage replaceTypeParameter(ResolvedTypeParameterDeclaration typeParameter, ResolvedType type) { + if (type == null) { + throw new IllegalArgumentException(); + } + + // TODO if the method declaration has a type param with that name ignore this call + MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, + typeParametersMap.toBuilder().setValue(typeParameter, type).build()); + + Map inferredTypes = new HashMap<>(); + for (int i = 0; i < paramTypes.size(); i++) { + ResolvedType originalParamType = paramTypes.get(i); + ResolvedType newParamType = originalParamType.replaceTypeVariables(typeParameter, type, inferredTypes); + res = res.replaceParamType(i, newParamType); + } + for (int i = 0; i < exceptionTypes.size(); i++) { + ResolvedType originalType = exceptionTypes.get(i); + ResolvedType newType = originalType.replaceTypeVariables(typeParameter, type, inferredTypes); + res = res.replaceExceptionType(i, newType); + } + ResolvedType oldReturnType = res.returnType; + ResolvedType newReturnType = oldReturnType.replaceTypeVariables(typeParameter, type, inferredTypes); + res = res.replaceReturnType(newReturnType); + return res; + } + + @Override + public ResolvedTypeParametersMap typeParametersMap() { + return typeParametersMap; + } + + public String getQualifiedSignature() { + // TODO use the type parameters + return this.getDeclaration().getQualifiedSignature(); + } + + public List exceptionTypes() { + return exceptionTypes; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/Resolvable.java b/JavaParser/src/com/github/javaparser/resolution/Resolvable.java new file mode 100644 index 0000000..2b12a1b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/Resolvable.java @@ -0,0 +1,26 @@ +/* + * 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.resolution; + +public interface Resolvable { + T resolve(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/SymbolResolver.java b/JavaParser/src/com/github/javaparser/resolution/SymbolResolver.java new file mode 100644 index 0000000..67f8a00 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/SymbolResolver.java @@ -0,0 +1,42 @@ +/* + * 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.resolution; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.types.ResolvedType; + +public interface SymbolResolver { + /** + * For a reference it would find the corresponding + * declaration. + */ + T resolveDeclaration(Node node, Class resultClass); + + /** + * For types it would find the corresponding resolved types. + */ + T toResolvedType(Type javaparserType, Class resultClass); + + ResolvedType calculateType(Expression expression); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/UnsolvedSymbolException.java b/JavaParser/src/com/github/javaparser/resolution/UnsolvedSymbolException.java new file mode 100644 index 0000000..b915096 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/UnsolvedSymbolException.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution; + +/** + * This exception is thrown when a symbol cannot be resolved. + * + * @author Federico Tomassetti + */ +public class UnsolvedSymbolException extends RuntimeException { + + private String context; + private String name; + + public UnsolvedSymbolException(String name, String context) { + super("Unsolved symbol in " + context + " : " + name); + this.context = context; + this.name = name; + } + + public UnsolvedSymbolException(String name) { + super("Unsolved symbol : " + name); + this.context = "unknown"; + this.name = name; + } + + @Override + public String toString() { + return "UnsolvedSymbolException{" + + "context='" + context + '\'' + + ", name='" + name + '\''+ + '}'; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java b/JavaParser/src/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java new file mode 100644 index 0000000..5d7e5bb --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java @@ -0,0 +1,38 @@ +/* + * 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.resolution.declarations; + +import com.github.javaparser.ast.AccessSpecifier; + +/** + * Anything which can have an AccessSpecifier. + * + * @author Federico Tomassetti + */ +public interface HasAccessSpecifier { + + /** + * The access specifier of this element. + */ + AccessSpecifier accessSpecifier(); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java new file mode 100644 index 0000000..c3124f2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java @@ -0,0 +1,32 @@ +/* + * 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.resolution.declarations; + +import java.util.List; + +/** + * @author Federico Tomassetti + */ +public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration { + + List getAnnotationMembers(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java new file mode 100644 index 0000000..0e6f856 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java @@ -0,0 +1,32 @@ +/* + * 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.resolution.declarations; + +import com.github.javaparser.ast.expr.Expression; + +/** + * @author Federico Tomassetti + */ +public interface ResolvedAnnotationMemberDeclaration extends ResolvedValueDeclaration { + + Expression getDefaultValue(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java new file mode 100644 index 0000000..08a8d75 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.declarations; + +import com.github.javaparser.resolution.types.ResolvedReferenceType; + +import java.util.List; + +/** + * Declaration of a Class (not an interface or an enum). + * + * @author Federico Tomassetti + */ +public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier { + + /** + * This method should always return true. + */ + @Override + default boolean isClass() { + return true; + } + + /** + * This is a ReferenceTypeUsage because it could contain type typeParametersValues. + * For example: class A extends B. + *

+ * Note that only the Object class should not have a superclass and therefore + * return null. + */ + ResolvedReferenceType getSuperClass(); + + /** + * Return all the interfaces implemented directly by this class. + * It does not include the interfaces implemented by superclasses or extended + * by the interfaces implemented. + */ + List getInterfaces(); + + /** + * Get all superclasses, with all the type typeParametersValues expressed as functions of the type + * typeParametersValues of this declaration. + */ + List getAllSuperClasses(); + + /** + * Return all the interfaces implemented by this class, either directly or indirectly, including the interfaces + * extended by interfaces it implements. + *

+ * Get all interfaces, with all the type typeParametersValues expressed as functions of the type + * typeParametersValues of this declaration. + */ + List getAllInterfaces(); + + /// + /// Constructors + /// + + /** + * List of constructors available for the class. + * This list should also include the default constructor. + */ + List getConstructors(); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java new file mode 100644 index 0000000..07f486c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java @@ -0,0 +1,36 @@ +/* + * 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.resolution.declarations; + +/** + * A declaration of a constructor. + * + * @author Federico Tomassetti + */ +public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration { + + /** + * A constructor can be declared in a class or an enum. + */ + @Override + ResolvedReferenceTypeDeclaration declaringType(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java new file mode 100644 index 0000000..86bee80 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java @@ -0,0 +1,98 @@ +/* + * 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.resolution.declarations; + +/** + * A generic declaration. + * + * @author Federico Tomassetti + */ +public interface ResolvedDeclaration { + + /** + * Anonymous classes do not have a name, for example. + */ + default boolean hasName() { + return true; + } + + /** + * Should return the name or throw a RuntimeException if the name is not available. + */ + String getName(); + + /** + * Does this declaration represents a class field? + */ + default boolean isField() { + return false; + } + + /** + * Does this declaration represents a method parameter? + */ + default boolean isParameter() { + return false; + } + + /** + * Does this declaration represents a type? + */ + default boolean isType() { + return false; + } + + /** + * Does this declaration represents a method? + */ + default boolean isMethod() { + return false; + } + + /** + * Return this as a FieldDeclaration or throw an UnsupportedOperationException + */ + default ResolvedFieldDeclaration asField() { + throw new UnsupportedOperationException(String.format("%s is not a FieldDeclaration", this)); + } + + /** + * Return this as a ParameterDeclaration or throw an UnsupportedOperationException + */ + default ResolvedParameterDeclaration asParameter() { + throw new UnsupportedOperationException(String.format("%s is not a ParameterDeclaration", this)); + } + + /** + * Return this as a TypeDeclaration or throw an UnsupportedOperationException + */ + default ResolvedTypeDeclaration asType() { + throw new UnsupportedOperationException(String.format("%s is not a TypeDeclaration", this)); + } + + /** + * Return this as a MethodDeclaration or throw an UnsupportedOperationException + */ + default ResolvedMethodDeclaration asMethod() { + throw new UnsupportedOperationException(String.format("%s is not a MethodDeclaration", this)); + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java new file mode 100644 index 0000000..aeb0ded --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java @@ -0,0 +1,30 @@ +/* + * 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.resolution.declarations; + +/** + * @author Federico Tomassetti + */ +public interface ResolvedEnumConstantDeclaration extends ResolvedValueDeclaration { + + String getName(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java new file mode 100644 index 0000000..e31a4fb --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java @@ -0,0 +1,45 @@ +/* + * 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.resolution.declarations; + +import java.util.List; + +/** + * Declaration of an Enum. + * + * @author Federico Tomassetti + */ +public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, + HasAccessSpecifier { + + @Override + default boolean isEnum() { + return true; + } + + @Override + default ResolvedEnumDeclaration asEnum() { + return this; + } + + List getEnumConstants(); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java new file mode 100644 index 0000000..194c892 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.declarations; + +/** + * Declaration of a field. + * + * @author Federico Tomassetti + */ +public interface ResolvedFieldDeclaration extends ResolvedValueDeclaration, HasAccessSpecifier { + + /** + * Is the field static? + */ + boolean isStatic(); + + @Override + default boolean isField() { + return true; + } + + @Override + default ResolvedFieldDeclaration asField() { + return this; + } + + /** + * The type on which this field has been declared + */ + ResolvedTypeDeclaration declaringType(); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java new file mode 100644 index 0000000..5ef53b2 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java @@ -0,0 +1,58 @@ +/* + * 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.resolution.declarations; + +import com.github.javaparser.resolution.types.ResolvedReferenceType; + +import java.util.ArrayList; +import java.util.List; + +/** + * An interface declaration. + * + * @author Federico Tomassetti + */ +public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier { + + @Override + default boolean isInterface() { + return true; + } + + /** + * Return the list of interfaces extended directly by this one. + */ + List getInterfacesExtended(); + + /** + * Return the list of interfaces extended directly or indirectly by this one. + */ + default List getAllInterfacesExtended() { + List interfaces = new ArrayList<>(); + for (ResolvedReferenceType interfaceDeclaration : getInterfacesExtended()) { + interfaces.add(interfaceDeclaration); + interfaces.addAll(interfaceDeclaration.getAllInterfacesAncestors()); + } + return interfaces; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java new file mode 100644 index 0000000..9f2f64c --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -0,0 +1,54 @@ +/* + * 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.resolution.declarations; + +import com.github.javaparser.resolution.types.ResolvedType; + +/** + * A declaration of a method (either in an interface, a class, an enum or an annotation). + * + * @author Federico Tomassetti + */ +public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration { + + /** + * The type of the value returned by the current method. This method can also be invoked + * for methods returning void. + */ + ResolvedType getReturnType(); + + /** + * Is the method abstract? All interface methods not marked as default are abstract. + */ + boolean isAbstract(); + + /** + * Is this a default method? + */ + boolean isDefaultMethod(); + + /* + * Is this method static? + */ + boolean isStatic(); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java new file mode 100644 index 0000000..97f35f5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java @@ -0,0 +1,159 @@ +/* + * 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.resolution.declarations; + +import com.github.javaparser.resolution.types.ResolvedType; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + +/** + * This is a common interface for MethodDeclaration and ConstructorDeclaration. + * + * @author Federico Tomassetti + */ +public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier { + /** + * The package name of the declaring type. + */ + default String getPackageName() { + return declaringType().getPackageName(); + } + + /** + * The class(es) wrapping the declaring type. + */ + default String getClassName() { + return declaringType().getClassName(); + } + + /** + * The qualified name of the method composed by the qualfied name of the declaring type + * followed by a dot and the name of the method. + */ + default String getQualifiedName() { + return declaringType().getQualifiedName() + "." + this.getName(); + } + + /** + * The signature of the method. + */ + default String getSignature() { + StringBuilder sb = new StringBuilder(); + sb.append(getName()); + sb.append("("); + for (int i = 0; i < getNumberOfParams(); i++) { + if (i != 0) { + sb.append(", "); + } + sb.append(getParam(i).describeType()); + } + sb.append(")"); + return sb.toString(); + } + + /** + * The qualified signature of the method. It is composed by the qualified name of the declaring type + * followed by the signature of the method. + */ + default String getQualifiedSignature() { + return declaringType().getId() + "." + this.getSignature(); + } + + /** + * The type in which the method is declared. + */ + ResolvedReferenceTypeDeclaration declaringType(); + + /** + * Number of params. + */ + int getNumberOfParams(); + + /** + * Get the ParameterDeclaration at the corresponding position or throw IllegalArgumentException. + */ + ResolvedParameterDeclaration getParam(int i); + + /** + * Utility method to get the last ParameterDeclaration. It throws UnsupportedOperationException if the method + * has no parameters. + * The last parameter can be variadic and sometimes it needs to be handled in a special way. + */ + default ResolvedParameterDeclaration getLastParam() { + if (getNumberOfParams() == 0) { + throw new UnsupportedOperationException("This method has no typeParametersValues, therefore it has no a last parameter"); + } + return getParam(getNumberOfParams() - 1); + } + + /** + * Has the method or construcor a variadic parameter? + * Note that when a method has a variadic parameter it should have an array type. + */ + default boolean hasVariadicParameter() { + if (getNumberOfParams() == 0) { + return false; + } else { + return getParam(getNumberOfParams() - 1).isVariadic(); + } + } + + @Override + default Optional findTypeParameter(String name) { + for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) { + if (tp.getName().equals(name)) { + return Optional.of(tp); + } + } + return declaringType().findTypeParameter(name); + } + + /** + * Number of exceptions listed in the throws clause. + */ + int getNumberOfSpecifiedExceptions(); + + /** + * Type of the corresponding entry in the throws clause. + * + * @throws IllegalArgumentException if the index is negative or it is equal or greater than the value returned by + * getNumberOfSpecifiedExceptions + * @throws UnsupportedOperationException for those types of methods of constructor that do not declare exceptions + */ + ResolvedType getSpecifiedException(int index); + + default List getSpecifiedExceptions() { + if (getNumberOfSpecifiedExceptions() == 0) { + return Collections.emptyList(); + } else { + List exceptions = new LinkedList<>(); + for (int i=0;i + * class A implements Comparable<String> {} + *

+ * In this case the ancestor is Comparable<String> + */ + List getAncestors(); + + /** + * The list of all the ancestors of the current declaration, direct and indirect. + * This list does not contains duplicates with the exacting same type parameters. + */ + default List getAllAncestors() { + List ancestors = new ArrayList<>(); + // We want to avoid infinite recursion in case of Object having Object as ancestor + if (!(Object.class.getCanonicalName().equals(getQualifiedName()))) { + for (ResolvedReferenceType ancestor : getAncestors()) { + ancestors.add(ancestor); + for (ResolvedReferenceType inheritedAncestor : ancestor.getAllAncestors()) { + if (!ancestors.contains(inheritedAncestor)) { + ancestors.add(inheritedAncestor); + } + } + } + } + return ancestors; + } + + /// + /// Fields + /// + + /** + * Note that the type of the field should be expressed using the type variables of this particular type. + * Consider for example: + *

+ * class Foo { E field; } + *

+ * class Bar extends Foo { } + *

+ * When calling getField("field") on Foo I should get a FieldDeclaration with type E, while calling it on + * Bar I should get a FieldDeclaration with type String. + */ + default ResolvedFieldDeclaration getField(String name) { + Optional field = this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst(); + if (field.isPresent()) { + return field.get(); + } else { + throw new UnsolvedSymbolException("Field not found: " + name); + } + } + + /** + * Consider only field or inherited field which is not private. + */ + default ResolvedFieldDeclaration getVisibleField(String name) { + Optional field = getVisibleFields().stream().filter(f -> f.getName().equals(name)).findFirst(); + if (field.isPresent()) { + return field.get(); + } else { + throw new IllegalArgumentException(); + } + } + + /** + * Has this type a field with the given name? + */ + default boolean hasField(String name) { + return this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst().isPresent(); + } + + /** + * Either a declared field or inherited field which is not private. + */ + default boolean hasVisibleField(String name) { + return getVisibleFields().stream().filter(f -> f.getName().equals(name)).findFirst().isPresent(); + } + + /** + * Return a list of all fields, either declared in this declaration or inherited. + */ + List getAllFields(); + + /** + * Return a list of all fields declared and the inherited ones which are not private. + */ + default List getVisibleFields() { + return getAllFields().stream() + .filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE) + .collect(Collectors.toList()); + } + + /** + * Return a list of all the non static fields, either declared or inherited. + */ + default List getAllNonStaticFields() { + return getAllFields().stream().filter(it -> !it.isStatic()).collect(Collectors.toList()); + } + + /** + * Return a list of all the static fields, either declared or inherited. + */ + default List getAllStaticFields() { + return getAllFields().stream().filter(it -> it.isStatic()).collect(Collectors.toList()); + } + + /** + * Return a list of all the fields declared in this type. + */ + default List getDeclaredFields() { + return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName().equals(getQualifiedName())).collect(Collectors.toList()); + } + + /// + /// Methods + /// + + /** + * Return a list of all the methods declared in this type declaration. + */ + Set getDeclaredMethods(); + + /** + * Return a list of all the methods declared of this type declaration, either declared or inherited. + * Note that it should not include overridden methods. + */ + Set getAllMethods(); + + /// + /// Assignability + /// + + /** + * Can we assign instances of the given type to variables having the type defined + * by this declaration? + */ + boolean isAssignableBy(ResolvedType type); + + /** + * Can we assign instances of the type defined by this declaration to variables having the type defined + * by the given type? + */ + default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { + return other.isAssignableBy(this); + } + + /** + * Can we assign instances of the given type to variables having the type defined + * by this declaration? + */ + boolean isAssignableBy(ResolvedReferenceTypeDeclaration other); + + /// + /// Annotations + /// + + /** + * Has the type at least one annotation declared having the specified qualified name? + */ + boolean hasDirectlyAnnotation(String qualifiedName); + + /** + * Has the type at least one annotation declared or inherited having the specified qualified name? + */ + default boolean hasAnnotation(String qualifiedName) { + if (hasDirectlyAnnotation(qualifiedName)) { + return true; + } + return getAllAncestors().stream().anyMatch(it -> it.asReferenceType().getTypeDeclaration().hasDirectlyAnnotation(qualifiedName)); + } + + /** + * This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method. + * Typically these classes has the FunctionInterface annotation but this is not mandatory. + */ + boolean isFunctionalInterface(); + + /// + /// Type parameters + /// + + @Override + default Optional findTypeParameter(String name) { + for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) { + if (tp.getName().equals(name)) { + return Optional.of(tp); + } + } + if (this.containerType().isPresent()) { + return this.containerType().get().findTypeParameter(name); + } + return Optional.empty(); + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java new file mode 100644 index 0000000..0b715fe --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.declarations; + +import com.github.javaparser.resolution.UnsolvedSymbolException; + +import java.util.Optional; +import java.util.Set; + +/** + * A declaration of a type. It could be a primitive type, an enum, a class, an interface + * or a type variable. + * It cannot be an annotation or an array. + * + * @author Federico Tomassetti + */ +public interface ResolvedTypeDeclaration extends ResolvedDeclaration { + + /// + /// Containment + /// + + /** + * Get the list of types defined inside the current type. + */ + default Set internalTypes() { + throw new UnsupportedOperationException("InternalTypes not available for " + this.getClass().getCanonicalName()); + } + + /** + * Returns a type declaration for the internal type based on name. + * (Does not include internal types inside internal types). + */ + default ResolvedReferenceTypeDeclaration getInternalType(String name) { + Optional type = + this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); + return type.orElseThrow(() -> + new UnsolvedSymbolException("Internal type not found: " + name)); + } + + /** + * Does this type contain an internal type with the given name? + * (Does not include internal types inside internal types). + */ + default boolean hasInternalType(String name) { + return this.internalTypes().stream().anyMatch(f -> f.getName().equals(name)); + } + + /** + * Get the ReferenceTypeDeclaration enclosing this declaration. + * + * @return + */ + Optional containerType(); + + /// + /// Misc + /// + + /** + * Is this the declaration of a class? + * Note that an Enum is not considered a Class in this case. + */ + default boolean isClass() { + return false; + } + + /** + * Is this the declaration of an interface? + */ + default boolean isInterface() { + return false; + } + + /** + * Is this the declaration of an enum? + */ + default boolean isEnum() { + return false; + } + + /** + * Is this the declaration of a type parameter? + */ + default boolean isTypeParameter() { + return false; + } + + @Override + default boolean isType() { + return true; + } + + /** + * Is this type declaration corresponding to an anonymous class? + * + * This is an example of anonymous class: + *

+     * HelloWorld frenchGreeting = new HelloWorld() {
+     *     String name = "tout le monde";
+     *
+     *     public void greet() {
+     *         greetSomeone("tout le monde");
+     *     }
+     *
+     *     public void greetSomeone(String someone) {
+     *         name = someone;
+     *         System.out.println("Salut " + name);
+     *     }
+     * };
+     * 
+ */ + default boolean isAnonymousClass() { + return false; + } + + @Override + default ResolvedTypeDeclaration asType() { + return this; + } + + /** + * Return this as a ClassDeclaration or throw UnsupportedOperationException. + */ + default ResolvedClassDeclaration asClass() { + throw new UnsupportedOperationException(String.format("%s is not a class", this)); + } + + /** + * Return this as a InterfaceDeclaration or throw UnsupportedOperationException. + */ + default ResolvedInterfaceDeclaration asInterface() { + throw new UnsupportedOperationException(String.format("%s is not an interface", this)); + } + + /** + * Return this as a EnumDeclaration or throw UnsupportedOperationException. + */ + default ResolvedEnumDeclaration asEnum() { + throw new UnsupportedOperationException(String.format("%s is not an enum", this)); + } + + /** + * Return this as a TypeParameterDeclaration or throw UnsupportedOperationException. + */ + default ResolvedTypeParameterDeclaration asTypeParameter() { + throw new UnsupportedOperationException(String.format("%s is not a type parameter", this)); + } + + default ResolvedReferenceTypeDeclaration asReferenceType() { + throw new UnsupportedOperationException(String.format("%s is not a reference type", this)); + } + + /** + * The package name of the type. + */ + String getPackageName(); + + /** + * The class(es) wrapping this type. + */ + String getClassName(); + + /** + * The fully qualified name of the type declared. + */ + String getQualifiedName(); + + /** + * The ID corresponds most of the type to the qualified name. It differs only for local + * classes which do not have a qualified name but have an ID. + */ + default String getId() { + String qname = getQualifiedName(); + if (qname == null) { + return String.format(":%s", getName()); + } + return qname; + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java new file mode 100644 index 0000000..14326db --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -0,0 +1,305 @@ +/* + * 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.resolution.declarations; + + +import com.github.javaparser.resolution.types.ResolvedType; + +import java.util.List; +import java.util.Optional; + +/** + * Declaration of a type parameter. + * For example: + *

+ * class A<E extends String>{} + *

+ *

+ * In this case E would be a type parameter. + * + * @author Federico Tomassetti + */ +public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaration { + + /** + * Instantiate a TypeParameter defined on a Type with the given data. + */ + static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List bounds) { + return new ResolvedTypeParameterDeclaration() { + @Override + public String getName() { + return name; + } + + @Override + public boolean declaredOnType() { + return true; + } + + @Override + public boolean declaredOnMethod() { + return false; + } + + @Override + public boolean declaredOnConstructor() { + return false; + } + + @Override + public String getContainerQualifiedName() { + return classQName; + } + + @Override + public String getContainerId() { + return classQName; + } + + @Override + public ResolvedTypeParametrizable getContainer() { + return null; + } + + @Override + public List getBounds() { + return bounds; + } + + @Override + public String toString() { + return "TypeParameter onType " + name; + } + + @Override + public Optional containerType() { + throw new UnsupportedOperationException(); + } + }; + } + + /** + * Name of the type parameter. + */ + String getName(); + + /** + * Is the type parameter been defined on a type? + */ + default boolean declaredOnType() { + return (getContainer() instanceof ResolvedReferenceTypeDeclaration); + } + + /** + * Is the type parameter been defined on a method? + */ + default boolean declaredOnMethod() { + return (getContainer() instanceof ResolvedMethodDeclaration); + } + + /** + * Is the type parameter been defined on a constructor? + */ + default boolean declaredOnConstructor() { + return (getContainer() instanceof ResolvedConstructorDeclaration); + } + + /** + * The package name of the type bound(s). + * This is unsupported because there is no package for a Type Parameter, only for its container. + */ + default String getPackageName() { + throw new UnsupportedOperationException(); + } + + /** + * The class(es) wrapping the type bound(s). + * This is unsupported because there is no class for a Type Parameter, only for its container. + */ + default String getClassName() { + throw new UnsupportedOperationException(); + } + + /** + * The qualified name of the Type Parameter. + * It is composed by the qualified name of the container followed by a dot and the name of the Type Parameter. + * The qualified name of a method is its qualified signature. + */ + default String getQualifiedName() { + return String.format("%s.%s", getContainerId(), getName()); + } + + /** + * The qualified name of the container. + */ + String getContainerQualifiedName(); + + /** + * The ID of the container. See TypeContainer.getId + */ + String getContainerId(); + + /** + * The TypeParametrizable of the container. Can be either a ReferenceTypeDeclaration or a MethodLikeDeclaration + */ + ResolvedTypeParametrizable getContainer(); + + /** + * The bounds specified for the type parameter. + * For example: + * "extends A" or "super B" + */ + List getBounds(); + + /** + * Has the type parameter a lower bound? + */ + default boolean hasLowerBound() { + for (Bound b : getBounds()) { + if (b.isExtends()) { + return true; + } + } + return false; + } + + /** + * Has the type parameter an upper bound? + */ + default boolean hasUpperBound() { + for (Bound b : getBounds()) { + if (b.isSuper()) { + return true; + } + } + return false; + } + + /** + * Get the type used as lower bound. + * + * @throws IllegalStateException if there is no lower bound + */ + default ResolvedType getLowerBound() { + for (Bound b : getBounds()) { + if (b.isExtends()) { + return b.getType(); + } + } + throw new IllegalStateException(); + } + + /** + * Get the type used as upper bound. + * + * @throws IllegalStateException if there is no upper bound + */ + default ResolvedType getUpperBound() { + for (Bound b : getBounds()) { + if (b.isSuper()) { + return b.getType(); + } + } + throw new IllegalStateException(); + } + + /** + * A Bound on a Type Parameter. + */ + class Bound { + private boolean extendsBound; + private ResolvedType type; + + private Bound(boolean extendsBound, ResolvedType type) { + this.extendsBound = extendsBound; + this.type = type; + } + + /** + * Create an extends bound with the given type: + *

+ * extends "given type" + *

+ */ + public static Bound extendsBound(ResolvedType type) { + return new Bound(true, type); + } + + /** + * Create a super bound with the given type: + *

+ * super "given type" + *

+ */ + public static Bound superBound(ResolvedType type) { + return new Bound(false, type); + } + + /** + * Get the type used in the Bound. + */ + public ResolvedType getType() { + return type; + } + + /** + * Is this an extends bound? + */ + public boolean isExtends() { + return extendsBound; + } + + /** + * Is this a super bound? + */ + public boolean isSuper() { + return !isExtends(); + } + + @Override + public String toString() { + return "Bound{" + + "extendsBound=" + extendsBound + + ", type=" + type + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Bound bound = (Bound) o; + + if (extendsBound != bound.extendsBound) return false; + return type != null ? type.equals(bound.type) : bound.type == null; + } + + @Override + public int hashCode() { + int result = (extendsBound ? 1 : 0); + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java new file mode 100644 index 0000000..3d6b92e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.declarations; + +import java.util.List; +import java.util.Optional; + +/** + * An entity which has type parameter. + * + * @author Federico Tomassetti + */ +public interface ResolvedTypeParametrizable { + + /** + * The list of type parameters defined on this element. + */ + List getTypeParameters(); + + /** + * Find the closest TypeParameterDeclaration with the given name. + * It first look on this element itself and then on the containers. + */ + Optional findTypeParameter(String name); + + default boolean isGeneric() { + return !getTypeParameters().isEmpty(); + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java new file mode 100644 index 0000000..ee6230a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.declarations; + + +import com.github.javaparser.resolution.types.ResolvedType; + +/** + * Declaration of a value. + * + * @author Federico Tomassetti + */ +public interface ResolvedValueDeclaration extends ResolvedDeclaration { + + /** + * Type of the declaration. + */ + ResolvedType getType(); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedArrayType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedArrayType.java new file mode 100644 index 0000000..bc422f7 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedArrayType.java @@ -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.resolution.types; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + +import java.util.Map; + +/** + * Array Type. + * + * @author Federico Tomassetti + */ +public class ResolvedArrayType implements ResolvedType { + + private ResolvedType baseType; + + public ResolvedArrayType(ResolvedType baseType) { + this.baseType = baseType; + } + + /// + /// Object methods + /// + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResolvedArrayType that = (ResolvedArrayType) o; + + if (!baseType.equals(that.baseType)) return false; + + return true; + } + + @Override + public int hashCode() { + return baseType.hashCode(); + } + + @Override + public String toString() { + return "ResolvedArrayType{" + baseType + "}"; + } + + /// + /// Type methods + /// + + @Override + public ResolvedArrayType asArrayType() { + return this; + } + + @Override + public boolean isArray() { + return true; + } + + @Override + public String describe() { + return baseType.describe() + "[]"; + } + + public ResolvedType getComponentType() { + return baseType; + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + if (other.isArray()) { + if (baseType.isPrimitive() && other.asArrayType().getComponentType().isPrimitive()) { + return baseType.equals(other.asArrayType().getComponentType()); + } + return baseType.isAssignableBy(other.asArrayType().getComponentType()); + } else if (other.isNull()) { + return true; + } + return false; + } + + @Override + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map inferredTypes) { + ResolvedType baseTypeReplaced = baseType.replaceTypeVariables(tpToReplace, replaced, inferredTypes); + if (baseTypeReplaced == baseType) { + return this; + } else { + return new ResolvedArrayType(baseTypeReplaced); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedIntersectionType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedIntersectionType.java new file mode 100644 index 0000000..e308fea --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedIntersectionType.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.types; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * An intersection type is defined in java as list of types separates by ampersands. + * + * @author Federico Tomassetti + */ +public class ResolvedIntersectionType implements ResolvedType { + private List elements; + + public ResolvedIntersectionType(Collection elements) { + if (elements.size() < 2) { + throw new IllegalArgumentException("An intersection type should have at least two elements. This has " + elements.size()); + } + this.elements = new LinkedList<>(elements); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResolvedIntersectionType that = (ResolvedIntersectionType) o; + + return new HashSet<>(elements).equals(new HashSet<>(that.elements)); + } + + @Override + public int hashCode() { + return new HashSet<>(elements).hashCode(); + } + + @Override + public String describe() { + return String.join(" & ", elements.stream().map(ResolvedType::describe).collect(Collectors.toList())); + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + return elements.stream().allMatch(e -> e.isAssignableBy(other)); + } + + @Override + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map inferredTypes) { + List elementsReplaced = elements.stream() + .map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)) + .collect(Collectors.toList()); + if (elementsReplaced.equals(elements)) { + return this; + } else { + return new ResolvedIntersectionType(elementsReplaced); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java new file mode 100644 index 0000000..e43d434 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.types; + +public class ResolvedLambdaConstraintType implements ResolvedType { + private ResolvedType bound; + + private ResolvedLambdaConstraintType(ResolvedType bound) { + this.bound = bound; + } + + @Override + public String describe() { + return "? super " + bound.describe(); + } + + public ResolvedType getBound() { + return bound; + } + + @Override + public boolean isConstraint() { + return true; + } + + @Override + public ResolvedLambdaConstraintType asConstraintType() { + return this; + } + + public static ResolvedLambdaConstraintType bound(ResolvedType bound){ + return new ResolvedLambdaConstraintType(bound); + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + return bound.isAssignableBy(other); + } + + @Override + public String toString() { + return "LambdaConstraintType{" + + "bound=" + bound + + '}'; + } +} \ No newline at end of file diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java new file mode 100644 index 0000000..4a7e292 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -0,0 +1,128 @@ +/* + * 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.resolution.types; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author Federico Tomassetti + */ +public enum ResolvedPrimitiveType implements ResolvedType { + + + BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()), + SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)), + CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()), + INT("int", Integer.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, CHAR)), + LONG("long", Long.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, INT, CHAR)), + BOOLEAN("boolean", Boolean.class.getCanonicalName(), Collections.emptyList()), + FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), + DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); + + /// + /// Fields + /// + + private String name; + private String boxTypeQName; + private List promotionTypes; + + private ResolvedPrimitiveType(String name, String boxTypeQName, List promotionTypes) { + this.name = name; + this.boxTypeQName = boxTypeQName; + this.promotionTypes = promotionTypes; + } + + public static ResolvedType byName(String name) { + name = name.toLowerCase(); + for (ResolvedPrimitiveType ptu : values()) { + if (ptu.describe().equals(name)) { + return ptu; + } + } + throw new IllegalArgumentException("Name " + name); + } + + @Override + public String toString() { + return "PrimitiveTypeUsage{" + + "name='" + name + '\'' + + '}'; + } + + public ResolvedPrimitiveType asPrimitive() { + return this; + } + + @Override + public boolean isArray() { + return false; + } + + @Override + public boolean isPrimitive() { + return true; + } + + @Override + public boolean isReferenceType() { + return false; + } + + @Override + public String describe() { + return name; + } + + @Override + public boolean isTypeVariable() { + return false; + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + if (other.isPrimitive()) { + return this == other || promotionTypes.contains(other); + } else if (other.isReferenceType()) { + if (other.asReferenceType().getQualifiedName().equals(boxTypeQName)) { + return true; + } + for (ResolvedPrimitiveType promotion : promotionTypes) { + if (other.asReferenceType().getQualifiedName().equals(promotion.boxTypeQName)) { + return true; + } + } + return false; + } else if (other.isConstraint()){ + return this.isAssignableBy(other.asConstraintType().getBound()); + } else { + return false; + } + } + + public String getBoxTypeQName() { + return boxTypeQName; + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedReferenceType.java new file mode 100644 index 0000000..4fecaf6 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -0,0 +1,451 @@ +/* + * 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.resolution.types; + +import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParameterValueProvider; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; +import com.github.javaparser.utils.Pair; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values + * specified for the type parameters. + * + * @author Federico Tomassetti + */ +public abstract class ResolvedReferenceType implements ResolvedType, + ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { + + // + // Fields + // + + protected ResolvedReferenceTypeDeclaration typeDeclaration; + protected ResolvedTypeParametersMap typeParametersMap; + + // + // Constructors + // + + public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration) { + this(typeDeclaration, deriveParams(typeDeclaration)); + } + + public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, List typeArguments) { + if (typeDeclaration.isTypeParameter()) { + throw new IllegalArgumentException("You should use only Classes, Interfaces and enums"); + } + if (typeArguments.size() > 0 && typeArguments.size() != typeDeclaration.getTypeParameters().size()) { + throw new IllegalArgumentException(String.format( + "expected either zero type arguments or has many as defined in the declaration (%d). Found %d", + typeDeclaration.getTypeParameters().size(), typeArguments.size())); + } + ResolvedTypeParametersMap.Builder typeParametersMapBuilder = new ResolvedTypeParametersMap.Builder(); + for (int i = 0; i < typeArguments.size(); i++) { + typeParametersMapBuilder.setValue(typeDeclaration.getTypeParameters().get(i), typeArguments.get(i)); + } + this.typeParametersMap = typeParametersMapBuilder.build(); + this.typeDeclaration = typeDeclaration; + } + + // + // Public Object methods + // + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResolvedReferenceType that = (ResolvedReferenceType) o; + + if (!typeDeclaration.equals(that.typeDeclaration)) return false; + if (!typeParametersMap.equals(that.typeParametersMap)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = typeDeclaration.hashCode(); + result = 31 * result + typeParametersMap.hashCode(); + return result; + } + + @Override + public String toString() { + return "ReferenceType{" + getQualifiedName() + + ", typeParametersMap=" + typeParametersMap + + '}'; + } + + /// + /// Relation with other types + /// + + @Override + public final boolean isReferenceType() { + return true; + } + + /// + /// Downcasting + /// + + @Override + public ResolvedReferenceType asReferenceType() { + return this; + } + + /// + /// Naming + /// + + @Override + public String describe() { + StringBuilder sb = new StringBuilder(); + if (hasName()) { + sb.append(typeDeclaration.getQualifiedName()); + } else { + sb.append(""); + } + if (!typeParametersMap().isEmpty()) { + sb.append("<"); + sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream() + .map(tp -> typeParametersMap().getValue(tp).describe()) + .collect(Collectors.toList()))); + sb.append(">"); + } + return sb.toString(); + } + + /// + /// TypeParameters + /// + + /** + * Execute a transformation on all the type parameters of this element. + */ + public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer); + + @Override + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, + Map inferredTypes) { + if (replaced == null) { + throw new IllegalArgumentException(); + } + + ResolvedReferenceType result = this; + int i = 0; + for (ResolvedType tp : this.typeParametersValues()) { + ResolvedType transformedTp = tp.replaceTypeVariables(tpToReplace, replaced, inferredTypes); + // Identity comparison on purpose + if (tp.isTypeVariable() && tp.asTypeVariable().describe().equals(tpToReplace.getName())) { + inferredTypes.put(tp.asTypeParameter(), replaced); + } + // FIXME + if (true) { + List typeParametersCorrected = result.asReferenceType().typeParametersValues(); + typeParametersCorrected.set(i, transformedTp); + result = create(typeDeclaration, typeParametersCorrected); + } + i++; + } + + List values = result.typeParametersValues(); + // FIXME + if(values.contains(tpToReplace)){ + int index = values.indexOf(tpToReplace); + values.set(index, replaced); + return create(result.getTypeDeclaration(), values); + } + + return result; + } + + /// + /// Assignability + /// + + /** + * This method checks if ThisType t = new OtherType() would compile. + */ + @Override + public abstract boolean isAssignableBy(ResolvedType other); + + /// + /// Ancestors + /// + + /** + * Return all ancestors, that means all superclasses and interfaces. + * This list should always include Object (unless this is a reference to Object). + * The type typeParametersValues should be expressed in terms of this type typeParametersValues. + *

+ * For example, given: + *

+ * class Foo<A, B> {} + * class Bar<C> extends Foo<C, String> {} + *

+ * a call to getAllAncestors on a reference to Bar having type parameter Boolean should include + * Foo<Boolean, String>. + */ + public abstract List getAllAncestors(); + + public final List getAllInterfacesAncestors() { + return getAllAncestors().stream() + .filter(it -> it.getTypeDeclaration().isInterface()) + .collect(Collectors.toList()); + } + + public final List getAllClassesAncestors() { + return getAllAncestors().stream() + .filter(it -> it.getTypeDeclaration().isClass()) + .collect(Collectors.toList()); + } + + /// + /// Type parameters + /// + + /** + * Get the type associated with the type parameter with the given name. + * It returns Optional.empty unless the type declaration declares a type parameter with the given name. + */ + public Optional getGenericParameterByName(String name) { + for (ResolvedTypeParameterDeclaration tp : typeDeclaration.getTypeParameters()) { + if (tp.getName().equals(name)) { + return Optional.of(this.typeParametersMap().getValue(tp)); + } + } + return Optional.empty(); + } + + /** + * Get the values for all type parameters declared on this type. + * The list can be empty for raw types. + */ + public List typeParametersValues() { + return this.typeParametersMap.isEmpty() ? Collections.emptyList() : typeDeclaration.getTypeParameters().stream().map(tp -> typeParametersMap.getValue(tp)).collect(Collectors.toList()); + } + + /** + * Get the values for all type parameters declared on this type. + * In case of raw types the values correspond to TypeVariables. + */ + public List> getTypeParametersMap() { + List> typeParametersMap = new ArrayList<>(); + if (!isRawType()) { + for (int i = 0; i < typeDeclaration.getTypeParameters().size(); i++) { + typeParametersMap.add(new Pair<>(typeDeclaration.getTypeParameters().get(0), typeParametersValues().get(i))); + } + } + return typeParametersMap; + } + + @Override + public ResolvedTypeParametersMap typeParametersMap() { + return typeParametersMap; + } + + /// + /// Other methods introduced by ReferenceType + /// + + /** + * Corresponding TypeDeclaration + */ + public final ResolvedReferenceTypeDeclaration getTypeDeclaration() { + return typeDeclaration; + } + + /** + * The type of the field could be different from the one in the corresponding FieldDeclaration because + * type variables would be solved. + */ + public Optional getFieldType(String name) { + if (!typeDeclaration.hasField(name)) { + return Optional.empty(); + } + ResolvedType type = typeDeclaration.getField(name).getType(); + type = useThisTypeParametersOnTheGivenType(type); + return Optional.of(type); + } + + /** + * Has the TypeDeclaration a name? Anonymous classes do not have one. + */ + public boolean hasName() { + return typeDeclaration.hasName(); + } + + /** + * Qualified name of the declaration. + */ + public String getQualifiedName() { + return typeDeclaration.getQualifiedName(); + } + + /** + * Id of the declaration. It corresponds to the qualified name, unless for local classes. + */ + public String getId() { + return typeDeclaration.getId(); + } + + /** + * Methods declared on this type. + */ + public abstract Set getDeclaredMethods(); + + public boolean isRawType() { + if (!typeDeclaration.getTypeParameters().isEmpty()) { + if (typeParametersMap().isEmpty()) { + return true; + } + for (String name : typeParametersMap().getNames()) { + Optional value = typeParametersMap().getValueBySignature(name); + if (value.isPresent() && value.get().isTypeVariable() && value.get().asTypeVariable().qualifiedName().equals(name)) { + // nothing to do + } else { + return false; + } + } + return true; + } + return false; + } + + public Optional typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration) { + if (typeParameterDeclaration.declaredOnMethod()) { + throw new IllegalArgumentException(); + } + String typeId = this.getTypeDeclaration().getId(); + if (typeId.equals(typeParameterDeclaration.getContainerId())) { + return Optional.of(this.typeParametersMap().getValue(typeParameterDeclaration)); + } + for (ResolvedReferenceType ancestor : this.getAllAncestors()) { + if (ancestor.getId().equals(typeParameterDeclaration.getContainerId())) { + return Optional.of(ancestor.typeParametersMap().getValue(typeParameterDeclaration)); + } + } + return Optional.empty(); + } + + public abstract ResolvedType toRawType(); + + // + // Protected methods + // + + protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParameters); + + protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap) { + return create(typeDeclaration, typeDeclaration.getTypeParameters().stream() + .map(typeParametersMap::getValue) + .collect(Collectors.toList())); + } + + protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration); + + protected boolean isCorrespondingBoxingType(String typeName) { + switch (typeName) { + case "boolean": + return getQualifiedName().equals(Boolean.class.getCanonicalName()); + case "char": + return getQualifiedName().equals(Character.class.getCanonicalName()); + case "byte": + return getQualifiedName().equals(Byte.class.getCanonicalName()); + case "short": + return getQualifiedName().equals(Short.class.getCanonicalName()); + case "int": + return getQualifiedName().equals(Integer.class.getCanonicalName()); + case "long": + return getQualifiedName().equals(Long.class.getCanonicalName()); + case "float": + return getQualifiedName().equals(Float.class.getCanonicalName()); + case "double": + return getQualifiedName().equals(Double.class.getCanonicalName()); + default: + throw new UnsupportedOperationException(typeName); + } + } + + protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) { + if (other.equals(this)) { + return true; + } + if (this.getQualifiedName().equals(other.getQualifiedName())) { + if (this.isRawType() || other.isRawType()) { + return true; + } + if (this.typeParametersValues().size() != other.typeParametersValues().size()) { + throw new IllegalStateException(); + } + for (int i = 0; i < typeParametersValues().size(); i++) { + ResolvedType thisParam = typeParametersValues().get(i); + ResolvedType otherParam = other.typeParametersValues().get(i); + if (!thisParam.equals(otherParam)) { + if (thisParam instanceof ResolvedWildcard) { + ResolvedWildcard thisParamAsWildcard = (ResolvedWildcard) thisParam; + if (thisParamAsWildcard.isSuper() && otherParam.isAssignableBy(thisParamAsWildcard.getBoundedType())) { + // ok + } else if (thisParamAsWildcard.isExtends() && thisParamAsWildcard.getBoundedType().isAssignableBy(otherParam)) { + // ok + } else if (!thisParamAsWildcard.isBounded()) { + // ok + } else { + return false; + } + } else { + if (thisParam instanceof ResolvedTypeVariable && otherParam instanceof ResolvedTypeVariable) { + List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds().stream().map(bound -> bound.getType()).collect(Collectors.toList()); + List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds().stream().map(bound -> bound.getType()).collect(Collectors.toList()); + if (thisBounds.size() == otherBounds.size() && otherBounds.containsAll(thisBounds)) { + return true; + } + } + return false; + } + } + } + return true; + } + return false; + } + + // + // Private methods + // + + private static List deriveParams(ResolvedReferenceTypeDeclaration typeDeclaration) { + return typeDeclaration.getTypeParameters().stream().map((tp) -> new ResolvedTypeVariable(tp)).collect(Collectors.toList()); + } + + public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedType.java new file mode 100644 index 0000000..d787b59 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedType.java @@ -0,0 +1,192 @@ +/* + * 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.resolution.types; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A resolved type. It could be a primitive type or a reference type (enum, class, interface). In the later case it + * could take type typeParametersValues (other TypeUsages). It could also be a TypeVariable, like in: + *

+ * class A<Bgt; { } + *

+ * where B is a TypeVariable. It could also be Wildcard Type, possibly with constraints. + * + * @author Federico Tomassetti + */ +public interface ResolvedType { + + /// + /// Relation with other types + /// + + /** + * Does this type represent an array? + */ + default boolean isArray() { + return false; + } + + default int arrayLevel() { + if (isArray()) { + return 1 + this.asArrayType().getComponentType().arrayLevel(); + } else { + return 0; + } + } + + /** + * Is this a primitive type? + */ + default boolean isPrimitive() { + return false; + } + + /** + * Is this the null type? + */ + default boolean isNull() { + return false; + } + + /** + * Is this a union type (as the ones used in multi catch clauses)? + */ + default boolean isUnionType() { + return false; + } + + /** + * Is this a non primitive value? + */ + default boolean isReference() { + return isReferenceType() || isArray() || isTypeVariable() || isNull() || isWildcard() || isUnionType(); + } + + /** + * Is this a lambda constraint type? + */ + default boolean isConstraint() { return false; } + + /** + * Can this be seen as a ReferenceTypeUsage? + * In other words: is this a reference to a class, an interface or an enum? + */ + default boolean isReferenceType() { + return false; + } + + default boolean isVoid() { + return false; + } + + default boolean isTypeVariable() { + return false; + } + + default boolean isWildcard() { + return false; + } + + /// + /// Downcasting + /// + + default ResolvedArrayType asArrayType() { + throw new UnsupportedOperationException(String.format("%s is not an Array", this)); + } + + default ResolvedReferenceType asReferenceType() { + throw new UnsupportedOperationException(String.format("%s is not a Reference Type", this)); + } + + default ResolvedTypeParameterDeclaration asTypeParameter() { + throw new UnsupportedOperationException(String.format("%s is not a Type parameter", this)); + } + + default ResolvedTypeVariable asTypeVariable() { + throw new UnsupportedOperationException(String.format("%s is not a Type variable", this)); + } + + default ResolvedPrimitiveType asPrimitive() { + throw new UnsupportedOperationException(String.format("%s is not a Primitive type", this)); + } + + default ResolvedWildcard asWildcard() { + throw new UnsupportedOperationException(String.format("%s is not a Wildcard", this)); + } + + default ResolvedLambdaConstraintType asConstraintType() { + throw new UnsupportedOperationException(String.format("%s is not a constraint type", this)); + } + + default ResolvedUnionType asUnionType() { + throw new UnsupportedOperationException(String.format("%s is not a union type", this)); + } + + /// + /// Naming + /// + + String describe(); + + /// + /// TypeParameters + /// + + /** + * Replace all variables referring to the given TypeParameter with the given value. + * By replacing these values I could also infer some type equivalence. + * Those would be collected in the given map. + */ + default ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map inferredTypes) { + return this; + } + + /** + * This is like ({@link #replaceTypeVariables(ResolvedTypeParameterDeclaration, ResolvedType, Map)} but ignores the inferred values. + */ + default ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced) { + return replaceTypeVariables(tp, replaced, new HashMap<>()); + } + + /** + * Does this type mention at all, directly or indirectly, the given type parameters? + */ + default boolean mention(List typeParameters) { + throw new UnsupportedOperationException(this.getClass().getCanonicalName()); + } + + /// + /// Assignability + /// + + /** + * This method checks if ThisType t = new OtherType() would compile. + */ + boolean isAssignableBy(ResolvedType other); + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java new file mode 100644 index 0000000..a5eaebe --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java @@ -0,0 +1,30 @@ +/* + * 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.resolution.types; + +/** + * @author Federico Tomassetti + */ +@FunctionalInterface +public interface ResolvedTypeTransformer { + ResolvedType transform(ResolvedType type); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeVariable.java new file mode 100644 index 0000000..5e91057 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -0,0 +1,129 @@ +/* + * 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.resolution.types; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + +import java.util.List; +import java.util.Map; + +/** + * From JLS 4.4: A type variable is introduced by the declaration of a type parameter of a generic class, + * interface, method, or constructor (§8.1.2, §9.1.2, §8.4.4, §8.8.4). + * + * @author Federico Tomassetti + */ +public class ResolvedTypeVariable implements ResolvedType { + + private ResolvedTypeParameterDeclaration typeParameter; + + public ResolvedTypeVariable(ResolvedTypeParameterDeclaration typeParameter) { + this.typeParameter = typeParameter; + } + + @Override + public String toString() { + return "TypeVariable {" + typeParameter.getQualifiedName() + "}"; + } + + public String qualifiedName() { + return this.typeParameter.getQualifiedName(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResolvedTypeVariable that = (ResolvedTypeVariable) o; + + if (!typeParameter.getName().equals(that.typeParameter.getName())) return false; + if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false; + if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false; + + return true; + } + + @Override + public int hashCode() { + return typeParameter.hashCode(); + } + + @Override + public boolean isArray() { + return false; + } + + @Override + public boolean isPrimitive() { + return false; + } + + @Override + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map inferredTypes) { + if(tpToBeReplaced.getName().equals(this.typeParameter.getName())){ + inferredTypes.put(this.asTypeParameter(), replaced); + return replaced; + } else { + return this; + } + } + + @Override + public boolean isReferenceType() { + return false; + } + + @Override + public String describe() { + return typeParameter.getName(); + } + + @Override + public ResolvedTypeParameterDeclaration asTypeParameter() { + return typeParameter; + } + + @Override + public ResolvedTypeVariable asTypeVariable() { + return this; + } + + @Override + public boolean isTypeVariable() { + return true; + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + if (other.isTypeVariable()) { + return describe().equals(other.describe()); + } else { + return true; + } + } + + @Override + public boolean mention(List typeParameters) { + return typeParameters.contains(typeParameter); + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedUnionType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedUnionType.java new file mode 100644 index 0000000..bd5361a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedUnionType.java @@ -0,0 +1,79 @@ +/* + * 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.resolution.types; + +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * A union type is defined in java as list of types separates by pipes. + * + * @author Federico Tomassetti + */ +public class ResolvedUnionType implements ResolvedType { + private List elements; + + public ResolvedUnionType(List elements) { + if (elements.size() < 2) { + throw new IllegalArgumentException("An union type should have at least two elements. This has " + elements.size()); + } + this.elements = new LinkedList<>(elements); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResolvedUnionType that = (ResolvedUnionType) o; + + return new HashSet<>(elements).equals(new HashSet<>(that.elements)); + } + + @Override + public int hashCode() { + return new HashSet<>(elements).hashCode(); + } + + @Override + public String describe() { + return String.join(" | ", elements.stream().map(ResolvedType::describe).collect(Collectors.toList())); + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + return elements.stream().allMatch(e -> e.isAssignableBy(other)); + } + + @Override + public boolean isUnionType() { + return true; + } + + @Override + public ResolvedUnionType asUnionType() { + return this; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedVoidType.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedVoidType.java new file mode 100644 index 0000000..b8f2194 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedVoidType.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.resolution.types; + +/** + * The special type void. + * + * @author Federico Tomassetti + */ +public class ResolvedVoidType implements ResolvedType { + public static final ResolvedType INSTANCE = new ResolvedVoidType(); + + private ResolvedVoidType() { + } + + @Override + public String describe() { + return "void"; + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isVoid() { + return true; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/ResolvedWildcard.java b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedWildcard.java new file mode 100644 index 0000000..51fd099 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/ResolvedWildcard.java @@ -0,0 +1,183 @@ +/* + * 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.resolution.types; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + +import java.util.List; +import java.util.Map; + +/** + * A wildcard can be: + * - unbounded (?) + * - have a lower bound (? super Number) + * - have an upper bound (? extends Number) + * It is not possible to have both a lower and an upper bound at the same time. + * + * @author Federico Tomassetti + */ +public class ResolvedWildcard implements ResolvedType { + + public static ResolvedWildcard UNBOUNDED = new ResolvedWildcard(null, null); + + private BoundType type; + private ResolvedType boundedType; + + private ResolvedWildcard(BoundType type, ResolvedType boundedType) { + if (type == null && boundedType != null) { + throw new IllegalArgumentException(); + } + if (type != null && boundedType == null) { + throw new IllegalArgumentException(); + } + this.type = type; + this.boundedType = boundedType; + } + + public static ResolvedWildcard superBound(ResolvedType type) { + return new ResolvedWildcard(BoundType.SUPER, type); + } + + public static ResolvedWildcard extendsBound(ResolvedType type) { + return new ResolvedWildcard(BoundType.EXTENDS, type); + } + + @Override + public String toString() { + return "WildcardUsage{" + + "type=" + type + + ", boundedType=" + boundedType + + '}'; + } + + public boolean isWildcard() { + return true; + } + + public ResolvedWildcard asWildcard() { + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ResolvedWildcard)) return false; + + ResolvedWildcard that = (ResolvedWildcard) o; + + if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) return false; + if (type != that.type) return false; + + return true; + } + + @Override + public int hashCode() { + int result = type != null ? type.hashCode() : 0; + result = 31 * result + (boundedType != null ? boundedType.hashCode() : 0); + return result; + } + + @Override + public String describe() { + if (type == null) { + return "?"; + } else if (type == BoundType.SUPER) { + return "? super " + boundedType.describe(); + } else if (type == BoundType.EXTENDS) { + return "? extends " + boundedType.describe(); + } else { + throw new UnsupportedOperationException(); + } + } + + public boolean isSuper() { + return type == BoundType.SUPER; + } + + public boolean isExtends() { + return type == BoundType.EXTENDS; + } + + public boolean isBounded() { + return isSuper() || isExtends(); + } + + public ResolvedType getBoundedType() { + if (boundedType == null) { + throw new IllegalStateException(); + } + return boundedType; + } + + @Override + public boolean isAssignableBy(ResolvedType other) { + if (boundedType == null) { + //return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); + return false; + } else if (type == BoundType.SUPER) { + return boundedType.isAssignableBy(other); + } else if (type == BoundType.EXTENDS) { + return false; + } else { + throw new RuntimeException(); + } + } + + @Override + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map inferredTypes) { + if (replaced == null) { + throw new IllegalArgumentException(); + } + if (boundedType == null) { + return this; + } + ResolvedType boundedTypeReplaced = boundedType.replaceTypeVariables(tpToReplace, replaced, inferredTypes); + if (boundedTypeReplaced == null) { + throw new RuntimeException(); + } + if (boundedTypeReplaced != boundedType) { + return new ResolvedWildcard(type, boundedTypeReplaced); + } else { + return this; + } + } + + @Override + public boolean mention(List typeParameters) { + return boundedType != null && boundedType.mention(typeParameters); + } + + public boolean isUpperBounded() { + return isSuper(); + } + + public boolean isLowerBounded() { + return isExtends(); + } + + public enum BoundType { + SUPER, + EXTENDS + } + +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java new file mode 100644 index 0000000..c310fb5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java @@ -0,0 +1,72 @@ +/* + * 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.resolution.types.parametrization; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.ResolvedWildcard; + +import java.util.Optional; + +/** + * @author Federico Tomassetti + */ +public interface ResolvedTypeParameterValueProvider { + + /** + * Calculate the value for the given type parameter. + * It could be inherited. + */ + Optional typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration); + + /** + * Replace the type typeParametersValues present in the given type with the ones for which this type + * has a value. + */ + default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { + if (type.isTypeVariable()) { + ResolvedTypeParameterDeclaration typeParameter = type.asTypeParameter(); + if (typeParameter.declaredOnType()) { + Optional typeParam = typeParamValue(typeParameter); + if (typeParam.isPresent()) { + type = typeParam.get(); + } + } + } + + if (type.isWildcard() && type.asWildcard().isBounded()) { + if (type.asWildcard().isExtends()) { + return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); + } else { + return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); + } + } + + if (type.isReferenceType()) { + type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType); + } + + return type; + } + + Optional getGenericParameterByName(String name); +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java new file mode 100644 index 0000000..b1cb16d --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java @@ -0,0 +1,146 @@ +/* + * 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.resolution.types.parametrization; + +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.ResolvedTypeVariable; + +import java.util.*; + +/** + * A map of values associated to TypeParameters. + * + * @author Federico Tomassetti + */ +public class ResolvedTypeParametersMap { + + public static class Builder { + private Map nameToValue; + private Map nameToDeclaration; + + public Builder() { + nameToValue = new HashMap<>(); + nameToDeclaration = new HashMap<>(); + } + + private Builder(Map nameToValue, + Map nameToDeclaration) { + this.nameToValue = new HashMap<>(); + this.nameToValue.putAll(nameToValue); + this.nameToDeclaration = new HashMap<>(); + this.nameToDeclaration.putAll(nameToDeclaration); + } + + public ResolvedTypeParametersMap build() { + return new ResolvedTypeParametersMap(nameToValue, nameToDeclaration); + } + + public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, + ResolvedType value) { + // TODO: we shouldn't just silently overwrite existing types! + String qualifiedName = typeParameter.getQualifiedName(); + nameToValue.put(qualifiedName, value); + nameToDeclaration.put(qualifiedName, typeParameter); + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ResolvedTypeParametersMap)) return false; + + ResolvedTypeParametersMap that = (ResolvedTypeParametersMap) o; + + return nameToValue.equals(that.nameToValue) && nameToDeclaration.equals(that.nameToDeclaration); + + } + + @Override + public int hashCode() { + return nameToValue.hashCode(); + } + + @Override + public String toString() { + return "TypeParametersMap{" + + "nameToValue=" + nameToValue + + '}'; + } + + private Map nameToValue; + private Map nameToDeclaration; + + public static ResolvedTypeParametersMap empty() { + return new Builder().build(); + } + + private ResolvedTypeParametersMap(Map nameToValue, + Map nameToDeclaration) { + this.nameToValue = new HashMap<>(); + this.nameToValue.putAll(nameToValue); + this.nameToDeclaration = new HashMap<>(); + this.nameToDeclaration.putAll(nameToDeclaration); + } + + public ResolvedType getValue(ResolvedTypeParameterDeclaration typeParameter) { + String qualifiedName = typeParameter.getQualifiedName(); + if (nameToValue.containsKey(qualifiedName)) { + return nameToValue.get(qualifiedName); + } else { + return new ResolvedTypeVariable(typeParameter); + } + } + + public Optional getValueBySignature(String signature) { + if (nameToValue.containsKey(signature)) { + return Optional.of(nameToValue.get(signature)); + } else { + return Optional.empty(); + } + } + + public List getNames(){ + return new ArrayList<>(nameToValue.keySet()); + } + + public List getTypes(){ + return new ArrayList<>(nameToValue.values()); + } + + public Builder toBuilder() { + return new Builder(nameToValue, nameToDeclaration); + } + + public boolean isEmpty() { + return nameToValue.isEmpty(); + } + + public ResolvedType replaceAll(ResolvedType type) { + Map inferredTypes = new HashMap<>(); + for (ResolvedTypeParameterDeclaration typeParameterDeclaration : this.nameToDeclaration.values()) { + type = type.replaceTypeVariables(typeParameterDeclaration, getValue(typeParameterDeclaration), inferredTypes); + } + return type; + } +} diff --git a/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java new file mode 100644 index 0000000..91a792a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java @@ -0,0 +1,31 @@ +/* + * 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.resolution.types.parametrization; + +/** + * Something which can have values for TypeParameters. + * + * @author Federico Tomassetti + */ +public interface ResolvedTypeParametrized { + ResolvedTypeParametersMap typeParametersMap(); +} diff --git a/JavaParser/src/com/github/javaparser/utils/ClassUtils.java b/JavaParser/src/com/github/javaparser/utils/ClassUtils.java new file mode 100644 index 0000000..b0bdf05 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/ClassUtils.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import java.util.HashMap; +import java.util.Map; + +public class ClassUtils { + /** + * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. + */ + private static final Map, Class> primitiveWrapperMap = new HashMap<>(); + + static { + primitiveWrapperMap.put(Boolean.TYPE, Boolean.class); + primitiveWrapperMap.put(Byte.TYPE, Byte.class); + primitiveWrapperMap.put(Character.TYPE, Character.class); + primitiveWrapperMap.put(Short.TYPE, Short.class); + primitiveWrapperMap.put(Integer.TYPE, Integer.class); + primitiveWrapperMap.put(Long.TYPE, Long.class); + primitiveWrapperMap.put(Double.TYPE, Double.class); + primitiveWrapperMap.put(Float.TYPE, Float.class); + primitiveWrapperMap.put(Void.TYPE, Void.TYPE); + } + + /** + * Maps wrapper {@code Class}es to their corresponding primitive types. + */ + private static final Map, Class> wrapperPrimitiveMap = new HashMap<>(); + + static { + for (final Class primitiveClass : primitiveWrapperMap.keySet()) { + final Class wrapperClass = primitiveWrapperMap.get(primitiveClass); + if (!primitiveClass.equals(wrapperClass)) { + wrapperPrimitiveMap.put(wrapperClass, primitiveClass); + } + } + } + + /** + * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, + * {@link Character}, + * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * + * @param type The class to query or null. + * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link + * Character}, {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + */ + public static boolean isPrimitiveOrWrapper(final Class type) { + if (type == null) { + return false; + } + return type.isPrimitive() || isPrimitiveWrapper(type); + } + + /** + * Returns whether the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, + * {@link Short}, + * {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * + * @param type The class to query or null. + * @return true if the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, + * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). + * @since 3.1 + */ + public static boolean isPrimitiveWrapper(final Class type) { + return wrapperPrimitiveMap.containsKey(type); + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/CodeGenerationUtils.java b/JavaParser/src/com/github/javaparser/utils/CodeGenerationUtils.java new file mode 100644 index 0000000..098920b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/CodeGenerationUtils.java @@ -0,0 +1,137 @@ +package com.github.javaparser.utils; + +import java.io.File; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static com.github.javaparser.utils.Utils.capitalize; +import static com.github.javaparser.utils.Utils.decapitalize; + +public final class CodeGenerationUtils { + private CodeGenerationUtils() { + } + + public static String getterName(Class type, String name) { + if (name.startsWith("is")) { + return name; + } else if (type.equals(Boolean.class)) { + return "is" + capitalize(name); + } + return "get" + capitalize(name); + } + + public static String getterToPropertyName(String getterName) { + if (getterName.startsWith("is")) { + return decapitalize(getterName.substring("is".length())); + } else if (getterName.startsWith("get")) { + return decapitalize(getterName.substring("get".length())); + } else if (getterName.startsWith("has")) { + return decapitalize(getterName.substring("has".length())); + } + throw new IllegalArgumentException("Unexpected getterName '" + getterName + "'"); + } + + public static String setterName(String fieldName) { + if (fieldName.startsWith("is")) { + return "set" + fieldName.substring(2); + } + return "set" + capitalize(fieldName); + } + + public static String optionalOf(String text, boolean isOptional) { + if (isOptional) { + return f("Optional.of(%s)", text); + } else { + return "Optional.empty()"; + } + } + + /** + * A shortcut to String.format. + */ + public static String f(String format, Object... params) { + return String.format(format, params); + } + + /** + * Calculates the path to a file in a package. + * + * @param root the root directory in which the package resides + * @param pkg the package in which the file resides, like "com.laamella.parser" + * @param file the filename of the file in the package. + */ + public static Path fileInPackageAbsolutePath(String root, String pkg, String file) { + pkg = packageToPath(pkg); + return Paths.get(root, pkg, file).normalize(); + } + + public static Path fileInPackageAbsolutePath(Path root, String pkg, String file) { + return fileInPackageAbsolutePath(root.toString(), pkg, file); + } + + /** + * Turns a package and a file into a relative path. "com.laamella" and "Simple.java" will become + * "com/laamella/Simple.java" + */ + public static Path fileInPackageRelativePath(String pkg, String file) { + pkg = packageToPath(pkg); + return Paths.get(pkg, file).normalize(); + } + + /** + * Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser" + */ + public static String packageToPath(String pkg) { + return pkg.replace(".", File.separator); + } + + /** + * Calculates the path of a package. + * + * @param root the root directory in which the package resides + * @param pkg the package, like "com.laamella.parser" + */ + public static Path packageAbsolutePath(String root, String pkg) { + pkg = packageToPath(pkg); + return Paths.get(root, pkg).normalize(); + } + + public static Path packageAbsolutePath(Path root, String pkg) { + return packageAbsolutePath(root.toString(), pkg); + } + + /** + * @return the root directory of the classloader for class c. + */ + public static Path classLoaderRoot(Class c) { + try { + return Paths.get(c.getProtectionDomain().getCodeSource().getLocation().toURI()); + } catch (URISyntaxException e) { + throw new AssertionError("Bug in JavaParser, please report.", e); + } + } + + /** + * Useful for locating source code in your Maven project. Finds the classpath for class c, then backs up out of + * "target/(test-)classes", giving the directory containing the pom.xml. + */ + public static Path mavenModuleRoot(Class c) { + return classLoaderRoot(c).resolve(Paths.get("..", "..")).normalize(); + } + + /** + * Shortens path "full" by cutting "difference" off the end of it. + */ + public static Path subtractPaths(Path full, Path difference) { + while (difference != null) { + if (difference.getFileName().equals(full.getFileName())) { + difference = difference.getParent(); + full = full.getParent(); + } else { + throw new RuntimeException(f("'%s' could not be subtracted from '%s'", difference, full)); + } + } + return full; + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/Log.java b/JavaParser/src/com/github/javaparser/utils/Log.java new file mode 100644 index 0000000..12a9cdc --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/Log.java @@ -0,0 +1,122 @@ +package com.github.javaparser.utils; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * To avoid dependencies on logging frameworks, we have invented yet another logging framework :-) + */ +public class Log { + /** + * This adapter logs to standard out and standard error. + */ + public static class StandardOutStandardErrorAdapter implements Adapter { + @Override + public void info(String message) { + System.out.println(message); + } + + @Override + public void trace(String message) { + System.out.println(message); + } + + @Override + public void error(Throwable throwable, String message) { + if (message == null) { + System.err.println(throwable.getMessage()); + printStackTrace(throwable); + } else if (throwable == null) { + System.err.println(message); + } else { + System.err.println(message + ":" + throwable.getMessage()); + printStackTrace(throwable); + } + } + + private void printStackTrace(Throwable throwable) { + try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { + throwable.printStackTrace(pw); + trace(sw.toString()); + } catch (IOException e) { + throw new AssertionError("Error in logging library"); + } + } + } + + /** + * This adapter logs nothing. + */ + public static class SilentAdapter implements Adapter { + @Override + public void info(String message) { + } + + @Override + public void trace(String message) { + } + + @Override + public void error(Throwable throwable, String f) { + } + } + + public interface Adapter { + + void info(String message); + + void trace(String message); + + /** + * Both can be null. + */ + void error(Throwable throwable, String f); + } + + private static Adapter CURRENT_ADAPTER = new SilentAdapter(); + + /** + * Change how logging is handled. You can set your own implementation that forwards to your logging library. + */ + public static void setAdapter(Adapter adapter) { + CURRENT_ADAPTER = adapter; + } + + /** + * For logging information that may help solving a problem. + */ + public static void trace(String format, Object... args) { + CURRENT_ADAPTER.trace(f(format, args)); + } + + /** + * For logging things that are nice to see scrolling by. + */ + public static void info(String format, Object... args) { + CURRENT_ADAPTER.info(f(format, args)); + } + + /** + * For drawing attention to an error. + */ + public static void error(Throwable throwable) { + CURRENT_ADAPTER.error(throwable, null); + } + + /** + * For drawing attention to an error that you don't have an exception for. + */ + public static void error(Throwable throwable, String format, Object... args) { + CURRENT_ADAPTER.error(throwable, f(format, args)); + } + + /** + * For drawing attention to an error that you don't have an exception for. + */ + public static void error(String format, Object... args) { + CURRENT_ADAPTER.error(null, f(format, args)); + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/Pair.java b/JavaParser/src/com/github/javaparser/utils/Pair.java new file mode 100644 index 0000000..6f84a7b --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/Pair.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * Simply a pair of objects. + * + * @param type of object a. + * @param type of object b. + */ +public class Pair { + public final A a; + public final B b; + + public Pair(A a, B b) { + this.a = a; + this.b = b; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Pair pair = (Pair) o; + + if (a != null ? !a.equals(pair.a) : pair.a != null) return false; + if (b != null ? !b.equals(pair.b) : pair.b != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = a != null ? a.hashCode() : 0; + return 31 * result + (b != null ? b.hashCode() : 0); + } + + @Override + public String toString() { + return f("<%s, %s>", a, b); + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/PositionUtils.java b/JavaParser/src/com/github/javaparser/utils/PositionUtils.java new file mode 100644 index 0000000..6852b29 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/PositionUtils.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import com.github.javaparser.Position; +import com.github.javaparser.Range; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; +import com.github.javaparser.ast.nodeTypes.NodeWithType; +import com.github.javaparser.ast.type.Type; + +import java.util.List; + +import static java.lang.Integer.signum; + +public final class PositionUtils { + + private PositionUtils() { + // prevent instantiation + } + + public static void sortByBeginPosition(List nodes) { + sortByBeginPosition(nodes, false); + } + + public static void sortByBeginPosition(NodeList nodes) { + sortByBeginPosition(nodes, false); + } + + public static void sortByBeginPosition(List nodes, final boolean ignoringAnnotations) { + nodes.sort((o1, o2) -> PositionUtils.compare(o1, o2, ignoringAnnotations)); + } + + public static boolean areInOrder(Node a, Node b) { + return areInOrder(a, b, false); + } + + public static boolean areInOrder(Node a, Node b, boolean ignoringAnnotations) { + return compare(a, b, ignoringAnnotations) <= 0; + } + + private static int compare(Node a, Node b, boolean ignoringAnnotations) { + if(a.getRange().isPresent() && !b.getRange().isPresent()) { + return -1; + } + if(!a.getRange().isPresent() && b.getRange().isPresent()) { + return 1; + } + if (!a.getRange().isPresent() && !b.getRange().isPresent()) { + return 0; + } + if (ignoringAnnotations) { + int signLine = signum(beginLineWithoutConsideringAnnotation(a) - beginLineWithoutConsideringAnnotation(b)); + if (signLine == 0) { + return signum(beginColumnWithoutConsideringAnnotation(a) - beginColumnWithoutConsideringAnnotation(b)); + } else { + return signLine; + } + } + + Position aBegin = a.getBegin().get(); + Position bBegin = b.getBegin().get(); + + int signLine = signum(aBegin.line - bBegin.line); + if (signLine == 0) { + return signum(aBegin.column - bBegin.column); + } else { + return signLine; + } + } + + public static AnnotationExpr getLastAnnotation(Node node) { + if (node instanceof NodeWithAnnotations) { + NodeList annotations = NodeList.nodeList(((NodeWithAnnotations) node).getAnnotations()); + if (annotations.isEmpty()) { + return null; + } + sortByBeginPosition(annotations); + return annotations.get(annotations.size() - 1); + } else { + return null; + } + } + + private static int beginLineWithoutConsideringAnnotation(Node node) { + return beginNodeWithoutConsideringAnnotations(node).getRange().get().begin.line; + } + + + private static int beginColumnWithoutConsideringAnnotation(Node node) { + return beginNodeWithoutConsideringAnnotations(node).getRange().get().begin.column; + } + + private static Node beginNodeWithoutConsideringAnnotations(Node node) { + if (node instanceof MethodDeclaration || node instanceof FieldDeclaration) { + NodeWithType casted = (NodeWithType) node; + return casted.getType(); + } else if (node instanceof ClassOrInterfaceDeclaration) { + ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; + return casted.getName(); + } else { + return node; + } + } + + public static boolean nodeContains(Node container, Node contained, boolean ignoringAnnotations) { + final Range containedRange = contained.getRange().get(); + final Range containerRange = container.getRange().get(); + if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) { + return container.containsWithin(contained); + } + if (!container.containsWithin(contained)) { + return false; + } + // if the node is contained, but it comes immediately after the annotations, + // let's not consider it contained + if (container instanceof NodeWithAnnotations) { + int bl = beginLineWithoutConsideringAnnotation(container); + int bc = beginColumnWithoutConsideringAnnotation(container); + if (bl > containedRange.begin.line) return false; + if (bl == containedRange.begin.line && bc > containedRange.begin.column) return false; + if (containerRange.end.line < containedRange.end.line) return false; + // TODO < or <= ? + return !(containerRange.end.line == containedRange.end.line && containerRange.end.column < containedRange.end.column); + } + return true; + } + +} diff --git a/JavaParser/src/com/github/javaparser/utils/SeparatedItemStringBuilder.java b/JavaParser/src/com/github/javaparser/utils/SeparatedItemStringBuilder.java new file mode 100644 index 0000000..3cef723 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/SeparatedItemStringBuilder.java @@ -0,0 +1,45 @@ +package com.github.javaparser.utils; + +/** + * Builds a string containing a list of items with a prefix, a postfix, and a separator. + *
Example: (1,2,3) which has prefix "(", separator ",", postfix ")" and the items 1 through 3. + *

Java 8 offers the very nice Collectors.joining(String, String, String) which does the same thing. + */ +public class SeparatedItemStringBuilder { + private final String separator; + private final String postfix; + private boolean hasItems = false; + private StringBuilder builder; + + public SeparatedItemStringBuilder(String prefix, String separator, String postfix) { + builder = new StringBuilder(prefix); + this.separator = separator; + this.postfix = postfix; + + } + + /** + * Add one item. Either pass a string, or a format for String.format and corresponding arguments. + */ + public SeparatedItemStringBuilder append(CharSequence format, Object... args) { + if (hasItems) { + builder.append(separator); + } + builder.append(String.format(format.toString(), args)); + hasItems = true; + return this; + } + + public boolean hasItems() { + return hasItems; + } + + /** + * Convert the builder into its final string representation. + */ + @Override + public String toString() { + // This order of toStringing avoids debuggers from making a mess. + return builder.toString() + postfix; + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/SourceRoot.java b/JavaParser/src/com/github/javaparser/utils/SourceRoot.java new file mode 100644 index 0000000..ba3591a --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/SourceRoot.java @@ -0,0 +1,588 @@ +package com.github.javaparser.utils; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseProblemException; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.PrettyPrinter; + +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.RecursiveAction; +import java.util.function.Function; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; +import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; +import static com.github.javaparser.utils.SourceRoot.Callback.Result.SAVE; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.nio.file.FileVisitResult.CONTINUE; +import static java.nio.file.FileVisitResult.SKIP_SUBTREE; + +/** + * A collection of Java source files located in one directory and its subdirectories on the file system. The root directory + * corresponds to the root of the package structure of the source files within. Files can be parsed and written back one + * by one or all together. Note that the internal cache used is thread-safe. + *

+ */ +public class SourceRoot { + @FunctionalInterface + public interface Callback { + enum Result { + SAVE, DONT_SAVE + } + + /** + * @param localPath the path to the file that was parsed, relative to the source root path. + * @param absolutePath the absolute path to the file that was parsed. + * @param result the result of of parsing the file. + */ + Result process(Path localPath, Path absolutePath, ParseResult result); + } + + private final Path root; + private final Map> cache = new ConcurrentHashMap<>(); + private ParserConfiguration parserConfiguration = new ParserConfiguration(); + private Function printer = new PrettyPrinter()::print; + private static final Pattern JAVA_IDENTIFIER = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*"); + + /** + * @param root the root directory of a set of source files. It corresponds to the root of the package structure of the + * source files within, like "javaparser/javaparser-core/src/main/java" + */ + public SourceRoot(Path root) { + assertNotNull(root); + if (!Files.isDirectory(root)) { + throw new IllegalArgumentException("Only directories are allowed as root path: " + root); + } + this.root = root.normalize(); + Log.info("New source root at \"%s\"", this.root); + } + + /** + * @param root the root directory of a set of source files. It corresponds to the root of the package structure of the + * source files within, like "javaparser/javaparser-core/src/main/java" + */ + public SourceRoot(Path root, ParserConfiguration parserConfiguration) { + this(root); + setParserConfiguration(parserConfiguration); + } + + /** + * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file + * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you + * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you + * might want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + * @deprecated pass ParserConfiguration instead of JavaParser + */ + @Deprecated + public ParseResult tryToParse(String startPackage, String filename, JavaParser javaParser) + throws IOException { + return tryToParse(startPackage, filename, javaParser.getParserConfiguration()); + } + + /** + * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file + * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you + * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you + * might want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public ParseResult tryToParse(String startPackage, String filename, ParserConfiguration configuration) throws IOException { + assertNotNull(startPackage); + assertNotNull(filename); + final Path relativePath = fileInPackageRelativePath(startPackage, filename); + if (cache.containsKey(relativePath)) { + Log.trace("Retrieving cached %s", relativePath); + return cache.get(relativePath); + } + final Path path = root.resolve(relativePath); + Log.trace("Parsing %s", path); + final ParseResult result = new JavaParser(configuration) + .parse(COMPILATION_UNIT, provider(path)); + result.getResult().ifPresent(cu -> cu.setStorage(path)); + cache.put(relativePath, result); + return result; + } + + /** + * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file + * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you + * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you + * might want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public ParseResult tryToParse(String startPackage, String filename) throws IOException { + return tryToParse(startPackage, filename, parserConfiguration); + } + + /** + * Tries to parse all .java files in a package recursively, and returns all files ever parsed with this source root. + * It keeps track of all parsed files so you can write them out with a single saveAll() call. Note that the cache + * grows with every file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple + * times (where the cache is useful) you might want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public List> tryToParse(String startPackage) throws IOException { + assertNotNull(startPackage); + logPackage(startPackage); + final Path path = packageAbsolutePath(root, startPackage); + Files.walkFileTree(path, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (!attrs.isDirectory() && file.toString().endsWith(".java")) { + Path relative = root.relativize(file.getParent()); + tryToParse(relative.toString(), file.getFileName().toString()); + } + return CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + return isSensibleDirectoryToEnter(dir) ? CONTINUE : SKIP_SUBTREE; + } + }); + return getCache(); + } + + private static boolean isSensibleDirectoryToEnter(Path dir) throws IOException { + final String dirToEnter = dir.getFileName().toString(); + // Don't enter directories that cannot be packages. + final boolean directoryIsAValidJavaIdentifier = JAVA_IDENTIFIER.matcher(dirToEnter).matches(); + // Don't enter directories that are hidden, assuming that people don't store source files in hidden directories. + if (Files.isHidden(dir) || !directoryIsAValidJavaIdentifier) { + Log.trace("Not processing directory \"%s\"", dirToEnter); + return false; + } + return true; + } + + /** + * Tries to parse all .java files under the source root recursively, and returns all files ever parsed with this + * source root. It keeps track of all parsed files so you can write them out with a single saveAll() call. Note that + * the cache grows with every file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse + * files multiple times (where the cache is useful) you might want to use the parse method with a callback. + */ + public List> tryToParse() throws IOException { + return tryToParse(""); + } + + /** + * Tries to parse all .java files in a package recursively using multiple threads, and returns all files ever parsed + * with this source root. A new thread is forked each time a new directory is visited and is responsible for parsing + * all .java files in that directory. Note that to ensure thread safety, a new parser instance is created for + * every file with the internal parser's (i.e. {@link #setJavaParser}) configuration. It keeps track of all parsed + * files so you can write them out with a single saveAll() call. Note that the cache grows with every file parsed, + * so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is + * useful) you might want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public List> tryToParseParallelized(String startPackage) { + assertNotNull(startPackage); + logPackage(startPackage); + final Path path = packageAbsolutePath(root, startPackage); + ParallelParse parse = new ParallelParse(path, (file, attrs) -> { + if (!attrs.isDirectory() && file.toString().endsWith(".java")) { + Path relative = root.relativize(file.getParent()); + try { + tryToParse( + relative.toString(), + file.getFileName().toString(), + parserConfiguration); + } catch (IOException e) { + Log.error(e); + } + } + return CONTINUE; + }); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(parse); + return getCache(); + } + + /** + * Tries to parse all .java files under the source root recursively using multiple threads, and returns all files + * ever parsed with this source root. A new thread is forked each time a new directory is visited and is responsible + * for parsing all .java files in that directory. Note that to ensure thread safety, a new parser instance is + * created for every file with the internal parser's (i.e. {@link #setJavaParser}) configuration. It keeps track of + * all parsed files so you can write them out with a single saveAll() call. Note that the cache grows with every + * file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the + * cache is useful) you might want to use the parse method with a callback. + */ + public List> tryToParseParallelized() throws IOException { + return tryToParseParallelized(""); + } + + /** + * Parses a .java files under the source root and returns its CompilationUnit. It keeps track of the parsed file so + * you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you don't + * need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you might + * want to use the parse method with a callback. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + * @throws ParseProblemException when something went wrong. + */ + public CompilationUnit parse(String startPackage, String filename) { + assertNotNull(startPackage); + assertNotNull(filename); + try { + final ParseResult result = tryToParse(startPackage, filename); + if (result.isSuccessful()) { + return result.getResult().get(); + } + throw new ParseProblemException(result.getProblems()); + } catch (IOException e) { + throw new ParseProblemException(e); + } + } + + /** + * Tries to parse all .java files in a package recursively and passes them one by one to the callback. In comparison + * to the other parse methods, this is much more memory efficient, but saveAll() won't work. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + * @deprecated pass ParserConfiguration instead of JavaParser + */ + @Deprecated + public SourceRoot parse(String startPackage, JavaParser javaParser, Callback callback) throws IOException { + return parse(startPackage, javaParser.getParserConfiguration(), callback); + } + + /** + * Tries to parse all .java files in a package recursively and passes them one by one to the callback. In comparison + * to the other parse methods, this is much more memory efficient, but saveAll() won't work. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public SourceRoot parse(String startPackage, ParserConfiguration configuration, Callback callback) throws IOException { + assertNotNull(startPackage); + assertNotNull(configuration); + assertNotNull(callback); + logPackage(startPackage); + final JavaParser javaParser = new JavaParser(configuration); + final Path path = packageAbsolutePath(root, startPackage); + Files.walkFileTree(path, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException { + if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) { + Path localPath = root.relativize(absolutePath); + Log.trace("Parsing %s", localPath); + final ParseResult result = javaParser.parse(COMPILATION_UNIT, + provider(absolutePath)); + result.getResult().ifPresent(cu -> cu.setStorage(absolutePath)); + if (callback.process(localPath, absolutePath, result) == SAVE) { + if (result.getResult().isPresent()) { + save(result.getResult().get(), path); + } + } + } + return CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + return isSensibleDirectoryToEnter(dir) ? CONTINUE : SKIP_SUBTREE; + } + }); + return this; + } + + private void logPackage(String startPackage) { + if (startPackage.isEmpty()) { + return; + } + Log.info("Parsing package \"%s\"", startPackage); + } + + /** + * Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the + * callback. A new thread is forked each time a new directory is visited and is responsible for parsing all .java + * files in that directory. Note that the provided {@link Callback} code must be made thread-safe. Note + * that to ensure thread safety, a new parser instance is created for every file with the provided {@link + * ParserConfiguration}. In comparison to the other parse methods, this is much more memory efficient, but saveAll() + * won't work. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public SourceRoot parseParallelized(String startPackage, ParserConfiguration configuration, Callback callback) { + assertNotNull(startPackage); + assertNotNull(configuration); + assertNotNull(callback); + logPackage(startPackage); + final Path path = packageAbsolutePath(root, startPackage); + ParallelParse parse = new ParallelParse(path, (file, attrs) -> { + if (!attrs.isDirectory() && file.toString().endsWith(".java")) { + Path localPath = root.relativize(file); + Log.trace("Parsing %s", localPath); + try { + ParseResult result = new JavaParser(configuration) + .parse(COMPILATION_UNIT, provider(file)); + result.getResult().ifPresent(cu -> cu.setStorage(file)); + if (callback.process(localPath, file, result) == SAVE) { + if (result.getResult().isPresent()) { + save(result.getResult().get(), path); + } + } + } catch (IOException e) { + Log.error(e); + } + } + return CONTINUE; + }); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(parse); + return this; + } + + /** + * Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the + * callback. A new thread is forked each time a new directory is visited and is responsible for parsing all .java + * files in that directory. Note that the provided {@link Callback} code must be made thread-safe. Note + * that to ensure thread safety, a new parser instance is created for every file. In comparison to the other + * parse methods, this is much more memory efficient, but saveAll() won't work. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public SourceRoot parseParallelized(String startPackage, Callback callback) throws IOException { + return parseParallelized(startPackage, new ParserConfiguration(), callback); + } + + /** + * Tries to parse all .java files recursively using multiple threads, and passes them one by one to the callback. A + * new thread is forked each time a new directory is visited and is responsible for parsing all .java files in that + * directory. Note that the provided {@link Callback} code must be made thread-safe. Note that to + * ensure thread safety, a new parser instance is created for every file. In comparison to the other parse methods, + * this is much more memory efficient, but saveAll() won't work. + */ + public SourceRoot parseParallelized(Callback callback) throws IOException { + return parseParallelized("", new ParserConfiguration(), callback); + } + + /** + * Add a newly created Java file to the cache of this source root. It will be saved when saveAll is called. + * + * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files. + */ + public SourceRoot add(String startPackage, String filename, CompilationUnit compilationUnit) { + assertNotNull(startPackage); + assertNotNull(filename); + assertNotNull(compilationUnit); + Log.trace("Adding new file %s.%s", startPackage, filename); + final Path path = fileInPackageRelativePath(startPackage, filename); + final ParseResult parseResult = new ParseResult<>( + compilationUnit, + new ArrayList<>(), + null, + null); + cache.put(path, parseResult); + return this; + } + + /** + * Add a newly created Java file to the cache of this source root. It will be saved when saveAll is called. It needs + * to have its path set. + */ + public SourceRoot add(CompilationUnit compilationUnit) { + assertNotNull(compilationUnit); + if (compilationUnit.getStorage().isPresent()) { + final Path path = compilationUnit.getStorage().get().getPath(); + Log.trace("Adding new file %s", path); + final ParseResult parseResult = new ParseResult<>( + compilationUnit, + new ArrayList<>(), + null, + null); + cache.put(path, parseResult); + } else { + throw new AssertionError("Files added with this method should have their path set."); + } + return this; + } + + /** + * Save the given compilation unit to the given path. + */ + private SourceRoot save(CompilationUnit cu, Path path) { + assertNotNull(cu); + assertNotNull(path); + cu.setStorage(path); + cu.getStorage().get().save(printer); + return this; + } + + /** + * Save all previously parsed files back to a new path. + */ + public SourceRoot saveAll(Path root) { + assertNotNull(root); + Log.info("Saving all files (%s) to %s", cache.size(), root); + for (Map.Entry> cu : cache.entrySet()) { + final Path path = root.resolve(cu.getKey()); + if (cu.getValue().getResult().isPresent()) { + Log.trace("Saving %s", path); + save(cu.getValue().getResult().get(), path); + } + } + return this; + } + + /** + * Save all previously parsed files back to where they were found. + */ + public SourceRoot saveAll() { + return saveAll(root); + } + + /** + * The Java files that have been parsed by this source root object, or have been added manually. + */ + public List> getCache() { + return new ArrayList<>(cache.values()); + } + + /** + * The CompilationUnits of the Java files that have been parsed succesfully by this source root object, or have been + * added manually. + */ + public List getCompilationUnits() { + return cache.values().stream() + .filter(ParseResult::isSuccessful) + .map(p -> p.getResult().get()) + .collect(Collectors.toList()); + } + + /** + * The path that was passed in the constructor. + */ + public Path getRoot() { + return root; + } + + /** + * @deprecated store ParserConfiguration now + */ + @Deprecated + public JavaParser getJavaParser() { + return new JavaParser(parserConfiguration); + } + + /** + * Set the parser that is used for parsing by default. + * + * @deprecated store ParserConfiguration now + */ + @Deprecated + public SourceRoot setJavaParser(JavaParser javaParser) { + assertNotNull(javaParser); + this.parserConfiguration = javaParser.getParserConfiguration(); + return this; + } + + public ParserConfiguration getParserConfiguration() { + return parserConfiguration; + } + + /** + * Set the parser configuration that is used for parsing when no configuration is passed to a method. + */ + public SourceRoot setParserConfiguration(ParserConfiguration parserConfiguration) { + assertNotNull(parserConfiguration); + this.parserConfiguration = parserConfiguration; + return this; + } + + /** + * Set the printing function that transforms compilation units into a string to save. + */ + public SourceRoot setPrinter(Function printer) { + assertNotNull(printer); + this.printer = printer; + return this; + } + + /** + * Get the printing function. + */ + public Function getPrinter() { + return printer; + } + + /** + * Executes a recursive file tree walk using threads. A new thread is invoked for each new directory discovered + * during the walk. For each file visited, the user-provided {@link VisitFileCallback} is called with the current + * path and file attributes. Any shared resources accessed in a {@link VisitFileCallback} should be made + * thread-safe. + */ + private static class ParallelParse extends RecursiveAction { + + private static final long serialVersionUID = 1L; + private final Path path; + private final VisitFileCallback callback; + + ParallelParse(Path path, VisitFileCallback callback) { + this.path = path; + this.callback = callback; + } + + @Override + protected void compute() { + final List walks = new ArrayList<>(); + try { + Files.walkFileTree(path, new SimpleFileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (!SourceRoot.isSensibleDirectoryToEnter(dir)) { + return SKIP_SUBTREE; + } + if (!dir.equals(ParallelParse.this.path)) { + ParallelParse w = new ParallelParse(dir, callback); + w.fork(); + walks.add(w); + return SKIP_SUBTREE; + } else { + return CONTINUE; + } + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + return callback.process(file, attrs); + } + }); + } catch (IOException e) { + Log.error(e); + } + + for (ParallelParse w : walks) { + w.join(); + } + } + + interface VisitFileCallback { + FileVisitResult process(Path file, BasicFileAttributes attrs); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/SourceZip.java b/JavaParser/src/com/github/javaparser/utils/SourceZip.java new file mode 100644 index 0000000..ffb64f4 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/SourceZip.java @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.Utils.assertNotNull; + +/** + * A collection of Java source files and its sub-directories located in a ZIP or JAR file on the file system. + * Files can be parsed with a callback. + * + */ +public class SourceZip { + + private final Path zipPath; + private ParserConfiguration parserConfiguration; + + /** + * Create a new ZIP parser. An instance of {@link JavaParser} with the default {@link ParserConfiguration} will be + * used to parse the ZIP. + * + * @param zipPath The absolute path of ZIP file to parse. + */ + public SourceZip(Path zipPath) { + this(zipPath, new ParserConfiguration()); + } + + /** + * Create a new ZIP parser. An instance of {@link JavaParser} with the given configuration will be used to parse + * the ZIP. + * + * @param zipPath The absolute path of ZIP file to parse. + * @param configuration The configuration to initiate the default parser with. + */ + public SourceZip(Path zipPath, ParserConfiguration configuration) { + assertNotNull(zipPath); + assertNotNull(configuration); + this.zipPath = zipPath.normalize(); + this.parserConfiguration = configuration; + Log.info("New source zip at \"%s\"", this.zipPath); + } + + /** + * Tries to parse all '.java' files in the ZIP located at this SourceZip's path and returns the parse + * results in a list. + * + * @return A list of path-compilation unit pairs. + * + * @throws IOException If an error occurs while trying to parse the given source. + */ + public List>> parse() throws IOException { + Log.info("Parsing zip at \"%s\"", zipPath); + List>> results = new ArrayList<>(); + parse((path, result) -> results.add(new Pair<>(path, result))); + return results; + } + + /** + * Tries to parse all '.java' files in the ZIP located at this SourceZip's path and returns the parse + * results in a list. + * + * @return A list of path-compilation unit pairs. + * + * @throws IOException If an error occurs while trying to parse the given source. + */ + public SourceZip parse(Callback callback) throws IOException { + Log.info("Parsing zip at \"%s\"", zipPath); + JavaParser javaParser = new JavaParser(parserConfiguration); + try (ZipFile zipFile = new ZipFile(zipPath.toFile())) { + for (ZipEntry entry : Collections.list(zipFile.entries())) { + if (!entry.isDirectory() && entry.getName().endsWith(".java")) { + Log.info("Parsing zip entry \"%s\"", entry.getName()); + final ParseResult result = javaParser.parse(COMPILATION_UNIT, + provider(zipFile.getInputStream(entry))); + callback.process(Paths.get(entry.getName()), result); + } + } + } + return this; + } + + /** + * An interface to define a callback for each file that's parsed. + */ + @FunctionalInterface + public interface Callback { + + /** + * Process the given parse result. + * + * @param relativeZipEntryPath The relative path of the entry in the ZIP file that was parsed. + * @param result The parse result of file located at absolutePath. + */ + void process(Path relativeZipEntryPath, ParseResult result); + } + + /** + * Get the path of the ZIP file to be parsed. + * + * @return The absolute path of this ZIP file. + */ + public Path getZipPath() { + return zipPath; + } + + /** + * @deprecated store ParserConfiguration now + */ + @Deprecated + public JavaParser getJavaParser() { + return new JavaParser(parserConfiguration); + } + + /** + * Set the parser that is used for parsing by default. + * + * @deprecated store ParserConfiguration now + */ + @Deprecated + public SourceZip setJavaParser(JavaParser javaParser) { + assertNotNull(javaParser); + this.parserConfiguration = javaParser.getParserConfiguration(); + return this; + } + + public ParserConfiguration getParserConfiguration() { + return parserConfiguration; + } + + public SourceZip setParserConfiguration(ParserConfiguration parserConfiguration) { + assertNotNull(parserConfiguration); + this.parserConfiguration = parserConfiguration; + return this; + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/StringEscapeUtils.java b/JavaParser/src/com/github/javaparser/utils/StringEscapeUtils.java new file mode 100644 index 0000000..a9732b9 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/StringEscapeUtils.java @@ -0,0 +1,435 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.javaparser.utils; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.HashSet; + +/** + * Adapted from apache commons-lang3 project. + *

+ * Unescapes escaped chars in strings. + */ +public class StringEscapeUtils { + + private StringEscapeUtils() { + } + + /** + *

Escapes the characters in a {@code String} using Java String rules.

+ *

+ *

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

+ *

+ *

So a tab becomes the characters {@code '\\'} and + * {@code 't'}.

+ *

+ *

The only difference between Java strings and JavaScript strings + * is that in JavaScript, a single quote and forward-slash (/) are escaped.

+ *

+ *

Example:

+ *
+     * input string: He didn't say, "Stop!"
+     * output string: He didn't say, \"Stop!\"
+     * 
+ * + * @param input String to escape values in, may be null + * @return String with escaped values, {@code null} if null string input + */ + public static String escapeJava(final String input) { + return ESCAPE_JAVA.translate(input); + } + + /** + *

Unescapes any Java literals found in the {@code String}. + * For example, it will turn a sequence of {@code '\'} and + * {@code 'n'} into a newline character, unless the {@code '\'} + * is preceded by another {@code '\'}.

+ * + * @param input the {@code String} to unescape, may be null + * @return a new unescaped {@code String}, {@code null} if null string input + */ + public static String unescapeJava(final String input) { + return UNESCAPE_JAVA.translate(input); + } + + private static final String[][] JAVA_CTRL_CHARS_UNESCAPE = { + {"\\b", "\b"}, + {"\\n", "\n"}, + {"\\t", "\t"}, + {"\\f", "\f"}, + {"\\r", "\r"} + }; + + private static final String[][] JAVA_CTRL_CHARS_ESCAPE = { + {"\b", "\\b"}, + {"\n", "\\n"}, + {"\t", "\\t"}, + {"\f", "\\f"}, + {"\r", "\\r"} + }; + + private static final CharSequenceTranslator ESCAPE_JAVA = + new AggregateTranslator( + new LookupTranslator( + new String[][]{ + {"\"", "\\\""}, + {"\\", "\\\\"}, + }), + new LookupTranslator(JAVA_CTRL_CHARS_ESCAPE.clone()) + ); + + private static final CharSequenceTranslator UNESCAPE_JAVA = + new AggregateTranslator( + new OctalUnescaper(), + new UnicodeUnescaper(), + new LookupTranslator(JAVA_CTRL_CHARS_UNESCAPE.clone()), + new LookupTranslator( + new String[][]{ + {"\\\\", "\\"}, + {"\\\"", "\""}, + {"\\'", "'"}, + {"\\", ""} + }) + ); + + /** + * Adapted from apache commons-lang3 project. + *

+ * An API for translating text. + * Its core use is to escape and unescape text. Because escaping and unescaping + * is completely contextual, the API does not present two separate signatures. + * + * @since 3.0 + */ + private static abstract class CharSequenceTranslator { + + /** + * Translate a set of codepoints, represented by an int index into a CharSequence, + * into another set of codepoints. The number of codepoints consumed must be returned, + * and the only IOExceptions thrown must be from interacting with the Writer so that + * the top level API may reliably ignore StringWriter IOExceptions. + * + * @param input CharSequence that is being translated + * @param index int representing the current point of translation + * @param out Writer to translate the text to + * @return int count of codepoints consumed + * @throws IOException if and only if the Writer produces an IOException + */ + public abstract int translate(CharSequence input, int index, Writer out) throws IOException; + + /** + * Helper for non-Writer usage. + * + * @param input CharSequence to be translated + * @return String output of translation + */ + public final String translate(final CharSequence input) { + if (input == null) { + return null; + } + try { + final StringWriter writer = new StringWriter(input.length() * 2); + translate(input, writer); + return writer.toString(); + } catch (final IOException ioe) { + // this should never ever happen while writing to a StringWriter + throw new RuntimeException(ioe); + } + } + + /** + * Translate an input onto a Writer. This is intentionally final as its algorithm is + * tightly coupled with the abstract method of this class. + * + * @param input CharSequence that is being translated + * @param out Writer to translate the text to + * @throws IOException if and only if the Writer produces an IOException + */ + public final void translate(final CharSequence input, final Writer out) throws IOException { + if (out == null) { + throw new IllegalArgumentException("The Writer must not be null"); + } + if (input == null) { + return; + } + int pos = 0; + final int len = input.length(); + while (pos < len) { + final int consumed = translate(input, pos, out); + if (consumed == 0) { + // inlined implementation of Character.toChars(Character.codePointAt(input, pos)) + // avoids allocating temp char arrays and duplicate checks + char c1 = input.charAt(pos); + out.write(c1); + pos++; + if (Character.isHighSurrogate(c1) && pos < len) { + char c2 = input.charAt(pos); + if (Character.isLowSurrogate(c2)) { + out.write(c2); + pos++; + } + } + continue; + } + // contract with translators is that they have to understand codepoints + // and they just took care of a surrogate pair + for (int pt = 0; pt < consumed; pt++) { + pos += Character.charCount(Character.codePointAt(input, pos)); + } + } + } + + /** + * Helper method to create a merger of this translator with another set of + * translators. Useful in customizing the standard functionality. + * + * @param translators CharSequenceTranslator array of translators to merge with this one + * @return CharSequenceTranslator merging this translator with the others + */ + public final CharSequenceTranslator with(final CharSequenceTranslator... translators) { + final CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1]; + newArray[0] = this; + System.arraycopy(translators, 0, newArray, 1, translators.length); + return new AggregateTranslator(newArray); + } + + } + + /** + * Adapted from apache commons-lang3 project. + *

+ * Translates a value using a lookup table. + * + * @since 3.0 + */ + private static class LookupTranslator extends CharSequenceTranslator { + + private final HashMap lookupMap; + private final HashSet prefixSet; + private final int shortest; + private final int longest; + + /** + * Define the lookup table to be used in translation + *

+ * Note that, as of Lang 3.1, the key to the lookup table is converted to a + * java.lang.String. This is because we need the key to support hashCode and + * equals(Object), allowing it to be the key for a HashMap. See LANG-882. + * + * @param lookup CharSequence[][] table of size [*][2] + */ + public LookupTranslator(final CharSequence[]... lookup) { + lookupMap = new HashMap<>(); + prefixSet = new HashSet<>(); + int _shortest = Integer.MAX_VALUE; + int _longest = 0; + if (lookup != null) { + for (final CharSequence[] seq : lookup) { + this.lookupMap.put(seq[0].toString(), seq[1].toString()); + this.prefixSet.add(seq[0].charAt(0)); + final int sz = seq[0].length(); + if (sz < _shortest) { + _shortest = sz; + } + if (sz > _longest) { + _longest = sz; + } + } + } + shortest = _shortest; + longest = _longest; + } + + /** + * {@inheritDoc} + */ + @Override + public int translate(final CharSequence input, final int index, final Writer out) throws IOException { + // check if translation exists for the input at position index + if (prefixSet.contains(input.charAt(index))) { + int max = longest; + if (index + longest > input.length()) { + max = input.length() - index; + } + // implement greedy algorithm by trying maximum match first + for (int i = max; i >= shortest; i--) { + final CharSequence subSeq = input.subSequence(index, index + i); + final String result = lookupMap.get(subSeq.toString()); + + if (result != null) { + out.write(result); + return i; + } + } + } + return 0; + } + } + + /** + * Adapted from apache commons-lang3 project. + *

+ * Executes a sequence of translators one after the other. Execution ends whenever + * the first translator consumes codepoints from the input. + * + * @since 3.0 + */ + private static class AggregateTranslator extends CharSequenceTranslator { + + private final CharSequenceTranslator[] translators; + + /** + * Specify the translators to be used at creation time. + * + * @param translators CharSequenceTranslator array to aggregate + */ + public AggregateTranslator(final CharSequenceTranslator... translators) { + this.translators = translators == null ? null : translators.clone(); + } + + /** + * The first translator to consume codepoints from the input is the 'winner'. + * Execution stops with the number of consumed codepoints being returned. + * {@inheritDoc} + */ + @Override + public int translate(final CharSequence input, final int index, final Writer out) throws IOException { + for (final CharSequenceTranslator translator : translators) { + final int consumed = translator.translate(input, index, out); + if (consumed != 0) { + return consumed; + } + } + return 0; + } + + } + + /** + * Adapted from apache commons-lang3 project. + *

+ * Translate escaped octal Strings back to their octal values. + *

+ * For example, "\45" should go back to being the specific value (a %). + *

+ * Note that this currently only supports the viable range of octal for Java; namely + * 1 to 377. This is because parsing Java is the main use case. + * + * @since 3.0 + */ + private static class OctalUnescaper extends CharSequenceTranslator { + + /** + * {@inheritDoc} + */ + @Override + public int translate(final CharSequence input, final int index, final Writer out) throws IOException { + final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ + final StringBuilder builder = new StringBuilder(); + if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) { + final int next = index + 1; + final int next2 = index + 2; + final int next3 = index + 3; + + // we know this is good as we checked it in the if block above + builder.append(input.charAt(next)); + + if (remaining > 1 && isOctalDigit(input.charAt(next2))) { + builder.append(input.charAt(next2)); + if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) { + builder.append(input.charAt(next3)); + } + } + + out.write(Integer.parseInt(builder.toString(), 8)); + return 1 + builder.length(); + } + return 0; + } + + /** + * Checks if the given char is an octal digit. Octal digits are the character representations of the digits 0 to + * 7. + * + * @param ch the char to check + * @return true if the given char is the character representation of one of the digits from 0 to 7 + */ + private boolean isOctalDigit(final char ch) { + return ch >= '0' && ch <= '7'; + } + + /** + * Checks if the given char is the character representation of one of the digit from 0 to 3. + * + * @param ch the char to check + * @return true if the given char is the character representation of one of the digits from 0 to 3 + */ + private boolean isZeroToThree(final char ch) { + return ch >= '0' && ch <= '3'; + } + } + + /** + * Adapted from apache commons-lang3 project. + *

+ * Translates escaped Unicode values of the form \\u+\d\d\d\d back to + * Unicode. It supports multiple 'u' characters and will work with or + * without the +. + * + * @since 3.0 + */ + private static class UnicodeUnescaper extends CharSequenceTranslator { + + /** + * {@inheritDoc} + */ + @Override + public int translate(final CharSequence input, final int index, final Writer out) throws IOException { + if (input.charAt(index) == '\\' && index + 1 < input.length() && input.charAt(index + 1) == 'u') { + // consume optional additional 'u' chars + int i = 2; + while (index + i < input.length() && input.charAt(index + i) == 'u') { + i++; + } + + if (index + i < input.length() && input.charAt(index + i) == '+') { + i++; + } + + if (index + i + 4 <= input.length()) { + // Get 4 hex digits + final CharSequence unicode = input.subSequence(index + i, index + i + 4); + + try { + final int value = Integer.parseInt(unicode.toString(), 16); + out.write((char) value); + } catch (final NumberFormatException nfe) { + throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe); + } + return i + 4; + } + throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + + "' due to end of CharSequence"); + } + return 0; + } + } + +} \ No newline at end of file diff --git a/JavaParser/src/com/github/javaparser/utils/Utils.java b/JavaParser/src/com/github/javaparser/utils/Utils.java new file mode 100644 index 0000000..2db00e5 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/Utils.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import java.io.IOException; +import java.io.Reader; +import java.util.*; +import java.util.function.Predicate; +import java.util.function.Function; + +import static java.util.Arrays.*; + +/** + * Any kind of utility. + * + * @author Federico Tomassetti + */ +public class Utils { + public static final String EOL = System.getProperty("line.separator"); + + public static final Predicate STRING_NOT_EMPTY = s -> !s.isEmpty(); + + /** + * @deprecated This is no longer in use by JavaParser, please write your own replacement. + */ + public static List ensureNotNull(List list) { + return list == null ? new ArrayList<>() : list; + } + + public static boolean isNullOrEmpty(Collection collection) { + return collection == null || collection.isEmpty(); + } + + public static T assertNotNull(T o) { + if (o == null) { + throw new AssertionError("A reference was unexpectedly null."); + } + return o; + } + + public static String assertNonEmpty(String string) { + if (string == null || string.isEmpty()) { + throw new AssertionError("A string was unexpectedly empty."); + } + return string; + } + + /** + * @return string with ASCII characters 10 and 13 replaced by the text "\n" and "\r". + */ + public static String escapeEndOfLines(String string) { + StringBuilder escapedString = new StringBuilder(); + for (char c : string.toCharArray()) { + switch (c) { + case '\n': + escapedString.append("\\n"); + break; + case '\r': + escapedString.append("\\r"); + break; + default: + escapedString.append(c); + } + } + return escapedString.toString(); + } + + public static String readerToString(Reader reader) throws IOException { + final StringBuilder result = new StringBuilder(); + final char[] buffer = new char[8 * 1024]; + int numChars; + + while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) { + result.append(buffer, 0, numChars); + } + + return result.toString(); + } + + /** + * Puts varargs in a mutable list. + * This does not have the disadvantage of Arrays#asList that it has a static size. + * + * @deprecated This is no longer in use by JavaParser, please write your own replacement. + */ + @Deprecated + public static List arrayToList(T[] array) { + List list = new LinkedList<>(); + Collections.addAll(list, array); + return list; + } + + /** + * @deprecated use screamingToCamelCase + */ + public static String toCamelCase(String original) { + return screamingToCamelCase(original); + } + + /** + * Transform a string to the camel case conversion. + *

@@ -50,9 +69,11 @@ public ClassComponent() { // Used when reverse engineering public ClassComponent(String name) { super(name); - fields = new LinkedHashSet<>(); - constructors = new LinkedHashSet<>(); - methods = new LinkedHashSet<>(); + fields = new ArrayList(); + constructors = new ArrayList(); + methods = new ArrayList(); + getterGeneration = GenerationSetting.AUTO; + setterGeneration = GenerationSetting.AUTO; } /** @@ -61,7 +82,7 @@ public ClassComponent(String name) { * @return HashSet of fields contained */ public LinkedHashSet getFields() { - return fields; + return new LinkedHashSet(fields); } /** @@ -70,7 +91,7 @@ public LinkedHashSet getFields() { * @return HashSet of methods contained */ public LinkedHashSet getMethods() { - return methods; + return new LinkedHashSet(methods); } /** @@ -79,7 +100,7 @@ public LinkedHashSet getMethods() { * @return HashSet of constructors contained */ public LinkedHashSet getConstructors() { - return constructors; + return new LinkedHashSet(constructors); } /** @@ -205,4 +226,235 @@ public void removeMember(MemberBase member) { else if (member instanceof Constructor) constructors.remove((Constructor) member); // else throw new RuntimeException("Removing unsupported member: " + member.toString()); } + + @Override + public boolean moveUpMember(MemberBase member) { + if (member instanceof Field) { + for (int i=1;i getRequestedGetters() { + List list = new ArrayList(); + for (Field field: fields) { + if (!field.getterGenerationRequested()) + continue; + Method method = field.createGetter(); + if (signatureExists(method.getSignature())) + continue; + list.add(field); + } + return list; + } + + /** + * Get generated getter methods (not added to the class) + * + * Only requested and undeclerared ones are created + * + * @return list of getters + */ + public List getRequestedSetters() { + List list = new ArrayList(); + for (Field field: fields) { + if (!field.setterGenerationRequested()) + continue; + Method method = field.createSetter(); + if (signatureExists(method.getSignature())) + continue; + list.add(field); + } + return list; + } + + public boolean hasMethod(String methodSignature) { + for (Method method : methods) { + if (methodSignature.equals(method.getSignature())) { + return true; + } + } + return false; + } + + public LinkedHashSet getUnimplementedMethods() { + ClassDiagram diagram = getParentDiagram(); + HashSet relations = diagram.getRelations(); + LinkedHashSet unimplementedMethods = new LinkedHashSet(); + for(RelationBase relation : relations) { + if (relation.getSource() != this) + continue; + if (relation instanceof ImplementsRelation) { + InterfaceComponent interfaceComponent = (InterfaceComponent)relation.getTarget(); + LinkedHashSet parentMethods = interfaceComponent.getMethods(); + for(Method parentMethod : parentMethods) { + if (parentMethod.isStatic()) + continue; + String parentSignature = parentMethod.getSignature(); + if (hasMethod(parentSignature)) + continue; + boolean found = false; + for (Method method : unimplementedMethods) { + if (parentSignature.equals(method.getSignature())) { + found = true; + break; + } + } + if (!found) { + try { + Method method = (Method)parentMethod.clone(); + method.setAbstract(false); + unimplementedMethods.add(method); + } catch (CloneNotSupportedException ex) { + Logger.getLogger(ClassComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } + if (relation instanceof IsRelation) { + ClassComponent classComponent = (ClassComponent)relation.getTarget(); + if (!classComponent.isAbstract()) + continue; + LinkedHashSet parentMethods = classComponent.getMethods(); + for(Method parentMethod : parentMethods) { + if (!parentMethod.isAbstract()) + continue; + String parentSignature = parentMethod.getSignature(); + if (hasMethod(parentSignature)) + continue; + boolean found = false; + for (Method method : unimplementedMethods) { + if (parentSignature.equals(method.getSignature())) { + found = true; + break; + } + } + if (!found) { + try { + Method method = (Method)parentMethod.clone(); + method.setAbstract(false); + unimplementedMethods.add(method); + } catch (CloneNotSupportedException ex) { + Logger.getLogger(ClassComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } + } + return unimplementedMethods; + } + } diff --git a/UMLModel/src/org/uml/model/components/ComponentBase.java b/UMLModel/src/org/uml/model/components/ComponentBase.java index 4904f50..d4510d7 100644 --- a/UMLModel/src/org/uml/model/components/ComponentBase.java +++ b/UMLModel/src/org/uml/model/components/ComponentBase.java @@ -7,6 +7,7 @@ import java.util.List; import org.uml.model.ClassDiagram; import org.uml.model.ContainerBase; +import org.uml.model.GenerationSetting; import org.uml.model.IHasSignature; import org.uml.model.INameable; import org.uml.model.Visibility; @@ -37,6 +38,16 @@ public abstract class ComponentBase extends ContainerBase implements */ private String parentPackage; + /** + * Parent package component (e.g., as visually seen on screen) + */ + private PackageComponent componentPackage; + + /** + * Enable / disable code generation + */ + private GenerationSetting generation; + /** * Visibility of the component. Can be public, private, package, protected in general, but * depends on the actual component. @@ -54,7 +65,7 @@ public abstract class ComponentBase extends ContainerBase implements /** * Location of the component on the diagram. */ - private Point location; + //private Point location; /** * Bounds of the component on the diagram. */ @@ -74,6 +85,7 @@ protected ComponentBase(String name) { super(name); parentPackage = ""; visibility = Visibility.PUBLIC; + generation = GenerationSetting.AUTO; } /** @@ -84,7 +96,19 @@ protected ComponentBase(String name) { * @param member */ public abstract void removeMember(MemberBase member); + + /** + * Move up the given member, if possible. + * @param member + */ + public abstract boolean moveUpMember(MemberBase member); + /** + * Move up the given member, if possible. + * @param member + */ + public abstract boolean moveDownMember(MemberBase member); + /** * Returns members that this component has. * @@ -122,7 +146,10 @@ public void setParentDiagram(ClassDiagram parentDiagram) { * @return point representing X and Y coordinates */ public Point getLocation() { - return location; + if (bounds == null) { + return null; + } + return bounds.getLocation(); } /** @@ -131,7 +158,10 @@ public Point getLocation() { * @param location point representing X and Y coordinates of the new location */ public void setLocation(Point location) { - this.location = location; + if (bounds == null) { + bounds = new Rectangle(0,0,0,0); + } + bounds.setLocation(location); } // TODO bounds @@ -164,6 +194,46 @@ public void setParentPackage(String parentPackage) { pcs.firePropertyChange("parentPackage", oldParentPackage, parentPackage); } + /** + * Returns the component package of the component. + * + * @return component package + */ + public PackageComponent getComponentPackage() { + return componentPackage; + } + + /** + * Sets component package of the component. + * + * @param componentPackage + */ + public void setComponentPackage(PackageComponent componentPackage) { + this.componentPackage = componentPackage; + } + + /** + * Returns the full parent package of the component, including + * component packages inclusions + * + * @return full parent package + */ + public String getFullParentPackage() { + if (componentPackage == null) + return parentPackage; + String fullParentPackage = componentPackage.getFullParentPackage(); + if (fullParentPackage == null || fullParentPackage.isEmpty()) { + fullParentPackage = componentPackage.getName(); + } + else { + fullParentPackage = fullParentPackage+"."+componentPackage.getName(); + } + if (parentPackage == null || parentPackage.isEmpty()) { + return fullParentPackage; + } + return fullParentPackage+"."+parentPackage; + } + /** * Returns the visibility of this component. * @@ -221,12 +291,17 @@ public void removeModifier(int modifier) { */ @Override public String getSignature() { - if (getParentPackage().equals("")) { + if (getFullParentPackage().equals("")) { return getName(); } else { - return getParentPackage() + "." + getName(); + return getFullParentPackage() + "." + getName(); } } + + @Override + public String getUMLSignature() { + return getSignature(); + } /** * Makes a signature with a potential new name so that we can check if the component @@ -236,10 +311,10 @@ public String getSignature() { * @return */ public String deriveSignatureFromNewName(String newName) { - if (getParentPackage().equals("")) { + if (getFullParentPackage().equals("")) { return newName; } else { - return getParentPackage() + "." + newName; + return getFullParentPackage() + "." + newName; } } @@ -289,7 +364,7 @@ public void setName(String newName) { * @param newComponentName new type */ private void updateTypes(ComponentBase component, String oldComponentName, String newComponentName) { - for (MemberBase member : component.getMembers()) { + for (MemberBase member : component.getMembers()) { if (member instanceof Constructor && component == this) { member.setName(newComponentName); } else if (member instanceof Method) { @@ -298,7 +373,7 @@ private void updateTypes(ComponentBase component, String oldComponentName, Strin method.setType(newMethodType); for (MethodArgument argument : method.getArguments()) { String newArgumentType = argument.getType().replaceAll("(? getRelevantRelations(){ } return relevantRelations; } + + + public GenerationSetting getGeneration() { + return generation; + } + + public void setGeneration(GenerationSetting generation) { + GenerationSetting oldGeneration = this.generation; + this.generation = generation; + pcs.firePropertyChange("generation", oldGeneration, generation); + } + + public boolean generationRequested() { + GenerationSetting setting = generation; + if (setting == GenerationSetting.AUTO) { + return true; + } + if (setting == GenerationSetting.ENABLED) { + return true; + } + if (setting == GenerationSetting.DISABLED) { + return false; + } + if (setting == GenerationSetting.NOTPUBLIC) { + return visibility != Visibility.PUBLIC; + } + if (setting == GenerationSetting.PRIVATE) { + return visibility == Visibility.PRIVATE; + } + if (setting == GenerationSetting.PROTECTED) { + return visibility == Visibility.PROTECTED; + } + return false; + } } diff --git a/UMLModel/src/org/uml/model/components/EnumComponent.java b/UMLModel/src/org/uml/model/components/EnumComponent.java index fa044ac..fe12af0 100644 --- a/UMLModel/src/org/uml/model/components/EnumComponent.java +++ b/UMLModel/src/org/uml/model/components/EnumComponent.java @@ -1,6 +1,8 @@ package org.uml.model.components; +import java.util.ArrayList; import java.util.LinkedHashSet; +import java.util.List; import org.uml.model.members.Literal; import org.uml.model.members.MemberBase; @@ -17,7 +19,7 @@ public class EnumComponent extends ComponentBase { /** * Set of literals this enum contains. */ - private LinkedHashSet literals; + private List literals; /** * Default constructor. Sets name to default value. @@ -38,7 +40,7 @@ public EnumComponent() { // Used when reverse engineering public EnumComponent(String name) { super(name); - literals = new LinkedHashSet<>(); + literals = new ArrayList(); } /** @@ -47,7 +49,7 @@ public EnumComponent(String name) { * @return HashSet of literals contained */ public LinkedHashSet getLiterals() { - return literals; + return new LinkedHashSet(literals); } /** @@ -76,4 +78,37 @@ public void removeMember(MemberBase member) { if (member instanceof Literal) literals.remove((Literal) member); // else throw new RuntimeException("Removing unsupported member: " + member.toString()); } + + @Override + public boolean moveUpMember(MemberBase member) { + if (member instanceof Literal) { + for (int i=1;i methods; + private List methods; /** * Default constructor. Sets name to default value. @@ -39,7 +41,7 @@ public InterfaceComponent() { // Used when reverse engineering public InterfaceComponent(String name) { super(name); - methods = new LinkedHashSet<>(); + methods = new ArrayList(); } /** @@ -48,7 +50,7 @@ public InterfaceComponent(String name) { * @return HashSet of methods contained */ public LinkedHashSet getMethods() { - return methods; + return new LinkedHashSet(methods); } /** @@ -98,4 +100,37 @@ public void removeMember(MemberBase member) { if (member instanceof Method) methods.remove((Method) member); // else throw new RuntimeException("Removing unsupported member: " + member.toString()); } + + @Override + public boolean moveUpMember(MemberBase member) { + if (member instanceof Method) { + for (int i=1;i args = new LinkedHashSet(); + args.add(new MethodArgument(type,name)); + method.setArguments(args); + return method; + } + } diff --git a/UMLModel/src/org/uml/model/members/Literal.java b/UMLModel/src/org/uml/model/members/Literal.java index 4a68af4..627f750 100644 --- a/UMLModel/src/org/uml/model/members/Literal.java +++ b/UMLModel/src/org/uml/model/members/Literal.java @@ -35,6 +35,15 @@ public String getSimpleTypeSignature() { return getSignature(); } + @Override + public String getUMLSignature() { + return name; + } + + @Override + public String getSimpleTypeUMLSignature() { + return getSignature(); + } @Override public String getLabelText(boolean isShort) { return getSignature(); diff --git a/UMLModel/src/org/uml/model/members/MemberBase.java b/UMLModel/src/org/uml/model/members/MemberBase.java index 5617be7..db7f9fa 100644 --- a/UMLModel/src/org/uml/model/members/MemberBase.java +++ b/UMLModel/src/org/uml/model/members/MemberBase.java @@ -197,6 +197,12 @@ public void setDeclaringComponent(ComponentBase declaringComponent) { */ protected abstract String getSimpleTypeSignature(); + /** + * Returns an UML signature with simple type names and without modifiers. + * @return simple signature of this member + */ + protected abstract String getSimpleTypeUMLSignature(); + /** * Returns the text which is shown to the user in the GUI. * @param isSimpleTypeNames - if simple type names are used or not diff --git a/UMLModel/src/org/uml/model/members/Method.java b/UMLModel/src/org/uml/model/members/Method.java index fbfabea..7cc5249 100644 --- a/UMLModel/src/org/uml/model/members/Method.java +++ b/UMLModel/src/org/uml/model/members/Method.java @@ -11,7 +11,7 @@ * @see Constructor * @see Literal */ -public class Method extends MethodBase { +public class Method extends MethodBase implements Cloneable { /** * Constructor that sets the name, return type and visibility of the method. @@ -146,8 +146,13 @@ public String getLabelText(boolean isSimpleTypeNames) { StringBuilder result = new StringBuilder(); // removes static because it is rendered as underline if (isStatic()) result.append(Modifier.toString(modifiers).replace("static ", "").trim().replace("\\s+", " ")).append(" "); - if (isSimpleTypeNames) result.append(getSimpleTypeSignature()); - else result.append(getSignature()); + if (isSimpleTypeNames) result.append(getSimpleTypeUMLSignature()); + else result.append(getUMLSignature()); return result.toString(); } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/UMLModel/src/org/uml/model/members/MethodBase.java b/UMLModel/src/org/uml/model/members/MethodBase.java index 9e8e769..a06c970 100644 --- a/UMLModel/src/org/uml/model/members/MethodBase.java +++ b/UMLModel/src/org/uml/model/members/MethodBase.java @@ -81,6 +81,30 @@ public String getSimpleTypeSignature() { result.append(")"); return result.toString(); } + + @Override + public String getUMLSignature() { + StringBuilder result = new StringBuilder(); + result.append(getName()).append("("); + if (getArguments() != null) { + result.append(getUMLArgumentsString(false)); + } + result.append("): "); + if (type != null) result.append(type); + return result.toString(); + } + + @Override + public String getSimpleTypeUMLSignature() { + StringBuilder result = new StringBuilder(); + result.append(getName()).append("("); + if (getArguments() != null) { + result.append(getUMLArgumentsString(true)); + } + result.append("): "); + if (type != null) result.append(getSimpleType(type)); + return result.toString(); + } @Override public String deriveSignatureFromName(String newName) { @@ -121,4 +145,30 @@ private String getArgumentsString(boolean isSimple) { } return args.toString(); } + + private String getUMLArgumentsString(boolean isSimple) { + StringBuilder args = new StringBuilder(); + String delimiter = ""; + for (MethodArgument argument : getArguments()) { + String argType = isSimple ? getSimpleType(argument.getType()) : argument.getType(); + args.append(delimiter).append(argument.getName()).append(": ").append(argType); + delimiter = ", "; + } + return args.toString(); + } + +/* @Override + public boolean equals(Object other) { + if (other == null) + return false; + if (!(other instanceof MethodBase)) + return false; + MethodBase method = (MethodBase)other; + return getSignature().equals(method.getSignature()); + } + + @Override + public int hashCode() { + return getSignature().hashCode(); + }*/ } diff --git a/UMLModel/src/org/uml/model/relations/CardinalityEnum.java b/UMLModel/src/org/uml/model/relations/CardinalityEnum.java index 9502fbb..b490130 100644 --- a/UMLModel/src/org/uml/model/relations/CardinalityEnum.java +++ b/UMLModel/src/org/uml/model/relations/CardinalityEnum.java @@ -47,6 +47,15 @@ public String toString() { public String toString() { return "0..*"; } + }, + /** + * No cardinality + */ + Nothing { + @Override + public String toString() { + return ""; + } }; /** @@ -69,6 +78,9 @@ public static CardinalityEnum parseString(String cardinalityEnum) { if (cardinalityEnum.equalsIgnoreCase("0..*")) { return CardinalityEnum.Zero2Many; } + if (cardinalityEnum.equalsIgnoreCase("")) { + return CardinalityEnum.Nothing; + } return CardinalityEnum.Zero2One; } diff --git a/UMLProjectType/manifest.mf b/UMLProjectType/manifest.mf index 7fddf17..f7ec30d 100644 --- a/UMLProjectType/manifest.mf +++ b/UMLProjectType/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.project OpenIDE-Module-Localizing-Bundle: org/uml/project/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLProjectType/nbproject/genfiles.properties b/UMLProjectType/nbproject/genfiles.properties index 3f68a60..fa6b31e 100644 --- a/UMLProjectType/nbproject/genfiles.properties +++ b/UMLProjectType/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=65b075e0 +build.xml.data.CRC32=cb37b4ad build.xml.script.CRC32=9456727a -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=65b075e0 +nbproject/build-impl.xml.data.CRC32=cb37b4ad nbproject/build-impl.xml.script.CRC32=fb9fc690 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLProjectType/nbproject/project.properties b/UMLProjectType/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLProjectType/nbproject/project.properties +++ b/UMLProjectType/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLProjectType/src/org/uml/project/actions/UMLProjectOpenedHook.java b/UMLProjectType/src/org/uml/project/actions/UMLProjectOpenedHook.java index f4715e2..ea86be1 100644 --- a/UMLProjectType/src/org/uml/project/actions/UMLProjectOpenedHook.java +++ b/UMLProjectType/src/org/uml/project/actions/UMLProjectOpenedHook.java @@ -38,8 +38,10 @@ protected void projectClosed() { // Close UMLTopComponents corresponding to diagram data objects and dispose diagram data objects for (Node node : classDiagramNodes) { ClassDiagramDataObject cddo = node.getLookup().lookup(ClassDiagramDataObject.class); - cddo.notifyDispose(); - } + if (cddo != null) { + cddo.notifyDispose(); + } + } // Check if there is some open UMLProject remaining boolean someUmlProjectOpen = false; for (Project openProject : OpenProjects.getDefault().getOpenProjects()) { diff --git a/UMLReverseEngineering/manifest.mf b/UMLReverseEngineering/manifest.mf index 7f785cc..5d7fb6b 100644 --- a/UMLReverseEngineering/manifest.mf +++ b/UMLReverseEngineering/manifest.mf @@ -2,4 +2,4 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.reveng OpenIDE-Module-Localizing-Bundle: org/uml/reveng/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLReverseEngineering/nbproject/genfiles.properties b/UMLReverseEngineering/nbproject/genfiles.properties index 7c46323..d933208 100644 --- a/UMLReverseEngineering/nbproject/genfiles.properties +++ b/UMLReverseEngineering/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=a8ef5152 +build.xml.data.CRC32=05b566c5 build.xml.script.CRC32=5271511d -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=a8ef5152 +nbproject/build-impl.xml.data.CRC32=05b566c5 nbproject/build-impl.xml.script.CRC32=28949a97 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLReverseEngineering/nbproject/project.properties b/UMLReverseEngineering/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLReverseEngineering/nbproject/project.properties +++ b/UMLReverseEngineering/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLReverseEngineering/src/org/uml/reveng/ReverseEngineer.java b/UMLReverseEngineering/src/org/uml/reveng/ReverseEngineer.java index 1d3ebb4..f7cfff0 100644 --- a/UMLReverseEngineering/src/org/uml/reveng/ReverseEngineer.java +++ b/UMLReverseEngineering/src/org/uml/reveng/ReverseEngineer.java @@ -2,7 +2,11 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParseException; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; @@ -10,9 +14,10 @@ import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.ClassOrInterfaceType; import java.awt.Point; import java.io.File; @@ -22,6 +27,7 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import org.openide.util.Exceptions; import org.uml.model.ClassDiagram; import org.uml.model.Visibility; @@ -94,7 +100,7 @@ private static List createComponents(File file) { List components = new LinkedList<>(); try { CompilationUnit cu = JavaParser.parse(file); - List types = cu.getTypes(); + NodeList> types = cu.getTypes(); for (TypeDeclaration type : types) { ComponentBase component = null; if (type instanceof ClassOrInterfaceDeclaration) { @@ -112,21 +118,26 @@ private static List createComponents(File file) { components.add(component); } } - } catch (ParseException | IOException ex) { + } catch (ParseProblemException | IOException ex) { Exceptions.printStackTrace(ex); } return components; } private static ClassComponent createClass(ClassOrInterfaceDeclaration declaration) { - ClassComponent clazz = new ClassComponent(declaration.getName()); - clazz.setAbstract(ModifierSet.isAbstract(declaration.getModifiers())); - clazz.setFinal(ModifierSet.isFinal(declaration.getModifiers())); - clazz.setStatic(ModifierSet.isStatic(declaration.getModifiers())); + ClassComponent clazz = new ClassComponent(declaration.getName().asString()); + clazz.setAbstract(declaration.isAbstract()); + clazz.setFinal(declaration.isFinal()); + clazz.setStatic(declaration.isStatic()); + // TODO fix for inner classes - CompilationUnit parent = (CompilationUnit) declaration.getParentNode(); - if (parent.getPackage() != null) { - clazz.setParentPackage(parent.getPackage().getName().toString()); + Optional optionalNode = declaration.getParentNode(); + Node parentNode = optionalNode.get(); + Optional optionalCU = parentNode.findCompilationUnit(); + CompilationUnit cu = optionalCU.get(); + Optional parentPackage = cu.getPackageDeclaration(); + if (parentPackage.isPresent()) { + clazz.setParentPackage(parentPackage.get().getName().asString()); } else { clazz.setParentPackage(""); } @@ -149,12 +160,16 @@ private static ClassComponent createClass(ClassOrInterfaceDeclaration declaratio } private static ComponentBase createInterface(ClassOrInterfaceDeclaration declaration) { - InterfaceComponent interfaze = new InterfaceComponent(declaration.getName()); - interfaze.setStatic(ModifierSet.isStatic(declaration.getModifiers())); - - CompilationUnit parent = (CompilationUnit) declaration.getParentNode(); - if (parent.getPackage() != null) { - interfaze.setParentPackage(parent.getPackage().getName().toString()); + InterfaceComponent interfaze = new InterfaceComponent(declaration.getName().asString()); + interfaze.setStatic(declaration.isStatic()); + + Optional optionalNode = declaration.getParentNode(); + Node parentNode = optionalNode.get(); + Optional optionalCU = parentNode.findCompilationUnit(); + CompilationUnit cu = optionalCU.get(); + Optional parentPackage = cu.getPackageDeclaration(); + if (parentPackage.isPresent()) { + interfaze.setParentPackage(parentPackage.get().getName().asString()); } else { interfaze.setParentPackage(""); } @@ -171,14 +186,18 @@ private static ComponentBase createInterface(ClassOrInterfaceDeclaration declara } private static ComponentBase createEnum(EnumDeclaration declaration) { - EnumComponent enumm = new EnumComponent(declaration.getName()); - - CompilationUnit parent = (CompilationUnit) declaration.getParentNode(); - if (parent.getPackage() != null) { - enumm.setParentPackage(parent.getPackage().getName().toString()); + EnumComponent enumm = new EnumComponent(declaration.getName().asString()); + + Optional optionalNode = declaration.getParentNode(); + Node parentNode = optionalNode.get(); + Optional optionalCU = parentNode.findCompilationUnit(); + CompilationUnit cu = optionalCU.get(); + Optional parentPackage = cu.getPackageDeclaration(); + if (parentPackage.isPresent()) { + enumm.setParentPackage(parentPackage.get().getName().asString()); } else { enumm.setParentPackage(""); - } + } for (BodyDeclaration entry : safe(declaration.getEntries())) { if (entry instanceof EnumConstantDeclaration) { @@ -192,26 +211,23 @@ private static ComponentBase createEnum(EnumDeclaration declaration) { } private static Field createField(FieldDeclaration declaration) { - String name = declaration.getVariables().get(0).getId().getName(); - Field field = new Field(name, declaration.getType().toString(), getVisibility(declaration)); + VariableDeclarator variable = declaration.getVariables().get(0); + Field field = new Field(variable.getName().asString(), variable.getType().asString(), getVisibility(declaration)); - int modifiers = declaration.getModifiers(); - field.setStatic(ModifierSet.isStatic(modifiers)); - field.setFinal(ModifierSet.isFinal(modifiers)); - field.setVolatile(ModifierSet.isVolatile(modifiers)); - field.setTransient(ModifierSet.isTransient(modifiers)); + field.setStatic(declaration.isStatic()); + field.setFinal(declaration.isFinal()); + field.setVolatile(declaration.isVolatile()); + field.setTransient(declaration.isTransient()); return field; } private static Visibility getVisibility(FieldDeclaration declaration) { - int modifiers = declaration.getModifiers(); - - if (ModifierSet.isPublic(modifiers)) { + if (declaration.isPublic()) { return Visibility.PUBLIC; - } else if (ModifierSet.isProtected(modifiers)) { + } else if (declaration.isProtected()) { return Visibility.PROTECTED; - } else if (ModifierSet.isPrivate(modifiers)) { + } else if (declaration.isPrivate()) { return Visibility.PRIVATE; } else { return Visibility.PACKAGE; @@ -219,18 +235,17 @@ private static Visibility getVisibility(FieldDeclaration declaration) { } private static Method createMethod(MethodDeclaration declaration) { - Method method = new Method(declaration.getName(), declaration.getType().toString()); + Method method = new Method(declaration.getName().asString(), declaration.getType().asString()); method.setVisibility(getVisibility(declaration)); - int modifiers = declaration.getModifiers(); - method.setAbstract(ModifierSet.isAbstract(modifiers)); - method.setStatic(ModifierSet.isStatic(modifiers)); - method.setFinal(ModifierSet.isFinal(modifiers)); - method.setSynchronized(ModifierSet.isSynchronized(modifiers)); - + method.setAbstract(declaration.isAbstract()); + method.setStatic(declaration.isStatic()); + method.setFinal(declaration.isFinal()); + method.setSynchronized(declaration.isSynchronized()); + LinkedHashSet arguments = method.getArguments(); for (Parameter parameter : safe(declaration.getParameters())) { - MethodArgument arg = new MethodArgument(parameter.getType().toString(), parameter.getId().getName()); + MethodArgument arg = new MethodArgument(parameter.getType().asString(), parameter.getName().asString()); arguments.add(arg); } @@ -238,12 +253,11 @@ private static Method createMethod(MethodDeclaration declaration) { } private static Visibility getVisibility(MethodDeclaration declaration) { - int modifiers = declaration.getModifiers(); - if (ModifierSet.isPublic(modifiers)) { + if (declaration.isPublic()) { return Visibility.PUBLIC; - } else if (ModifierSet.isProtected(modifiers)) { + } else if (declaration.isProtected()) { return Visibility.PROTECTED; - } else if (ModifierSet.isPrivate(modifiers)) { + } else if (declaration.isPrivate()) { return Visibility.PRIVATE; } else { return Visibility.PACKAGE; @@ -251,13 +265,13 @@ private static Visibility getVisibility(MethodDeclaration declaration) { } private static Constructor createConstructor(ConstructorDeclaration declaration) { - Constructor constructor = new Constructor(declaration.getName()); + Constructor constructor = new Constructor(declaration.getName().asString()); constructor.setVisibility(getVisibility(declaration)); LinkedHashSet arguments = constructor.getArguments(); for (Parameter parameter : safe(declaration.getParameters())) { - MethodArgument arg = new MethodArgument(parameter.getType().toString(), parameter.getId().getName()); + MethodArgument arg = new MethodArgument(parameter.getType().asString(), parameter.getName().asString()); arguments.add(arg); } @@ -265,12 +279,11 @@ private static Constructor createConstructor(ConstructorDeclaration declaration) } private static Visibility getVisibility(ConstructorDeclaration declaration) { - int modifiers = declaration.getModifiers(); - if (ModifierSet.isPublic(modifiers)) { + if (declaration.isPublic()) { return Visibility.PUBLIC; - } else if (ModifierSet.isProtected(modifiers)) { + } else if (declaration.isProtected()) { return Visibility.PROTECTED; - } else if (ModifierSet.isPrivate(modifiers)) { + } else if (declaration.isPrivate()) { return Visibility.PRIVATE; } else { return Visibility.PACKAGE; @@ -278,13 +291,14 @@ private static Visibility getVisibility(ConstructorDeclaration declaration) { } private static Literal createLiteral(EnumConstantDeclaration declaration) { - Literal literal = new Literal(declaration.getName()); + Literal literal = new Literal(declaration.getName().asString()); return literal; } private static List createRelations(File file, ClassDiagram classDiagram) { List relations = new LinkedList<>(); - try { + //!TODO: Update to JavaParser 9 + /*try { CompilationUnit cu = JavaParser.parse(file); for (TypeDeclaration typedecl : safe(cu.getTypes())) { if (typedecl instanceof ClassOrInterfaceDeclaration) { @@ -405,7 +419,7 @@ private static List createRelations(File file, ClassDiagram classD } } catch (ParseException | IOException ex) { Exceptions.printStackTrace(ex); - } + }*/ return relations; } diff --git a/UMLVisual/build.xml b/UMLVisual/build.xml index 375b19b..3530e1c 100644 --- a/UMLVisual/build.xml +++ b/UMLVisual/build.xml @@ -1,8 +1,8 @@ - - - - - - Builds, tests, and runs the project org.uml.visual. - - + + + + + + Builds, tests, and runs the project org.uml.visual. + + diff --git a/UMLVisual/manifest.mf b/UMLVisual/manifest.mf index 84a6e53..142b61c 100644 --- a/UMLVisual/manifest.mf +++ b/UMLVisual/manifest.mf @@ -2,4 +2,4 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.visual OpenIDE-Module-Localizing-Bundle: org/uml/visual/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLVisual/nbproject/build-impl.xml b/UMLVisual/nbproject/build-impl.xml index d80d6aa..e2360f8 100644 --- a/UMLVisual/nbproject/build-impl.xml +++ b/UMLVisual/nbproject/build-impl.xml @@ -1,45 +1,45 @@ - - - - - - - - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UMLVisual/nbproject/genfiles.properties b/UMLVisual/nbproject/genfiles.properties index 4921ac1..e844cc9 100644 --- a/UMLVisual/nbproject/genfiles.properties +++ b/UMLVisual/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=889a0410 +build.xml.data.CRC32=7f10535c build.xml.script.CRC32=4d41163f -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=889a0410 +nbproject/build-impl.xml.data.CRC32=7f10535c nbproject/build-impl.xml.script.CRC32=09f47c5e -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLVisual/nbproject/project.properties b/UMLVisual/nbproject/project.properties index 2a75346..e1f1492 100644 --- a/UMLVisual/nbproject/project.properties +++ b/UMLVisual/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial -Xlint\:-path license.file=LICENSE-2.0.txt diff --git a/UMLVisual/src/org/uml/visual/dialogs/Bundle.properties b/UMLVisual/src/org/uml/visual/dialogs/Bundle.properties index e3ff121..8834766 100644 --- a/UMLVisual/src/org/uml/visual/dialogs/Bundle.properties +++ b/UMLVisual/src/org/uml/visual/dialogs/Bundle.properties @@ -8,3 +8,7 @@ ConnectRelationPanel.lblTarget.text=Target: ConnectRelationPanel.lblSource.text=Source: ConnectRelationPanel.lblSource.AccessibleContext.accessibleName=Source: CardinalityChangePanel.lblCardinality.text=Cardinality: +CustomSizePanel.jLabel1.text=Width +CustomSizePanel.jTextField1.text=jTextField1 +CustomSizePanel.jLabel2.text=Height +CustomSizePanel.jTextField2.text=jTextField2 diff --git a/UMLVisual/src/org/uml/visual/dialogs/CardinalityChangePanel.java b/UMLVisual/src/org/uml/visual/dialogs/CardinalityChangePanel.java index bf6c8df..ab4c54a 100644 --- a/UMLVisual/src/org/uml/visual/dialogs/CardinalityChangePanel.java +++ b/UMLVisual/src/org/uml/visual/dialogs/CardinalityChangePanel.java @@ -86,6 +86,7 @@ private void fillCardinalityComboBox(JComboBox comboBox) { comboBox.addItem(CardinalityEnum.One2Many); comboBox.addItem(CardinalityEnum.Zero2One); comboBox.addItem(CardinalityEnum.Zero2Many); + comboBox.addItem(CardinalityEnum.Nothing); comboBox.setRenderer(new CardinalityListCellRenderer()); comboBox.setEnabled(true); } diff --git a/UMLVisual/src/org/uml/visual/dialogs/ConnectRelationPanel.java b/UMLVisual/src/org/uml/visual/dialogs/ConnectRelationPanel.java index 79e030a..b224c45 100644 --- a/UMLVisual/src/org/uml/visual/dialogs/ConnectRelationPanel.java +++ b/UMLVisual/src/org/uml/visual/dialogs/ConnectRelationPanel.java @@ -473,7 +473,9 @@ private void cbxRelationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F txfName.setEnabled(true); fillCardinalityComboBox(cbxCardinalitySource); lblCardinalitySource.setEnabled(true); + cbxCardinalitySource.setSelectedItem(CardinalityEnum.Nothing); fillCardinalityComboBox(cbxCardinalityTarget); + cbxCardinalityTarget.setSelectedItem(CardinalityEnum.Nothing); lblCardinalityTarget.setEnabled(true); } adaptLayoutBasedOnRelation(relation); @@ -580,6 +582,7 @@ private void fillCardinalityComboBox(JComboBox comboBox) { comboBox.addItem(CardinalityEnum.One2Many); comboBox.addItem(CardinalityEnum.Zero2One); comboBox.addItem(CardinalityEnum.Zero2Many); + comboBox.addItem(CardinalityEnum.Nothing); comboBox.setRenderer(new CardinalityListCellRenderer()); comboBox.setEnabled(true); } diff --git a/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.form b/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.form new file mode 100644 index 0000000..03537f8 --- /dev/null +++ b/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.form @@ -0,0 +1,417 @@ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.java b/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.java new file mode 100644 index 0000000..bc27994 --- /dev/null +++ b/UMLVisual/src/org/uml/visual/dialogs/CustomSizePanel.java @@ -0,0 +1,133 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.uml.visual.dialogs; + +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; + +/** + * + * @author gosselin + */ +public class CustomSizePanel extends javax.swing.JPanel { + + private DialogDescriptor dd; + private Dialog dialog; + private JButton btnOK = new JButton("OK"); + private JButton btnCancel = new JButton("Cancel"); + private int customWidth, customHeight; + private boolean ok; + + + /** + * Creates new form CustomSizePanel + */ + public CustomSizePanel(int width,int height) { + initComponents(); + customWidth = width; + customHeight = height; + jTextField1.setText(Integer.toString(width)); + jTextField2.setText(Integer.toString(height)); + ok = false; + btnOK.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + customWidth = Integer.parseInt(jTextField1.getText()); + customHeight = Integer.parseInt(jTextField2.getText()); + ok = true; + } + }); + btnCancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dialog.dispose(); + } + }); + } + + public int getWidth() { + return customWidth; + } + + public int getHeight() { + return customHeight; + } + + public boolean openDialog() { + dd = new DialogDescriptor(this, "Select custom size", true, new Object[]{btnOK, btnCancel}, null, DialogDescriptor.DEFAULT_ALIGN, null, null); + dialog = DialogDisplayer.getDefault().createDialog(dd); + //dialog.setPreferredSize(new Dimension(400,100)); + dialog.setVisible(true); + return ok; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + jLabel1 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jTextField2 = new javax.swing.JTextField(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(200, 50)); + setRequestFocusEnabled(false); + java.awt.GridBagLayout layout = new java.awt.GridBagLayout(); + layout.columnWidths = new int[] {0, 7, 0, 7, 0}; + layout.rowHeights = new int[] {0, 7, 0}; + setLayout(layout); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CustomSizePanel.class, "CustomSizePanel.jLabel1.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jLabel1, gridBagConstraints); + + jTextField1.setText(org.openide.util.NbBundle.getMessage(CustomSizePanel.class, "CustomSizePanel.jTextField1.text")); // NOI18N + jTextField1.setMinimumSize(new java.awt.Dimension(500, 19)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + add(jTextField1, gridBagConstraints); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CustomSizePanel.class, "CustomSizePanel.jLabel2.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + add(jLabel2, gridBagConstraints); + + jTextField2.setText(org.openide.util.NbBundle.getMessage(CustomSizePanel.class, "CustomSizePanel.jTextField2.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + add(jTextField2, gridBagConstraints); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + // End of variables declaration//GEN-END:variables +} diff --git a/UMLVisual/src/org/uml/visual/themes/BlueGrayTheme.java b/UMLVisual/src/org/uml/visual/themes/BlueGrayTheme.java index db7b9e3..b10b1f6 100644 --- a/UMLVisual/src/org/uml/visual/themes/BlueGrayTheme.java +++ b/UMLVisual/src/org/uml/visual/themes/BlueGrayTheme.java @@ -13,6 +13,7 @@ public class BlueGrayTheme implements Theme { // Component - colors protected static final Color DEFAULT_COLOR = new Color(0xF7F7F7); + protected static final Color BACKGROUND_COLOR = new Color(0xFFFFFF); protected static final Color HOVER_COLOR = new Color(0xF4F4F4); protected static final Color SELECT_COLOR = new Color(0xF0F0F0); protected static final Color HOVER_SELECT_COLOR = new Color(0xEBEBEB); @@ -56,6 +57,11 @@ public Color getDefaultColor() { return DEFAULT_COLOR; } + @Override + public Color getBackgroundColor() { + return BACKGROUND_COLOR; + } + @Override public Color getHoverColor() { return HOVER_COLOR; diff --git a/UMLVisual/src/org/uml/visual/themes/SandRedTheme.java b/UMLVisual/src/org/uml/visual/themes/SandRedTheme.java index 5a6abd6..4a32747 100644 --- a/UMLVisual/src/org/uml/visual/themes/SandRedTheme.java +++ b/UMLVisual/src/org/uml/visual/themes/SandRedTheme.java @@ -13,6 +13,7 @@ public class SandRedTheme implements Theme { // Component - colors protected static final Color DEFAULT_COLOR = new Color(0xF2D3BD); + protected static final Color BACKGROUND_COLOR = new Color(0xFFFFFF); protected static final Color HOVER_COLOR = new Color(0xF2CFB6); protected static final Color SELECT_COLOR = new Color(0xEDC9AF); protected static final Color HOVER_SELECT_COLOR = new Color(0xEBC3A7); @@ -57,6 +58,12 @@ public Color getDefaultColor() { return DEFAULT_COLOR; } + + @Override + public Color getBackgroundColor() { + return BACKGROUND_COLOR; + } + @Override public Color getHoverColor() { return HOVER_COLOR; diff --git a/UMLVisual/src/org/uml/visual/themes/Theme.java b/UMLVisual/src/org/uml/visual/themes/Theme.java index a319488..bc566ab 100644 --- a/UMLVisual/src/org/uml/visual/themes/Theme.java +++ b/UMLVisual/src/org/uml/visual/themes/Theme.java @@ -12,6 +12,7 @@ public interface Theme { public static final Color TRANSPARENT = new Color(0, 0, 0, 1); public Color getDefaultColor(); + public Color getBackgroundColor(); public Color getHoverColor(); public Color getSelectColor(); public Color getHoverSelectColor(); diff --git a/UMLVisual/src/org/uml/visual/widgets/ClassDiagramScene.java b/UMLVisual/src/org/uml/visual/widgets/ClassDiagramScene.java index 8c5805b..110b26a 100644 --- a/UMLVisual/src/org/uml/visual/widgets/ClassDiagramScene.java +++ b/UMLVisual/src/org/uml/visual/widgets/ClassDiagramScene.java @@ -2,10 +2,14 @@ import org.uml.visual.widgets.anchors.SelfLinkRouter; import com.timboudreau.vl.jung.ObjectSceneAdapter; +import java.awt.Color; import java.awt.Font; +import java.awt.Point; +import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import org.uml.visual.widgets.components.ClassWidget; @@ -19,6 +23,7 @@ import org.uml.model.relations.RelationBase; import org.uml.model.relations.HasBaseRelation; import java.util.HashMap; +import java.util.List; import java.util.Set; import javax.swing.JOptionPane; import org.netbeans.api.visual.action.*; @@ -29,6 +34,7 @@ import org.netbeans.api.visual.widget.*; import org.openide.explorer.ExplorerManager; import org.openide.nodes.Node; +import org.openide.nodes.Sheet; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.LookupEvent; @@ -39,6 +45,7 @@ import org.uml.explorer.ComponentNode; import org.uml.explorer.MemberNode; import org.uml.model.*; +import org.uml.model.components.PackageComponent; import org.uml.model.members.MemberBase; import org.uml.model.relations.ImplementsRelation; import org.uml.model.relations.IsRelation; @@ -47,6 +54,7 @@ import org.uml.visual.themes.Theme; import org.uml.visual.themes.ColorThemesStore; import org.uml.visual.widgets.anchors.ParallelNodeAnchor; +import org.uml.visual.widgets.components.PackageWidget; import org.uml.visual.widgets.providers.*; import org.uml.visual.widgets.popups.ScenePopupMenuProvider; import org.uml.visual.widgets.relations.HasBaseRelationWidget; @@ -109,7 +117,6 @@ public class ClassDiagramScene extends GraphScene i * Visual options flags and themes. */ private boolean showIcons = true; - private boolean showMembers = true; private boolean showSimpleTypes = false; private Theme colorTheme = ColorThemesStore.DEFAULT_COLOR_THEME; @@ -123,6 +130,8 @@ public class ClassDiagramScene extends GraphScene i @SuppressWarnings("LeakingThisInConstructor") public ClassDiagramScene(ClassDiagram umlClassDiagram, final UMLTopComponent umlTopComponent) { + setBackground(Color.WHITE); + classDiagram = umlClassDiagram; addObject(classDiagram, this); // seleciton of scene classDiagram.addPropertyChangeListener(this); @@ -155,8 +164,15 @@ public ClassDiagramScene(ClassDiagram umlClassDiagram, final UMLTopComponent uml // Add all the components to the diagram for (ComponentBase comp : classDiagram.getComponents()) { Widget w = addNode(comp); - w.setPreferredLocation(convertLocalToScene(comp.getLocation())); -// w.setPreferredBounds(comp.getBounds()); + Rectangle bounds = comp.getBounds(); + if (bounds == null || bounds.getWidth() == 0 || bounds.getHeight() == 0) { + w.setPreferredLocation(convertLocalToScene(comp.getLocation())); + } + else { + w.setPreferredLocation(convertLocalToScene(bounds.getLocation())); + bounds = new Rectangle(bounds.getSize()); + w.setPreferredBounds(convertLocalToScene(bounds)); + } } // Add all the relations to the diagram @@ -223,23 +239,19 @@ public void setShowIcons(boolean showIcons) { } repaint(); validate(); - } + } - public boolean isShowMembers() { - return showMembers; - } - - public void setShowMembers(boolean showMembers) { - this.showMembers = showMembers; + public void updateMembersDisplay() { for (Widget widget : mainLayer.getChildren()) { if (widget instanceof ComponentWidgetBase) { ComponentWidgetBase componentWidget = (ComponentWidgetBase) widget; - componentWidget.updateMemberDisplay(showMembers); + componentWidget.updateMemberDisplay(classDiagram.isShowMembers()); + componentWidget.updateAddMemberDisplay(classDiagram.isShowAddMember()); } } repaint(); validate(); - } + } public boolean isShowSimpleTypes() { return showSimpleTypes; @@ -297,6 +309,8 @@ protected Widget attachNodeWidget(ComponentBase component) { widget = new InterfaceWidget(this, (InterfaceComponent) component); } else if (component instanceof EnumComponent) { widget = new EnumWidget(this, (EnumComponent) component); + } else if (component instanceof PackageComponent) { + widget = new PackageWidget(this, (PackageComponent) component); } else { // throw new RuntimeException("Unknown component!"); } @@ -462,6 +476,12 @@ public void propertyChange(PropertyChangeEvent evt) { switch (evt.getPropertyName()) { case "name": break; + case "SHOW_MEMBERS": + updateMembersDisplay(); + break; + case "SHOW_ADD_MEMBER": + updateMembersDisplay(); + break; case "ADD_COMPONENT": break; case "REMOVE_COMPONENT": @@ -560,4 +580,46 @@ private void selectBackgroundNode(Node node) { private void deselectAllBackgroundNodes() { selectBackgroundNode(null); } + + /** + * Return the list of component wigets (class, enum, interface and packages) + * in visual order, from background to foreground + * @return + */ + public List getComponentWidgets() { + List list = new ArrayList(); + for (Widget layer : getChildren()) { + for (Widget w : layer.getChildren()) { + if (!(w instanceof ComponentWidgetBase)) + continue; + ComponentWidgetBase widgetBase = (ComponentWidgetBase)w; + list.add(widgetBase); + } + } + return list; + } + + public void updateComponents() { + //System.out.println("Update components..."); + for (ComponentWidgetBase widget : getComponentWidgets()) { + ComponentBase component = widget.getComponent(); + Rectangle bounds = widget.getBounds(); + Point location = widget.getPreferredLocation(); + bounds.setLocation(location); + component.setBounds(bounds); + } + classDiagram.updateComponentPackages(); + } + + public void updateComponentsZOrder() { + //System.out.println("Update components z order..."); + List list = getComponentWidgets(); + List components = new ArrayList(); + for (ComponentWidgetBase widget : list) { + ComponentBase component = widget.getComponent(); + components.add(component); + } + classDiagram.updateComponentOrder(components); + classDiagram.updateComponentPackages(); + } } diff --git a/UMLVisual/src/org/uml/visual/widgets/ResampledImageWidget.java b/UMLVisual/src/org/uml/visual/widgets/ResampledImageWidget.java new file mode 100644 index 0000000..b2ed1f6 --- /dev/null +++ b/UMLVisual/src/org/uml/visual/widgets/ResampledImageWidget.java @@ -0,0 +1,148 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.uml.visual.widgets; + +import org.openide.ErrorManager; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.ImageObserver; +import org.netbeans.api.visual.widget.*; +/** + * + * @author gosselin + */ +public class ResampledImageWidget extends Widget { + + private Image image; + private Image disabledImage; + private int width, height; + private boolean paintAsDisabled; + private ImageObserver observer = new ImageObserver() { + public boolean imageUpdate (Image img, int infoflags, int x, int y, int width, int height) { +// System.out.println ("INFO: " + infoflags); + setImageCore (image); + getScene ().validate (); + return (infoflags & (ImageObserver.ABORT | ImageObserver.ERROR)) == 0; + } + }; + + /** + * Creates an image widget. + * @param scene the scene + */ + public ResampledImageWidget (Scene scene) { + super (scene); + } + + /** + * Creates an image widget. + * @param scene the scene + * @param image the image + */ + public ResampledImageWidget (Scene scene, Image image) { + super (scene); + setImage (image); + } + + /** + * Returns an image. + * @return the image + */ + public Image getImage () { + return image; + } + + /** + * Sets an image + * @param image the image + */ + public void setImage (Image image) { + if (this.image == image) + return; + setImageCore (image); + } + + private void setImageCore (Image image) { + if (image == this.image) { + return; + } + int oldWidth = width; + int oldHeight = height; + + this.image = image; + this.disabledImage = null; + width = image != null ? image.getWidth (null) : 0; + height = image != null ? image.getHeight (null) : 0; + + if (oldWidth == width && oldHeight == height) + repaint (); + else + revalidate (); + } + + /** + * Returns whether the label is painted as disabled. + * @return true, if the label is painted as disabled + */ + public boolean isPaintAsDisabled () { + return paintAsDisabled; + } + + /** + * Sets whether the label is painted as disabled. + * @param paintAsDisabled if true, then the label is painted as disabled + */ + public void setPaintAsDisabled (boolean paintAsDisabled) { + boolean repaint = this.paintAsDisabled != paintAsDisabled; + this.paintAsDisabled = paintAsDisabled; + if (repaint) + repaint (); + } + + /** + * Calculates a client area of the image + * @return the calculated client area + */ + protected Rectangle calculateClientArea () { + if (image != null) + return new Rectangle (0, 0, width, height); + return super.calculateClientArea (); + } + + /** + * Paints the image widget. + */ + protected void paintWidget () { + if (image == null) + return; + Graphics2D gr = getGraphics (); + if (image != null) { + if (paintAsDisabled) { + if (disabledImage == null) { + disabledImage = GrayFilter.createDisabledImage (image); + MediaTracker tracker = new MediaTracker (getScene ().getView ()); + tracker.addImage (disabledImage, 0); + try { + tracker.waitForAll (); + } catch (InterruptedException e) { + ErrorManager.getDefault ().notify (e); + } + } + gr.drawImage (disabledImage, + 0, 0, getMaximumSize().width, getMaximumSize().height, + 0, 0, width, height, + observer); + } else { + gr.drawImage (image, + 0, 0, getMaximumSize().width, getMaximumSize().height, + 0, 0, width, height, + observer); + } + } + } + +} diff --git a/UMLVisual/src/org/uml/visual/widgets/components/ClassWidget.java b/UMLVisual/src/org/uml/visual/widgets/components/ClassWidget.java index ef7ad22..20fb2f3 100644 --- a/UMLVisual/src/org/uml/visual/widgets/components/ClassWidget.java +++ b/UMLVisual/src/org/uml/visual/widgets/components/ClassWidget.java @@ -6,12 +6,15 @@ import java.awt.Font; import java.awt.event.MouseListener; import java.beans.PropertyChangeEvent; +import java.util.LinkedHashSet; +import java.util.List; import java.util.concurrent.Callable; import javax.swing.JOptionPane; import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.WidgetAction; import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.SeparatorWidget; +import org.uml.memberparser.MemberParser; import org.uml.model.components.ClassComponent; import org.uml.model.members.Constructor; import org.uml.model.members.Field; @@ -44,7 +47,7 @@ public ClassWidget(ClassDiagramScene scene, ClassComponent classComponent) { } else { setMinimumSize(MIN_DIMENSION_1ROW); } - iconNameContainer.addChild(iconWidget); + //iconNameContainer.addChild(iconWidget); iconNameContainer.addChild(nameLabel); headerWidget.addChild(iconNameContainer); addChild(headerWidget); @@ -121,11 +124,50 @@ public void addFieldWidget() { MouseListener mouseListener = new CloseInplaceEditorOnClickAdapter(nameEditorAction); getScene().getView().addMouseListener(mouseListener); } + + public void addField(String fieldSignature) { + if (getComponent().signatureExists(fieldSignature)) + return; + Field field = new Field("untitledField", "Object", Visibility.PRIVATE); + try { + MemberParser.fillFieldComponents(field, fieldSignature); + } + catch(Exception ex) { + JOptionPane.showMessageDialog(null, "Error while parsing field "+fieldSignature, "Error", JOptionPane.ERROR_MESSAGE); + return; + } + getComponent().addField(field); + FieldWidget fieldWidget = new FieldWidget(getClassDiagramScene(), field); + addMember(fieldsContainer, fieldWidget); + getScene().validate(); + } + + public void addFields(List fieldSignatures) { + for (String field : fieldSignatures) { + addField(field); + } + } + + public void addFields(String fieldSignatures) { + String[] list = fieldSignatures.split("[\\r\\n]+"); + for (String field : list) { + addField(field); + } + } public void removeField(FieldWidget field) { removeMember(fieldsContainer, field); } + public void addMethodWidgets(LinkedHashSet methods) { + for (Method method : methods) { + getComponent().addMethod(method); + MethodWidget methodWidget = new MethodWidget(getClassDiagramScene(), method); + addMember(methodsContainer, methodWidget); + } + getScene().validate(); + } + public void addMethodWidget() { Method method = new Method("untitledMethod", "void"); getComponent().addMethod(method); @@ -139,6 +181,36 @@ public void addMethodWidget() { MouseListener mouseListener = new CloseInplaceEditorOnClickAdapter(nameEditorAction); getScene().getView().addMouseListener(mouseListener); } + + public void addMethod(String methodSignature) { + if (getComponent().signatureExists(methodSignature)) + return; + Method method = new Method("untitledMethod", "void"); + try { + MemberParser.fillMethodComponents(method, methodSignature); + } + catch(Exception ex) { + JOptionPane.showMessageDialog(null, "Error while parsing method "+methodSignature, "Error", JOptionPane.ERROR_MESSAGE); + return; + } + getComponent().addMethod(method); + MethodWidget methodWidget = new MethodWidget(getClassDiagramScene(), method); + addMember(methodsContainer, methodWidget); + getScene().validate(); + } + + public void addMethods(List methodSignatures) { + for (String method : methodSignatures) { + addMethod(method); + } + } + + public void addMethods(String methodSignatures) { + String[] list = methodSignatures.split("[\\r\\n]+"); + for (String method : list) { + addMethod(method); + } + } public final void addDefaultConstructorWidget() { Constructor constructor = new Constructor(getName()); diff --git a/UMLVisual/src/org/uml/visual/widgets/components/ComponentWidgetBase.java b/UMLVisual/src/org/uml/visual/widgets/components/ComponentWidgetBase.java index 54b71e8..3b066c0 100644 --- a/UMLVisual/src/org/uml/visual/widgets/components/ComponentWidgetBase.java +++ b/UMLVisual/src/org/uml/visual/widgets/components/ComponentWidgetBase.java @@ -1,5 +1,6 @@ package org.uml.visual.widgets.components; +import java.awt.Color; import org.uml.visual.widgets.providers.ComponentAlignWithResizeStrategyProvider; import org.uml.visual.widgets.providers.ComponentAlignWithMoveStrategyProvider; import org.uml.visual.widgets.members.MemberWidgetBase; @@ -28,8 +29,10 @@ import org.uml.model.components.ComponentBase; import org.uml.model.components.EnumComponent; import org.uml.model.components.InterfaceComponent; +import org.uml.model.components.PackageComponent; import org.uml.visual.themes.Theme; import org.uml.visual.widgets.ClassDiagramScene; +import org.uml.visual.widgets.ResampledImageWidget; import org.uml.visual.widgets.actions.ComponentNameEditor; //import org.uml.visual.widgets.actions.ComponentWidgetKeyboardAction; import org.uml.visual.widgets.providers.ComponentConnectProvider; @@ -45,7 +48,7 @@ abstract public class ComponentWidgetBase extends Widget implements PropertyChan protected final Widget headerWidget; protected Widget iconNameContainer = new Widget(getScene()); protected static String iconFolderPath = "org/uml/visual/widgets/icons/"; - protected ImageWidget iconWidget = new ImageWidget(getScene()); + protected ResampledImageWidget iconWidget = new ResampledImageWidget(getScene()); protected LabelWidget nameLabel; protected LinkedList separators = new LinkedList<>(); @@ -81,25 +84,34 @@ public ComponentWidgetBase(final ClassDiagramScene scene, ComponentBase componen setLayout(LayoutFactory.createVerticalFlowLayout()); setOpaque(true); setCheckClipping(true); - setBackground(getColorTheme().getDefaultColor()); headerWidget = new Widget(scene); // mora ovako zbog layouta ne moze this - headerWidget.setLayout(LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.CENTER, 0)); + if (component instanceof PackageComponent) { + headerWidget.setLayout(LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.LEFT_TOP, 0)); + setBackground(getColorTheme().getBackgroundColor()); + } + else { + setBackground(getColorTheme().getDefaultColor()); + headerWidget.setLayout(LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.CENTER, 0)); + } headerWidget.setBorder(EMPTY_CONTAINER_BORDER); iconWidget.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 3)); iconWidget.setVisible(scene.isShowIcons()); + iconWidget.setMaximumSize(new Dimension(12,12)); if (component instanceof ClassComponent) { iconWidget.setImage(ImageUtilities.loadImage(iconFolderPath + "class.png")); } else if (component instanceof InterfaceComponent) { iconWidget.setImage(ImageUtilities.loadImage(iconFolderPath + "interface.png")); } else if (component instanceof EnumComponent) { iconWidget.setImage(ImageUtilities.loadImage(iconFolderPath + "enum.png")); + } else if (component instanceof PackageComponent) { + iconWidget.setImage(ImageUtilities.loadImage(iconFolderPath + "other/package.png")); } iconNameContainer.setLayout(LayoutFactory.createHorizontalFlowLayout()); nameLabel = new LabelWidget(scene); nameLabel.setLabel(component.getName()); - nameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 12 + 3)); + //nameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 12 + 3)); nameLabel.setFont(scene.getFont().deriveFont(Font.BOLD)); nameLabel.getActions().addAction(ActionFactory.createInplaceEditorAction(new ComponentNameEditor(this))); @@ -154,7 +166,7 @@ public void notifyStateChanged(ObjectState previousState, ObjectState state) { boolean focused = state.isFocused(); boolean hovered = state.isHovered(); - + if (focused) { setBorder(getColorTheme().getSelectBorder()); if (hovered) setBackground(getColorTheme().getHoverSelectColor()); @@ -162,15 +174,24 @@ public void notifyStateChanged(ObjectState previousState, ObjectState state) { for (SeparatorWidget separator : separators) { separator.setForeground(getColorTheme().getSelectBorderColor()); } - } else if (hovered) { - setBorder(getColorTheme().getHoverBorder()); - setBackground(getColorTheme().getHoverColor()); - for (SeparatorWidget separator : separators) { - separator.setForeground(getColorTheme().getHoverBorderColor()); + } else if (!(component instanceof PackageComponent)) { + if (hovered) { + setBorder(getColorTheme().getHoverBorder()); + setBackground(getColorTheme().getHoverColor()); + for (SeparatorWidget separator : separators) { + separator.setForeground(getColorTheme().getHoverBorderColor()); + } + } else { + setBorder(getColorTheme().getDefaultBorder()); + setBackground(getColorTheme().getDefaultColor()); + for (SeparatorWidget separator : separators) { + separator.setForeground(getColorTheme().getDefaultBorderColor()); + } } - } else { + } + else { setBorder(getColorTheme().getDefaultBorder()); - setBackground(getColorTheme().getDefaultColor()); + setBackground(getColorTheme().getBackgroundColor()); for (SeparatorWidget separator : separators) { separator.setForeground(getColorTheme().getDefaultBorderColor()); } @@ -188,8 +209,8 @@ public final String getName() { public void setName(String newName) { if (!getName().equals(newName)) { - if (component.getParentDiagram().signatureExists(component.getParentPackage() + "." + newName)) { - JOptionPane.showMessageDialog(getScene().getView(), "Name \"" + component.getParentPackage() + "." + newName + "\" already exists!"); + if (component.getParentDiagram().signatureExists(component.getFullParentPackage() + "." + newName)) { + JOptionPane.showMessageDialog(getScene().getView(), "Name \"" + component.getFullParentPackage() + "." + newName + "\" already exists!"); } else { component.setName(newName); } @@ -230,6 +251,15 @@ public void updateMemberDisplay(boolean memberDisplayEnabled) { } } + public void updateAddMemberDisplay(boolean addMemberDisplayEnabled) { + for (Widget widget : getChildren()) { + if (widget instanceof MemberContainerWidget) { + MemberContainerWidget mcw = (MemberContainerWidget) widget; + mcw.updateAddMemberDisplay(addMemberDisplayEnabled); + } + } + } + public void updateTypeNamesDisplay(boolean simpleTypeNamesDisplayEnabled) { for (Widget widget : getChildren()) { if (widget instanceof MemberContainerWidget) { diff --git a/UMLVisual/src/org/uml/visual/widgets/components/InterfaceWidget.java b/UMLVisual/src/org/uml/visual/widgets/components/InterfaceWidget.java index 7102f73..23aaea3 100644 --- a/UMLVisual/src/org/uml/visual/widgets/components/InterfaceWidget.java +++ b/UMLVisual/src/org/uml/visual/widgets/components/InterfaceWidget.java @@ -2,7 +2,9 @@ import java.awt.Dimension; import java.awt.event.MouseListener; +import java.util.List; import java.util.concurrent.Callable; +import javax.swing.JOptionPane; import org.uml.visual.widgets.members.MethodWidget; import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.WidgetAction; @@ -10,6 +12,7 @@ import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.SeparatorWidget; import org.netbeans.api.visual.widget.Widget; +import org.uml.memberparser.MemberParser; import org.uml.model.components.InterfaceComponent; import org.uml.model.members.Method; import org.uml.visual.widgets.ClassDiagramScene; @@ -84,4 +87,34 @@ public void addMethodWidget() { MouseListener mouseListener = new CloseInplaceEditorOnClickAdapter(nameEditorAction); getScene().getView().addMouseListener(mouseListener); } + + public void addMethod(String methodSignature) { + if (getComponent().signatureExists(methodSignature)) + return; + Method method = new Method("untitledMethod", "void"); + try { + MemberParser.fillMethodComponents(method, methodSignature); + } + catch(Exception ex) { + JOptionPane.showMessageDialog(null, "Error while parsing method "+methodSignature, "Error", JOptionPane.ERROR_MESSAGE); + return; + } + getComponent().addMethod(method); + MethodWidget methodWidget = new MethodWidget(getClassDiagramScene(), method); + addMember(methodsContainer, methodWidget); + getScene().validate(); + } + + public void addMethods(List methodSignatures) { + for (String method : methodSignatures) { + addMethod(method); + } + } + + public void addMethods(String methodSignatures) { + String[] list = methodSignatures.split("[\\r\\n]+"); + for (String method : list) { + addMethod(method); + } + } } diff --git a/UMLVisual/src/org/uml/visual/widgets/components/MemberContainerWidget.java b/UMLVisual/src/org/uml/visual/widgets/components/MemberContainerWidget.java index f891b7b..a2becac 100644 --- a/UMLVisual/src/org/uml/visual/widgets/components/MemberContainerWidget.java +++ b/UMLVisual/src/org/uml/visual/widgets/components/MemberContainerWidget.java @@ -1,6 +1,9 @@ package org.uml.visual.widgets.components; import java.awt.Font; +import java.awt.Point; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.Callable; import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.EditProvider; @@ -9,6 +12,7 @@ import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.Widget; import org.openide.util.Exceptions; +import org.uml.model.members.MemberBase; import org.uml.visual.themes.Theme; import org.uml.visual.widgets.ClassDiagramScene; import static org.uml.visual.widgets.components.ComponentWidgetBase.ADD_LABEL_FONT_SIZE; @@ -62,7 +66,8 @@ protected void notifyStateChanged(ObjectState previousState, ObjectState state) addMemberLabel.setFont(getScene().getFont().deriveFont(Font.ITALIC, ADD_LABEL_FONT_SIZE)); addChild(addMemberLabel); - updateMemberDisplay(scene.isShowMembers()); + updateMemberDisplay(scene.getClassDiagram().isShowMembers()); + updateAddMemberDisplay(scene.getClassDiagram().isShowAddMember()); } public void addAddAction(final Callable function) { @@ -101,7 +106,35 @@ public void addMemberWidget(MemberWidgetBase memberWidget) { addChild(getChildren().size() - 1, memberWidget); // add so it's 1 before "add" LabelWidget } } - + + public void moveUpMemberWidget(MemberWidgetBase memberWidget) { + List children = new ArrayList(getChildren()); + for (int i=1;i children = new ArrayList(getChildren()); + for (int i=0;i methods = classComponent.getUnimplementedMethods(); + /*for (Method method : methods) { + System.out.println(method.getSignature()); + }*/ + classWidget.addMethodWidgets(methods); + } + }; + ActionListener pasteMethodsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + String clipboard = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); + classWidget.addMethods(clipboard); + } catch (Exception ex) { + } + } + }; + ActionListener copyMethodsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ClassComponent classComponent = classWidget.getComponent(); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos, true, "utf-8"); + for (Method method : classComponent.getMethods()) { + ps.println(method.getSignature()); + } + StringSelection selection = new StringSelection(baos.toString()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection,selection); + } catch (UnsupportedEncodingException ex) { + } + } + }; + ActionListener pasteFieldsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + String clipboard = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); + classWidget.addFields(clipboard); + } catch (Exception ex) { + } + } + }; + ActionListener copyFieldsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ClassComponent classComponent = classWidget.getComponent(); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos, true, "utf-8"); + for (Field field : classComponent.getFields()) { + ps.println(field.getSignature()); + } + StringSelection selection = new StringSelection(baos.toString()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection,selection); + } catch (UnsupportedEncodingException ex) { + } + } + }; + @Override public JPopupMenu getPopupMenu(Widget widget, Point point) { return menu; diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/ComponentPopupMenuProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/ComponentPopupMenuProvider.java new file mode 100644 index 0000000..b3c9d9a --- /dev/null +++ b/UMLVisual/src/org/uml/visual/widgets/popups/ComponentPopupMenuProvider.java @@ -0,0 +1,45 @@ +package org.uml.visual.widgets.popups; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.uml.visual.widgets.components.ComponentWidgetBase; + +/** + * + * @author Philippe-Henri Gosselin + */ +public abstract class ComponentPopupMenuProvider implements PopupMenuProvider { + + private ComponentWidgetBase widget; + private JMenuItem moveToFront; + private JMenuItem moveToBack; + + ComponentPopupMenuProvider(ComponentWidgetBase widget) { + this.widget = widget; + } + + void addZMenuItems(JPopupMenu menu) { + (moveToFront = new JMenuItem("Move to front")).addActionListener(moveToFrontListener); + menu.add(moveToFront); + (moveToBack = new JMenuItem("Move to back")).addActionListener(moveToBackListener); + menu.add(moveToBack); + } + + ActionListener moveToFrontListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + widget.bringToFront(); + widget.getClassDiagramScene().updateComponentsZOrder(); + } + }; + ActionListener moveToBackListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + widget.bringToBack(); + widget.getClassDiagramScene().updateComponentsZOrder(); + } + }; +} diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/EnumPopupMenuProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/EnumPopupMenuProvider.java index 64d5c63..889dce8 100644 --- a/UMLVisual/src/org/uml/visual/widgets/popups/EnumPopupMenuProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/popups/EnumPopupMenuProvider.java @@ -13,7 +13,7 @@ * * @author Jelena */ -public class EnumPopupMenuProvider implements PopupMenuProvider { +public class EnumPopupMenuProvider extends ComponentPopupMenuProvider { private EnumWidget enumWidget; private JPopupMenu menu; @@ -21,6 +21,7 @@ public class EnumPopupMenuProvider implements PopupMenuProvider { private JMenuItem addLiteral; public EnumPopupMenuProvider(EnumWidget enumWidget) { + super(enumWidget); this.enumWidget = enumWidget; menu = new JPopupMenu("Enum Menu"); @@ -29,6 +30,10 @@ public EnumPopupMenuProvider(EnumWidget enumWidget) { menu.addSeparator(); + addZMenuItems(menu); + + menu.addSeparator(); + (deleteClass = new JMenuItem("Delete Enum")).addActionListener(removeWidgetListener); menu.add(deleteClass); diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/InterfacePopupMenuProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/InterfacePopupMenuProvider.java index d950ae7..519bee6 100644 --- a/UMLVisual/src/org/uml/visual/widgets/popups/InterfacePopupMenuProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/popups/InterfacePopupMenuProvider.java @@ -1,33 +1,58 @@ package org.uml.visual.widgets.popups; import java.awt.Point; +import java.awt.Toolkit; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import org.netbeans.api.visual.action.PopupMenuProvider; import org.netbeans.api.visual.widget.Widget; +import org.openide.util.Exceptions; import org.uml.model.ClassDiagram; +import org.uml.model.components.ClassComponent; +import org.uml.model.components.InterfaceComponent; +import org.uml.model.members.Method; import org.uml.visual.widgets.components.InterfaceWidget; /** * * @author Jelena */ -public class InterfacePopupMenuProvider implements PopupMenuProvider { +public class InterfacePopupMenuProvider extends ComponentPopupMenuProvider { private InterfaceWidget interfaceWidget; private JPopupMenu menu; - private JMenuItem addMethod; + private JMenuItem addMethod,copyMethods,pasteMethods; private JMenuItem deleteInterface; public InterfacePopupMenuProvider(InterfaceWidget interfaceWidget) { + super(interfaceWidget); this.interfaceWidget = interfaceWidget; menu = new JPopupMenu("Interface Menu"); (addMethod = new JMenuItem("Add Method")).addActionListener(addMethodListener); menu.add(addMethod); + (pasteMethods = new JMenuItem("Paste methods from clipboard")).addActionListener(pasteMethodsListener); + menu.add(pasteMethods); + + menu.addSeparator(); + + (copyMethods = new JMenuItem("Copy methods to clipboard")).addActionListener(copyMethodsListener); + menu.add(copyMethods); + + menu.addSeparator(); + + addZMenuItems(menu); + menu.addSeparator(); (deleteInterface = new JMenuItem("Delete Interface")).addActionListener(removeWidgetListener); @@ -39,7 +64,32 @@ public void actionPerformed(ActionEvent e) { interfaceWidget.addMethodWidget(); } }; - + ActionListener pasteMethodsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + String clipboard = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); + interfaceWidget.addMethods(clipboard); + } catch (Exception ex) { + } + } + }; + ActionListener copyMethodsListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + InterfaceComponent interfaceComponent = interfaceWidget.getComponent(); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos, true, "utf-8"); + for (Method method : interfaceComponent.getMethods()) { + ps.println(method.getSignature()); + } + StringSelection selection = new StringSelection(baos.toString()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection,selection); + } catch (UnsupportedEncodingException ex) { + } + } + }; ActionListener removeWidgetListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/MemberBasePopupProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/MemberBasePopupProvider.java index 3b1bdcb..a68433d 100644 --- a/UMLVisual/src/org/uml/visual/widgets/popups/MemberBasePopupProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/popups/MemberBasePopupProvider.java @@ -8,6 +8,7 @@ import org.netbeans.api.visual.action.PopupMenuProvider; import org.netbeans.api.visual.widget.Widget; import org.uml.model.members.MemberBase; +import org.uml.visual.widgets.components.MemberContainerWidget; import org.uml.visual.widgets.members.MemberWidgetBase; /** @@ -18,17 +19,53 @@ public class MemberBasePopupProvider implements PopupMenuProvider { protected MemberWidgetBase widget; protected JPopupMenu menu; - private JMenuItem deleteMember; + private JMenuItem moveUp,moveDown,deleteMember; public MemberBasePopupProvider(MemberWidgetBase widget){ this.widget = widget; String name = widget.getMember().getClass().getSimpleName(); menu = new JPopupMenu(name+" Menu"); + + (moveUp = new JMenuItem("Move up")).addActionListener(moveUpWidgetListener); + menu.add(moveUp); + + (moveDown = new JMenuItem("Move down")).addActionListener(moveDownWidgetListener); + menu.add(moveDown); (deleteMember = new JMenuItem("Delete "+name)).addActionListener(removeWidgetListener); menu.add(deleteMember); } + ActionListener moveUpWidgetListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Widget container = widget.getParentWidget(); + if (!(container instanceof MemberContainerWidget)) { + return; + } + MemberBase member = widget.getMember(); + if (member.getDeclaringComponent().moveUpMember(member)) { + MemberContainerWidget memberContainerWidget = (MemberContainerWidget)container; + memberContainerWidget.moveUpMemberWidget(widget); + } + } + }; + + ActionListener moveDownWidgetListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Widget container = widget.getParentWidget(); + if (!(container instanceof MemberContainerWidget)) { + return; + } + MemberBase member = widget.getMember(); + if (member.getDeclaringComponent().moveDownMember(member)) { + MemberContainerWidget memberContainerWidget = (MemberContainerWidget)container; + memberContainerWidget.moveDownMemberWidget(widget); + } + } + }; + ActionListener removeWidgetListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/PackagePopupMenuProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/PackagePopupMenuProvider.java new file mode 100644 index 0000000..cecd0d8 --- /dev/null +++ b/UMLVisual/src/org/uml/visual/widgets/popups/PackagePopupMenuProvider.java @@ -0,0 +1,50 @@ +package org.uml.visual.widgets.popups; + +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.widget.Widget; +import org.uml.visual.widgets.components.PackageWidget; + +/** + * + * @author Jelena + */ +public class PackagePopupMenuProvider extends ComponentPopupMenuProvider { + + private PackageWidget packageWidget; + private JPopupMenu menu; + private JMenuItem deleteClass; + + public PackagePopupMenuProvider(PackageWidget packageWidget) { + super(packageWidget); + this.packageWidget = packageWidget; + menu = new JPopupMenu("Package Menu"); + + menu.addSeparator(); + + addZMenuItems(menu); + + menu.addSeparator(); + + (deleteClass = new JMenuItem("Delete Package")).addActionListener(removeWidgetListener); + menu.add(deleteClass); + + } + + ActionListener removeWidgetListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + packageWidget.getComponent().getParentDiagram().removeComponentFromContainer(packageWidget.getComponent()); + packageWidget.removeFromParent(); + } + }; + + @Override + public JPopupMenu getPopupMenu(Widget widget, Point point) { + return menu; + } +} diff --git a/UMLVisual/src/org/uml/visual/widgets/popups/ScenePopupMenuProvider.java b/UMLVisual/src/org/uml/visual/widgets/popups/ScenePopupMenuProvider.java index ca15e47..20e2f32 100644 --- a/UMLVisual/src/org/uml/visual/widgets/popups/ScenePopupMenuProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/popups/ScenePopupMenuProvider.java @@ -1,6 +1,7 @@ package org.uml.visual.widgets.popups; import java.awt.Point; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -22,15 +23,20 @@ import org.openide.util.Exceptions; import org.openide.windows.WindowManager; import org.uml.jung.JUNGEngine; +import org.uml.model.ClassDiagram; import org.uml.model.components.ClassComponent; +import org.uml.model.components.ComponentBase; import org.uml.model.components.EnumComponent; import org.uml.model.components.InterfaceComponent; +import org.uml.model.components.PackageComponent; import org.uml.visual.dialogs.ConnectRelationPanel; +import org.uml.visual.dialogs.CustomSizePanel; import org.uml.visual.widgets.ClassDiagramScene; import org.uml.visual.widgets.actions.ComponentNameEditor; import org.uml.visual.widgets.components.ClassWidget; import org.uml.visual.widgets.components.EnumWidget; import org.uml.visual.widgets.components.InterfaceWidget; +import org.uml.visual.widgets.components.PackageWidget; import org.uml.visual.widgets.providers.CloseInplaceEditorOnClickAdapter; /** @@ -44,12 +50,14 @@ public class ScenePopupMenuProvider implements PopupMenuProvider { private JMenuItem miCreateClass; private JMenuItem miCreateInterface; private JMenuItem miCreateEnum; + private JMenuItem miCreatePackage; private JMenuItem miCreateRelationship; // private JMenuItem miGenerateCode; private JMenu mExportAsImage; private JMenuItem miApplyJUNGLayout; private JMenu mVisualOptions; private JCheckBoxMenuItem miShowIcons; + private JCheckBoxMenuItem miShowAddMember; private JCheckBoxMenuItem miShowMembers; private JCheckBoxMenuItem miShowSimpleTypeNames; private final JRadioButtonMenuItem miBlueGray = new JRadioButtonMenuItem("Blue-gray"); @@ -119,7 +127,22 @@ public void actionPerformed(ActionEvent e) { scene.getView().addMouseListener(new CloseInplaceEditorOnClickAdapter(editorAction)); } }); + miCreatePackage = new JMenuItem("Add Package"); + miCreatePackage.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + PackageWidget widget = (PackageWidget) scene.addNode(new PackageComponent()); + widget.bringToBack(); + widget.setPreferredLocation(popupPoint); + widget.getComponent().setLocation(popupPoint); + scene.validate(); + // Temp renamer + WidgetAction editorAction = ActionFactory.createInplaceEditorAction(new ComponentNameEditor(widget)); + ActionFactory.getInplaceEditorController(editorAction).openEditor(widget.getNameLabel()); + scene.getView().addMouseListener(new CloseInplaceEditorOnClickAdapter(editorAction)); + } + }); miCreateRelationship = new JMenuItem("Add Relationship"); miCreateRelationship.addActionListener(new ActionListener() { @Override @@ -144,7 +167,7 @@ public void actionPerformed(ActionEvent e) { miExportAsImageCurrent.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - exportAsImage(true); + exportAsImage(true,false); } }); mExportAsImage.add(miExportAsImageCurrent); @@ -152,11 +175,18 @@ public void actionPerformed(ActionEvent e) { miExportAsImageWhole.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - exportAsImage(false); + exportAsImage(false,false); + } + }); + mExportAsImage.add(miExportAsImageWhole); + miExportAsImageWhole = new JMenuItem("Whole diagram (custom size)"); + miExportAsImageWhole.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + exportAsImage(false,true); } }); mExportAsImage.add(miExportAsImageWhole); - miApplyJUNGLayout = new JMenuItem("Arrange diagram (experimental)"); miApplyJUNGLayout.addActionListener(new ActionListener() { @Override @@ -170,7 +200,6 @@ public void actionPerformed(ActionEvent e) { miShowIcons = new JCheckBoxMenuItem("Show icons"); miShowIcons.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { scene.setShowIcons(!scene.isShowIcons()); @@ -179,12 +208,23 @@ public void actionPerformed(ActionEvent e) { }); mVisualOptions.add(miShowIcons); + miShowAddMember = new JCheckBoxMenuItem("Show add member"); + miShowAddMember.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ClassDiagram classDiagram = scene.getClassDiagram(); + classDiagram.setShowAddMember(!classDiagram.isShowAddMember()); + WindowManager.getDefault().findTopComponent("properties").repaint(); + } + }); + mVisualOptions.add(miShowAddMember); + miShowMembers = new JCheckBoxMenuItem("Show members"); miShowMembers.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - scene.setShowMembers(!scene.isShowMembers()); + ClassDiagram classDiagram = scene.getClassDiagram(); + classDiagram.setShowMembers(!classDiagram.isShowMembers()); WindowManager.getDefault().findTopComponent("properties").repaint(); } }); @@ -230,6 +270,8 @@ public void actionPerformed(ActionEvent e) { sceneMenu.add(miCreateEnum); +// sceneMenu.add(miCreatePackage); + sceneMenu.addSeparator(); sceneMenu.add(miCreateRelationship); @@ -251,7 +293,8 @@ public void actionPerformed(ActionEvent e) { private void updateMenu() { miShowIcons.setSelected(scene.isShowIcons()); - miShowMembers.setSelected(scene.isShowMembers()); + miShowMembers.setSelected(scene.getClassDiagram().isShowMembers()); + miShowAddMember.setSelected(scene.getClassDiagram().isShowAddMember()); miShowSimpleTypeNames.setSelected(scene.isShowSimpleTypes()); switch(scene.getColorTheme().getName()){ case "blue-gray": @@ -263,7 +306,17 @@ private void updateMenu() { } } - private void exportAsImage(boolean onlyVisiblePart) { + private static File currentSaveDirectory; + private void exportAsImage(boolean onlyVisiblePart,boolean customSize) { + int customWidth = 4*scene.getPreferredBounds().width; + int customHeight = 4*scene.getPreferredBounds().height; + if (customSize) { + CustomSizePanel customSizePanel = new CustomSizePanel(customWidth,customHeight); + if (!customSizePanel.openDialog()) + return; + customWidth = customSizePanel.getWidth(); + customHeight = customSizePanel.getHeight(); + } JFileChooser chooser = new JFileChooser() { @Override public void approveSelection() { @@ -286,15 +339,21 @@ public void approveSelection() { super.approveSelection(); } }; + if (currentSaveDirectory != null) { + chooser.setCurrentDirectory(currentSaveDirectory); + } chooser.setFileFilter(new FileNameExtensionFilter("Portable Network Graphics (.png)", "png")); if (chooser.showSaveDialog(scene.getView()) == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); + if (f != null && f.getParentFile() != null) { + currentSaveDirectory = f; + } if (!f.getName().toLowerCase().endsWith(".png")) { f = new File(f.getParentFile(), f.getName() + ".png"); } try { // Zoom type is overriden if onlyVisiblePart is set - SceneExporter.createImage(scene, f, SceneExporter.ImageType.PNG, SceneExporter.ZoomType.ACTUAL_SIZE, onlyVisiblePart, false, 0, 0, 0); + SceneExporter.createImage(scene, f, SceneExporter.ImageType.PNG, customSize?SceneExporter.ZoomType.CUSTOM_SIZE:SceneExporter.ZoomType.ACTUAL_SIZE, onlyVisiblePart, false, 0, customWidth, customHeight); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Cannot export scene as image!", "Input-output error!", JOptionPane.ERROR_MESSAGE); Exceptions.printStackTrace(ex); diff --git a/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithMoveStrategyProvider.java b/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithMoveStrategyProvider.java index ebc6790..6a4667b 100644 --- a/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithMoveStrategyProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithMoveStrategyProvider.java @@ -62,6 +62,7 @@ public void movementStarted(Widget widget) { public void movementFinished(Widget widget) { hide(); if(!startLocation.equals(widget.getLocation())) { + scene.updateComponents(); scene.getUmlTopComponent().notifyModified(); } } diff --git a/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithResizeStrategyProvider.java b/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithResizeStrategyProvider.java index 4c1e5ad..755e63c 100644 --- a/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithResizeStrategyProvider.java +++ b/UMLVisual/src/org/uml/visual/widgets/providers/ComponentAlignWithResizeStrategyProvider.java @@ -228,7 +228,7 @@ public void resizingStarted(Widget widget) { public void resizingFinished(Widget widget) { hide(); - // TODO enable notifyModified on resize, when component sizes are being persistedh -// scene.getUmlTopComponent().notifyModified(); + scene.updateComponents(); + scene.getUmlTopComponent().notifyModified(); } } diff --git a/UMLVisual/src/org/uml/xmlDeserialization/ClassDiagramDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/ClassDiagramDeserializer.java index 8b28f1f..74c6e96 100644 --- a/UMLVisual/src/org/uml/xmlDeserialization/ClassDiagramDeserializer.java +++ b/UMLVisual/src/org/uml/xmlDeserialization/ClassDiagramDeserializer.java @@ -12,13 +12,16 @@ import org.dom4j.Element; import org.uml.model.components.ClassComponent; import org.uml.model.ClassDiagram; +import org.uml.model.GenerationSetting; import org.uml.model.components.ComponentBase; import org.uml.model.components.EnumComponent; import org.uml.model.relations.HasBaseRelation; import org.uml.model.relations.ImplementsRelation; import org.uml.model.components.InterfaceComponent; +import org.uml.model.components.PackageComponent; import org.uml.model.relations.IsRelation; import org.uml.model.relations.UseRelation; +import org.uml.xmlDeserialization.components.PackageDeserializer; /** * @@ -43,36 +46,54 @@ public ClassDiagramDeserializer(ClassDiagram classDiagram) { public void deserialize(Element node) { classDiagram.setName(node.attributeValue("name")); + String gettersGeneration = node.attributeValue("gettersGeneration"); + String settersGeneration = node.attributeValue("settersGeneration"); + if (gettersGeneration != null) classDiagram.setGetterGeneration(GenerationSetting.stringToGenerationSetting(gettersGeneration)); + if (settersGeneration != null) classDiagram.setSetterGeneration(GenerationSetting.stringToGenerationSetting(settersGeneration)); + + String showMembers = node.attributeValue("showMembers"); + String showAddMember = node.attributeValue("showAddMember"); + if (showMembers != null) classDiagram.setShowMembers(showMembers.equalsIgnoreCase("true")); + if (showAddMember != null) classDiagram.setShowAddMember(showAddMember.equalsIgnoreCase("true")); + Element classDiagramComponents = node.element("ClassDiagramComponents"); - Iterator classIterator = classDiagramComponents.elementIterator("Class"); - while (classIterator != null && classIterator.hasNext()) { - Element componentNode = (Element) classIterator.next(); - - ClassComponent component = new ClassComponent(); - ClassDeserializer cd = new ClassDeserializer(component); - cd.deserialize(componentNode); - classDiagram.addComponent(component); - } - - Iterator interfaceIterator = classDiagramComponents.elementIterator("Interface"); - while (interfaceIterator != null && interfaceIterator.hasNext()) { - Element interfaceNode = (Element) interfaceIterator.next(); - - InterfaceComponent component = new InterfaceComponent(); - InterfaceDeserializer id = new InterfaceDeserializer(component); - id.deserialize(interfaceNode); - classDiagram.addComponent(component); - } - Iterator enumIterator = classDiagramComponents.elementIterator("Enum"); - while (enumIterator != null && enumIterator.hasNext()) { - Element enumNode = (Element) enumIterator.next(); - - EnumComponent component = new EnumComponent(); - EnumDeserializer ed = new EnumDeserializer(component); - ed.deserialize(enumNode); - classDiagram.addComponent(component); + Iterator nodeIterator = classDiagramComponents.elementIterator(); + while (nodeIterator != null && nodeIterator.hasNext()) { + Element componentNode = nodeIterator.next(); + String name = componentNode.getName(); + if (name == null) + continue; + if (name.equals("Class")) { + ClassComponent component = new ClassComponent(); + ClassDeserializer cd = new ClassDeserializer(component); + cd.deserialize(componentNode); + classDiagram.addComponent(component); + } + else if (name.equals("Interface")) { + InterfaceComponent component = new InterfaceComponent(); + InterfaceDeserializer id = new InterfaceDeserializer(component); + id.deserialize(componentNode); + classDiagram.addComponent(component); + } + else if (name.equals("Enum")) { + EnumComponent component = new EnumComponent(); + EnumDeserializer ed = new EnumDeserializer(component); + ed.deserialize(componentNode); + classDiagram.addComponent(component); + } + else if (name.equals("Package")) { + PackageComponent component = new PackageComponent(); + PackageDeserializer ed = new PackageDeserializer(component); + ed.deserialize(componentNode); + classDiagram.addComponent(component); + } + else { + System.err.println("Unsupported node "+name); + } + } + classDiagram.updateComponentPackages(); ArrayList components = new ArrayList<>(classDiagram.getComponents()); Element classDiagramRelations = node.element("ClassDiagramRelations"); diff --git a/UMLVisual/src/org/uml/xmlDeserialization/components/ClassDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/components/ClassDeserializer.java index c12bbe2..973c51b 100644 --- a/UMLVisual/src/org/uml/xmlDeserialization/components/ClassDeserializer.java +++ b/UMLVisual/src/org/uml/xmlDeserialization/components/ClassDeserializer.java @@ -4,8 +4,10 @@ import org.uml.xmlDeserialization.members.FieldDeserializer; import org.uml.xmlDeserialization.members.MethodDeserializer; import java.awt.Point; +import java.awt.Rectangle; import java.util.Iterator; import org.dom4j.Element; +import org.uml.model.GenerationSetting; import org.uml.model.components.ClassComponent; import org.uml.model.members.Constructor; import org.uml.model.members.Field; @@ -40,20 +42,11 @@ public void deserialize(Element node) { String isAbstract = node.attributeValue("isAbstract"); String isStatic = node.attributeValue("isStatic"); String isFinal = node.attributeValue("isFinal"); + String generation = node.attributeValue("generation"); + String gettersGeneration = node.attributeValue("gettersGeneration"); + String settersGeneration = node.attributeValue("settersGeneration"); int xPos = (int) Double.parseDouble(node.attributeValue("xPosition")); int yPos = (int) Double.parseDouble(node.attributeValue("yPosition")); -// String widthString = node.attributeValue("width"); -// String heightString = node.attributeValue("height"); -// String xOffString = node.attributeValue("xOff"); -// String yOffString = node.attributeValue("yOff"); - -// if (widthString != null) { -// int width = Integer.parseInt(widthString); -// int height = Integer.parseInt(heightString); -// int xOff = Integer.parseInt(xOffString); -// int yOff = Integer.parseInt(yOffString); -// classComponent.setBounds(new Rectangle(xOff, yOff, width, height)); -// } if (name != null) classComponent.setName(name); if (packageName != null) classComponent.setParentPackage(packageName); @@ -61,8 +54,19 @@ public void deserialize(Element node) { if (isAbstract != null) classComponent.setAbstract(Boolean.parseBoolean(isAbstract)); if (isStatic != null) classComponent.setStatic(Boolean.parseBoolean(isStatic)); if (isFinal != null) classComponent.setFinal(Boolean.parseBoolean(isFinal)); - classComponent.setLocation(new Point(xPos, yPos)); - + if (generation != null) classComponent.setGeneration(GenerationSetting.stringToGenerationSetting(generation)); + if (gettersGeneration != null) classComponent.setGetterGeneration(GenerationSetting.stringToGenerationSetting(gettersGeneration)); + if (settersGeneration != null) classComponent.setSetterGeneration(GenerationSetting.stringToGenerationSetting(settersGeneration)); + + int width = 0; + int height = 0; + if (node.attribute("width") != null && node.attribute("height") != null) { + width = (int) Double.parseDouble(node.attributeValue("width")); + height = (int) Double.parseDouble(node.attributeValue("height")); + } + Rectangle bounds = new Rectangle(xPos,yPos,width,height); + classComponent.setBounds(bounds); + Iterator fieldIterator = node.element("Fields").elementIterator("Field"); while (fieldIterator != null && fieldIterator.hasNext()) { Element fieldElement = (Element) fieldIterator.next(); diff --git a/UMLVisual/src/org/uml/xmlDeserialization/components/EnumDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/components/EnumDeserializer.java index 55228a6..26feaad 100644 --- a/UMLVisual/src/org/uml/xmlDeserialization/components/EnumDeserializer.java +++ b/UMLVisual/src/org/uml/xmlDeserialization/components/EnumDeserializer.java @@ -2,8 +2,10 @@ import org.uml.xmlDeserialization.members.LiteralDeserializer; import java.awt.Point; +import java.awt.Rectangle; import java.util.Iterator; import org.dom4j.Element; +import org.uml.model.GenerationSetting; import org.uml.model.components.EnumComponent; import org.uml.model.members.Literal; import org.uml.model.Visibility; @@ -33,14 +35,24 @@ public void deserialize(Element node) { String name = node.attributeValue("name"); String packageName = node.attributeValue("package"); String visibility = node.attributeValue("visibility"); + String generation = node.attributeValue("generation"); int xPos = (int) Double.parseDouble(node.attributeValue("xPosition")); int yPos = (int) Double.parseDouble(node.attributeValue("yPosition")); if (name != null) enumComponent.setName(name); if (packageName != null) enumComponent.setParentPackage(packageName); if (visibility != null) enumComponent.setVisibility(Visibility.valueOf(visibility.toUpperCase())); - enumComponent.setLocation(new Point(xPos, yPos)); - + if (generation != null) enumComponent.setGeneration(GenerationSetting.stringToGenerationSetting(generation)); + //enumComponent.setLocation(new Point(xPos, yPos)); + int width = 0; + int height = 0; + if (node.attribute("width") != null && node.attribute("height") != null) { + width = (int) Double.parseDouble(node.attributeValue("width")); + height = (int) Double.parseDouble(node.attributeValue("height")); + } + Rectangle bounds = new Rectangle(xPos,yPos,width,height); + enumComponent.setBounds(bounds); + Iterator literalIterator = node.element("Literals").elementIterator("Literal"); while (literalIterator != null && literalIterator.hasNext()) { Element literalElement = (Element) literalIterator.next(); diff --git a/UMLVisual/src/org/uml/xmlDeserialization/components/InterfaceDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/components/InterfaceDeserializer.java index d4ca33a..d9a952a 100644 --- a/UMLVisual/src/org/uml/xmlDeserialization/components/InterfaceDeserializer.java +++ b/UMLVisual/src/org/uml/xmlDeserialization/components/InterfaceDeserializer.java @@ -2,8 +2,10 @@ import org.uml.xmlDeserialization.members.MethodDeserializer; import java.awt.Point; +import java.awt.Rectangle; import java.util.Iterator; import org.dom4j.Element; +import org.uml.model.GenerationSetting; import org.uml.model.components.InterfaceComponent; import org.uml.model.Visibility; import org.uml.model.members.Method; @@ -34,7 +36,7 @@ public void deserialize(Element node) { String packageName = node.attributeValue("package"); String visibility = node.attributeValue("visibility"); String isStatic = node.attributeValue("isStatic"); - + String generation = node.attributeValue("generation"); int xPos = (int) Double.parseDouble(node.attributeValue("xPosition")); int yPos = (int) Double.parseDouble(node.attributeValue("yPosition")); @@ -42,8 +44,17 @@ public void deserialize(Element node) { if (packageName != null) interfaceComponent.setParentPackage(packageName); if (visibility != null) interfaceComponent.setVisibility(Visibility.valueOf(visibility.toUpperCase())); if (isStatic != null) interfaceComponent.setStatic(Boolean.parseBoolean(isStatic)); - interfaceComponent.setLocation(new Point(xPos, yPos)); - + if (generation != null) interfaceComponent.setGeneration(GenerationSetting.stringToGenerationSetting(generation)); + //interfaceComponent.setLocation(new Point(xPos, yPos)); + int width = 0; + int height = 0; + if (node.attribute("width") != null && node.attribute("height") != null) { + width = (int) Double.parseDouble(node.attributeValue("width")); + height = (int) Double.parseDouble(node.attributeValue("height")); + } + Rectangle bounds = new Rectangle(xPos,yPos,width,height); + interfaceComponent.setBounds(bounds); + Iterator methodIterator = node.element("Methods").elementIterator("Method"); while (methodIterator != null && methodIterator.hasNext()) { Element methodElement = (Element) methodIterator.next(); diff --git a/UMLVisual/src/org/uml/xmlDeserialization/components/PackageDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/components/PackageDeserializer.java new file mode 100644 index 0000000..974a44c --- /dev/null +++ b/UMLVisual/src/org/uml/xmlDeserialization/components/PackageDeserializer.java @@ -0,0 +1,53 @@ +package org.uml.xmlDeserialization.components; + +import java.awt.Point; +import java.awt.Rectangle; +import org.dom4j.Element; +import org.uml.model.GenerationSetting; +import org.uml.model.Visibility; +import org.uml.model.components.PackageComponent; +import org.uml.xmlDeserialization.XmlDeserializer; + +/** + * + * @author stefanpetrovic + */ +public class PackageDeserializer implements XmlDeserializer { + + private PackageComponent packageComponent; + + public PackageDeserializer(PackageComponent packageComponent) { + this.packageComponent = packageComponent; + } + + /** + * Fills in attributes of packageComponent object by reading attributes and + * sub-nodes of the node input element. + * + * @param node is XML tree node whose attributes and sub-nodes represent + * attributes of the packageComponent. + */ + @Override + public void deserialize(Element node) { + String name = node.attributeValue("name"); + String packageName = node.attributeValue("package"); + String visibility = node.attributeValue("visibility"); + String generation = node.attributeValue("generation"); + int xPos = (int) Double.parseDouble(node.attributeValue("xPosition")); + int yPos = (int) Double.parseDouble(node.attributeValue("yPosition")); + + if (name != null) packageComponent.setName(name); + if (packageName != null) packageComponent.setParentPackage(packageName); + if (visibility != null) packageComponent.setVisibility(Visibility.valueOf(visibility.toUpperCase())); + if (generation != null) packageComponent.setGeneration(GenerationSetting.stringToGenerationSetting(generation)); + //packageComponent.setLocation(new Point(xPos, yPos)); + int width = 0; + int height = 0; + if (node.attribute("width") != null && node.attribute("height") != null) { + width = (int) Double.parseDouble(node.attributeValue("width")); + height = (int) Double.parseDouble(node.attributeValue("height")); + } + Rectangle bounds = new Rectangle(xPos,yPos,width,height); + packageComponent.setBounds(bounds); + } +} diff --git a/UMLVisual/src/org/uml/xmlDeserialization/members/FieldDeserializer.java b/UMLVisual/src/org/uml/xmlDeserialization/members/FieldDeserializer.java index 60e0710..a808948 100644 --- a/UMLVisual/src/org/uml/xmlDeserialization/members/FieldDeserializer.java +++ b/UMLVisual/src/org/uml/xmlDeserialization/members/FieldDeserializer.java @@ -1,6 +1,7 @@ package org.uml.xmlDeserialization.members; import org.dom4j.Element; +import org.uml.model.GenerationSetting; import org.uml.model.members.Field; import org.uml.model.Visibility; import org.uml.xmlDeserialization.XmlDeserializer; @@ -30,6 +31,8 @@ public void deserialize(Element node) { String isFinal = node.attributeValue("isFinal"); String isTransient = node.attributeValue("isTransient"); String isVolatile = node.attributeValue("isVolatile"); + String gettersGeneration = node.attributeValue("gettersGeneration"); + String settersGeneration = node.attributeValue("settersGeneration"); if (name != null) field.setName(name); if (visibility != null) field.setVisibility(Visibility.valueOf(visibility.toUpperCase())); if (type != null) field.setType(type); @@ -37,5 +40,7 @@ public void deserialize(Element node) { if (isFinal != null) field.setFinal(Boolean.parseBoolean(isFinal)); if (isTransient != null) field.setTransient(Boolean.parseBoolean(isTransient)); if (isVolatile != null) field.setTransient(Boolean.parseBoolean(isVolatile)); + if (gettersGeneration != null) field.setGetterGeneration(GenerationSetting.stringToGenerationSetting(gettersGeneration)); + if (settersGeneration != null) field.setSetterGeneration(GenerationSetting.stringToGenerationSetting(settersGeneration)); } } diff --git a/UMLVisual/src/org/uml/xmlSerialization/ClassDiagramSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/ClassDiagramSerializer.java index 34f3635..cea370d 100644 --- a/UMLVisual/src/org/uml/xmlSerialization/ClassDiagramSerializer.java +++ b/UMLVisual/src/org/uml/xmlSerialization/ClassDiagramSerializer.java @@ -1,5 +1,6 @@ package org.uml.xmlSerialization; +import java.awt.Rectangle; import org.uml.xmlSerialization.components.ComponentSerializer; import org.uml.xmlSerialization.relations.HasRelationSerializer; import org.uml.xmlSerialization.relations.IsRelationSerializer; @@ -11,7 +12,6 @@ import org.uml.xmlSerialization.components.InterfaceSerializer; import java.util.HashMap; import org.dom4j.Element; -import org.netbeans.api.visual.widget.Widget; import org.uml.model.components.ClassComponent; import org.uml.model.ClassDiagram; import org.uml.model.components.ComponentBase; @@ -19,6 +19,7 @@ import org.uml.model.relations.HasBaseRelation; import org.uml.model.relations.ImplementsRelation; import org.uml.model.components.InterfaceComponent; +import org.uml.model.components.PackageComponent; import org.uml.model.relations.AggregationRelation; import org.uml.model.relations.CompositionRelation; import org.uml.model.relations.HasRelation; @@ -26,6 +27,7 @@ import org.uml.model.relations.RelationBase; import org.uml.model.relations.UseRelation; import org.uml.visual.widgets.ClassDiagramScene; +import org.uml.xmlSerialization.components.PackageSerializer; //import org.uml.xmltesting.serialization.ClassDiagramXmlSerializerDeserializer; /** @@ -45,6 +47,7 @@ private ClassDiagramSerializer() { componentSerializers.put(ClassComponent.class, new ClassSerializer()); componentSerializers.put(InterfaceComponent.class, new InterfaceSerializer()); componentSerializers.put(EnumComponent.class, new EnumSerializer()); + componentSerializers.put(PackageComponent.class, new PackageSerializer()); relationSerializers.put(IsRelation.class, new IsRelationSerializer()); relationSerializers.put(ImplementsRelation.class, new ImplementsRelationSerializer()); relationSerializers.put(HasRelation.class, new HasRelationSerializer()); @@ -76,23 +79,25 @@ public void serialize(Element node) { if (classDiagram.getName() != null) { node.addAttribute("name", classDiagram.getName()); } + if (classDiagram.getGetterGeneration() != null) node.addAttribute("gettersGeneration", classDiagram.getGetterGeneration().toString()); + if (classDiagram.getSetterGeneration()!= null) node.addAttribute("settersGeneration", classDiagram.getSetterGeneration().toString()); + node.addAttribute("showMembers", classDiagram.isShowMembers()?"true":"false"); + node.addAttribute("showAddMember", classDiagram.isShowAddMember()?"true":"false"); + // node.addAttribute("showIcons", Boolean.toString(classDiagramScene.isShowIcons())); // node.addAttribute("showMembers", Boolean.toString(classDiagramScene.isShowMembers())); // node.addAttribute("showSimpleTypeNames", Boolean.toString(classDiagramScene.isShowSimpleTypes())); Element classDiagramComponents = node.addElement("ClassDiagramComponents"); for (ComponentBase component : classDiagram.getComponents()) { Element componentNode = classDiagramComponents.addElement(component.getClass().getSimpleName().replace("Component", "")); - Widget w = classDiagramScene.findWidget(component); -// componentNode.addAttribute("width", String.valueOf(w.getBounds().width)); -// componentNode.addAttribute("height", String.valueOf(w.getBounds().height)); -// componentNode.addAttribute("xOff", String.valueOf(w.getBounds().x)); -// componentNode.addAttribute("yOff", String.valueOf(w.getBounds().y)); - ComponentSerializer serializer = componentSerializers.get(component.getClass()); serializer.setClassDiagramComponent(component); serializer.serialize(componentNode); - componentNode.addAttribute("xPosition", String.valueOf(w.getPreferredLocation().getX())); - componentNode.addAttribute("yPosition", String.valueOf(w.getPreferredLocation().getY())); + Rectangle bounds = component.getBounds(); + componentNode.addAttribute("xPosition", String.valueOf(bounds.getX())); + componentNode.addAttribute("yPosition", String.valueOf(bounds.getY())); + componentNode.addAttribute("width", String.valueOf(bounds.getSize().width)); + componentNode.addAttribute("height", String.valueOf(bounds.getSize().height)); } Element classDiagramRelations = node.addElement("ClassDiagramRelations"); diff --git a/UMLVisual/src/org/uml/xmlSerialization/components/ClassSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/components/ClassSerializer.java index 6162447..170fee5 100644 --- a/UMLVisual/src/org/uml/xmlSerialization/components/ClassSerializer.java +++ b/UMLVisual/src/org/uml/xmlSerialization/components/ClassSerializer.java @@ -2,6 +2,7 @@ import org.dom4j.Element; import org.openide.util.Exceptions; +import org.uml.model.GenerationSetting; import org.uml.model.components.ClassComponent; import org.uml.model.components.ComponentBase; import org.uml.xmlSerialization.members.ConstructorSerializer; @@ -45,6 +46,9 @@ public void serialize(Element node) { if (classComponent.isAbstract()) node.addAttribute("isAbstract", Boolean.toString(classComponent.isAbstract())); if (classComponent.isStatic()) node.addAttribute("isStatic", Boolean.toString(classComponent.isStatic())); if (classComponent.isFinal()) node.addAttribute("isFinal", Boolean.toString(classComponent.isFinal())); + if (classComponent.getGetterGeneration() != null) node.addAttribute("gettersGeneration", classComponent.getGetterGeneration().toString()); + if (classComponent.getSetterGeneration()!= null) node.addAttribute("settersGeneration", classComponent.getSetterGeneration().toString()); + if (classComponent.getGeneration()!= null) node.addAttribute("generation", classComponent.getGeneration().toString()); Element fields = node.addElement("Fields"); XmlSerializer serializer = new FieldSerializer(classComponent.getFields()); diff --git a/UMLVisual/src/org/uml/xmlSerialization/components/EnumSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/components/EnumSerializer.java index 8497b8e..ea633de 100644 --- a/UMLVisual/src/org/uml/xmlSerialization/components/EnumSerializer.java +++ b/UMLVisual/src/org/uml/xmlSerialization/components/EnumSerializer.java @@ -39,6 +39,7 @@ public void serialize(Element node) { if (enumComponent.getName() != null) node.addAttribute("name", enumComponent.getName()); if (enumComponent.getParentPackage() != null) node.addAttribute("package", enumComponent.getParentPackage()); if (enumComponent.getVisibility() != null) node.addAttribute("visibility", enumComponent.getVisibility().name().toLowerCase()); + if (enumComponent.getGeneration()!= null) node.addAttribute("generation", enumComponent.getGeneration().toString()); Element literals = node.addElement("Literals"); XmlSerializer serializer = new LiteralSerializer(enumComponent.getLiterals()); diff --git a/UMLVisual/src/org/uml/xmlSerialization/components/InterfaceSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/components/InterfaceSerializer.java index f7fda4f..acb60e5 100644 --- a/UMLVisual/src/org/uml/xmlSerialization/components/InterfaceSerializer.java +++ b/UMLVisual/src/org/uml/xmlSerialization/components/InterfaceSerializer.java @@ -40,6 +40,7 @@ public void serialize(Element node) { if (interfaceComponent.getParentPackage() != null) node.addAttribute("package", interfaceComponent.getParentPackage()); if (interfaceComponent.getVisibility() != null) node.addAttribute("visibility", interfaceComponent.getVisibility().name().toLowerCase()); if (interfaceComponent.isStatic()) node.addAttribute("isStatic", Boolean.toString(interfaceComponent.isStatic())); + if (interfaceComponent.getGeneration()!= null) node.addAttribute("generation", interfaceComponent.getGeneration().toString()); Element methods = node.addElement("Methods"); XmlSerializer serializer = new MethodSerializer(interfaceComponent.getMethods()); diff --git a/UMLVisual/src/org/uml/xmlSerialization/components/PackageSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/components/PackageSerializer.java new file mode 100644 index 0000000..59949f7 --- /dev/null +++ b/UMLVisual/src/org/uml/xmlSerialization/components/PackageSerializer.java @@ -0,0 +1,42 @@ +package org.uml.xmlSerialization.components; + +import org.dom4j.Element; +import org.uml.model.components.ComponentBase; +import org.uml.model.components.PackageComponent; + +/** + * + * @author Stefan + */ +public class PackageSerializer implements ComponentSerializer { + + private PackageComponent packageComponent; + + /** + * Sets the packageComponent object that is going to be serialized. + * + * @param component represents enumComponent object to be serialized. + */ + @Override + public void setClassDiagramComponent(ComponentBase component) { + try { + packageComponent = (PackageComponent) component; + } catch (ClassCastException e) { + System.out.println("You have tried to cast invalid type to PackageComponent!"); + e.printStackTrace(); + } + } + + /** + * Serializes - object to XML by translating its fields into parameter node's attributes and subelements. + * + * @param node represents the node that will contain serialized - object. + */ + @Override + public void serialize(Element node) { + if (packageComponent.getName() != null) node.addAttribute("name", packageComponent.getName()); + if (packageComponent.getParentPackage() != null) node.addAttribute("package", packageComponent.getParentPackage()); + if (packageComponent.getVisibility() != null) node.addAttribute("visibility", packageComponent.getVisibility().name().toLowerCase()); + if (packageComponent.getGeneration()!= null) node.addAttribute("generation", packageComponent.getGeneration().toString()); + } +} diff --git a/UMLVisual/src/org/uml/xmlSerialization/members/FieldSerializer.java b/UMLVisual/src/org/uml/xmlSerialization/members/FieldSerializer.java index 0ad0fea..4cefa9d 100644 --- a/UMLVisual/src/org/uml/xmlSerialization/members/FieldSerializer.java +++ b/UMLVisual/src/org/uml/xmlSerialization/members/FieldSerializer.java @@ -35,6 +35,8 @@ public void serialize(Element node) { if (field.isFinal()) fieldNode.addAttribute("isFinal", Boolean.toString(field.isFinal())); if (field.isTransient()) fieldNode.addAttribute("isTransient", Boolean.toString(field.isTransient())); if (field.isVolatile()) fieldNode.addAttribute("isVolatile", Boolean.toString(field.isVolatile())); + if (field.getGetterGeneration() != null) fieldNode.addAttribute("gettersGeneration", field.getGetterGeneration().toString()); + if (field.getSetterGeneration()!= null) fieldNode.addAttribute("settersGeneration", field.getSetterGeneration().toString()); } } } diff --git a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties index cfbcce6..45df794 100644 --- a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties +++ b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties @@ -1,2 +1,4 @@ -currentVersion=UML {0} -LBL_splash_window_title=Starting UML +currentVersion=NetbeansEasyUML {0} +LBL_splash_window_title=Starting NetbeansEasyUML +SplashProgressBarBounds=0,249,473,3 +SplashRunningTextBounds=10,235,450,12 diff --git a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties index 48bba88..059cbec 100644 --- a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties +++ b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -1,2 +1,2 @@ -CTL_MainWindow_Title=UML {0} -CTL_MainWindow_Title_No_Project=UML {0} +CTL_MainWindow_Title=NetbeansEasyUML {0} +CTL_MainWindow_Title_No_Project=NetbeansEasyUML {0} diff --git a/dom4j/manifest.mf b/dom4j/manifest.mf index ca53eaf..7a69985 100644 --- a/dom4j/manifest.mf +++ b/dom4j/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.dom4j OpenIDE-Module-Localizing-Bundle: org/uml/dom4j/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/dom4j/nbproject/project.properties b/dom4j/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/dom4j/nbproject/project.properties +++ b/dom4j/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/easyUML/manifest.mf b/easyUML/manifest.mf index c53c72e..ce7d7c3 100644 --- a/easyUML/manifest.mf +++ b/easyUML/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: true OpenIDE-Module: easyuml OpenIDE-Module-Localizing-Bundle: easyuml/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/easyUML/nbproject/project.properties b/easyUML/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/easyUML/nbproject/project.properties +++ b/easyUML/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index c17d530..43fcf7b 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,11 +1,11 @@ -build.xml.data.CRC32=8cce6767 -build.xml.script.CRC32=677d5075 -build.xml.stylesheet.CRC32=eaf9f76a@2.67.1 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=8cce6767 -nbproject/build-impl.xml.script.CRC32=522b19cc -nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.67.1 -nbproject/platform.xml.data.CRC32=8cce6767 -nbproject/platform.xml.script.CRC32=6dcbd131 -nbproject/platform.xml.stylesheet.CRC32=4e1f53d4@2.67.1 +build.xml.data.CRC32=8cce6767 +build.xml.script.CRC32=677d5075 +build.xml.stylesheet.CRC32=eaf9f76a@2.67.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=8cce6767 +nbproject/build-impl.xml.script.CRC32=522b19cc +nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.67.1 +nbproject/platform.xml.data.CRC32=8cce6767 +nbproject/platform.xml.script.CRC32=6dcbd131 +nbproject/platform.xml.stylesheet.CRC32=45ddf0e0@2.72.1 diff --git a/nbproject/platform.properties b/nbproject/platform.properties index e77a2a5..42b98a9 100644 --- a/nbproject/platform.properties +++ b/nbproject/platform.properties @@ -1,153 +1,130 @@ -branding.token=nbuml -cluster.path=\ - ${nbplatform.active.dir}/apisupport:\ - ${nbplatform.active.dir}/extide:\ - ${nbplatform.active.dir}/harness:\ - ${nbplatform.active.dir}/ide:\ - ${nbplatform.active.dir}/java:\ - ${nbplatform.active.dir}/platform -disabled.modules=\ - org.apache.commons.httpclient,\ - org.apache.commons.lang,\ - org.apache.ws.commons.util,\ - org.apache.xmlrpc,\ - org.eclipse.core.net,\ - org.eclipse.equinox.security,\ - org.eclipse.jgit,\ - org.eclipse.jgit.java7,\ - org.eclipse.mylyn.bugzilla.core,\ - org.eclipse.mylyn.commons.core,\ - org.eclipse.mylyn.commons.net,\ - org.eclipse.mylyn.commons.repositories.core,\ - org.eclipse.mylyn.commons.xmlrpc,\ - org.eclipse.mylyn.tasks.core,\ - org.eclipse.mylyn.wikitext.confluence.core,\ - org.eclipse.mylyn.wikitext.core,\ - org.eclipse.mylyn.wikitext.textile.core,\ - org.netbeans.api.maven,\ - org.netbeans.core.browser,\ - org.netbeans.core.browser.webview,\ - org.netbeans.core.network,\ - org.netbeans.core.osgi,\ - org.netbeans.libs.commons_net,\ - org.netbeans.libs.git,\ - org.netbeans.libs.ini4j,\ - org.netbeans.libs.javafx,\ - org.netbeans.libs.jsch.agentproxy,\ - org.netbeans.libs.jsr223,\ - org.netbeans.libs.smack,\ - org.netbeans.libs.springframework,\ - org.netbeans.libs.svnClientAdapter,\ - org.netbeans.libs.svnClientAdapter.javahl,\ - org.netbeans.libs.svnClientAdapter.svnkit,\ - org.netbeans.libs.testng,\ - org.netbeans.modules.apisupport.crudsample,\ - org.netbeans.modules.apisupport.feedreader,\ - org.netbeans.modules.apisupport.installer,\ - org.netbeans.modules.apisupport.installer.maven,\ - org.netbeans.modules.apisupport.kit,\ - org.netbeans.modules.apisupport.paintapp,\ - org.netbeans.modules.applemenu,\ - org.netbeans.modules.bugtracking,\ - org.netbeans.modules.bugtracking.bridge,\ - org.netbeans.modules.bugtracking.commons,\ - org.netbeans.modules.bugzilla,\ - org.netbeans.modules.css.prep,\ - org.netbeans.modules.db,\ - org.netbeans.modules.db.core,\ - org.netbeans.modules.db.dataview,\ - org.netbeans.modules.db.drivers,\ - org.netbeans.modules.db.kit,\ - org.netbeans.modules.db.metadata.model,\ - org.netbeans.modules.db.mysql,\ - org.netbeans.modules.db.sql.editor,\ - org.netbeans.modules.db.sql.visualeditor,\ - org.netbeans.modules.dbapi,\ - org.netbeans.modules.dbschema,\ - org.netbeans.modules.debugger.jpda,\ - org.netbeans.modules.debugger.jpda.js,\ - org.netbeans.modules.debugger.jpda.jsui,\ - org.netbeans.modules.debugger.jpda.kit,\ - org.netbeans.modules.debugger.jpda.projects,\ - org.netbeans.modules.debugger.jpda.ui,\ - org.netbeans.modules.debugger.jpda.visual,\ - org.netbeans.modules.derby,\ - org.netbeans.modules.extexecution.impl,\ - org.netbeans.modules.form.j2ee,\ - org.netbeans.modules.git,\ - org.netbeans.modules.hibernate,\ - org.netbeans.modules.hibernate4lib,\ - org.netbeans.modules.html.custom,\ - org.netbeans.modules.hudson,\ - org.netbeans.modules.hudson.ant,\ - org.netbeans.modules.hudson.git,\ - org.netbeans.modules.hudson.maven,\ - org.netbeans.modules.hudson.mercurial,\ - org.netbeans.modules.hudson.subversion,\ - org.netbeans.modules.hudson.tasklist,\ - org.netbeans.modules.hudson.ui,\ - org.netbeans.modules.j2ee.core.utilities,\ - org.netbeans.modules.j2ee.eclipselink,\ - org.netbeans.modules.j2ee.eclipselinkmodelgen,\ - org.netbeans.modules.j2ee.jpa.refactoring,\ - org.netbeans.modules.j2ee.jpa.verification,\ - org.netbeans.modules.j2ee.persistence,\ - org.netbeans.modules.j2ee.persistence.kit,\ - org.netbeans.modules.java.hints.declarative.test,\ - org.netbeans.modules.java.hints.test,\ - org.netbeans.modules.javaee.injection,\ - org.netbeans.modules.javascript2.debug,\ - org.netbeans.modules.javascript2.debug.ui,\ - org.netbeans.modules.jellytools.ide,\ - org.netbeans.modules.jellytools.java,\ - org.netbeans.modules.jellytools.platform,\ - org.netbeans.modules.jemmy,\ - org.netbeans.modules.keyring.fallback,\ - org.netbeans.modules.keyring.impl,\ - org.netbeans.modules.languages,\ - org.netbeans.modules.localhistory,\ - org.netbeans.modules.localtasks,\ - org.netbeans.modules.masterfs.linux,\ - org.netbeans.modules.masterfs.macosx,\ - org.netbeans.modules.masterfs.nio2,\ - org.netbeans.modules.maven.hints,\ - org.netbeans.modules.maven.junit,\ - org.netbeans.modules.maven.persistence,\ - org.netbeans.modules.maven.search,\ - org.netbeans.modules.maven.spring,\ - org.netbeans.modules.mercurial,\ - org.netbeans.modules.mylyn.util,\ - org.netbeans.modules.notifications,\ - org.netbeans.modules.performance,\ - org.netbeans.modules.performance.java,\ - org.netbeans.modules.progress.ui,\ - org.netbeans.modules.projectimport.eclipse.j2se,\ - org.netbeans.modules.schema2beans,\ - org.netbeans.modules.server,\ - org.netbeans.modules.spellchecker.bindings.htmlxml,\ - org.netbeans.modules.spring.beans,\ - org.netbeans.modules.subversion,\ - org.netbeans.modules.target.iterator,\ - org.netbeans.modules.team.commons,\ - org.netbeans.modules.team.ide,\ - org.netbeans.modules.testng,\ - org.netbeans.modules.testng.ant,\ - org.netbeans.modules.testng.maven,\ - org.netbeans.modules.uihandler,\ - org.netbeans.modules.versioning,\ - org.netbeans.modules.versioning.core,\ - org.netbeans.modules.versioning.indexingbridge,\ - org.netbeans.modules.versioning.masterfs,\ - org.netbeans.modules.versioning.system.cvss.installer,\ - org.netbeans.modules.versioning.ui,\ - org.netbeans.modules.versioning.util,\ - org.netbeans.modules.web.webkit.debugging,\ - org.netbeans.modules.websvc.saas.codegen.java,\ - org.netbeans.modules.xml.multiview,\ - org.netbeans.modules.xml.wsdl.model,\ - org.openide.compat,\ - org.openide.options,\ - org.openide.util.enumerations,\ - org.openidex.util -nbjdk.active=default -nbplatform.active=default +branding.token=nbuml +cluster.path=\ + ${nbplatform.active.dir}/apisupport:\ + ${nbplatform.active.dir}/extide:\ + ${nbplatform.active.dir}/harness:\ + ${nbplatform.active.dir}/ide:\ + ${nbplatform.active.dir}/java:\ + ${nbplatform.active.dir}/platform +disabled.modules=\ + org.apache.commons.httpclient,\ + org.apache.commons.lang,\ + org.apache.ws.commons.util,\ + org.apache.xmlrpc,\ + org.eclipse.core.net,\ + org.eclipse.equinox.security,\ + org.eclipse.jgit.java7,\ + org.eclipse.mylyn.bugzilla.core,\ + org.eclipse.mylyn.commons.core,\ + org.eclipse.mylyn.commons.net,\ + org.eclipse.mylyn.commons.repositories.core,\ + org.eclipse.mylyn.commons.xmlrpc,\ + org.eclipse.mylyn.tasks.core,\ + org.eclipse.mylyn.wikitext.confluence.core,\ + org.eclipse.mylyn.wikitext.core,\ + org.eclipse.mylyn.wikitext.textile.core,\ + org.netbeans.api.maven,\ + org.netbeans.core.browser,\ + org.netbeans.core.browser.webview,\ + org.netbeans.core.network,\ + org.netbeans.core.osgi,\ + org.netbeans.libs.commons_net,\ + org.netbeans.libs.ini4j,\ + org.netbeans.libs.javafx,\ + org.netbeans.libs.jsr223,\ + org.netbeans.libs.smack,\ + org.netbeans.libs.springframework,\ + org.netbeans.libs.svnClientAdapter,\ + org.netbeans.libs.svnClientAdapter.javahl,\ + org.netbeans.libs.svnClientAdapter.svnkit,\ + org.netbeans.libs.testng,\ + org.netbeans.modules.apisupport.crudsample,\ + org.netbeans.modules.apisupport.feedreader,\ + org.netbeans.modules.apisupport.installer,\ + org.netbeans.modules.apisupport.installer.maven,\ + org.netbeans.modules.apisupport.kit,\ + org.netbeans.modules.apisupport.paintapp,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.bugtracking,\ + org.netbeans.modules.bugtracking.bridge,\ + org.netbeans.modules.bugtracking.commons,\ + org.netbeans.modules.bugzilla,\ + org.netbeans.modules.css.prep,\ + org.netbeans.modules.db,\ + org.netbeans.modules.db.core,\ + org.netbeans.modules.db.dataview,\ + org.netbeans.modules.db.drivers,\ + org.netbeans.modules.db.kit,\ + org.netbeans.modules.db.metadata.model,\ + org.netbeans.modules.db.mysql,\ + org.netbeans.modules.db.sql.editor,\ + org.netbeans.modules.db.sql.visualeditor,\ + org.netbeans.modules.dbapi,\ + org.netbeans.modules.dbschema,\ + org.netbeans.modules.derby,\ + org.netbeans.modules.extexecution.impl,\ + org.netbeans.modules.form.j2ee,\ + org.netbeans.modules.hibernate,\ + org.netbeans.modules.hibernate4lib,\ + org.netbeans.modules.html.custom,\ + org.netbeans.modules.hudson,\ + org.netbeans.modules.hudson.ant,\ + org.netbeans.modules.hudson.git,\ + org.netbeans.modules.hudson.maven,\ + org.netbeans.modules.hudson.mercurial,\ + org.netbeans.modules.hudson.subversion,\ + org.netbeans.modules.hudson.tasklist,\ + org.netbeans.modules.hudson.ui,\ + org.netbeans.modules.j2ee.core.utilities,\ + org.netbeans.modules.j2ee.eclipselink,\ + org.netbeans.modules.j2ee.eclipselinkmodelgen,\ + org.netbeans.modules.j2ee.jpa.refactoring,\ + org.netbeans.modules.j2ee.jpa.verification,\ + org.netbeans.modules.j2ee.persistence,\ + org.netbeans.modules.j2ee.persistence.kit,\ + org.netbeans.modules.java.hints.declarative.test,\ + org.netbeans.modules.java.hints.test,\ + org.netbeans.modules.javaee.injection,\ + org.netbeans.modules.jellytools.ide,\ + org.netbeans.modules.jellytools.java,\ + org.netbeans.modules.jellytools.platform,\ + org.netbeans.modules.jemmy,\ + org.netbeans.modules.keyring.fallback,\ + org.netbeans.modules.keyring.impl,\ + org.netbeans.modules.languages,\ + org.netbeans.modules.localtasks,\ + org.netbeans.modules.masterfs.linux,\ + org.netbeans.modules.masterfs.macosx,\ + org.netbeans.modules.masterfs.nio2,\ + org.netbeans.modules.maven.hints,\ + org.netbeans.modules.maven.junit,\ + org.netbeans.modules.maven.persistence,\ + org.netbeans.modules.maven.search,\ + org.netbeans.modules.maven.spring,\ + org.netbeans.modules.mercurial,\ + org.netbeans.modules.mylyn.util,\ + org.netbeans.modules.notifications,\ + org.netbeans.modules.performance,\ + org.netbeans.modules.performance.java,\ + org.netbeans.modules.progress.ui,\ + org.netbeans.modules.projectimport.eclipse.j2se,\ + org.netbeans.modules.schema2beans,\ + org.netbeans.modules.server,\ + org.netbeans.modules.spellchecker.bindings.htmlxml,\ + org.netbeans.modules.spring.beans,\ + org.netbeans.modules.subversion,\ + org.netbeans.modules.target.iterator,\ + org.netbeans.modules.testng,\ + org.netbeans.modules.testng.ant,\ + org.netbeans.modules.testng.maven,\ + org.netbeans.modules.uihandler,\ + org.netbeans.modules.web.webkit.debugging,\ + org.netbeans.modules.websvc.saas.codegen.java,\ + org.netbeans.modules.xml.multiview,\ + org.netbeans.modules.xml.wsdl.model,\ + org.openide.compat,\ + org.openide.options,\ + org.openide.util.enumerations,\ + org.openidex.util +nbjdk.active=default +nbplatform.active=default diff --git a/nbproject/project.properties b/nbproject/project.properties index 20f3b14..54de947 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,37 +1,38 @@ -app.name=${branding.token} -app.title=UML -auxiliary.org-netbeans-modules-apisupport-installer.license-type=no -auxiliary.org-netbeans-modules-apisupport-installer.os-linux=true -auxiliary.org-netbeans-modules-apisupport-installer.os-macosx=true -auxiliary.org-netbeans-modules-apisupport-installer.os-solaris=false -auxiliary.org-netbeans-modules-apisupport-installer.os-windows=true -auxiliary.org-netbeans-modules-apisupport-installer.pack200-enabled=false -auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml -modules=\ - ${project.org.uml.dom4j}:\ - ${project.easyuml}:\ - ${project.org.uml.explorer}:\ - ${project.org.uml.filetype}:\ - ${project.org.uml.model}:\ - ${project.org.uml.reveng}:\ - ${project.org.uml.visual}:\ - ${project.com.github.javaparser}:\ - ${project.org.uml.code}:\ - ${project.org.uml.project} -project.easyuml=easyUML -project.com.github.javaparser=JavaParser -project.org.uml.code=UMLCodeGenerator -project.org.uml.dom4j=dom4j -project.org.uml.explorer=UMLExplorer -project.org.uml.filetype=UMLFileTypes -project.org.uml.model=UMLModel -project.org.uml.project=UMLProjectType -project.org.uml.reveng=UMLReverseEngineering -project.org.uml.visual=UMLVisual -run.args.extra=-J-Xms512m -J-Xmx2048m -J-XX:MaxPermSize=128M --nosplash - -keystore.dname=CN=easyUML, OU=Faculty of Organisational Sciences Open Source Software Development Center, O=University of Belgrade, L=Belgrade, ST=Serbia, C=RS -keystore.location=nbproject/private/ -keystore.name=easyUMLkeystore -keystore.alias=easyUML -keystore.password=fon154 \ No newline at end of file +app.icon=branding/core/core.jar/org/netbeans/core/startup/frame48.gif +app.name=${branding.token} +app.title=NetbeansEasyUML +auxiliary.org-netbeans-modules-apisupport-installer.license-type=no +auxiliary.org-netbeans-modules-apisupport-installer.os-linux=true +auxiliary.org-netbeans-modules-apisupport-installer.os-macosx=true +auxiliary.org-netbeans-modules-apisupport-installer.os-solaris=false +auxiliary.org-netbeans-modules-apisupport-installer.os-windows=true +auxiliary.org-netbeans-modules-apisupport-installer.pack200-enabled=false +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +modules=\ + ${project.org.uml.dom4j}:\ + ${project.easyuml}:\ + ${project.org.uml.explorer}:\ + ${project.org.uml.filetype}:\ + ${project.org.uml.model}:\ + ${project.org.uml.reveng}:\ + ${project.org.uml.visual}:\ + ${project.com.github.javaparser}:\ + ${project.org.uml.code}:\ + ${project.org.uml.project} +project.easyuml=easyUML +project.com.github.javaparser=JavaParser +project.org.uml.code=UMLCodeGenerator +project.org.uml.dom4j=dom4j +project.org.uml.explorer=UMLExplorer +project.org.uml.filetype=UMLFileTypes +project.org.uml.model=UMLModel +project.org.uml.project=UMLProjectType +project.org.uml.reveng=UMLReverseEngineering +project.org.uml.visual=UMLVisual +run.args.extra=-J-Xms512m -J-Xmx2048m -J-XX:MaxPermSize=128M --nosplash + +keystore.dname=CN=easyUML, OU=Faculty of Organisational Sciences Open Source Software Development Center, O=University of Belgrade, L=Belgrade, ST=Serbia, C=RS +keystore.location=nbproject/private/ +keystore.name=easyUMLkeystore +keystore.alias=easyUML +keystore.password=fon154

+ * For example "ABC_DEF" becomes "abcDef" + */ + public static String screamingToCamelCase(String original) { + StringBuilder sb = new StringBuilder(); + String[] parts = original.toLowerCase().split("_"); + for (int i = 0; i < parts.length; i++) { + sb.append(i == 0 ? parts[i] : capitalize(parts[i])); + } + return sb.toString(); + } + + + /** + * @param input "aCamelCaseString" + * @return "A_CAMEL_CASE_STRING" + */ + public static String camelCaseToScreaming(String input) { + if (input.isEmpty()) { + return ""; + } + StringBuilder scream = new StringBuilder(input.substring(0, 1).toUpperCase()); + for (char c : input.substring(1).toCharArray()) { + if (Character.isUpperCase(c)) { + scream.append("_"); + } + scream.append(Character.toUpperCase(c)); + } + return scream.toString(); + } + + /** + * Return the next word of the string, in other words it stops when a space is encountered. + */ + public static String nextWord(String string) { + int index = 0; + while (index < string.length() && !Character.isWhitespace(string.charAt(index))) { + index++; + } + return string.substring(0, index); + } + + /** + * Make an indent by appending indentLevel tab characters to the builder. + */ + public static StringBuilder indent(StringBuilder builder, int indentLevel) { + for (int i = 0; i < indentLevel; i++) { + builder.append("\t"); + } + return builder; + } + + /** + * Capitalizes the first character in the string. + */ + public static String capitalize(String s) { + return stringTransformer(s, "capitalize", String::toUpperCase); + } + + /** + * Lower-cases the first character in the string. + */ + public static String decapitalize(String s) { + return stringTransformer(s, "decapitalize", String::toLowerCase); + } + + private static String stringTransformer(String s, String operationDescription, Function transformation) { + if (s.isEmpty()) { + throw new IllegalArgumentException(String.format("You cannot %s an empty string", operationDescription)); + } + return transformation.apply(s.substring(0, 1)) + + s.substring(1); + } + + /** + * @return true if the value is null, an empty Optional, or an empty String. + */ + public static boolean valueIsNullOrEmpty(Object value) { + if (value == null) { + return true; + } + if (value instanceof Optional) { + if (((Optional) value).isPresent()) { + value = ((Optional) value).get(); + } else { + return true; + } + } + if (value instanceof Collection) { + if (((Collection) value).isEmpty()) { + return true; + } + } + return false; + } + + /** + * @return a set of the items. + */ + public static Set set(T... items) { + return new HashSet<>(asList(items)); + } + + /** + * @return content with all kinds of EOL characters replaced by endOfLineCharacter + */ + public static String normalizeEolInTextBlock(String content, String endOfLineCharacter) { + return content + .replaceAll("\\R", endOfLineCharacter); + } + + /** + * @return the filename with the last "." and everything following it removed. + */ + public static String removeFileExtension(String filename) { + int extensionIndex = filename.lastIndexOf("."); + if (extensionIndex == -1) + return filename; + + return filename.substring(0, extensionIndex); + } + + /** + * Like {@link String#trim()}, but only the trailing spaces. + */ + public static String trimTrailingSpaces(String line) { + while (line.length() > 0 && line.charAt(line.length() - 1) <= 0x20) { + line = line.substring(0, line.length() - 1); + } + return line; + } + +} diff --git a/JavaParser/src/com/github/javaparser/utils/VisitorList.java b/JavaParser/src/com/github/javaparser/utils/VisitorList.java new file mode 100644 index 0000000..ea21787 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/VisitorList.java @@ -0,0 +1,303 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * A list that overrides the equals and hashcode calculation of the added nodes + * by using another equals and hashcode visitor for those methods. + */ +public class VisitorList implements List { + + protected List innerList; + protected final GenericVisitor hashcodeVisitor; + protected final GenericVisitor equalsVisitor; + + /** + * Pass the visitors to use for equals and hashcode. + */ + public VisitorList(GenericVisitor hashcodeVisitor, + GenericVisitor equalsVisitor) { + this.hashcodeVisitor = hashcodeVisitor; + this.equalsVisitor = equalsVisitor; + innerList = new ArrayList<>(); + } + + @Override + public boolean add(N elem) { + return innerList.add(new EqualsHashcodeOverridingFacade(elem)); + } + + @Override + public void add(int index, N elem) { + innerList.add(index, new EqualsHashcodeOverridingFacade(elem)); + } + + @Override + public boolean addAll(Collection col) { + boolean modified = false; + for (N elem : col) + if (add(elem)) + modified = true; + return modified; + } + + @Override + public boolean addAll(int index, Collection col) { + if (col.isEmpty()) + return false; + for (N elem : col) { + if (index == size()) + add(elem); + else + add(index, elem); + index++; + } + return true; + } + + @Override + public void clear() { + innerList.clear(); + } + + @Override + public boolean contains(Object elem) { + return innerList.contains(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public boolean containsAll(Collection col) { + for (Object elem : col) + if (!contains(elem)) + return false; + return true; + } + + @Override + public N get(int index) { + return innerList.get(index).overridden; + } + + @Override + public int indexOf(Object elem) { + return innerList.indexOf(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public boolean isEmpty() { + return innerList.isEmpty(); + } + + @Override + public Iterator iterator() { + return new Iterator() { + final Iterator itr = innerList.iterator(); + + @Override + public boolean hasNext() { + return itr.hasNext(); + } + + @Override + public N next() { + return itr.next().overridden; + } + + @Override + public void remove() { + itr.remove(); + } + }; + } + + @Override + public int lastIndexOf(Object elem) { + return innerList.lastIndexOf(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public ListIterator listIterator() { + return listIterator(0); + } + + @Override + public ListIterator listIterator(int index) { + return new ListIterator() { + final ListIterator itr = innerList.listIterator(index); + + @Override + public boolean hasNext() { + return itr.hasNext(); + } + + @Override + public N next() { + return itr.next().overridden; + } + + @Override + public void remove() { + itr.remove(); + } + + @Override + public void add(N elem) { + itr.add(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public boolean hasPrevious() { + return itr.hasPrevious(); + } + + @Override + public int nextIndex() { + return itr.nextIndex(); + } + + @Override + public N previous() { + return itr.previous().overridden; + } + + @Override + public int previousIndex() { + return itr.previousIndex(); + } + + @Override + public void set(N elem) { + itr.set(new EqualsHashcodeOverridingFacade((N) elem)); + } + }; + } + + @Override + public boolean remove(Object elem) { + return innerList.remove(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public N remove(int index) { + return innerList.remove(index).overridden; + } + + @Override + public boolean removeAll(Collection col) { + boolean modified = false; + for (Object elem : col) + if (remove(elem)) + modified = true; + return modified; + } + + @Override + public boolean retainAll(Collection col) { + int oldSize = size(); + clear(); + addAll((Collection) col); + return size() != oldSize; + } + + @Override + public N set(int index, N elem) { + return innerList.set(index, new EqualsHashcodeOverridingFacade((N) elem)).overridden; + } + + @Override + public int size() { + return innerList.size(); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return new VisitorList(hashcodeVisitor, equalsVisitor) { + { + this.innerList = VisitorList.this.innerList.subList(fromIndex, toIndex); + } + }; + } + + @Override + public Object[] toArray() { + return innerList.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(); + } + + @Override + public T[] toArray(T[] arr) { + return innerList.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(arr); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("["); + if (size() == 0) + return sb.append("]").toString(); + for (EqualsHashcodeOverridingFacade facade : innerList) { + sb.append(facade.overridden.toString() + ", "); + } + return sb.replace(sb.length() - 2, sb.length(), "]").toString(); + } + + private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; + + EqualsHashcodeOverridingFacade(N overridden) { + this.overridden = overridden; + } + + @Override + public R accept(GenericVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public void accept(VoidVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public final int hashCode() { + return overridden.accept(hashcodeVisitor, null); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof VisitorList.EqualsHashcodeOverridingFacade)) { + return false; + } + return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); + } + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/VisitorMap.java b/JavaParser/src/com/github/javaparser/utils/VisitorMap.java new file mode 100644 index 0000000..ab21b91 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/VisitorMap.java @@ -0,0 +1,125 @@ +package com.github.javaparser.utils; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A map that overrides the equals and hashcode calculation of the added nodes + * by using another equals and hashcode visitor for those methods. + */ +public class VisitorMap implements Map { + private final Map innerMap = new HashMap<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; + + /** + * Pass the visitors to use for equals and hashcode. + */ + public VisitorMap(GenericVisitor hashcodeVisitor, GenericVisitor equalsVisitor) { + this.hashcodeVisitor = hashcodeVisitor; + this.equalsVisitor = equalsVisitor; + } + + @Override + public int size() { + return innerMap.size(); + } + + @Override + public boolean isEmpty() { + return innerMap.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return innerMap.containsKey(new EqualsHashcodeOverridingFacade((N) key)); + } + + @Override + public boolean containsValue(Object value) { + return innerMap.containsValue(value); + } + + @Override + public V get(Object key) { + return innerMap.get(new EqualsHashcodeOverridingFacade((N) key)); + } + + @Override + public V put(N key, V value) { + return innerMap.put(new EqualsHashcodeOverridingFacade(key), value); + } + + private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; + + EqualsHashcodeOverridingFacade(N overridden) { + this.overridden = overridden; + } + + @Override + public R accept(GenericVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public void accept(VoidVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public final int hashCode() { + return overridden.accept(hashcodeVisitor, null); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof VisitorMap.EqualsHashcodeOverridingFacade)) { + return false; + } + return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); + } + } + + @Override + public V remove(Object key) { + return innerMap.remove(new EqualsHashcodeOverridingFacade((N) key)); + } + + @Override + public void putAll(Map m) { + m.forEach(this::put); + } + + @Override + public void clear() { + innerMap.clear(); + } + + @Override + public Set keySet() { + return innerMap.keySet().stream() + .map(k -> k.overridden) + .collect(Collectors.toSet()); + } + + @Override + public Collection values() { + return innerMap.values(); + } + + @Override + public Set> entrySet() { + return innerMap.entrySet().stream() + .map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())) + .collect(Collectors.toSet()); + } +} diff --git a/JavaParser/src/com/github/javaparser/utils/VisitorSet.java b/JavaParser/src/com/github/javaparser/utils/VisitorSet.java new file mode 100644 index 0000000..70fc358 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/utils/VisitorSet.java @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.utils; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + +/** + * A set that overrides the equals and hashcode calculation of the added nodes + * by using another equals and hashcode visitor for those methods. + */ +public class VisitorSet implements Set { + + private final Set innerSet = new HashSet<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; + + /** + * Pass the visitors to use for equals and hashcode. + */ + public VisitorSet(GenericVisitor hashcodeVisitor, GenericVisitor equalsVisitor) { + this.hashcodeVisitor = hashcodeVisitor; + this.equalsVisitor = equalsVisitor; + } + + @Override + public boolean add(N elem) { + return innerSet.add(new EqualsHashcodeOverridingFacade(elem)); + } + + @Override + public boolean addAll(Collection col) { + boolean modified = false; + for (N elem : col) + if (add(elem)) + modified = true; + return modified; + } + + @Override + public void clear() { + innerSet.clear(); + } + + @Override + public boolean contains(Object elem) { + return innerSet.contains(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public boolean containsAll(Collection col) { + for (Object elem : col) + if (!contains(elem)) + return false; + return true; + } + + @Override + public boolean isEmpty() { + return innerSet.isEmpty(); + } + + @Override + public Iterator iterator() { + return new Iterator() { + final Iterator itr = innerSet.iterator(); + + @Override + public boolean hasNext() { + return itr.hasNext(); + } + + @Override + public N next() { + return itr.next().overridden; + } + + @Override + public void remove() { + itr.remove(); + } + }; + } + + @Override + public boolean remove(Object elem) { + return innerSet.remove(new EqualsHashcodeOverridingFacade((N) elem)); + } + + @Override + public boolean removeAll(Collection col) { + boolean modified = false; + for (Object elem : col) + if (remove(elem)) + modified = true; + return modified; + } + + @Override + public boolean retainAll(Collection col) { + int oldSize = size(); + clear(); + addAll((Collection) col); + return size() != oldSize; + } + + @Override + public int size() { + return innerSet.size(); + } + + @Override + public Object[] toArray() { + return innerSet.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(); + } + + @Override + public T[] toArray(T[] arr) { + return innerSet.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(arr); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("["); + if (size() == 0) + return sb.append("]").toString(); + for (EqualsHashcodeOverridingFacade facade : innerSet) { + sb.append(facade.overridden.toString() + ","); + } + return sb.replace(sb.length() - 2, sb.length(), "]").toString(); + } + + private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; + + EqualsHashcodeOverridingFacade(N overridden) { + this.overridden = overridden; + } + + @Override + public R accept(GenericVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public void accept(VoidVisitor v, A arg) { + throw new AssertionError(); + } + + @Override + public final int hashCode() { + return overridden.accept(hashcodeVisitor, null); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof VisitorSet.EqualsHashcodeOverridingFacade)) { + return false; + } + return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); + } + } + +} diff --git a/JavaParser/src/com/github/javaparser/version/Java10PostProcessor.java b/JavaParser/src/com/github/javaparser/version/Java10PostProcessor.java new file mode 100644 index 0000000..7130870 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/version/Java10PostProcessor.java @@ -0,0 +1,24 @@ +package com.github.javaparser.version; + +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.VarType; + +import static com.github.javaparser.ParseResult.PostProcessor; + +/** + * Processes the generic AST into a Java 10 AST and validates it. + */ +public class Java10PostProcessor extends PostProcessors { + protected final PostProcessor varNodeCreator = (result, configuration) -> + result.getResult().ifPresent(node -> { + node.findAll(ClassOrInterfaceType.class).forEach(n -> { + if (n.getNameAsString().equals("var")) { + n.replace(new VarType(n.getTokenRange().orElse(null))); + } + }); + }); + + public Java10PostProcessor() { + add(varNodeCreator); + } +} diff --git a/JavaParser/src/com/github/javaparser/version/Java11PostProcessor.java b/JavaParser/src/com/github/javaparser/version/Java11PostProcessor.java new file mode 100644 index 0000000..004967e --- /dev/null +++ b/JavaParser/src/com/github/javaparser/version/Java11PostProcessor.java @@ -0,0 +1,7 @@ +package com.github.javaparser.version; + +/** + * Processes the generic AST into a Java 10 AST and validates it. + */ +public class Java11PostProcessor extends Java10PostProcessor { +} diff --git a/JavaParser/src/com/github/javaparser/version/PostProcessors.java b/JavaParser/src/com/github/javaparser/version/PostProcessors.java new file mode 100644 index 0000000..4220de3 --- /dev/null +++ b/JavaParser/src/com/github/javaparser/version/PostProcessors.java @@ -0,0 +1,49 @@ +package com.github.javaparser.version; + +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.Node; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static com.github.javaparser.ParseResult.PostProcessor; + +/** + * A post processor that will call a collection of post processors. + */ +public class PostProcessors implements PostProcessor { + private final List postProcessors = new ArrayList<>(); + + public PostProcessors(PostProcessor... postProcessors) { + this.postProcessors.addAll(Arrays.asList(postProcessors)); + } + + public List getPostProcessors() { + return postProcessors; + } + + public PostProcessors remove(PostProcessor postProcessor) { + if (!postProcessors.remove(postProcessor)) { + throw new AssertionError("Trying to remove a post processor that isn't there."); + } + return this; + } + + public PostProcessors replace(PostProcessor oldProcessor, PostProcessor newProcessor) { + remove(oldProcessor); + add(newProcessor); + return this; + } + + public PostProcessors add(PostProcessor newProcessor) { + postProcessors.add(newProcessor); + return this; + } + + @Override + public void process(ParseResult result, ParserConfiguration configuration) { + postProcessors.forEach(pp -> pp.process(result, configuration)); + } +} diff --git a/UMLCodeGenerator/manifest.mf b/UMLCodeGenerator/manifest.mf index 83fc1d5..89640cb 100644 --- a/UMLCodeGenerator/manifest.mf +++ b/UMLCodeGenerator/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.newcode OpenIDE-Module-Localizing-Bundle: org/uml/newcode/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLCodeGenerator/nbproject/genfiles.properties b/UMLCodeGenerator/nbproject/genfiles.properties index c0d31a9..c545532 100644 --- a/UMLCodeGenerator/nbproject/genfiles.properties +++ b/UMLCodeGenerator/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=b4cf2638 +build.xml.data.CRC32=2fde246e build.xml.script.CRC32=3d6fbdc0 -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=b4cf2638 +nbproject/build-impl.xml.data.CRC32=2fde246e nbproject/build-impl.xml.script.CRC32=b6c02f05 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLCodeGenerator/nbproject/project.properties b/UMLCodeGenerator/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLCodeGenerator/nbproject/project.properties +++ b/UMLCodeGenerator/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLCodeGenerator/src/org/uml/newcode/ClassDiagramCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/ClassDiagramCodeGenerator.java index 9dfd33a..8d3df97 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/ClassDiagramCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/ClassDiagramCodeGenerator.java @@ -27,7 +27,10 @@ public class ClassDiagramCodeGenerator { * @param srcPath to save generated code to */ public static void generateOrUpdateCode(ClassDiagram classDiagram, MyClassDiagramRenameTable renames, String srcPath) { + classDiagram.updateComponentPackages(); for (ComponentBase component : classDiagram.getComponents()) { + if (!component.generationRequested()) + continue; // Generate code if (component instanceof ClassComponent) { ClassCodeGenerator.getInstance().generateOrUpdateCode((ClassComponent) component, renames, srcPath); diff --git a/UMLCodeGenerator/src/org/uml/newcode/CodeGeneratorUtils.java b/UMLCodeGenerator/src/org/uml/newcode/CodeGeneratorUtils.java index 00755f0..04e4237 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/CodeGeneratorUtils.java +++ b/UMLCodeGenerator/src/org/uml/newcode/CodeGeneratorUtils.java @@ -2,6 +2,7 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParseException; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.type.Type; @@ -27,8 +28,8 @@ public static Type parseType(String typeString) { try { BodyDeclaration bd = JavaParser.parseBodyDeclaration(typeString + " field;"); FieldDeclaration declaration = (FieldDeclaration) bd; - type = declaration.getType(); - } catch (ParseException ex) { + type = declaration.getVariables().get(0).getType(); + } catch (ParseProblemException ex) { Exceptions.printStackTrace(ex); } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/components/ClassCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/components/ClassCodeGenerator.java index 930a314..13f6725 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/components/ClassCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/components/ClassCodeGenerator.java @@ -1,12 +1,12 @@ package org.uml.newcode.components; +import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; import java.util.LinkedList; import java.util.List; @@ -34,18 +34,22 @@ public static ClassCodeGenerator getInstance() { if (instance == null) instance = new ClassCodeGenerator(); return instance; } - + @Override - protected String generateCode(ClassComponent component) { + protected CompilationUnit generateCode(ClassComponent component) { + System.out.println("Generate class "+component.getSignature()); CompilationUnit cu = new CompilationUnit(); - cu.setTypes(new LinkedList()); - if (!component.getParentPackage().isEmpty()) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + cu.setTypes(new NodeList>()); + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } createSkeleton(component, cu); FieldCodeGenerator.createFields(component, cu); ConstructorCodeGenerator.createConstructors(component, cu); MethodCodeGenerator.createMethods(component, cu); - return cu.toString(); + return cu; } private static void createSkeleton(ClassComponent component, CompilationUnit cu) { @@ -53,35 +57,38 @@ private static void createSkeleton(ClassComponent component, CompilationUnit cu) declaration.setName(component.getName()); switch (component.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.addModifier(Modifier.PUBLIC); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.addModifier(Modifier.PROTECTED); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.addModifier(Modifier.PRIVATE); break; } - if (component.isAbstract()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.ABSTRACT)); - if (component.isStatic()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); - if (component.isFinal()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.FINAL)); + if (component.isAbstract()) + declaration.addModifier(Modifier.ABSTRACT); + if (component.isStatic()) + declaration.addModifier(Modifier.STATIC); + if (component.isFinal()) + declaration.addModifier(Modifier.FINAL); ComponentBase extendedClass = getExtendedClass(component); if (extendedClass != null) { - List extended = new LinkedList<>(); - extended.add(new ClassOrInterfaceType(extendedClass.getName())); - declaration.setExtends(extended); + NodeList extended = new NodeList(); + extended.add(JavaParser.parseClassOrInterfaceType(extendedClass.getName())); + declaration.setExtendedTypes(extended); } List implementedInterfaces = getImplementedInterfaces(component); if (!implementedInterfaces.isEmpty()) { - List implemented = new LinkedList<>(); + NodeList implemented = new NodeList(); for (ComponentBase implementedComponent : implementedInterfaces) { - implemented.add(new ClassOrInterfaceType(implementedComponent.getName())); + implemented.add(JavaParser.parseClassOrInterfaceType(implementedComponent.getName())); } - declaration.setImplements(implemented); + declaration.setImplementedTypes(implemented); } - declaration.setMembers(new LinkedList()); + declaration.setMembers(new NodeList>()); cu.getTypes().add(declaration); } @@ -106,18 +113,22 @@ private static List getImplementedInterfaces(ClassComponent compo } @Override - protected String updateCode(ClassComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { - if (!component.getParentPackage().equals("")) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + protected CompilationUnit updateCode(ClassComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { + System.out.println("Update class "+component.getSignature()); + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } updateSkeleton(component, cu); FieldCodeGenerator.updateFields(component, renames.getComponentRenames().getMembersRenameTable(component), renames.getRelationRenames(), cu); ConstructorCodeGenerator.updateConstructors(component, renames.getComponentRenames().getMembersRenameTable(component), cu); MethodCodeGenerator.updateMethods(component, renames.getComponentRenames().getMembersRenameTable(component), cu); - return cu.toString(); + return cu; } - + private static void updateSkeleton(ClassComponent component, CompilationUnit cu) { - List types = cu.getTypes(); + NodeList> types = cu.getTypes(); for (TypeDeclaration type : types) { if (type instanceof ClassOrInterfaceDeclaration) { ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration) type; @@ -125,27 +136,18 @@ private static void updateSkeleton(ClassComponent component, CompilationUnit cu) updateVisibility(declaration, component.getVisibility()); - if (component.isAbstract()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.ABSTRACT)); - else declaration.setModifiers(ModifierSet.removeModifier(declaration.getModifiers(), ModifierSet.ABSTRACT)); - if (component.isFinal()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.FINAL)); - else declaration.setModifiers(ModifierSet.removeModifier(declaration.getModifiers(), ModifierSet.FINAL)); - if (component.isStatic()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); - else declaration.setModifiers(ModifierSet.removeModifier(declaration.getModifiers(), ModifierSet.STATIC)); - + declaration.setModifier(Modifier.ABSTRACT, component.isAbstract()); + declaration.setModifier(Modifier.FINAL, component.isFinal()); + declaration.setModifier(Modifier.STATIC, component.isStatic()); + ComponentBase extendedClass = getExtendedClass(component); if (extendedClass != null) { - List extended = new LinkedList<>(); - extended.add(new ClassOrInterfaceType(extendedClass.getName())); - declaration.setExtends(extended); - } - List implementedInterfaces = getImplementedInterfaces(component); - if (!implementedInterfaces.isEmpty()) { - List implemented = new LinkedList<>(); - for (ComponentBase implementedComponent : implementedInterfaces) { - implemented.add(new ClassOrInterfaceType(implementedComponent.getName())); - } - declaration.setImplements(implemented); + NodeList extended = new NodeList(); + extended.add(JavaParser.parseClassOrInterfaceType(extendedClass.getName())); + declaration.setExtendedTypes(extended); } + + updateImplementedInterfaces(component,declaration); } // Process only the first one // TODO what if there are more classes in one file @@ -153,21 +155,57 @@ private static void updateSkeleton(ClassComponent component, CompilationUnit cu) } } + /** + * Update implemented inferfaces + * @param component + * @param declaration + * @return true if changes were made + */ + private static boolean updateImplementedInterfaces(ClassComponent component,ClassOrInterfaceDeclaration declaration) + { + NodeList implementedTypes = declaration.getImplementedTypes(); + List implementedInterfaces = getImplementedInterfaces(component); + if(implementedTypes.size() == implementedInterfaces.size()) { + boolean similar = true; + for (ComponentBase implementedComponent : implementedInterfaces) { + ClassOrInterfaceType type = JavaParser.parseClassOrInterfaceType(implementedComponent.getName()); + boolean found = false; + for(ClassOrInterfaceType implementedType : implementedTypes) { + if (implementedType.equals(type)) { + found = true; + break; + } + } + if (!found) { + similar = false; + break; + } + } + if (similar) { + return false; + } + } + NodeList implemented = new NodeList(); + if (!implementedInterfaces.isEmpty()) { + for (ComponentBase implementedComponent : implementedInterfaces) { + implemented.add(JavaParser.parseClassOrInterfaceType(implementedComponent.getName())); + } + } + declaration.setImplementedTypes(implemented); + return true; + } + private static void updateVisibility(TypeDeclaration declaration, Visibility visibility) { - int modifiers = declaration.getModifiers(); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PUBLIC); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PROTECTED); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PRIVATE); - + declaration.removeModifier(Modifier.PUBLIC,Modifier.PROTECTED,Modifier.PRIVATE); switch (visibility) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/components/ComponentCodeGeneratorBase.java b/UMLCodeGenerator/src/org/uml/newcode/components/ComponentCodeGeneratorBase.java index 5eebf4e..4a601c7 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/components/ComponentCodeGeneratorBase.java +++ b/UMLCodeGenerator/src/org/uml/newcode/components/ComponentCodeGeneratorBase.java @@ -1,16 +1,13 @@ package org.uml.newcode.components; import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseException; -import com.github.javaparser.Token; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import javax.swing.JOptionPane; import org.apache.commons.io.FileUtils; -import org.openide.util.Exceptions; import org.uml.filetype.cdg.renaming.MyClassDiagramRenameTable; import org.uml.model.components.ComponentBase; @@ -22,8 +19,8 @@ */ public abstract class ComponentCodeGeneratorBase { - protected abstract String generateCode(T component); - protected abstract String updateCode(T component, MyClassDiagramRenameTable renames, CompilationUnit cu); + protected abstract CompilationUnit generateCode(T component); + protected abstract CompilationUnit updateCode(T component, MyClassDiagramRenameTable renames, CompilationUnit cu); /** * Generates the code of the component to the given path. @@ -34,13 +31,13 @@ public abstract class ComponentCodeGeneratorBase { */ public void generateOrUpdateCode(T component, MyClassDiagramRenameTable renames, String sourcePath) { - String code = ""; File sourceFile; // If the component has been renamed, the source file should have the old name if (renames.getComponentRenames().contains(component)) { //-> new to old String oldFullQualifiedName = renames.getComponentRenames().getOriginalSignature(component); String pathToOldFile = sourcePath + oldFullQualifiedName.replace(".", File.separator) + ".java"; sourceFile = new File(pathToOldFile); + System.out.println("Component "+component.getSignature()+" renamed from "+pathToOldFile); } // If the component has not been renamed, the source should have the new name else { String fullQualifiedName = component.getSignature(); @@ -49,35 +46,33 @@ public void generateOrUpdateCode(T component, MyClassDiagramRenameTable renames, } // If source exists, update code + CompilationUnit code = null; + boolean lexicallyPreserved = false; if (sourceFile.exists()) { try { CompilationUnit cu; try (FileReader fileReader = new FileReader(sourceFile)) { - // TODO doesn't parse comments, as there is trobule generating them back to code - // In the current parser implementation, comments need to be anchored to some element, - // so the comments which are freely writen throughout the code are not well placed - // when generating the code. - cu = JavaParser.parse(fileReader, false); + cu = JavaParser.parse(fileReader); + LexicalPreservingPrinter.setup(cu); + lexicallyPreserved = true; } code = updateCode(component, renames, cu); - sourceFile.delete(); - } catch (ParseException ex) { - Token tok = ex.currentToken; - JOptionPane.showMessageDialog(null, "Malformed code at line " + tok.beginLine + " column " + tok.beginColumn + ". Cannot update!", "Error", JOptionPane.ERROR_MESSAGE); - } catch (FileNotFoundException ex) { - // Already checked for file existance, but if file is somehow deleted, generate code. - code = generateCode(component); - } catch (IOException ex) { - JOptionPane.showMessageDialog(null, "IOException!", "Error", JOptionPane.ERROR_MESSAGE); - Exceptions.printStackTrace(ex); + } catch (Exception ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(null, "Parse problem in "+sourceFile+". Cannot update!", "Error", JOptionPane.ERROR_MESSAGE); + return; } } // If source does not exist, generate code from scratch else { code = generateCode(component); } + + if (code == null) { + return; + } // Add package to the path - String packag = component.getParentPackage(); + String packag = component.getFullParentPackage(); String fullPath; if (!packag.equals("")) { String packagePath = packag.replace(".", File.separator); @@ -85,15 +80,41 @@ public void generateOrUpdateCode(T component, MyClassDiagramRenameTable renames, } else { fullPath = sourcePath; } + + String name = component.getName(); + // Try to generate while preserving presentation + String output; + if (lexicallyPreserved) { + try { + output = LexicalPreservingPrinter.print(code); + } + catch(Exception ex) { + ex.printStackTrace(); + int result = JOptionPane.showConfirmDialog(null, + "Code for "+name+" cannot be generated with lexical preservation.\n" + + "Many spaces and line returnes will diseapear.\n" + + "Generate code anyway ?", + "Problem in code generation", + JOptionPane.YES_NO_OPTION); + if (result != JOptionPane.YES_OPTION) + return; + output = code.toString(); + } + } + else { + output = code.toString(); + } // Create path folder structure new File(fullPath).mkdirs(); - String name = component.getName(); // Write-out the source file File outSourceFile = new File(fullPath + name + ".java"); try { - FileUtils.writeStringToFile(outSourceFile, code); + if (sourceFile.exists()) { + sourceFile.delete(); + } + FileUtils.writeStringToFile(outSourceFile, output); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Cannot write file " + outSourceFile.getName() + "!", "Error", JOptionPane.ERROR_MESSAGE); } @@ -108,4 +129,5 @@ public void generateOrUpdateCode(T component, MyClassDiagramRenameTable renames, // } catch (FileNotFoundException ex) { // } } + } diff --git a/UMLCodeGenerator/src/org/uml/newcode/components/EnumCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/components/EnumCodeGenerator.java index 460cce7..af100de 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/components/EnumCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/components/EnumCodeGenerator.java @@ -1,15 +1,12 @@ package org.uml.newcode.components; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.EnumConstantDeclaration; import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.expr.NameExpr; import org.uml.newcode.members.LiteralCodeGenerator; -import java.util.LinkedList; -import java.util.List; import org.uml.filetype.cdg.renaming.MyClassDiagramRenameTable; import org.uml.model.Visibility; import static org.uml.model.Visibility.PRIVATE; @@ -31,14 +28,17 @@ public static EnumCodeGenerator getInstance() { } @Override - protected String generateCode(EnumComponent component) { + protected CompilationUnit generateCode(EnumComponent component) { CompilationUnit cu = new CompilationUnit(); - cu.setTypes(new LinkedList()); - if (!component.getParentPackage().equals("")) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + cu.setTypes(new NodeList>()); + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } createSkeleton(component, cu); LiteralCodeGenerator.createLiterals(component, cu); - return cu.toString(); + return cu; } private static void createSkeleton(EnumComponent component, CompilationUnit cu) { @@ -46,31 +46,34 @@ private static void createSkeleton(EnumComponent component, CompilationUnit cu) declaration.setName(component.getName()); switch (component.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } - declaration.setEntries(new LinkedList()); + declaration.setEntries(new NodeList()); cu.getTypes().add(declaration); } @Override - protected String updateCode(EnumComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { - if (!component.getParentPackage().equals("")) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + protected CompilationUnit updateCode(EnumComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } updateSkeleton(component, cu); LiteralCodeGenerator.updateLiterals(component, renames.getComponentRenames().getMembersRenameTable(component), cu); - return cu.toString(); + return cu; } private static void updateSkeleton(EnumComponent component, CompilationUnit cu) { - List types = cu.getTypes(); + NodeList> types = cu.getTypes(); for (TypeDeclaration type : types) { if (type instanceof EnumDeclaration) { EnumDeclaration declaration = (EnumDeclaration) type; @@ -85,20 +88,16 @@ private static void updateSkeleton(EnumComponent component, CompilationUnit cu) } private static void updateVisibility(TypeDeclaration declaration, Visibility visibility) { - int modifiers = declaration.getModifiers(); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PUBLIC); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PROTECTED); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PRIVATE); - + declaration.removeModifier(Modifier.PUBLIC,Modifier.PROTECTED,Modifier.PRIVATE); switch (visibility) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/components/InterfaceCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/components/InterfaceCodeGenerator.java index 73bd129..00b5419 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/components/InterfaceCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/components/InterfaceCodeGenerator.java @@ -1,15 +1,13 @@ package org.uml.newcode.components; +import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import java.util.LinkedList; -import java.util.List; import org.uml.filetype.cdg.renaming.MyClassDiagramRenameTable; import org.uml.model.Visibility; import org.uml.model.components.ComponentBase; @@ -33,14 +31,17 @@ public static InterfaceCodeGenerator getInstance() { } @Override - protected String generateCode(InterfaceComponent component) { + protected CompilationUnit generateCode(InterfaceComponent component) { CompilationUnit cu = new CompilationUnit(); - cu.setTypes(new LinkedList()); - if (!component.getParentPackage().equals("")) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + cu.setTypes(new NodeList>()); + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } createSkeleton(component, cu); MethodCodeGenerator.createMethods(component, cu); - return cu.toString(); + return cu; } private static void createSkeleton(InterfaceComponent component, CompilationUnit cu) { @@ -49,25 +50,26 @@ private static void createSkeleton(InterfaceComponent component, CompilationUnit declaration.setName(component.getName()); switch (component.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } - if (component.isStatic()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); - - ComponentBase extendedInterface = getExtendedInterface(component); - if (extendedInterface != null) { - List extended = new LinkedList<>(); - extended.add(new ClassOrInterfaceType(extendedInterface.getName())); - declaration.setExtends(extended); - } - - declaration.setMembers(new LinkedList()); + if (component.isStatic()) + declaration.setModifier(Modifier.STATIC, true); + + ComponentBase extendedClass = getExtendedInterface(component); + if (extendedClass != null) { + NodeList extended = new NodeList(); + extended.add(JavaParser.parseClassOrInterfaceType(extendedClass.getName())); + declaration.setExtendedTypes(extended); + } + + declaration.setMembers(new NodeList>()); cu.getTypes().add(declaration); } @@ -82,16 +84,19 @@ private static ComponentBase getExtendedInterface(InterfaceComponent component) } @Override - protected String updateCode(InterfaceComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { - if (!component.getParentPackage().equals("")) cu.setPackage(new PackageDeclaration(new NameExpr(component.getParentPackage()))); + protected CompilationUnit updateCode(InterfaceComponent component, MyClassDiagramRenameTable renames, CompilationUnit cu) { + String parentPackage = component.getFullParentPackage(); + if (!parentPackage.isEmpty()) { + cu.setPackageDeclaration(parentPackage); + } updateHeader(component, cu); MethodCodeGenerator.updateMethods(component, renames.getComponentRenames().getMembersRenameTable(component), cu); - return cu.toString(); + return cu; } private static void updateHeader(InterfaceComponent component, CompilationUnit cu) { - List types = cu.getTypes(); + NodeList> types = cu.getTypes(); for (TypeDeclaration type : types) { if (type instanceof ClassOrInterfaceDeclaration) { ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration) type; @@ -99,15 +104,14 @@ private static void updateHeader(InterfaceComponent component, CompilationUnit c updateVisibility(declaration, component.getVisibility()); - if (component.isStatic()) declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); - else declaration.setModifiers(ModifierSet.removeModifier(declaration.getModifiers(), ModifierSet.STATIC)); + declaration.setModifier(Modifier.STATIC, component.isStatic()); - ComponentBase extendedInterface = getExtendedInterface(component); - if (extendedInterface != null) { - List extended = new LinkedList<>(); - extended.add(new ClassOrInterfaceType(extendedInterface.getName())); - declaration.setExtends(extended); - } + ComponentBase extendedClass = getExtendedInterface(component); + if (extendedClass != null) { + NodeList extended = new NodeList(); + extended.add(JavaParser.parseClassOrInterfaceType(extendedClass.getName())); + declaration.setExtendedTypes(extended); + } } // Process only the first one // TODO what if there are more classes in one file @@ -116,20 +120,16 @@ private static void updateHeader(InterfaceComponent component, CompilationUnit c } private static void updateVisibility(TypeDeclaration declaration, Visibility visibility) { - int modifiers = declaration.getModifiers(); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PUBLIC); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PROTECTED); - modifiers = ModifierSet.removeModifier(modifiers, ModifierSet.PRIVATE); - + declaration.removeModifier(Modifier.PUBLIC,Modifier.PROTECTED,Modifier.PRIVATE); switch (visibility) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(modifiers, ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/members/ConstructorCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/members/ConstructorCodeGenerator.java index 896eaaa..7e87b1f 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/members/ConstructorCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/members/ConstructorCodeGenerator.java @@ -1,11 +1,11 @@ package org.uml.newcode.members; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclaratorId; import com.github.javaparser.ast.stmt.BlockStmt; import java.util.LinkedList; import java.util.List; @@ -22,7 +22,7 @@ public class ConstructorCodeGenerator { public static void createConstructors(ClassComponent component, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); for (Constructor constructor : component.getConstructors()) { // create and add constructor declaration @@ -32,7 +32,7 @@ public static void createConstructors(ClassComponent component, CompilationUnit } public static void updateConstructors(ClassComponent component, MyMembersRenameTable renames, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); // Generate or update all direct constructors for (Constructor constructor : component.getConstructors()) { ConstructorDeclaration existingDeclaration = findExistingDeclaration(members, constructor); @@ -48,12 +48,12 @@ public static void updateConstructors(ClassComponent component, MyMembersRenameT // Update the old constructor declaration declaration.setName(constructor.getName()); if (!constructor.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : constructor.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); @@ -76,7 +76,7 @@ public static void updateConstructors(ClassComponent component, MyMembersRenameT } } - private static ConstructorDeclaration findExistingDeclaration(List declarations, Constructor constructor) { + private static ConstructorDeclaration findExistingDeclaration(NodeList> declarations, Constructor constructor) { for (BodyDeclaration declaration : declarations) { if (declaration instanceof ConstructorDeclaration && constructor.getSignature().equals(getConstructorDeclarationSignature((ConstructorDeclaration) declaration))) { return (ConstructorDeclaration) declaration; @@ -90,27 +90,27 @@ private static ConstructorDeclaration createConstructorDeclaration(Constructor c declaration.setName(constructor.getDeclaringComponent().getName()); switch (constructor.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.setModifier(Modifier.PUBLIC, true); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.setModifier(Modifier.PROTECTED, true); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.setModifier(Modifier.PRIVATE, true); break; } if (!constructor.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : constructor.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); } - declaration.setBlock(new BlockStmt()); + declaration.setBody(new BlockStmt()); return declaration; } @@ -120,7 +120,7 @@ private static String getConstructorDeclarationSignature(ConstructorDeclaration String args = ""; if (declaration.getParameters() != null) { for (Parameter parameter : declaration.getParameters()) { - args += parameter.getType() + " " + parameter.getId().getName() + ", "; + args += parameter.getType() + " " + parameter.getName() + ", "; } if (!args.equals("")) { args = args.substring(0, args.length() - 2); diff --git a/UMLCodeGenerator/src/org/uml/newcode/members/FieldCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/members/FieldCodeGenerator.java index 7fde05e..9cbd95c 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/members/FieldCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/members/FieldCodeGenerator.java @@ -1,15 +1,13 @@ package org.uml.newcode.members; import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseException; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.body.VariableDeclaratorId; -import java.util.LinkedList; -import java.util.List; import org.openide.util.Exceptions; import org.uml.filetype.cdg.renaming.MyMembersRenameTable; import org.uml.filetype.cdg.renaming.MyRelationsRenameTable; @@ -26,7 +24,7 @@ public class FieldCodeGenerator { public static void createFields(ClassComponent component, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); // Generate direct fields for (Field field : component.getFields()) { @@ -48,7 +46,7 @@ public static void createFields(ClassComponent component, CompilationUnit cu) { } public static void updateFields(ClassComponent component, MyMembersRenameTable memberRenames, MyRelationsRenameTable relationRenames, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); // Generate or update all direct fields for (Field field : component.getFields()) { FieldDeclaration existingDeclaration = findExistingDeclaration(members, field.getSignature()); @@ -62,9 +60,11 @@ public static void updateFields(ClassComponent component, MyMembersRenameTable m FieldDeclaration declaration = (FieldDeclaration) member; if (oldSignature.equals(getFieldDeclarationSignature(declaration))) { // Update the old field declaration - declaration.setType(CodeGeneratorUtils.parseType(field.getType())); - declaration.getVariables().get(0).getId().setName(field.getName()); - // Finish updating the old field declaration + NodeList variables = new NodeList(); + VariableDeclarator variable; + variable = new VariableDeclarator(CodeGeneratorUtils.parseType(field.getType()),field.getName()); + variables.add(variable); + declaration.setVariables(variables); found = true; break; } @@ -122,7 +122,7 @@ public static void updateFields(ClassComponent component, MyMembersRenameTable m // } } - private static FieldDeclaration findExistingDeclaration(List declarations, String signature) { + private static FieldDeclaration findExistingDeclaration(NodeList> declarations, String signature) { for (BodyDeclaration declaration : declarations) { if (declaration instanceof FieldDeclaration && signature.equals(getFieldDeclarationSignature((FieldDeclaration) declaration))) { return (FieldDeclaration) declaration; @@ -133,35 +133,37 @@ private static FieldDeclaration findExistingDeclaration(List de private static FieldDeclaration createFieldDeclaration(Field field) { FieldDeclaration declaration = new FieldDeclaration(); - VariableDeclarator variable = new VariableDeclarator(new VariableDeclaratorId(field.getName())); - List variables = new LinkedList<>(); + + NodeList variables = new NodeList(); + VariableDeclarator variable; + variable = new VariableDeclarator(CodeGeneratorUtils.parseType(field.getType()), field.getName()); variables.add(variable); declaration.setVariables(variables); - String type = field.getType(); - declaration.setType(CodeGeneratorUtils.parseType(type)); + switch (field.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.addModifier(Modifier.PUBLIC); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.addModifier(Modifier.PROTECTED); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.addModifier(Modifier.PRIVATE); break; } if (field.isStatic()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); + declaration.addModifier(Modifier.STATIC); } if (field.isFinal()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.FINAL)); - } + declaration.addModifier(Modifier.FINAL); + } if (field.isVolatile()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.VOLATILE)); + declaration.addModifier(Modifier.VOLATILE); } if (field.isTransient()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.TRANSIENT)); + declaration.addModifier(Modifier.TRANSIENT); } + return declaration; } @@ -171,15 +173,16 @@ private static FieldDeclaration createFieldDeclaration(HasBaseRelation hasRelati BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature); FieldDeclaration declaration = (FieldDeclaration) bd; return declaration; - } catch (ParseException ex) { + } catch (ParseProblemException ex) { Exceptions.printStackTrace(ex); } return null; } private static String getFieldDeclarationSignature(FieldDeclaration declaration) { - String type = declaration.getType().toString(); - String name = declaration.getVariables().get(0).getId().getName(); + NodeList variables = declaration.getVariables(); + String type = variables.get(0).getType().asString(); + String name = variables.get(0).getName().asString(); return type + " " + name; } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/members/LiteralCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/members/LiteralCodeGenerator.java index 2ff2d32..f962f5a 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/members/LiteralCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/members/LiteralCodeGenerator.java @@ -1,9 +1,11 @@ package org.uml.newcode.members; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.EnumConstantDeclaration; import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.TypeDeclaration; +import java.util.ArrayList; import java.util.List; import org.uml.filetype.cdg.renaming.MyMembersRenameTable; import org.uml.model.components.EnumComponent; @@ -29,43 +31,64 @@ public static void createLiterals(EnumComponent component, CompilationUnit cu) { } public static void updateLiterals(EnumComponent component, MyMembersRenameTable memberRenames, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> types = cu.getTypes(); + TypeDeclaration type = types.get(0); + EnumDeclaration enumType = (EnumDeclaration)type; + NodeList entries = enumType.getEntries(); // Generate or update all direct fields for (Literal literal : component.getLiterals()) { - EnumConstantDeclaration existingDeclaration = findExistingDeclaration(members, literal.getSignature()); + EnumConstantDeclaration existingDeclaration = findExistingDeclaration(entries, literal.getSignature()); if (existingDeclaration == null) { // If there is not existing declaration in the class body if (memberRenames.contains(literal)) { // If the lieteral has been renamed // Find the old literal declaration String oldSignature = memberRenames.getOriginalSignature(literal); boolean found = false; - for (BodyDeclaration member : members) { - if (member instanceof EnumConstantDeclaration) { - EnumConstantDeclaration declaration = (EnumConstantDeclaration) member; - if (oldSignature.equals(getEnumConstantDeclarationSignature(declaration))) { - // Update the old literal declaration - declaration.setName(literal.getName()); - // Finish updating the old literal declaration - found = true; - break; - } + for (EnumConstantDeclaration declaration : entries) { + if (oldSignature.equals(getEnumConstantDeclarationSignature(declaration))) { + // Update the old literal declaration + declaration.setName(literal.getName()); + // Finish updating the old literal declaration + found = true; + break; } } if (!found) { // If the old literal declaration has not been found and updated, create it and add it EnumConstantDeclaration declaration = createLiteralDeclaration(literal); - members.add(declaration); + entries.add(declaration); } } else { // If the literal has not been renamed, there is nothing to update, so create and add it EnumConstantDeclaration declaration = createLiteralDeclaration(literal); - members.add(declaration); + entries.add(declaration); } } } + // Find removed declarations + ArrayList toRemove = new ArrayList(); + for (EnumConstantDeclaration declaration : entries) { + boolean found = false; + String name = declaration.getName().asString(); + for (Literal literal : component.getLiterals()) { + if (literal.getSignature().equals(name)) { + found = true; + break; + } + } + if (!found) { + toRemove.add(declaration); + } + } + for (EnumConstantDeclaration declaration : toRemove) { + entries.remove(declaration); + } } - private static EnumConstantDeclaration findExistingDeclaration(List declarations, String signature) { - for (BodyDeclaration declaration : declarations) { - if (declaration instanceof EnumConstantDeclaration && signature.equals(((EnumConstantDeclaration) declaration).getName())) { - return (EnumConstantDeclaration) declaration; + private static EnumConstantDeclaration findExistingDeclaration(List entries, String signature) { + if (entries == null) { + return null; + } + for (EnumConstantDeclaration entry : entries) { + if (signature.equals(entry.getName().asString())) { + return entry; } } return null; @@ -78,6 +101,6 @@ private static EnumConstantDeclaration createLiteralDeclaration(Literal literal) } private static String getEnumConstantDeclarationSignature(EnumConstantDeclaration declaration) { - return declaration.getName(); + return declaration.getName().asString(); } } diff --git a/UMLCodeGenerator/src/org/uml/newcode/members/MethodCodeGenerator.java b/UMLCodeGenerator/src/org/uml/newcode/members/MethodCodeGenerator.java index 4e5ac3b..e1369da 100644 --- a/UMLCodeGenerator/src/org/uml/newcode/members/MethodCodeGenerator.java +++ b/UMLCodeGenerator/src/org/uml/newcode/members/MethodCodeGenerator.java @@ -1,24 +1,35 @@ package org.uml.newcode.members; +import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.ModifierSet; import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclaratorId; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.AssignExpr; import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.ThrowStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import org.uml.filetype.cdg.renaming.MyMembersRenameTable; import org.uml.model.components.ClassComponent; import org.uml.model.components.InterfaceComponent; +import org.uml.model.members.Field; import org.uml.model.members.Method; import org.uml.model.members.MethodArgument; import org.uml.newcode.CodeGeneratorUtils; @@ -30,20 +41,32 @@ public class MethodCodeGenerator { public static void createMethods(ClassComponent component, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); for (Method method : component.getMethods()) { // create and add method declaration - MethodDeclaration declaration = createMethodDeclaration(method); + MethodDeclaration declaration = createMethodDeclaration(method,null); + members.add(declaration); + } + + // Generate getters + for (Field field : component.getRequestedGetters()) { + MethodDeclaration declaration = createMethodDeclaration(field.createGetter(),createGetterBody(field)); members.add(declaration); } + // Generate setters + for (Field field : component.getRequestedSetters()) { + MethodDeclaration declaration = createMethodDeclaration(field.createSetter(),createSetterBody(field)); + members.add(declaration); + } + // Do not generate methods for implemented or extended interfaces, // let NetBeans show error and take care of that } public static void createMethods(InterfaceComponent component, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); for (Method method : component.getMethods()) { // create and add method declaration @@ -53,7 +76,7 @@ public static void createMethods(InterfaceComponent component, CompilationUnit c } public static void updateMethods(ClassComponent component, MyMembersRenameTable renames, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); // Generate or update all direct methods for (Method method : component.getMethods()) { MethodDeclaration existingDeclaration = findExistingDeclaration(members, method); @@ -61,6 +84,7 @@ public static void updateMethods(ClassComponent component, MyMembersRenameTable if (renames.contains(method)) { // If the method has been renamed // Find the old method declaration String oldSignature = renames.getOriginalSignature(method); + System.out.println(component.getSignature()+"."+method.getSignature()+": renamed from "+oldSignature); boolean found = false; for (BodyDeclaration member : members) { if (member instanceof MethodDeclaration) { @@ -70,16 +94,17 @@ public static void updateMethods(ClassComponent component, MyMembersRenameTable declaration.setName(method.getName()); declaration.setType(CodeGeneratorUtils.parseType(method.getType())); if (!method.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : method.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); } + System.out.println(" Update method "+method.getSignature()); // Finish updating the old method declaration found = true; break; @@ -87,19 +112,43 @@ public static void updateMethods(ClassComponent component, MyMembersRenameTable } } if (!found) { // If the old method declaration has not been found and updated, create it and add it - MethodDeclaration declaration = createMethodDeclaration(method); + MethodDeclaration declaration = createMethodDeclaration(method,null); members.add(declaration); + System.out.println(" Add renamed method "+method.getSignature()); } } else { // If the method has not been renamed, there is nothing to update, so create and add it - MethodDeclaration declaration = createMethodDeclaration(method); + MethodDeclaration declaration = createMethodDeclaration(method,null); members.add(declaration); + System.out.println(" Add method "+method.getSignature()); } } } + // Generate getters + for (Field field : component.getRequestedGetters()) { + Method method = field.createGetter(); + MethodDeclaration existingDeclaration = findExistingDeclaration(members, method); + if (existingDeclaration != null) + continue; + MethodDeclaration declaration = createMethodDeclaration(method,createGetterBody(field)); + members.add(declaration); + System.out.println(" Add getter "+method.getSignature()); + } + + // Generate setters + for (Field field : component.getRequestedSetters()) { + Method method = field.createSetter(); + MethodDeclaration existingDeclaration = findExistingDeclaration(members, method); + if (existingDeclaration != null) + continue; + MethodDeclaration declaration = createMethodDeclaration(method,createSetterBody(field)); + members.add(declaration); + System.out.println(" Add setter "+method.getSignature()); + } + } public static void updateMethods(InterfaceComponent component, MyMembersRenameTable renames, CompilationUnit cu) { - List members = cu.getTypes().get(0).getMembers(); + NodeList> members = cu.getTypes().get(0).getMembers(); // Generate or update all direct methods for (Method method : component.getMethods()) { // If the method has been renamed update or generate @@ -114,12 +163,12 @@ public static void updateMethods(InterfaceComponent component, MyMembersRenameTa if (oldSignature.equals(getMethodDeclarationSignature(declaration))) { declaration.setName(oldSignature); if (!method.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : method.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); @@ -146,7 +195,7 @@ public static void updateMethods(InterfaceComponent component, MyMembersRenameTa } } - private static MethodDeclaration createMethodDeclaration(Method method) { + private static MethodDeclaration createMethodDeclaration(Method method,BlockStmt body) { MethodDeclaration declaration = new MethodDeclaration(); // Set name declaration.setName(method.getName()); @@ -156,64 +205,72 @@ private static MethodDeclaration createMethodDeclaration(Method method) { // Set visibility switch (method.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.addModifier(Modifier.PUBLIC); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.addModifier(Modifier.PROTECTED); break; case PRIVATE: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PRIVATE)); + declaration.addModifier(Modifier.PRIVATE); break; } - // Set modifiers if (method.isStatic()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); + declaration.addModifier(Modifier.STATIC); } if (method.isFinal()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.FINAL)); + declaration.addModifier(Modifier.FINAL); } if (method.isAbstract()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.ABSTRACT)); + declaration.addModifier(Modifier.ABSTRACT); } if (method.isSynchronized()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.SYNCHRONIZED)); + declaration.addModifier(Modifier.SYNCHRONIZED); } // Set arguments if (!method.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : method.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); } // Fill method body if (!method.isAbstract()) { - BlockStmt body = new BlockStmt(); - // If the return type is not void, set the body to UnsupportedOperationException - // Otherwise, leave body empty - if (!(declaration.getType() instanceof VoidType)) { - List statements = new LinkedList<>(); - ObjectCreationExpr exception = new ObjectCreationExpr(); - exception.setType(new ClassOrInterfaceType("UnsupportedOperationException")); - List arguments = new LinkedList<>(); - arguments.add(new StringLiteralExpr("Not supported yet.")); - exception.setArgs(arguments); - statements.add(new ThrowStmt(exception)); - body.setStmts(statements); + if (body == null) { + body = new BlockStmt(); + // If the return type is not void, set the body to UnsupportedOperationException + // Otherwise, leave body empty + if (!(declaration.getType() instanceof VoidType)) { + NodeList statements = new NodeList<>(); + ObjectCreationExpr exception = new ObjectCreationExpr(); + exception.setType(JavaParser.parseClassOrInterfaceType("UnsupportedOperationException")); + NodeList arguments = new NodeList<>(); + arguments.add(new StringLiteralExpr("Not supported yet.")); + exception.setArguments(arguments); + statements.add(new ThrowStmt(exception)); + body.setStatements(statements); + } } declaration.setBody(body); } + else { + declaration.setBody(null); + } return declaration; } - private static MethodDeclaration findExistingDeclaration(List declarations, Method method) { + private static MethodDeclaration findExistingDeclaration(NodeList> declarations, Method method) { for (BodyDeclaration declaration : declarations) { - if (declaration instanceof MethodDeclaration && method.getSignature().equals(getMethodDeclarationSignature((MethodDeclaration) declaration))) { + if (!(declaration instanceof MethodDeclaration)) + continue; + String methodSignature = method.getSignature(); + String declarationSignature = getMethodDeclarationSignature((MethodDeclaration) declaration); + if (methodSignature.equals(declarationSignature)) { return (MethodDeclaration) declaration; } } @@ -225,46 +282,62 @@ private static MethodDeclaration createInterfaceMethodDeclaration(Method method) declaration.setName(method.getName()); String returnType = method.getType(); declaration.setType(CodeGeneratorUtils.parseType(returnType)); + switch (method.getVisibility()) { case PUBLIC: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PUBLIC)); + declaration.addModifier(Modifier.PUBLIC); break; case PROTECTED: - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.PROTECTED)); + declaration.addModifier(Modifier.PROTECTED); break; } - if (method.isStatic()) { - declaration.setModifiers(ModifierSet.addModifier(declaration.getModifiers(), ModifierSet.STATIC)); - } + if (method.isStatic()) + declaration.addModifier(Modifier.STATIC); if (!method.getArguments().isEmpty()) { - List parameters = new LinkedList<>(); + NodeList parameters = new NodeList<>(); for (MethodArgument argument : method.getArguments()) { Parameter parameter = new Parameter(); String type = argument.getType(); parameter.setType(CodeGeneratorUtils.parseType(type)); - parameter.setId(new VariableDeclaratorId(argument.getName())); + parameter.setName(argument.getName()); parameters.add(parameter); } declaration.setParameters(parameters); } + + declaration.setBody(null); + return declaration; } - + private static String getMethodDeclarationSignature(MethodDeclaration declaration) { - StringBuilder result = new StringBuilder(); - result.append(declaration.getType().toString()).append(" "); - result.append(declaration.getName()).append("("); - String args = ""; - if (declaration.getParameters() != null) { - for (Parameter parameter : declaration.getParameters()) { - args += parameter.getType() + " " + parameter.getId().getName() + ", "; - } - if (!args.equals("")) { - args = args.substring(0, args.length() - 2); - } + Method method = new Method(declaration.getName().asString(), declaration.getType().asString()); + + LinkedHashSet arguments = method.getArguments(); + for (Parameter parameter : declaration.getParameters()) { + MethodArgument arg = new MethodArgument(parameter.getType().asString(), parameter.getName().asString()); + arguments.add(arg); } - result.append(args).append(")"); - return result.toString(); + + return method.getSignature(); + } + + public static BlockStmt createGetterBody(Field field) { + BlockStmt body = new BlockStmt(); + NodeList statements = new NodeList<>(); + statements.add(new ReturnStmt(new NameExpr(field.getName()))); + body.setStatements(statements); + return body; + } + + public static BlockStmt createSetterBody(Field field) { + BlockStmt body = new BlockStmt(); + NodeList statements = new NodeList<>(); + Expression expr = new FieldAccessExpr(new ThisExpr(),field.getName()); + statements.add(new ExpressionStmt(new AssignExpr(expr,new NameExpr(field.getName()),AssignExpr.Operator.ASSIGN))); + body.setStatements(statements); + return body; } + } diff --git a/UMLExplorer/manifest.mf b/UMLExplorer/manifest.mf index 9758634..7da751c 100644 --- a/UMLExplorer/manifest.mf +++ b/UMLExplorer/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.explorer OpenIDE-Module-Localizing-Bundle: org/uml/explorer/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLExplorer/nbproject/genfiles.properties b/UMLExplorer/nbproject/genfiles.properties index 7236c6c..365827a 100644 --- a/UMLExplorer/nbproject/genfiles.properties +++ b/UMLExplorer/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=0821d8b3 +build.xml.data.CRC32=d8bc7dc0 build.xml.script.CRC32=7ebd0419 -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=0821d8b3 +nbproject/build-impl.xml.data.CRC32=d8bc7dc0 nbproject/build-impl.xml.script.CRC32=468b15a1 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLExplorer/nbproject/project.properties b/UMLExplorer/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLExplorer/nbproject/project.properties +++ b/UMLExplorer/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLExplorer/src/org/uml/explorer/ClassDiagramNode.java b/UMLExplorer/src/org/uml/explorer/ClassDiagramNode.java index e20beb6..1f7d44c 100644 --- a/UMLExplorer/src/org/uml/explorer/ClassDiagramNode.java +++ b/UMLExplorer/src/org/uml/explorer/ClassDiagramNode.java @@ -18,6 +18,7 @@ import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.uml.model.ClassDiagram; +import org.uml.model.GenerationSetting; /** * @@ -95,15 +96,33 @@ protected Sheet createSheet() { generalProperties.setName("generalSet"); generalProperties.setDisplayName("General"); + Sheet.Set generationProperties = Sheet.createPropertiesSet(); + generationProperties.setName("generationSet"); + generationProperties.setDisplayName("Code generation"); + try { Property nameProp = new PropertySupport.Reflection<>(classDiagram, String.class, "getName", "setName"); nameProp.setName("Name"); generalProperties.put(nameProp); + + Property showAddMemberProp = new PropertySupport.Reflection<>(classDiagram, boolean.class, "isShowAddMember", "setShowAddMember"); + showAddMemberProp.setName("Show add member"); + generalProperties.put(showAddMemberProp); + + Property getterGenerationProp = new PropertySupport.Reflection<>(classDiagram, GenerationSetting.class, "getGetterGeneration", "setGetterGeneration"); + getterGenerationProp.setName("Getters"); + generationProperties.put(getterGenerationProp); + + Property setterGenerationProp = new PropertySupport.Reflection<>(classDiagram, GenerationSetting.class, "getSetterGeneration", "setSetterGeneration"); + setterGenerationProp.setName("Setters"); + generationProperties.put(setterGenerationProp); + } catch (Exception e) { Exceptions.printStackTrace(e); } sheet.put(generalProperties); + sheet.put(generationProperties); // Sheet.Set visualProperties = Sheet.createPropertiesSet(); // visualProperties.setName("visualSet"); // visualProperties.setDisplayName("Visual"); diff --git a/UMLExplorer/src/org/uml/explorer/ComponentNode.java b/UMLExplorer/src/org/uml/explorer/ComponentNode.java index 9ea4854..ed1cfc1 100644 --- a/UMLExplorer/src/org/uml/explorer/ComponentNode.java +++ b/UMLExplorer/src/org/uml/explorer/ComponentNode.java @@ -20,11 +20,13 @@ import org.openide.util.actions.SystemAction; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; +import org.uml.model.GenerationSetting; import org.uml.model.components.ClassComponent; import org.uml.model.components.ComponentBase; import org.uml.model.components.EnumComponent; import org.uml.model.components.InterfaceComponent; import org.uml.model.Visibility; +import org.uml.model.components.PackageComponent; /** * @@ -99,6 +101,9 @@ public Image getIcon(int type) { if (component instanceof EnumComponent) { return ImageUtilities.loadImage(iconFolderPath + "enum.png"); } + if (component instanceof PackageComponent) { + return ImageUtilities.loadImage(iconFolderPath + "package.png"); + } return super.getIcon(type); } @@ -119,6 +124,10 @@ protected Sheet createSheet() { modifiersProperties.setName("modifiersSet"); modifiersProperties.setDisplayName("Modifiers"); + Sheet.Set generationProperties = Sheet.createPropertiesSet(); + generationProperties.setName("generationSet"); + generationProperties.setDisplayName("Code generation"); + try { Property nameProp = new PropertySupport.Reflection<>(this, String.class, "getComponentName", "setComponentName"); nameProp.setName("Name"); @@ -127,6 +136,10 @@ protected Sheet createSheet() { Property packageProp = new PropertySupport.Reflection<>(this, String.class, "getParentPackage", "setParentPackage"); packageProp.setName("Package"); generalProperties.put(packageProp); + + Property generationProp = new PropertySupport.Reflection<>(component, GenerationSetting.class, "getGeneration", "setGeneration"); + generationProp.setName("Generation"); + generationProperties.put(generationProp); if (component instanceof ClassComponent || component instanceof InterfaceComponent) { @@ -147,6 +160,15 @@ protected Sheet createSheet() { Property isAbstractProp = new PropertySupport.Reflection<>(classComponent, boolean.class, "isAbstract", "setAbstract"); isAbstractProp.setName("abstract"); modifiersProperties.put(isAbstractProp); + + Property getterGenerationProp = new PropertySupport.Reflection<>(component, GenerationSetting.class, "getGetterGeneration", "setGetterGeneration"); + getterGenerationProp.setName("Getters"); + generationProperties.put(getterGenerationProp); + + Property setterGenerationProp = new PropertySupport.Reflection<>(component, GenerationSetting.class, "getSetterGeneration", "setSetterGeneration"); + setterGenerationProp.setName("Setters"); + generationProperties.put(setterGenerationProp); + } else if (component instanceof InterfaceComponent) { InterfaceComponent interfaceComponent = (InterfaceComponent) component; Property isStaticProp = new PropertySupport.Reflection<>(interfaceComponent, boolean.class, "isStatic", "setStatic"); @@ -160,6 +182,7 @@ protected Sheet createSheet() { sheet.put(generalProperties); sheet.put(modifiersProperties); + sheet.put(generationProperties); return sheet; } diff --git a/UMLExplorer/src/org/uml/explorer/MemberNode.java b/UMLExplorer/src/org/uml/explorer/MemberNode.java index 9f0590d..7cc55f0 100644 --- a/UMLExplorer/src/org/uml/explorer/MemberNode.java +++ b/UMLExplorer/src/org/uml/explorer/MemberNode.java @@ -19,6 +19,7 @@ import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.uml.memberparser.MemberParser; +import org.uml.model.GenerationSetting; import org.uml.model.Visibility; import org.uml.model.components.ComponentBase; import org.uml.model.components.InterfaceComponent; @@ -118,6 +119,10 @@ protected Sheet createSheet() { modifiersProperties.setName("modifiersSet"); modifiersProperties.setDisplayName("Modifiers"); + Sheet.Set generationProperties = Sheet.createPropertiesSet(); + generationProperties.setName("generationSet"); + generationProperties.setDisplayName("Code generation"); + try { if (member instanceof Constructor) { Property visibilityProp = new PropertySupport.Reflection<>(member, Visibility.class, "getVisibility", "setVisibility"); @@ -154,6 +159,18 @@ protected Sheet createSheet() { Property isVolatileProp = new PropertySupport.Reflection<>(field, boolean.class, "isVolatile", "setVolatile"); isVolatileProp.setName("volatile"); modifiersProperties.put(isVolatileProp); + + if (!field.isStatic()) { + Property getterGenerationProp = new PropertySupport.Reflection<>(field, GenerationSetting.class, "getGetterGeneration", "setGetterGeneration"); + getterGenerationProp.setName("Getters"); + generationProperties.put(getterGenerationProp); + + Property setterGenerationProp = new PropertySupport.Reflection<>(field, GenerationSetting.class, "getSetterGeneration", "setSetterGeneration"); + setterGenerationProp.setName("Setters"); + generationProperties.put(setterGenerationProp); + } + + } else if (member instanceof Method) { Method method = (Method) member; @@ -196,6 +213,7 @@ protected Sheet createSheet() { sheet.put(generalProperties); sheet.put(modifiersProperties); + sheet.put(generationProperties); return sheet; } diff --git a/UMLExplorer/src/org/uml/explorer/icons/package.png b/UMLExplorer/src/org/uml/explorer/icons/package.png new file mode 100644 index 0000000..5fb8413 Binary files /dev/null and b/UMLExplorer/src/org/uml/explorer/icons/package.png differ diff --git a/UMLFileTypes/manifest.mf b/UMLFileTypes/manifest.mf index 8ba023d..fd8e76a 100644 --- a/UMLFileTypes/manifest.mf +++ b/UMLFileTypes/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.filetype OpenIDE-Module-Localizing-Bundle: org/uml/filetype/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLFileTypes/nbproject/genfiles.properties b/UMLFileTypes/nbproject/genfiles.properties index 36ef623..87defce 100644 --- a/UMLFileTypes/nbproject/genfiles.properties +++ b/UMLFileTypes/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=7a58790d +build.xml.data.CRC32=d46e03e0 build.xml.script.CRC32=69e387b4 -build.xml.stylesheet.CRC32=a56c6a5b@2.71.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.72.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=7a58790d +nbproject/build-impl.xml.data.CRC32=d46e03e0 nbproject/build-impl.xml.script.CRC32=785323e7 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.71.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.72.1 diff --git a/UMLFileTypes/nbproject/project.properties b/UMLFileTypes/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLFileTypes/nbproject/project.properties +++ b/UMLFileTypes/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLFileTypes/src/org/uml/filetype/cdg/renaming/MyClassDiagramRenameTable.java b/UMLFileTypes/src/org/uml/filetype/cdg/renaming/MyClassDiagramRenameTable.java index 92b0013..556b6a9 100644 --- a/UMLFileTypes/src/org/uml/filetype/cdg/renaming/MyClassDiagramRenameTable.java +++ b/UMLFileTypes/src/org/uml/filetype/cdg/renaming/MyClassDiagramRenameTable.java @@ -15,6 +15,7 @@ public class MyClassDiagramRenameTable implements PropertyChangeListener { MyRelationsRenameTable relationRenames; public MyClassDiagramRenameTable(ClassDiagram classDiagram) { + classDiagram.updateComponentPackages(); this.componentRenames = new MyComponentsRenameTable(this, classDiagram); this.relationRenames = new MyRelationsRenameTable(this, classDiagram); @@ -30,6 +31,7 @@ public MyRelationsRenameTable getRelationRenames() { } public final void updateClassDiagram(ClassDiagram classDiagram) { + classDiagram.updateComponentPackages(); componentRenames.updateComponents(classDiagram); relationRenames.updateRelations(classDiagram); diff --git a/UMLModel/manifest.mf b/UMLModel/manifest.mf index 58671db..e23c37e 100644 --- a/UMLModel/manifest.mf +++ b/UMLModel/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false OpenIDE-Module: org.uml.model OpenIDE-Module-Localizing-Bundle: org/uml/model/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.4.1 diff --git a/UMLModel/nbproject/project.properties b/UMLModel/nbproject/project.properties index 19ee4dd..0398487 100644 --- a/UMLModel/nbproject/project.properties +++ b/UMLModel/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 06 Mar 2016 16:07:19 -0800 +#Sat, 29 Sep 2018 20:19:10 +0200 javac.source=1.8 javac.compilerargs=-Xlint -Xlint\:-serial license.file=LICENSE-2.0.txt diff --git a/UMLModel/src/org/uml/memberparser/MemberParser.java b/UMLModel/src/org/uml/memberparser/MemberParser.java index 835b5fe..68d6f38 100644 --- a/UMLModel/src/org/uml/memberparser/MemberParser.java +++ b/UMLModel/src/org/uml/memberparser/MemberParser.java @@ -2,9 +2,16 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParseException; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.type.Type; +import java.util.ArrayList; import java.util.LinkedHashSet; import org.uml.model.members.Constructor; import org.uml.model.members.Field; @@ -34,7 +41,7 @@ public class MemberParser { /** * Type convention - one or more alphanum, <, >, [, ] characters */ - static final String TYPE = "[\\w\\<\\>\\[\\]]+"; + static final String TYPE = "[\\w\\<\\,\\>\\[\\]]+"; /** * Field convention - optional type, spaces, name. . @@ -136,7 +143,8 @@ private static String getFieldOrArgumentType(String signature) throws ParseExcep String type; BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); FieldDeclaration declaration = (FieldDeclaration) bd; - type = declaration.getType().toString(); + NodeList variables = declaration.getVariables(); + type = variables.get(0).getType().asString().replaceAll(SPACES,""); return type; } @@ -150,7 +158,7 @@ private static String getFieldName(String signature) throws ParseException { String name; BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); FieldDeclaration declaration = (FieldDeclaration) bd; - name = declaration.getVariables().get(0).getId().getName(); + name = declaration.getVariables().get(0).getName().asString(); return name; } @@ -161,18 +169,13 @@ private static String getFieldName(String signature) throws ParseException { * @return return type of a method */ private static String getReturnType(String signature) throws ParseException { - String type; - // has to empty the arguments list in order not to have an argument exception - signature = signature.replaceAll("\\(.*\\)", "()"); - if (signature.contains("void")) { - type = "void"; - } else { - BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); - - AnnotationMemberDeclaration declaration = (AnnotationMemberDeclaration) bd; - type = declaration.getType().toString(); + BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); + if (!(bd instanceof MethodDeclaration)) { + throw new ParseException("Invalid method '"+signature+"'"); } - return type; + MethodDeclaration declaration = (MethodDeclaration) bd; + Type type = declaration.getType(); + return type.asString(); } /** @@ -182,30 +185,27 @@ private static String getReturnType(String signature) throws ParseException { * @return name */ private static String getMethodName(String signature) throws ParseException { - String name; - // Need to empty the arguments list in order not to an argument exception - signature = signature.replaceAll("\\(.*\\)", "()"); - if (signature.contains("void")) { - signature = signature.replace("void", "int"); // arbitrary type, not to have exception because of void - } BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); - AnnotationMemberDeclaration declaration = (AnnotationMemberDeclaration) bd; - name = declaration.getName(); - return name; + if (!(bd instanceof MethodDeclaration)) { + throw new ParseException("Invalid method '"+signature+"'"); + } + MethodDeclaration declaration = (MethodDeclaration) bd; + SimpleName name = declaration.getName(); + return name.asString(); } private static LinkedHashSet getArguments(String signature) throws ParseException { - LinkedHashSet arguments = new LinkedHashSet<>(); - String argumentString = signature.substring(signature.indexOf("(") + 1, signature.indexOf(")")); - String[] argumentsArray = argumentString.split(","); - for (String argument : argumentsArray) { - if (!argument.equals("")) { - argument = argument.trim() + ";"; - - BodyDeclaration bd = JavaParser.parseBodyDeclaration(argument); - FieldDeclaration declaration = (FieldDeclaration) bd; - arguments.add(new MethodArgument(declaration.getType().toString(), declaration.getVariables().get(0).getId().getName())); - } + BodyDeclaration bd = JavaParser.parseBodyDeclaration(signature + ";"); + if (!(bd instanceof MethodDeclaration)) { + throw new ParseException("Invalid method '"+signature+"'"); + } + MethodDeclaration declaration = (MethodDeclaration) bd; + LinkedHashSet arguments = new LinkedHashSet(); + NodeList parameters = declaration.getParameters(); + for (Parameter parameter : parameters) { + String name = parameter.getName().asString(); + String type = parameter.getType().asString(); + arguments.add(new MethodArgument(type,name)); } return arguments; } diff --git a/UMLModel/src/org/uml/model/ClassDiagram.java b/UMLModel/src/org/uml/model/ClassDiagram.java index c27b0b7..d8bbfb5 100644 --- a/UMLModel/src/org/uml/model/ClassDiagram.java +++ b/UMLModel/src/org/uml/model/ClassDiagram.java @@ -1,12 +1,15 @@ package org.uml.model; +import java.awt.Rectangle; import java.io.Serializable; +import java.util.ArrayList; import org.uml.model.components.ComponentBase; import org.uml.model.relations.RelationBase; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import org.uml.model.components.PackageComponent; /** * UML Class Diagrams which can contain class, interface and enum components, @@ -24,6 +27,25 @@ public class ClassDiagram extends ContainerBase implements Serial */ private final HashSet relations; + /** + * Getters automatic generation setting + */ + private GenerationSetting getterGeneration; + /** + * Setters automatic generation setting + */ + private GenerationSetting setterGeneration; + + /** + * Show/Hide members + */ + private boolean showMembers; + + /** + * Leave space for adding a member with double-click + */ + private boolean showAddMember; + /** * Constructs a ClassDiagram object with name set to "UML ClassDiagram" * and an empty relations set. @@ -31,6 +53,10 @@ public class ClassDiagram extends ContainerBase implements Serial public ClassDiagram() { super("UML Class Diagram"); this.relations = new HashSet<>(); + getterGeneration = GenerationSetting.DISABLED; + setterGeneration = GenerationSetting.DISABLED; + showMembers = true; + showAddMember = true; } /** @@ -110,4 +136,71 @@ public void setName(String newName) { name = newName; pcs.firePropertyChange("name", oldName, newName); } + + public boolean isShowMembers() { + return showMembers; + } + + public void setShowMembers(boolean showMembers) { + boolean old = this.showMembers; + this.showMembers = showMembers; + pcs.firePropertyChange("SHOW_MEMBERS", old, showMembers); + } + + public boolean isShowAddMember() { + return showAddMember; + } + + public void setShowAddMember(boolean showAddMember) { + boolean old = this.showAddMember; + this.showAddMember = showAddMember; + pcs.firePropertyChange("SHOW_ADD_MEMBER", old, showAddMember); + } + + /** + * Automatically sets component packages: + * - if a PackageComponent visually includes a component, then it is its component package + * - otherwise it is null + */ + public void updateComponentPackages() { + //System.out.println("Update component packages..."); + List list = new ArrayList(components); + // For each components, + for (int j=0;jj components are visually after j + ComponentBase component = list.get(i); + Rectangle componentBounds = component.getBounds(); + if (!packageBounds.contains(componentBounds)) + continue; + component.setComponentPackage(packageComponent); + //System.err.println(packageComponent.getName()+" includes "+component.getName()); + } + } + /*for (ComponentBase component : components) { + String fullPackage = component.getFullParentPackage(); + System.err.println(component.getName()+":"+fullPackage); + }*/ + } + + public GenerationSetting getGetterGeneration() { + return getterGeneration; + } + + public void setGetterGeneration(GenerationSetting generateGetters) { + this.getterGeneration = generateGetters; + } + + public GenerationSetting getSetterGeneration() { + return setterGeneration; + } + + public void setSetterGeneration(GenerationSetting generateSetters) { + this.setterGeneration = generateSetters; + } } diff --git a/UMLModel/src/org/uml/model/ContainerBase.java b/UMLModel/src/org/uml/model/ContainerBase.java index 31b60df..d1927d8 100644 --- a/UMLModel/src/org/uml/model/ContainerBase.java +++ b/UMLModel/src/org/uml/model/ContainerBase.java @@ -2,8 +2,9 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedHashSet; +import java.util.List; /** * Abstract class representing a container which can contain some components. @@ -25,7 +26,7 @@ public abstract class ContainerBase impleme /** * Components contained in the container. */ - protected LinkedHashSet components = new LinkedHashSet<>(); + protected List components = new ArrayList(); /** * Property change support and related methods. @@ -73,6 +74,24 @@ protected void addComponentToContainter(T component) { components.add(component); pcs.firePropertyChange("ADD_COMPONENT", null, component); } + + public void updateComponentOrder(List list) { + components.clear(); + for (T component : list) { + components.add(component); + } + pcs.firePropertyChange("COMPONENT_ORDER", null, this); + } + + public void moveUpComponent(T component) { + for (int i=1;i fields; + private List fields; /** * Set of constructors this class contains. */ - private LinkedHashSet constructors; + private List constructors; /** * Set of method this class contains. */ - private LinkedHashSet methods; - + private List methods; + + /** + * Getters automatic generation setting + */ + private GenerationSetting getterGeneration; + /** + * Setters automatic generation setting + */ + private GenerationSetting setterGeneration; + /** * Default constructor. Sets name to default value. *