diff options
Diffstat (limited to 'javaparser-core/src/main/java/com/github/javaparser/ast')
198 files changed, 42159 insertions, 0 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java new file mode 100644 index 000000000..63e96b87a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast; + +/** + * Access specifier. Represents one of the possible levels of + * access permitted by the language. + * + * @author Federico Tomassetti + * @since July 2014 + */ +public enum AccessSpecifier { + + PUBLIC("public"), + PRIVATE("private"), + PROTECTED("protected"), + DEFAULT(""); + + private String codeRepresenation; + + AccessSpecifier(String codeRepresentation) { + this.codeRepresenation = codeRepresentation; + } + + public String asString() { + return this.codeRepresenation; + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java new file mode 100644 index 000000000..33d58e49a --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java new file mode 100644 index 000000000..09148fe7c --- /dev/null +++ b/javaparser-core/src/main/java/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 <code>new int[1][2];</code> 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<ArrayCreationLevel> { + + @OptionalProperty + private Expression dimension; + + private NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange); + setDimension(dimension); + setAnnotations(annotations); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Expression> getDimension() { + return Optional.ofNullable(dimension); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<AnnotationExpr> getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationLevel setAnnotations(final NodeList<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java new file mode 100644 index 000000000..fd8bb20a0 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java @@ -0,0 +1,694 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <p> + * This class represents the entire compilation unit. Each java file denotes a + * compilation unit. + * </p> + * 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<ImportDeclaration> imports; + + private NodeList<TypeDeclaration<?>> 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<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> 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<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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.<br> + * 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<Comment> getComments() { + return this.getAllContainedComments(); + } + + /** + * Retrieves the list of imports declared in this compilation unit or + * <code>null</code> if there is no import. + * + * @return the list of imports or <code>none</code> if there is no import + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ImportDeclaration> getImports() { + return imports; + } + + public ImportDeclaration getImport(int i) { + return getImports().get(i); + } + + /** + * Retrieves the package declaration of this compilation unit.<br> + * If this compilation unit has no package declaration (default package), + * <code>Optional.none()</code> is returned. + * + * @return the package declaration or <code>none</code> + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<PackageDeclaration> getPackageDeclaration() { + return Optional.ofNullable(packageDeclaration); + } + + /** + * Return the list of top level types declared in this compilation unit.<br> + * If there are no types declared, <code>none</code> is returned. + * + * @return the list of types or <code>none</code> null if there is no type + * @see AnnotationDeclaration + * @see ClassOrInterfaceDeclaration + * @see EnumDeclaration + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<TypeDeclaration<?>> getTypes() { + return types; + } + + /** + * Convenience method that wraps <code>getTypes()</code>.<br> + * If <code>i</code> is out of bounds, throws <code>IndexOutOfBoundsException.</code> + * + * @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 + * <code>null</code>. + * + * @param imports the list of imports + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public CompilationUnit setImports(final NodeList<ImportDeclaration> 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 <code>null</code> 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<TypeDeclaration<?>> 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<TypeDeclaration<?>> copy = new NodeList<>(); + copy.addAll(getTypes()); + getTypes().set(i, type); + notifyPropertyChange(ObservableProperty.TYPES, copy, types); + return this; + } + + public CompilationUnit addType(TypeDeclaration<?> type) { + NodeList<TypeDeclaration<?>> 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<br> + * shorthand for {@link #addImport(String, boolean, boolean)} with name,false,false + * + * @param name the import name + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit addImport(String name) { + return addImport(name, false, false); + } + + /** + * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br> + * shorthand for {@link #addImport(String)} with clazz.getName() + * + * @param clazz the class to import + * @return this, the {@link CompilationUnit} + * @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<br> + * <b>This method check if no import with the same name is already in the list</b> + * + * @param name the import name + * @param isStatic is it an "import static" + * @param isAsterisk does the import end with ".*" + * @return this, the {@link CompilationUnit} + */ + public CompilationUnit addImport(String name, boolean isStatic, boolean isAsterisk) { + 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<ClassOrInterfaceDeclaration> 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<ClassOrInterfaceDeclaration> 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<EnumDeclaration> 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<String> 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<TypeDeclaration<?>> 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<AnnotationDeclaration> 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<ModuleDeclaration> 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<Storage> 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<String> 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<CompilationUnit, String> 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<CompilationUnit> 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-core/src/main/java/com/github/javaparser/ast/DataKey.java b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java new file mode 100644 index 000000000..2f2115d0e --- /dev/null +++ b/javaparser-core/src/main/java/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: + * <p> + * <pre> + * <code> + * public static final DataKey<Role> ROLE = new DataKey<Role>() { }; + * </code> + * </pre> + * <p> + * This code was taken from the <a href="http://wicket.apache.org/">Wicket project</a>. + * + * @param <T> The type of the object which is stored + * @see Node#getData(DataKey) + */ +public abstract class DataKey<T> { + @Override + public int hashCode() { + return getClass().hashCode(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj != null && getClass().equals(obj.getClass()); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java new file mode 100644 index 000000000..88ab096e5 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>import com.github.javaparser.JavaParser;</code> + * <br/><code>import com.github.javaparser.*;</code> + * <br/><code>import com.github.javaparser.JavaParser.*; </code> + * <br/><code>import static com.github.javaparser.JavaParser.*;</code> + * <br/><code>import static com.github.javaparser.JavaParser.parse;</code> + * + * <p>The name does not include the asterisk or the static keyword.</p> + * @author Julio Vilmar Gesser + */ +public final class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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-core/src/main/java/com/github/javaparser/ast/Modifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java new file mode 100644 index 000000000..b6d0309af --- /dev/null +++ b/javaparser-core/src/main/java/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<Modifier> toEnumSet() {
+ return EnumSet.of(this);
+ }
+
+ public static AccessSpecifier getAccessSpecifier(EnumSet<Modifier> modifiers) {
+ if (modifiers.contains(Modifier.PUBLIC)) {
+ return AccessSpecifier.PUBLIC;
+ } else if (modifiers.contains(Modifier.PROTECTED)) {
+ return AccessSpecifier.PROTECTED;
+ } else if (modifiers.contains(Modifier.PRIVATE)) {
+ return AccessSpecifier.PRIVATE;
+ } else {
+ return AccessSpecifier.DEFAULT;
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java new file mode 100644 index 000000000..98d0bbcb6 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -0,0 +1,1004 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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.Range; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.comments.Comment; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.nodeTypes.NodeWithRange; +import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange; +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.visitor.CloneVisitor; +import com.github.javaparser.ast.visitor.EqualsVisitor; +import com.github.javaparser.ast.visitor.HashCodeVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.metamodel.*; +import com.github.javaparser.printer.PrettyPrinter; +import com.github.javaparser.printer.PrettyPrinterConfiguration; +import com.github.javaparser.resolution.SymbolResolver; +import javax.annotation.Generated; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; +import static com.github.javaparser.ast.Node.Parsedness.PARSED; +import static com.github.javaparser.ast.Node.TreeTraversal.PREORDER; +import static java.util.Collections.unmodifiableList; +import static java.util.Spliterator.DISTINCT; +import static java.util.Spliterator.NONNULL; +import com.github.javaparser.ast.Node; +import com.github.javaparser.metamodel.NodeMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; + +/** + * Base class for all nodes of the abstract syntax tree. + * <h2>Construction</h2> + * <p>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... + * <ul> + * <li>use a convenience method, like "addStatement(...)", or if none are available...</li> + * <li>use a convenient constructor, like ClassOrInterfaceType(String name), or if none are available...</li> + * <li>use the default constructor.</li> + * <li>Alternatively, use one of the JavaParser.parse(snippet) methods.</li> + * </ul> + * ... and use the various methods on the node to initialize it further, if needed. + * <h2>Parent/child</h2> + * <p>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. + * <h2>Comments</h2> + * <p>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. + * <h2>Positions</h2> + * <p>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 <i>abstract</i> 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. + * <h2>Observers</h2> + * <p>It is possible to add observers to the the tree. + * Any change in the tree is sent as an event to any observers watching. + * <h2>Visitors</h2> + * <p>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: + * <pre>node.accept(visitor, argument);</pre> + * where argument is an object of your choice (often simply null.) + * + * @author Julio Vilmar Gesser + */ +public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable, NodeWithRange<Node>, NodeWithTokenRange<Node> { + + /** + * 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<NodeWithRange<?>> 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<Node> childNodes = new LinkedList<>(); + + @InternalProperty + private List<Comment> orphanComments = new LinkedList<>(); + + @InternalProperty + private IdentityHashMap<DataKey<?>, Object> data = null; + + @OptionalProperty + private Comment comment; + + @InternalProperty + private List<AstObserver> 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<Comment> getComment() { + return Optional.ofNullable(comment); + } + + /** + * @return the range of characters in the source code that this node covers. + */ + public Optional<Range> getRange() { + return Optional.ofNullable(range); + } + + /** + * @return the range of tokens that this node covers. + */ + public Optional<TokenRange> 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<Node> 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<Node> 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. + * <p> + * For example, comments at the end of methods (immediately before the parenthesis) + * or at the end of CompilationUnit are orphan comments. + * <p> + * When more than one comment preceeds a statement, the one immediately preceding it + * it is associated with the statements, while the others are orphans. + * <p> + * Changes to this list are not persisted. + * + * @return all comments that cannot be attributed to a concept + */ + public List<Comment> 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<Comment> getAllContainedComments() { + List<Comment> 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<Node> 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 <N extends Node> List<N> getChildNodesByType(Class<N> clazz) { + List<N> 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 <N extends Node> List<N> getNodesByType(Class<N> clazz) { + return getChildNodesByType(clazz); + } + + /** + * Gets data for this node using the given key. + * + * @param <M> 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> M getData(final DataKey<M> 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 <M> The type of data + * @param key The singleton key for the data + * @param object The data object + * @see DataKey + */ + public <M> void setData(DataKey<M> 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. + * <p> + * 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<? extends Node> list) { + if (list != null) { + list.setParentNode(getParentNodeForChildren()); + } + } + + public <P> 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 <i>ObserverRegistrationMode</i>. + */ + 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<CompilationUnit> 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<SymbolResolver> SYMBOL_RESOLVER_KEY = new DataKey<SymbolResolver>() { + }; + + public enum TreeTraversal { + + PREORDER, BREADTHFIRST, POSTORDER, PARENTS, DIRECT_CHILDREN + } + + private Iterator<Node> 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<Node> treeIterable(TreeTraversal traversal) { + return () -> treeIterator(traversal); + } + + /** + * Make a stream of nodes using traversal algorithm "traversal". + */ + public Stream<Node> stream(TreeTraversal traversal) { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(traversal), NONNULL | DISTINCT), false); + } + + /** + * Make a stream of nodes using pre-order traversal. + */ + public Stream<Node> stream() { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(PREORDER), NONNULL | DISTINCT), false); + } + + /** + * Walks the AST, calling the consumer for every node, with traversal algorithm "traversal". + * <br/>This is the most general walk method. All other walk and findAll methods are based on this. + */ + public void walk(TreeTraversal traversal, Consumer<Node> 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<Node> consumer) { + walk(PREORDER, consumer); + } + + /** + * Walks the AST with pre-order traversal, calling the consumer for every node of type "nodeType". + */ + public <T extends Node> void walk(Class<T> nodeType, Consumer<T> 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 <T extends Node> List<T> findAll(Class<T> nodeType) { + final List<T> 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 <T extends Node> List<T> findAll(Class<T> nodeType, Predicate<T> predicate) { + final List<T> 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. <br/>This is the + * most general findFirst method. All other findFirst methods are based on this. + */ + public <T> Optional<T> findFirst(TreeTraversal traversal, Function<Node, Optional<T>> consumer) { + for (Node node : treeIterable(traversal)) { + final Optional<T> 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 <N extends Node> Optional<N> findFirst(Class<N> 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 <N extends Node> Optional<N> findFirst(Class<N> nodeType, Predicate<N> 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 <N extends Node> Optional<N> findParent(Class<N> 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 <a href="https://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first traversal</a> + */ + public static class BreadthFirstIterator implements Iterator<Node> { + + private final Queue<Node> 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<Node> { + + private final Iterator<Node> 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<Node> { + + 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 <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a> + */ + public static class PreOrderIterator implements Iterator<Node> { + + private final Stack<Node> 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<Node> 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 <a href="https://en.wikipedia.org/wiki/Post-order">Post-order traversal</a> + */ + public static class PostOrderIterator implements Iterator<Node> { + + private final Stack<List<Node>> nodesStack = new Stack<>(); + + private final Stack<Integer> 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<Node> 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<Node> 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<Node> nodes = nodesStack.peek(); + final int cursor = cursorStack.pop(); + cursorStack.push(cursor + 1); + return nodes.get(cursor); + } + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java new file mode 100644 index 000000000..f370e960d --- /dev/null +++ b/javaparser-core/src/main/java/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 <N> the type of nodes contained. + */ +public class NodeList<N extends Node> implements List<N>, Iterable<N>, HasParentNode<NodeList<N>>, Visitable, Observable { + @InternalProperty + private List<N> innerList = new ArrayList<>(0); + + private Node parentNode; + + private List<AstObserver> observers = new ArrayList<>(); + + public NodeList() { + parentNode = null; + } + + public NodeList(Collection<N> 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 <X extends Node> NodeList<X> nodeList(X... nodes) { + final NodeList<X> nodeList = new NodeList<>(); + Collections.addAll(nodeList, nodes); + return nodeList; + } + + public static <X extends Node> NodeList<X> nodeList(Collection<X> nodes) { + final NodeList<X> nodeList = new NodeList<>(); + nodeList.addAll(nodes); + return nodeList; + } + + public static <X extends Node> NodeList<X> nodeList(NodeList<X> nodes) { + final NodeList<X> 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<N> 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<? super N> comparator) { + innerList.sort(comparator); + } + + public void addAll(NodeList<N> 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<N> addFirst(N node) { + add(0, node); + return this; + } + + /** + * Inserts the node after all other nodes. (This is simply an alias for add.) + */ + public NodeList<N> addLast(N node) { + add(node); + return this; + } + + /** + * Inserts the node after afterThisNode. + * + * @throws IllegalArgumentException when afterThisNode is not in this list. + */ + public NodeList<N> 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<N> 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<Node> getParentNode() { + return Optional.ofNullable(parentNode); + } + + /** + * Sets the parentNode + * + * @param parentNode the parentNode + * @return this, the NodeList + */ + @Override + public NodeList<N> setParentNode(Node parentNode) { + this.parentNode = parentNode; + setAsParentNodeOf(innerList); + return this; + } + + @Override + public Node getParentNodeForChildren() { + return parentNode; + } + + @Override + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + /** + * @see java.lang.Iterable#forEach(java.util.function.Consumer) + */ + @Override + public void forEach(Consumer<? super N> 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> 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<? extends N> c) { + c.forEach(this::add); + return !c.isEmpty(); + } + + /** + * @see java.util.List#addAll(int, java.util.Collection) + */ + @Override + public boolean addAll(int index, Collection<? extends N> 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<N> 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<? super N> 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<N> listIterator() { + return innerList.listIterator(); + } + + /** + * @see java.util.List#listIterator(int) + */ + @Override + public ListIterator<N> listIterator(int index) { + return innerList.listIterator(index); + } + + /** + * @see java.util.Collection#parallelStream() + */ + @Override + public Stream<N> parallelStream() { + return innerList.parallelStream(); + } + + /** + * @see java.util.List#subList(int, int) + */ + @Override + public List<N> subList(int fromIndex, int toIndex) { + return innerList.subList(fromIndex, toIndex); + } + + /** + * @see java.util.List#spliterator() + */ + @Override + public Spliterator<N> 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<? super NodeList<N>> consumer) { + if (isNonEmpty()) + consumer.accept(this); + } + + public static <T extends Node> Collector<T, NodeList<T>, NodeList<T>> toNodeList() { + return Collector.of(NodeList::new, NodeList::add, (left, right) -> { + left.addAll(right); + return left; + }); + } + + private void setAsParentNodeOf(List<? extends Node> 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-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java new file mode 100644 index 000000000..65a1ca74a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.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.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. + * <br/><code>package com.github.javaparser.ast;</code> + * <br/><code>@Wonderful package anything.can.be.annotated.nowadays;</code> + * + * @author Julio Vilmar Gesser + */ +public final class PackageDeclaration extends Node implements NodeWithAnnotations<PackageDeclaration>, NodeWithName<PackageDeclaration> { + + private NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> annotations, Name name) { + super(tokenRange); + setAnnotations(annotations); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + /** + * Retrieves the list of annotations declared before the package + * declaration. Return <code>null</code> if there are no annotations. + * + * @return list of annotations or <code>null</code> + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<AnnotationExpr> 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<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java new file mode 100644 index 000000000..aa793efb9 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.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.<br/><code>@interface X { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> implements NodeWithAbstractModifier<AnnotationDeclaration>, Resolvable<ResolvedAnnotationDeclaration> { + + public AnnotationDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>()); + } + + public AnnotationDeclaration(EnumSet<Modifier> modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>()); + } + + @AllFieldsConstructor + public AnnotationDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) { + super(tokenRange, modifiers, annotations, name, members); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AnnotationDeclaration> 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<AnnotationDeclaration> toAnnotationDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java new file mode 100644 index 000000000..48b6db6f5 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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 <code>@interface X { int id(); }</code> + * <p> + * <br/>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<AnnotationMemberDeclaration> implements NodeWithJavadoc<AnnotationMemberDeclaration>, NodeWithSimpleName<AnnotationMemberDeclaration>, NodeWithType<AnnotationMemberDeclaration, Type>, NodeWithPublicModifier<AnnotationMemberDeclaration>, NodeWithAbstractModifier<AnnotationMemberDeclaration>, Resolvable<ResolvedAnnotationMemberDeclaration> { + + private EnumSet<Modifier> 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<Modifier> modifiers, Type type, String name, Expression defaultValue) { + this(null, modifiers, new NodeList<>(), type, new SimpleName(name), defaultValue); + } + + @AllFieldsConstructor + public AnnotationMemberDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> 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<Modifier> modifiers, NodeList<AnnotationExpr> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> 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<Modifier> 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<Modifier> 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<AnnotationMemberDeclaration> 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<AnnotationMemberDeclaration> toAnnotationMemberDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java new file mode 100644 index 000000000..dc871e3cd --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<T extends BodyDeclaration<?>> extends Node implements NodeWithAnnotations<T> { + + private NodeList<AnnotationExpr> annotations; + + public BodyDeclaration() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public BodyDeclaration(NodeList<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange); + setAnnotations(annotations); + customInitialization(); + } + + protected BodyDeclaration(TokenRange range) { + this(range, new NodeList<>()); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<AnnotationExpr> getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setAnnotations(final NodeList<AnnotationExpr> 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<AnnotationDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAnnotationMemberDeclaration(Consumer<AnnotationMemberDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCallableDeclaration(Consumer<CallableDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceDeclaration(Consumer<ClassOrInterfaceDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConstructorDeclaration(Consumer<ConstructorDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumConstantDeclaration(Consumer<EnumConstantDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnumDeclaration(Consumer<EnumDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldDeclaration(Consumer<FieldDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInitializerDeclaration(Consumer<InitializerDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodDeclaration(Consumer<MethodDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeDeclaration(Consumer<TypeDeclaration> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AnnotationDeclaration> toAnnotationDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AnnotationMemberDeclaration> toAnnotationMemberDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<CallableDeclaration> toCallableDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ClassOrInterfaceDeclaration> toClassOrInterfaceDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ConstructorDeclaration> toConstructorDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EnumConstantDeclaration> toEnumConstantDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EnumDeclaration> toEnumDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<FieldDeclaration> toFieldDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<InitializerDeclaration> toInitializerDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MethodDeclaration> toMethodDeclaration() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TypeDeclaration> toTypeDeclaration() { + return Optional.empty(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java new file mode 100644 index 000000000..e2e41fe15 --- /dev/null +++ b/javaparser-core/src/main/java/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<T extends CallableDeclaration<?>> extends BodyDeclaration<T> implements NodeWithAccessModifiers<T>, NodeWithDeclaration, NodeWithSimpleName<T>, NodeWithParameters<T>, NodeWithThrownExceptions<T>, NodeWithTypeParameters<T>, NodeWithJavadoc<T>, NodeWithAbstractModifier<T>, NodeWithStaticModifier<T>, NodeWithFinalModifier<T>, NodeWithStrictfpModifier<T> { + + private EnumSet<Modifier> modifiers; + + private NodeList<TypeParameter> typeParameters; + + private SimpleName name; + + private NodeList<Parameter> parameters; + + private NodeList<ReferenceType> thrownExceptions; + + @OptionalProperty + private ReceiverParameter receiverParameter; + + @AllFieldsConstructor + CallableDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> 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<Modifier> getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setModifiers(final EnumSet<Modifier> 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<Parameter> getParameters() { + return parameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setParameters(final NodeList<Parameter> 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<ReferenceType> getThrownExceptions() { + return thrownExceptions; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setThrownExceptions(final NodeList<ReferenceType> 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<TypeParameter> getTypeParameters() { + return typeParameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setTypeParameters(final NodeList<TypeParameter> 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. + * <p/>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<Type> parameterTypes; + + private Signature(String name, List<Type> parameterTypes) { + this.name = name; + this.parameterTypes = parameterTypes; + } + + public String getName() { + return name; + } + + public List<Type> 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<Type>) 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<CallableDeclaration> action) { + action.accept(this); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<ReceiverParameter> 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<CallableDeclaration> toCallableDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java new file mode 100644 index 000000000..a275066ad --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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.<br/><code>class X { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration>, NodeWithTypeParameters<ClassOrInterfaceDeclaration>, NodeWithAbstractModifier<ClassOrInterfaceDeclaration>, NodeWithFinalModifier<ClassOrInterfaceDeclaration>, NodeWithConstructors<ClassOrInterfaceDeclaration>, Resolvable<ResolvedReferenceTypeDeclaration> { + + private boolean isInterface; + + private NodeList<TypeParameter> typeParameters; + + // Can contain more than one item if this is an interface + private NodeList<ClassOrInterfaceType> extendedTypes; + + private NodeList<ClassOrInterfaceType> 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<Modifier> 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<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final boolean isInterface, final SimpleName name, final NodeList<TypeParameter> typeParameters, final NodeList<ClassOrInterfaceType> extendedTypes, final NodeList<ClassOrInterfaceType> implementedTypes, final NodeList<BodyDeclaration<?>> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ClassOrInterfaceType> getExtendedTypes() { + return extendedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ClassOrInterfaceType> getImplementedTypes() { + return implementedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<TypeParameter> 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<ClassOrInterfaceType> 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<ClassOrInterfaceType> 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<TypeParameter> 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<ClassOrInterfaceDeclaration> 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<ClassOrInterfaceDeclaration> toClassOrInterfaceDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java new file mode 100644 index 000000000..ab1dad9cb --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java @@ -0,0 +1,248 @@ +/* + * 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: <code>class X { X() { } }</code> where X(){} is the constructor declaration. + * + * <br/>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<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration>, Resolvable<ResolvedConstructorDeclaration> { + + 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<Modifier> modifiers, String name) { + this(null, modifiers, new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); + } + + public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body) { + this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, null); + } + + @AllFieldsConstructor + public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Modifier> modifiers) { + return super.setModifiers(modifiers); + } + + @Override + public ConstructorDeclaration setName(final SimpleName name) { + return super.setName(name); + } + + @Override + public ConstructorDeclaration setParameters(final NodeList<Parameter> parameters) { + return super.setParameters(parameters); + } + + @Override + public ConstructorDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) { + return super.setThrownExceptions(thrownExceptions); + } + + @Override + public ConstructorDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters) { + return super.setTypeParameters(typeParameters); + } + + /** + * The declaration returned has this schema: + * <p> + * [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<ConstructorDeclaration> 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<ConstructorDeclaration> toConstructorDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java new file mode 100644 index 000000000..5a331e4a6 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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: <code>enum X { A(1), B(2) }</code> + * + * @author Julio Vilmar Gesser + */ +public final class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> implements NodeWithJavadoc<EnumConstantDeclaration>, NodeWithSimpleName<EnumConstantDeclaration>, NodeWithArguments<EnumConstantDeclaration>, Resolvable<ResolvedEnumConstantDeclaration> { + + private SimpleName name; + + private NodeList<Expression> arguments; + + private NodeList<BodyDeclaration<?>> 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<AnnotationExpr> annotations, SimpleName name, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> 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<AnnotationExpr> annotations, SimpleName name, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> classBody) { + super(tokenRange, annotations); + setName(name); + setArguments(arguments); + setClassBody(classBody); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> getArguments() { + return arguments; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<BodyDeclaration<?>> 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<Expression> 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<BodyDeclaration<?>> 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<EnumConstantDeclaration> 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<EnumConstantDeclaration> toEnumConstantDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java new file mode 100644 index 000000000..44fb1e411 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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.<br/><code>enum X { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class EnumDeclaration extends TypeDeclaration<EnumDeclaration> implements NodeWithImplements<EnumDeclaration>, NodeWithConstructors<EnumDeclaration>, Resolvable<ResolvedEnumDeclaration> { + + private NodeList<ClassOrInterfaceType> implementedTypes; + + private NodeList<EnumConstantDeclaration> entries; + + public EnumDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + public EnumDeclaration(EnumSet<Modifier> modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new NodeList<>()); + } + + @AllFieldsConstructor + public EnumDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<EnumConstantDeclaration> entries, NodeList<BodyDeclaration<?>> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<EnumConstantDeclaration> entries, NodeList<BodyDeclaration<?>> members) { + super(tokenRange, modifiers, annotations, name, members); + setImplementedTypes(implementedTypes); + setEntries(entries); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<EnumConstantDeclaration> 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<ClassOrInterfaceType> getImplementedTypes() { + return implementedTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumDeclaration setEntries(final NodeList<EnumConstantDeclaration> 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<ClassOrInterfaceType> 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<EnumDeclaration> 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<EnumDeclaration> toEnumDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java new file mode 100644 index 000000000..547e95ab9 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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: <code>class X { private static + * int a=15*15; }</code> + * + * <br/>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<FieldDeclaration> implements NodeWithJavadoc<FieldDeclaration>, NodeWithVariables<FieldDeclaration>, NodeWithAccessModifiers<FieldDeclaration>, NodeWithStaticModifier<FieldDeclaration>, NodeWithFinalModifier<FieldDeclaration>, Resolvable<ResolvedFieldDeclaration> { + + private EnumSet<Modifier> modifiers; + + @NonEmptyProperty + private NodeList<VariableDeclarator> variables; + + public FieldDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>()); + } + + public FieldDeclaration(EnumSet<Modifier> modifiers, VariableDeclarator variable) { + this(null, modifiers, new NodeList<>(), nodeList(variable)); + } + + public FieldDeclaration(EnumSet<Modifier> modifiers, NodeList<VariableDeclarator> variables) { + this(null, modifiers, new NodeList<>(), variables); + } + + @AllFieldsConstructor + public FieldDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> 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<Modifier> modifiers, Type type, String name) { + this(assertNotNull(modifiers), new VariableDeclarator(type, assertNotNull(name))); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Modifier> getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<VariableDeclarator> getVariables() { + return variables; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public FieldDeclaration setModifiers(final EnumSet<Modifier> 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<VariableDeclarator> 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, <b>will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration</b> + * + * @return the {@link MethodDeclaration} created + * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a + * class or enum + */ + public MethodDeclaration createGetter() { + if (getVariables().size() != 1) + throw new IllegalStateException("You can use this only when the field declares only 1 variable name"); + Optional<ClassOrInterfaceDeclaration> parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class); + Optional<EnumDeclaration> 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, <b>will only work if this field declares only 1 identifier and if this field is + * already added to a ClassOrInterfaceDeclaration</b> + * + * @return the {@link MethodDeclaration} created + * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a + * class or enum + */ + public MethodDeclaration createSetter() { + if (getVariables().size() != 1) + throw new IllegalStateException("You can use this only when the field declares only 1 variable name"); + Optional<ClassOrInterfaceDeclaration> parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class); + Optional<EnumDeclaration> 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<FieldDeclaration> 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<FieldDeclaration> toFieldDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java new file mode 100644 index 000000000..06fe78e85 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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: <code>class X { static { a=3; } } </code> + * + * @author Julio Vilmar Gesser + */ +public final class InitializerDeclaration extends BodyDeclaration<InitializerDeclaration> implements NodeWithJavadoc<InitializerDeclaration>, NodeWithBlockStmt<InitializerDeclaration> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<InitializerDeclaration> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<InitializerDeclaration> toInitializerDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java new file mode 100644 index 000000000..dff4cad55 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -0,0 +1,348 @@ +/* + * 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: <code>class X { public int abc() {return 1;} + * }</code> + * + * <br/>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<MethodDeclaration> implements NodeWithType<MethodDeclaration, Type>, NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithJavadoc<MethodDeclaration>, NodeWithDeclaration, NodeWithSimpleName<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrownExceptions<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration>, NodeWithAccessModifiers<MethodDeclaration>, NodeWithAbstractModifier<MethodDeclaration>, NodeWithStaticModifier<MethodDeclaration>, NodeWithFinalModifier<MethodDeclaration>, NodeWithStrictfpModifier<MethodDeclaration>, Resolvable<ResolvedMethodDeclaration> { + + 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<Modifier> 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<Modifier> modifiers, final String name, final Type type, final NodeList<Parameter> parameters) { + this(null, modifiers, new NodeList<>(), new NodeList<>(), type, new SimpleName(name), parameters, new NodeList<>(), new BlockStmt(), null); + } + + public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body) { + this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, null); + } + + @AllFieldsConstructor + public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> 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<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final boolean isDefault, final NodeList<Parameter> parameters, final NodeList<ReferenceType> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<BlockStmt> 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<Modifier> modifiers) { + return super.setModifiers(modifiers); + } + + @Override + public MethodDeclaration setName(final SimpleName name) { + return super.setName(name); + } + + @Override + public MethodDeclaration setParameters(final NodeList<Parameter> parameters) { + return super.setParameters(parameters); + } + + @Override + public MethodDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) { + return super.setThrownExceptions(thrownExceptions); + } + + @Override + public MethodDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters) { + return super.setTypeParameters(typeParameters); + } + + /** + * The declaration returned has this schema: + * <p> + * [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<MethodDeclaration> 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<MethodDeclaration> toMethodDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java new file mode 100644 index 000000000..a7cf357a2 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>Note that <a href="https://en.wikipedia.org/wiki/Parameter_(computer_programming)#Parameters_and_arguments">parameters + * are different from arguments.</a> <br/>"String x" and "float y" are the parameters in <code>int abc(String x, float + * y) {...}</code> + * + * <br/>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<Parameter, Type>, NodeWithAnnotations<Parameter>, NodeWithSimpleName<Parameter>, NodeWithFinalModifier<Parameter>, Resolvable<ResolvedParameterDeclaration> { + + private Type type; + + private boolean isVarArgs; + + private NodeList<AnnotationExpr> varArgsAnnotations; + + private EnumSet<Modifier> modifiers; + + private NodeList<AnnotationExpr> 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<Modifier> modifiers, Type type, SimpleName name) { + this(null, modifiers, new NodeList<>(), type, false, new NodeList<>(), name); + } + + @AllFieldsConstructor + public Parameter(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, boolean isVarArgs, NodeList<AnnotationExpr> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, boolean isVarArgs, NodeList<AnnotationExpr> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AnnotationExpr> 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<Modifier> getModifiers() { + return modifiers; + } + + /** + * @param annotations a null value is currently treated as an empty list. This behavior could change in the future, + * so please avoid passing null + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setAnnotations(final NodeList<AnnotationExpr> 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<Modifier> 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<AnnotationExpr> getVarArgsAnnotations() { + return varArgsAnnotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Parameter setVarArgsAnnotations(final NodeList<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java new file mode 100644 index 000000000..b0038e1eb --- /dev/null +++ b/javaparser-core/src/main/java/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 <a href="http://blog.joda.org/2015/12/explicit-receiver-parameters.html">"receiver parameter" feature of Java</a>. + * + * <br/>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<ReceiverParameter, Type>, NodeWithAnnotations<ReceiverParameter>, NodeWithName<ReceiverParameter> { + + private Type type; + + private NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AnnotationExpr> 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<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java new file mode 100644 index 000000000..06f9753b1 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.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.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<T extends TypeDeclaration<?>> extends BodyDeclaration<T> implements NodeWithSimpleName<T>, NodeWithJavadoc<T>, NodeWithMembers<T>, NodeWithAccessModifiers<T>, NodeWithStaticModifier<T>, NodeWithStrictfpModifier<T> { + + private SimpleName name; + + private EnumSet<Modifier> modifiers; + + private NodeList<BodyDeclaration<?>> members; + + public TypeDeclaration() { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>()); + } + + public TypeDeclaration(EnumSet<Modifier> modifiers, String name) { + this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>()); + } + + @AllFieldsConstructor + public TypeDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> 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<BodyDeclaration<?>> members = getMembers(); + members.add(decl); + return (T) this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<BodyDeclaration<?>> getMembers() { + return members; + } + + /** + * Return the modifiers of this type declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @SuppressWarnings("unchecked") + public T setMembers(final NodeList<BodyDeclaration<?>> 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<Modifier> 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<CallableDeclaration<?>> 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<TypeDeclaration> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TypeDeclaration> toTypeDeclaration() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java new file mode 100644 index 000000000..0d342ac58 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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.<br/>In <code>int x = 14, y = 3;</code> "int x = 14" and "int y = 3" are + * VariableDeclarators. + * <p/>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<VariableDeclarator, Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedFieldDeclaration> { + + 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 <code>=</code> 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<Type> currentMaxCommonType = nodeWithVariables.getMaximumCommonType(); + List<Type> 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<Type> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> 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-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java new file mode 100644 index 000000000..8d30b2862 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.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.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; + +/** + * <p> + * AST node that represent block comments. + * </p> + * Block comments can has multi lines and are delimited by "/*" and + * "*/". + * + * @author Julio Vilmar Gesser + */ +public final class BlockComment extends Comment { + + public BlockComment() { + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<BlockComment> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BlockComment> toBlockComment() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java new file mode 100644 index 000000000..0c5f6b4a3 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<Node> 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<BlockComment> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifJavadocComment(Consumer<JavadocComment> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLineComment(Consumer<LineComment> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BlockComment> toBlockComment() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<JavadocComment> toJavadocComment() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LineComment> toLineComment() { + return Optional.empty(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java new file mode 100644 index 000000000..f3f25777e --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.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<Comment> comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); + + public CommentsCollection() { + } + + public CommentsCollection(Collection<Comment> commentsToCopy) { + comments.addAll(commentsToCopy); + } + + public Set<LineComment> getLineComments() { + return comments.stream() + .filter(comment -> comment instanceof LineComment) + .map(comment -> (LineComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set<BlockComment> getBlockComments() { + return comments.stream() + .filter(comment -> comment instanceof BlockComment) + .map(comment -> (BlockComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public Set<JavadocComment> getJavadocComments() { + return comments.stream() + .filter(comment -> comment instanceof JavadocComment) + .map(comment -> (JavadocComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + } + + public void addComment(Comment comment) { + comments.add(comment); + } + + public boolean contains(Comment comment) { + 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<Comment> getComments() { + return comments; + } + + public int size() { + return comments.size(); + } + + public CommentsCollection minus(CommentsCollection other) { + CommentsCollection result = new CommentsCollection(); + result.comments.addAll( + comments.stream() + .filter(comment -> !other.contains(comment)) + .collect(Collectors.toList())); + return result; + } + + public CommentsCollection copy() { + return new CommentsCollection(comments); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java new file mode 100644 index 000000000..d795997bd --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.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.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. <code>/** a comment */</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<JavadocComment> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<JavadocComment> toJavadocComment() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java new file mode 100644 index 000000000..ddbce8024 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <p> + * AST node that represent line comments. + * </p> + * 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<LineComment> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LineComment> toLineComment() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java new file mode 100644 index 000000000..31c70fb5a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.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<AnnotationExpr> { + + 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<AnnotationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AnnotationExpr> toAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java new file mode 100644 index 000000000..6945dd9ae --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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 <br/><code>getNames()[15*15]</code> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ArrayAccessExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayAccessExpr> toArrayAccessExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java new file mode 100644 index 000000000..509925803 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <code>new int[5][4][][]</code> or <code>new int[][]{{1},{2,3}}</code>. + * + * <br/>"int" is the element type. + * <br/>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<ArrayCreationLevel> levels; + + private Type elementType; + + @OptionalProperty + private ArrayInitializerExpr initializer; + + public ArrayCreationExpr() { + this(null, new ClassOrInterfaceType(), new NodeList<>(), new ArrayInitializerExpr()); + } + + @AllFieldsConstructor + public ArrayCreationExpr(Type elementType, NodeList<ArrayCreationLevel> 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<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) { + super(tokenRange); + setElementType(elementType); + setLevels(levels); + setInitializer(initializer); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<ArrayInitializerExpr> 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<ArrayCreationLevel> getLevels() { + return levels; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayCreationExpr setLevels(final NodeList<ArrayCreationLevel> 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<ArrayCreationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayCreationExpr> toArrayCreationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java new file mode 100644 index 000000000..d585a1833 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>new int[][]{{1, 1}, {2, 2}};</code> + * + * @author Julio Vilmar Gesser + */ +public final class ArrayInitializerExpr extends Expression { + + private NodeList<Expression> values; + + public ArrayInitializerExpr() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public ArrayInitializerExpr(NodeList<Expression> 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<Expression> values) { + super(tokenRange); + setValues(values); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> getValues() { + return values; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ArrayInitializerExpr setValues(final NodeList<Expression> 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<ArrayInitializerExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayInitializerExpr> toArrayInitializerExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java new file mode 100644 index 000000000..fbb46874d --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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. + * <br/><code>a=5</code> + * <br/><code>time+=500</code> + * <br/><code>watch.time+=500</code> + * <br/><code>(((time)))=100*60</code> + * <br/><code>peanut[a]=true</code> + * + * @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<BinaryExpr.Operator> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AssignExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AssignExpr> toAssignExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java new file mode 100644 index 000000000..5ec79c0af --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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. + * <br/><code>a && b</code> + * <br/><code>155 * 33</code> + * + * @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<AssignExpr.Operator> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<BinaryExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BinaryExpr> toBinaryExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java new file mode 100644 index 000000000..4be43b298 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>true</code> + * <br/><code>false</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<BooleanLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BooleanLiteralExpr> toBooleanLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java new file mode 100644 index 000000000..174d24cad --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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 <code>(long)15</code> + * + * @author Julio Vilmar Gesser + */ +public final class CastExpr extends Expression implements NodeWithType<CastExpr, Type>, NodeWithExpression<CastExpr> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<CastExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<CastExpr> toCastExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java new file mode 100644 index 000000000..bc2db0023 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.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.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. + * <br/><code>'a'</code> + * <br/><code>'\t'</code> + * <br/><code>'Ω'</code> + * <br/><code>'\177'</code> + * <br/><code>'đ©'</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<CharLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<CharLiteralExpr> toCharLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java new file mode 100644 index 000000000..729bd4ff2 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>Object.class</code> + * + * @author Julio Vilmar Gesser + */ +public final class ClassExpr extends Expression implements NodeWithType<ClassExpr, Type> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ClassExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ClassExpr> toClassExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java new file mode 100644 index 000000000..bdc50a061 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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 <code>b==0?x:y</code>, b==0 is the condition, x is thenExpr, and y is elseExpr. + * + * @author Julio Vilmar Gesser + */ +public final class ConditionalExpr extends Expression implements NodeWithCondition<ConditionalExpr> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ConditionalExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ConditionalExpr> toConditionalExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java new file mode 100644 index 000000000..007fdf320 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.expr; + +import com.github.javaparser.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. + * <br/><code>100.1f</code> + * <br/><code>23958D</code> + * <br/><code>0x4.5p1f</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<DoubleLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<DoubleLiteralExpr> toDoubleLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java new file mode 100644 index 000000000..c3d56d887 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.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.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 ( ). + * <br/><code>(1+1)</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<EnclosedExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EnclosedExpr> toEnclosedExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java new file mode 100644 index 000000000..de9e52b4c --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java @@ -0,0 +1,733 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<AnnotationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayAccessExpr(Consumer<ArrayAccessExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayCreationExpr(Consumer<ArrayCreationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifArrayInitializerExpr(Consumer<ArrayInitializerExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifAssignExpr(Consumer<AssignExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBinaryExpr(Consumer<BinaryExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBooleanLiteralExpr(Consumer<BooleanLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCastExpr(Consumer<CastExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifCharLiteralExpr(Consumer<CharLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassExpr(Consumer<ClassExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifConditionalExpr(Consumer<ConditionalExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoubleLiteralExpr(Consumer<DoubleLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEnclosedExpr(Consumer<EnclosedExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifFieldAccessExpr(Consumer<FieldAccessExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifInstanceOfExpr(Consumer<InstanceOfExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntegerLiteralExpr(Consumer<IntegerLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLambdaExpr(Consumer<LambdaExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralExpr(Consumer<LiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLiteralStringValueExpr(Consumer<LiteralStringValueExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLongLiteralExpr(Consumer<LongLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMarkerAnnotationExpr(Consumer<MarkerAnnotationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodCallExpr(Consumer<MethodCallExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifMethodReferenceExpr(Consumer<MethodReferenceExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNameExpr(Consumer<NameExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNormalAnnotationExpr(Consumer<NormalAnnotationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifNullLiteralExpr(Consumer<NullLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifObjectCreationExpr(Consumer<ObjectCreationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSingleMemberAnnotationExpr(Consumer<SingleMemberAnnotationExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifStringLiteralExpr(Consumer<StringLiteralExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSuperExpr(Consumer<SuperExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThisExpr(Consumer<ThisExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeExpr(Consumer<TypeExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnaryExpr(Consumer<UnaryExpr> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVariableDeclarationExpr(Consumer<VariableDeclarationExpr> action) { + } + + public ResolvedType calculateResolvedType() { + return getSymbolResolver().calculateType(this); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AnnotationExpr> toAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayAccessExpr> toArrayAccessExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayCreationExpr> toArrayCreationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayInitializerExpr> toArrayInitializerExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AssignExpr> toAssignExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BinaryExpr> toBinaryExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BooleanLiteralExpr> toBooleanLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<CastExpr> toCastExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<CharLiteralExpr> toCharLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ClassExpr> toClassExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ConditionalExpr> toConditionalExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<DoubleLiteralExpr> toDoubleLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EnclosedExpr> toEnclosedExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<FieldAccessExpr> toFieldAccessExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<InstanceOfExpr> toInstanceOfExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<IntegerLiteralExpr> toIntegerLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LambdaExpr> toLambdaExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LiteralExpr> toLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LiteralStringValueExpr> toLiteralStringValueExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LongLiteralExpr> toLongLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MarkerAnnotationExpr> toMarkerAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MethodCallExpr> toMethodCallExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MethodReferenceExpr> toMethodReferenceExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<NameExpr> toNameExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<NormalAnnotationExpr> toNormalAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<NullLiteralExpr> toNullLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ObjectCreationExpr> toObjectCreationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SingleMemberAnnotationExpr> toSingleMemberAnnotationExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<StringLiteralExpr> toStringLiteralExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SuperExpr> toSuperExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ThisExpr> toThisExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TypeExpr> toTypeExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnaryExpr> toUnaryExpr() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<VariableDeclarationExpr> toVariableDeclarationExpr() { + return Optional.empty(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java new file mode 100644 index 000000000..c6b9e0a94 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>person.name</code> "name" is the name and "person" is the scope. + * + * @author Julio Vilmar Gesser + */ +public final class FieldAccessExpr extends Expression implements NodeWithSimpleName<FieldAccessExpr>, NodeWithTypeArguments<FieldAccessExpr>, NodeWithScope<FieldAccessExpr> { + + private Expression scope; + + @OptionalProperty + private NodeList<Type> 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<Type> 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<Type> typeArguments, SimpleName name) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<NodeList<Type>> 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<Type> 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<FieldAccessExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<FieldAccessExpr> toFieldAccessExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java new file mode 100644 index 000000000..69a505b7c --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>tool instanceof Drill</code> + * + * @author Julio Vilmar Gesser + */ +public final class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr, ReferenceType>, NodeWithExpression<InstanceOfExpr> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<InstanceOfExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<InstanceOfExpr> toInstanceOfExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java new file mode 100644 index 000000000..a0d394986 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.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.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. + * <br/><code>8934</code> + * <br/><code>0x01</code> + * <br/><code>022</code> + * <br/><code>0B10101010</code> + * <br/><code>99999999L</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<IntegerLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<IntegerLiteralExpr> toIntegerLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java new file mode 100644 index 000000000..a69176f2a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <h1>A lambda expression</h1> + * <h2>Java 1-7</h2> + * Does not exist. + * <h2>Java 8+</h2> + * <code>(a, b) -> a + b</code> + * <br/><code>a -> ...</code> + * <br/><code>(Long a) -> { println(a); }</code> + * <p/>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 <code>UnknownType</code>. + * If they are in ( ), "isEnclosingParameters" is true. + * <br/>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<LambdaExpr> { + + private NodeList<Parameter> parameters; + + private boolean isEnclosingParameters; + + private Statement body; + + public LambdaExpr() { + this(null, new NodeList<>(), new ReturnStmt(), false); + } + + @AllFieldsConstructor + public LambdaExpr(NodeList<Parameter> 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<Parameter> parameters, Statement body, boolean isEnclosingParameters) { + super(tokenRange); + setParameters(parameters); + setBody(body); + setEnclosingParameters(isEnclosingParameters); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Parameter> getParameters() { + return parameters; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LambdaExpr setParameters(final NodeList<Parameter> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Expression> 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<LambdaExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LambdaExpr> toLambdaExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java new file mode 100644 index 000000000..2c81560c6 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.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.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<LiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LiteralExpr> toLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java new file mode 100644 index 000000000..49561469e --- /dev/null +++ b/javaparser-core/src/main/java/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<LiteralStringValueExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LiteralStringValueExpr> toLiteralStringValueExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java new file mode 100644 index 000000000..d15442fbc --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.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.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. + * <br/><code>8934l</code> + * <br/><code>0x01L</code> + * <br/><code>022l</code> + * <br/><code>0B10101010L</code> + * <br/><code>99999999L</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<LongLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LongLiteralExpr> toLongLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java new file mode 100644 index 000000000..e9ab8941d --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.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.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. + * <br/><code>@Override</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<MarkerAnnotationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MarkerAnnotationExpr> toMarkerAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java new file mode 100644 index 000000000..8accb7b0f --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.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.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 <code>@Counters(a=15)</code> 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<MemberValuePair> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java new file mode 100644 index 000000000..dc914c9d4 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. <br/><code>circle.circumference()</code> <br/>In <code>a.<String>bb(15);</code> 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<MethodCallExpr>, NodeWithArguments<MethodCallExpr>, NodeWithSimpleName<MethodCallExpr>, NodeWithOptionalScope<MethodCallExpr> { + + @OptionalProperty + private Expression scope; + + @OptionalProperty + private NodeList<Type> typeArguments; + + private SimpleName name; + + private NodeList<Expression> 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<Expression> arguments) { + this(null, scope, new NodeList<>(), new SimpleName(name), arguments); + } + + public MethodCallExpr(final Expression scope, final SimpleName name, final NodeList<Expression> arguments) { + this(null, scope, new NodeList<>(), name, arguments); + } + + @AllFieldsConstructor + public MethodCallExpr(final Expression scope, final NodeList<Type> typeArguments, final SimpleName name, final NodeList<Expression> 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<Type> typeArguments, SimpleName name, NodeList<Expression> arguments) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setName(name); + setArguments(arguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> 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<Expression> getScope() { + return Optional.ofNullable(scope); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public MethodCallExpr setArguments(final NodeList<Expression> 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<NodeList<Type>> 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<Type> 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<MethodCallExpr> action) { + action.accept(this); + } + + public ResolvedMethodDeclaration resolveInvokedMethod() { + return getSymbolResolver().resolveDeclaration(this, ResolvedMethodDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MethodCallExpr> toMethodCallExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java new file mode 100644 index 000000000..8ddaac00d --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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". + * <br/>In <code>System.out::println;</code> the scope is System.out and the identifier is "println" + * <br/><code>(test ? stream.map(String::trim) : stream)::toArray;</code> + * <br/>In <code>Bar<String>::<Integer>new</code> 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<MethodReferenceExpr>, NodeWithIdentifier<MethodReferenceExpr> { + + private Expression scope; + + @OptionalProperty + private NodeList<Type> typeArguments; + + @NonEmptyProperty + private String identifier; + + public MethodReferenceExpr() { + this(null, new ClassExpr(), null, "empty"); + } + + @AllFieldsConstructor + public MethodReferenceExpr(Expression scope, NodeList<Type> 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<Type> typeArguments, String identifier) { + super(tokenRange); + setScope(scope); + setTypeArguments(typeArguments); + setIdentifier(identifier); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<NodeList<Type>> 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<Type> 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<MethodReferenceExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<MethodReferenceExpr> toMethodReferenceExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java new file mode 100644 index 000000000..0eeabd3ce --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <p> + * The rightmost identifier is "identifier", + * The one to the left of it is "qualifier.identifier", etc. + * <p> + * 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<Name>, NodeWithAnnotations<Name> { + + @NonEmptyProperty + private String identifier; + + @OptionalProperty + private Name qualifier; + + private NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange); + setQualifier(qualifier); + setIdentifier(identifier); + setAnnotations(annotations); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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.<br> + * 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<Name> 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<AnnotationExpr> getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Name setAnnotations(final NodeList<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java new file mode 100644 index 000000000..d87158983 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.expr; + +import com.github.javaparser.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. + * <br/>In <code>int x = a + 3;</code> a is a SimpleName inside a NameExpr. + * + * @author Julio Vilmar Gesser + */ +public final class NameExpr extends Expression implements NodeWithSimpleName<NameExpr>, Resolvable<ResolvedValueDeclaration> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<NameExpr> 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<NameExpr> toNameExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java new file mode 100644 index 000000000..dd0fce54f --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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.<br/><code>@Mapping(a=5, d=10)</code> + * @author Julio Vilmar Gesser + */ +public final class NormalAnnotationExpr extends AnnotationExpr { + + private NodeList<MemberValuePair> pairs; + + public NormalAnnotationExpr() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public NormalAnnotationExpr(final Name name, final NodeList<MemberValuePair> 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<MemberValuePair> pairs) { + super(tokenRange, name); + setPairs(pairs); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<MemberValuePair> getPairs() { + return pairs; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NormalAnnotationExpr setPairs(final NodeList<MemberValuePair> 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<NormalAnnotationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<NormalAnnotationExpr> toNormalAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java new file mode 100644 index 000000000..b71ed5b80 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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". + * <br/><code>null</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<NullLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<NullLiteralExpr> toNullLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java new file mode 100644 index 000000000..c4fe045b7 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java @@ -0,0 +1,355 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>new HashMap.Entry<String, Long>(15) {public String getKey() {return null;}};</code> + * HashMap.Entry is the type, String and Long are type arguments, 15 is an argument, and everything in { } + * is the anonymous class body. + * <p/>In <code>class B { class C { public void a() { new B().new C(); } } }</code> the scope is <code>new B()</code> + * of ObjectCreationExpr <code>new B().new C()</code> + * + * @author Julio Vilmar Gesser + */ +public final class ObjectCreationExpr extends Expression implements NodeWithTypeArguments<ObjectCreationExpr>, NodeWithType<ObjectCreationExpr, ClassOrInterfaceType>, NodeWithArguments<ObjectCreationExpr>, NodeWithOptionalScope<ObjectCreationExpr> { + + @OptionalProperty + private Expression scope; + + private ClassOrInterfaceType type; + + @OptionalProperty + private NodeList<Type> typeArguments; + + private NodeList<Expression> arguments; + + @OptionalProperty + private NodeList<BodyDeclaration<?>> 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<Expression> arguments) { + this(null, scope, type, new NodeList<>(), arguments, null); + } + + @AllFieldsConstructor + public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList<Type> typeArguments, final NodeList<Expression> arguments, final NodeList<BodyDeclaration<?>> 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<Type> typeArguments, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<NodeList<BodyDeclaration<?>>> 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<Expression> getArguments() { + return arguments; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> getScope() { + return Optional.ofNullable(scope); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ClassOrInterfaceType getType() { + return type; + } + + /** + * Sets the anonymousClassBody<br> + * Null means no class body<br> + * 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<BodyDeclaration<?>> 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<Expression> 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<NodeList<Type>> 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<Type> 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<ObjectCreationExpr> action) { + action.accept(this); + } + + public ResolvedConstructorDeclaration resolveInvokedConstructor() { + return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ObjectCreationExpr> toObjectCreationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java new file mode 100644 index 000000000..faaa541cd --- /dev/null +++ b/javaparser-core/src/main/java/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<SimpleName> { + + @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java new file mode 100644 index 000000000..679c71475 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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. <br/><code>@Count(15)</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<SingleMemberAnnotationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SingleMemberAnnotationExpr> toSingleMemberAnnotationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java new file mode 100644 index 000000000..a7b4dd541 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>"Hello World!"</code> + * <br/><code>"\"\n"</code> + * <br/><code>"\u2122"</code> + * <br/><code>"âą"</code> + * <br/><code>"đ©"</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<StringLiteralExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<StringLiteralExpr> toStringLiteralExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java new file mode 100644 index 000000000..2de37fb25 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. <br/><code>World.super.greet()</code> is a MethodCallExpr of method name greet, + * and scope "World.super" which is a SuperExpr with classExpr "World". <br/><code>super.name</code> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> 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<SuperExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SuperExpr> toSuperExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java new file mode 100644 index 000000000..dc9981d82 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. <br/><code>World.this.greet()</code> is a MethodCallExpr of method name greet, + * and scope "World.super" which is a ThisExpr with classExpr "World". <br/><code>this.name</code> 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<ResolvedTypeDeclaration> { + + @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> 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<ThisExpr> 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<ThisExpr> toThisExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java new file mode 100644 index 000000000..3d74b6eea --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>World::greet</code> 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<TypeExpr, Type> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<TypeExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TypeExpr> toTypeExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java new file mode 100644 index 000000000..4008544d9 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>11++</code> + * <br/><code>++11</code> + * <br/><code>~1</code> + * <br/><code>-333</code> + * + * @author Julio Vilmar Gesser + */ +public final class UnaryExpr extends Expression implements NodeWithExpression<UnaryExpr> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<UnaryExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnaryExpr> toUnaryExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java new file mode 100644 index 000000000..8745ce72b --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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. + * <br/><code>final int x=3, y=55</code> + * + * <br/>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<VariableDeclarationExpr>, NodeWithAnnotations<VariableDeclarationExpr>, NodeWithVariables<VariableDeclarationExpr> { + + private EnumSet<Modifier> modifiers; + + private NodeList<AnnotationExpr> annotations; + + @NonEmptyProperty + private NodeList<VariableDeclarator> 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<VariableDeclarator> variables) { + this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), variables); + } + + public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final NodeList<VariableDeclarator> variables) { + this(null, modifiers, new NodeList<>(), variables); + } + + @AllFieldsConstructor + public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<VariableDeclarator> 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<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables) { + super(tokenRange); + setModifiers(modifiers); + setAnnotations(annotations); + setVariables(variables); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<AnnotationExpr> getAnnotations() { + return annotations; + } + + /** + * Return the modifiers of this variable declaration. + * + * @return modifiers + * @see Modifier + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<VariableDeclarator> getVariables() { + return variables; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public VariableDeclarationExpr setAnnotations(final NodeList<AnnotationExpr> 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<Modifier> 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<VariableDeclarator> 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<VariableDeclarationExpr> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<VariableDeclarationExpr> toVariableDeclarationExpr() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java new file mode 100644 index 000000000..547c2ccf7 --- /dev/null +++ b/javaparser-core/src/main/java/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. <code>@Foo module com.github.abc { requires a.B; }</code> + */ +public final class ModuleDeclaration extends Node implements NodeWithName<ModuleDeclaration>, NodeWithAnnotations<ModuleDeclaration> { + + private Name name; + + private NodeList<AnnotationExpr> annotations; + + private boolean isOpen; + + private NodeList<ModuleStmt> 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<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> 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<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> moduleStmts) { + super(tokenRange); + setAnnotations(annotations); + setName(name); + setOpen(isOpen); + setModuleStmts(moduleStmts); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AnnotationExpr> getAnnotations() { + return annotations; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setAnnotations(final NodeList<AnnotationExpr> 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<ModuleStmt> getModuleStmts() { + return moduleStmts; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleDeclaration setModuleStmts(final NodeList<ModuleStmt> 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-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java new file mode 100644 index 000000000..61440b1a7 --- /dev/null +++ b/javaparser-core/src/main/java/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<ModuleExportsStmt> { + + private Name name; + + private NodeList<Name> moduleNames; + + public ModuleExportsStmt() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleExportsStmt(Name name, NodeList<Name> 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<Name> moduleNames) { + super(tokenRange); + setName(name); + setModuleNames(moduleNames); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Name> getModuleNames() { + return moduleNames; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleExportsStmt setModuleNames(final NodeList<Name> 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<ModuleExportsStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleExportsStmt> toModuleExportsStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java new file mode 100644 index 000000000..25565dadd --- /dev/null +++ b/javaparser-core/src/main/java/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<ModuleOpensStmt> { + + private Name name; + + private NodeList<Name> moduleNames; + + public ModuleOpensStmt() { + this(null, new Name(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleOpensStmt(Name name, NodeList<Name> 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<Name> moduleNames) { + super(tokenRange); + setName(name); + setModuleNames(moduleNames); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Name> getModuleNames() { + return moduleNames; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleOpensStmt setModuleNames(final NodeList<Name> 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<ModuleOpensStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleOpensStmt> toModuleOpensStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java new file mode 100644 index 000000000..4ddbced06 --- /dev/null +++ b/javaparser-core/src/main/java/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<ModuleProvidesStmt, Type> { + + private Type type; + + private NodeList<Type> withTypes; + + public ModuleProvidesStmt() { + this(null, new ClassOrInterfaceType(), new NodeList<>()); + } + + @AllFieldsConstructor + public ModuleProvidesStmt(Type type, NodeList<Type> 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<Type> withTypes) { + super(tokenRange); + setType(type); + setWithTypes(withTypes); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Type> getWithTypes() { + return withTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleProvidesStmt setWithTypes(final NodeList<Type> 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<ModuleProvidesStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleProvidesStmt> toModuleProvidesStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java new file mode 100644 index 000000000..cede81c2d --- /dev/null +++ b/javaparser-core/src/main/java/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. <code>require a.b.C;</code> + */ +public final class ModuleRequiresStmt extends ModuleStmt implements NodeWithStaticModifier<ModuleRequiresStmt>, NodeWithName<ModuleRequiresStmt> { + + private EnumSet<Modifier> modifiers; + + private Name name; + + public ModuleRequiresStmt() { + this(null, EnumSet.noneOf(Modifier.class), new Name()); + } + + @AllFieldsConstructor + public ModuleRequiresStmt(EnumSet<Modifier> 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<Modifier> modifiers, Name name) { + super(tokenRange); + setModifiers(modifiers); + setName(name); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public EnumSet<Modifier> getModifiers() { + return modifiers; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public ModuleRequiresStmt setModifiers(final EnumSet<Modifier> 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<ModuleRequiresStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleRequiresStmt> toModuleRequiresStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java new file mode 100644 index 000000000..176c791b8 --- /dev/null +++ b/javaparser-core/src/main/java/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<ModuleExportsStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleOpensStmt(Consumer<ModuleOpensStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleProvidesStmt(Consumer<ModuleProvidesStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleRequiresStmt(Consumer<ModuleRequiresStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifModuleUsesStmt(Consumer<ModuleUsesStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleExportsStmt> toModuleExportsStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleOpensStmt> toModuleOpensStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleProvidesStmt> toModuleProvidesStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleRequiresStmt> toModuleRequiresStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleUsesStmt> toModuleUsesStmt() { + return Optional.empty(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java new file mode 100644 index 000000000..2bf985601 --- /dev/null +++ b/javaparser-core/src/main/java/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<ModuleUsesStmt, Type> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ModuleUsesStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ModuleUsesStmt> toModuleUsesStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java new file mode 100644 index 000000000..72060c612 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + NodeList<AnnotationExpr> getAnnotations(); + + N setAnnotations(NodeList<AnnotationExpr> 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<? extends Annotation> 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<? extends Annotation> 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<? extends Annotation> 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<? extends Annotation> 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<? extends Annotation> annotationClass) { + return isAnnotationPresent(annotationClass.getSimpleName()); + } + + /** + * Try to find an annotation by its name + * + * @param annotationName the name of the annotation + */ + default Optional<AnnotationExpr> 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<AnnotationExpr> getAnnotationByClass(Class<? extends Annotation> annotationClass) { + return getAnnotationByName(annotationClass.getSimpleName()); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java new file mode 100644 index 000000000..702707ca1 --- /dev/null +++ b/javaparser-core/src/main/java/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 extends Node> { + N setArguments(NodeList<Expression> arguments); + + NodeList<Expression> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java new file mode 100644 index 000000000..a23e3e266 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ BlockStmt getBody();
+
+ N setBody(BlockStmt block);
+
+ default BlockStmt createBody() {
+ BlockStmt block = new BlockStmt();
+ setBody(block);
+ return block;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java new file mode 100644 index 000000000..2388824af --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ Statement getBody();
+
+ N setBody(final Statement body);
+
+ default BlockStmt createBlockStatementAsBody() {
+ BlockStmt b = new BlockStmt();
+ setBody(b);
+ return b;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java new file mode 100644 index 000000000..4113f8b69 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + Expression getCondition(); + + N setCondition(Expression condition); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java new file mode 100644 index 000000000..b2f2507ee --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithSimpleName<N>, NodeWithMembers<N> { + /** + * Try to find a {@link ConstructorDeclaration} with no parameters by its name + * + * @return the constructors found (multiple in case of polymorphism) + */ + default Optional<ConstructorDeclaration> 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<ConstructorDeclaration> 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<br> void + * foo(Map<Integer,String> myMap,int number) + * @return the constructor found (multiple in case of overloading) + */ + default Optional<ConstructorDeclaration> 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<br> void + * foo(Map<Integer,String> myMap,int number) + * @return the constructors found (multiple in case of overloading) + */ + default Optional<ConstructorDeclaration> getConstructorByParameterTypes(Class<?>... paramTypes) { + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java new file mode 100644 index 000000000..d490ed158 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.ast.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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java new file mode 100644 index 000000000..3a1dd712f --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + Expression getExpression(); + + N setExpression(Expression expression); + + default N setExpression(String expression) { + return setExpression(parseExpression(expression)); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java new file mode 100644 index 000000000..af4adf800 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ NodeList<ClassOrInterfaceType> getExtendedTypes();
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ default ClassOrInterfaceType getExtendedTypes(int i) {
+ return getExtendedTypes().get(i);
+ }
+
+ N setExtendedTypes(NodeList<ClassOrInterfaceType> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java new file mode 100644 index 000000000..22a583a44 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java new file mode 100644 index 000000000..84cee4d32 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ NodeList<ClassOrInterfaceType> getImplementedTypes();
+
+ default ClassOrInterfaceType getImplementedTypes(int i) {
+ return getImplementedTypes().get(i);
+ }
+
+ N setImplementedTypes(NodeList<ClassOrInterfaceType> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java new file mode 100644 index 000000000..592947e07 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + Optional<Comment> 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<JavadocComment> 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<Javadoc> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java new file mode 100644 index 000000000..6d5f0c3ff --- /dev/null +++ b/javaparser-core/src/main/java/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.
+ * <p>
+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getMembers
+ * method.
+ */
+public interface NodeWithMembers<N extends Node> {
+ /**
+ * @return all members inside the braces of this node,
+ * like fields, methods, nested types, etc.
+ */
+ NodeList<BodyDeclaration<?>> 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<BodyDeclaration<?>> members);
+
+ /**
+ * Add a field to this and automatically add the import of the type if needed
+ *
+ * @param typeClass the type of the field
+ * @param name the name of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addField(Class<?> typeClass, String name, Modifier... modifiers) {
+ 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<MethodDeclaration> 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<MethodDeclaration> getMethods() {
+ return unmodifiableList(getMembers().stream()
+ .filter(m -> m instanceof MethodDeclaration)
+ .map(m -> (MethodDeclaration) m)
+ .collect(toList()));
+ }
+
+ /**
+ * Try to find a {@link MethodDeclaration} by its parameters types
+ *
+ * @param paramTypes the types of parameters like "Map<Integer,String>","int" to match<br> void
+ * foo(Map<Integer,String> myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> 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<br> void
+ * foo(Map<Integer,String> myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> 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<br> void
+ * foo(Map<Integer,String> myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> 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<FieldDeclaration> 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<FieldDeclaration> getFields() {
+ return unmodifiableList(getMembers().stream()
+ .filter(m -> m instanceof FieldDeclaration)
+ .map(m -> (FieldDeclaration) m)
+ .collect(toList()));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java new file mode 100644 index 000000000..3a499bfa3 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + /** + * 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<Modifier> getModifiers(); + + N setModifiers(EnumSet<Modifier> modifiers); + + @SuppressWarnings("unchecked") + default N addModifier(Modifier... modifiers) { + EnumSet<Modifier> 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<Modifier> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java new file mode 100644 index 000000000..bc25cad05 --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <p> + * 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<N extends Node> { + 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java new file mode 100644 index 000000000..0bf89a4d2 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ Optional<BlockStmt> getBody();
+
+ N setBody(BlockStmt block);
+
+ N removeBody();
+
+ default BlockStmt createBody() {
+ BlockStmt block = new BlockStmt();
+ setBody(block);
+ return block;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java new file mode 100644 index 000000000..93ab11a5a --- /dev/null +++ b/javaparser-core/src/main/java/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<T extends Node> { + Optional<SimpleName> getLabel(); + + T setLabel(SimpleName label); + + T removeLabel(); + + default T setLabel(String label) { + assertNonEmpty(label); + return setLabel(new SimpleName(label)); + } + + default Optional<String> getLabelAsString() { + return getLabel().flatMap(l -> Optional.of(l.getIdentifier())); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java new file mode 100644 index 000000000..46bd59c84 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithTraversableScope { + + Optional<Expression> getScope(); + + N setScope(Expression scope); + + N removeScope(); + + default Optional<Expression> traverseScope() { + return getScope(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java new file mode 100644 index 000000000..517d8f574 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ NodeList<Parameter> 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<Parameter> 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<Parameter> 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<Parameter> 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 <b>take care about generics, it wont work</b>
+ * @return null if not found, the param found otherwise
+ */
+ default Optional<Parameter> 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<br> 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<br> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java new file mode 100644 index 000000000..d1e2fb767 --- /dev/null +++ b/javaparser-core/src/main/java/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<N> { + Optional<Range> getRange(); + + N setRange(Range range); + + /** + * The begin position of this node in the source file. + */ + default Optional<Position> getBegin() { + return getRange().map(r -> r.begin); + } + + /** + * The end position of this node in the source file. + */ + default Optional<Position> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java new file mode 100644 index 000000000..15ea3ac25 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithTraversableScope { + + Expression getScope(); + + N setScope(Expression scope); + + default Optional<Expression> traverseScope() { + return Optional.of(getScope()); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java new file mode 100644 index 000000000..ebd3957b8 --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <p> + * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. + */ +public interface NodeWithSimpleName<N extends Node> { + 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java new file mode 100644 index 000000000..4d2c90cec --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> {
+ NodeList<Statement> 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<Statement> 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 extends Statement> 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<Statement> nodeList) {
+ for (Statement n : nodeList) {
+ addStatement(n.clone());
+ }
+ return (N) this;
+ }
+
+ default N copyStatements(NodeWithStatements<?> other) {
+ return copyStatements(other.getStatements());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java new file mode 100644 index 000000000..e1b9007f6 --- /dev/null +++ b/javaparser-core/src/main/java/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 extends Node> { + N setThrownExceptions(NodeList<ReferenceType> thrownExceptions); + + NodeList<ReferenceType> 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<? extends Throwable> 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<? extends Throwable> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java new file mode 100644 index 000000000..b043f6426 --- /dev/null +++ b/javaparser-core/src/main/java/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<N> { + Optional<TokenRange> getTokenRange(); + + N setTokenRange(TokenRange range); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java new file mode 100644 index 000000000..a1b9b3be5 --- /dev/null +++ b/javaparser-core/src/main/java/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<Expression> traverseScope(); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java new file mode 100644 index 000000000..06e66fb91 --- /dev/null +++ b/javaparser-core/src/main/java/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.
+ * <p>
+ * 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<N extends Node, T extends Type> {
+ /**
+ * 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java new file mode 100644 index 000000000..0c72b225e --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <p> + * <pre> + * new X(); --> typeArguments == Optional is empty + * new X<>(); --> typeArguments = [], diamondOperator = true + * new X<C,D>(); --> typeArguments = [C,D], diamondOperator = false + * </pre> + */ +public interface NodeWithTypeArguments<N extends Node> { + /** + * @return the types that can be found in the type arguments: <String, Integer>. + */ + Optional<NodeList<Type>> getTypeArguments(); + + /** + * Allows you to set the generic arguments + * + * @param typeArguments The list of types of the generics, can be null + */ + N setTypeArguments(NodeList<Type> 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<Type>) null); + } + + @SuppressWarnings("unchecked") + default N setTypeArguments(Type... typeArguments) { + return setTypeArguments(nodeList(typeArguments)); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java new file mode 100644 index 000000000..8817a7620 --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <pre> + * class X {} --> typeParameters == [] + * class X<> {} --> does not occur. + * class X<C,D> {} --> typeParameters = [C,D] + * </pre> + */ +public interface NodeWithTypeParameters<N extends Node> { + NodeList<TypeParameter> 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<TypeParameter> typeParameters); + + default boolean isGeneric() { + return getTypeParameters().size() > 0; + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java new file mode 100644 index 000000000..5daf38a14 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> { + NodeList<VariableDeclarator> getVariables(); + + N setVariables(NodeList<VariableDeclarator> 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. + * <br/>For <code>int a;</code> this is int. + * <br/>For <code>int a,b,c,d;</code> this is also int. + * <br/>For <code>int a,b[],c;</code> this is an assertion error since b is an int[], not an int. + * <br/>For <code>int a,b;</code>, 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<VariableDeclarator> 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. + * <br/>For <code>int a;</code> this is int. + * <br/>For <code>int a,b,c,d;</code> this is also int. + * <br/>For <code>int a,b[],c;</code> this is also int. Note: no mention of b being an array. + * <br/>For <code>int a,b;</code>, 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<VariableDeclarator> 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. + * <p> + * <br/>For <code>int a;</code> this is int. + * <br/>For <code>int a,b,c,d;</code> this is also int. + * <br/>For <code>int a,b[],c;</code> this is also int. + * <br/>For <code>int[] a[][],b[],c[][];</code> this is int[][]. + */ + @DerivedProperty + default Optional<Type> getMaximumCommonType() { + return calculateMaximumCommonType(getVariables().stream().map(v -> v.getType()).collect(Collectors.toList())); + } + + static Optional<Type> calculateMaximumCommonType(List<Type> 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<Type> 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<Type> 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-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java new file mode 100644 index 000000000..c81c4c616 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isAbstract() { + return getModifiers().contains(ABSTRACT); + } + + @SuppressWarnings("unchecked") + default N setAbstract(boolean set) { + return setModifier(ABSTRACT, set); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java new file mode 100644 index 000000000..956962448 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithPublicModifier<N>, NodeWithPrivateModifier<N>, NodeWithProtectedModifier<N> { +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java new file mode 100644 index 000000000..91aae402e --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isFinal() { + return getModifiers().contains(FINAL); + } + + @SuppressWarnings("unchecked") + default N setFinal(boolean set) { + return setModifier(FINAL, set); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java new file mode 100644 index 000000000..4aa022cfe --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isPrivate() { + return getModifiers().contains(PRIVATE); + } + + @SuppressWarnings("unchecked") + default N setPrivate(boolean set) { + return setModifier(PRIVATE, set); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java new file mode 100644 index 000000000..d2200b74a --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isProtected() { + return getModifiers().contains(PROTECTED); + } + + @SuppressWarnings("unchecked") + default N setProtected(boolean set) { + return setModifier(PROTECTED, set); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java new file mode 100644 index 000000000..64b4067bf --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isPublic() { + return getModifiers().contains(PUBLIC); + } + + @SuppressWarnings("unchecked") + default N setPublic(boolean set) { + return setModifier(PUBLIC, set); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java new file mode 100644 index 000000000..5ac63ea40 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + + default boolean isStatic() { + return getModifiers().contains(STATIC); + } + + @SuppressWarnings("unchecked") + default N setStatic(boolean set) { + return setModifier(STATIC, set); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java new file mode 100644 index 000000000..1d8fb4112 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends NodeWithModifiers<N> { + default boolean isStrictfp() { + return getModifiers().contains(STRICTFP); + } + + @SuppressWarnings("unchecked") + default N setStrictfp(boolean set) { + return setModifier(STRICTFP, set); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java new file mode 100644 index 000000000..6c41f4b02 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java new file mode 100644 index 000000000..82b91949d --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/observer/Observable.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/Observable.java new file mode 100644 index 000000000..ce0f926bf --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java new file mode 100644 index 000000000..d7f82f36c --- /dev/null +++ b/javaparser-core/src/main/java/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> 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<Node> opt = (Optional<Node>) 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<? extends Node> getValueAsMultipleReference(Node node) { + Object rawValue = getRawValue(node); + try { + if (rawValue == null) { + return null; + } + if (rawValue instanceof NodeList) { + return (NodeList) rawValue; + } else { + Optional<NodeList> opt = (Optional<NodeList>) 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-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java new file mode 100644 index 000000000..1579474c3 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java new file mode 100644 index 000000000..a6eb59fe3 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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" + * <br/>In <code>assert dead : "Wasn't expecting to be dead here";</code> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Expression> 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<AssertStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AssertStmt> toAssertStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java new file mode 100644 index 000000000..3e25b9647 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.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.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<BlockStmt> { + + private NodeList<Statement> statements; + + public BlockStmt() { + this(null, new NodeList<>()); + } + + @AllFieldsConstructor + public BlockStmt(final NodeList<Statement> 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<Statement> statements) { + super(tokenRange); + setStatements(statements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Statement> getStatements() { + return statements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public BlockStmt setStatements(final NodeList<Statement> 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<BlockStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BlockStmt> toBlockStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java new file mode 100644 index 000000000..4a0b411c4 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>break abc;</code> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<SimpleName> 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<BreakStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BreakStmt> toBreakStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java new file mode 100644 index 000000000..9eaa30efe --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.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.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. <br/>In <code>try { ... } catch (Exception e) { ... }</code> the CatchClause + * is <code>catch (Exception e) { ... }</code>. Exception e is the parameter. The { ... } is the body. + * + * @author Julio Vilmar Gesser + */ +public final class CatchClause extends Node implements NodeWithBlockStmt<CatchClause> { + + private Parameter parameter; + + private BlockStmt body; + + public CatchClause() { + this(null, new Parameter(), new BlockStmt()); + } + + public CatchClause(final EnumSet<Modifier> exceptModifier, final NodeList<AnnotationExpr> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java new file mode 100644 index 000000000..b82995084 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + * <br/><code>continue brains;</code> + * <br/><code>continue;</code> + * + * @author Julio Vilmar Gesser + */ +public final class ContinueStmt extends Statement implements NodeWithOptionalLabel<ContinueStmt> { + + @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<SimpleName> 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<ContinueStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ContinueStmt> toContinueStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java new file mode 100644 index 000000000..7c161ff8d --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>do { ... } while ( a==0 );</code> + * + * @author Julio Vilmar Gesser + */ +public final class DoStmt extends Statement implements NodeWithBody<DoStmt>, NodeWithCondition<DoStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<DoStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<DoStmt> toDoStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java new file mode 100644 index 000000000..d73ede61b --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<EmptyStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EmptyStmt> toEmptyStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java new file mode 100644 index 000000000..2b9b9c200 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>class X { X() { super(15); } }</code> + * <br/><code>class X { X() { this(1, 2); } }</code> + * + * @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<ExplicitConstructorInvocationStmt> { + + @OptionalProperty + private NodeList<Type> typeArguments; + + private boolean isThis; + + @OptionalProperty + private Expression expression; + + private NodeList<Expression> arguments; + + public ExplicitConstructorInvocationStmt() { + this(null, new NodeList<>(), true, null, new NodeList<>()); + } + + public ExplicitConstructorInvocationStmt(final boolean isThis, final Expression expression, final NodeList<Expression> arguments) { + this(null, new NodeList<>(), isThis, expression, arguments); + } + + @AllFieldsConstructor + public ExplicitConstructorInvocationStmt(final NodeList<Type> typeArguments, final boolean isThis, final Expression expression, final NodeList<Expression> 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<Type> typeArguments, boolean isThis, Expression expression, NodeList<Expression> arguments) { + super(tokenRange); + setTypeArguments(typeArguments); + setThis(isThis); + setExpression(expression); + setArguments(arguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> 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<Expression> 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<Expression> 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<NodeList<Type>> 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<Type> 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<ExplicitConstructorInvocationStmt> action) { + action.accept(this); + } + + public ResolvedConstructorDeclaration resolveInvokedConstructor() { + return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ExplicitConstructorInvocationStmt> toExplicitConstructorInvocationStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java new file mode 100644 index 000000000..483c45dee --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.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.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<ExpressionStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ExpressionStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ExpressionStmt> toExpressionStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java new file mode 100644 index 000000000..d288991df --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java @@ -0,0 +1,290 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <h1>The classic for statement</h1> + * Examples: + * <ol> + * <li><code>for(int a=3, b=5; a<99; a++, b++) hello();</code></li> + * <li><code>for(a=3, b=5; a<99; a++) { hello(); }</code> </li> + * <li><code>for(a(),b();;) hello();</code> </li> + * </ol> + * <ul> + * <li><i>initialization</i> 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.</li> + * <li><i>compare</i> is an expression, + * in example 1 and 2 it is a BinaryExpr. + * In example 3 there is no expression, it is empty.</li> + * <li><i>update</i> is a list of expressions, + * in example 1 and 2 they are UnaryExpr's. + * In example 3 there is no expression, the list empty.</li> + * <li><i>body</i> is a statement, + * in example 1 and 3 it is an ExpressionStmt. + * in example 2 it is a BlockStmt.</li> + * </ul> + * + * @author Julio Vilmar Gesser + * @see com.github.javaparser.ast.expr.VariableDeclarationExpr + */ +public final class ForStmt extends Statement implements NodeWithBody<ForStmt> { + + private NodeList<Expression> initialization; + + @OptionalProperty + private Expression compare; + + private NodeList<Expression> update; + + private Statement body; + + public ForStmt() { + this(null, new NodeList<>(), new BooleanLiteralExpr(), new NodeList<>(), new ReturnStmt()); + } + + @AllFieldsConstructor + public ForStmt(final NodeList<Expression> initialization, final Expression compare, final NodeList<Expression> 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<Expression> initialization, Expression compare, NodeList<Expression> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Expression> getCompare() { + return Optional.ofNullable(compare); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> getInitialization() { + return initialization; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Expression> 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<Expression> 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<Expression> 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<ForStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ForStmt> toForStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java new file mode 100644 index 000000000..7a04e5bcb --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>for(Object o: objects) { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class ForeachStmt extends Statement implements NodeWithBody<ForeachStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ForeachStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ForeachStmt> toForeachStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java new file mode 100644 index 000000000..f873ff89a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>if(a==5) hurray() else boo();</code> 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<IfStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<Statement> 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<IfStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<IfStmt> toIfStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java new file mode 100644 index 000000000..7906d0c6a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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 <code>label123: println("continuing");</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<LabeledStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LabeledStmt> toLabeledStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java new file mode 100644 index 000000000..f78eebc3d --- /dev/null +++ b/javaparser-core/src/main/java/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; + +/** + * <h1>A class declaration inside a method.</h1> + * <h2>Java 1.0</h2> + * Not available. + * <h2>Java 1.1+</h2> + * A statement consisting of a class declaration. + * <br/><code>class X { void m() { <b>class Y { }</b> } }</code> + * + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<LocalClassDeclarationStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LocalClassDeclarationStmt> toLocalClassDeclarationStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java new file mode 100644 index 000000000..c9bdb4583 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>return 5 * 5;</code> + * @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> 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<ReturnStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ReturnStmt> toReturnStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java new file mode 100644 index 000000000..75100e829 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java @@ -0,0 +1,481 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<AssertStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBlockStmt(Consumer<BlockStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifBreakStmt(Consumer<BreakStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifContinueStmt(Consumer<ContinueStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifDoStmt(Consumer<DoStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifEmptyStmt(Consumer<EmptyStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExplicitConstructorInvocationStmt(Consumer<ExplicitConstructorInvocationStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifExpressionStmt(Consumer<ExpressionStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForStmt(Consumer<ForStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifForeachStmt(Consumer<ForeachStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIfStmt(Consumer<IfStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLabeledStmt(Consumer<LabeledStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifLocalClassDeclarationStmt(Consumer<LocalClassDeclarationStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReturnStmt(Consumer<ReturnStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchEntryStmt(Consumer<SwitchEntryStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSwitchStmt(Consumer<SwitchStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifSynchronizedStmt(Consumer<SynchronizedStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifThrowStmt(Consumer<ThrowStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTryStmt(Consumer<TryStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnparsableStmt(Consumer<UnparsableStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWhileStmt(Consumer<WhileStmt> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<AssertStmt> toAssertStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BlockStmt> toBlockStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<BreakStmt> toBreakStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ContinueStmt> toContinueStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<DoStmt> toDoStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<EmptyStmt> toEmptyStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ExplicitConstructorInvocationStmt> toExplicitConstructorInvocationStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ExpressionStmt> toExpressionStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ForStmt> toForStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ForeachStmt> toForeachStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<IfStmt> toIfStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LabeledStmt> toLabeledStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<LocalClassDeclarationStmt> toLocalClassDeclarationStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ReturnStmt> toReturnStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SwitchEntryStmt> toSwitchEntryStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SwitchStmt> toSwitchStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SynchronizedStmt> toSynchronizedStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ThrowStmt> toThrowStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TryStmt> toTryStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnparsableStmt> toUnparsableStmt() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<WhileStmt> toWhileStmt() { + return Optional.empty(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java new file mode 100644 index 000000000..afa8fcecb --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><pre> + * switch (i) { + * case 1: + * case 2: + * System.out.println(444); + * break; + * default: + * System.out.println(0); + * } + * </pre> + * This contains three SwitchEntryStmts. + * <br/>The first one has label 1 and no statements. + * <br/>The second has label 2 and two statements (the println and the break). + * <br/>The third, the default, has no label and one statement. + * + * @author Julio Vilmar Gesser + * @see SwitchStmt + */ +public final class SwitchEntryStmt extends Statement implements NodeWithStatements<SwitchEntryStmt> { + + @OptionalProperty + private Expression label; + + private NodeList<Statement> statements; + + public SwitchEntryStmt() { + this(null, null, new NodeList<>()); + } + + @AllFieldsConstructor + public SwitchEntryStmt(final Expression label, final NodeList<Statement> 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<Statement> statements) { + super(tokenRange); + setLabel(label); + setStatements(statements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<Expression> getLabel() { + return Optional.ofNullable(label); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<Statement> 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<Statement> 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<SwitchEntryStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SwitchEntryStmt> toSwitchEntryStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java new file mode 100644 index 000000000..36e88b27c --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.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.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. + * <br/>In <code>switch(a) { ... }</code> 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<SwitchEntryStmt> entries; + + public SwitchStmt() { + this(null, new NameExpr(), new NodeList<>()); + } + + @AllFieldsConstructor + public SwitchStmt(final Expression selector, final NodeList<SwitchEntryStmt> 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<SwitchEntryStmt> entries) { + super(tokenRange); + setSelector(selector); + setEntries(entries); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<SwitchEntryStmt> 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<SwitchEntryStmt> 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<SwitchStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SwitchStmt> toSwitchStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java new file mode 100644 index 000000000..376d525b7 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/>In <code>synchronized (a123) { ... }</code> the expression is a123 and { ... } is the body + * + * @author Julio Vilmar Gesser + */ +public final class SynchronizedStmt extends Statement implements NodeWithBlockStmt<SynchronizedStmt>, NodeWithExpression<SynchronizedStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<SynchronizedStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<SynchronizedStmt> toSynchronizedStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java new file mode 100644 index 000000000..736b8351e --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>throw new Exception()</code> + * + * @author Julio Vilmar Gesser + */ +public final class ThrowStmt extends Statement implements NodeWithExpression<ThrowStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ThrowStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ThrowStmt> toThrowStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java new file mode 100644 index 000000000..6e4a81a42 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java @@ -0,0 +1,321 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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; + +/** + * <h1>The try statement</h1> + * <h2>Java 1.0-6</h2> + * <pre> + * try { + * // ... + * } catch (IOException e) { + * // ... + * } finally { + * // ... + * } + * </pre> + * 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. + * <p> + * The catch and finally blocks are optional, but they should not be empty at the same time. + * <h2>Java 7-8</h2> + * <pre> + * try (InputStream i = new FileInputStream("file")) { + * // ... + * } catch (IOException|NullPointerException e) { + * // ... + * } finally { + * // ... + * } + * </pre> + * Java 7 introduced two things: + * <ul> + * <li>Resources can be specified after "try", but only variable declarations (VariableDeclarationExpr.)</li> + * <li>A single catch can catch multiple exception types. This uses the IntersectionType.</li> + * </ul> + * <h2>Java 9+</h2> + * <pre> + * try (r) { + * // ... + * } catch (IOException|NullPointerException e) { + * // ... + * } finally { + * // ... + * } + * </pre> + * Java 9 finishes resources: you can now refer to a resource that was declared somewhere else. + * The following types are allowed: + * <ul> + * <li>VariableDeclarationExpr: "X x = new X()" like in Java 7-8.</li> + * <li>NameExpr: "a".</li> + * <li>FieldAccessExpr: "x.y.z", "super.test" etc.</li> + * </ul> + * + * @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<Expression> resources; + + private BlockStmt tryBlock; + + private NodeList<CatchClause> catchClauses; + + @OptionalProperty + private BlockStmt finallyBlock; + + public TryStmt() { + this(null, new NodeList<>(), new BlockStmt(), new NodeList<>(), null); + } + + public TryStmt(final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock) { + this(null, new NodeList<>(), tryBlock, catchClauses, finallyBlock); + } + + @AllFieldsConstructor + public TryStmt(NodeList<Expression> resources, final BlockStmt tryBlock, final NodeList<CatchClause> 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<Expression> resources, BlockStmt tryBlock, NodeList<CatchClause> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<CatchClause> getCatchClauses() { + return catchClauses; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<BlockStmt> 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<Expression> getResources() { + return resources; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public TryStmt setCatchClauses(final NodeList<CatchClause> 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<Expression> 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<TryStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TryStmt> toTryStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java new file mode 100644 index 000000000..2a7fc011b --- /dev/null +++ b/javaparser-core/src/main/java/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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<UnparsableStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnparsableStmt> toUnparsableStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java new file mode 100644 index 000000000..5fb1f9971 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>while(true) { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class WhileStmt extends Statement implements NodeWithBody<WhileStmt>, NodeWithCondition<WhileStmt> { + + 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<WhileStmt> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<WhileStmt> toWhileStmt() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java new file mode 100644 index 000000000..76dba1f3f --- /dev/null +++ b/javaparser-core/src/main/java/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<ArrayType> { + + @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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange, annotations); + setComponentType(componentType); + setOrigin(origin); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ArrayBracketPair>... arrayBracketPairLists) { + for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) { + final List<ArrayBracketPair> arrayBracketPairList = arrayBracketPairLists[i]; + if (arrayBracketPairList != null) { + for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) { + 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<Type, List<ArrayBracketPair>> unwrapArrayTypes(Type type) { + final List<ArrayBracketPair> 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<AnnotationExpr> annotations = new NodeList<>(); + + private Origin origin; + + public ArrayBracketPair(TokenRange tokenRange, Origin origin, NodeList<AnnotationExpr> annotations) { + setTokenRange(tokenRange); + setAnnotations(annotations); + setOrigin(origin); + } + + public NodeList<AnnotationExpr> getAnnotations() { + return annotations; + } + + public ArrayBracketPair setAnnotations(NodeList<AnnotationExpr> annotations) { + this.annotations = assertNotNull(annotations); + return this; + } + + public ArrayBracketPair setTokenRange(TokenRange range) { + this.tokenRange = range; + return this; + } + + public Optional<TokenRange> 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<AnnotationExpr> 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<ArrayType> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayType> toArrayType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java new file mode 100644 index 000000000..f3b6846c6 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. <br/><code>Object</code> <br/><code>HashMap<String, String></code> + * <br/><code>java.util.Punchcard</code> + * <p> + * <p>Note that the syntax is ambiguous here, and JavaParser does not know what is to the left of the class. It assumes + * cases like <code>Map.Entry</code> where Map is the scope of Entry. In <code>java.util.Punchcard</code>, 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</p> + * + * @author Julio Vilmar Gesser + */ +public final class ClassOrInterfaceType extends ReferenceType implements NodeWithSimpleName<ClassOrInterfaceType>, NodeWithAnnotations<ClassOrInterfaceType>, NodeWithTypeArguments<ClassOrInterfaceType> { + + @OptionalProperty + private ClassOrInterfaceType scope; + + private SimpleName name; + + @OptionalProperty + private NodeList<Type> 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<Type> typeArguments) { + this(null, scope, name, typeArguments, new NodeList<>()); + } + + @AllFieldsConstructor + public ClassOrInterfaceType(final ClassOrInterfaceType scope, final SimpleName name, final NodeList<Type> typeArguments, final NodeList<AnnotationExpr> 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<Type> typeArguments, NodeList<AnnotationExpr> annotations) { + super(tokenRange, annotations); + setScope(scope); + setName(name); + setTypeArguments(typeArguments); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<ClassOrInterfaceType> 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<NodeList<Type>> 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<Type> 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<AnnotationExpr> 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<ClassOrInterfaceType> 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<ClassOrInterfaceType> toClassOrInterfaceType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java new file mode 100644 index 000000000..6b1056bf2 --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <p> + * For example: + * <code>public class A<T extends Serializable & Cloneable> { }</code> + * <p> + * Or: + * <code>void foo((Serializable & Cloneable)myObject);</code> + * + * @since 3.0.0 + */ +public final class IntersectionType extends Type implements NodeWithAnnotations<IntersectionType> { + + @NonEmptyProperty + private NodeList<ReferenceType> elements; + + @AllFieldsConstructor + public IntersectionType(NodeList<ReferenceType> 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<ReferenceType> elements) { + super(tokenRange); + setElements(elements); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ReferenceType> getElements() { + return elements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public IntersectionType setElements(final NodeList<ReferenceType> 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<AnnotationExpr> 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<IntersectionType> 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<IntersectionType> toIntersectionType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java new file mode 100644 index 000000000..e359b7f09 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>int</code> + * <br/><code>boolean</code> + * <br/><code>short</code> + * + * @author Julio Vilmar Gesser + */ +public final class PrimitiveType extends Type implements NodeWithAnnotations<PrimitiveType> { + + 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<String, Primitive> 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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange, annotations); + setType(type); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<AnnotationExpr> 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<PrimitiveType> 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<PrimitiveType> toPrimitiveType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java new file mode 100644 index 000000000..f39ee0e4a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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<AnnotationExpr> 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<AnnotationExpr> 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<ReferenceType> action) { + action.accept(this); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ReferenceType> toReferenceType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java new file mode 100644 index 000000000..acaf5a9ed --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java @@ -0,0 +1,371 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<Object> { + + private NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange); + setAnnotations(annotations); + customInitialization(); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<AnnotationExpr> 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<AnnotationExpr> 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. + * <p> + * In "<code>int[] a[];</code>", 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<ArrayType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifClassOrInterfaceType(Consumer<ClassOrInterfaceType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifIntersectionType(Consumer<IntersectionType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifPrimitiveType(Consumer<PrimitiveType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifReferenceType(Consumer<ReferenceType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifTypeParameter(Consumer<TypeParameter> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnionType(Consumer<UnionType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifUnknownType(Consumer<UnknownType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVoidType(Consumer<VoidType> action) { + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifWildcardType(Consumer<WildcardType> action) { + } + + @Override + public abstract ResolvedType resolve(); + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ArrayType> toArrayType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ClassOrInterfaceType> toClassOrInterfaceType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<IntersectionType> toIntersectionType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<PrimitiveType> toPrimitiveType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<ReferenceType> toReferenceType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<TypeParameter> toTypeParameter() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnionType> toUnionType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<UnknownType> toUnknownType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<VoidType> toVoidType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public Optional<WildcardType> 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<VarType> toVarType() { + return Optional.empty(); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVarType(Consumer<VarType> action) { + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java new file mode 100644 index 000000000..c3f8cedab --- /dev/null +++ b/javaparser-core/src/main/java/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. + * <br/><code><<b>U</b>> U getU() { ... }</code> + * <br/><code>class D <<b>@Brain T extends B & A & @Tripe C</b>> { ... }</code> + * <p>U and T are type parameter names. + * <br/>B, A, and C are type parameter bounds. + * <br/>Tripe is an annotation on type parameter bound C. + * <br/>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<TypeParameter>, NodeWithAnnotations<TypeParameter> { + + private SimpleName name; + + private NodeList<ClassOrInterfaceType> 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<ClassOrInterfaceType> 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<ClassOrInterfaceType> typeBound) { + this(null, name, typeBound, new NodeList<>()); + setRange(range); + } + + @AllFieldsConstructor + public TypeParameter(SimpleName name, NodeList<ClassOrInterfaceType> typeBound, NodeList<AnnotationExpr> 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<ClassOrInterfaceType> typeBound, NodeList<AnnotationExpr> annotations) { + super(tokenRange, annotations); + setName(name); + setTypeBound(typeBound); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + /** + * Return the name of the paramenter. + * + * @return the name of the paramenter + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + /** + * Return the list of {@link ClassOrInterfaceType} that this parameter + * extends. Return <code>null</code> null if there are no type. + * + * @return list of types that this paramente extends or <code>null</code> + */ + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ClassOrInterfaceType> 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<ClassOrInterfaceType> 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<AnnotationExpr> 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<TypeParameter> 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<TypeParameter> toTypeParameter() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java new file mode 100644 index 000000000..5fa78f10a --- /dev/null +++ b/javaparser-core/src/main/java/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; + +/** + * <h1>The union type</h1> + * Represents a set of types. A given value of this type has to be assignable to at least one of the element types. + * <h2>Java 1-6</h2> + * Does not exist. + * <h2>Java 7+</h2> + * As of Java 7 it is used in catch clauses. + * <pre><code> + * try { + * ... + * } catch(<b>IOException | NullPointerException ex</b>) { + * ... + * } + * </pre> + * + * The types that make up the union type are its "elements" + */ +public final class UnionType extends Type implements NodeWithAnnotations<UnionType> { + + @NonEmptyProperty + private NodeList<ReferenceType> 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<ReferenceType> elements) { + super(tokenRange); + setElements(elements); + customInitialization(); + } + + @AllFieldsConstructor + public UnionType(NodeList<ReferenceType> elements) { + this(null, elements); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList<ReferenceType> getElements() { + return elements; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public UnionType setElements(final NodeList<ReferenceType> 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<AnnotationExpr> annotations) { + return (UnionType) super.setAnnotations(annotations); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<UnionType> 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<UnionType> toUnionType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java new file mode 100644 index 000000000..d415214f7 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.ast.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. + * <p> + * <br/>In <code>DoubleToIntFunction d = <b>x</b> -> (int)x + 1;</code> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Override + public UnknownType setAnnotations(NodeList<AnnotationExpr> 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<UnknownType> 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<UnknownType> toUnknownType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java new file mode 100644 index 000000000..3755c2fb8 --- /dev/null +++ b/javaparser-core/src/main/java/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<AnnotationExpr> 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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> 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<VarType> toVarType() { + return Optional.of(this); + } + + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") + public void ifVarType(Consumer<VarType> action) { + action.accept(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java new file mode 100644 index 000000000..860a9d675 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.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. + * <br/><code><b>void</b> helloWorld() { ... }</code> + * + * @author Julio Vilmar Gesser + */ +public final class VoidType extends Type implements NodeWithAnnotations<VoidType> { + + @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, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Override + public VoidType setAnnotations(NodeList<AnnotationExpr> 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<VoidType> 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<VoidType> toVoidType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java new file mode 100644 index 000000000..e37842e67 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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. + * <br/><code>void printCollection(Collection<<b>?</b>> c) { ... }</code> + * <br/><code>boolean addAll(Collection<<b>? extends E</b>> c)</code> + * <br/><code>Reference(T referent, ReferenceQueue<<b>? super T</b>> queue)</code> + * + * @author Julio Vilmar Gesser + */ +public final class WildcardType extends Type implements NodeWithAnnotations<WildcardType> { + + @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<AnnotationExpr> 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<AnnotationExpr> annotations) { + super(tokenRange, annotations); + setExtendedType(extendedType); + setSuperType(superType); + customInitialization(); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public <A> void accept(final VoidVisitor<A> v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<ReferenceType> getExtendedType() { + return Optional.ofNullable(extendedType); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional<ReferenceType> getSuperType() { + return Optional.ofNullable(superType); + } + + /** + * @deprecated use getExtendedType instead. + */ + @Deprecated + public Optional<ReferenceType> getExtendedTypes() { + return getExtendedType(); + } + + /** + * @deprecated use getSuperType instead. + */ + @Deprecated + public Optional<ReferenceType> 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<AnnotationExpr> 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<WildcardType> 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<WildcardType> toWildcardType() { + return Optional.of(this); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java new file mode 100644 index 000000000..c7fda2f46 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java new file mode 100644 index 000000000..0eb879aa0 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java new file mode 100644 index 000000000..0d1051d67 --- /dev/null +++ b/javaparser-core/src/main/java/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<? extends Node>) node).getTypeArguments().isPresent()) { + reporter.report(node, "Generics are not supported."); + } + } + if (node instanceof NodeWithTypeParameters) { + if (((NodeWithTypeParameters<? extends Node>) node).getTypeParameters().isNonEmpty()) { + reporter.report(node, "Generics are not supported."); + } + } + }); + protected final SingleNodeTypeValidator<TryStmt> 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-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java new file mode 100644 index 000000000..5279b7f95 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java new file mode 100644 index 000000000..4ac7565b2 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java new file mode 100644 index 000000000..72830a117 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java new file mode 100644 index 000000000..2d4ad5e86 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java new file mode 100644 index 000000000..d8b1aab1b --- /dev/null +++ b/javaparser-core/src/main/java/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<NodeList<Type>> typeArguments = ((NodeWithTypeArguments<? extends Node>) 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<NodeList<Type>> typeArguments = ((NodeWithTypeArguments<? extends Node>) 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-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java new file mode 100644 index 000000000..705400318 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java new file mode 100644 index 000000000..995e83620 --- /dev/null +++ b/javaparser-core/src/main/java/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<TryStmt> 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<UnionType> 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-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java new file mode 100644 index 000000000..e6aca92d0 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java new file mode 100644 index 000000000..2175c9af3 --- /dev/null +++ b/javaparser-core/src/main/java/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<TryStmt> 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-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java new file mode 100644 index 000000000..002668892 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java new file mode 100644 index 000000000..eb54810c1 --- /dev/null +++ b/javaparser-core/src/main/java/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<Problem> problemConsumer; + + public ProblemReporter(Consumer<Problem> 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-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java new file mode 100644 index 000000000..51a08bdca --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java new file mode 100644 index 000000000..b705b9146 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends SingleNodeTypeValidator<N> { + public SimpleValidator(Class<N> type, Predicate<N> condition, BiConsumer<N, ProblemReporter> problemSupplier) { + super(type, (node, problemReporter) -> { + if (condition.test(node)) { + problemSupplier.accept(node, problemReporter); + } + }); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java new file mode 100644 index 000000000..169849489 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> implements Validator { + private final Class<N> type; + private final TypedValidator<N> validator; + + public SingleNodeTypeValidator(Class<N> type, TypedValidator<N> 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-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java new file mode 100644 index 000000000..ae8e049e0 --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java new file mode 100644 index 000000000..588c53f11 --- /dev/null +++ b/javaparser-core/src/main/java/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<N extends Node> extends BiConsumer<N, ProblemReporter> { + /** + * @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-core/src/main/java/com/github/javaparser/ast/validator/Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validator.java new file mode 100644 index 000000000..0d5752a03 --- /dev/null +++ b/javaparser-core/src/main/java/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<Node> { + /** + * @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-core/src/main/java/com/github/javaparser/ast/validator/Validators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validators.java new file mode 100644 index 000000000..dd6926ab7 --- /dev/null +++ b/javaparser-core/src/main/java/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<Validator> validators = new ArrayList<>(); + + public Validators(Validator... validators) { + this.validators.addAll(Arrays.asList(validators)); + } + + public List<Validator> 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-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java new file mode 100644 index 000000000..547092d67 --- /dev/null +++ b/javaparser-core/src/main/java/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<ProblemReporter> implements Validator { + @Override + public void accept(Node node, ProblemReporter problemReporter) { + node.accept(this, problemReporter); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java new file mode 100644 index 000000000..5e5b7919e --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java new file mode 100644 index 000000000..0a01c3349 --- /dev/null +++ b/javaparser-core/src/main/java/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 <T extends NodeWithModifiers<?> & 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<Modifier> 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 <T extends NodeWithModifiers<?> & NodeWithTokenRange<?>> void validateAtMostOneOf(T t, ProblemReporter reporter, Modifier... modifiers) { + List<Modifier> 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-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java new file mode 100644 index 000000000..82e8dd7cc --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java new file mode 100644 index 000000000..901b7348f --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java new file mode 100644 index 000000000..e812597bb --- /dev/null +++ b/javaparser-core/src/main/java/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-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java new file mode 100644 index 000000000..19357e83c --- /dev/null +++ b/javaparser-core/src/main/java/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<VarType> { + 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> 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<Node> 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<Node> 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-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java new file mode 100644 index 000000000..4ae343ac6 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -0,0 +1,1080 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<Visitable, Object> { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final CompilationUnit n, final Object arg) { + NodeList<ImportDeclaration> imports = cloneList(n.getImports(), arg); + ModuleDeclaration module = cloneNode(n.getModule(), arg); + PackageDeclaration packageDeclaration = cloneNode(n.getPackageDeclaration(), arg); + NodeList<TypeDeclaration<?>> 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<AnnotationExpr> 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<ClassOrInterfaceType> typeBound = cloneList(n.getTypeBound(), arg); + NodeList<AnnotationExpr> 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<ClassOrInterfaceType> extendedTypes = cloneList(n.getExtendedTypes(), arg); + NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg); + NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList<AnnotationExpr> 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<EnumConstantDeclaration> entries = cloneList(n.getEntries(), arg); + NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg); + NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList<AnnotationExpr> 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<Expression> arguments = cloneList(n.getArguments(), arg); + NodeList<BodyDeclaration<?>> classBody = cloneList(n.getClassBody(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList<AnnotationExpr> 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<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg); + SimpleName name = cloneNode(n.getName(), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<VariableDeclarator> variables = cloneList(n.getVariables(), arg); + NodeList<AnnotationExpr> 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<Parameter> parameters = cloneList(n.getParameters(), arg); + ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); + NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); + NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList<AnnotationExpr> 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<Parameter> parameters = cloneList(n.getParameters(), arg); + ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg); + NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); + NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Type type = cloneNode(n.getType(), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<ReferenceType> elements = cloneList(n.getElements(), arg); + NodeList<AnnotationExpr> 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<ReferenceType> elements = cloneList(n.getElements(), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<ArrayCreationLevel> 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<Expression> 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<Type> 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<Expression> arguments = cloneList(n.getArguments(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Expression scope = cloneNode(n.getScope(), arg); + NodeList<Type> 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<BodyDeclaration<?>> anonymousClassBody = cloneList(n.getAnonymousClassBody().orElse(null), arg); + NodeList<Expression> arguments = cloneList(n.getArguments(), arg); + Expression scope = cloneNode(n.getScope(), arg); + ClassOrInterfaceType type = cloneNode(n.getType(), arg); + NodeList<Type> 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<AnnotationExpr> 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<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); + NodeList<VariableDeclarator> 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<MemberValuePair> 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<Expression> arguments = cloneList(n.getArguments(), arg); + Expression expression = cloneNode(n.getExpression(), arg); + NodeList<Type> 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<Statement> 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<SwitchEntryStmt> 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<Statement> 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<Expression> initialization = cloneList(n.getInitialization(), arg); + NodeList<Expression> 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<CatchClause> catchClauses = cloneList(n.getCatchClauses(), arg); + BlockStmt finallyBlock = cloneNode(n.getFinallyBlock(), arg); + NodeList<Expression> 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<Parameter> 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<Type> 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<Node> 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<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); + NodeList<ModuleStmt> 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 extends Node> T cloneNode(Optional<T> node, Object arg) { + if (!node.isPresent()) { + return null; + } + Node r = (Node) node.get().accept(this, arg); + if (r == null) { + return null; + } + return (T) r; + } + + @SuppressWarnings("unchecked") + protected <T extends Node> T cloneNode(T node, Object arg) { + if (node == null) { + return null; + } + Node r = (Node) node.accept(this, arg); + if (r == null) { + return null; + } + return (T) r; + } + + private <N extends Node> NodeList<N> cloneList(NodeList<N> list, Object arg) { + if (list == null) { + return null; + } + return (NodeList<N>) list.accept(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") + public Visitable visit(final ModuleExportsStmt n, final Object arg) { + NodeList<Name> 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<Type> 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<Name> 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<AnnotationExpr> 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<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java new file mode 100644 index 000000000..2062185a1 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java @@ -0,0 +1,1389 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<Boolean, Visitable> { + + 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 <T extends Node> boolean nodesEquals(final List<T> nodes1, final List<T> nodes2) { + if (nodes1 == null) { + return nodes2 == null; + } else if (nodes2 == null) { + return false; + } + if (nodes1.size() != nodes2.size()) { + return false; + } + for (int i = 0; i < nodes1.size(); i++) { + if (!nodeEquals(nodes1.get(i), nodes2.get(i))) { + return false; + } + } + return true; + } + + private <N extends Node> boolean nodesEquals(NodeList<N> n, NodeList<N> 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 <T extends Node> 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 <T extends Node> boolean nodeEquals(final Optional<T> n, final Optional<T> n2) { + return nodeEquals(n.orElse(null), n2.orElse(null)); + } + + private <T extends Node> boolean nodesEquals(final Optional<NodeList<T>> n, final Optional<NodeList<T>> 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<Node>) n, (NodeList<Node>) 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-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java new file mode 100644 index 000000000..2defdfa9f --- /dev/null +++ b/javaparser-core/src/main/java/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<R>}), 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<R>}. + * + * @author Enno Boland + */ +public abstract class GenericListVisitorAdapter<R, A> implements GenericVisitor<List<R>, A> { + + @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator") + public List<R> visit(final AnnotationDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final AnnotationMemberDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ArrayAccessExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ArrayCreationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ArrayCreationLevel n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ArrayInitializerExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ArrayType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final AssertStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final AssignExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final BinaryExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final BlockComment n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final BlockStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final BooleanLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final BreakStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final CastExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final CatchClause n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final CharLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ClassExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ClassOrInterfaceDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ClassOrInterfaceType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final CompilationUnit n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ConditionalExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ConstructorDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ContinueStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final DoStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final DoubleLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final EmptyStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final EnclosedExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final EnumConstantDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final EnumDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ExplicitConstructorInvocationStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ExpressionStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final FieldAccessExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final FieldDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ForStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ForeachStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final IfStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ImportDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final InitializerDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final InstanceOfExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final IntegerLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final IntersectionType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final JavadocComment n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final LabeledStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final LambdaExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final LineComment n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final LocalClassDeclarationStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final LongLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final MarkerAnnotationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final MemberValuePair n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final MethodCallExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final MethodDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final MethodReferenceExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final NameExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final Name n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final NormalAnnotationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final NullLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ObjectCreationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final PackageDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final Parameter n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final PrimitiveType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ReturnStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SimpleName n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SingleMemberAnnotationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final StringLiteralExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SuperExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SwitchEntryStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SwitchStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final SynchronizedStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ThisExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ThrowStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final TryStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final TypeExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final TypeParameter n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final UnaryExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final UnionType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final UnknownType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final VariableDeclarationExpr n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final VariableDeclarator n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final VoidType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final WhileStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final WildcardType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(NodeList n, A arg) { + return ((NodeList<? extends Node>) 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<R> visit(final ModuleDeclaration n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ModuleExportsStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ModuleOpensStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ModuleProvidesStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ModuleRequiresStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ModuleUsesStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final UnparsableStmt n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final ReceiverParameter n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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<R> visit(final VarType n, final A arg) { + List<R> result = new ArrayList<>(); + List<R> 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-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java new file mode 100644 index 000000000..494013cc3 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<R, A> { + + // - 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-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java new file mode 100644 index 000000000..3d5de4fbb --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java @@ -0,0 +1,2054 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<R, A> implements GenericVisitor<R, A> { + + @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-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java new file mode 100644 index 000000000..2cd9a0fdc --- /dev/null +++ b/javaparser-core/src/main/java/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<R, A> implements GenericVisitor<R, A> { + + /** + * 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-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java new file mode 100644 index 000000000..92da13e8f --- /dev/null +++ b/javaparser-core/src/main/java/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<Integer, Void> { + + 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-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java new file mode 100644 index 000000000..c7808641d --- /dev/null +++ b/javaparser-core/src/main/java/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<A> implements GenericVisitor<Visitable, A> { + + @Override + @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator") + public Visitable visit(final AnnotationDeclaration n, final A arg) { + NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<ArrayCreationLevel> 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<Expression> 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<Statement> 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<ClassOrInterfaceType> extendedTypes = modifyList(n.getExtendedTypes(), arg); + NodeList<ClassOrInterfaceType> implementedTypes = modifyList(n.getImplementedTypes(), arg); + NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList<AnnotationExpr> 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<Type> typeArguments = modifyList(n.getTypeArguments(), arg); + NodeList<AnnotationExpr> 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<ImportDeclaration> 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<TypeDeclaration<?>> 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<Parameter> parameters = modifyList(n.getParameters(), arg); + ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); + NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg); + NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList<AnnotationExpr> 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<Expression> arguments = modifyList(n.getArguments(), arg); + NodeList<BodyDeclaration<?>> classBody = modifyList(n.getClassBody(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList<AnnotationExpr> 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<EnumConstantDeclaration> entries = modifyList(n.getEntries(), arg); + NodeList<ClassOrInterfaceType> implementedTypes = modifyList(n.getImplementedTypes(), arg); + NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList<AnnotationExpr> 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<Expression> arguments = modifyList(n.getArguments(), arg); + Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList<Type> 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<Type> 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<VariableDeclarator> variables = modifyList(n.getVariables(), arg); + NodeList<AnnotationExpr> 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<Expression> initialization = modifyList(n.getInitialization(), arg); + NodeList<Expression> 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<AnnotationExpr> 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<Expression> 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<Type> 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<Parameter> parameters = modifyList(n.getParameters(), arg); + ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); + NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg); + NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList<AnnotationExpr> 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<MemberValuePair> 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<BodyDeclaration<?>> anonymousClassBody = modifyList(n.getAnonymousClassBody(), arg); + NodeList<Expression> 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<Type> 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<AnnotationExpr> 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<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Type type = (Type) n.getType().accept(this, arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> 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<ReferenceType> elements = modifyList(n.getElements(), arg); + NodeList<AnnotationExpr> 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<ReferenceType> elements = modifyList(n.getElements(), arg); + NodeList<AnnotationExpr> 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<Statement> 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<SwitchEntryStmt> 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<CatchClause> catchClauses = modifyList(n.getCatchClauses(), arg); + BlockStmt finallyBlock = n.getFinallyBlock().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); + NodeList<Expression> 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<ClassOrInterfaceType> typeBound = modifyList(n.getTypeBound(), arg); + NodeList<AnnotationExpr> 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<AnnotationExpr> 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<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); + NodeList<VariableDeclarator> 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<AnnotationExpr> 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<AnnotationExpr> 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<Parameter> 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<Type> 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<Pair<Node, Node>> changeList = new ArrayList<>(); + final List<Node> listCopy = new ArrayList<>(n); + for (Node node : listCopy) { + final Node newNode = (Node) node.accept(this, arg); + changeList.add(new Pair<>(node, newNode)); + } + for (Pair<Node, Node> 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 <N extends Node> NodeList<N> modifyList(NodeList<N> list, A arg) { + return (NodeList<N>) list.accept(this, arg); + } + + private <N extends Node> NodeList<N> modifyList(Optional<NodeList<N>> 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<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); + NodeList<ModuleStmt> 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<Name> 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<Type> 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<Name> 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<AnnotationExpr> 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<AnnotationExpr> 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-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java new file mode 100644 index 000000000..b3c1dceff --- /dev/null +++ b/javaparser-core/src/main/java/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<Boolean, Visitable> { + + private static final NoCommentEqualsVisitor SINGLETON = new NoCommentEqualsVisitor(); + + public static boolean equals(final Node n, final Node n2) { + return SINGLETON.nodeEquals(n, n2); + } + + private <N extends Node> boolean nodesEquals(NodeList<N> n, NodeList<N> 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 <T extends Node> 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 <T extends Node> boolean nodeEquals(final Optional<T> n, final Optional<T> n2) { + return nodeEquals(n.orElse(null), n2.orElse(null)); + } + + private <T extends Node> boolean nodesEquals(final Optional<NodeList<T>> n, final Optional<NodeList<T>> 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<Node>) n, (NodeList<Node>) 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-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java new file mode 100644 index 000000000..774e5d914 --- /dev/null +++ b/javaparser-core/src/main/java/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<Integer, Void> { + + 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-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java new file mode 100644 index 000000000..7c642bbdb --- /dev/null +++ b/javaparser-core/src/main/java/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<Boolean, Visitable> { + + 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-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java new file mode 100644 index 000000000..c53cf79a8 --- /dev/null +++ b/javaparser-core/src/main/java/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<Integer, Void> { + + 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-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java new file mode 100644 index 000000000..3c4aecd9f --- /dev/null +++ b/javaparser-core/src/main/java/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 <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a> + */ + 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 <a href="https://en.wikipedia.org/wiki/Post-order">Post-order traversal</a> + */ + 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 <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a> + * @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<Node> 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-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java new file mode 100644 index 000000000..32c01a134 --- /dev/null +++ b/javaparser-core/src/main/java/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 <R> the type of the return value of the visitor + * @param <A> 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, A> R accept(GenericVisitor<R, A> v, A arg); + + /** + * Accept method for visitor support. + * + * @param <A> the type the argument passed for the visitor + * @param v the visitor implementation + * @param arg any value relevant for the visitor (of type A) + */ + <A> void accept(VoidVisitor<A> v, A arg); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java new file mode 100644 index 000000000..37c9c1c3b --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java @@ -0,0 +1,314 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<A> { + + 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-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java new file mode 100644 index 000000000..1ee82669a --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -0,0 +1,773 @@ +/* + * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied 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<A> implements VoidVisitor<A> { + + @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-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java new file mode 100644 index 000000000..6622567e6 --- /dev/null +++ b/javaparser-core/src/main/java/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<A> implements VoidVisitor<A> { + + /** + * 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); + } +} |