From 4e163d82329e4b7753af57999d07dde4ba00487a Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Wed, 3 Feb 2021 13:27:14 +0000 Subject: [PATCH 001/280] Simplified AssociableToAST --- .../declarations/AssociableToAST.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java index f71d9a2236..2e3f7ac547 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java @@ -27,9 +27,8 @@ /** * A declaration that can be potentially associated with an AST node. - * @param type of AST Node that can be associated */ -public interface AssociableToAST { +public interface AssociableToAST { /** * If the declaration is associated to an AST node return it, otherwise it return empty. @@ -52,7 +51,23 @@ public interface AssociableToAST { * In these cases getWrappedNode is particularly nice because it returns the right type of AST node, * not just a Node. */ - default Optional toAst() { - throw new UnsupportedOperationException(); + Optional toAst(); + + /** + * If the declaration is associated to an AST node and the type matches the expected {@link Class} return it, + * otherwise it returns empty. + * + * @param clazz The expected class of the AST Node. + * @param The expected type of AST Node. + * + * @return The declaration with the expected {@link Class}. + * + * @see AssociableToAST#toAst() + */ + default Optional toAst(Class clazz) { + return toAst() + .filter(clazz::isInstance) + .map(clazz::cast); } + } From 731fc791c80d8fda08ba1652e4a338353c766a83 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Feb 2021 13:40:05 +0000 Subject: [PATCH 002/280] Simplified classes that depend on AssociableToAST --- .../ResolvedAnnotationDeclaration.java | 5 +-- .../ResolvedClassDeclaration.java | 3 +- .../ResolvedConstructorDeclaration.java | 5 +-- .../declarations/ResolvedDeclaration.java | 2 +- .../ResolvedFieldDeclaration.java | 4 +-- .../ResolvedInterfaceDeclaration.java | 3 +- .../ResolvedMethodDeclaration.java | 4 +-- .../ResolvedTypeParameterDeclaration.java | 7 ++++ .../symbolsolver/JavaSymbolSolver.java | 7 ++++ .../contexts/CompilationUnitContext.java | 34 +++++-------------- .../DefaultConstructorDeclaration.java | 10 +++--- .../JavaParserAnnotationDeclaration.java | 9 ++--- ...JavaParserAnnotationMemberDeclaration.java | 9 +++++ .../JavaParserClassDeclaration.java | 20 +++-------- .../JavaParserConstructorDeclaration.java | 10 +++--- .../JavaParserEnumConstantDeclaration.java | 8 +++++ .../JavaParserEnumDeclaration.java | 18 ++++++---- .../JavaParserFieldDeclaration.java | 7 ++-- .../JavaParserInterfaceDeclaration.java | 24 ++++--------- .../JavaParserMethodDeclaration.java | 3 +- .../JavaParserParameterDeclaration.java | 7 ++-- .../JavaParserPatternDeclaration.java | 6 ++-- .../JavaParserSymbolDeclaration.java | 6 ++++ .../declarations/JavaParserTypeParameter.java | 6 ++++ .../JavaParserTypeVariableDeclaration.java | 4 +-- .../JavaParserVariableDeclaration.java | 7 ++-- .../JavassistAnnotationDeclaration.java | 4 +-- .../JavassistAnnotationMemberDeclaration.java | 33 ++++++++---------- .../JavassistConstructorDeclaration.java | 13 ++++--- .../JavassistEnumConstantDeclaration.java | 8 +++++ .../JavassistEnumDeclaration.java | 6 ++++ .../JavassistFieldDeclaration.java | 7 ++++ .../JavassistInterfaceDeclaration.java | 19 +++-------- .../JavassistMethodDeclaration.java | 8 +++-- .../JavassistParameterDeclaration.java | 9 +++++ .../JavassistTypeParameter.java | 12 +++++-- .../ReflectionAnnotationDeclaration.java | 4 +-- ...ReflectionAnnotationMemberDeclaration.java | 26 +++++++------- .../ReflectionConstructorDeclaration.java | 4 +-- .../ReflectionEnumConstantDeclaration.java | 7 ++++ .../ReflectionEnumDeclaration.java | 6 ++++ .../ReflectionFieldDeclaration.java | 7 ++++ .../ReflectionInterfaceDeclaration.java | 3 +- .../ReflectionMethodDeclaration.java | 4 +-- .../ReflectionParameterDeclaration.java | 7 ++++ .../ReflectionPatternDeclaration.java | 7 ++++ .../ReflectionTypeParameter.java | 6 ++++ 47 files changed, 247 insertions(+), 181 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java index 8d6c55d1f7..89859aca77 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java @@ -21,15 +21,12 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.AnnotationDeclaration; - import java.util.List; /** * @author Federico Tomassetti */ -public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, - AssociableToAST { +public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration { List getAnnotationMembers(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java index bf336f9241..0b6f0211cb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java @@ -21,7 +21,6 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.types.ResolvedReferenceType; import java.util.List; @@ -36,7 +35,7 @@ * @author Federico Tomassetti */ public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { + ResolvedTypeParametrizable, HasAccessSpecifier { /** * This method should always return true. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java index 5959f1f835..e04a1d3a1f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java @@ -21,15 +21,12 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.ConstructorDeclaration; - /** * A declaration of a constructor. * * @author Federico Tomassetti */ -public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, - AssociableToAST { +public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration { /** * A constructor can be declared in a class or an enum. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java index 53913aa349..93fe2abbea 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java @@ -26,7 +26,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedDeclaration { +public interface ResolvedDeclaration extends AssociableToAST { /** * Anonymous classes do not have a name, for example. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java index ded5dcd459..c38ea3faae 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java @@ -21,14 +21,12 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.FieldDeclaration; - /** * Declaration of a field. * * @author Federico Tomassetti */ -public interface ResolvedFieldDeclaration extends ResolvedValueDeclaration, HasAccessSpecifier, AssociableToAST { +public interface ResolvedFieldDeclaration extends ResolvedValueDeclaration, HasAccessSpecifier { /** * Is the field static? diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java index 5cc22165d9..8975fa5995 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java @@ -21,7 +21,6 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import java.util.ArrayList; @@ -33,7 +32,7 @@ * @author Federico Tomassetti */ public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { + ResolvedTypeParametrizable, HasAccessSpecifier { @Override default boolean isInterface() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java index 3fc3d801b7..2b474efd52 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -21,7 +21,6 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.types.ResolvedType; /** @@ -29,7 +28,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration, AssociableToAST { +public interface +ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration { /** * The type of the value returned by the current method. This method can also be invoked diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index 099b3ffe6f..a8875d1821 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.resolution.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.types.ResolvedType; import java.util.List; @@ -45,6 +46,7 @@ public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaratio */ static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List bounds) { return new ResolvedTypeParameterDeclaration() { + @Override public String getName() { return name; @@ -94,6 +96,11 @@ public String toString() { public Optional containerType() { throw new UnsupportedOperationException(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } }; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index d93a52cfd3..62f66334a8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -38,6 +38,8 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.Optional; + /** * This implementation of the SymbolResolver wraps the functionality of the library to make them easily usable * from JavaParser nodes. @@ -68,6 +70,11 @@ public String getName() { public ResolvedType getType() { return ResolvedPrimitiveType.INT; } + + @Override + public Optional toAst() { + return Optional.empty(); + } } private TypeSolver typeSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index 3107cd0240..a2dae1db7c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -22,14 +22,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; - -import static com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext.isQualifiedName; - -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; @@ -39,12 +31,7 @@ import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; @@ -56,6 +43,10 @@ import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -351,18 +342,9 @@ private String getMember(String qName) { } private boolean isAncestorOf(ResolvedTypeDeclaration descendant) { - if (descendant instanceof AssociableToAST) { - Optional astOpt = ((AssociableToAST) descendant).toAst(); - if (astOpt.isPresent()) { - return wrappedNode.isAncestorOf(astOpt.get()); - } else { - return false; - } - } else if (descendant instanceof JavaParserEnumDeclaration) { - return wrappedNode.isAncestorOf(((JavaParserEnumDeclaration) descendant).getWrappedNode()); - } else { - throw new UnsupportedOperationException(); - } + return descendant.toAst() + .filter(node -> wrappedNode.isAncestorOf(node)) + .isPresent(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java index 49864fc101..c646fa964f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java @@ -22,9 +22,11 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import java.util.Collections; @@ -86,7 +88,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java index 45b7094f8f..824584628b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.*; @@ -30,11 +31,7 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -141,7 +138,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java index 67451e1140..7e4326cdcb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; @@ -30,6 +31,8 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.Optional; + /** * @author Federico Tomassetti */ @@ -65,4 +68,10 @@ public String getName() { private Context getContext() { return JavaParserFactory.getContext(wrappedNode, typeSolver); } + + @Override + public Optional toAst() { + return Optional.of(wrappedNode); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 51409e2f67..32f492a776 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -21,29 +21,16 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -57,6 +44,9 @@ import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.*; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -149,7 +139,7 @@ public ResolvedTypeDeclaration declaringType() { } @Override - public Optional toAst() { + public Optional toAst() { return f.toAst(); } }); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java index 9be898cca5..d68800d54f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java @@ -22,9 +22,11 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; @@ -107,7 +109,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java index 25ca5ca751..ba60d9fe84 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java @@ -21,12 +21,15 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; +import java.util.Optional; + import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; /** @@ -61,4 +64,9 @@ public com.github.javaparser.ast.body.EnumConstantDeclaration getWrappedNode() { return wrappedNode; } + @Override + public Optional toAst() { + return Optional.of(wrappedNode); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index decb636e9d..9f1c68e06f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -26,7 +26,6 @@ import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -56,8 +55,7 @@ * @author Federico Tomassetti */ public class JavaParserEnumDeclaration extends AbstractTypeDeclaration - implements ResolvedEnumDeclaration, MethodResolutionCapability, MethodUsageResolutionCapability, - AssociableToAST { + implements ResolvedEnumDeclaration, MethodResolutionCapability, MethodUsageResolutionCapability { private TypeSolver typeSolver; private EnumDeclaration wrappedNode; @@ -327,7 +325,6 @@ public List getEnumConstants() { .collect(Collectors.toList()); } - /** * Needed by ContextHelper * @@ -417,7 +414,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } @@ -461,6 +458,7 @@ public int getNumberOfParams() { public ResolvedParameterDeclaration getParam(int i) { if (i == 0) { return new ResolvedParameterDeclaration() { + @Override public String getName() { return "name"; @@ -475,6 +473,12 @@ public ResolvedType getType() { public boolean isVariadic() { return false; } + + @Override + public Optional toAst() { + return Optional.empty(); + } + }; } @@ -531,7 +535,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } @@ -563,7 +567,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java index 293f20ebc7..25f54917bd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java @@ -23,10 +23,9 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; @@ -40,7 +39,7 @@ /** * @author Federico Tomassetti */ -public class JavaParserFieldDeclaration implements ResolvedFieldDeclaration, AssociableToAST { +public class JavaParserFieldDeclaration implements ResolvedFieldDeclaration { private VariableDeclarator variableDeclarator; private com.github.javaparser.ast.body.FieldDeclaration wrappedNode; @@ -111,7 +110,7 @@ public ResolvedTypeDeclaration declaringType() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.ofNullable(wrappedNode); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index a822942535..d6e462cc61 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -21,29 +21,14 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -58,6 +43,9 @@ import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.*; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -239,7 +227,7 @@ public ResolvedTypeDeclaration declaringType() { } @Override - public Optional toAst() { + public Optional toAst() { return f.toAst(); } }); @@ -376,7 +364,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java index ad1161308b..d68bb14b73 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java @@ -23,7 +23,6 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -159,7 +158,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java index fceabe0ec9..7311cd25a3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.type.UnknownType; -import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedType; @@ -38,7 +38,7 @@ /** * @author Federico Tomassetti */ -public class JavaParserParameterDeclaration implements ResolvedParameterDeclaration, AssociableToAST { +public class JavaParserParameterDeclaration implements ResolvedParameterDeclaration { private final Parameter wrappedNode; private final TypeSolver typeSolver; @@ -78,12 +78,13 @@ public ResolvedType getType() { * * @return A visitable JavaParser node wrapped by this object. */ + public Parameter getWrappedNode() { return wrappedNode; } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java index 47f6c77a69..d508566d30 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -35,7 +35,7 @@ * * @author Roger Howell */ -public class JavaParserPatternDeclaration implements ResolvedPatternDeclaration, AssociableToAST { +public class JavaParserPatternDeclaration implements ResolvedPatternDeclaration { private final PatternExpr wrappedNode; private final TypeSolver typeSolver; @@ -65,7 +65,7 @@ public PatternExpr getWrappedNode() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java index 83de669062..588d053df7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java @@ -39,6 +39,8 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.Optional; + import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; /** @@ -189,5 +191,9 @@ public Node getWrappedNode() { return wrappedNode; } + @Override + public Optional toAst() { + return Optional.of(wrappedNode); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 8927ea2180..c1f5ea1b06 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -231,4 +231,10 @@ public Optional containerType() { public List getConstructors() { return Collections.emptyList(); } + + @Override + public Optional toAst() { + return Optional.of(wrappedNode); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 3a8cd8e236..f44efd5c8c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -37,7 +37,7 @@ /** * @author Federico Tomassetti */ -public class JavaParserTypeVariableDeclaration extends AbstractTypeDeclaration implements AssociableToAST { +public class JavaParserTypeVariableDeclaration extends AbstractTypeDeclaration { private TypeParameter wrappedNode; private TypeSolver typeSolver; @@ -180,7 +180,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java index 6be6794377..54ae246dc7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -36,7 +36,7 @@ /** * @author Federico Tomassetti */ -public class JavaParserVariableDeclaration implements ResolvedValueDeclaration, AssociableToAST { +public class JavaParserVariableDeclaration implements ResolvedValueDeclaration { private VariableDeclarator variableDeclarator; private VariableDeclarationExpr wrappedNode; @@ -88,7 +88,8 @@ public String toString() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.of(wrappedNode); } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java index f4c7f1f515..6229c6dbf9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -150,7 +150,7 @@ public List getAnnotationMembers() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index c1546c6ab7..2606f4e70e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -21,17 +21,8 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; @@ -39,18 +30,16 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; - import javassist.CtClass; import javassist.CtMethod; import javassist.NotFoundException; import javassist.bytecode.AnnotationDefaultAttribute; -import javassist.bytecode.annotation.BooleanMemberValue; -import javassist.bytecode.annotation.CharMemberValue; -import javassist.bytecode.annotation.DoubleMemberValue; -import javassist.bytecode.annotation.IntegerMemberValue; -import javassist.bytecode.annotation.LongMemberValue; -import javassist.bytecode.annotation.MemberValue; -import javassist.bytecode.annotation.StringMemberValue; +import javassist.bytecode.annotation.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; /** * @author Malte Skoruppa @@ -106,4 +95,10 @@ public ResolvedType getType() { public String getName() { return annotationMember.getName(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java index f6265dadbe..fcc0f9c3df 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java @@ -22,14 +22,17 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import javassist.CtConstructor; import javassist.NotFoundException; -import javassist.bytecode.*; +import javassist.bytecode.BadBytecode; +import javassist.bytecode.SignatureAttribute; import java.util.Arrays; import java.util.Collections; @@ -156,7 +159,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java index e9db25eb14..5fe1b22960 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; @@ -28,6 +29,8 @@ import javassist.CtField; import javassist.bytecode.AccessFlag; +import java.util.Optional; + /** * @author Federico Tomassetti */ @@ -73,4 +76,9 @@ public String toString() { '}'; } + @Override + public Optional toAst() { + return Optional.empty(); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index a019861aca..07bdd3c3e1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -308,4 +309,9 @@ public String toString() { ", typeSolver=" + typeSolver + '}'; } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java index a4ec4407ea..63398d057d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; @@ -33,6 +34,7 @@ import javassist.bytecode.SignatureAttribute; import java.lang.reflect.Modifier; +import java.util.Optional; /** * @author Federico Tomassetti @@ -94,4 +96,9 @@ public AccessSpecifier accessSpecifier() { public ResolvedTypeDeclaration declaringType() { return JavassistFactory.toTypeDeclaration(ctField.getDeclaringClass(), typeSolver); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index d44d3b14ea..a1accb706c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -22,16 +22,10 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -53,12 +47,7 @@ import javassist.bytecode.SyntheticAttribute; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -325,7 +314,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java index 2b87c65a5f..82c6eb07c1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java @@ -23,7 +23,6 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; @@ -42,7 +41,10 @@ import javassist.bytecode.SignatureAttribute; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -217,7 +219,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java index a92214faef..20251b8afd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java @@ -21,15 +21,19 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import javassist.CtClass; +import java.util.Optional; + /** * @author Federico Tomassetti */ public class JavassistParameterDeclaration implements ResolvedParameterDeclaration { + private ResolvedType type; private TypeSolver typeSolver; private boolean variadic; @@ -89,4 +93,9 @@ public boolean isType() { public ResolvedType getType() { return type; } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java index 253c5583b0..b508533da3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java @@ -21,9 +21,12 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - import javassist.bytecode.SignatureAttribute; import java.util.ArrayList; @@ -117,4 +120,9 @@ public Optional containerType() { } return Optional.empty(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index ceef11fa8e..c19700c590 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -194,7 +194,7 @@ public List getAnnotationMembers() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index 2df69993cc..8bb1260c12 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -21,18 +21,8 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; @@ -41,6 +31,12 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; + /** * @author Malte Skoruppa */ @@ -89,4 +85,10 @@ public ResolvedType getType() { public String getName() { return annotationMember.getName(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java index 51e1b98dda..f5e9a3f565 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; @@ -102,7 +102,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java index af013d74ce..e26c629e22 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; @@ -28,6 +29,7 @@ import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; +import java.util.Optional; public class ReflectionEnumConstantDeclaration implements ResolvedEnumConstantDeclaration { @@ -53,4 +55,9 @@ public ResolvedType getType() { ResolvedReferenceTypeDeclaration typeDeclaration = new ReflectionEnumDeclaration(enumClass, typeSolver); return new ReferenceTypeImpl(typeDeclaration, typeSolver); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index b5bea9e76a..b778521fc4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -224,4 +225,9 @@ public Set internalTypes() { public List getConstructors() { return reflectionClassAdapter.getConstructors(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java index c1062430ec..c8cc9cda02 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; @@ -29,6 +30,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.Optional; /** * @author Federico Tomassetti @@ -99,4 +101,9 @@ public boolean isType() { public AccessSpecifier accessSpecifier() { return ReflectionFactory.modifiersToAccessLevel(field.getModifiers()); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index f2bd21baf3..bbb3261596 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -23,7 +23,6 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -326,7 +325,7 @@ public List getConstructors() { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java index e37b7901b0..b026473e77 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; @@ -159,7 +159,7 @@ public ResolvedType getSpecifiedException(int index) { } @Override - public Optional toAst() { + public Optional toAst() { return Optional.empty(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java index 729d240a60..4d68e81457 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java @@ -21,11 +21,13 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Objects; +import java.util.Optional; /** * @author Federico Tomassetti @@ -117,4 +119,9 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(type, genericType, typeSolver, variadic, name); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java index 96caa0af8c..f5d1e0fa89 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java @@ -21,10 +21,13 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.Optional; + /** * WARNING: Implemented fairly blindly. Unsure if required or even appropriate. Use with extreme caution. * @@ -82,4 +85,8 @@ public ResolvedType getType() { return ReflectionFactory.typeUsageFor(type, typeSolver); } + @Override + public Optional toAst() { + return Optional.empty(); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java index 76b37230ff..89a32fd290 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -132,4 +133,9 @@ public Optional containerType() { } return Optional.empty(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } From 666e8d7e73b386e3271ab191c26009c3309e1ae2 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Feb 2021 13:42:18 +0000 Subject: [PATCH 003/280] Updated tests to expect the correct behavior --- .../declarations/AssociableToASTTest.java | 30 ++++++++++++++----- .../declarations/ResolvedDeclarationTest.java | 2 +- .../ResolvedFieldDeclarationTest.java | 4 +-- .../symbolsolver/Issue1479Test.java | 17 +++++------ .../JavaParserEnumDeclarationTest.java | 3 +- .../JavaParserFieldDeclarationTest.java | 3 +- .../JavaParserInterfaceDeclarationTest.java | 5 ++-- .../JavaParserMethodDeclarationTest.java | 7 ++--- .../JavaParserParameterDeclarationTest.java | 6 ++-- .../JavaParserPatternDeclarationTest.java | 6 ++-- .../JavaParserTypeParameterTest.java | 11 +++++++ ...JavaParserTypeVariableDeclarationTest.java | 6 ++-- .../JavaParserVariableDeclarationTest.java | 8 ++--- .../JavassistAnnotationDeclarationTest.java | 9 ++++++ ...assistAnnotationMemberDeclarationTest.java | 9 ++++++ .../JavassistClassDeclarationTest.java | 12 +++++--- .../JavassistEnumConstantDeclarationTest.java | 9 ++++++ .../resolution/DefaultPackageTest.java | 12 ++++---- 18 files changed, 107 insertions(+), 52 deletions(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/AssociableToASTTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/AssociableToASTTest.java index 08ec4b0e0d..3cedd30b0f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/AssociableToASTTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/AssociableToASTTest.java @@ -29,24 +29,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -public interface AssociableToASTTest { +public interface AssociableToASTTest { /** * Helper method to cast the instance to the correct {@link Class}. * * @param instance The instance to be casted. * @param clazz The expected {@link Class}. - * @param The expected type. + * @param The expected type. * * @return The instance casted as the correct type. */ - default > R safeCast(AssociableToAST instance, Class clazz) { + default T safeCast(AssociableToAST instance, Class clazz) { if (clazz.isInstance(instance)) return clazz.cast(instance); throw new UnsupportedOperationException(String.format("Unable to cast %s into %s.", instance.getClass().getName(), clazz.getName())); } - AssociableToAST createValue(); + /** + * Create a new instance of {@link AssociableToAST} to be used for testing. + * + * @return The created instance. + */ + AssociableToAST createValue(); /** * Get the node that can be associated with an AST. @@ -55,16 +60,27 @@ default > R safeCast(AssociableToAST instance, C * * @return The node being wrapped. */ - Optional getWrappedDeclaration(AssociableToAST associableToAST); + Optional getWrappedDeclaration(AssociableToAST associableToAST); @Test default void checkThatToASTMatchesTheCorrectWrappedNode() { - AssociableToAST associableToAST = createValue(); - Optional wrappedNode = getWrappedDeclaration(associableToAST); + AssociableToAST associableToAST = createValue(); + Optional wrappedNode = getWrappedDeclaration(associableToAST); if (wrappedNode.isPresent()) assertEquals(wrappedNode, associableToAST.toAst()); else assertFalse(associableToAST.toAst().isPresent()); } + @Test + default void checkThatToASTWithCorrectTypeMatchesTheCorrectWrappedNode() { + AssociableToAST associableToAST = createValue(); + Optional wrappedNode = getWrappedDeclaration(associableToAST); + if (wrappedNode.isPresent()) + assertEquals(wrappedNode, associableToAST.toAst(wrappedNode.get().getClass())); + else + assertFalse(associableToAST.toAst().isPresent()); + + } + } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java index c395e51638..e4b228c104 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java @@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.*; -public interface ResolvedDeclarationTest { +public interface ResolvedDeclarationTest extends AssociableToASTTest { ResolvedDeclaration createValue(); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclarationTest.java index 01b23bb11d..27129dc851 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclarationTest.java @@ -21,13 +21,11 @@ package com.github.javaparser.resolution.declarations; -import com.github.javaparser.ast.body.FieldDeclaration; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -public interface ResolvedFieldDeclarationTest extends ResolvedValueDeclarationTest, HasAccessSpecifierTest, - AssociableToASTTest { +public interface ResolvedFieldDeclarationTest extends ResolvedValueDeclarationTest, HasAccessSpecifierTest { /** * Create a new non-static {@link ResolvedFieldDeclaration}. diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java index 1556dd84a1..70b0efdf0d 100755 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java @@ -1,13 +1,5 @@ package com.github.javaparser.symbolsolver; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.FieldDeclaration; @@ -16,6 +8,13 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue1479Test extends AbstractSymbolResolutionTest { @@ -40,7 +39,7 @@ public void test() throws IOException { assertTrue(fae.calculateResolvedType().describe().equals("java.lang.String")); ResolvedFieldDeclaration value = fae.resolve().asField(); assertTrue(value.getName().equals("AFIELD")); - Optional fd = value.toAst(); + Optional fd = value.toAst(FieldDeclaration.class); assertEquals("a", fd.get().getVariable(0).getInitializer().get().asStringLiteralExpr().getValue()); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java index a7d9f78216..d770ee414e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java @@ -59,8 +59,7 @@ import static org.junit.jupiter.api.Assertions.*; class JavaParserEnumDeclarationTest extends AbstractTypeDeclarationTest implements ResolvedEnumDeclarationTest, - MethodResolutionCapabilityTest, MethodUsageResolutionCapabilityTest, - AssociableToASTTest { + MethodResolutionCapabilityTest, MethodUsageResolutionCapabilityTest { private TypeSolver typeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclarationTest.java index f5a572f5ad..f8052f89d1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclarationTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.resolution.declarations.AssociableToAST; @@ -70,7 +71,7 @@ public ResolvedFieldDeclaration createStaticValue() { } @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserFieldDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java index 509b54d4ad..ceeb2ad458 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java @@ -25,6 +25,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -58,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -class JavaParserInterfaceDeclarationTest extends AbstractTypeDeclarationTest implements AssociableToASTTest { +class JavaParserInterfaceDeclarationTest extends AbstractTypeDeclarationTest { private TypeSolver typeSolver; @@ -905,7 +906,7 @@ void issue1528() { } @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserInterfaceDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java index f158c8b390..7511036b5b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclarationTest; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapabilityTest; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; @@ -32,11 +32,10 @@ import java.util.Optional; -class JavaParserMethodDeclarationTest implements ResolvedMethodDeclarationTest, TypeVariableResolutionCapabilityTest, - AssociableToASTTest { +class JavaParserMethodDeclarationTest implements ResolvedMethodDeclarationTest, TypeVariableResolutionCapabilityTest { @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserMethodDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclarationTest.java index 16bebf3fe4..80eebf5caf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclarationTest.java @@ -22,19 +22,19 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import java.util.Optional; -class JavaParserParameterDeclarationTest implements ResolvedParameterDeclarationTest, AssociableToASTTest { +class JavaParserParameterDeclarationTest implements ResolvedParameterDeclarationTest { @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserParameterDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclarationTest.java index dd35eeb3dd..8ad10b0b0f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclarationTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; @@ -33,7 +33,7 @@ import java.util.Optional; -class JavaParserPatternDeclarationTest implements ResolvedPatternDeclarationTest, AssociableToASTTest { +class JavaParserPatternDeclarationTest implements ResolvedPatternDeclarationTest { @BeforeAll public static void setup() { @@ -42,7 +42,7 @@ public static void setup() { } @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserPatternDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java index 58a0d007df..568f0200bf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java @@ -22,13 +22,17 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import java.util.Optional; + class JavaParserTypeParameterTest extends AbstractTypeDeclarationTest implements ResolvedTypeParameterDeclarationTest { @Override @@ -39,6 +43,13 @@ public JavaParserTypeParameter createValue() { return new JavaParserTypeParameter(typeParameter, typeSolver); } + @Override + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + return Optional.of( + safeCast(associableToAST, JavaParserTypeParameter.class).getWrappedNode() + ); + } + @Override public boolean isFunctionalInterface(AbstractTypeDeclaration typeDeclaration) { return false; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java index 0747866015..b588e08618 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; -class JavaParserTypeVariableDeclarationTest extends AbstractTypeDeclarationTest implements AssociableToASTTest { +class JavaParserTypeVariableDeclarationTest extends AbstractTypeDeclarationTest { @Override public JavaParserTypeVariableDeclaration createValue() { @@ -46,7 +46,7 @@ public JavaParserTypeVariableDeclaration createValue() { } @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserTypeVariableDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclarationTest.java index 47f63ea14d..1d4eebae1e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclarationTest.java @@ -23,21 +23,19 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclarationTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import java.util.Optional; -class JavaParserVariableDeclarationTest implements ResolvedValueDeclarationTest, - AssociableToASTTest { +class JavaParserVariableDeclarationTest implements ResolvedValueDeclarationTest { @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserVariableDeclaration.class).getWrappedNode() ); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java index eafa78200c..c7d918d52c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java @@ -21,6 +21,8 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; @@ -32,6 +34,8 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import java.util.Optional; + class JavassistAnnotationDeclarationTest extends AbstractTypeDeclarationTest implements ResolvedAnnotationDeclarationTest { @Override @@ -45,6 +49,11 @@ public JavassistAnnotationDeclaration createValue() { } } + @Override + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + return Optional.empty(); + } + @Override public boolean isFunctionalInterface(AbstractTypeDeclaration typeDeclaration) { return false; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java index 7ffe6d3b84..8efd587ce3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java @@ -21,6 +21,8 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; @@ -30,6 +32,8 @@ import javassist.CtMethod; import javassist.NotFoundException; +import java.util.Optional; + class JavassistAnnotationMemberDeclarationTest implements ResolvedAnnotationMemberDeclarationTest { @Override @@ -47,6 +51,11 @@ public JavassistAnnotationMemberDeclaration createValue() { } } + @Override + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + return Optional.empty(); + } + @Override public String getCanonicalNameOfExpectedType(ResolvedValueDeclaration resolvedDeclaration) { return "java.lang.StringBuilder"; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java index 706949fba8..e2f49e1aa4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java @@ -21,7 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -42,10 +44,7 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -510,6 +509,11 @@ public AbstractClassDeclaration createValue() { } } + @Override + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + return Optional.empty(); + } + @Override public boolean isFunctionalInterface(AbstractTypeDeclaration typeDeclaration) { return false; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java index a290057f71..14addbd9bf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java @@ -21,6 +21,8 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; @@ -30,6 +32,8 @@ import javassist.CtField; import javassist.NotFoundException; +import java.util.Optional; + class JavassistEnumConstantDeclarationTest implements ResolvedEnumConstantDeclarationTest { @Override @@ -44,6 +48,11 @@ public JavassistEnumConstantDeclaration createValue() { } } + @Override + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + return Optional.empty(); + } + @Override public String getCanonicalNameOfExpectedType(ResolvedValueDeclaration resolvedDeclaration) { return "java.time.DayOfWeek"; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java index fa8021a0fa..4348ca6870 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -33,11 +34,7 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import org.junit.jupiter.api.Test; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import static com.github.javaparser.StaticJavaParser.parse; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -150,6 +147,11 @@ public Optional containerType() { public SymbolReference solveMethod(String name, List argumentsTypes, boolean staticOnly) { throw new UnsupportedOperationException(); } + + @Override + public Optional toAst() { + return Optional.empty(); + } } @Test From f17174d0d12f825eba2c58c64cb7ecbf67ab36be Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Feb 2021 14:10:31 +0000 Subject: [PATCH 004/280] Enabled test that is now valid --- .../resolution/declarations/ResolvedDeclarationTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java index e4b228c104..4d1496225d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedDeclarationTest.java @@ -21,7 +21,6 @@ package com.github.javaparser.resolution.declarations; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -99,7 +98,6 @@ default void whenDeclarationIsATypeTheCallToTheMethodAsTypeShouldNotThrow() { * * @see AssociableToAST#toAst() */ - @Disabled(value = "This test is disabled, since not all of the classes implement this yet!") @Test default void declarationMostBeAssociableToAST() { ResolvedDeclaration resolvedDeclaration = createValue(); From c49a53c1c65a7de923b20e75dd5d9e7ec7902c83 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 16:40:04 +0000 Subject: [PATCH 005/280] Added NotNull and Nullable annotation --- .../github/javaparser/quality/NotNull.java | 30 +++++++++++++++++++ .../github/javaparser/quality/Nullable.java | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 javaparser-core/src/main/java/com/github/javaparser/quality/NotNull.java create mode 100644 javaparser-core/src/main/java/com/github/javaparser/quality/Nullable.java diff --git a/javaparser-core/src/main/java/com/github/javaparser/quality/NotNull.java b/javaparser-core/src/main/java/com/github/javaparser/quality/NotNull.java new file mode 100644 index 0000000000..c673f36c83 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/quality/NotNull.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.quality; + +import java.lang.annotation.*; + +@Inherited +@Documented +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.SOURCE) +public @interface NotNull { +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/quality/Nullable.java b/javaparser-core/src/main/java/com/github/javaparser/quality/Nullable.java new file mode 100644 index 0000000000..1407fe04c8 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/quality/Nullable.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.quality; + +import java.lang.annotation.*; + +@Inherited +@Documented +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.SOURCE) +public @interface Nullable { +} From df670882852a53fd8f885d9f32db7ba63d367750 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 16:40:25 +0000 Subject: [PATCH 006/280] Added Preconditions utils --- .../javaparser/quality/PreconditionsTest.java | 52 +++++++++++++ .../javaparser/quality/Preconditions.java | 78 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 javaparser-core-testing/src/test/java/com/github/javaparser/quality/PreconditionsTest.java create mode 100644 javaparser-core/src/main/java/com/github/javaparser/quality/Preconditions.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/quality/PreconditionsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/quality/PreconditionsTest.java new file mode 100644 index 0000000000..9a627c637d --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/quality/PreconditionsTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.quality; + +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.quality.Preconditions.checkArgument; +import static com.github.javaparser.quality.Preconditions.checkNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class PreconditionsTest { + + @Test + void checkArgument_withTrueExpression() { + checkArgument(true); + } + + @Test + void checkArgument_withFalseExpression() { + assertThrows(IllegalArgumentException.class, () -> checkArgument(false)); + } + + @Test + void checkNotNull_withNonNull() { + checkNotNull(new Object()); + } + + @Test + void checkNotNull_withNull() { + assertThrows(IllegalArgumentException.class, () -> checkNotNull(null)); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/quality/Preconditions.java b/javaparser-core/src/main/java/com/github/javaparser/quality/Preconditions.java new file mode 100644 index 0000000000..cd968b3b4c --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/quality/Preconditions.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.quality; + +public final class Preconditions { + + private Preconditions() { + // This constructor hide the public one. + } + + /** + * Ensures the truth of an expression involving one or more parameters to the calling method. + * + * @param expression a boolean expression. + * @param message the exception message to use if the check fails; + * will be converted to a string using String.valueOf(Object) + * + * @throws IllegalArgumentException if expression is false. + */ + public static void checkArgument(boolean expression, Object message) { + if (!expression) { + throw new IllegalArgumentException(String.valueOf(message)); + } + } + + /** + * Ensures the truth of an expression involving one or more parameters to the calling method. + * + * @param expression a boolean expression. + * + * @throws IllegalArgumentException if expression is false. + */ + public static void checkArgument(boolean expression) { + checkArgument(expression, "Invalid argument provided."); + } + + /** + * Ensures that an object reference passed as a parameter to the calling method is not null. + * + * @param reference an object reference. + * @param message the exception message to use if the check fails; + * will be converted to a string using String.valueOf(Object) + * + * @throws IllegalArgumentException if reference is {@code null}. + */ + public static void checkNotNull(Object reference, Object message) { + checkArgument(reference != null, message); + } + + /** + * Ensures that an object reference passed as a parameter to the calling method is not null. + * + * @param reference an object reference. + * + * @throws IllegalArgumentException if reference is {@code null}. + */ + public static void checkNotNull(Object reference) { + checkNotNull(reference, "A null value is not allowed here."); + } +} From 1792c5a8cb1a29a953a4b4e021dedc637bfc015f Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 16:43:46 +0000 Subject: [PATCH 007/280] Added NotNullGenerator --- .../generator/CompilationUnitGenerator.java | 46 +++++ .../generator/core/CoreGenerator.java | 5 +- .../core/quality/NotNullGenerator.java | 179 ++++++++++++++++++ 3 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 javaparser-core-generators/src/main/java/com/github/javaparser/generator/CompilationUnitGenerator.java create mode 100644 javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/CompilationUnitGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/CompilationUnitGenerator.java new file mode 100644 index 0000000000..db1fb71382 --- /dev/null +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/CompilationUnitGenerator.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.generator; + +import com.github.javaparser.ParseResult; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.utils.SourceRoot; + +import java.util.List; + +public abstract class CompilationUnitGenerator extends Generator { + + protected CompilationUnitGenerator(SourceRoot sourceRoot) { + super(sourceRoot); + } + + @Override + public void generate() throws Exception { + List> parsedCus = sourceRoot.tryToParse(); + for (ParseResult cu : parsedCus) { + cu.ifSuccessful(this::generateCompilationUnit); + } + } + + protected abstract void generateCompilationUnit(CompilationUnit compilationUnit); + +} diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java index f5b15fff1f..cea67cf398 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2020 The JavaParser Team. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. * * This file is part of JavaParser. * @@ -26,6 +26,7 @@ import com.github.javaparser.generator.core.node.*; import com.github.javaparser.generator.core.other.BndGenerator; import com.github.javaparser.generator.core.other.TokenKindGenerator; +import com.github.javaparser.generator.core.quality.NotNullGenerator; import com.github.javaparser.generator.core.visitor.*; import com.github.javaparser.utils.Log; import com.github.javaparser.utils.SourceRoot; @@ -97,5 +98,7 @@ private void run(SourceRoot sourceRoot, SourceRoot generatedJavaCcSourceRoot) th new AcceptGenerator(sourceRoot).generate(); new TokenKindGenerator(sourceRoot, generatedJavaCcSourceRoot).generate(); new BndGenerator(sourceRoot).generate(); + + new NotNullGenerator(sourceRoot).generate(); } } diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java new file mode 100644 index 0000000000..8819ba5e9d --- /dev/null +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.generator.core.quality; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.CallableDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.generator.CompilationUnitGenerator; +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; +import com.github.javaparser.utils.SourceRoot; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; + +/** + * Generator to process annotations {@link com.github.javaparser.quality.NotNull}. + */ +public class NotNullGenerator extends CompilationUnitGenerator { + + public NotNullGenerator(SourceRoot sourceRoot) { + super(sourceRoot); + } + + @Override + public void generateCompilationUnit(CompilationUnit compilationUnit) { + compilationUnit.findAll(ConstructorDeclaration.class).forEach(this::generateQualityForConstructor); + compilationUnit.findAll(MethodDeclaration.class).forEach(this::generateQualityForMethod); + } + + /** + * Generate the pre conditions based on the method parameters. + *
+ * If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is + * passed, the method should throw an {@link IllegalArgumentException}. + *
+ * If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be + * changed. + * + * @param methodDeclaration The method declaration to generate. + */ + protected void generateQualityForMethod(MethodDeclaration methodDeclaration) { + methodDeclaration.getBody().ifPresent(blockStmt -> + generateQualityForParameter(methodDeclaration, methodDeclaration.getParameters(), blockStmt)); + } + + /** + * Generate the pre conditions based on the constructor parameters. + *
+ * If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is + * passed, the method should throw an {@link IllegalArgumentException}. + *
+ * If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be + * changed. + * + * @param constructorDeclaration The constructor declaration to generate. + */ + protected void generateQualityForConstructor(ConstructorDeclaration constructorDeclaration) { + generateQualityForParameter(constructorDeclaration, constructorDeclaration.getParameters(), constructorDeclaration.getBody()); + } + + /** + * Generate the pre conditions for the parameters. + *
+ * If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is + * passed, the method should throw an {@link IllegalArgumentException}. + *
+ * If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be + * changed. + * + * @param callableDeclaration The declaration where the parameters belong. + * @param parameters The list of parameters. + * @param blockStmt The block where the assertions should be added. + * + * @param The callable declaration type. + */ + protected > + void generateQualityForParameter(N callableDeclaration, NodeList parameters, BlockStmt blockStmt) { + + List assertions = new ArrayList<>(); + + for (Parameter parameter : parameters) { + Optional nonNullAnnotation = parameter.getAnnotationByClass(NotNull.class); + if (nonNullAnnotation.isPresent()) { + assertions.add(createAssertion(parameter)); + } + } + + insertAssertionsInBlock(callableDeclaration, blockStmt, assertions); + } + + /** + * Create assertion for the parameters. + * + * @param parameter The parameter to create the assertion. + * + * @return The assertion to be added to the code. + */ + private Statement createAssertion(Parameter parameter) { + + parameter.tryAddImportToParentCompilationUnit(Preconditions.class); + return StaticJavaParser.parseStatement( + f("Preconditions.checkNotNull(%s, \"Parameter %s can't be null.\");", parameter.getNameAsString(), + parameter.getNameAsString()) + ); + } + + /** + * Insert the assertions into the block. + * + * @param callableDeclaration The declaration where the parameters belong. + * @param blockStmt The block where the assertions should be added. + * @param assertions The list of assertions to be inserted. + * + * @param The callable declaration type. + */ + private > + void insertAssertionsInBlock(N callableDeclaration, BlockStmt blockStmt, List assertions) { + + // If there's nothing to add, just ignore + if (assertions.isEmpty()) + return; + + int position = 0; + NodeList statements = blockStmt.getStatements(); + + // When the callable is a constructor we must check if is a ExplicitConstructorInvocationStmt. + if (callableDeclaration.isConstructorDeclaration()) { + Optional optionalFirstStatement = statements.getFirst(); + if (optionalFirstStatement.isPresent()) { + + // Check if the first item is a "super" expr. If it's then we add the assertions after it. + Statement firstStatement = optionalFirstStatement.get(); + if (firstStatement instanceof ExplicitConstructorInvocationStmt) { + position = 1; + } + } + } + + // Register assertions + for (int i = 0 ; i < assertions.size() ; i++) { + Statement assertion = assertions.get(i); + if (!statements.contains(assertion)) { + blockStmt.addStatement(position + i, assertion); + } + } + } + +} From fedecb9245eb9f2623145f3c5af41607979a18a6 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 16:44:15 +0000 Subject: [PATCH 008/280] Added tests for NotNullGenerator --- javaparser-core-generators/pom.xml | 27 +++++++ .../core/quality/NotNullGeneratorTest.java | 81 +++++++++++++++++++ .../expected/ConstructorParameterTest.java | 42 ++++++++++ .../ConstructorParameterWithSuperTest.java | 37 +++++++++ .../expected/MethodParameterTest.java | 33 ++++++++ .../original/ConstructorParameterTest.java | 40 +++++++++ .../ConstructorParameterWithSuperTest.java | 34 ++++++++ .../original/MethodParameterTest.java | 31 +++++++ 8 files changed, 325 insertions(+) create mode 100644 javaparser-core-generators/src/test/java/com/github/javaparser/generator/core/quality/NotNullGeneratorTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterWithSuperTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterTest.java diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 25d3132e36..82a4282876 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -1,4 +1,25 @@ + + javaparser-parent @@ -16,6 +37,12 @@ javaparser-core ${project.version} + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + diff --git a/javaparser-core-generators/src/test/java/com/github/javaparser/generator/core/quality/NotNullGeneratorTest.java b/javaparser-core-generators/src/test/java/com/github/javaparser/generator/core/quality/NotNullGeneratorTest.java new file mode 100644 index 0000000000..2d28c29056 --- /dev/null +++ b/javaparser-core-generators/src/test/java/com/github/javaparser/generator/core/quality/NotNullGeneratorTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.generator.core.quality; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.DefaultPrettyPrinter; +import com.github.javaparser.utils.SourceRoot; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +class NotNullGeneratorTest { + + @Test + void testExecutionOfGenerator() throws Exception { + + // Setup the + String resourcesFolderPath = getClass().getCanonicalName().replace(".", File.separator); + + String basePath = Paths.get("src", "test", "resources").toString(); + Path originalFile = Paths.get(basePath, resourcesFolderPath, "original"); + Path expectedFile = Paths.get(basePath, resourcesFolderPath, "expected"); + + SourceRoot originalSources = new SourceRoot(originalFile); + SourceRoot expectedSources = new SourceRoot(expectedFile); + expectedSources.tryToParse(); + + // Generate the information + new NotNullGenerator(originalSources).generate(); + + List editedSourceCus = originalSources.getCompilationUnits(); + List expectedSourcesCus = expectedSources.getCompilationUnits(); + assertEquals(expectedSourcesCus.size(), editedSourceCus.size()); + + // Check if all the files match the expected result + for (int i = 0 ; i < editedSourceCus.size() ; i++) { + + DefaultPrettyPrinter printer = new DefaultPrettyPrinter(); + String expectedCode = printer.print(expectedSourcesCus.get(i)); + String editedCode = printer.print(editedSourceCus.get(i)); + + if (!expectedCode.equals(editedCode)) { + System.out.println("Expected:"); + System.out.println("####"); + System.out.println(expectedSourcesCus.get(i)); + System.out.println("####"); + System.out.println("Actual:"); + System.out.println("####"); + System.out.println(editedSourceCus.get(i)); + System.out.println("####"); + fail("Actual code doesn't match with the expected code."); + } + } + } + +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterTest.java new file mode 100644 index 0000000000..15bfffaae5 --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.example; + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Nullable; +import com.github.javaparser.quality.Preconditions; + +class ConstructorParameterTest { + + private final String a; + + private final String b; + + private final String c; + + public ConstructorParameterTest(@NotNull String notNullString, @Nullable String nullableString, String otherString) { + Preconditions.checkNotNull(notNullString, "Parameter notNullString can't be null."); + this.a = notNullString; + this.b = nullableString; + this.c = otherString; + } +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java new file mode 100644 index 0000000000..35aaa3faa9 --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; + +class A { + + public A(String a) { + } +} + +class B { + + public B(@NotNull String c) { + super("ok"); + Preconditions.checkNotNull(c, "Parameter c can't be null."); + } +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterTest.java new file mode 100644 index 0000000000..5c5ba8ea50 --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; + +class A { + + public void method(@NotNull String notNull) { + Preconditions.checkNotNull(notNull, "Parameter notNull can't be null."); + } + + public void method(int age) { + } +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterTest.java new file mode 100644 index 0000000000..9f9a593a2d --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.example; + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Nullable; + +class ConstructorParameterTest { + + private final String a; + private final String b; + private final String c; + + public ConstructorParameterTest(@NotNull String notNullString, @Nullable String nullableString, + String otherString) { + this.a = notNullString; + this.b = nullableString; + this.c = otherString; + } + +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterWithSuperTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterWithSuperTest.java new file mode 100644 index 0000000000..293819157d --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/ConstructorParameterWithSuperTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; + +class A { + public A(String a) {} +} + +class B { + + public B(@NotNull String c) { + super("ok"); + } + +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterTest.java new file mode 100644 index 0000000000..f66e0b9475 --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; + +class A { + + public void method(@NotNull String notNull) {} + + public void method(int age) {} + +} From d7a0c865489aacdf73b565ac12e55a2ccb999a67 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 17:15:48 +0000 Subject: [PATCH 009/280] Removed uncessesary copyrights --- javaparser-core-generators/pom.xml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 82a4282876..ad097fab6b 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -1,25 +1,4 @@ - - javaparser-parent From 18d024c8eaca88323c48da9e678bd75fdd359290 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 17:23:59 +0000 Subject: [PATCH 010/280] Fixed testcase --- .../expected/ConstructorParameterWithSuperTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java index 35aaa3faa9..43649c6031 100644 --- a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/ConstructorParameterWithSuperTest.java @@ -1,3 +1,4 @@ +import com.github.javaparser.quality.NotNull; /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2021 The JavaParser Team. @@ -18,8 +19,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - -import com.github.javaparser.quality.NotNull; import com.github.javaparser.quality.Preconditions; class A { From 41cd008db118f06947d7c6a3316b594009167e56 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 5 Mar 2021 18:39:23 +0000 Subject: [PATCH 011/280] Generator now updates the message if it was changed. --- .../core/quality/NotNullGenerator.java | 31 ++++++++++++++++++- .../expected/MethodParameterRerunTest.java | 31 +++++++++++++++++++ .../original/MethodParameterRerunTest.java | 31 +++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterRerunTest.java create mode 100644 javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterRerunTest.java diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java index 8819ba5e9d..07c29020d5 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/quality/NotNullGenerator.java @@ -29,8 +29,10 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.generator.CompilationUnitGenerator; import com.github.javaparser.quality.NotNull; @@ -170,10 +172,37 @@ void insertAssertionsInBlock(N callableDeclaration, BlockStmt blockStmt, List optOldStmt = getSimilarAssertionInBlock(assertion, blockStmt); + + if (optOldStmt.isPresent()) { + optOldStmt.get().replace(assertion); + } else { blockStmt.addStatement(position + i, assertion); } } } + private Optional getSimilarAssertionInBlock(Statement assertion, BlockStmt blockStmt) { + + MethodCallExpr assertionCall = assertion.asExpressionStmt().getExpression().asMethodCallExpr(); + List methodCallExpressions = blockStmt.findAll(MethodCallExpr.class); + + for (MethodCallExpr blockMethodCall : methodCallExpressions) { + + // Check if the method calls name match + if ( + blockMethodCall.getNameAsExpression().equals(assertionCall.getNameAsExpression()) && + blockMethodCall.getScope().equals(assertionCall.getScope()) && + blockMethodCall.getArguments().size() == 2 && + blockMethodCall.getArguments().get(0).equals(assertionCall.getArgument(0)) + ) { + return blockMethodCall.findAncestor(ExpressionStmt.class); + } + + } + // TODO: + return Optional.empty(); + } + } diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterRerunTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterRerunTest.java new file mode 100644 index 0000000000..22e149edd2 --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/expected/MethodParameterRerunTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; + +class A { + + public void method(@NotNull String notNull, @NotNull String secondNotNull) { + Preconditions.checkNotNull(notNull, "Parameter notNull can't be null."); + Preconditions.checkNotNull(secondNotNull, "Parameter secondNotNull can't be null."); + } +} diff --git a/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterRerunTest.java b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterRerunTest.java new file mode 100644 index 0000000000..30ce35b47d --- /dev/null +++ b/javaparser-core-generators/src/test/resources/com/github/javaparser/generator/core/quality/NotNullGeneratorTest/original/MethodParameterRerunTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; + +class A { + + public void method(@NotNull String notNull, @NotNull String secondNotNull) { + Preconditions.checkNotNull(notNull, "This was aan old message."); + Preconditions.checkNotNull(secondNotNull, "Parameter secondNotNull can't be null."); + } +} From b85ccc602c05c406239b296ef43dec912bb61ab8 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 5 Mar 2021 18:47:56 +0000 Subject: [PATCH 012/280] Added @NotNull annotations to StaticJavaParser --- .../github/javaparser/StaticJavaParser.java | 87 +++++++++---------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java index aa4fb12823..abfb86cee8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java @@ -21,14 +21,6 @@ package com.github.javaparser; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.nio.charset.Charset; -import java.nio.file.Path; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; @@ -37,11 +29,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.expr.AnnotationExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.modules.ModuleDeclaration; import com.github.javaparser.ast.modules.ModuleDirective; import com.github.javaparser.ast.stmt.BlockStmt; @@ -51,6 +39,11 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.quality.NotNull; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.file.Path; /** * A simpler, static API than {@link JavaParser}. @@ -74,7 +67,7 @@ public static ParserConfiguration getConfiguration() { * Set the configuration for the static parse... methods. * This is a STATIC field, so modifying it will directly change how all static parse... methods work! */ - public static void setConfiguration(ParserConfiguration configuration) { + public static void setConfiguration(@NotNull ParserConfiguration configuration) { localConfiguration.set(configuration); } @@ -93,7 +86,7 @@ private static JavaParser newParser() { * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parse(final InputStream in, Charset encoding) { + public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Charset encoding) { return handleResult(newParser().parse(in, encoding)); } @@ -105,7 +98,7 @@ public static CompilationUnit parse(final InputStream in, Charset encoding) { * @return CompilationUnit representing the Java source code * @throws ParseProblemException if the source code has parser errors */ - public static CompilationUnit parse(final InputStream in) { + public static CompilationUnit parse(@NotNull final InputStream in) { return handleResult(newParser().parse(in)); } @@ -121,7 +114,7 @@ public static CompilationUnit parse(final InputStream in) { * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parse(final File file, final Charset encoding) throws FileNotFoundException { + public static CompilationUnit parse(@NotNull final File file, @NotNull final Charset encoding) throws FileNotFoundException { return handleResult(newParser().parse(file, encoding)); } @@ -134,7 +127,7 @@ public static CompilationUnit parse(final File file, final Charset encoding) thr * @throws ParseProblemException if the source code has parser errors * @throws FileNotFoundException the file was not found */ - public static CompilationUnit parse(final File file) throws FileNotFoundException { + public static CompilationUnit parse(@NotNull final File file) throws FileNotFoundException { return handleResult(newParser().parse(file)); } @@ -150,7 +143,7 @@ public static CompilationUnit parse(final File file) throws FileNotFoundExceptio * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parse(final Path path, final Charset encoding) throws IOException { + public static CompilationUnit parse(@NotNull final Path path, @NotNull final Charset encoding) throws IOException { return handleResult(newParser().parse(path, encoding)); } @@ -163,7 +156,7 @@ public static CompilationUnit parse(final Path path, final Charset encoding) thr * @throws ParseProblemException if the source code has parser errors * @throws IOException the path could not be accessed */ - public static CompilationUnit parse(final Path path) throws IOException { + public static CompilationUnit parse(@NotNull final Path path) throws IOException { return handleResult(newParser().parse(path)); } @@ -177,7 +170,7 @@ public static CompilationUnit parse(final Path path) throws IOException { * @throws ParseProblemException if the source code has parser errors * @throws IOException the path could not be accessed */ - public static CompilationUnit parseResource(final String path) throws IOException { + public static CompilationUnit parseResource(@NotNull final String path) throws IOException { return handleResult(newParser().parseResource(path)); } @@ -194,7 +187,7 @@ public static CompilationUnit parseResource(final String path) throws IOExceptio * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parseResource(final String path, Charset encoding) throws IOException { + public static CompilationUnit parseResource(@NotNull final String path, @NotNull Charset encoding) throws IOException { return handleResult(newParser().parseResource(path, encoding)); } @@ -211,7 +204,9 @@ public static CompilationUnit parseResource(final String path, Charset encoding) * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parseResource(final ClassLoader classLoader, final String path, Charset encoding) throws IOException { + public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, + @NotNull final String path, + @NotNull Charset encoding) throws IOException { return handleResult(newParser().parseResource(classLoader, path, encoding)); } @@ -223,7 +218,7 @@ public static CompilationUnit parseResource(final ClassLoader classLoader, final * @return CompilationUnit representing the Java source code * @throws ParseProblemException if the source code has parser errors */ - public static CompilationUnit parse(final Reader reader) { + public static CompilationUnit parse(@NotNull final Reader reader) { return handleResult(newParser().parse(reader)); } @@ -235,7 +230,7 @@ public static CompilationUnit parse(final Reader reader) { * @return CompilationUnit representing the Java source code * @throws ParseProblemException if the source code has parser errors */ - public static CompilationUnit parse(String code) { + public static CompilationUnit parse(@NotNull String code) { return handleResult(newParser().parse(code)); } @@ -247,7 +242,7 @@ public static CompilationUnit parse(String code) { * @return BlockStmt representing the Java block * @throws ParseProblemException if the source code has parser errors */ - public static BlockStmt parseBlock(final String blockStatement) { + public static BlockStmt parseBlock(@NotNull final String blockStatement) { return handleResult(newParser().parseBlock(blockStatement)); } @@ -259,7 +254,7 @@ public static BlockStmt parseBlock(final String blockStatement) { * @return Statement representing the Java statement * @throws ParseProblemException if the source code has parser errors */ - public static Statement parseStatement(final String statement) { + public static Statement parseStatement(@NotNull final String statement) { return handleResult(newParser().parseStatement(statement)); } @@ -278,7 +273,7 @@ private static T handleResult(ParseResult result) { * @return ImportDeclaration representing the Java import declaration * @throws ParseProblemException if the source code has parser errors */ - public static ImportDeclaration parseImport(final String importDeclaration) { + public static ImportDeclaration parseImport(@NotNull final String importDeclaration) { return handleResult(newParser().parseImport(importDeclaration)); } @@ -290,7 +285,7 @@ public static ImportDeclaration parseImport(final String importDeclaration) { * @return Expression representing the Java expression * @throws ParseProblemException if the source code has parser errors */ - public static T parseExpression(final String expression) { + public static T parseExpression(@NotNull final String expression) { return handleResult(newParser().parseExpression(expression)); } @@ -302,7 +297,7 @@ public static T parseExpression(final String expression) * @return AnnotationExpr representing the Java annotation * @throws ParseProblemException if the source code has parser errors */ - public static AnnotationExpr parseAnnotation(final String annotation) { + public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { return handleResult(newParser().parseAnnotation(annotation)); } @@ -314,7 +309,7 @@ public static AnnotationExpr parseAnnotation(final String annotation) { * @return BodyDeclaration representing the Java annotation * @throws ParseProblemException if the source code has parser errors */ - public static BodyDeclaration parseAnnotationBodyDeclaration(final String body) { + public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final String body) { return handleResult(newParser().parseAnnotationBodyDeclaration(body)); } @@ -326,7 +321,7 @@ public static BodyDeclaration parseAnnotationBodyDeclaration(final String bod * @return BodyDeclaration representing the Java interface body * @throws ParseProblemException if the source code has parser errors */ - public static BodyDeclaration parseBodyDeclaration(String body) { + public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { return handleResult(newParser().parseBodyDeclaration(body)); } @@ -337,7 +332,7 @@ public static BodyDeclaration parseBodyDeclaration(String body) { * @return ClassOrInterfaceType representing the type * @throws ParseProblemException if the source code has parser errors */ - public static ClassOrInterfaceType parseClassOrInterfaceType(String type) { + public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String type) { return handleResult(newParser().parseClassOrInterfaceType(type)); } @@ -348,7 +343,7 @@ public static ClassOrInterfaceType parseClassOrInterfaceType(String type) { * @return ClassOrInterfaceType representing the type * @throws ParseProblemException if the source code has parser errors */ - public static Type parseType(String type) { + public static Type parseType(@NotNull String type) { return handleResult(newParser().parseType(type)); } @@ -360,7 +355,7 @@ public static Type parseType(String type) { * @return VariableDeclarationExpr representing the type * @throws ParseProblemException if the source code has parser errors */ - public static VariableDeclarationExpr parseVariableDeclarationExpr(String declaration) { + public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull String declaration) { return handleResult(newParser().parseVariableDeclarationExpr(declaration)); } @@ -372,7 +367,7 @@ public static VariableDeclarationExpr parseVariableDeclarationExpr(String declar * @return Javadoc representing the content of the comment * @throws ParseProblemException if the source code has parser errors */ - public static Javadoc parseJavadoc(String content) { + public static Javadoc parseJavadoc(@NotNull String content) { return JavadocParser.parse(content); } @@ -383,7 +378,7 @@ public static Javadoc parseJavadoc(String content) { * @return the AST for the statement. * @throws ParseProblemException if the source code has parser errors */ - public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) { + public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(@NotNull String statement) { return handleResult(newParser().parseExplicitConstructorInvocationStmt(statement)); } @@ -394,7 +389,7 @@ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocati * @return the AST for the name * @throws ParseProblemException if the source code has parser errors */ - public static Name parseName(String qualifiedName) { + public static Name parseName(@NotNull String qualifiedName) { return handleResult(newParser().parseName(qualifiedName)); } @@ -405,7 +400,7 @@ public static Name parseName(String qualifiedName) { * @return the AST for the name * @throws ParseProblemException if the source code has parser errors */ - public static SimpleName parseSimpleName(String name) { + public static SimpleName parseSimpleName(@NotNull String name) { return handleResult(newParser().parseSimpleName(name)); } @@ -416,7 +411,7 @@ public static SimpleName parseSimpleName(String name) { * @return the AST for the parameter * @throws ParseProblemException if the source code has parser errors */ - public static Parameter parseParameter(String parameter) { + public static Parameter parseParameter(@NotNull String parameter) { return handleResult(newParser().parseParameter(parameter)); } @@ -427,7 +422,7 @@ public static Parameter parseParameter(String parameter) { * @return the AST for the parameter * @throws ParseProblemException if the source code has parser errors */ - public static PackageDeclaration parsePackageDeclaration(String packageDeclaration) { + public static PackageDeclaration parsePackageDeclaration(@NotNull String packageDeclaration) { return handleResult(newParser().parsePackageDeclaration(packageDeclaration)); } @@ -438,7 +433,7 @@ public static PackageDeclaration parsePackageDeclaration(String packageDeclarati * @return the AST for the type declaration * @throws ParseProblemException if the source code has parser errors */ - public static TypeDeclaration parseTypeDeclaration(String typeDeclaration) { + public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclaration) { return handleResult(newParser().parseTypeDeclaration(typeDeclaration)); } @@ -450,7 +445,7 @@ public static TypeDeclaration parseTypeDeclaration(String typeDeclaration) { * @throws ParseProblemException if the source code has parser errors * @see ModuleDeclaration */ - public static ModuleDeclaration parseModuleDeclaration(String moduleDeclaration) { + public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDeclaration) { return handleResult(newParser().parseModuleDeclaration(moduleDeclaration)); } @@ -462,7 +457,7 @@ public static ModuleDeclaration parseModuleDeclaration(String moduleDeclaration) * @throws ParseProblemException if the source code has parser errors * @see ModuleDirective */ - public static ModuleDirective parseModuleDirective(String moduleDirective) { + public static ModuleDirective parseModuleDirective(@NotNull String moduleDirective) { return handleResult(newParser().parseModuleDirective(moduleDirective)); } @@ -474,7 +469,7 @@ public static ModuleDirective parseModuleDirective(String moduleDirective) { * @return the AST for the type parameter * @throws ParseProblemException if the source code has parser errors */ - public static TypeParameter parseTypeParameter(String typeParameter) { + public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { return handleResult(newParser().parseTypeParameter(typeParameter)); } @@ -486,7 +481,7 @@ public static TypeParameter parseTypeParameter(String typeParameter) { * @throws ParseProblemException if the source code has parser errors * @see MethodDeclaration */ - public static MethodDeclaration parseMethodDeclaration(String methodDeclaration) { + public static MethodDeclaration parseMethodDeclaration(@NotNull String methodDeclaration) { return handleResult(newParser().parseMethodDeclaration(methodDeclaration)); } From 7876a3a8e640ff74610bfac018272e3021b86f1d Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 5 Mar 2021 18:51:47 +0000 Subject: [PATCH 013/280] Executed generators --- javaparser-core/bnd.bnd | 1 + .../github/javaparser/CommentsInserter.java | 70 +- .../com/github/javaparser/HasParentNode.java | 10 +- .../com/github/javaparser/JavaParser.java | 18 +- .../com/github/javaparser/JavadocParser.java | 33 +- .../LineEndingProcessingProvider.java | 12 +- .../javaparser/ParseProblemException.java | 2 +- .../com/github/javaparser/ParseResult.java | 5 +- .../com/github/javaparser/ParseStart.java | 22 +- .../javaparser/ParserConfiguration.java | 95 +- .../java/com/github/javaparser/Position.java | 27 +- .../java/com/github/javaparser/Problem.java | 10 +- .../java/com/github/javaparser/Providers.java | 11 +- .../java/com/github/javaparser/Range.java | 17 +- .../github/javaparser/StaticJavaParser.java | 49 +- .../com/github/javaparser/TokenRange.java | 15 +- .../com/github/javaparser/TokenTypes.java | 4 +- .../UnicodeEscapeProcessingProvider.java | 1135 ++++++++--------- .../javaparser/ast/AccessSpecifier.java | 6 +- .../javaparser/ast/AllFieldsConstructor.java | 1 - .../com/github/javaparser/ast/DataKey.java | 2 +- .../com/github/javaparser/ast/Generated.java | 5 +- .../com/github/javaparser/ast/NodeList.java | 13 +- .../ast/comments/CommentsCollection.java | 26 +- .../ast/nodeTypes/NodeWithAnnotations.java | 17 +- .../ast/nodeTypes/NodeWithArguments.java | 3 +- .../ast/nodeTypes/NodeWithBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithBody.java | 6 +- .../ast/nodeTypes/NodeWithCondition.java | 2 +- .../ast/nodeTypes/NodeWithDeclaration.java | 1 - .../ast/nodeTypes/NodeWithExpression.java | 2 +- .../ast/nodeTypes/NodeWithExtends.java | 2 - .../ast/nodeTypes/NodeWithIdentifier.java | 2 +- .../ast/nodeTypes/NodeWithImplements.java | 14 +- .../ast/nodeTypes/NodeWithJavadoc.java | 7 +- .../ast/nodeTypes/NodeWithMembers.java | 53 +- .../ast/nodeTypes/NodeWithModifiers.java | 11 +- .../ast/nodeTypes/NodeWithName.java | 2 +- .../nodeTypes/NodeWithOptionalBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithOptionalLabel.java | 4 +- .../ast/nodeTypes/NodeWithOptionalScope.java | 3 +- .../ast/nodeTypes/NodeWithParameters.java | 25 +- .../ast/nodeTypes/NodeWithRange.java | 8 +- .../ast/nodeTypes/NodeWithScope.java | 1 - .../ast/nodeTypes/NodeWithSimpleName.java | 2 +- .../ast/nodeTypes/NodeWithStatements.java | 2 +- .../nodeTypes/NodeWithThrownExceptions.java | 2 +- .../ast/nodeTypes/NodeWithTokenRange.java | 3 +- .../nodeTypes/NodeWithTraversableScope.java | 1 - .../ast/nodeTypes/NodeWithType.java | 2 +- .../ast/nodeTypes/NodeWithTypeArguments.java | 2 +- .../ast/nodeTypes/NodeWithTypeParameters.java | 2 +- .../ast/nodeTypes/NodeWithVariables.java | 5 +- .../javaparser/ast/nodeTypes/SwitchNode.java | 4 +- .../modifiers/NodeWithAbstractModifier.java | 2 +- .../modifiers/NodeWithAccessModifiers.java | 1 - .../modifiers/NodeWithFinalModifier.java | 2 +- .../modifiers/NodeWithPrivateModifier.java | 2 +- .../modifiers/NodeWithProtectedModifier.java | 2 +- .../modifiers/NodeWithPublicModifier.java | 3 +- .../modifiers/NodeWithStaticModifier.java | 2 - .../modifiers/NodeWithStrictfpModifier.java | 2 +- .../javaparser/ast/observer/AstObserver.java | 5 +- .../ast/observer/AstObserverAdapter.java | 1 - .../javaparser/ast/observer/Observable.java | 1 - .../ast/observer/PropagatingAstObserver.java | 3 +- .../ast/validator/ProblemReporter.java | 2 +- .../validator/ReservedKeywordValidator.java | 3 +- .../ast/validator/SimpleValidator.java | 2 +- .../validator/SingleNodeTypeValidator.java | 3 +- .../ast/validator/TreeVisitorValidator.java | 2 +- .../ast/validator/TypedValidator.java | 7 +- .../javaparser/ast/validator/Validator.java | 2 +- .../javaparser/ast/validator/Validators.java | 2 +- .../ast/validator/VisitorValidator.java | 2 +- .../Java10PreviewValidator.java | 10 - .../Java10Validator.java | 4 - .../Java11PreviewValidator.java | 10 - .../Java11Validator.java | 4 +- .../Java12PreviewValidator.java | 6 - .../Java12Validator.java | 3 - .../Java13PreviewValidator.java | 8 +- .../Java13Validator.java | 3 - .../Java14PreviewValidator.java | 11 +- .../Java14Validator.java | 2 - .../Java15PreviewValidator.java | 8 +- .../Java15Validator.java | 5 +- .../Java16PreviewValidator.java | 5 - .../Java16Validator.java | 5 +- .../Java1_0Validator.java | 108 +- .../Java1_1Validator.java | 12 +- .../Java1_2Validator.java | 3 +- .../Java1_3Validator.java | 2 +- .../Java1_4Validator.java | 2 +- .../Java5Validator.java | 7 +- .../Java6Validator.java | 4 +- .../Java7Validator.java | 7 +- .../Java8Validator.java | 22 +- .../Java9Validator.java | 11 +- .../chunks/CommonValidators.java | 76 +- .../chunks/ModifierValidator.java | 14 +- .../NoBinaryIntegerLiteralsValidator.java | 2 +- ...UnderscoresInIntegerLiteralsValidator.java | 2 +- .../chunks/UnderscoreKeywordValidator.java | 2 +- .../chunks/VarValidator.java | 14 +- .../postprocessors/Java10PostProcessor.java | 17 +- .../postprocessors/PostProcessors.java | 2 +- .../ast/visitor/ModifierVisitor.java | 84 +- .../javaparser/ast/visitor/TreeVisitor.java | 1 - .../javaparser/ast/visitor/Visitable.java | 2 +- .../github/javaparser/javadoc/Javadoc.java | 19 +- .../javaparser/javadoc/JavadocBlockTag.java | 26 +- .../description/JavadocDescription.java | 16 +- .../JavadocDescriptionElement.java | 2 +- .../javadoc/description/JavadocInlineTag.java | 27 +- .../javadoc/description/JavadocSnippet.java | 15 +- .../metamodel/BaseNodeMetaModel.java | 27 +- .../javaparser/metamodel/DerivedProperty.java | 1 - .../metamodel/InternalProperty.java | 1 - .../metamodel/NonEmptyProperty.java | 3 +- .../metamodel/OptionalProperty.java | 1 - .../metamodel/PropertyMetaModel.java | 24 +- .../printer/ConcreteSyntaxModel.java | 980 ++------------ .../printer/DefaultPrettyPrinter.java | 36 +- .../printer/DefaultPrettyPrinterVisitor.java | 314 +---- .../github/javaparser/printer/DotPrinter.java | 38 +- .../printer/PrettyPrintVisitor.java | 312 +---- .../javaparser/printer/PrettyPrinter.java | 20 +- .../github/javaparser/printer/Printer.java | 8 +- .../javaparser/printer/SourcePrinter.java | 52 +- .../github/javaparser/printer/Stringable.java | 1 + .../github/javaparser/printer/XmlPrinter.java | 7 +- .../javaparser/printer/YamlPrinter.java | 41 +- .../concretesyntaxmodel/CsmAttribute.java | 37 +- .../printer/concretesyntaxmodel/CsmChar.java | 2 +- .../concretesyntaxmodel/CsmComment.java | 2 - .../concretesyntaxmodel/CsmConditional.java | 15 +- .../concretesyntaxmodel/CsmElement.java | 8 +- .../concretesyntaxmodel/CsmIndent.java | 1 - .../printer/concretesyntaxmodel/CsmList.java | 6 +- .../printer/concretesyntaxmodel/CsmMix.java | 10 +- .../printer/concretesyntaxmodel/CsmNone.java | 3 - .../CsmOrphanCommentsEnding.java | 5 +- .../concretesyntaxmodel/CsmSequence.java | 2 +- .../CsmSingleReference.java | 2 +- .../concretesyntaxmodel/CsmString.java | 3 +- .../concretesyntaxmodel/CsmTextBlock.java | 6 +- .../printer/concretesyntaxmodel/CsmToken.java | 25 +- .../concretesyntaxmodel/CsmUnindent.java | 1 - .../concretesyntaxmodel/PrintingHelper.java | 3 +- .../configuration/ConfigurationOption.java | 3 +- .../DefaultConfigurationOption.java | 12 +- .../DefaultPrinterConfiguration.java | 55 +- .../printer/configuration/Indentation.java | 44 +- .../PrettyPrinterConfiguration.java | 56 +- .../configuration/PrinterConfiguration.java | 5 +- .../printer/lexicalpreservation/Added.java | 18 +- .../lexicalpreservation/ChildTextElement.java | 17 +- .../lexicalpreservation/Difference.java | 202 +-- .../DifferenceElement.java | 2 +- .../DifferenceElementCalculator.java | 91 +- .../printer/lexicalpreservation/Kept.java | 35 +- .../LexicalDifferenceCalculator.java | 84 +- .../LexicalPreservingPrinter.java | 185 +-- .../printer/lexicalpreservation/NodeText.java | 42 +- .../lexicalpreservation/PhantomNodeLogic.java | 22 +- .../printer/lexicalpreservation/Removed.java | 29 +- .../lexicalpreservation/RemovedGroup.java | 28 +- .../lexicalpreservation/Reshuffled.java | 16 +- .../lexicalpreservation/TextElement.java | 12 +- .../TextElementIteratorsFactory.java | 24 +- .../TextElementMatcher.java | 1 - .../TextElementMatchers.java | 2 +- .../lexicalpreservation/TokenTextElement.java | 18 +- .../WrappingRangeIterator.java | 3 +- .../lexicalpreservation/changes/Change.java | 3 +- .../changes/ListAdditionChange.java | 6 +- .../changes/ListRemovalChange.java | 8 +- .../changes/ListReplacementChange.java | 6 +- .../lexicalpreservation/changes/NoChange.java | 1 - .../changes/PropertyChange.java | 3 +- .../resolution/MethodAmbiguityException.java | 2 - .../javaparser/resolution/MethodUsage.java | 29 +- .../javaparser/resolution/Resolvable.java | 2 +- .../javaparser/resolution/SymbolResolver.java | 2 +- .../resolution/UnsolvedSymbolException.java | 7 +- .../declarations/AssociableToAST.java | 1 - .../declarations/HasAccessSpecifier.java | 2 - .../ResolvedAnnotationDeclaration.java | 4 +- .../ResolvedAnnotationMemberDeclaration.java | 1 - .../ResolvedClassDeclaration.java | 12 +- .../ResolvedConstructorDeclaration.java | 4 +- .../declarations/ResolvedDeclaration.java | 1 - .../ResolvedEnumConstantDeclaration.java | 1 - .../declarations/ResolvedEnumDeclaration.java | 7 +- .../ResolvedFieldDeclaration.java | 2 - .../ResolvedInterfaceDeclaration.java | 4 +- .../ResolvedMethodDeclaration.java | 2 - .../ResolvedMethodLikeDeclaration.java | 7 +- .../ResolvedParameterDeclaration.java | 1 - .../ResolvedPatternDeclaration.java | 2 - .../ResolvedReferenceTypeDeclaration.java | 85 +- .../declarations/ResolvedTypeDeclaration.java | 22 +- .../ResolvedTypeParameterDeclaration.java | 26 +- .../ResolvedTypeParametrizable.java | 2 - .../ResolvedValueDeclaration.java | 3 - .../resolution/types/ResolvedArrayType.java | 30 +- .../types/ResolvedIntersectionType.java | 15 +- .../types/ResolvedLambdaConstraintType.java | 8 +- .../types/ResolvedPrimitiveType.java | 42 +- .../types/ResolvedReferenceType.java | 225 ++-- .../resolution/types/ResolvedType.java | 51 +- .../types/ResolvedTypeTransformer.java | 2 +- .../types/ResolvedTypeVariable.java | 21 +- .../resolution/types/ResolvedUnionType.java | 23 +- .../resolution/types/ResolvedVoidType.java | 2 +- .../resolution/types/ResolvedWildcard.java | 29 +- .../ResolvedTypeParameterValueProvider.java | 4 - .../ResolvedTypeParametersMap.java | 30 +- .../ResolvedTypeParametrized.java | 2 +- .../github/javaparser/utils/ClassUtils.java | 2 +- .../javaparser/utils/CodeGenerationUtils.java | 2 +- .../javaparser/utils/CollectionStrategy.java | 2 - .../javaparser/utils/LineSeparator.java | 27 +- .../java/com/github/javaparser/utils/Log.java | 8 +- .../com/github/javaparser/utils/Pair.java | 18 +- .../utils/ParserCollectionStrategy.java | 9 +- .../javaparser/utils/PositionUtils.java | 51 +- .../github/javaparser/utils/ProjectRoot.java | 3 +- .../utils/SeparatedItemStringBuilder.java | 6 +- .../github/javaparser/utils/SourceRoot.java | 69 +- .../github/javaparser/utils/SourceZip.java | 16 +- .../javaparser/utils/StringEscapeUtils.java | 70 +- .../com/github/javaparser/utils/Utils.java | 20 +- .../github/javaparser/utils/VisitorList.java | 35 +- .../github/javaparser/utils/VisitorMap.java | 15 +- .../github/javaparser/utils/VisitorSet.java | 31 +- 237 files changed, 2291 insertions(+), 4253 deletions(-) diff --git a/javaparser-core/bnd.bnd b/javaparser-core/bnd.bnd index 9d1d1b49e2..9e678f6b78 100644 --- a/javaparser-core/bnd.bnd +++ b/javaparser-core/bnd.bnd @@ -29,6 +29,7 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core com.github.javaparser.printer.configuration, \ com.github.javaparser.printer.lexicalpreservation, \ com.github.javaparser.printer.lexicalpreservation.changes, \ + com.github.javaparser.quality, \ com.github.javaparser.resolution, \ com.github.javaparser.resolution.declarations, \ com.github.javaparser.resolution.types, \ diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java index 5dc320f046..cc0d11e0cb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -43,6 +42,7 @@ * @author Júlio Vilmar Gesser */ class CommentsInserter { + private final ParserConfiguration configuration; CommentsInserter(ParserConfiguration configuration) { @@ -56,20 +56,14 @@ class CommentsInserter { private void insertComments(CompilationUnit cu, TreeSet comments) { if (comments.isEmpty()) return; - /* I should sort all the direct children and the comments, if a comment is the first thing then it is a comment to the CompilationUnit */ - // FIXME if there is no package it could be also a comment to the following class... // so I could use some heuristics in these cases to distinguish the two // cases - List children = cu.getChildNodes(); - Comment firstComment = comments.iterator().next(); - if (cu.getPackageDeclaration().isPresent() - && (children.isEmpty() || PositionUtils.areInOrder( - firstComment, cu.getPackageDeclaration().get()))) { + if (cu.getPackageDeclaration().isPresent() && (children.isEmpty() || PositionUtils.areInOrder(firstComment, cu.getPackageDeclaration().get()))) { cu.setComment(firstComment); comments.remove(firstComment); } @@ -82,37 +76,23 @@ private void insertComments(CompilationUnit cu, TreeSet comments) { void insertComments(Node node, TreeSet commentsToAttribute) { if (commentsToAttribute.isEmpty()) return; - if (node instanceof CompilationUnit) { insertComments((CompilationUnit) node, commentsToAttribute); } - /* the comment can... 1) be inside one of the children, then the comment should be associated to this child 2) be outside all children. They could be preceding nothing, a comment or a child. If they preceed a child they are assigned to it, otherwise they remain "orphans" */ - - List children = node.getChildNodes().stream() - // Never attribute comments to modifiers. - .filter(n -> !(n instanceof Modifier)) - .collect(toList()); - + List children = node.getChildNodes().stream().filter(n -> !(n instanceof Modifier)).collect(toList()); boolean attributeToAnnotation = !(configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node child : children) { TreeSet commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION); - commentsInsideChild.addAll( - commentsToAttribute.stream() - .filter(comment -> comment.getRange().isPresent()) - .filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)) - .collect(toList()) - ); + commentsInsideChild.addAll(commentsToAttribute.stream().filter(comment -> comment.getRange().isPresent()).filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)).collect(toList())); commentsToAttribute.removeAll(commentsInsideChild); insertComments(child, commentsInsideChild); } - attributeLineCommentsOnSameLine(commentsToAttribute, children); - /* if a comment is on the line right before a node it should belong to that node*/ if (!commentsToAttribute.isEmpty()) { @@ -121,7 +101,6 @@ void insertComments(Node node, TreeSet commentsToAttribute) { commentsToAttribute.remove(commentsToAttribute.first()); } } - /* at this point I create an ordered list of all remaining comments and children */ Comment previousComment = null; @@ -130,11 +109,8 @@ void insertComments(Node node, TreeSet commentsToAttribute) { // Avoid attributing comments to a meaningless container. childrenAndComments.addAll(children); commentsToAttribute.removeAll(attributedComments); - childrenAndComments.addAll(commentsToAttribute); - PositionUtils.sortByBeginPosition(childrenAndComments, - configuration.isIgnoreAnnotationsWhenAttributingComments()); - + PositionUtils.sortByBeginPosition(childrenAndComments, configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node thing : childrenAndComments) { if (thing instanceof Comment) { previousComment = (Comment) thing; @@ -143,8 +119,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } else { if (previousComment != null && !thing.getComment().isPresent()) { - if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() - || !thereAreLinesBetween(previousComment, thing)) { + if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() || !thereAreLinesBetween(previousComment, thing)) { thing.setComment(previousComment); attributedComments.add(previousComment); previousComment = null; @@ -152,9 +127,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } } - commentsToAttribute.removeAll(attributedComments); - // all the remaining are orphan nodes for (Comment c : commentsToAttribute) { if (c.isOrphan()) { @@ -167,20 +140,13 @@ private void attributeLineCommentsOnSameLine(TreeSet commentsToAttribut /* I can attribute in line comments to elements preceeding them, if there is something contained in their line */ List attributedComments = new LinkedList<>(); - commentsToAttribute.stream() - .filter(comment -> comment.getRange().isPresent()) - .filter(Comment::isLineComment) - .forEach(comment -> children.stream() - .filter(child -> child.getRange().isPresent()) - .forEach(child -> { - Range commentRange = comment.getRange().get(); - Range childRange = child.getRange().get(); - if (childRange.end.line == commentRange.begin.line - && attributeLineCommentToNodeOrChild(child, - comment.asLineComment())) { - attributedComments.add(comment); - } - })); + commentsToAttribute.stream().filter(comment -> comment.getRange().isPresent()).filter(Comment::isLineComment).forEach(comment -> children.stream().filter(child -> child.getRange().isPresent()).forEach(child -> { + Range commentRange = comment.getRange().get(); + Range childRange = child.getRange().get(); + if (childRange.end.line == commentRange.begin.line && attributeLineCommentToNodeOrChild(child, comment.asLineComment())) { + attributedComments.add(comment); + } + })); commentsToAttribute.removeAll(attributedComments); } @@ -188,11 +154,9 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom if (!node.getRange().isPresent() || !lineComment.getRange().isPresent()) { return false; } - // The node start and end at the same line as the comment, // let's give to it the comment - if (node.getBegin().get().line == lineComment.getBegin().get().line - && !node.getComment().isPresent()) { + if (node.getBegin().get().line == lineComment.getBegin().get().line && !node.getComment().isPresent()) { if (!(node instanceof Comment)) { node.setComment(lineComment); } @@ -204,13 +168,11 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom children.addAll(node.getChildNodes()); PositionUtils.sortByBeginPosition(children); Collections.reverse(children); - for (Node child : children) { if (attributeLineCommentToNodeOrChild(child, lineComment)) { return true; } } - return false; } } @@ -227,8 +189,8 @@ private boolean thereAreLinesBetween(Node a, Node b) { } private boolean commentIsOnNextLine(Node a, Comment c) { - if (!c.getRange().isPresent() || !a.getRange().isPresent()) return false; + if (!c.getRange().isPresent() || !a.getRange().isPresent()) + return false; return c.getRange().get().end.line + 1 == a.getRange().get().begin.line; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java index 7ab0fa51d2..85fc685c0c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -18,15 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import java.util.Optional; -import java.util.function.Predicate; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.observer.Observable; +import java.util.Optional; +import java.util.function.Predicate; + /** * An object that can have a parent node. */ @@ -38,7 +37,7 @@ public interface HasParentNode extends Observable { default boolean hasParentNode() { return getParentNode().isPresent(); } - + /** * Returns the parent node, or {@code Optional.empty} if no parent is set. */ @@ -97,5 +96,4 @@ default Optional findAncestor(Class type, Predicate predicate) { default boolean isDescendantOf(Node ancestor) { return findAncestor(Node.class, n -> n == ancestor).isPresent(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java index ed576eda30..989dc5cfe9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -55,6 +54,7 @@ * @see StaticJavaParser */ public final class JavaParser { + private final ParserConfiguration configuration; private GeneratedJavaParser astParser = null; @@ -90,10 +90,9 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { } astParser.setTabSize(configuration.getTabSize()); astParser.setStoreTokens(configuration.isStoreTokens()); - ParserConfiguration.LanguageLevel languageLevel = configuration.getLanguageLevel(); if (languageLevel != null) { - if(languageLevel.isYieldSupported()) { + if (languageLevel.isYieldSupported()) { astParser.setYieldSupported(); } } @@ -113,22 +112,15 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { public ParseResult parse(ParseStart start, Provider provider) { assertNotNull(start); assertNotNull(provider); - for (PreProcessor preProcessor : configuration.getPreProcessors()) { provider = preProcessor.process(provider); } - final GeneratedJavaParser parser = getParserForProvider(provider); try { N resultNode = start.parse(parser); ParseResult result = new ParseResult<>(resultNode, parser.problems, parser.getCommentsCollection()); - - configuration.getPostProcessors() - .forEach(postProcessor -> postProcessor.process(result, configuration)); - - result.getProblems() - .sort(PROBLEM_BY_BEGIN_POSITION); - + configuration.getPostProcessors().forEach(postProcessor -> postProcessor.process(result, configuration)); + result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION); return result; } catch (Exception e) { final String message = e.getMessage() == null ? "Unknown error" : e.getMessage(); @@ -516,7 +508,6 @@ public ParseResult parseModuleDirective(String moduleDirective) return parse(MODULE_DIRECTIVE, provider(moduleDirective)); } - /** * Parses a type parameter and returns it as a TypeParameter * @@ -539,5 +530,4 @@ public ParseResult parseTypeParameter(String typeParameter) { public ParseResult parseMethodDeclaration(String methodDeclaration) { return parse(METHOD_DECLARATION, provider(methodDeclaration)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java index fd7ce3086f..1149d8ffe5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.JavadocBlockTag; import com.github.javaparser.javadoc.description.JavadocDescription; + import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -40,6 +40,7 @@ class JavadocParser { private static String BLOCK_TAG_PREFIX = "@"; + private static Pattern BLOCK_PATTERN = Pattern.compile("^\\s*" + BLOCK_TAG_PREFIX, Pattern.MULTILINE); public static Javadoc parse(JavadocComment comment) { @@ -48,11 +49,7 @@ public static Javadoc parse(JavadocComment comment) { public static Javadoc parse(String commentContent) { List cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, SYSTEM_EOL)); - int indexOfFirstBlockTag = cleanLines.stream() - .filter(JavadocParser::isABlockLine) - .map(cleanLines::indexOf) - .findFirst() - .orElse(-1); + int indexOfFirstBlockTag = cleanLines.stream().filter(JavadocParser::isABlockLine).map(cleanLines::indexOf).findFirst().orElse(-1); List blockLines; String descriptionText; if (indexOfFirstBlockTag == -1) { @@ -60,21 +57,13 @@ public static Javadoc parse(String commentContent) { blockLines = Collections.emptyList(); } else { descriptionText = trimRight(String.join(SYSTEM_EOL, cleanLines.subList(0, indexOfFirstBlockTag))); - - //Combine cleaned lines, but only starting with the first block tag till the end - //In this combined string it is easier to handle multiple lines which actually belong together - String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()) - .stream() - .collect(Collectors.joining(SYSTEM_EOL)); - - //Split up the entire tag back again, considering now that some lines belong to the same block tag. - //The pattern splits the block at each new line starting with the '@' symbol, thus the symbol - //then needs to be added again so that the block parsers handles everything correctly. - blockLines = BLOCK_PATTERN - .splitAsStream(tagBlock) - .filter(s1 -> !s1.isEmpty()) - .map(s -> BLOCK_TAG_PREFIX + s) - .collect(Collectors.toList()); + // Combine cleaned lines, but only starting with the first block tag till the end + // In this combined string it is easier to handle multiple lines which actually belong together + String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()).stream().collect(Collectors.joining(SYSTEM_EOL)); + // Split up the entire tag back again, considering now that some lines belong to the same block tag. + // The pattern splits the block at each new line starting with the '@' symbol, thus the symbol + // then needs to be added again so that the block parsers handles everything correctly. + blockLines = BLOCK_PATTERN.splitAsStream(tagBlock).filter(s1 -> !s1.isEmpty()).map(s -> BLOCK_TAG_PREFIX + s).collect(Collectors.toList()); } Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText)); blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l))); @@ -104,7 +93,6 @@ private static List cleanLines(String content) { if (lines.length == 0) { return Collections.emptyList(); } - List cleanedLines = Arrays.stream(lines).map(l -> { int asteriskIndex = startsWithAsterisk(l); if (asteriskIndex == -1) { @@ -113,7 +101,6 @@ private static List cleanLines(String content) { // if a line starts with space followed by an asterisk drop to the asterisk // if there is a space immediately after the asterisk drop it also if (l.length() > (asteriskIndex + 1)) { - char c = l.charAt(asteriskIndex + 1); if (c == ' ' || c == '\t') { return l.substring(asteriskIndex + 2); diff --git a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java index f13f2145d0..55438e8b8e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java @@ -82,11 +82,7 @@ private int fillBuffer() throws IOException { } public LineSeparator getDetectedLineEnding() { - return LineSeparator.getLineEnding( - eolCounts.getOrDefault(LineSeparator.CR, 0), - eolCounts.getOrDefault(LineSeparator.LF, 0), - eolCounts.getOrDefault(LineSeparator.CRLF, 0) - ); + return LineSeparator.getLineEnding(eolCounts.getOrDefault(LineSeparator.CR, 0), eolCounts.getOrDefault(LineSeparator.LF, 0), eolCounts.getOrDefault(LineSeparator.CRLF, 0)); } private boolean isBufferEmpty() { @@ -125,14 +121,11 @@ public int read(char[] buffer, final int offset, int len) throws IOException { } else { String str = String.valueOf((char) ch); Optional lookup = LineSeparator.lookup(str); - if (lookup.isPresent()) { LineSeparator lineSeparator = lookup.get(); - // Track the number of times this character is found.. eolCounts.putIfAbsent(lineSeparator, 0); eolCounts.put(lineSeparator, eolCounts.get(lineSeparator) + 1); - // Handle line separators of length two (specifically CRLF) // TODO: Make this more generic than just CRLF (e.g. track the previous char rather than the previous line separator if (lineSeparator == LineSeparator.LF) { @@ -141,19 +134,16 @@ public int read(char[] buffer, final int offset, int len) throws IOException { eolCounts.put(LineSeparator.CRLF, eolCounts.get(LineSeparator.CRLF) + 1); } } - // If "this" (current) char is a line separator, set the next loop's "previous" to this previousLineSeparator = lineSeparator; } else { // If "this" (current) char is not a line separator, set the next loop's "previous" to null previousLineSeparator = null; } - // Move to next character buffer[pos++] = (char) ch; } } return pos - offset; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java index 88d660dd07..4fd9f12828 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import java.util.List; @@ -31,6 +30,7 @@ * Thrown when parsing problems occur during parsing with the static methods on JavaParser. */ public class ParseProblemException extends RuntimeException { + /** * The problems that were encountered during parsing */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java index 7aa5f322e5..fae01c39d2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.Node; @@ -34,8 +33,11 @@ * The results given when parsing with an instance of JavaParser. */ public class ParseResult { + private final T result; + private final List problems; + private final CommentsCollection commentsCollection; /** @@ -110,6 +112,7 @@ public String toString() { * A post processor that can be added to ParserConfiguration to add some processing right after parsing. */ public interface PostProcessor { + void process(ParseResult result, ParserConfiguration configuration); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java index 1047137def..7bc8bb8526 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -49,26 +48,47 @@ */ @FunctionalInterface public interface ParseStart { + ParseStart COMPILATION_UNIT = GeneratedJavaParser::CompilationUnit; + ParseStart BLOCK = GeneratedJavaParser::BlockParseStart; + ParseStart STATEMENT = GeneratedJavaParser::BlockStatementParseStart; + ParseStart IMPORT_DECLARATION = GeneratedJavaParser::ImportDeclarationParseStart; + ParseStart EXPRESSION = GeneratedJavaParser::ExpressionParseStart; + ParseStart ANNOTATION = GeneratedJavaParser::AnnotationParseStart; + ParseStart> ANNOTATION_BODY = GeneratedJavaParser::AnnotationBodyDeclarationParseStart; + ParseStart> CLASS_BODY = GeneratedJavaParser::ClassOrInterfaceBodyDeclarationParseStart; + ParseStart CLASS_OR_INTERFACE_TYPE = GeneratedJavaParser::ClassOrInterfaceTypeParseStart; + ParseStart TYPE = GeneratedJavaParser::ResultTypeParseStart; + ParseStart TYPE_PARAMETER = GeneratedJavaParser::TypeParameterParseStart; + ParseStart VARIABLE_DECLARATION_EXPR = GeneratedJavaParser::VariableDeclarationExpressionParseStart; + ParseStart EXPLICIT_CONSTRUCTOR_INVOCATION_STMT = GeneratedJavaParser::ExplicitConstructorInvocationParseStart; + ParseStart NAME = GeneratedJavaParser::NameParseStart; + ParseStart SIMPLE_NAME = GeneratedJavaParser::SimpleNameParseStart; + ParseStart PARAMETER = GeneratedJavaParser::ParameterParseStart; + ParseStart PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart; + ParseStart> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart; + ParseStart MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart; + ParseStart MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart; + ParseStart METHOD_DECLARATION = GeneratedJavaParser::MethodDeclarationParseStart; R parse(GeneratedJavaParser parser) throws ParseException; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java index 25acd289fc..f855bbf7e3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ParseResult.PostProcessor; @@ -26,12 +25,13 @@ import com.github.javaparser.UnicodeEscapeProcessingProvider.PositionMapping; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.validator.*; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.Validator; import com.github.javaparser.ast.validator.language_level_validations.*; +import com.github.javaparser.ast.validator.postprocessors.Java10PostProcessor; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.utils.LineSeparator; -import com.github.javaparser.ast.validator.postprocessors.Java10PostProcessor; import java.nio.charset.Charset; import java.util.ArrayList; @@ -49,6 +49,7 @@ public class ParserConfiguration { public enum LanguageLevel { + /** * Java 1.0 */ @@ -163,28 +164,27 @@ public enum LanguageLevel { * Does no post processing or validation. Only for people wanting the fastest parsing. */ public static LanguageLevel RAW = null; + /** * The most used Java version. */ public static LanguageLevel POPULAR = JAVA_8; + /** * The latest Java version that is available. */ public static LanguageLevel CURRENT = JAVA_15; + /** * The newest Java features supported. */ public static LanguageLevel BLEEDING_EDGE = JAVA_16_PREVIEW; final Validator validator; + final ParseResult.PostProcessor postProcessor; - private static final LanguageLevel[] yieldSupport = new LanguageLevel[]{ - JAVA_13, JAVA_13_PREVIEW, - JAVA_14, JAVA_14_PREVIEW, - JAVA_15, JAVA_15_PREVIEW, - JAVA_16, JAVA_16_PREVIEW - }; + private static final LanguageLevel[] yieldSupport = new LanguageLevel[] { JAVA_13, JAVA_13_PREVIEW, JAVA_14, JAVA_14_PREVIEW, JAVA_15, JAVA_15_PREVIEW, JAVA_16, JAVA_16_PREVIEW }; LanguageLevel(Validator validator, ParseResult.PostProcessor postProcessor) { this.validator = validator; @@ -196,27 +196,36 @@ public boolean isYieldSupported() { } } - - // TODO: Add a configurable option e.g. setDesiredLineEnding(...) to replace/swap out existing line endings private boolean detectOriginalLineSeparator = true; + private boolean storeTokens = true; + private boolean attributeComments = true; + private boolean doNotAssignCommentsPrecedingEmptyLines = true; + private boolean ignoreAnnotationsWhenAttributingComments = false; + private boolean lexicalPreservationEnabled = false; + private boolean preprocessUnicodeEscapes = false; + private SymbolResolver symbolResolver = null; + private int tabSize = 1; + private LanguageLevel languageLevel = JAVA_8; + private Charset characterEncoding = Providers.UTF8; private final List preProcessors = new ArrayList<>(); + private final List postProcessors = new ArrayList<>(); public ParserConfiguration() { - class UnicodeEscapeProcessor implements PreProcessor, PostProcessor { + private UnicodeEscapeProcessingProvider _unicodeDecoder; @Override @@ -229,24 +238,19 @@ public Provider process(Provider innerProvider) { } @Override - public void process(ParseResult result, - ParserConfiguration configuration) { + public void process(ParseResult result, ParserConfiguration configuration) { if (isPreprocessUnicodeEscapes()) { - result.getResult().ifPresent( - root -> { - PositionMapping mapping = _unicodeDecoder.getPositionMapping(); - if (!mapping.isEmpty()) { - root.walk( - node -> node.getRange().ifPresent( - range -> node.setRange(mapping.transform(range)))); - } - } - ); + result.getResult().ifPresent(root -> { + PositionMapping mapping = _unicodeDecoder.getPositionMapping(); + if (!mapping.isEmpty()) { + root.walk(node -> node.getRange().ifPresent(range -> node.setRange(mapping.transform(range)))); + } + }); } } } - class LineEndingProcessor implements PreProcessor, PostProcessor { + private LineEndingProcessingProvider _lineEndingProcessingProvider; @Override @@ -261,36 +265,26 @@ public Provider process(Provider innerProvider) { @Override public void process(ParseResult result, ParserConfiguration configuration) { if (isDetectOriginalLineSeparator()) { - result.getResult().ifPresent( - rootNode -> { - LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); - - // Set the line ending on the root node - rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); - -// // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" -// rootNode.findAll(Node.class) -// .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); - } - ); + result.getResult().ifPresent(rootNode -> { + LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); + // Set the line ending on the root node + rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); + // // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" + // rootNode.findAll(Node.class) + // .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); + }); } } } - UnicodeEscapeProcessor unicodeProcessor = new UnicodeEscapeProcessor(); preProcessors.add(unicodeProcessor); postProcessors.add(unicodeProcessor); - LineEndingProcessor lineEndingProcessor = new LineEndingProcessor(); preProcessors.add(lineEndingProcessor); postProcessors.add(lineEndingProcessor); - - postProcessors.add((result, configuration) -> { if (configuration.isAttributeComments()) { - result.ifSuccessful(resultNode -> result - .getCommentsCollection().ifPresent(comments -> - new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); + result.ifSuccessful(resultNode -> result.getCommentsCollection().ifPresent(comments -> new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); } }); postProcessors.add((result, configuration) -> { @@ -304,13 +298,11 @@ public void process(ParseResult result, ParserConfiguration conf } } }); - postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver -> - result.ifSuccessful(resultNode -> { - if (resultNode instanceof CompilationUnit) { - resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); - } - }) - )); + postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver -> result.ifSuccessful(resultNode -> { + if (resultNode instanceof CompilationUnit) { + resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); + } + }))); postProcessors.add((result, configuration) -> { if (configuration.isLexicalPreservationEnabled()) { result.ifSuccessful(LexicalPreservingPrinter::setup); @@ -456,5 +448,4 @@ public ParserConfiguration setCharacterEncoding(Charset characterEncoding) { this.characterEncoding = characterEncoding; return this; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index 907bf351c4..d730db2085 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -18,11 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import com.github.javaparser.ast.Node; - import java.util.Objects; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -31,23 +28,26 @@ * A position in a source file. Lines and columns start counting at 1. */ public class Position implements Comparable { + public final int line; + public final int column; /** * The first line -- note that it is 1-indexed (i.e. the first line is line 1, as opposed to 0) */ public static final int FIRST_LINE = 1; + /** * The first column -- note that it is 1-indexed (i.e. the first column is column 1, as opposed to 0) */ public static final int FIRST_COLUMN = 1; + /** * The first position in the file. */ public static final Position HOME = new Position(FIRST_LINE, FIRST_COLUMN); - /** * Line numbers must be positive, thus */ @@ -55,7 +55,6 @@ public class Position implements Comparable { public static final int ABSOLUTE_END_LINE = -2; - /** * TODO: Do we refer to the characters as columns, * ...or the spaces between (thus also before/after) characters as columns? @@ -67,8 +66,8 @@ public Position(int line, int column) { } if (column < -1) { // TODO: This allows/permits column 0, which seemingly contradicts first column being 1 - // ... (see also nextLine() which indicates 1 being the first column of the next line) - // ... (see also valid() which requires a column > 0) + // ... (see also nextLine() which indicates 1 being the first column of the next line) + // ... (see also valid() which requires a column > 0) // TODO: Maybe we need an "ABSOLUTE_BEGIN_LINE" and "ABSOLUTE_END_LINE"? throw new IllegalArgumentException("Can't position at column " + column); } @@ -140,7 +139,7 @@ public boolean invalid() { public Position orIfInvalid(Position alternativePosition) { assertNotNull(alternativePosition); // TODO: Why the || ? - // ... It seems that if both this and the alternative are invalid, then we return this..? + // ... It seems that if both this and the alternative are invalid, then we return this..? if (valid() || alternativePosition.invalid()) { return this; } @@ -159,7 +158,6 @@ public boolean isAfter(Position otherPosition) { return column > otherPosition.column; } return false; - } public boolean isAfterOrEqual(Position otherPosition) { @@ -200,13 +198,12 @@ public int compareTo(Position otherPosition) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Position otherPosition = (Position) o; - - return Objects.equals(line, otherPosition.line) - && Objects.equals(column, otherPosition.column); + return Objects.equals(line, otherPosition.line) && Objects.equals(column, otherPosition.column); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/Problem.java b/javaparser-core/src/main/java/com/github/javaparser/Problem.java index f881daffef..d1cbd2daeb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Problem.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Problem.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import java.util.Comparator; @@ -31,13 +30,15 @@ * A problem that was encountered during parsing. */ public class Problem { + private final String message; + private final TokenRange location; + private final Throwable cause; public Problem(String message, TokenRange location, Throwable cause) { assertNotNull(message); - this.message = message; this.location = location; this.cause = cause; @@ -90,9 +91,8 @@ public Optional getCause() { * Sorts problems on position. */ public static Comparator PROBLEM_BY_BEGIN_POSITION = (a, b) -> { - final Optional aBegin= a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + final Optional aBegin = a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); final Optional bBegin = b.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); - if (aBegin.isPresent() && bBegin.isPresent()) { return aBegin.get().compareTo(bBegin.get()); } @@ -104,6 +104,4 @@ public Optional getCause() { } return 0; }; - - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Providers.java b/javaparser-core/src/main/java/com/github/javaparser/Providers.java index 07a86f5683..c907fcdd6f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Providers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Providers.java @@ -18,15 +18,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; +import java.io.*; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -38,6 +32,7 @@ * use UTF-8. */ public final class Providers { + public static final Charset UTF8 = Charset.forName("utf-8"); private Providers() { @@ -83,7 +78,6 @@ public static Provider provider(String source) { return new StringProvider(assertNotNull(source)); } - /** * Provide a Provider from the resource found in class loader with the provided encoding.
As resource is * accessed through a class loader, a leading "/" is not allowed in pathToResource @@ -114,6 +108,7 @@ public static Provider resourceProvider(String pathToResource) throws IOExceptio } public interface PreProcessor { + Provider process(Provider innerProvider); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Range.java b/javaparser-core/src/main/java/com/github/javaparser/Range.java index 796e026a59..0dfc747afe 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Range.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Range.java @@ -18,16 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import static com.github.javaparser.Position.pos; - /** * A range of characters in a source file, from "begin" to "end", including the characters at "begin" and "end". */ public class Range { + public final Position begin; + public final Position end; /** @@ -46,7 +45,6 @@ public Range(Position begin, Position end) { if (end == null) { throw new IllegalArgumentException("end can't be null"); } - // Force `begin` to be the position that is earliest within the document: if (begin.isBefore(end)) { this.begin = begin; @@ -118,7 +116,6 @@ public Range withEndLine(int endLine) { return range(begin, end.withLine(endLine)); } - /** * @param begin The value used to replace the current begin position. * @return A copy of this `Range` object, but with the begin position replaced with the given position. @@ -193,8 +190,7 @@ public boolean strictlyContains(Position position) { * Range 2: CDE */ public boolean overlapsWith(Range other) { - return (contains(other.begin) || contains(other.end)) || - (other.contains(begin) || other.contains(end)); + return (contains(other.begin) || contains(other.end)) || (other.contains(begin) || other.contains(end)); } /** @@ -215,9 +211,10 @@ public boolean isAfter(Position position) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Range range = (Range) o; return begin.equals(range.begin) && end.equals(range.end); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java index abfb86cee8..7e7da4fb07 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -40,6 +39,7 @@ import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; import java.io.*; import java.nio.charset.Charset; @@ -49,7 +49,7 @@ * A simpler, static API than {@link JavaParser}. */ public final class StaticJavaParser { - + // use ThreadLocal to resolve possible concurrency issues. private static ThreadLocal localConfiguration = ThreadLocal.withInitial(() -> new ParserConfiguration()); @@ -68,6 +68,7 @@ public static ParserConfiguration getConfiguration() { * This is a STATIC field, so modifying it will directly change how all static parse... methods work! */ public static void setConfiguration(@NotNull ParserConfiguration configuration) { + Preconditions.checkNotNull(configuration, "Parameter configuration can't be null."); localConfiguration.set(configuration); } @@ -87,6 +88,8 @@ private static JavaParser newParser() { */ @Deprecated public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Charset encoding) { + Preconditions.checkNotNull(in, "Parameter in can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(in, encoding)); } @@ -99,6 +102,7 @@ public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Char * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final InputStream in) { + Preconditions.checkNotNull(in, "Parameter in can't be null."); return handleResult(newParser().parse(in)); } @@ -115,6 +119,8 @@ public static CompilationUnit parse(@NotNull final InputStream in) { */ @Deprecated public static CompilationUnit parse(@NotNull final File file, @NotNull final Charset encoding) throws FileNotFoundException { + Preconditions.checkNotNull(file, "Parameter file can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(file, encoding)); } @@ -128,6 +134,7 @@ public static CompilationUnit parse(@NotNull final File file, @NotNull final Cha * @throws FileNotFoundException the file was not found */ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoundException { + Preconditions.checkNotNull(file, "Parameter file can't be null."); return handleResult(newParser().parse(file)); } @@ -144,6 +151,8 @@ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoun */ @Deprecated public static CompilationUnit parse(@NotNull final Path path, @NotNull final Charset encoding) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(path, encoding)); } @@ -157,6 +166,7 @@ public static CompilationUnit parse(@NotNull final Path path, @NotNull final Cha * @throws IOException the path could not be accessed */ public static CompilationUnit parse(@NotNull final Path path) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parse(path)); } @@ -171,6 +181,7 @@ public static CompilationUnit parse(@NotNull final Path path) throws IOException * @throws IOException the path could not be accessed */ public static CompilationUnit parseResource(@NotNull final String path) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parseResource(path)); } @@ -188,6 +199,8 @@ public static CompilationUnit parseResource(@NotNull final String path) throws I */ @Deprecated public static CompilationUnit parseResource(@NotNull final String path, @NotNull Charset encoding) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parseResource(path, encoding)); } @@ -204,9 +217,10 @@ public static CompilationUnit parseResource(@NotNull final String path, @NotNull * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, - @NotNull final String path, - @NotNull Charset encoding) throws IOException { + public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, @NotNull final String path, @NotNull Charset encoding) throws IOException { + Preconditions.checkNotNull(classLoader, "Parameter classLoader can't be null."); + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parseResource(classLoader, path, encoding)); } @@ -219,6 +233,7 @@ public static CompilationUnit parseResource(@NotNull final ClassLoader classLoad * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final Reader reader) { + Preconditions.checkNotNull(reader, "Parameter reader can't be null."); return handleResult(newParser().parse(reader)); } @@ -231,6 +246,7 @@ public static CompilationUnit parse(@NotNull final Reader reader) { * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull String code) { + Preconditions.checkNotNull(code, "Parameter code can't be null."); return handleResult(newParser().parse(code)); } @@ -243,6 +259,7 @@ public static CompilationUnit parse(@NotNull String code) { * @throws ParseProblemException if the source code has parser errors */ public static BlockStmt parseBlock(@NotNull final String blockStatement) { + Preconditions.checkNotNull(blockStatement, "Parameter blockStatement can't be null."); return handleResult(newParser().parseBlock(blockStatement)); } @@ -255,6 +272,7 @@ public static BlockStmt parseBlock(@NotNull final String blockStatement) { * @throws ParseProblemException if the source code has parser errors */ public static Statement parseStatement(@NotNull final String statement) { + Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseStatement(statement)); } @@ -274,6 +292,7 @@ private static T handleResult(ParseResult result) { * @throws ParseProblemException if the source code has parser errors */ public static ImportDeclaration parseImport(@NotNull final String importDeclaration) { + Preconditions.checkNotNull(importDeclaration, "Parameter importDeclaration can't be null."); return handleResult(newParser().parseImport(importDeclaration)); } @@ -286,6 +305,7 @@ public static ImportDeclaration parseImport(@NotNull final String importDeclarat * @throws ParseProblemException if the source code has parser errors */ public static T parseExpression(@NotNull final String expression) { + Preconditions.checkNotNull(expression, "Parameter expression can't be null."); return handleResult(newParser().parseExpression(expression)); } @@ -298,6 +318,7 @@ public static T parseExpression(@NotNull final String exp * @throws ParseProblemException if the source code has parser errors */ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { + Preconditions.checkNotNull(annotation, "Parameter annotation can't be null."); return handleResult(newParser().parseAnnotation(annotation)); } @@ -310,6 +331,7 @@ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final String body) { + Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseAnnotationBodyDeclaration(body)); } @@ -322,6 +344,7 @@ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final S * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { + Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseBodyDeclaration(body)); } @@ -333,6 +356,7 @@ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { * @throws ParseProblemException if the source code has parser errors */ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String type) { + Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseClassOrInterfaceType(type)); } @@ -344,6 +368,7 @@ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String typ * @throws ParseProblemException if the source code has parser errors */ public static Type parseType(@NotNull String type) { + Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseType(type)); } @@ -356,6 +381,7 @@ public static Type parseType(@NotNull String type) { * @throws ParseProblemException if the source code has parser errors */ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull String declaration) { + Preconditions.checkNotNull(declaration, "Parameter declaration can't be null."); return handleResult(newParser().parseVariableDeclarationExpr(declaration)); } @@ -368,6 +394,7 @@ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull Stri * @throws ParseProblemException if the source code has parser errors */ public static Javadoc parseJavadoc(@NotNull String content) { + Preconditions.checkNotNull(content, "Parameter content can't be null."); return JavadocParser.parse(content); } @@ -379,6 +406,7 @@ public static Javadoc parseJavadoc(@NotNull String content) { * @throws ParseProblemException if the source code has parser errors */ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(@NotNull String statement) { + Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseExplicitConstructorInvocationStmt(statement)); } @@ -390,6 +418,7 @@ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocati * @throws ParseProblemException if the source code has parser errors */ public static Name parseName(@NotNull String qualifiedName) { + Preconditions.checkNotNull(qualifiedName, "Parameter qualifiedName can't be null."); return handleResult(newParser().parseName(qualifiedName)); } @@ -401,6 +430,7 @@ public static Name parseName(@NotNull String qualifiedName) { * @throws ParseProblemException if the source code has parser errors */ public static SimpleName parseSimpleName(@NotNull String name) { + Preconditions.checkNotNull(name, "Parameter name can't be null."); return handleResult(newParser().parseSimpleName(name)); } @@ -412,6 +442,7 @@ public static SimpleName parseSimpleName(@NotNull String name) { * @throws ParseProblemException if the source code has parser errors */ public static Parameter parseParameter(@NotNull String parameter) { + Preconditions.checkNotNull(parameter, "Parameter parameter can't be null."); return handleResult(newParser().parseParameter(parameter)); } @@ -423,6 +454,7 @@ public static Parameter parseParameter(@NotNull String parameter) { * @throws ParseProblemException if the source code has parser errors */ public static PackageDeclaration parsePackageDeclaration(@NotNull String packageDeclaration) { + Preconditions.checkNotNull(packageDeclaration, "Parameter packageDeclaration can't be null."); return handleResult(newParser().parsePackageDeclaration(packageDeclaration)); } @@ -434,6 +466,7 @@ public static PackageDeclaration parsePackageDeclaration(@NotNull String package * @throws ParseProblemException if the source code has parser errors */ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclaration) { + Preconditions.checkNotNull(typeDeclaration, "Parameter typeDeclaration can't be null."); return handleResult(newParser().parseTypeDeclaration(typeDeclaration)); } @@ -446,6 +479,7 @@ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclar * @see ModuleDeclaration */ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDeclaration) { + Preconditions.checkNotNull(moduleDeclaration, "Parameter moduleDeclaration can't be null."); return handleResult(newParser().parseModuleDeclaration(moduleDeclaration)); } @@ -458,10 +492,10 @@ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDec * @see ModuleDirective */ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirective) { + Preconditions.checkNotNull(moduleDirective, "Parameter moduleDirective can't be null."); return handleResult(newParser().parseModuleDirective(moduleDirective)); } - /** * Parses a type parameter and returns it as a TypeParameter * @@ -470,6 +504,7 @@ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirecti * @throws ParseProblemException if the source code has parser errors */ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { + Preconditions.checkNotNull(typeParameter, "Parameter typeParameter can't be null."); return handleResult(newParser().parseTypeParameter(typeParameter)); } @@ -482,7 +517,7 @@ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { * @see MethodDeclaration */ public static MethodDeclaration parseMethodDeclaration(@NotNull String methodDeclaration) { + Preconditions.checkNotNull(methodDeclaration, "Parameter methodDeclaration can't be null."); return handleResult(newParser().parseMethodDeclaration(methodDeclaration)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java index 1796581feb..9c7889ed0d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java @@ -18,21 +18,22 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Iterator; import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; + /** * The range of tokens covered by this node. */ public class TokenRange implements Iterable { + public static final TokenRange INVALID = new TokenRange(JavaToken.INVALID, JavaToken.INVALID); private final JavaToken begin; + private final JavaToken end; public TokenRange(JavaToken begin, JavaToken end) { @@ -66,7 +67,7 @@ public TokenRange withEnd(JavaToken end) { @Override public String toString() { StringBuilder result = new StringBuilder(); - for(JavaToken t: this) { + for (JavaToken t : this) { result.append(t.getText()); } return result.toString(); @@ -75,7 +76,9 @@ public String toString() { @Override public Iterator iterator() { return new Iterator() { + private boolean hasNext = true; + private JavaToken current = begin; @Override @@ -86,14 +89,14 @@ public boolean hasNext() { @Override public JavaToken next() { JavaToken retval = current; - if(current == null){ + if (current == null) { throw new IllegalStateException("Attempting to move past end of range."); } if (current == end) { hasNext = false; } current = current.getNextToken().orElse(null); - if(current == null && hasNext){ + if (current == null && hasNext) { throw new IllegalStateException("End token is not linked to begin token."); } return retval; diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java index a5554efa36..36836f1260 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.utils.LineSeparator; @@ -29,6 +28,7 @@ * Complements GeneratedJavaParserConstants */ public class TokenTypes { + public static boolean isWhitespace(int kind) { return getCategory(kind).isWhitespace(); } @@ -96,7 +96,7 @@ public static int spaceTokenKind() { * FIXME: It appears that {@code ...} {@code ELLIPSIS} and {@code ::} {@code DOUBLECOLON} are (wrongly) listed in the "operators" section, rather than "separators" */ public static JavaToken.Category getCategory(int kind) { - switch (kind) { + switch(kind) { case WINDOWS_EOL: case UNIX_EOL: case OLD_MAC_EOL: diff --git a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java index 63032c829a..80c14c666d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java @@ -29,572 +29,571 @@ * {@link Provider} un-escaping unicode escape sequences in the input sequence. */ public class UnicodeEscapeProcessingProvider implements Provider { - - private static final char LF = '\n'; - - private static final char CR = '\r'; - - private static final char BACKSLASH = '\\'; - - private static final int EOF = -1; - - private char[] _data; - - /** - * The number of characters in {@link #_data}. - */ - private int _len = 0; - - /** - * The position in {@link #_data} where to read the next source character from. - */ - private int _pos = 0; - - private boolean _backslashSeen; - - private final LineCounter _inputLine = new LineCounter(); - - private final LineCounter _outputLine = new LineCounter(); - - private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); - - private Provider _input; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(Provider input) { - this(2048, input); - } - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { - _input = input; - _data = new char[bufferSize]; - } - - /** - * The {@link LineCounter} of the input file. - */ - public LineCounter getInputCounter() { - return _inputLine; - } - - /** - * The {@link LineCounter} of the output file. - */ - public LineCounter getOutputCounter() { - return _outputLine; - } - - @Override - public int read(char[] buffer, final int offset, int len) throws IOException { - int pos = offset; - int stop = offset + len; - while (pos < stop) { - int ch = _outputLine.process(nextOutputChar()); - if (ch < 0) { - if (pos == offset) { - // Nothing read yet, this is the end of the stream. - return EOF; - } else { - break; - } - } else { - _mappingBuilder.update(); - buffer[pos++] = (char) ch; - } - } - return pos - offset; - } - - @Override - public void close() throws IOException { - _input.close(); - } - - /** - * Produces the next un-escaped character to be written to the output. - * - * @return The next character or {@code -1} if no more characters are available. - */ - private int nextOutputChar() throws IOException { - int next = nextInputChar(); - switch (next) { - case EOF: - return EOF; - case BACKSLASH: { - if (_backslashSeen) { - return clearBackSlashSeen(next); - } else { - return backSlashSeen(); - } - } - default: { - // An arbitrary character. - return clearBackSlashSeen(next); - } - } - } - - private int clearBackSlashSeen(int next) { - _backslashSeen = false; - return next; - } - - private int backSlashSeen() throws IOException { - _backslashSeen = true; - - int next = nextInputChar(); - switch (next) { - case EOF: - // End of file after backslash produces the backslash itself. - return BACKSLASH; - case 'u': { - return unicodeStartSeen(); - } - default: { - pushBack(next); - return BACKSLASH; - } - } - } - - private int unicodeStartSeen() throws IOException { - int uCnt = 1; - while (true) { - int next = nextInputChar(); - switch (next) { - case EOF: { - pushBackUs(uCnt); - return BACKSLASH; - } - case 'u': { - uCnt++; - continue; - } - default: { - return readDigits(uCnt, next); - } - } - } - } - - private int readDigits(int uCnt, int next3) throws IOException { - int digit3 = digit(next3); - if (digit3 < 0) { - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next2 = nextInputChar(); - int digit2 = digit(next2); - if (digit2 < 0) { - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next1 = nextInputChar(); - int digit1 = digit(next1); - if (digit1 < 0) { - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next0 = nextInputChar(); - int digit0 = digit(next0); - if (digit0 < 0) { - pushBack(next0); - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; - return clearBackSlashSeen(ch); - } - - private void pushBackUs(int cnt) { - for (int n = 0; n < cnt; n++) { - pushBack('u'); - } - } - - private static int digit(int ch) { - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } - if (ch >= 'A' && ch <= 'F') { - return 10 + ch - 'A'; - } - if (ch >= 'a' && ch <= 'f') { - return 10 + ch - 'a'; - } - return -1; - } - - /** - * Processes column/line information from the input file. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextInputChar() throws IOException { - int result = nextBufferedChar(); - return _inputLine.process(result); - } - - /** - * Retrieves the next un-escaped character from the buffered {@link #_input}. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextBufferedChar() throws IOException { - while (isBufferEmpty()) { - int direct = fillBuffer(); - if (direct < 0) { - return EOF; - } - } - return _data[_pos++]; - } - - private boolean isBufferEmpty() { - return _pos >= _len; - } - - private int fillBuffer() throws IOException { - _pos = 0; - int direct = _input.read(_data, 0, _data.length); - if (direct != 0) { - _len = direct; - } - return direct; - } - - private void pushBack(int ch) { - if (ch < 0) { - return; - } - - if (isBufferEmpty()) { - _pos = _data.length; - _len = _data.length; - } else if (_pos == 0) { - if (_len == _data.length) { - // Buffer is completely full, no push possible, enlarge buffer. - char[] newData = new char[_data.length + 1024]; - _len = newData.length; - _pos = newData.length - _data.length; - System.arraycopy(_data, 0, newData, _pos, _data.length); - _data = newData; - } else { - // Move contents to the right. - int cnt = _len - _pos; - _pos = _data.length - _len; - _len = _data.length; - System.arraycopy(_data, 0, _data, _pos, cnt); - } - } - _data[--_pos] = (char) ch; - } - - /** - * The {@link PositionMapping} being built during processing the file. - */ - public PositionMapping getPositionMapping() { - return _mappingBuilder.getMapping(); - } - - /** - * An algorithm mapping {@link Position} form two corresponding files. - */ - public static final class PositionMapping { - - private final List _deltas = new ArrayList<>(); - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. - */ - public PositionMapping() { - super(); - } - - /** - * Whether this is the identity transformation. - */ - public boolean isEmpty() { - return _deltas.isEmpty(); - } - - void add(int line, int column, int lineDelta, int columnDelta) { - _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); - } - - /** - * Looks up the {@link PositionUpdate} for the given Position. - */ - public PositionUpdate lookup(Position position) { - int result = Collections.binarySearch(_deltas, position); - if (result >= 0) { - return _deltas.get(result); - } else { - int insertIndex = -result - 1; - if (insertIndex == 0) { - // Before the first delta info, identity mapping. - return PositionUpdate.NONE; - } else { - // The relevant update is the one with the position smaller - // than the requested position. - return _deltas.get(insertIndex - 1); - } - } - } - - /** - * Algorithm updating a {@link Position} from one file to a - * {@link Position} in a corresponding file. - */ - public static interface PositionUpdate { - - /** - * The identity position mapping. - */ - PositionUpdate NONE = new PositionUpdate() { - @Override - public int transformLine(int line) { - return line; - } - - @Override - public int transformColumn(int column) { - return column; - } - - @Override - public Position transform(Position pos) { - return pos; - } - }; - - /** - * Maps the given line to an original line. - */ - int transformLine(int line); - - /** - * Maps the given column to an original column. - */ - int transformColumn(int column); - - /** - * The transformed position. - */ - default Position transform(Position pos) { - int line = pos.line; - int column = pos.column; - int transformedLine = transformLine(line); - int transformedColumn = transformColumn(column); - return new Position(transformedLine, transformedColumn); - } - - } - - private static final class DeltaInfo extends Position implements PositionUpdate { - - /** - * The offset to add to the {@link #line} and all following source - * positions up to the next {@link PositionUpdate}. - */ - private final int _lineDelta; - - /** - * The offset to add to the {@link #column} and all following - * source positions up to the next {@link PositionUpdate}. - */ - private final int _columnDelta; - - /** - * Creates a {@link PositionUpdate}. - */ - public DeltaInfo(int line, int column, int lineDelta, - int columnDelta) { - super(line, column); - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - - @Override - public int transformLine(int sourceLine) { - return sourceLine + _lineDelta; - } - - @Override - public int transformColumn(int sourceColumn) { - return sourceColumn + _columnDelta; - } - - @Override - public String toString() { - return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; - } - - } - - /** - * Transforms the given {@link Position}. - */ - public Position transform(Position pos) { - return lookup(pos).transform(pos); - } - - /** - * Transforms the given {@link Range}. - */ - public Range transform(Range range) { - Position begin = transform(range.begin); - Position end = transform(range.end); - if (begin == range.begin && end == range.end) { - // No change. - return range; - } - return new Range(begin, end); - } - } - - private static final class PositionMappingBuilder { - - private LineCounter _left; - - private LineCounter _right; - - private final PositionMapping _mapping = new PositionMapping(); - - private int _lineDelta = 0; - private int _columnDelta = 0; - - /** - * Creates a {@link PositionMappingBuilder}. - * - * @param left The source {@link LineCounter}. - * @param right The target {@link LineCounter}. - */ - public PositionMappingBuilder(LineCounter left, LineCounter right) { - _left = left; - _right = right; - update(); - } - - /** - * The built {@link PositionMapping}. - */ - public PositionMapping getMapping() { - return _mapping; - } - - public void update() { - int lineDelta = _right.getLine() - _left.getLine(); - int columnDelta = _right.getColumn() - _left.getColumn(); - - if (lineDelta != _lineDelta || columnDelta != _columnDelta) { - _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); - - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - } - - } - - /** - * Processor keeping track of the current line and column in a stream of - * incoming characters. - * - * @see #process(int) - */ - public static final class LineCounter { - - /** - * Whether {@link #CR} has been seen on the input as last character. - */ - private boolean _crSeen; - - private int _line = 1; - - private int _column = 1; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. - */ - public LineCounter() { - super(); - } - - /** - * The line of the currently processed input character. - */ - public int getLine() { - return _line; - } - - /** - * The column of the currently processed input character. - */ - public int getColumn() { - return _column; - } - - /** - * The current position. - */ - public Position getPosition() { - return new Position(getLine(), getColumn()); - } - - /** - * Analyzes the given character for line feed. - */ - public int process(int ch) { - switch (ch) { - case EOF: { - break; - } - case CR: { - incLine(); - _crSeen = true; - break; - } - case LF: { - // CR LF does only count as a single line terminator. - if (_crSeen) { - _crSeen = false; - } else { - incLine(); - } - break; - } - default: { - _crSeen = false; - _column++; - } - } - return ch; - } - - private void incLine() { - _line++; - _column = 1; - } - - } - + + private static final char LF = '\n'; + + private static final char CR = '\r'; + + private static final char BACKSLASH = '\\'; + + private static final int EOF = -1; + + private char[] _data; + + /** + * The number of characters in {@link #_data}. + */ + private int _len = 0; + + /** + * The position in {@link #_data} where to read the next source character from. + */ + private int _pos = 0; + + private boolean _backslashSeen; + + private final LineCounter _inputLine = new LineCounter(); + + private final LineCounter _outputLine = new LineCounter(); + + private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); + + private Provider _input; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(Provider input) { + this(2048, input); + } + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { + _input = input; + _data = new char[bufferSize]; + } + + /** + * The {@link LineCounter} of the input file. + */ + public LineCounter getInputCounter() { + return _inputLine; + } + + /** + * The {@link LineCounter} of the output file. + */ + public LineCounter getOutputCounter() { + return _outputLine; + } + + @Override + public int read(char[] buffer, final int offset, int len) throws IOException { + int pos = offset; + int stop = offset + len; + while (pos < stop) { + int ch = _outputLine.process(nextOutputChar()); + if (ch < 0) { + if (pos == offset) { + // Nothing read yet, this is the end of the stream. + return EOF; + } else { + break; + } + } else { + _mappingBuilder.update(); + buffer[pos++] = (char) ch; + } + } + return pos - offset; + } + + @Override + public void close() throws IOException { + _input.close(); + } + + /** + * Produces the next un-escaped character to be written to the output. + * + * @return The next character or {@code -1} if no more characters are available. + */ + private int nextOutputChar() throws IOException { + int next = nextInputChar(); + switch(next) { + case EOF: + return EOF; + case BACKSLASH: + { + if (_backslashSeen) { + return clearBackSlashSeen(next); + } else { + return backSlashSeen(); + } + } + default: + { + // An arbitrary character. + return clearBackSlashSeen(next); + } + } + } + + private int clearBackSlashSeen(int next) { + _backslashSeen = false; + return next; + } + + private int backSlashSeen() throws IOException { + _backslashSeen = true; + int next = nextInputChar(); + switch(next) { + case EOF: + // End of file after backslash produces the backslash itself. + return BACKSLASH; + case 'u': + { + return unicodeStartSeen(); + } + default: + { + pushBack(next); + return BACKSLASH; + } + } + } + + private int unicodeStartSeen() throws IOException { + int uCnt = 1; + while (true) { + int next = nextInputChar(); + switch(next) { + case EOF: + { + pushBackUs(uCnt); + return BACKSLASH; + } + case 'u': + { + uCnt++; + continue; + } + default: + { + return readDigits(uCnt, next); + } + } + } + } + + private int readDigits(int uCnt, int next3) throws IOException { + int digit3 = digit(next3); + if (digit3 < 0) { + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next2 = nextInputChar(); + int digit2 = digit(next2); + if (digit2 < 0) { + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next1 = nextInputChar(); + int digit1 = digit(next1); + if (digit1 < 0) { + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next0 = nextInputChar(); + int digit0 = digit(next0); + if (digit0 < 0) { + pushBack(next0); + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; + return clearBackSlashSeen(ch); + } + + private void pushBackUs(int cnt) { + for (int n = 0; n < cnt; n++) { + pushBack('u'); + } + } + + private static int digit(int ch) { + if (ch >= '0' && ch <= '9') { + return ch - '0'; + } + if (ch >= 'A' && ch <= 'F') { + return 10 + ch - 'A'; + } + if (ch >= 'a' && ch <= 'f') { + return 10 + ch - 'a'; + } + return -1; + } + + /** + * Processes column/line information from the input file. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextInputChar() throws IOException { + int result = nextBufferedChar(); + return _inputLine.process(result); + } + + /** + * Retrieves the next un-escaped character from the buffered {@link #_input}. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextBufferedChar() throws IOException { + while (isBufferEmpty()) { + int direct = fillBuffer(); + if (direct < 0) { + return EOF; + } + } + return _data[_pos++]; + } + + private boolean isBufferEmpty() { + return _pos >= _len; + } + + private int fillBuffer() throws IOException { + _pos = 0; + int direct = _input.read(_data, 0, _data.length); + if (direct != 0) { + _len = direct; + } + return direct; + } + + private void pushBack(int ch) { + if (ch < 0) { + return; + } + if (isBufferEmpty()) { + _pos = _data.length; + _len = _data.length; + } else if (_pos == 0) { + if (_len == _data.length) { + // Buffer is completely full, no push possible, enlarge buffer. + char[] newData = new char[_data.length + 1024]; + _len = newData.length; + _pos = newData.length - _data.length; + System.arraycopy(_data, 0, newData, _pos, _data.length); + _data = newData; + } else { + // Move contents to the right. + int cnt = _len - _pos; + _pos = _data.length - _len; + _len = _data.length; + System.arraycopy(_data, 0, _data, _pos, cnt); + } + } + _data[--_pos] = (char) ch; + } + + /** + * The {@link PositionMapping} being built during processing the file. + */ + public PositionMapping getPositionMapping() { + return _mappingBuilder.getMapping(); + } + + /** + * An algorithm mapping {@link Position} form two corresponding files. + */ + public static final class PositionMapping { + + private final List _deltas = new ArrayList<>(); + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. + */ + public PositionMapping() { + super(); + } + + /** + * Whether this is the identity transformation. + */ + public boolean isEmpty() { + return _deltas.isEmpty(); + } + + void add(int line, int column, int lineDelta, int columnDelta) { + _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); + } + + /** + * Looks up the {@link PositionUpdate} for the given Position. + */ + public PositionUpdate lookup(Position position) { + int result = Collections.binarySearch(_deltas, position); + if (result >= 0) { + return _deltas.get(result); + } else { + int insertIndex = -result - 1; + if (insertIndex == 0) { + // Before the first delta info, identity mapping. + return PositionUpdate.NONE; + } else { + // The relevant update is the one with the position smaller + // than the requested position. + return _deltas.get(insertIndex - 1); + } + } + } + + /** + * Algorithm updating a {@link Position} from one file to a + * {@link Position} in a corresponding file. + */ + public static interface PositionUpdate { + + /** + * The identity position mapping. + */ + PositionUpdate NONE = new PositionUpdate() { + + @Override + public int transformLine(int line) { + return line; + } + + @Override + public int transformColumn(int column) { + return column; + } + + @Override + public Position transform(Position pos) { + return pos; + } + }; + + /** + * Maps the given line to an original line. + */ + int transformLine(int line); + + /** + * Maps the given column to an original column. + */ + int transformColumn(int column); + + /** + * The transformed position. + */ + default Position transform(Position pos) { + int line = pos.line; + int column = pos.column; + int transformedLine = transformLine(line); + int transformedColumn = transformColumn(column); + return new Position(transformedLine, transformedColumn); + } + } + + private static final class DeltaInfo extends Position implements PositionUpdate { + + /** + * The offset to add to the {@link #line} and all following source + * positions up to the next {@link PositionUpdate}. + */ + private final int _lineDelta; + + /** + * The offset to add to the {@link #column} and all following + * source positions up to the next {@link PositionUpdate}. + */ + private final int _columnDelta; + + /** + * Creates a {@link PositionUpdate}. + */ + public DeltaInfo(int line, int column, int lineDelta, int columnDelta) { + super(line, column); + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + + @Override + public int transformLine(int sourceLine) { + return sourceLine + _lineDelta; + } + + @Override + public int transformColumn(int sourceColumn) { + return sourceColumn + _columnDelta; + } + + @Override + public String toString() { + return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; + } + } + + /** + * Transforms the given {@link Position}. + */ + public Position transform(Position pos) { + return lookup(pos).transform(pos); + } + + /** + * Transforms the given {@link Range}. + */ + public Range transform(Range range) { + Position begin = transform(range.begin); + Position end = transform(range.end); + if (begin == range.begin && end == range.end) { + // No change. + return range; + } + return new Range(begin, end); + } + } + + private static final class PositionMappingBuilder { + + private LineCounter _left; + + private LineCounter _right; + + private final PositionMapping _mapping = new PositionMapping(); + + private int _lineDelta = 0; + + private int _columnDelta = 0; + + /** + * Creates a {@link PositionMappingBuilder}. + * + * @param left The source {@link LineCounter}. + * @param right The target {@link LineCounter}. + */ + public PositionMappingBuilder(LineCounter left, LineCounter right) { + _left = left; + _right = right; + update(); + } + + /** + * The built {@link PositionMapping}. + */ + public PositionMapping getMapping() { + return _mapping; + } + + public void update() { + int lineDelta = _right.getLine() - _left.getLine(); + int columnDelta = _right.getColumn() - _left.getColumn(); + if (lineDelta != _lineDelta || columnDelta != _columnDelta) { + _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + } + } + + /** + * Processor keeping track of the current line and column in a stream of + * incoming characters. + * + * @see #process(int) + */ + public static final class LineCounter { + + /** + * Whether {@link #CR} has been seen on the input as last character. + */ + private boolean _crSeen; + + private int _line = 1; + + private int _column = 1; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. + */ + public LineCounter() { + super(); + } + + /** + * The line of the currently processed input character. + */ + public int getLine() { + return _line; + } + + /** + * The column of the currently processed input character. + */ + public int getColumn() { + return _column; + } + + /** + * The current position. + */ + public Position getPosition() { + return new Position(getLine(), getColumn()); + } + + /** + * Analyzes the given character for line feed. + */ + public int process(int ch) { + switch(ch) { + case EOF: + { + break; + } + case CR: + { + incLine(); + _crSeen = true; + break; + } + case LF: + { + // CR LF does only count as a single line terminator. + if (_crSeen) { + _crSeen = false; + } else { + incLine(); + } + break; + } + default: + { + _crSeen = false; + _column++; + } + } + return ch; + } + + private void incLine() { + _line++; + _column = 1; + } + } } 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 index b16d7d6952..f25f7b2d89 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; /** @@ -30,10 +29,7 @@ */ public enum AccessSpecifier { - PUBLIC("public"), - PRIVATE("private"), - PROTECTED("protected"), - PACKAGE_PRIVATE(""); + PUBLIC("public"), PRIVATE("private"), PROTECTED("protected"), PACKAGE_PRIVATE(""); private String 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 index 18efc78290..bc6e83b425 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; import java.lang.annotation.ElementType; 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 index f92abef865..7cd32c25c3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; /** @@ -41,6 +40,7 @@ * @see Node#getData(DataKey) */ public abstract class DataKey { + @Override public int hashCode() { return getClass().hashCode(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java index 96b5d8c0d0..423a1d116d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; import java.lang.annotation.Retention; @@ -34,9 +33,9 @@ * and will be overwritten the next time the generators are run. */ @Retention(SOURCE) -@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, - LOCAL_VARIABLE, PARAMETER}) +@Target({ PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER }) public @interface Generated { + /** * The value element must have the name of the code generator. * The recommended convention is to use the fully qualified name of the diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java index 2d7584b95b..adb975824b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java @@ -18,7 +18,6 @@ * 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; @@ -47,6 +46,7 @@ * @param the type of nodes contained. */ public class NodeList implements List, Iterable, HasParentNode>, Visitable, Observable { + @InternalProperty private final List innerList = new ArrayList<>(0); @@ -140,8 +140,7 @@ public Iterator 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); + 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; @@ -228,7 +227,6 @@ public NodeList addBefore(N node, N beforeThisNode) { return this; } - /** * @return the first node, or empty if the list is empty. */ @@ -567,9 +565,10 @@ public String toString() { return innerList.stream().map(Node::toString).collect(Collectors.joining(", ", "[", "]")); } - protected class NodeListIterator implements ListIterator{ + protected class NodeListIterator implements ListIterator { ListIterator iterator; + N current = null; // initialize pointer to head of the list for iteration @@ -627,14 +626,12 @@ public void remove() { public void set(N n) { int index = innerList.indexOf(current); 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); + throw new IllegalArgumentException("Illegal index. The index should be between 0 and " + innerList.size() + " excluded. It is instead " + index); } if (n != innerList.get(index)) { notifyElementReplaced(index, n); innerList.get(index).setParentNode(null); setAsParentNodeOf(n); - iterator.set(n); } } 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 index 17cfa87964..96eca384bc 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,6 +33,7 @@ * The comments contained in a certain parsed piece of source code. */ public class CommentsCollection { + private final TreeSet comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); public CommentsCollection() { @@ -44,24 +44,15 @@ public CommentsCollection(Collection commentsToCopy) { } public Set getLineComments() { - return comments.stream() - .filter(comment -> comment instanceof LineComment) - .map(comment -> (LineComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream().filter(comment -> comment instanceof LineComment).map(comment -> (LineComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getBlockComments() { - return comments.stream() - .filter(comment -> comment instanceof BlockComment) - .map(comment -> (BlockComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream().filter(comment -> comment instanceof BlockComment).map(comment -> (BlockComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getJavadocComments() { - return comments.stream() - .filter(comment -> comment instanceof JavadocComment) - .map(comment -> (JavadocComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + 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) { @@ -80,9 +71,7 @@ public boolean contains(Comment comment) { 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) { + if (cRange.begin.equals(commentRange.begin) && cRange.end.line == commentRange.end.line && Math.abs(cRange.end.column - commentRange.end.column) < 2) { return true; } } @@ -99,10 +88,7 @@ public int size() { public CommentsCollection minus(CommentsCollection other) { CommentsCollection result = new CommentsCollection(); - result.comments.addAll( - comments.stream() - .filter(comment -> !other.contains(comment)) - .collect(Collectors.toList())); + result.comments.addAll(comments.stream().filter(comment -> !other.contains(comment)).collect(Collectors.toList())); return result; } 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 index 503f98f8a7..d06ba13b9c 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -38,6 +37,7 @@ * @since July 2014 */ public interface NodeWithAnnotations { + NodeList getAnnotations(); N setAnnotations(NodeList annotations); @@ -68,8 +68,7 @@ default N addAnnotation(AnnotationExpr element) { */ @SuppressWarnings("unchecked") default N addAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr( - parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); addAnnotation(annotation); return (N) this; } @@ -82,8 +81,7 @@ default N addAnnotation(String name) { */ @SuppressWarnings("unchecked") default NormalAnnotationExpr addAndGetAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr( - parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); addAnnotation(annotation); return annotation; } @@ -118,8 +116,7 @@ default NormalAnnotationExpr addAndGetAnnotation(Class cla */ @SuppressWarnings("unchecked") default N addMarkerAnnotation(String name) { - MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr( - parseName(name)); + MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr(parseName(name)); addAnnotation(markerAnnotationExpr); return (N) this; } @@ -144,8 +141,7 @@ default N addMarkerAnnotation(Class clazz) { */ @SuppressWarnings("unchecked") default N addSingleMemberAnnotation(String name, Expression expression) { - SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr( - parseName(name), expression); + SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr(parseName(name), expression); return addAnnotation(singleMemberAnnotationExpr); } @@ -179,8 +175,7 @@ default N addSingleMemberAnnotation(String name, String value) { * @param value the value, don't forget to add \"\" for a string value * @return this */ - default N addSingleMemberAnnotation(Class clazz, - String value) { + default N addSingleMemberAnnotation(Class clazz, String value) { tryAddImportToParentCompilationUnit(clazz); return addSingleMemberAnnotation(clazz.getSimpleName(), value); } 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 index c639336183..537cb3e45e 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node with arguments. */ public interface NodeWithArguments { + N setArguments(NodeList arguments); NodeList getArguments(); @@ -55,5 +55,4 @@ 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 index eb22b78d1e..1212b5b0e9 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -28,6 +27,7 @@ * A node with a body that is a BlockStmt. */ public interface NodeWithBlockStmt { + BlockStmt getBody(); N setBody(BlockStmt 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 index cea664c77a..4d198d6bc4 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -27,6 +26,7 @@ import com.github.javaparser.ast.stmt.Statement; public interface NodeWithBody { + Statement getBody(); N setBody(final Statement body); @@ -42,8 +42,6 @@ default BlockStmt createBlockStatementAsBody() { */ default boolean hasEmptyBody() { Statement body = getBody(); - return body.toBlockStmt().map(bs -> bs.isEmpty()) - .orElse(body.isEmptyStmt()); + return body.toBlockStmt().map(bs -> bs.isEmpty()).orElse(body.isEmptyStmt()); } - } 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 index 3987d8f911..b276d94c0e 100644 --- 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 @@ -18,13 +18,13 @@ * 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; public interface NodeWithCondition { + Expression getCondition(); N setCondition(Expression condition); 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 index 5e04f0519b..874ea05000 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes; /** 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 index 647f48227b..7ce9d18345 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -30,6 +29,7 @@ * A node that has an expression in it. */ public interface NodeWithExpression { + Expression getExpression(); N setExpression(Expression 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 index 53ff093f0f..f1c5482873 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -98,5 +97,4 @@ 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 index 0634b58c9f..45bb713c4b 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -26,6 +25,7 @@ import static com.github.javaparser.utils.Utils.assertNonEmpty; public interface NodeWithIdentifier { + String getIdentifier(); N setIdentifier(String 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 index a62b012115..f583a2d2fa 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node that implements other types. */ public interface NodeWithImplements { + NodeList getImplementedTypes(); default ClassOrInterfaceType getImplementedTypes(int i) { @@ -38,9 +38,9 @@ default ClassOrInterfaceType getImplementedTypes(int i) { } N setImplementedTypes(NodeList implementsList); - + void tryAddImportToParentCompilationUnit(Class clazz); - + @SuppressWarnings("unchecked") default N setImplementedType(int i, ClassOrInterfaceType implement) { getImplementedTypes().set(i, implement); @@ -53,12 +53,16 @@ default N addImplementedType(ClassOrInterfaceType implement) { return (N) this; } - /** @deprecated use addImplementedType instead */ + /** + * @deprecated use addImplementedType instead + */ default N addImplements(String name) { return addImplementedType(name); } - /** @deprecated use addImplementedType instead */ + /** + * @deprecated use addImplementedType instead + */ default N addImplements(Class clazz) { return addImplementedType(clazz); } 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 index 10941e6453..7252ef0d9b 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -32,6 +31,7 @@ * A node that can be documented with a Javadoc comment. */ public interface NodeWithJavadoc { + Optional getComment(); Node setComment(Comment comment); @@ -43,9 +43,7 @@ public interface NodeWithJavadoc { * @return The JavadocComment for this node wrapped in an optional as it may be absent. */ default Optional getJavadocComment() { - return getComment() - .filter(comment -> comment instanceof JavadocComment) - .map(comment -> (JavadocComment) comment); + return getComment().filter(comment -> comment instanceof JavadocComment).map(comment -> (JavadocComment) comment); } /** @@ -87,5 +85,4 @@ default boolean removeJavaDocComment() { 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 index 6fd6975261..53b313357c 100644 --- 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 @@ -46,6 +46,7 @@ * method. */ public interface NodeWithMembers extends NodeWithSimpleName { + /** * @return all members inside the braces of this node, * like fields, methods, nested types, etc. @@ -315,9 +316,7 @@ default BlockStmt addStaticInitializer() { * @return the methods found (multiple in case of overloading) */ default List getMethodsByName(String name) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.getNameAsString().equals(name)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.getNameAsString().equals(name)).collect(toList())); } /** @@ -326,10 +325,7 @@ default List getMethodsByName(String name) { * @return the methods found. This list is immutable. */ default List getMethods() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof MethodDeclaration) - .map(m -> (MethodDeclaration) m) - .collect(toList())); + return unmodifiableList(getMembers().stream().filter(m -> m instanceof MethodDeclaration).map(m -> (MethodDeclaration) m).collect(toList())); } /** @@ -348,9 +344,7 @@ default List getMethods() { * @return the methods found */ default List getMethodsByParameterTypes(String... paramTypes) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -362,9 +356,7 @@ default List getMethodsByParameterTypes(String... paramTypes) * @return the methods found */ default List getMethodsBySignature(String name, String... paramTypes) { - return unmodifiableList(getMethodsByName(name).stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethodsByName(name).stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -380,9 +372,7 @@ default List getMethodsBySignature(String name, String... par * @return the methods found */ default List getMethodsByParameterTypes(Class... paramTypes) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -391,10 +381,7 @@ default List getMethodsByParameterTypes(Class... paramType * @return the constructors found. This list is immutable. */ default List getConstructors() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof ConstructorDeclaration) - .map(m -> (ConstructorDeclaration) m) - .collect(toList())); + return unmodifiableList(getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).collect(toList())); } /** @@ -403,11 +390,7 @@ default List getConstructors() { * @return the constructor found, if any. */ default Optional getDefaultConstructor() { - return getMembers().stream() - .filter(m -> m instanceof ConstructorDeclaration) - .map(m -> (ConstructorDeclaration) m) - .filter(cd -> cd.getParameters().isEmpty()) - .findFirst(); + return getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).filter(cd -> cd.getParameters().isEmpty()).findFirst(); } /** @@ -427,9 +410,7 @@ default Optional getDefaultConstructor() { * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(String... paramTypes) { - return getConstructors().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .findFirst(); + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); } /** @@ -445,9 +426,7 @@ default Optional getConstructorByParameterTypes(String.. * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(Class... paramTypes) { - return getConstructors().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .findFirst(); + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); } /** @@ -457,12 +436,7 @@ default Optional getConstructorByParameterTypes(Class * @return null if not found, the FieldDeclaration otherwise */ default Optional getFieldByName(String name) { - return getMembers().stream() - .filter(m -> m instanceof FieldDeclaration) - .map(f -> (FieldDeclaration) f) - .filter(f -> f.getVariables().stream() - .anyMatch(var -> var.getNameAsString().equals(name))) - .findFirst(); + return getMembers().stream().filter(m -> m instanceof FieldDeclaration).map(f -> (FieldDeclaration) f).filter(f -> f.getVariables().stream().anyMatch(var -> var.getNameAsString().equals(name))).findFirst(); } /** @@ -471,10 +445,7 @@ default Optional getFieldByName(String name) { * @return the fields found. This list is immutable. */ default List getFields() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof FieldDeclaration) - .map(m -> (FieldDeclaration) m) - .collect(toList())); + 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 index 02893b0d4f..592e50ed73 100644 --- 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 @@ -18,19 +18,15 @@ * 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.AccessSpecifier; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.resolution.declarations.HasAccessSpecifier; import java.util.Arrays; import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Collectors; import static com.github.javaparser.ast.NodeList.toNodeList; @@ -39,6 +35,7 @@ * Note that not all modifiers may be valid for this node. */ public interface NodeWithModifiers { + /** * Return the modifiers of this variable declaration. * Warning: modifying the returned set will not trigger observers, @@ -67,9 +64,7 @@ default N addModifier(Modifier.Keyword... newModifiers) { @SuppressWarnings("unchecked") default N removeModifier(Modifier.Keyword... modifiersToRemove) { List modifiersToRemoveAsList = Arrays.asList(modifiersToRemove); - NodeList remaining = getModifiers().stream() - .filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())) - .collect(toNodeList()); + NodeList remaining = getModifiers().stream().filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())).collect(toNodeList()); setModifiers(remaining); return (N) this; } @@ -104,7 +99,7 @@ default N setModifiers(final Modifier.Keyword... modifiers) { */ default AccessSpecifier getAccessSpecifier() { for (Modifier modifier : getModifiers()) { - switch (modifier.getKeyword()) { + switch(modifier.getKeyword()) { case PUBLIC: return AccessSpecifier.PUBLIC; case PROTECTED: 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 index 75d0b0c2eb..8aecc8e421 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -35,6 +34,7 @@ * @since 2.0.1 */ public interface NodeWithName { + Name getName(); N setName(Name name); 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 index 8cded1c2e5..b014cbef21 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -30,6 +29,7 @@ * A node with a body that is a BlockStmt, which is optional. */ public interface NodeWithOptionalBlockStmt { + Optional getBody(); N setBody(BlockStmt 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 index ae1bf591a4..f70876d4a1 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -32,10 +31,11 @@ * A node that has an optional label. */ public interface NodeWithOptionalLabel { + Optional getLabel(); T setLabel(SimpleName label); - + T removeLabel(); default T setLabel(String label) { 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 index debdd3ae57..6ac604f937 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,7 +33,7 @@ public interface NodeWithOptionalScope extends NodeWithTraversab Optional getScope(); N setScope(Expression scope); - + N removeScope(); default Optional traverseScope() { 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 index e86106f566..5485ca9c1f 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,6 +33,7 @@ import static java.util.stream.Collectors.toList; public interface NodeWithParameters { + NodeList getParameters(); default Parameter getParameter(int i) { @@ -107,8 +107,7 @@ default Parameter addAndGetParameter(Parameter parameter) { * @return null if not found, the param found otherwise */ default Optional getParameterByName(String name) { - return getParameters().stream() - .filter(p -> p.getNameAsString().equals(name)).findFirst(); + return getParameters().stream().filter(p -> p.getNameAsString().equals(name)).findFirst(); } /** @@ -118,8 +117,7 @@ default Optional getParameterByName(String name) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(String type) { - return getParameters().stream() - .filter(p -> p.getType().toString().equals(type)).findFirst(); + return getParameters().stream().filter(p -> p.getType().toString().equals(type)).findFirst(); } /** @@ -129,8 +127,7 @@ default Optional getParameterByType(String type) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(Class type) { - return getParameters().stream() - .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); + return getParameters().stream().filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); } /** @@ -149,10 +146,7 @@ default Optional getParameterByType(Class type) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(String... paramTypes) { - return getParameters().stream() - .map(p -> p.getType().asString()) - .collect(toList()) - .equals(Arrays.asList(paramTypes)); + return getParameters().stream().map(p -> p.getType().asString()).collect(toList()).equals(Arrays.asList(paramTypes)); } /** @@ -168,13 +162,6 @@ default boolean hasParametersOfType(String... paramTypes) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(Class... paramTypes) { - return getParameters().stream() - // if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter - // is "List", we want to consider it as "List", so we need to call getName() - .map(p -> p.getType().toClassOrInterfaceType() - .map(NodeWithSimpleName::getNameAsString) - .orElse(p.getType().asString())) - .collect(toList()) - .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); + return getParameters().stream().map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElse(p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); } } 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 index f344cdd5c0..4d3e68acbb 100644 --- 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 @@ -18,19 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes; -import java.util.Optional; - import com.github.javaparser.Position; import com.github.javaparser.Range; import com.github.javaparser.ast.Node; +import java.util.Optional; + /** * A node that has a Range, which is every Node. */ public interface NodeWithRange { + Optional getRange(); N setRange(Range range); @@ -76,7 +76,7 @@ default boolean containsWithinRange(Node other) { } return false; } - + /* * Returns true if the node has a range */ 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 index 888d0f4dba..e88d57eac0 100644 --- 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 @@ -18,7 +18,6 @@ * 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; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java index 5718528793..78baf7bdaf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java @@ -18,7 +18,6 @@ * 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; @@ -33,6 +32,7 @@ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. */ public interface NodeWithSimpleName { + SimpleName getName(); N setName(SimpleName name); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java index 385d266b1b..d0cc4843c6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -18,7 +18,6 @@ * 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; @@ -35,6 +34,7 @@ * A node that contains a list of statements. */ public interface NodeWithStatements { + NodeList getStatements(); default Statement getStatement(int i) { 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 index a82a2afa6c..d273df85b6 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node that declares the types of exception it throws. */ public interface NodeWithThrownExceptions { + N setThrownExceptions(NodeList thrownExceptions); NodeList getThrownExceptions(); 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 index e4f465b4b9..8981337697 100644 --- 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 @@ -18,7 +18,6 @@ * 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.TokenRange; @@ -27,9 +26,9 @@ /** * A node that has a Range, which is every Node. - * */ public interface NodeWithTokenRange { + Optional 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 index 1bc2d37cb5..4d34d49a7d 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 9e89fe02d1..27e686ba73 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -37,6 +36,7 @@ * @since 2.3.1 */ public interface NodeWithType { + /** * Gets the type * diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java index 2cac20688a..b26195a5c7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -18,7 +18,6 @@ * 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; @@ -42,6 +41,7 @@ * On other nodes it is treated the same as the first case. */ public interface NodeWithTypeArguments { + /** * @return the types that can be found in the type arguments: {@code }. */ 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 index 14d7f1095f..c9041b5f9a 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -36,6 +35,7 @@ * */ public interface NodeWithTypeParameters { + NodeList getTypeParameters(); default TypeParameter getTypeParameter(int i) { 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 index 78ed419b3a..b80e6fc431 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -36,6 +35,7 @@ * A node which has a list of variables. */ public interface NodeWithVariables { + NodeList getVariables(); N setVariables(NodeList variables); @@ -130,6 +130,7 @@ default Optional getMaximumCommonType() { static Optional calculateMaximumCommonType(List types) { // we use a local class because we cannot use an helper static method in an interface class Helper { + // Conceptually: given a type we start from the Element Type and get as many array levels as indicated // From the implementation point of view we start from the actual type and we remove how many array // levels as needed to get the target level of arrays @@ -147,7 +148,6 @@ private Optional toArrayLevel(Type type, int level) { return Optional.of(type); } } - Helper helper = new Helper(); int level = 0; boolean keepGoing = true; @@ -170,5 +170,4 @@ private Optional toArrayLevel(Type type, int level) { } return helper.toArrayLevel(types.get(0), --level); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java index ac688875e0..b90446ee7c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java @@ -18,7 +18,6 @@ * 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; @@ -33,6 +32,7 @@ * The common interface of {@link com.github.javaparser.ast.expr.SwitchExpr} and {@link com.github.javaparser.ast.stmt.SwitchStmt} */ public interface SwitchNode { + NodeList getEntries(); SwitchEntry getEntry(int i); @@ -57,8 +57,6 @@ public interface SwitchNode { default boolean isEmpty() { return getEntries().isEmpty(); } - - // Too bad Node isn't an interface, or this could have easily inherited all of its methods. // Add more when required. } 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 index 93ff4f9e39..23161d3e79 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be abstract. */ public interface NodeWithAbstractModifier extends NodeWithModifiers { + default boolean isAbstract() { return hasModifier(ABSTRACT); } 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 index 9cb8923e41..8e58735dff 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; 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 index 78744d3e1e..7528613fb6 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be final. */ public interface NodeWithFinalModifier extends NodeWithModifiers { + default boolean isFinal() { return hasModifier(FINAL); } 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 index fb841e9cf6..0cef1e8238 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be private. */ public interface NodeWithPrivateModifier extends NodeWithModifiers { + default boolean isPrivate() { return hasModifier(PRIVATE); } 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 index 9424c0aa17..db954188f1 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be protected. */ public interface NodeWithProtectedModifier extends NodeWithModifiers { + default boolean isProtected() { return hasModifier(PROTECTED); } 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 index a52b1405c7..8221e94f00 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be public. */ public interface NodeWithPublicModifier extends NodeWithModifiers { + default boolean isPublic() { return hasModifier(PUBLIC); } @@ -38,5 +38,4 @@ default boolean isPublic() { 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 index 409a18936e..a2d532b27a 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -39,5 +38,4 @@ default boolean isStatic() { 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 index 3a3bf1fd3a..52bd23cbf4 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be strictfp. */ public interface NodeWithStrictfpModifier extends NodeWithModifiers { + default boolean isStrictfp() { return hasModifier(STRICTFP); } 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 index 637796b768..78efdd329f 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -33,8 +32,8 @@ public interface AstObserver { * Type of change occurring on a List */ enum ListChangeType { - ADDITION, - REMOVAL + + ADDITION, REMOVAL } /** 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 index 0e14b51148..7fa2231739 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 0148df7f3e..f9d366a18d 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.observer; /** 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 index 5cd335be09..286efa924b 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -38,6 +37,7 @@ public static PropagatingAstObserver transformInPropagatingObserver(final AstObs return (PropagatingAstObserver) observer; } return new PropagatingAstObserver() { + @Override public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { observer.propertyChange(observedNode, property, oldValue, newValue); @@ -114,5 +114,4 @@ private void considerAdding(Object element) { ((Observable) element).register(this); } } - } 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 index 15f3a6b604..09532aedbb 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.Problem; @@ -33,6 +32,7 @@ * A simple interface where validators can report found problems. */ public class ProblemReporter { + private final Consumer problemConsumer; public ProblemReporter(Consumer problemConsumer) { 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 index 700825c3a7..5a15a28049 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.expr.Name; @@ -31,7 +30,9 @@ * 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) { 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 index cab40ae284..5644c29132 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ * and adds a problem for all nodes that pass a condition. */ public class SimpleValidator extends SingleNodeTypeValidator { + public SimpleValidator(Class type, Predicate condition, BiConsumer problemSupplier) { super(type, (node, problemReporter) -> { if (condition.test(node)) { 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 index da83649a27..27069f9196 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -27,7 +26,9 @@ * Runs a validator on all nodes of a certain type. */ public class SingleNodeTypeValidator implements Validator { + private final Class type; + private final TypedValidator validator; public SingleNodeTypeValidator(Class type, TypedValidator validator) { 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 index 443240b1b7..1c2fa2eda9 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ * A validator that walks the whole tree, visiting every node. */ public class TreeVisitorValidator implements Validator { + private final Validator validator; public TreeVisitorValidator(Validator validator) { 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 index 7a03dab25b..3f2fbd456c 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ParseResult; @@ -30,6 +29,7 @@ * A validator that validates a known node type. */ public interface TypedValidator extends BiConsumer { + /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here @@ -38,9 +38,6 @@ public interface TypedValidator extends BiConsumer - result.getResult().ifPresent(node -> - accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem))) - ); + 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 index f108dfdc95..e4a2cb54dd 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -28,6 +27,7 @@ * It is fully up to the implementor how to do this. */ public interface Validator extends TypedValidator { + /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here 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 index e2dc370197..8c479ba608 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ * A validator that will call a collection of validators. */ public class Validators implements Validator { + private final List validators = new ArrayList<>(); public Validators(Validator... validators) { 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 index 823276fa6d..d8f65508d8 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * Implement the "visit" methods you want to use for validation. */ public abstract class VisitorValidator extends VoidVisitorAdapter implements Validator { + @Override public void accept(Node node, ProblemReporter problemReporter) { node.accept(this, problemReporter); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java index 5d53e0594a..9a179b32f5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java @@ -18,14 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.validator.SingleNodeTypeValidator; -import com.github.javaparser.ast.validator.Validator; -import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; - /** * This validator validates according to Java 10 syntax rules -- including incubator/preview/second preview features. * @@ -35,15 +29,11 @@ public class Java10PreviewValidator extends Java10Validator { public Java10PreviewValidator() { super(); - // Incubator // No incubator language features added within Java 10 - // Preview // No preview language features added within Java 10 - // 2nd Preview // No 2nd preview language features added within Java 10 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java index d84bc37d6e..53f92b9679 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -37,9 +36,7 @@ public class Java10Validator extends Java9Validator { public Java10Validator() { super(); - // Released Language Features - { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -47,6 +44,5 @@ public Java10Validator() { */ add(varOnlyOnLocalVariableDefinitionAndForAndTry); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java index 32b27cf8d1..49c84f6770 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java @@ -18,14 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.validator.SingleNodeTypeValidator; -import com.github.javaparser.ast.validator.Validator; -import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; - /** * This validator validates according to Java 11 syntax rules -- including incubator/preview/second preview features. * @@ -35,15 +29,11 @@ public class Java11PreviewValidator extends Java11Validator { public Java11PreviewValidator() { super(); - // Incubator // No incubator language features added within Java 11 - // Preview // No preview language features added within Java 11 - // 2nd Preview // No 2nd preview language features added within Java 11 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java index 4d2d4b45ec..b781ed16e8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -32,11 +31,11 @@ * @see https://openjdk.java.net/projects/jdk/11/ */ public class Java11Validator extends Java10Validator { + final Validator varAlsoInLambdaParameters = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(true)); public Java11Validator() { super(); - { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -44,6 +43,5 @@ public Java11Validator() { */ replace(varOnlyOnLocalVariableDefinitionAndForAndTry, varAlsoInLambdaParameters); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java index e3b31d54ce..69e70ee113 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,12 +29,9 @@ public class Java12PreviewValidator extends Java12Validator { public Java12PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 12 - // Preview - { /* * Switch Expressions (Preview) - first preview within Java 12 - https://openjdk.java.net/jeps/325 @@ -48,9 +44,7 @@ public Java12PreviewValidator() { remove(noSwitchExpressions); remove(onlyOneLabelInSwitchCase); } - // 2nd Preview // No new 2nd preview language features added within Java 12 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java index 3e35a31349..2894990c35 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,7 @@ public class Java12Validator extends Java11Validator { public Java12Validator() { super(); - // Released Language Features // No new released language features added within Java 12 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java index 77cb55e3b6..1f2a6632cb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,13 +29,11 @@ public class Java13PreviewValidator extends Java13Validator { public Java13PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 13 - // Preview - remove(noTextBlockLiteral); // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 - + // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 + remove(noTextBlockLiteral); // 2nd Preview { /* @@ -51,6 +48,5 @@ public Java13PreviewValidator() { remove(onlyOneLabelInSwitchCase); remove(noYield); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java index 3075977ad8..2ada45fdc1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,7 @@ public class Java13Validator extends Java12Validator { public Java13Validator() { super(); - // Released Language Features // No new released language features added in Java 13 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java index 5fb91f3ee0..a4c2f42716 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,16 +29,14 @@ public class Java14PreviewValidator extends Java14Validator { public Java14PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 14 - // Preview - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); // remove(noRecordDeclaration); // Records - first preview within Java 14 - https://openjdk.java.net/jeps/359 - // 2nd Preview - remove(noTextBlockLiteral); // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 - + // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 + remove(noTextBlockLiteral); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java index b4ee0eedcb..a1fc518e75 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,7 +29,6 @@ public class Java14Validator extends Java13Validator { public Java14Validator() { super(); - // Released Language Features { /* diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java index 630020cf52..2313ba63ac 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,16 +29,13 @@ public class Java15PreviewValidator extends Java15Validator { public Java15PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 15 - // Preview // remove(noSealedClasses); // Sealed Classes - first preview within Java 15 - https://openjdk.java.net/jeps/360 - // 2nd Preview - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); // TODO: remove(noRecordDeclaration); // Records - 2nd preview within Java 15 - https://openjdk.java.net/jeps/384 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java index 01d1709d2a..b01bee5418 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,8 +29,8 @@ public class Java15Validator extends Java14Validator { public Java15Validator() { super(); - // Released Language Features - remove(noTextBlockLiteral); // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 + // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 + remove(noTextBlockLiteral); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java index 652a93dc68..b2633a0c4f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,15 +29,11 @@ public class Java16PreviewValidator extends Java16Validator { public Java16PreviewValidator() { super(); - // Incubator // No new incubator language features added in Java 16 - // Preview // No new preview language features added in Java 16 - // 2nd Preview // TODO: remove(noSealedClasses); // Sealed Classes - 2nd preview in Java 16 - https://openjdk.java.net/jeps/397 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java index 8300398d35..9afad897b9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,9 @@ public class Java16Validator extends Java15Validator { public Java16Validator() { super(); - // Released Language Features - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); // TODO: remove(noRecordDeclaration); // Records released within Java 16 - https://openjdk.java.net/jeps/395 } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java index c316eea8b0..34bc7a32b4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.ImportDeclaration; @@ -33,11 +32,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.UnionType; -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.Validator; -import com.github.javaparser.ast.validator.Validators; +import com.github.javaparser.ast.validator.*; import com.github.javaparser.ast.validator.language_level_validations.chunks.CommonValidators; import com.github.javaparser.ast.validator.language_level_validations.chunks.ModifierValidator; import com.github.javaparser.ast.validator.language_level_validations.chunks.NoBinaryIntegerLiteralsValidator; @@ -47,20 +42,15 @@ * This validator validates according to Java 1.0 syntax rules. */ public class Java1_0Validator extends Validators { - final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods - = new ModifierValidator(false, false, false); - final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.") - ); - final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, - n -> !n.isTopLevelType(), - (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.") - ); - final Validator noReflection = new SimpleValidator<>(ClassExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Reflection is not supported.") - ); + + final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(false, false, false); + + final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, n -> true, (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.")); + + final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, n -> !n.isTopLevelType(), (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.")); + + final Validator noReflection = new SimpleValidator<>(ClassExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Reflection is not supported.")); + final Validator noGenerics = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { if (((NodeWithTypeArguments) node).getTypeArguments().isPresent()) { @@ -73,6 +63,7 @@ public class Java1_0Validator extends Validators { } } }); + final SingleNodeTypeValidator tryWithoutResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { if (n.getCatchClauses().isEmpty() && !n.getFinallyBlock().isPresent()) { reporter.report(n, "Try has no finally and no catch."); @@ -81,65 +72,40 @@ public class Java1_0Validator extends Validators { reporter.report(n, "Catch with resource is not supported."); } }); + final Validator noAnnotations = new TreeVisitorValidator((node, reporter) -> { if (node instanceof AnnotationExpr || node instanceof AnnotationDeclaration) { reporter.report(node, "Annotations are not supported."); } }); - final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, - n -> true, - (n, reporter) -> reporter.report(n, "Enumerations are not supported.") - ); - final Validator noVarargs = new SimpleValidator<>(Parameter.class, - Parameter::isVarArgs, - (n, reporter) -> reporter.report(n, "Varargs are not supported.") - ); - final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "For-each loops are not supported.") - ); - final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, - ImportDeclaration::isStatic, - (n, reporter) -> reporter.report(n, "Static imports are not supported.") - ); - final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, - n -> n.getLabels().size() > 1, - (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.") - ); - final Validator noYield = new SimpleValidator<>(YieldStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.") - ); + + final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Enumerations are not supported.")); + + final Validator noVarargs = new SimpleValidator<>(Parameter.class, Parameter::isVarArgs, (n, reporter) -> reporter.report(n, "Varargs are not supported.")); + + final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, n -> true, (n, reporter) -> reporter.report(n, "For-each loops are not supported.")); + + final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, ImportDeclaration::isStatic, (n, reporter) -> reporter.report(n, "Static imports are not supported.")); + + final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, n -> n.getLabels().size() > 1, (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.")); + + final Validator noYield = new SimpleValidator<>(YieldStmt.class, n -> true, (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.")); + final Validator noBinaryIntegerLiterals = new NoBinaryIntegerLiteralsValidator(); + final Validator noUnderscoresInIntegerLiterals = new NoUnderscoresInIntegerLiteralsValidator(); - final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, - n -> true, - (n, reporter) -> reporter.report(n, "Multi-catch is not supported.") - ); - final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Lambdas are not supported.") - ); - final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, - n -> true, - (n, reporter) -> reporter.report(n, "Modules are not supported.") - ); - final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Switch expressions are not supported.") - ); - - - final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, - n -> n.getPattern().isPresent(), - (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.") - ); - - final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.") - ); + final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, n -> true, (n, reporter) -> reporter.report(n, "Multi-catch is not supported.")); + + final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Lambdas are not supported.")); + + final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Modules are not supported.")); + + final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Switch expressions are not supported.")); + + final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, n -> n.getPattern().isPresent(), (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.")); + + final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.")); public Java1_0Validator() { super(new CommonValidators()); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java index de042ca41a..9327643387 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -30,12 +29,11 @@ * This validator validates according to Java 1.1 syntax rules. */ public class Java1_1Validator extends Java1_0Validator { - 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."); - }) - ); + + 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(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java index b842083725..7f89d5c14e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.validator.ReservedKeywordValidator; @@ -29,7 +28,9 @@ * This validator validates according to Java 1.2 syntax rules. */ public class Java1_2Validator extends Java1_1Validator { + final Validator modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(true, false, false); + final Validator strictfpNotAllowed = new ReservedKeywordValidator("strictfp"); public Java1_2Validator() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java index aac41631eb..a5435bf9d8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java1_4Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java index 7206a50cbd..04c337ea49 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java5Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java index 416a13228e..cdd11ac419 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.Node; @@ -39,6 +38,7 @@ * This validator validates according to Java 5 syntax rules. */ public class Java5Validator extends Java1_4Validator { + final Validator genericsWithoutDiamondOperator = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { Optional> typeArguments = ((NodeWithTypeArguments) node).getTypeArguments(); @@ -65,8 +65,7 @@ public class Java5Validator extends Java1_4Validator { VariableDeclarationExpr declaration = node.getVariable(); // assert that the variable declaration expression has exactly one variable declarator if (declaration.getVariables().size() != 1) { - reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + - "declarator. Given: " + declaration.getVariables().size() + "."); + reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + "declarator. Given: " + declaration.getVariables().size() + "."); } }); @@ -78,11 +77,9 @@ public Java5Validator() { add(noPrimitiveGenericArguments); add(enumNotAllowed); add(forEachStmt); - // 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java index 064974a9f8..f87b66eea5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * This validator validates according to Java 6 syntax rules. */ -public class Java6Validator extends Java5Validator{ +public class Java6Validator extends Java5Validator { + public Java6Validator() { super(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java index 5414b7da22..6adb54f392 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.expr.Expression; @@ -30,10 +29,9 @@ * This validator validates according to Java 7 syntax rules. */ public class Java7Validator extends Java6Validator { + final SingleNodeTypeValidator tryWithLimitedResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() - && n.getResources().isEmpty() - && !n.getFinallyBlock().isPresent()) { + 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()) { @@ -42,6 +40,7 @@ public class Java7Validator extends Java6Validator { } } }); + private final SingleNodeTypeValidator multiCatch = new SingleNodeTypeValidator<>(UnionType.class, (n, reporter) -> { // Case "0 elements" is caught elsewhere. if (n.getElements().size() == 1) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java index 31691c6ce5..5be5febe52 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -33,25 +32,24 @@ * @see https://openjdk.java.net/projects/jdk8/features */ public class Java8Validator extends Java7Validator { + final Validator modifiersWithoutPrivateInterfaceMethods = new ModifierValidator(true, true, false); - 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."); - } - }); + + 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/language_level_validations/Java9Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java index 854e311a89..9392f88b7b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.stmt.TryStmt; @@ -33,27 +32,25 @@ * @see https://openjdk.java.net/projects/jdk9/ */ public class Java9Validator extends Java8Validator { + final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator(); + final Validator modifiers = new ModifierValidator(true, true, true); + final SingleNodeTypeValidator tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() - && n.getResources().isEmpty() - && !n.getFinallyBlock().isPresent()) { + 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(); - // Released Language Features - /* * Note 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 (that is done by the Java 10 post-processor). * You can add the node by hand, but that is obscure enough to ignore. */ - add(underscoreKeywordValidator); remove(noModules); replace(modifiersWithoutPrivateInterfaceMethods, modifiers); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java index 38b15182ef..ef18eaf30f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.NodeList; @@ -36,54 +35,39 @@ * 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(); + 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."); } - 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 "" + }); + } + }), 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/language_level_validations/chunks/ModifierValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java index 5b81bc5fef..244b2cfe82 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Modifier; @@ -39,17 +38,21 @@ import static com.github.javaparser.ast.Modifier.Keyword.*; 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.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP}; - private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; - private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[]{PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; + + private final Modifier.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP }; + + private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT }; + + private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[] { 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) { @@ -228,5 +231,4 @@ private & NodeWithTokenRange> void validateAt reporter.report(t, builder.toString()); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java index e2fba257be..642ec34a66 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -28,6 +27,7 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoBinaryIntegerLiteralsValidator extends VisitorValidator { + @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java index 19fdc527c6..8a828d0edb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -28,6 +27,7 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoUnderscoresInIntegerLiteralsValidator extends VisitorValidator { + @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java index b9d3503724..ed91401de4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -28,6 +27,7 @@ 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java index 0d2b61931b..76c51b02fe 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -29,8 +28,8 @@ 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.stmt.ForStmt; import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.ast.type.VarType; import com.github.javaparser.ast.validator.ProblemReporter; @@ -39,6 +38,7 @@ import java.util.Optional; public class VarValidator implements TypedValidator { + private boolean varAllowedInLambdaParameters; public VarValidator(boolean varAllowedInLambdaParameters) { @@ -52,10 +52,7 @@ public void accept(VarType node, ProblemReporter reporter) { if (!variableDeclarator.isPresent()) { // Java 11's var in lambda's if (varAllowedInLambdaParameters) { - boolean valid = node - .findAncestor(Parameter.class) - .flatMap(Node::getParentNode) - .map((Node p) -> p instanceof LambdaExpr).orElse(false); + boolean valid = node.findAncestor(Parameter.class).flatMap(Node::getParentNode).map((Node p) -> p instanceof LambdaExpr).orElse(false); if (valid) { return; } @@ -87,8 +84,7 @@ public void accept(VarType node, ProblemReporter reporter) { return; } container.ifPresent(c -> { - boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || - c instanceof ExpressionStmt || c instanceof TryStmt; + boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || c instanceof ExpressionStmt || c instanceof TryStmt; if (!positionIsFine) { reportIllegalPosition(node, reporter); } @@ -105,12 +101,10 @@ public void accept(VarType node, ProblemReporter reporter) { reporter.report(node, "\"var\" cannot infer array types."); } }); - } }); }); }); - } private void reportIllegalPosition(VarType n, ProblemReporter reporter) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java index 01935fab75..81a947acd0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ast.type.ClassOrInterfaceType; @@ -30,14 +29,14 @@ * Processes the generic AST into a Java 10 AST and validates it. */ public class Java10PostProcessor extends PostProcessors { - protected final PostProcessor varNodeCreator = (result, configuration) -> - result.getResult().ifPresent(node -> { - node.findAll(ClassOrInterfaceType.class).forEach(n -> { - if (n.getNameAsString().equals("var")) { - n.replace(new VarType(n.getTokenRange().orElse(null))); - } - }); - }); + + protected final PostProcessor varNodeCreator = (result, configuration) -> result.getResult().ifPresent(node -> { + node.findAll(ClassOrInterfaceType.class).forEach(n -> { + if (n.getNameAsString().equals("var")) { + n.replace(new VarType(n.getTokenRange().orElse(null))); + } + }); + }); public Java10PostProcessor() { add(varNodeCreator); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java index 873a106a00..7b4a785d33 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ParseResult; @@ -35,6 +34,7 @@ * A post processor that will call a collection of post processors. */ public class PostProcessors implements PostProcessor { + private final List postProcessors = new ArrayList<>(); public PostProcessors(PostProcessor... postProcessors) { 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 index 93c6b9135b..64206badd8 100644 --- 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 @@ -54,36 +54,36 @@ public class ModifierVisitor implements GenericVisitor { @Override public Visitable visit(final AnnotationDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList> members = modifyList(n.getMembers(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - NodeList> members = modifyList(n.getMembers(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); + n.setMembers(members); n.setModifiers(modifiers); n.setName(name); - n.setMembers(members); + n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || type == null) return null; - n.setAnnotations(annotations); - n.setModifiers(modifiers); n.setDefaultValue(defaultValue); + n.setModifiers(modifiers); n.setName(name); n.setType(type); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -237,40 +237,40 @@ public Visitable visit(final ClassExpr n, final A arg) { @Override public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList extendedTypes = modifyList(n.getExtendedTypes(), arg); NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); NodeList> members = modifyList(n.getMembers(), arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); - n.setModifiers(modifiers); n.setExtendedTypes(extendedTypes); n.setImplementedTypes(implementedTypes); n.setTypeParameters(typeParameters); n.setMembers(members); + n.setModifiers(modifiers); n.setName(name); + n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final ClassOrInterfaceType n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); ClassOrInterfaceType scope = n.getScope().map(s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null); NodeList typeArguments = modifyList(n.getTypeArguments(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); n.setName(name); n.setScope(scope); n.setTypeArguments(typeArguments); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -307,25 +307,25 @@ public Visitable visit(final ConditionalExpr n, final A arg) { @Override public Visitable visit(final ConstructorDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList parameters = modifyList(n.getParameters(), arg); ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || name == null) return null; - n.setAnnotations(annotations); - n.setModifiers(modifiers); n.setBody(body); + n.setModifiers(modifiers); n.setName(name); n.setParameters(parameters); n.setReceiverParameter(receiverParameter); n.setThrownExceptions(thrownExceptions); n.setTypeParameters(typeParameters); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -379,38 +379,38 @@ public Visitable visit(final EnclosedExpr n, final A arg) { @Override public Visitable visit(final EnumConstantDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList arguments = modifyList(n.getArguments(), arg); NodeList> classBody = modifyList(n.getClassBody(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); n.setArguments(arguments); n.setClassBody(classBody); n.setName(name); + n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final EnumDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList entries = modifyList(n.getEntries(), arg); NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); NodeList> members = modifyList(n.getMembers(), arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); - n.setModifiers(modifiers); n.setEntries(entries); n.setImplementedTypes(implementedTypes); n.setMembers(members); + n.setModifiers(modifiers); n.setName(name); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -456,15 +456,15 @@ public Visitable visit(final FieldAccessExpr n, final A arg) { @Override public Visitable visit(final FieldDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList variables = modifyList(n.getVariables(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (variables.isEmpty()) return null; - n.setAnnotations(annotations); n.setModifiers(modifiers); n.setVariables(variables); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -518,13 +518,13 @@ public Visitable visit(final IfStmt n, final A arg) { @Override public Visitable visit(final InitializerDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null) return null; - n.setAnnotations(annotations); n.setBody(body); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -621,27 +621,27 @@ public Visitable visit(final MethodCallExpr n, final A arg) { @Override public Visitable visit(final MethodDeclaration n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); BlockStmt body = n.getBody().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); Type type = (Type) n.getType().accept(this, arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList parameters = modifyList(n.getParameters(), arg); ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null || name == null) return null; - n.setAnnotations(annotations); - n.setModifiers(modifiers); n.setBody(body); n.setType(type); + n.setModifiers(modifiers); n.setName(name); n.setParameters(parameters); n.setReceiverParameter(receiverParameter); n.setThrownExceptions(thrownExceptions); n.setTypeParameters(typeParameters); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -755,13 +755,13 @@ public Visitable visit(final SimpleName n, final A arg) { @Override public Visitable visit(final ArrayType n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); Type componentType = (Type) n.getComponentType().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (componentType == null) return null; - n.setAnnotations(annotations); n.setComponentType(componentType); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -779,26 +779,26 @@ public Visitable visit(final ArrayCreationLevel n, final A arg) { @Override public Visitable visit(final IntersectionType n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList elements = modifyList(n.getElements(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (elements.isEmpty()) return null; - n.setAnnotations(annotations); n.setElements(elements); + n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final UnionType n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList elements = modifyList(n.getElements(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (elements.isEmpty()) return null; - n.setAnnotations(annotations); n.setElements(elements); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -928,15 +928,15 @@ public Visitable visit(final LocalClassDeclarationStmt n, final A arg) { @Override public Visitable visit(final TypeParameter n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList typeBound = modifyList(n.getTypeBound(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setAnnotations(annotations); n.setName(name); n.setTypeBound(typeBound); + n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -1015,13 +1015,13 @@ public Visitable visit(final WhileStmt n, final A arg) { @Override public Visitable visit(final WildcardType n, final A arg) { - NodeList annotations = modifyList(n.getAnnotations(), arg); ReferenceType extendedType = n.getExtendedType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); ReferenceType superType = n.getSuperType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); + NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); - n.setAnnotations(annotations); n.setExtendedType(extendedType); n.setSuperType(superType); + n.setAnnotations(annotations); n.setComment(comment); return n; } 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 index 678b821d4c..4360652bf1 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 23d173332a..41daf2a0d9 100644 --- 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 @@ -18,10 +18,10 @@ * 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. * diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java index cf574cef8e..de662381e6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc; import com.github.javaparser.ast.comments.JavadocComment; @@ -27,7 +26,7 @@ import java.util.LinkedList; import java.util.List; -import static com.github.javaparser.utils.Utils.*; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; /** * The structured content of a single Javadoc comment. @@ -40,6 +39,7 @@ public class Javadoc { private JavadocDescription description; + private List blockTags; public Javadoc(JavadocDescription description) { @@ -140,13 +140,12 @@ public List getBlockTags() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Javadoc document = (Javadoc) o; - return description.equals(document.description) && blockTags.equals(document.blockTags); - } @Override @@ -158,10 +157,6 @@ public int hashCode() { @Override public String toString() { - return "Javadoc{" + - "description=" + description + - ", blockTags=" + blockTags + - '}'; + return "Javadoc{" + "description=" + description + ", blockTags=" + blockTags + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java index 54ca9df544..1a2d18d7d4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc; import com.github.javaparser.javadoc.description.JavadocDescription; @@ -45,6 +44,7 @@ public class JavadocBlockTag { * an unknown tag. */ public enum Type { + AUTHOR, DEPRECATED, EXCEPTION, @@ -77,12 +77,14 @@ static Type fromName(String tagName) { } return UNKNOWN; } - } private Type type; + private JavadocDescription content; + private Optional name = Optional.empty(); + private String tagName; public JavadocBlockTag(Type type, String content) { @@ -134,13 +136,15 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocBlockTag that = (JavadocBlockTag) o; - - if (type != that.type) return false; - if (!content.equals(that.content)) return false; + if (type != that.type) + return false; + if (!content.equals(that.content)) + return false; return name.equals(that.name); } @@ -154,10 +158,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocBlockTag{" + - "type=" + type + - ", content='" + content + '\'' + - ", name=" + name + - '}'; + return "JavadocBlockTag{" + "type=" + type + ", content='" + content + '\'' + ", name=" + name + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java index 6a65e5436c..65196882ef 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; import com.github.javaparser.utils.Pair; @@ -71,7 +70,6 @@ public JavadocDescription() { public JavadocDescription(List elements) { this(); - this.elements.addAll(elements); } @@ -95,13 +93,12 @@ public boolean isEmpty() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocDescription that = (JavadocDescription) o; - return elements.equals(that.elements); - } @Override @@ -111,9 +108,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocDescription{" + - "elements=" + elements + - '}'; + return "JavadocDescription{" + "elements=" + elements + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java index 7d04300a7a..12d2431107 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; /** @@ -27,5 +26,6 @@ * So for example {@code a text} or {@link String} could be valid description elements. */ public interface JavadocDescriptionElement { + String toText(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java index 5ebbfc9f2b..7377910a86 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; import static com.github.javaparser.utils.Utils.nextWord; @@ -50,6 +49,7 @@ public static JavadocDescriptionElement fromText(String text) { * an unknown tag. */ public enum Type { + CODE, DOC_ROOT, INHERIT_DOC, @@ -74,11 +74,12 @@ static JavadocInlineTag.Type fromName(String tagName) { } return UNKNOWN; } - } private String tagName; + private Type type; + private String content; public JavadocInlineTag(String tagName, Type type, String content) { @@ -101,18 +102,20 @@ public String getName() { @Override public String toText() { - return "{@" + tagName + this.content +"}"; + return "{@" + tagName + this.content + "}"; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocInlineTag that = (JavadocInlineTag) o; - - if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false; - if (type != that.type) return false; + if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) + return false; + if (type != that.type) + return false; return content != null ? content.equals(that.content) : that.content == null; } @@ -126,10 +129,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocInlineTag{" + - "tagName='" + tagName + '\'' + - ", type=" + type + - ", content='" + content + '\'' + - '}'; + return "JavadocInlineTag{" + "tagName='" + tagName + '\'' + ", type=" + type + ", content='" + content + '\'' + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java index 8b4c545f04..59e7ad4f06 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; /** @@ -28,6 +27,7 @@ * before and one after the inline tag ({@link String}). */ public class JavadocSnippet implements JavadocDescriptionElement { + private String text; public JavadocSnippet(String text) { @@ -44,13 +44,12 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocSnippet that = (JavadocSnippet) o; - return text.equals(that.text); - } @Override @@ -60,8 +59,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocSnippet{" + - "text='" + text + '\'' + - '}'; + return "JavadocSnippet{" + "text='" + text + '\'' + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java index c4b2b7316d..257d7cac06 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import com.github.javaparser.ast.AllFieldsConstructor; @@ -27,7 +26,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; import static com.github.javaparser.utils.Utils.decapitalize; @@ -35,14 +37,23 @@ * Meta-data about all classes in the AST. These are all Nodes, except NodeList. */ public abstract class BaseNodeMetaModel { + private final Optional superNodeMetaModel; + private final List declaredPropertyMetaModels = new ArrayList<>(); + private final List derivedPropertyMetaModels = new ArrayList<>(); + private final List constructorParameters = new ArrayList<>(); + private final Class type; + private final String name; + private final String packageName; + private final boolean isAbstract; + private final boolean hasWildcard; public BaseNodeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { @@ -157,13 +168,13 @@ public boolean isRootNode() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; BaseNodeMetaModel classMetaModel = (BaseNodeMetaModel) o; - - if (!type.equals(classMetaModel.type)) return false; - + if (!type.equals(classMetaModel.type)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java index 98c90a1553..39fae20950 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java index d33af4fe7d..0070dbe420 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java index 9ad79ee8da..1b1731f756 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; @@ -34,6 +33,6 @@ * (Used during generation of the meta model.) */ @Retention(RUNTIME) -@Target({FIELD, METHOD}) +@Target({ FIELD, METHOD }) public @interface NonEmptyProperty { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java index b107e2afc2..fe975b9eac 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java index 659d7e3203..1335615909 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import com.github.javaparser.ast.Node; @@ -33,13 +32,21 @@ * Meta-data about a property of a node in the AST. */ public class PropertyMetaModel { + private final BaseNodeMetaModel containingNodeMetaModel; + private final String name; + private final Class type; + private final Optional nodeReference; + private final boolean isOptional; + private final boolean isNonEmpty; + private final boolean isNodeList; + private final boolean hasWildcard; public PropertyMetaModel(BaseNodeMetaModel containingNodeMetaModel, String name, Class type, Optional nodeReference, boolean isOptional, boolean isNonEmpty, boolean isNodeList, boolean hasWildcard) { @@ -158,14 +165,15 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; PropertyMetaModel that = (PropertyMetaModel) o; - - if (!name.equals(that.name)) return false; - if (!type.equals(that.type)) return false; - + if (!name.equals(that.name)) + return false; + if (!type.equals(that.type)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java index 0bfb7d0546..66c50da79c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; import com.github.javaparser.GeneratedJavaParserConstants; @@ -50,6 +49,7 @@ public class ConcreteSyntaxModel { private static final Map concreteSyntaxModelByClass = new HashMap<>(); + private static Optional initializationError; private static CsmElement modifiers() { @@ -72,884 +72,128 @@ private static CsmElement annotations() { } private static CsmElement typeParameters() { - return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), - sequence(token(GeneratedJavaParserConstants.GT), space())); + return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT), space())); } private static CsmElement typeArguments() { - return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), - sequence(token(GeneratedJavaParserConstants.GT))); + return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT))); } static { - - /// - /// Body - /// - - concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - token(GeneratedJavaParserConstants.AT), - token(GeneratedJavaParserConstants.INTERFACE), - space(), - child(ObservableProperty.NAME), - space(), - token(LBRACE), - newline(), - indent(), - list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), - unindent(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME), - token(LPAREN), - token(RPAREN), - conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), - semicolon() - )); - - concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), - space(), - child(ObservableProperty.NAME), - list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), - list(ObservableProperty.EXTENDED_TYPES, - sequence(string(GeneratedJavaParserConstants.COMMA), space()), - sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), - none()), - list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence( - space(), - token(GeneratedJavaParserConstants.IMPLEMENTS), - space()), none()), - space(), - block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))) - )); - - concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - typeParameters(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence( - comment(), - memberAnnotations(), - child(ObservableProperty.NAME), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), - conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), - list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), - unindent(), - token(RBRACE), newline())) - )); - - concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence( - comment(), - annotations(), - modifiers(), - token(GeneratedJavaParserConstants.ENUM), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.IMPLEMENTED_TYPES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), - none()), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - indent(), - newline(), - list(ObservableProperty.ENTRIES, - sequence(comma(), newline()), - none(), - none()), - conditional(ObservableProperty.MEMBERS, IS_EMPTY, - conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), - sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), - unindent(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence( - orphanCommentsBeforeThis(), - comment(), - annotations(), - modifiers(), - conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), - space(), - list(ObservableProperty.VARIABLES, sequence(comma(), space())), - semicolon())); - - concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence( - comment(), - conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), - child(ObservableProperty.BODY))); - - concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence( - orphanCommentsBeforeThis(), - comment(), - mix(memberAnnotations(), modifiers()), - typeParameters(), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), - list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), - conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()) - )); - - concreteSyntaxModelByClass.put(Parameter.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - modifiers(), - child(ObservableProperty.TYPE), - conditional(ObservableProperty.VAR_ARGS, FLAG, sequence( - list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), - token(GeneratedJavaParserConstants.ELLIPSIS))), - space(), - child(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence( - comment(), - child(ObservableProperty.NAME), - // FIXME: we should introduce a derived property - // list(ObservableProperty.EXTRA_ARRAY_LEVELS), - conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), - child(ObservableProperty.INITIALIZER))) - )); - - /// - /// Expressions - /// - - concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence( - comment(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LBRACKET), - child(ObservableProperty.INDEX), - token(GeneratedJavaParserConstants.RBRACKET) - )); - - concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.NEW), - space(), - child(ObservableProperty.ELEMENT_TYPE), - list(ObservableProperty.LEVELS), - conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))) - )); - - concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LBRACE), - list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), - orphanCommentsEnding(), - token(RBRACE))); - - concreteSyntaxModelByClass.put(AssignExpr.class, sequence( - comment(), - child(ObservableProperty.TARGET), - space(), - attribute(ObservableProperty.OPERATOR), - space(), - child(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(BinaryExpr.class, sequence( - comment(), - child(ObservableProperty.LEFT), - space(), - attribute(ObservableProperty.OPERATOR), - space(), - child(ObservableProperty.RIGHT) - )); - - concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence( - comment(), attribute(VALUE) - )); - - concreteSyntaxModelByClass.put(CastExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.TYPE), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.EXPRESSION) - )); - - concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence( - comment(), - charToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(ClassExpr.class, sequence( - comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); - - concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence( - comment(), - child(ObservableProperty.CONDITION), - space(), - token(GeneratedJavaParserConstants.HOOK), - space(), - child(ObservableProperty.THEN_EXPR), - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.ELSE_EXPR) - )); - - concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.INNER), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence( - comment(), - child(SCOPE), - token(GeneratedJavaParserConstants.DOT), - child(ObservableProperty.NAME) - )); - - concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence( - comment(), - child(ObservableProperty.EXPRESSION), - space(), - token(GeneratedJavaParserConstants.INSTANCEOF), - space(), - child(ObservableProperty.TYPE) - )); - - concreteSyntaxModelByClass.put(PatternExpr.class, sequence( - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME) - )); - - concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(LambdaExpr.class, sequence( - comment(), - conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), - list(ObservableProperty.PARAMETERS, sequence(comma(), space())), - conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), - space(), - token(GeneratedJavaParserConstants.ARROW), - space(), - conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)) - )); - - concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - + // / + // / Body + // / + concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), token(GeneratedJavaParserConstants.AT), token(GeneratedJavaParserConstants.INTERFACE), space(), child(ObservableProperty.NAME), space(), token(LBRACE), newline(), indent(), list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), unindent(), token(RBRACE))); + concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(LPAREN), token(RPAREN), conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), semicolon())); + concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), space(), child(ObservableProperty.NAME), list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(ObservableProperty.EXTENDED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))))); + concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), typeParameters(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence(comment(), memberAnnotations(), child(ObservableProperty.NAME), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), unindent(), token(RBRACE), newline())))); + concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence(comment(), annotations(), modifiers(), token(GeneratedJavaParserConstants.ENUM), space(), child(ObservableProperty.NAME), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.ENTRIES, sequence(comma(), newline()), none(), none()), conditional(ObservableProperty.MEMBERS, IS_EMPTY, conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), unindent(), token(RBRACE))); + concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), annotations(), modifiers(), conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())), semicolon())); + concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence(comment(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), mix(memberAnnotations(), modifiers()), typeParameters(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()))); + concreteSyntaxModelByClass.put(Parameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.TYPE), conditional(ObservableProperty.VAR_ARGS, FLAG, sequence(list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), token(GeneratedJavaParserConstants.ELLIPSIS))), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), // FIXME: we should introduce a derived property + // list(ObservableProperty.EXTRA_ARRAY_LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER))))); + // / + // / Expressions + // / + concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence(comment(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.INDEX), token(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NEW), space(), child(ObservableProperty.ELEMENT_TYPE), list(ObservableProperty.LEVELS), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))))); + concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LBRACE), list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), orphanCommentsEnding(), token(RBRACE))); + concreteSyntaxModelByClass.put(AssignExpr.class, sequence(comment(), child(ObservableProperty.TARGET), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(BinaryExpr.class, sequence(comment(), child(ObservableProperty.LEFT), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.RIGHT))); + concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence(comment(), attribute(VALUE))); + concreteSyntaxModelByClass.put(CastExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.EXPRESSION))); + concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence(comment(), charToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(ClassExpr.class, sequence(comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); + concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence(comment(), child(ObservableProperty.CONDITION), space(), token(GeneratedJavaParserConstants.HOOK), space(), child(ObservableProperty.THEN_EXPR), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ELSE_EXPR))); + concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.INNER), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence(comment(), child(SCOPE), token(GeneratedJavaParserConstants.DOT), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence(comment(), child(ObservableProperty.EXPRESSION), space(), token(GeneratedJavaParserConstants.INSTANCEOF), space(), child(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(PatternExpr.class, sequence(child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(LambdaExpr.class, sequence(comment(), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), list(ObservableProperty.PARAMETERS, sequence(comma(), space())), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), space(), token(GeneratedJavaParserConstants.ARROW), space(), conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)))); + concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); concreteSyntaxModelByClass.put(MarkerAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), attribute(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), - child(ObservableProperty.NAME), - space(), - token(GeneratedJavaParserConstants.ASSIGN), - space(), - child(ObservableProperty.VALUE))); - - concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence( - comment(), - conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), - typeArguments(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence( - comment(), - child(ObservableProperty.SCOPE), - token(GeneratedJavaParserConstants.DOUBLECOLON), - typeArguments(), - attribute(ObservableProperty.IDENTIFIER) - )); - + concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), typeArguments(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence(comment(), child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOUBLECOLON), typeArguments(), attribute(ObservableProperty.IDENTIFIER))); concreteSyntaxModelByClass.put(Modifier.class, attribute(ObservableProperty.KEYWORD)); - - concreteSyntaxModelByClass.put(Name.class, sequence( - comment(), - conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), - attribute(ObservableProperty.IDENTIFIER), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(NameExpr.class, sequence( - comment(), - child(ObservableProperty.NAME), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.AT), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.PAIRS, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.NULL) - )); - - concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence( - comment(), - conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.NEW), - space(), - list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), - conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), - child(ObservableProperty.TYPE), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, - sequence( - space(), token(LBRACE), newline(), indent(), - list(ObservableProperty.ANONYMOUS_CLASS_BODY, - newline(), - newline(), - newline(), - newline()), - unindent(), - token(RBRACE) - )) - )); - + concreteSyntaxModelByClass.put(Name.class, sequence(comment(), conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), attribute(ObservableProperty.IDENTIFIER), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(NameExpr.class, sequence(comment(), child(ObservableProperty.NAME), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PAIRS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NULL))); + concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.NEW), space(), list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, sequence(space(), token(LBRACE), newline(), indent(), list(ObservableProperty.ANONYMOUS_CLASS_BODY, newline(), newline(), newline(), newline()), unindent(), token(RBRACE))))); concreteSyntaxModelByClass.put(SimpleName.class, attribute(ObservableProperty.IDENTIFIER)); - - concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.AT), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.MEMBER_VALUE), - token(GeneratedJavaParserConstants.RPAREN))); - - concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence( - comment(), - stringToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence( - comment(), - textBlockToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(SuperExpr.class, sequence( - comment(), - conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.SUPER) - )); - - concreteSyntaxModelByClass.put(ThisExpr.class, sequence( - comment(), - conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.THIS) - )); - - concreteSyntaxModelByClass.put(TypeExpr.class, sequence( - comment(), - child(ObservableProperty.TYPE) - )); - - concreteSyntaxModelByClass.put(UnaryExpr.class, sequence( - conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), - child(ObservableProperty.EXPRESSION), - conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)) - )); - - concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - modifiers(), - child(ObservableProperty.MAXIMUM_COMMON_TYPE), - space(), - list(ObservableProperty.VARIABLES, sequence(comma(), space())) - )); - - /// - /// Statements - /// - - concreteSyntaxModelByClass.put(AssertStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.ASSERT), - space(), - child(ObservableProperty.CHECK), - conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence( - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.MESSAGE) - )), - semicolon() - )); - - concreteSyntaxModelByClass.put(BlockStmt.class, sequence( - orphanCommentsBeforeThis(), - comment(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), - orphanCommentsEnding(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(BreakStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.BREAK), - conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), - semicolon() - )); - - concreteSyntaxModelByClass.put(CatchClause.class, sequence( - comment(), - space(), - token(GeneratedJavaParserConstants.CATCH), - space(), - token(LPAREN), - child(ObservableProperty.PARAMETER), - token(RPAREN), - space(), - child(BODY) - )); - - concreteSyntaxModelByClass.put(ContinueStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.CONTINUE), - conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), - semicolon() - )); - - concreteSyntaxModelByClass.put(DoStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.DO), - space(), - child(ObservableProperty.BODY), - space(), - token(GeneratedJavaParserConstants.WHILE), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - semicolon() - )); - - concreteSyntaxModelByClass.put(EmptyStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SEMICOLON) - )); - - concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SEMICOLON) - )); - - concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence( - comment(), - conditional(ObservableProperty.THIS, FLAG, - sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), - sequence( - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), - typeArguments(), - token(GeneratedJavaParserConstants.SUPER) - )), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN), - semicolon() - )); - - concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence( - orphanCommentsBeforeThis(), - comment(), - child(ObservableProperty.EXPRESSION), - semicolon() - )); - - concreteSyntaxModelByClass.put(ForEachStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.FOR), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.VARIABLE), - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.ITERABLE), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(ForStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.FOR), - space(), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), - semicolon(), - space(), - child(ObservableProperty.COMPARE), - semicolon(), - space(), - list(ObservableProperty.UPDATE, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(IfStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.IF), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, - sequence(space(), child(ObservableProperty.THEN_STMT), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), - sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), - unindent())), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, - sequence(token(GeneratedJavaParserConstants.ELSE), - conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, - sequence(space(), child(ObservableProperty.ELSE_STMT)), - sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))) - )); - - concreteSyntaxModelByClass.put(LabeledStmt.class, sequence( - comment(), - child(ObservableProperty.LABEL), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.STATEMENT) - )); - - concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence( - comment(), - child(ObservableProperty.CLASS_DECLARATION) - )); - - concreteSyntaxModelByClass.put(ReturnStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.RETURN), - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), - semicolon())); - - concreteSyntaxModelByClass.put(YieldStmt.class, sequence( - comment(), - token(YIELD), - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), - semicolon())); - - concreteSyntaxModelByClass.put(SwitchEntry.class, sequence( - comment(), - conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, - sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), - sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), - newline(), - indent(), - list(ObservableProperty.STATEMENTS, newline(), none(), newline()), - unindent() - )); - - concreteSyntaxModelByClass.put(SwitchStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SWITCH), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.SELECTOR), - token(GeneratedJavaParserConstants.RPAREN), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.ENTRIES, none(), indent(), unindent()), - token(GeneratedJavaParserConstants.RBRACE) - )); - - concreteSyntaxModelByClass.put(SwitchExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SWITCH), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.SELECTOR), - token(GeneratedJavaParserConstants.RPAREN), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.ENTRIES, none(), indent(), unindent()), - token(GeneratedJavaParserConstants.RBRACE) - )); - - concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SYNCHRONIZED), - space(), - token(LPAREN), - child(EXPRESSION), - token(RPAREN), - space(), - child(BODY) - )); - - concreteSyntaxModelByClass.put(ThrowStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.THROW), - space(), - child(ObservableProperty.EXPRESSION), - semicolon() - )); - - concreteSyntaxModelByClass.put(TryStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.TRY), - space(), - conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence( - token(LPAREN), - list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), - token(RPAREN), - space())), - child(ObservableProperty.TRY_BLOCK), - list(ObservableProperty.CATCH_CLAUSES), - conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))) - )); - - concreteSyntaxModelByClass.put(WhileStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.WHILE), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - /// - /// Types - /// - - concreteSyntaxModelByClass.put(ArrayType.class, sequence( - child(ObservableProperty.COMPONENT_TYPE), - list(ObservableProperty.ANNOTATIONS), - string(GeneratedJavaParserConstants.LBRACKET), - string(GeneratedJavaParserConstants.RBRACKET))); - - concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), - conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), - list(ANNOTATIONS, space(), none(), space()), - child(NAME), - conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, - sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), - list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); - - concreteSyntaxModelByClass.put(IntersectionType.class, sequence( - comment(), - annotations(), - list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); - - concreteSyntaxModelByClass.put(PrimitiveType.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS), - attribute(ObservableProperty.TYPE))); - - concreteSyntaxModelByClass.put(TypeParameter.class, sequence( - comment(), - annotations(), - child(ObservableProperty.NAME), - list(ObservableProperty.TYPE_BOUND, - sequence( - space(), - token(GeneratedJavaParserConstants.BIT_AND), - space()), - sequence( - space(), - token(GeneratedJavaParserConstants.EXTENDS), - space()), - none()) - )); - - concreteSyntaxModelByClass.put(UnionType.class, sequence( - comment(), - annotations(), - list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())) - )); - + concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.MEMBER_VALUE), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence(comment(), stringToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence(comment(), textBlockToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(SuperExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.SUPER))); + concreteSyntaxModelByClass.put(ThisExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.THIS))); + concreteSyntaxModelByClass.put(TypeExpr.class, sequence(comment(), child(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(UnaryExpr.class, sequence(conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), child(ObservableProperty.EXPRESSION), conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)))); + concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.MAXIMUM_COMMON_TYPE), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())))); + // / + // / Statements + // / + concreteSyntaxModelByClass.put(AssertStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.ASSERT), space(), child(ObservableProperty.CHECK), conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.MESSAGE))), semicolon())); + concreteSyntaxModelByClass.put(BlockStmt.class, sequence(orphanCommentsBeforeThis(), comment(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), orphanCommentsEnding(), token(RBRACE))); + concreteSyntaxModelByClass.put(BreakStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.BREAK), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); + concreteSyntaxModelByClass.put(CatchClause.class, sequence(comment(), space(), token(GeneratedJavaParserConstants.CATCH), space(), token(LPAREN), child(ObservableProperty.PARAMETER), token(RPAREN), space(), child(BODY))); + concreteSyntaxModelByClass.put(ContinueStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.CONTINUE), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); + concreteSyntaxModelByClass.put(DoStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.DO), space(), child(ObservableProperty.BODY), space(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), semicolon())); + concreteSyntaxModelByClass.put(EmptyStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); + concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); + concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence(comment(), conditional(ObservableProperty.THIS, FLAG, sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), sequence(conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), typeArguments(), token(GeneratedJavaParserConstants.SUPER))), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), semicolon())); + concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence(orphanCommentsBeforeThis(), comment(), child(ObservableProperty.EXPRESSION), semicolon())); + concreteSyntaxModelByClass.put(ForEachStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.VARIABLE), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ITERABLE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(ForStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), semicolon(), space(), child(ObservableProperty.COMPARE), semicolon(), space(), list(ObservableProperty.UPDATE, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(IfStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.IF), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), unindent())), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, sequence(token(GeneratedJavaParserConstants.ELSE), conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.ELSE_STMT)), sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))))); + concreteSyntaxModelByClass.put(LabeledStmt.class, sequence(comment(), child(ObservableProperty.LABEL), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.STATEMENT))); + concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence(comment(), child(ObservableProperty.CLASS_DECLARATION))); + concreteSyntaxModelByClass.put(ReturnStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.RETURN), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); + concreteSyntaxModelByClass.put(YieldStmt.class, sequence(comment(), token(YIELD), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); + concreteSyntaxModelByClass.put(SwitchEntry.class, sequence(comment(), conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), newline(), indent(), list(ObservableProperty.STATEMENTS, newline(), none(), newline()), unindent())); + concreteSyntaxModelByClass.put(SwitchStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); + concreteSyntaxModelByClass.put(SwitchExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); + concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SYNCHRONIZED), space(), token(LPAREN), child(EXPRESSION), token(RPAREN), space(), child(BODY))); + concreteSyntaxModelByClass.put(ThrowStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.THROW), space(), child(ObservableProperty.EXPRESSION), semicolon())); + concreteSyntaxModelByClass.put(TryStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.TRY), space(), conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence(token(LPAREN), list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), token(RPAREN), space())), child(ObservableProperty.TRY_BLOCK), list(ObservableProperty.CATCH_CLAUSES), conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))))); + concreteSyntaxModelByClass.put(WhileStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + // / + // / Types + // / + concreteSyntaxModelByClass.put(ArrayType.class, sequence(child(ObservableProperty.COMPONENT_TYPE), list(ObservableProperty.ANNOTATIONS), string(GeneratedJavaParserConstants.LBRACKET), string(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), list(ANNOTATIONS, space(), none(), space()), child(NAME), conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); + concreteSyntaxModelByClass.put(IntersectionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); + concreteSyntaxModelByClass.put(PrimitiveType.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS), attribute(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(TypeParameter.class, sequence(comment(), annotations(), child(ObservableProperty.NAME), list(ObservableProperty.TYPE_BOUND, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()))); + concreteSyntaxModelByClass.put(UnionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())))); concreteSyntaxModelByClass.put(UnknownType.class, none()); - concreteSyntaxModelByClass.put(VoidType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.VOID))); - concreteSyntaxModelByClass.put(VarType.class, sequence(comment(), annotations(), string(GeneratedJavaParserConstants.IDENTIFIER, "var"))); - - concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), - conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), - conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); - - /// - /// Top Level - /// - - concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence( - annotations(), - token(GeneratedJavaParserConstants.LBRACKET), - child(ObservableProperty.DIMENSION), - token(GeneratedJavaParserConstants.RBRACKET) - )); - - concreteSyntaxModelByClass.put(CompilationUnit.class, sequence( - comment(), - child(ObservableProperty.PACKAGE_DECLARATION), - list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), - list(TYPES, newline(), newline(), none(), newline()), - child(ObservableProperty.MODULE), - orphanCommentsEnding())); - - concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence( - comment(), - token(GeneratedJavaParserConstants.IMPORT), - space(), - conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), - child(ObservableProperty.NAME), - conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), - semicolon(), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence( - comment(), - memberAnnotations(), - token(GeneratedJavaParserConstants.PACKAGE), - space(), - child(ObservableProperty.NAME), - semicolon(), - newline(), - newline(), - orphanCommentsEnding())); - - /// - /// Module info - /// - - concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence( - memberAnnotations(), - conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), - token(GeneratedJavaParserConstants.MODULE), - space(), - child(ObservableProperty.NAME), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - indent(), - list(ObservableProperty.DIRECTIVES), - unindent(), - token(GeneratedJavaParserConstants.RBRACE), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence( - token(GeneratedJavaParserConstants.EXPORTS), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.MODULE_NAMES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.TO), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence( - token(GeneratedJavaParserConstants.OPENS), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.MODULE_NAMES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.TO), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence( - token(GeneratedJavaParserConstants.PROVIDES), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.WITH, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence( - token(GeneratedJavaParserConstants.REQUIRES), - space(), - modifiers(), - child(ObservableProperty.NAME), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence( - token(GeneratedJavaParserConstants.USES), - space(), - child(ObservableProperty.NAME), - semicolon(), - newline() - )); - - List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream() - .filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())) - .map(nm -> nm.getType().getSimpleName()) - .collect(Collectors.toList()); + concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); + // / + // / Top Level + // / + concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence(annotations(), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.DIMENSION), token(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(CompilationUnit.class, sequence(comment(), child(ObservableProperty.PACKAGE_DECLARATION), list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), list(TYPES, newline(), newline(), none(), newline()), child(ObservableProperty.MODULE), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence(comment(), token(GeneratedJavaParserConstants.IMPORT), space(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.NAME), conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), semicolon(), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence(comment(), memberAnnotations(), token(GeneratedJavaParserConstants.PACKAGE), space(), child(ObservableProperty.NAME), semicolon(), newline(), newline(), orphanCommentsEnding())); + // / + // / Module info + // / + concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence(memberAnnotations(), conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), token(GeneratedJavaParserConstants.MODULE), space(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), list(ObservableProperty.DIRECTIVES), unindent(), token(GeneratedJavaParserConstants.RBRACE), newline())); + concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence(token(GeneratedJavaParserConstants.EXPORTS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence(token(GeneratedJavaParserConstants.OPENS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence(token(GeneratedJavaParserConstants.PROVIDES), space(), child(ObservableProperty.NAME), list(ObservableProperty.WITH, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence(token(GeneratedJavaParserConstants.REQUIRES), space(), modifiers(), child(ObservableProperty.NAME), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence(token(GeneratedJavaParserConstants.USES), space(), child(ObservableProperty.NAME), semicolon(), newline())); + List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream().filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())).map(nm -> nm.getType().getSimpleName()).collect(Collectors.toList()); if (unsupportedNodeClassNames.isEmpty()) { initializationError = Optional.empty(); } else { @@ -958,7 +202,6 @@ private static CsmElement typeArguments() { } private ConcreteSyntaxModel() { - } public static void genericPrettyPrint(Node node, SourcePrinter printer) { @@ -980,5 +223,4 @@ public static CsmElement forClass(Class nodeClazz) { } return concreteSyntaxModelByClass.get(nodeClazz); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java index 2f14d09bb9..2ba6418d14 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java @@ -18,70 +18,66 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.function.Function; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; +import com.github.javaparser.printer.configuration.PrinterConfiguration; + +import java.util.function.Function; /** * Pretty printer for AST nodes. */ public class DefaultPrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + // visitor factory Function> visitorFactory; - - // static methods - + + // static methods private static Function> createDefaultVisitor() { PrinterConfiguration configuration = createDefaultConfiguration(); return createDefaultVisitor(configuration); } - + private static Function> createDefaultVisitor(PrinterConfiguration configuration) { return (config) -> new DefaultPrettyPrinterVisitor(config, new SourcePrinter(config)); } - + private static PrinterConfiguration createDefaultConfiguration() { return new DefaultPrinterConfiguration(); } - - // Constructors + // Constructors /** * Build a new DefaultPrettyPrinter with a default configuration and a default factory */ public DefaultPrettyPrinter() { - this(createDefaultVisitor(), createDefaultConfiguration() ); + this(createDefaultVisitor(), createDefaultConfiguration()); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a default factory * @param configuration */ public DefaultPrettyPrinter(PrinterConfiguration configuration) { - this(createDefaultVisitor(configuration), configuration ); + this(createDefaultVisitor(configuration), configuration); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a factory to create a visitor to browse the nodes of the AST - * @param visitorFactory + * @param visitorFactory * @param configuration Configuration to apply */ public DefaultPrettyPrinter(Function> visitorFactory, PrinterConfiguration configuration) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + // Methods - /* * Returns the Printer configuration */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java index 9432e7cd90..2e3f603843 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java @@ -17,136 +17,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.isNullOrEmpty; -import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; -import static com.github.javaparser.utils.Utils.trimTrailingSpaces; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.ReceiverParameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; +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.AnnotationExpr; -import com.github.javaparser.ast.expr.ArrayAccessExpr; -import com.github.javaparser.ast.expr.ArrayCreationExpr; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.SuperExpr; -import com.github.javaparser.ast.expr.SwitchExpr; -import com.github.javaparser.ast.expr.TextBlockLiteralExpr; -import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.ast.expr.TypeExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.modules.ModuleDeclaration; -import com.github.javaparser.ast.modules.ModuleExportsDirective; -import com.github.javaparser.ast.modules.ModuleOpensDirective; -import com.github.javaparser.ast.modules.ModuleProvidesDirective; -import com.github.javaparser.ast.modules.ModuleRequiresDirective; -import com.github.javaparser.ast.modules.ModuleUsesDirective; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithVariables; -import com.github.javaparser.ast.nodeTypes.SwitchNode; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForEachStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntry; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.UnparsableStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.stmt.YieldStmt; -import com.github.javaparser.ast.type.ArrayType; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.IntersectionType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.ReferenceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.type.UnionType; -import com.github.javaparser.ast.type.UnknownType; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.ConfigurationOption; @@ -154,18 +37,29 @@ import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.*; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + /** * Outputs the AST as formatted Java source code. - * */ public class DefaultPrettyPrinterVisitor implements VoidVisitor { + protected final PrinterConfiguration configuration; + protected final SourcePrinter printer; public DefaultPrettyPrinterVisitor(PrinterConfiguration configuration) { this(configuration, new SourcePrinter(configuration)); } - + public DefaultPrettyPrinterVisitor(PrinterConfiguration configuration, SourcePrinter printer) { this.configuration = configuration; this.printer = printer; @@ -200,8 +94,7 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, - final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { if (annotations.isEmpty()) { return; } @@ -309,16 +202,13 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } - if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } - n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } - for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -326,9 +216,7 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } - n.getModule().ifPresent(m -> m.accept(this, arg)); - printOrphanCommentsEnding(n); } @@ -341,7 +229,6 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); - printOrphanCommentsEnding(n); } @@ -350,7 +237,6 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - printOrphanCommentsEnding(n); } @@ -363,7 +249,6 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); - printOrphanCommentsEnding(n); } @@ -378,17 +263,13 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } - n.getName().accept(this, arg); - printTypeParameters(n.getTypeParameters(), arg); - if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -399,7 +280,6 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -410,15 +290,12 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -439,7 +316,6 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } - boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -474,9 +350,7 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); - n.getName().accept(this, arg); - if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -519,7 +393,6 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } - type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -593,7 +466,6 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -604,7 +476,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } - printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -613,7 +484,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } - printer.print(";"); } @@ -622,13 +492,9 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { - final Type type = n.getType(); - ArrayType arrayType = null; - for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -639,7 +505,6 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); - if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -728,12 +593,9 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } - - /** * work in progress for issue-545 */ - @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -803,7 +665,7 @@ public void visit(final InstanceOfExpr n, final Void arg) { n.getExpression().accept(this, arg); printer.print(" instanceof "); n.getType().accept(this, arg); - if(n.getName().isPresent()) { + if (n.getName().isPresent()) { printer.print(" "); n.getName().get().accept(this, arg); } @@ -909,7 +771,6 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -917,38 +778,24 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (getOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN).isPresent()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() - || p.isThrowStmt() - || p.isAssertStmt() - || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(c::equals) - .orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { c = p.get(); p = c.getParentNode(); } - // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } - // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode() - .filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(node::equals) - .orElse(false)) { + while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -956,15 +803,13 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } - // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -972,7 +817,6 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } - // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -997,7 +841,6 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); - printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -1017,18 +860,13 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } - printer.print("new "); - printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } - n.getType().accept(this, arg); - printArguments(n.getArguments(), arg); - if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -1045,9 +883,7 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } - n.getExpression().accept(this, arg); - if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -1059,13 +895,11 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -1077,7 +911,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1095,7 +928,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -1103,11 +935,9 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); - printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -1125,7 +955,6 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1200,12 +1029,10 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); - if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); - for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1307,7 +1134,6 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - if (isNullOrEmpty(n.getLabels())) { printer.print("default:"); } else { @@ -1368,10 +1194,8 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("enum "); n.getName().accept(this, arg); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1382,15 +1206,12 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = - // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || - // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1422,11 +1243,9 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); - if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } - if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1453,7 +1272,8 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (thenBlock) // block statement should start on the same line + if (// block statement should start on the same line + thenBlock) printer.print(") "); else { printer.println(")"); @@ -1469,7 +1289,8 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (elseIf || elseBlock) // put chained if and start of block statement on a same level + if (// put chained if and start of block statement on a same level + elseIf || elseBlock) printer.print("else "); else { printer.println("else"); @@ -1626,7 +1447,6 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1644,7 +1464,6 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1708,9 +1527,7 @@ public void visit(final LineComment n, final Void arg) { if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) { return; } - printer - .print("// ") - .println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1719,13 +1536,16 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString()); - String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + String[] lines = commentContent.split("\\R", -1); printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); } - printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` + // last line is not followed by a newline, and simply terminated with `*/` + printer.print(lines[lines.length - 1]); printer.println("*/"); } @@ -1733,10 +1553,8 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); - if (printPar) { printer.print("("); } @@ -1750,7 +1568,6 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } - printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1770,7 +1587,6 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } - printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1790,11 +1606,9 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (getOption(ConfigOption.ORDER_IMPORTS).isPresent() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - //noinspection unchecked + // noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort( - comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) - .thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1818,11 +1632,9 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); - printOrphanCommentsEnding(n); } - @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1881,15 +1693,18 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; - if (node instanceof Comment) return; - + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) + return; + if (node instanceof Comment) + return; Node parent = node.getParentNode().orElse(null); - if (parent == null) return; + if (parent == null) + return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { + // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1900,28 +1715,26 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) + positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException( - "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " - + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; - + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) + return; // extract all nodes for which the position/range is indicated to avoid to skip orphan comments - List everything = node.getChildNodes().stream().filter(n->n.getRange().isPresent()).collect(Collectors.toList()); + List everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -1935,16 +1748,17 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - private void indentIf(boolean expr){ - if(expr) + + private void indentIf(boolean expr) { + if (expr) printer.indent(); - } - private void unindentIf(boolean expr){ - if(expr) + } + + private void unindentIf(boolean expr) { + if (expr) printer.unindent(); } - - + private Optional getOption(ConfigOption cOption) { return configuration.get(new DefaultConfigurationOption(cOption)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java index 82b979cd38..a7dde26050 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java @@ -18,26 +18,26 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import java.util.List; + +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + /** * Outputs a Graphviz diagram of the AST. */ public class DotPrinter { private int nodeCount; + private final boolean outputNodeType; public DotPrinter(boolean outputNodeType) { @@ -57,37 +57,26 @@ public void output(Node node, String parentNodeName, String name, StringBuilder assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) - .collect(toList()); - + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); String ndName = nextNodeName(); if (outputNodeType) - builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() - + ")\"];"); + builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() + ")\"];"); else builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + "\"];"); - if (parentNodeName != null) builder.append(SYSTEM_EOL + parentNodeName + " -> " + ndName + ";"); - for (PropertyMetaModel a : attributes) { String attrName = nextNodeName(); - builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" - + escape(a.getValue(node).toString()) + "'\"];"); + builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" + escape(a.getValue(node).toString()) + "'\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + attrName + ";"); - } - for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, ndName, sn.getName(), builder); } - for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { @@ -95,8 +84,7 @@ public void output(Node node, String parentNodeName, String name, StringBuilder builder.append(SYSTEM_EOL + ndLstName + " [label=\"" + escape(sl.getName()) + "\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + ndLstName + ";"); String slName = sl.getName().substring(0, sl.getName().length() - 1); - for (Node nd : nl) - output(nd, ndLstName, slName, builder); + for (Node nd : nl) output(nd, ndLstName, slName, builder); } } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index d9731f6abf..e478a1463e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -18,158 +18,53 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.isNullOrEmpty; -import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; -import static com.github.javaparser.utils.Utils.trimTrailingSpaces; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.ReceiverParameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; +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.AnnotationExpr; -import com.github.javaparser.ast.expr.ArrayAccessExpr; -import com.github.javaparser.ast.expr.ArrayCreationExpr; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.SuperExpr; -import com.github.javaparser.ast.expr.SwitchExpr; -import com.github.javaparser.ast.expr.TextBlockLiteralExpr; -import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.ast.expr.TypeExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.modules.ModuleDeclaration; -import com.github.javaparser.ast.modules.ModuleExportsDirective; -import com.github.javaparser.ast.modules.ModuleOpensDirective; -import com.github.javaparser.ast.modules.ModuleProvidesDirective; -import com.github.javaparser.ast.modules.ModuleRequiresDirective; -import com.github.javaparser.ast.modules.ModuleUsesDirective; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithVariables; -import com.github.javaparser.ast.nodeTypes.SwitchNode; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForEachStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntry; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.UnparsableStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.stmt.YieldStmt; -import com.github.javaparser.ast.type.ArrayType; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.IntersectionType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.ReferenceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.type.UnionType; -import com.github.javaparser.ast.type.UnknownType; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.*; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + /** * Outputs the AST as formatted Java source code. * This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation *

Use {@link DefaultPrettyPrinterVisitor default implementation } instead. * @author Julio Vilmar Gesser - * @deprecated This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation. + * @deprecated This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation. * This class could be removed in a future version. Use default DefaultPrettyPrinterVisitor. */ @Deprecated public class PrettyPrintVisitor implements VoidVisitor { + protected PrettyPrinterConfiguration configuration; + protected final SourcePrinter printer; public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) { this.configuration = prettyPrinterConfiguration; printer = new SourcePrinter(configuration); } - + public void setConfiguration(PrettyPrinterConfiguration prettyPrinterConfiguration) { this.configuration = prettyPrinterConfiguration; } @@ -211,8 +106,7 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, - final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { if (annotations.isEmpty()) { return; } @@ -320,16 +214,13 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } - if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } - n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } - for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -337,9 +228,7 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } - n.getModule().ifPresent(m -> m.accept(this, arg)); - printOrphanCommentsEnding(n); } @@ -352,7 +241,6 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); - printOrphanCommentsEnding(n); } @@ -361,7 +249,6 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - printOrphanCommentsEnding(n); } @@ -374,7 +261,6 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); - printOrphanCommentsEnding(n); } @@ -389,17 +275,13 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } - n.getName().accept(this, arg); - printTypeParameters(n.getTypeParameters(), arg); - if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -410,7 +292,6 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -421,15 +302,12 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -450,7 +328,6 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } - boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -485,9 +362,7 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); - n.getName().accept(this, arg); - if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -530,7 +405,6 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } - type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -604,7 +478,6 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -615,7 +488,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } - printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -624,7 +496,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } - printer.print(";"); } @@ -633,13 +504,9 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { - final Type type = n.getType(); - ArrayType arrayType = null; - for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -650,7 +517,6 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); - if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -739,12 +605,9 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } - - /** * work in progress for issue-545 */ - @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -814,7 +677,7 @@ public void visit(final InstanceOfExpr n, final Void arg) { n.getExpression().accept(this, arg); printer.print(" instanceof "); n.getType().accept(this, arg); - if(n.getName().isPresent()) { + if (n.getName().isPresent()) { printer.print(" "); n.getName().get().accept(this, arg); } @@ -920,7 +783,6 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -928,38 +790,24 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (configuration.isColumnAlignFirstMethodChain()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() - || p.isThrowStmt() - || p.isAssertStmt() - || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(c::equals) - .orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { c = p.get(); p = c.getParentNode(); } - // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } - // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode() - .filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(node::equals) - .orElse(false)) { + while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -967,15 +815,13 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } - // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -983,7 +829,6 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } - // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -1008,7 +853,6 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); - printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -1028,18 +872,13 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } - printer.print("new "); - printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } - n.getType().accept(this, arg); - printArguments(n.getArguments(), arg); - if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -1056,9 +895,7 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } - n.getExpression().accept(this, arg); - if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -1070,13 +907,11 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -1088,7 +923,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1106,7 +940,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -1114,11 +947,9 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); - printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -1136,7 +967,6 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1211,12 +1041,10 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); - if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); - for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1318,7 +1146,6 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - if (isNullOrEmpty(n.getLabels())) { printer.print("default:"); } else { @@ -1379,10 +1206,8 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("enum "); n.getName().accept(this, arg); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1393,15 +1218,12 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = - // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || - // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1433,11 +1255,9 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); - if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } - if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1464,7 +1284,8 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (thenBlock) // block statement should start on the same line + if (// block statement should start on the same line + thenBlock) printer.print(") "); else { printer.println(")"); @@ -1480,7 +1301,8 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (elseIf || elseBlock) // put chained if and start of block statement on a same level + if (// put chained if and start of block statement on a same level + elseIf || elseBlock) printer.print("else "); else { printer.println("else"); @@ -1637,7 +1459,6 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1655,7 +1476,6 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1719,9 +1539,7 @@ public void visit(final LineComment n, final Void arg) { if (configuration.isIgnoreComments()) { return; } - printer - .print("// ") - .println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1730,13 +1548,16 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter()); - String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + String[] lines = commentContent.split("\\R", -1); printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - printer.print(configuration.getEndOfLineCharacter()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + printer.print(configuration.getEndOfLineCharacter()); } - printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` + // last line is not followed by a newline, and simply terminated with `*/` + printer.print(lines[lines.length - 1]); printer.println("*/"); } @@ -1744,10 +1565,8 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); - if (printPar) { printer.print("("); } @@ -1761,7 +1580,6 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } - printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1781,7 +1599,6 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } - printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1801,11 +1618,9 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (configuration.isOrderImports() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - //noinspection unchecked + // noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort( - comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) - .thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1829,11 +1644,9 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); - printOrphanCommentsEnding(n); } - @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1892,15 +1705,18 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (configuration.isIgnoreComments()) return; - if (node instanceof Comment) return; - + if (configuration.isIgnoreComments()) + return; + if (node instanceof Comment) + return; Node parent = node.getParentNode().orElse(null); - if (parent == null) return; + if (parent == null) + return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { + // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1911,28 +1727,26 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) + positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException( - "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " - + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (configuration.isIgnoreComments()) return; - + if (configuration.isIgnoreComments()) + return; // extract all nodes for which the position/range is indicated to avoid to skip orphan comments - List everything = node.getChildNodes().stream().filter(n->n.getRange().isPresent()).collect(Collectors.toList()); + List everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -1946,12 +1760,14 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - private void indentIf(boolean expr){ - if(expr) + + private void indentIf(boolean expr) { + if (expr) printer.indent(); - } - private void unindentIf(boolean expr){ - if(expr) + } + + private void unindentIf(boolean expr) { + if (expr) printer.unindent(); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java index 8e56a4c54c..23a391764f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java @@ -18,15 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.function.Function; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import com.github.javaparser.printer.configuration.PrinterConfiguration; + +import java.util.function.Function; /** * Pretty printer for AST nodes. @@ -36,24 +35,24 @@ */ @Deprecated public class PrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + private Function> visitorFactory; public PrettyPrinter() { this(new PrettyPrinterConfiguration()); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration) { this(configuration, PrettyPrintVisitor::new); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration, Function> visitorFactory) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + /* * Returns the PrettyPrinter configuration */ @@ -73,9 +72,8 @@ public Printer setConfiguration(PrinterConfiguration configuration) { @Override public String print(Node node) { - final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration)configuration); + final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration) configuration); node.accept(visitor, null); return visitor.toString(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java index 09a51e86e9..0e3d651145 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java @@ -5,15 +5,13 @@ /** * Printer interface defines the API for a printer. - * A printer outputs the AST as formatted Java source code. - * + * A printer outputs the AST as formatted Java source code. */ public interface Printer { String print(Node node); Printer setConfiguration(PrinterConfiguration configuration); - - PrinterConfiguration getConfiguration(); -} \ No newline at end of file + PrinterConfiguration getConfiguration(); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java index a0841da3b0..e13a7f7306 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java @@ -18,49 +18,51 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.Deque; -import java.util.LinkedList; - import com.github.javaparser.Position; -import com.github.javaparser.printer.configuration.DefaultConfigurationOption; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; +import com.github.javaparser.printer.configuration.*; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; -import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.utils.Utils; +import java.util.Deque; +import java.util.LinkedList; + /** * A support class for code that outputs formatted source code. */ public class SourcePrinter { + private String endOfLineCharacter; + private Indentation indentation; private final Deque indents = new LinkedList<>(); + private final Deque reindentedIndents = new LinkedList<>(); + private String lastPrintedIndent = ""; + private final StringBuilder buf = new StringBuilder(); - private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); // Start before the first column + + // Start before the first column + private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); + private boolean indented = false; SourcePrinter() { this(new DefaultPrinterConfiguration()); } - + SourcePrinter(final PrettyPrinterConfiguration configuration) { this(configuration.getIndentation(), configuration.getEndOfLineCharacter()); } SourcePrinter(final PrinterConfiguration configuration) { - this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), - configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); + this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); } - + SourcePrinter(Indentation indentation, String eol) { this.indentation = indentation; this.endOfLineCharacter = eol; @@ -73,16 +75,14 @@ public class SourcePrinter { */ public SourcePrinter indent() { String currentIndent = indents.peek(); - switch (indentation.getType()) { + switch(indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: indents.push(currentIndent + indentation.getIndent()); break; - case TABS: indents.push(indentation.getIndent() + currentIndent); break; - default: throw new AssertionError("Unhandled indent type"); } @@ -99,21 +99,19 @@ public SourcePrinter indentWithAlignTo(int column) { } private String calculateIndentWithAlignTo(int column) { - if (column < lastPrintedIndent.length()){ + if (column < lastPrintedIndent.length()) { throw new IllegalStateException("Attempt to indent less than the previous indent."); } - StringBuilder newIndent = new StringBuilder(lastPrintedIndent); - switch (indentation.getType()) { + switch(indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: while (newIndent.length() < column) { newIndent.append(IndentType.SPACES.getCar()); } break; - case TABS: - IndentType currentIndentType = indentation.getType(); + IndentType currentIndentType = indentation.getType(); int logicalIndentLength = newIndent.length(); while ((logicalIndentLength + currentIndentType.getWidth()) <= column) { newIndent.insert(0, currentIndentType.getCar()); @@ -124,21 +122,18 @@ private String calculateIndentWithAlignTo(int column) { logicalIndentLength++; } StringBuilder fullTab = new StringBuilder(); - for(int i=0; i= currentIndentType.getWidth()) - && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { + if ((newIndent.length() >= currentIndentType.getWidth()) && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { int i = newIndent.indexOf(fullTabString); newIndent.replace(i, i + currentIndentType.getWidth(), currentIndentType.getCar().toString()); } break; - default: throw new AssertionError("Unhandled indent type"); } - return newIndent.toString(); } @@ -208,7 +203,8 @@ public SourcePrinter println(final String arg) { */ public SourcePrinter println() { buf.append(endOfLineCharacter); - cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); // Start before the first column + // Start before the first column + cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); indented = false; return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java index b299b2f3d6..dc6f0ab42d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java @@ -24,5 +24,6 @@ * Something that has a printable form. I.e., it can be converted to a user-facing String. */ public interface Stringable { + String asString(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java index 7c9bc5455e..434f2526fe 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; import com.github.javaparser.ast.Node; @@ -35,6 +34,7 @@ * Outputs an XML file containing the AST meant for inspecting it. */ public class XmlPrinter { + private final boolean outputNodeType; public XmlPrinter(boolean outputNodeType) { @@ -54,24 +54,20 @@ public void output(Node node, String name, int level, StringBuilder builder) { List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); - builder.append("<").append(name); if (outputNodeType) { builder.append(attribute("type", metaModel.getTypeName())); } - for (PropertyMetaModel attributeMetaModel : attributes) { builder.append(attribute(attributeMetaModel.getName(), attributeMetaModel.getValue(node).toString())); } builder.append(">"); - for (PropertyMetaModel subNodeMetaModel : subNodes) { Node value = (Node) subNodeMetaModel.getValue(node); if (value != null) { output(value, subNodeMetaModel.getName(), level + 1, builder); } } - for (PropertyMetaModel subListMetaModel : subLists) { NodeList subList = (NodeList) subListMetaModel.getValue(node); if (subList != null && !subList.isEmpty()) { @@ -99,4 +95,3 @@ public static void print(Node node) { System.out.println(new XmlPrinter(true).output(node)); } } - diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java index 1375e81e61..726e95d4da 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java @@ -18,25 +18,25 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import java.util.List; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + /** * Outputs a YAML file containing the AST meant for inspecting it. */ public class YamlPrinter { private static final int NUM_SPACES_FOR_INDENT = 4; + private final boolean outputNodeType; public YamlPrinter(boolean outputNodeType) { @@ -55,58 +55,41 @@ public void output(Node node, String name, int level, StringBuilder builder) { assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) - .collect(toList()); - + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); if (outputNodeType) builder.append(System.lineSeparator() + indent(level) + name + "(Type=" + metaModel.getTypeName() + "): "); else builder.append(System.lineSeparator() + indent(level) + name + ": "); - level++; for (PropertyMetaModel a : attributes) { builder.append(System.lineSeparator() + indent(level) + a.getName() + ": " + escapeValue(a.getValue(node).toString())); } - for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, sn.getName(), level, builder); } - for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { builder.append(System.lineSeparator() + indent(level) + sl.getName() + ": "); String slName = sl.getName(); slName = slName.endsWith("s") ? slName.substring(0, sl.getName().length() - 1) : slName; - for (Node nd : nl) - output(nd, "- " + slName, level + 1, builder); + for (Node nd : nl) output(nd, "- " + slName, level + 1, builder); } } } private String indent(int level) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < level; i++) - for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) - sb.append(" "); + for (int i = 0; i < level; i++) for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) sb.append(" "); return sb.toString(); } private String escapeValue(String value) { - return "\"" + value - .replace("\\", "\\\\") - .replaceAll("\"", "\\\\\"") - .replace("\n", "\\n") - .replace("\r", "\\r") - .replace("\f", "\\f") - .replace("\b", "\\b") - .replace("\t", "\\t") + "\""; + return "\"" + value.replace("\\", "\\\\").replaceAll("\"", "\\\\\"").replace("\n", "\\n").replace("\r", "\\r").replace("\f", "\\f").replace("\b", "\\b").replace("\t", "\\t") + "\""; } public static void print(Node node) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java index daafd13c00..921c6e7c45 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -30,6 +29,7 @@ import static com.github.javaparser.utils.CodeGenerationUtils.f; public class CsmAttribute implements CsmElement { + public ObservableProperty getProperty() { return property; } @@ -53,28 +53,30 @@ public void prettyPrint(Node node, SourcePrinter printer) { * @param tokenText Operator's token text */ public int getTokenType(Node node, String text, String tokenText) { - switch (property) { + switch(property) { case IDENTIFIER: return GeneratedJavaParserConstants.IDENTIFIER; - case TYPE: { - String expectedImage = "\"" + text.toLowerCase() + "\""; - for (int i=0;i process(c, printer)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java index 4e4b0afb2e..f0c84f2507 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -30,9 +29,13 @@ import java.util.List; public class CsmConditional implements CsmElement { + private final Condition condition; + private final List properties; + private final CsmElement thenElement; + private final CsmElement elseElement; public Condition getCondition() { @@ -45,7 +48,7 @@ public ObservableProperty getProperty() { } return properties.get(0); } - + public List getProperties() { return properties; } @@ -59,12 +62,10 @@ public CsmElement getElseElement() { } public enum Condition { - IS_EMPTY, - IS_NOT_EMPTY, - IS_PRESENT, - FLAG; - boolean evaluate(Node node, ObservableProperty property){ + IS_EMPTY, IS_NOT_EMPTY, IS_PRESENT, FLAG; + + boolean evaluate(Node node, ObservableProperty property) { if (this == IS_PRESENT) { return !property.isNullOrNotPresent(node); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java index 73ddc032c3..867e301c05 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -30,7 +29,8 @@ import java.util.Arrays; import java.util.List; -import static com.github.javaparser.TokenTypes.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.TokenTypes.spaceTokenKind; public interface CsmElement { @@ -96,7 +96,9 @@ static CsmElement semicolon() { return new CsmToken(GeneratedJavaParserConstants.SEMICOLON); } - static CsmElement comment() { return new CsmComment(); } + static CsmElement comment() { + return new CsmComment(); + } static CsmElement newline() { return newline(LineSeparator.SYSTEM); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java index 9170730d21..ce0dcb2b5b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java index 30a49983f2..596872d909 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -31,10 +30,15 @@ import java.util.Iterator; public class CsmList implements CsmElement { + private final ObservableProperty property; + private final CsmElement separatorPost; + private final CsmElement separatorPre; + private final CsmElement preceeding; + private final CsmElement following; public ObservableProperty getProperty() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java index 5418e7c6ed..e2bb1dfb4d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -32,6 +31,7 @@ * A group of elements that could be in any order. */ public class CsmMix implements CsmElement { + private List elements; public CsmMix(List elements) { @@ -55,11 +55,11 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmMix csmMix = (CsmMix) o; - return elements != null ? elements.equals(csmMix.elements) : csmMix.elements == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java index 5bb932f42d..1d080d02fd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -28,7 +27,5 @@ public class CsmNone implements CsmElement { @Override public void prettyPrint(Node node, SourcePrinter printer) { - } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java index 2144c3bff7..d55a9915e8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -40,7 +39,6 @@ public void prettyPrint(Node node, SourcePrinter printer) { if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -51,9 +49,8 @@ public void prettyPrint(Node node, SourcePrinter printer) { } } for (int i = 0; i < commentsAtEnd; i++) { - Comment c = (Comment)everything.get(everything.size() - commentsAtEnd + i); + Comment c = (Comment) everything.get(everything.size() - commentsAtEnd + i); CsmComment.process(c, printer); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java index a9bb3300d0..aed7b37106 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -28,6 +27,7 @@ import java.util.Objects; public class CsmSequence implements CsmElement { + private List elements; public CsmSequence(List elements) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java index a92f003384..fa9a92865b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmSingleReference implements CsmElement { + private final ObservableProperty property; public ObservableProperty getProperty() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java index 2b66ffcec4..c2f4e24ad8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -26,6 +25,7 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmString implements CsmElement { + private final ObservableProperty property; public CsmString(ObservableProperty property) { @@ -43,5 +43,4 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("CsmString(property:%s)", property); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java index ba86ff9af6..45ad100d1c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -26,6 +25,7 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmTextBlock implements CsmElement { + private final ObservableProperty property; public CsmTextBlock(ObservableProperty property) { @@ -36,7 +36,8 @@ public CsmTextBlock(ObservableProperty property) { public void prettyPrint(Node node, SourcePrinter printer) { // Note that values within TextBlocks ALWAYS have the \n line ending, per https://openjdk.java.net/jeps/378#1--Line-terminators printer.print("\"\"\"\n"); - printer.print(property.getValueAsStringAttribute(node)); // TODO: Confirm if we need to force this to use {@code \n} separators + // TODO: Confirm if we need to force this to use {@code \n} separators + printer.print(property.getValueAsStringAttribute(node)); printer.print("\"\"\""); } @@ -44,5 +45,4 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("CsmTextBlock(property:%s)", property); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java index bc3724e6eb..7f3803ff50 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -27,14 +26,19 @@ import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.utils.LineSeparator; -import static com.github.javaparser.TokenTypes.*; +import static com.github.javaparser.TokenTypes.isEndOfLineToken; +import static com.github.javaparser.TokenTypes.isWhitespaceButNotEndOfLine; public class CsmToken implements CsmElement { + private final int tokenType; + private String content; + private TokenContentCalculator tokenContentCalculator; public interface TokenContentCalculator { + String calculate(Node node); } @@ -55,9 +59,8 @@ public CsmToken(int tokenType) { if (content.startsWith("\"")) { content = content.substring(1, content.length() - 1); } - // Replace "raw" values with escaped textual counterparts (e.g. newlines {@code \r\n}) - // and "placeholder" values ({@code }) with their textual counterparts + // and "placeholder" values ({@code }) with their textual counterparts if (isEndOfLineToken(tokenType)) { // Use the unescaped version content = LineSeparator.lookupEscaped(this.content).get().asRawString(); @@ -92,13 +95,15 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmToken csmToken = (CsmToken) o; - - if (tokenType != csmToken.tokenType) return false; - if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) return false; + if (tokenType != csmToken.tokenType) + return false; + if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) + return false; return tokenContentCalculator != null ? tokenContentCalculator.equals(csmToken.tokenContentCalculator) : csmToken.tokenContentCalculator == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java index 0234eb156a..6ab7655a8d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java index 592da61bf4..f114589eab 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.printer.Stringable; @@ -27,7 +26,7 @@ class PrintingHelper { static String printToString(Object value) { if (value instanceof Stringable) { - return ((Stringable)value).asString(); + return ((Stringable) value).asString(); } if (value instanceof Enum) { return ((Enum) value).name().toLowerCase(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java index a60d0804b3..3a0c0b5e08 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java @@ -28,5 +28,4 @@ public interface ConfigurationOption { Boolean asBoolean(); T asValue(); - -} \ No newline at end of file +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java index 50070a7643..9896308302 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java @@ -17,7 +17,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; @@ -27,7 +26,9 @@ * An option is a pair of ConfigOption and a currentValue */ public class DefaultConfigurationOption implements ConfigurationOption { + ConfigOption configOption; + Object currentValue; public DefaultConfigurationOption(ConfigOption configOption) { @@ -42,7 +43,8 @@ public DefaultConfigurationOption(ConfigOption configOption, Object value) { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof DefaultConfigurationOption)) return false; + if (o == null || !(o instanceof DefaultConfigurationOption)) + return false; DefaultConfigurationOption other = (DefaultConfigurationOption) o; return configOption.equals(other.configOption); } @@ -61,8 +63,7 @@ public ConfigurationOption value(Object value) { this.currentValue = value; // verify the currentValue's type if (!(configOption.type.isAssignableFrom(value.getClass()))) { - throw new IllegalArgumentException( - String.format("%s is not an instance of %s", value, configOption.type.getName())); + throw new IllegalArgumentException(String.format("%s is not an instance of %s", value, configOption.type.getName())); } return this; } @@ -109,7 +110,6 @@ private T cast() { throw new IllegalArgumentException(String.format("The option %s has no currentValue", configOption.name())); if (configOption.type.isAssignableFrom(currentValue.getClass())) return (T) configOption.type.cast(currentValue); - throw new IllegalArgumentException( - String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); + throw new IllegalArgumentException(String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java index 1a2cc7f269..f62555a7a5 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java @@ -17,38 +17,38 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; +import com.github.javaparser.printer.Printer; +import com.github.javaparser.printer.configuration.Indentation.IndentType; +import com.github.javaparser.utils.Utils; + import java.util.Arrays; import java.util.HashSet; import java.util.Optional; import java.util.Set; -import com.github.javaparser.printer.Printer; -import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.utils.Utils; - /** * Configuration options for the {@link Printer}. */ public class DefaultPrinterConfiguration implements PrinterConfiguration { - + public enum ConfigOption { + /** * Order imports alphabetically */ - ORDER_IMPORTS(Boolean.class), + ORDER_IMPORTS(Boolean.class), /** * Print comments only. It can be combined with {@code PRINT_JAVADOC} to print regular comments and javadoc. */ - PRINT_COMMENTS(Boolean.class), + PRINT_COMMENTS(Boolean.class), /** * Print javadoc comments only. It can be combined with {@code PRINT_COMMENTS} to print regular javadoc and comments */ - PRINT_JAVADOC(Boolean.class), - SPACE_AROUND_OPERATORS(Boolean.class), - COLUMN_ALIGN_PARAMETERS(Boolean.class), + PRINT_JAVADOC(Boolean.class), + SPACE_AROUND_OPERATORS(Boolean.class), + COLUMN_ALIGN_PARAMETERS(Boolean.class), COLUMN_ALIGN_FIRST_METHOD_CHAIN(Boolean.class), /** * Indent the case when it is true, don't if false @@ -91,16 +91,16 @@ public enum ConfigOption { * Indentation proprerty */ INDENTATION(Indentation.class, new Indentation(IndentType.SPACES, 4)); - + Object defaultValue; - + Class type; - + // DefaultConfigurationOption without currentValue ConfigOption(Class clazz) { this.type = clazz; } - + // DefaultConfigurationOption with initial currentValue ConfigOption(Class clazz, Object value) { this.type = clazz; @@ -109,25 +109,15 @@ public enum ConfigOption { } this.defaultValue = value; } - - } - + // contains all available options // an option contained in the set is considered as activated - private Set defaultOptions = new HashSet<>(Arrays.asList( - new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), - new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), - new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), - new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), - new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), - new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), - new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue) - )); + private Set defaultOptions = new HashSet<>(Arrays.asList(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue))); public DefaultPrinterConfiguration() { } - + /* * add the specified option if it does not exist or replace the existing option */ @@ -137,7 +127,7 @@ public PrinterConfiguration addOption(ConfigurationOption option) { defaultOptions.add(option); return this; } - + /* * remove the specified option */ @@ -146,7 +136,7 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { defaultOptions.remove(option); return this; } - + /* * True if an option is activated */ @@ -154,13 +144,13 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { public boolean isActivated(ConfigurationOption option) { return defaultOptions.contains(option); } - + /* * returns the specified option */ @Override public Optional get(ConfigurationOption option) { - return defaultOptions.stream().filter(o-> o.equals(option)).findFirst(); + return defaultOptions.stream().filter(o -> o.equals(option)).findFirst(); } /** @@ -170,5 +160,4 @@ public Optional get(ConfigurationOption option) { public Set get() { return defaultOptions; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java index 1474b4bfc2..a30a92ca8f 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java @@ -17,27 +17,24 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; /** - * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). - * + * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). */ public class Indentation { - + public enum IndentType { + /** * Indent with spaces. */ SPACES(' ', 1), - /** * Indent with tabs as far as possible. * For proper aligning, the tab width is necessary and by default 4. */ TABS('\t', 4), - /** * Indent with tabs but align with spaces when wrapping and aligning * method call chains and method call parameters. @@ -60,11 +57,11 @@ public enum IndentType { * */ TABS_WITH_SPACE_ALIGN('\t', 4); - + private Character car; - + private int width; - + private IndentType(Character c, int width) { this.car = c; this.width = width; @@ -77,21 +74,20 @@ public Character getCar() { public int getWidth() { return width; } - } - + // default size - private static final int DEFAULT_SIZE = 4; - + private static final int DEFAULT_SIZE = 4; + // type of the indentation private IndentType type; - + // size of the indentation (define how many spaces or tabs is used to indent) private int size; - + // formatted indentation private String formattedIndentation = ""; - + /* * Creates an Indentation with a type and size */ @@ -100,14 +96,14 @@ public Indentation(IndentType type, int size) { this.size = size; format(); } - + /* * Creates an Indentation with the default size */ public Indentation(IndentType type) { this(type, DEFAULT_SIZE); } - + /* * set the size of the indentation (how many spaces or tabs?) */ @@ -116,11 +112,11 @@ public Indentation setSize(int size) { format(); return this; } - + public int getSize() { return size; } - + /* * set the type of the indentation (spaces, tabs...) */ @@ -129,7 +125,7 @@ public Indentation setType(IndentType type) { format(); return this; } - + public IndentType getType() { return type; } @@ -140,7 +136,7 @@ public IndentType getType() { public String getIndent() { return formattedIndentation; } - + // format the indentation string private void format() { StringBuilder indentString = new StringBuilder(); @@ -150,9 +146,9 @@ private void format() { } formattedIndentation = indentString.toString(); } - + @Override public String toString() { - return type.name() + " size=" + size ; + return type.name() + " size=" + size; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java index 06b9407b03..a8518da893 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java @@ -18,19 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; -import static com.github.javaparser.utils.Utils.assertNonNegative; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.assertPositive; +import com.github.javaparser.printer.PrettyPrinter; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; +import com.github.javaparser.printer.configuration.Indentation.IndentType; import java.util.Optional; import java.util.Set; -import com.github.javaparser.printer.PrettyPrinter; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation.IndentType; +import static com.github.javaparser.utils.Utils.*; /** * Configuration options for the {@link PrettyPrinter}. @@ -40,24 +37,23 @@ */ @Deprecated public class PrettyPrinterConfiguration implements PrinterConfiguration { - - + PrinterConfiguration wrappedConfiguration; - + /* * Default constructor */ public PrettyPrinterConfiguration() { this.wrappedConfiguration = new DefaultPrinterConfiguration(); } - + /* * returns the indentation parameters */ public Indentation getIndentation() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(); } - + public PrettyPrinterConfiguration setIndentation(Indentation indentation) { wrappedConfiguration.addOption(new DefaultConfigurationOption(ConfigOption.INDENTATION, indentation)); return this; @@ -112,8 +108,6 @@ public PrettyPrinterConfiguration setIndentType(IndentType indentType) { return this; } - - /** * Get the tab width for pretty aligning. * @deprecated (@see Indentation.size) @@ -144,7 +138,7 @@ public boolean isPrintComments() { public boolean isIgnoreComments() { return !wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)).isPresent(); } - + public boolean isSpaceAroundOperators() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)).isPresent(); } @@ -165,15 +159,12 @@ public boolean isIndentCaseInSwitch() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)).isPresent(); } - /** * When true, all comments will be printed, unless printJavadoc is false, then only line and block comments will be * printed. */ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { - wrappedConfiguration = printComments ? - addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); + wrappedConfiguration = printComments ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); return this; } @@ -181,40 +172,30 @@ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { * When true, Javadoc will be printed. */ public PrettyPrinterConfiguration setPrintJavadoc(boolean printJavadoc) { - wrappedConfiguration = printJavadoc ? - addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : - removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); + wrappedConfiguration = printJavadoc ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); return this; } /** * Set if there should be spaces between operators */ - public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators){ - wrappedConfiguration = spaceAroundOperators ? - addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); + public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators) { + wrappedConfiguration = spaceAroundOperators ? addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); return this; } public PrettyPrinterConfiguration setColumnAlignParameters(boolean columnAlignParameters) { - wrappedConfiguration = columnAlignParameters ? - addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); + wrappedConfiguration = columnAlignParameters ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); return this; } public PrettyPrinterConfiguration setColumnAlignFirstMethodChain(boolean columnAlignFirstMethodChain) { - wrappedConfiguration = columnAlignFirstMethodChain ? - addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : - removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); + wrappedConfiguration = columnAlignFirstMethodChain ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); return this; } public PrettyPrinterConfiguration setIndentCaseInSwitch(boolean indentInSwitch) { - wrappedConfiguration = indentInSwitch ? - addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : - removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); + wrappedConfiguration = indentInSwitch ? addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); return this; } @@ -234,13 +215,10 @@ public PrettyPrinterConfiguration setEndOfLineCharacter(String endOfLineCharacte * When true, orders imports by alphabetically. */ public PrettyPrinterConfiguration setOrderImports(boolean orderImports) { - wrappedConfiguration = orderImports ? - addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); + wrappedConfiguration = orderImports ? addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); return this; } - - public int getMaxEnumConstantsToAlignHorizontally() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY)).get().asInteger(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java index dd50a93829..448cd9fff1 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java @@ -13,7 +13,7 @@ public interface PrinterConfiguration { * add or update an option */ PrinterConfiguration addOption(ConfigurationOption option); - + /* * Remove an option */ @@ -33,5 +33,4 @@ public interface PrinterConfiguration { * returns all activated options */ Set get(); - -} \ No newline at end of file +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java index 3b321de77c..afb8d93cb4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Added implements DifferenceElement { + private final CsmElement element; Added(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Added added = (Added) o; - return element.equals(added.element); } @@ -68,9 +68,13 @@ public boolean isRemoved() { return false; } - public boolean isIndent() { return element instanceof CsmIndent; } + public boolean isIndent() { + return element instanceof CsmIndent; + } - public boolean isUnindent() { return element instanceof CsmUnindent; } + public boolean isUnindent() { + return element instanceof CsmUnindent; + } public TextElement toTextElement() { if (element instanceof LexicalDifferenceCalculator.CsmChild) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java index 131144a46c..c0666b5634 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.Range; @@ -31,6 +30,7 @@ * Represent the position of a child node in the NodeText of its parent. */ class ChildTextElement extends TextElement { + private final Node child; ChildTextElement(Node child) { @@ -61,13 +61,12 @@ NodeText getNodeTextForWrappedNode() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ChildTextElement that = (ChildTextElement) o; - return child.equals(that.child); - } @Override @@ -99,17 +98,17 @@ public boolean isNewline() { public boolean isComment() { return child instanceof Comment; } - + @Override public boolean isSeparator() { return false; } - + @Override public boolean isIdentifier() { return false; } - + @Override public boolean isPrimitive() { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 14149f8bce..23d300dee1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -18,23 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.GeneratedJavaParserConstants.LBRACE; -import static com.github.javaparser.GeneratedJavaParserConstants.RBRACE; -import static com.github.javaparser.GeneratedJavaParserConstants.SPACE; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Optional; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.JavaToken; import com.github.javaparser.JavaToken.Kind; @@ -44,13 +29,13 @@ import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.type.Type; -import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; +import java.util.*; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; + /** * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements * to remove or to add and follow by another sequence of elements. @@ -62,26 +47,29 @@ public class Difference { public static final int STANDARD_INDENTATION_SIZE = 4; private final NodeText nodeText; + private final Node node; private final List diffElements; + private final List originalElements; + private int originalIndex = 0; + private int diffIndex = 0; private final List indentation; + private boolean addedIndentation = false; Difference(List diffElements, NodeText nodeText, Node node) { if (nodeText == null) { throw new NullPointerException("nodeText can not be null"); } - this.nodeText = nodeText; this.node = node; this.diffElements = diffElements; this.originalElements = nodeText.getElements(); - this.indentation = LexicalPreservingPrinter.findIndentation(node); } @@ -93,7 +81,7 @@ private List processIndentation(List indentation, res.clear(); afterNl = true; } else { - if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement)e).getTokenKind())) { + if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement) e).getTokenKind())) { res.add(e); } else { afterNl = false; @@ -159,21 +147,17 @@ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { void apply() { extractReshuffledDiffElements(diffElements); Map removedGroups = combineRemovedElementsToRemovedGroups(); - do { boolean isLeftOverDiffElement = applyLeftOverDiffElements(); boolean isLeftOverOriginalElement = applyLeftOverOriginalElements(); - - if (!isLeftOverDiffElement && !isLeftOverOriginalElement){ + if (!isLeftOverDiffElement && !isLeftOverOriginalElement) { DifferenceElement diffElement = diffElements.get(diffIndex); - if (diffElement instanceof Added) { applyAddedDiffElement((Added) diffElement); } else { TextElement originalElement = originalElements.get(originalIndex); boolean originalElementIsChild = originalElement instanceof ChildTextElement; boolean originalElementIsToken = originalElement instanceof TokenTextElement; - if (diffElement instanceof Kept) { applyKeptDiffElement((Kept) diffElement, originalElement, originalElementIsChild, originalElementIsToken); } else if (diffElement instanceof Removed) { @@ -191,14 +175,11 @@ private boolean applyLeftOverOriginalElements() { boolean isLeftOverElement = false; if (diffIndex >= diffElements.size() && originalIndex < originalElements.size()) { TextElement originalElement = originalElements.get(originalIndex); - if (originalElement.isWhiteSpaceOrComment()) { originalIndex++; } else { - throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " - + this + " " + originalElement); + throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " + this + " " + originalElement); } - isLeftOverElement = true; } return isLeftOverElement; @@ -210,26 +191,21 @@ private boolean applyLeftOverDiffElements() { DifferenceElement diffElement = diffElements.get(diffIndex); if (diffElement instanceof Kept) { Kept kept = (Kept) diffElement; - if (kept.isWhiteSpaceOrComment() || kept.isIndent() || kept.isUnindent()) { diffIndex++; } else { - throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " - + nodeText + ". Difference: " + this); + throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " + nodeText + ". Difference: " + this); } } else if (diffElement instanceof Added) { Added addedElement = (Added) diffElement; - nodeText.addElement(originalIndex, addedElement.toTextElement()); originalIndex++; diffIndex++; } else { throw new UnsupportedOperationException(diffElement.getClass().getSimpleName()); } - isLeftOverElement = true; } - return isLeftOverElement; } @@ -238,17 +214,13 @@ private void extractReshuffledDiffElements(List diffElements) DifferenceElement diffElement = diffElements.get(index); if (diffElement instanceof Reshuffled) { Reshuffled reshuffled = (Reshuffled) diffElement; - // First, let's see how many tokens we need to attribute to the previous version of the of the CsmMix CsmMix elementsFromPreviousOrder = reshuffled.getPreviousOrder(); CsmMix elementsFromNextOrder = reshuffled.getNextOrder(); - // This contains indexes from elementsFromNextOrder to indexes from elementsFromPreviousOrder Map correspondanceBetweenNextOrderAndPreviousOrder = getCorrespondanceBetweenNextOrderAndPreviousOrder(elementsFromPreviousOrder, elementsFromNextOrder); - // We now find out which Node Text elements corresponds to the elements in the original CSM List nodeTextIndexOfPreviousElements = findIndexOfCorrespondingNodeTextElement(elementsFromPreviousOrder.getElements(), nodeText, originalIndex, node); - Map nodeTextIndexToPreviousCSMIndex = new HashMap<>(); for (int i = 0; i < nodeTextIndexOfPreviousElements.size(); i++) { int value = nodeTextIndexOfPreviousElements.get(i); @@ -257,11 +229,9 @@ private void extractReshuffledDiffElements(List diffElements) } } int lastNodeTextIndex = nodeTextIndexOfPreviousElements.stream().max(Integer::compareTo).orElse(-1); - // Elements to be added at the end List elementsToBeAddedAtTheEnd = new LinkedList<>(); List nextOrderElements = elementsFromNextOrder.getElements(); - Map> elementsToAddBeforeGivenOriginalCSMElement = new HashMap<>(); for (int ni = 0; ni < nextOrderElements.size(); ni++) { // If it has a mapping, then it is kept @@ -284,22 +254,18 @@ private void extractReshuffledDiffElements(List diffElements) } } } - // We go over the original node text elements, in the order they appear in the NodeText. // Considering an original node text element (ONE) // * we verify if it corresponds to a CSM element. If it does not we just move on, otherwise - // we find the correspond OCE (Original CSM Element) + // we find the correspond OCE (Original CSM Element) // * we first add new elements that are marked to be added before OCE // * if OCE is marked to be present also in the "after" CSM we add a kept element, - // otherwise we add a removed element - + // otherwise we add a removed element // Remove the whole Reshuffled element diffElements.remove(index); - int diffElIterator = index; if (lastNodeTextIndex != -1) { for (int ntIndex = originalIndex; ntIndex <= lastNodeTextIndex; ntIndex++) { - if (nodeTextIndexToPreviousCSMIndex.containsKey(ntIndex)) { int indexOfOriginalCSMElement = nodeTextIndexToPreviousCSMIndex.get(ntIndex); if (elementsToAddBeforeGivenOriginalCSMElement.containsKey(indexOfOriginalCSMElement)) { @@ -307,7 +273,6 @@ private void extractReshuffledDiffElements(List diffElements) diffElements.add(diffElIterator++, new Added(elementToAdd)); } } - CsmElement originalCSMElement = elementsFromPreviousOrder.getElements().get(indexOfOriginalCSMElement); boolean toBeKept = correspondanceBetweenNextOrderAndPreviousOrder.containsValue(indexOfOriginalCSMElement); if (toBeKept) { @@ -319,7 +284,6 @@ private void extractReshuffledDiffElements(List diffElements) // else we have a simple node text element, without associated csm element, just keep ignore it } } - // Finally we look for the remaining new elements that were not yet added and // add all of them for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) { @@ -344,25 +308,21 @@ private void extractReshuffledDiffElements(List diffElements) */ private Map combineRemovedElementsToRemovedGroups() { Map> removedElementsMap = groupConsecutiveRemovedElements(); - List removedGroups = new ArrayList<>(); for (Map.Entry> entry : removedElementsMap.entrySet()) { removedGroups.add(RemovedGroup.of(entry.getKey(), entry.getValue())); } - Map map = new HashMap<>(); - for (RemovedGroup removedGroup : removedGroups){ + for (RemovedGroup removedGroup : removedGroups) { for (Removed index : removedGroup) { map.put(index, removedGroup); } } - return map; } private Map> groupConsecutiveRemovedElements() { Map> removedElementsMap = new HashMap<>(); - Integer firstElement = null; for (int i = 0; i < diffElements.size(); i++) { DifferenceElement diffElement = diffElements.get(i); @@ -370,9 +330,7 @@ private Map> groupConsecutiveRemovedElements() { if (firstElement == null) { firstElement = i; } - - removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()) - .add((Removed) diffElement); + removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()).add((Removed) diffElement); } else { firstElement = null; } @@ -394,30 +352,23 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } else { nodeText.removeElement(originalIndex); - - if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1) instanceof Added)) - && !removedGroup.isACompleteLine()) { + if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1) instanceof Added)) && !removedGroup.isACompleteLine()) { originalIndex = considerEnforcingIndentation(nodeText, originalIndex); } // If in front we have one space and before also we had space let's drop one space if (originalElements.size() > originalIndex && originalIndex > 0) { - if (originalElements.get(originalIndex).isWhiteSpace() - && originalElements.get(originalIndex - 1).isWhiteSpace()) { + if (originalElements.get(originalIndex).isWhiteSpace() && originalElements.get(originalIndex - 1).isWhiteSpace()) { // However we do not want to do that when we are about to adding or removing elements if ((diffIndex + 1) == diffElements.size() || (diffElements.get(diffIndex + 1) instanceof Kept)) { originalElements.remove(originalIndex--); } } } - diffIndex++; } - } else if (removed.isToken() && originalElementIsToken && - (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() - // handle EOLs separately as their token kind might not be equal. This is because the 'removed' - // element always has the current operating system's EOL as type - || (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() - && removed.isNewLine()))) { + } else if (removed.isToken() && originalElementIsToken && (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // handle EOLs separately as their token kind might not be equal. This is because the 'removed' + // element always has the current operating system's EOL as type + (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() && removed.isNewLine()))) { nodeText.removeElement(originalIndex); diffIndex++; } else if (originalElementIsToken && originalElement.isWhiteSpaceOrComment()) { @@ -439,7 +390,6 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } else { throw new UnsupportedOperationException("removed " + removed.getElement() + " vs " + originalElement); } - cleanTheLineOfLeftOverSpace(removedGroup, removed); } @@ -451,13 +401,9 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo // if all elements were already processed there is nothing to do return; } - - if (!removedGroup.isProcessed() - && removedGroup.getLastElement() == removed - && removedGroup.isACompleteLine()) { + if (!removedGroup.isProcessed() && removedGroup.getLastElement() == removed && removedGroup.isACompleteLine()) { Integer lastElementIndex = removedGroup.getLastElementIndex(); Optional indentation = removedGroup.getIndentation(); - if (indentation.isPresent() && !isReplaced(lastElementIndex)) { for (int i = 0; i < indentation.get(); i++) { if (originalElements.get(originalIndex).isSpaceOrTab()) { @@ -470,7 +416,6 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo } } } - // Mark RemovedGroup as processed removedGroup.processed(); } @@ -482,7 +427,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) { if (originalElement.isComment()) { originalIndex++; - } else if (kept.isChild() && ((CsmChild)kept.getElement()).getChild() instanceof Comment ) { + } else if (kept.isChild() && ((CsmChild) kept.getElement()).getChild() instanceof Comment) { diffIndex++; } else if (kept.isChild() && originalElementIsChild) { diffIndex++; @@ -515,7 +460,6 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea } } else if (kept.isToken() && originalElementIsToken) { TokenTextElement originalTextToken = (TokenTextElement) originalElement; - if (kept.getTokenType() == originalTextToken.getTokenKind()) { originalIndex++; diffIndex++; @@ -547,7 +491,6 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea // Nothing to do, beside considering indentation // However we want to consider the case in which the indentation was not applied, like when we have // just a left brace followed by space - diffIndex++; if (!openBraceWasOnSameLine()) { for (int i = 0; i < STANDARD_INDENTATION_SIZE && originalIndex >= 1 && nodeText.getTextElement(originalIndex - 1).isSpaceOrTab(); i++) { @@ -589,9 +532,11 @@ private boolean isNodeWithTypeArguments(DifferenceElement element) { * @return the number of token to skip in originalElements list */ private int getIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator) { - int step = 0; // number of token to skip + // number of token to skip + int step = 0; Optional next = element.getToken().getNextToken(); - if (!next.isPresent()) return step; + if (!next.isPresent()) + return step; // because there is a token, first we need to increment the number of token to skip step++; // manage nested diamond operators by incrementing the level on LT token and decrementing on GT @@ -631,9 +576,7 @@ private boolean openBraceWasOnSameLine() { } private boolean wasSpaceBetweenBraces() { - return nodeText.getTextElement(originalIndex).isToken(RBRACE) - && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) - && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); + return nodeText.getTextElement(originalIndex).isToken(RBRACE) && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); } private boolean doWeHaveLeftBraceFollowedBySpace(int index) { @@ -654,7 +597,7 @@ private int rewindSpace(int index) { private boolean nextIsRightBrace(int index) { List elements = originalElements.subList(index, originalElements.size()); - for(TextElement element : elements) { + for (TextElement element : elements) { if (!element.isSpaceOrTab()) { return element.isToken(RBRACE); } @@ -664,7 +607,7 @@ private boolean nextIsRightBrace(int index) { private void applyAddedDiffElement(Added added) { if (added.isIndent()) { - for (int i=0;i 0) && originalElements.get(originalIndex - 1).isNewline(); @@ -687,9 +629,7 @@ private void applyAddedDiffElement(Added added) { List elements = processIndentation(indentation, originalElements.subList(0, originalIndex - 1)); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); for (TextElement e : elements) { - if (!nextIsRightBrace - && e instanceof TokenTextElement - && originalElements.get(originalIndex).isToken(((TokenTextElement)e).getTokenKind())) { + if (!nextIsRightBrace && e instanceof TokenTextElement && originalElements.get(originalIndex).isToken(((TokenTextElement) e).getTokenKind())) { originalIndex++; } else { nodeText.addElement(originalIndex++, e); @@ -719,7 +659,6 @@ private void applyAddedDiffElement(Added added) { } } } - if (!used) { // Handling trailing comments boolean sufficientTokensRemainToSkip = nodeText.numberOfElements() > originalIndex + 2; @@ -728,37 +667,41 @@ private void applyAddedDiffElement(Added added) { boolean currentIsNewline = nodeText.getTextElement(originalIndex).isNewline(); boolean isFirstElement = originalIndex == 0; boolean previousIsWhiteSpace = originalIndex > 0 && nodeText.getTextElement(originalIndex - 1).isWhiteSpace(); - if (sufficientTokensRemainToSkip && currentIsAComment) { // Need to get behind the comment: - originalIndex += 2; // FIXME: Why 2? This comment and the next newline? - nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment - + // FIXME: Why 2? This comment and the next newline? + originalIndex += 2; + // Defer originalIndex increment + nodeText.addElement(originalIndex, addedTextElement); // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - originalIndex++; // Now we can increment + // Now we can increment + originalIndex++; } else if (currentIsNewline && previousIsAComment) { /* * Manage the case where we want to add an element, after an expression which is followed by a comment on the same line. * This is not the same case as the one who handles the trailing comments, because in this case the node text element is a new line (not a comment) * For example : {@code private String a; // this is a } */ - originalIndex++; // Insert after the new line which follows this comment. - + // Insert after the new line which follows this comment. + originalIndex++; // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment - originalIndex++; // Now we can increment. + // Defer originalIndex increment + nodeText.addElement(originalIndex, addedTextElement); + // Now we can increment. + originalIndex++; } else if (currentIsNewline && addedTextElement.isChild()) { // here we want to place the new child element after the current new line character. - // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) + // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) // or if the previous character is a space (it could be the case if we want to replace a statement) // Example 1 : if we insert a statement (a duplicated method call expression ) after this one value();\n\n // we want to have this result value();\n value();\n not value();\n \nvalue(); - // Example 2 : if we want to insert a statement after this one \n we want to have value();\n - // not \nvalue(); --> this case appears on member replacement for example + // Example 2 : if we want to insert a statement after this one \n we want to have value();\n + // not \nvalue(); --> this case appears on member replacement for example if (!isPreviousElementNewline && !isFirstElement && !previousIsWhiteSpace) { - originalIndex++; // Insert after the new line + // Insert after the new line + originalIndex++; } nodeText.addElement(originalIndex, addedTextElement); originalIndex++; @@ -767,7 +710,6 @@ private void applyAddedDiffElement(Added added) { originalIndex++; } } - if (addedTextElement.isNewline()) { boolean followedByUnindent = isFollowedByUnindent(diffElements, diffIndex); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); @@ -776,7 +718,6 @@ private void applyAddedDiffElement(Added added) { originalIndex = adjustIndentation(indentation, nodeText, originalIndex, followedByUnindent); } } - diffIndex++; } @@ -786,65 +727,50 @@ private String tokenDescription(int kind) { private Map getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder) { Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); - List nextOrderElements = elementsFromNextOrder.getElements(); List previousOrderElements = elementsFromPreviousOrder.getElements(); WrappingRangeIterator piNext = new WrappingRangeIterator(previousOrderElements.size()); - for (int ni = 0; ni < nextOrderElements.size(); ni++) { boolean found = false; CsmElement ne = nextOrderElements.get(ni); - for (int counter = 0; counter < previousOrderElements.size() && !found; counter++) { Integer pi = piNext.next(); CsmElement pe = previousOrderElements.get(pi); - if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) - && DifferenceElementCalculator.matching(ne, pe)) { + if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) && DifferenceElementCalculator.matching(ne, pe)) { found = true; correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi); } } } - return correspondanceBetweenNextOrderAndPreviousOrder; } private boolean isFollowedByUnindent(List diffElements, int diffIndex) { - return (diffIndex + 1) < diffElements.size() - && diffElements.get(diffIndex + 1).isAdded() - && diffElements.get(diffIndex + 1).getElement() instanceof CsmUnindent; + return (diffIndex + 1) < diffElements.size() && diffElements.get(diffIndex + 1).isAdded() && diffElements.get(diffIndex + 1).getElement() instanceof CsmUnindent; } private List findIndexOfCorrespondingNodeTextElement(List elements, NodeText nodeText, int startIndex, Node node) { List correspondingIndices = new ArrayList<>(); for (ListIterator csmElementListIterator = elements.listIterator(); csmElementListIterator.hasNext(); ) { - int previousCsmElementIndex = csmElementListIterator.previousIndex(); CsmElement csmElement = csmElementListIterator.next(); int nextCsmElementIndex = csmElementListIterator.nextIndex(); - Map potentialMatches = new EnumMap<>(MatchClassification.class); - for (int i = startIndex; i < nodeText.getElements().size(); i++){ + for (int i = startIndex; i < nodeText.getElements().size(); i++) { if (!correspondingIndices.contains(i)) { TextElement textElement = nodeText.getTextElement(i); - boolean isCorresponding = isCorrespondingElement(textElement, csmElement, node); - if (isCorresponding) { boolean hasSamePreviousElement = false; if (i > 0 && previousCsmElementIndex > -1) { TextElement previousTextElement = nodeText.getTextElement(i - 1); - hasSamePreviousElement = isCorrespondingElement(previousTextElement, elements.get(previousCsmElementIndex), node); } - boolean hasSameNextElement = false; if (i < nodeText.getElements().size() - 1 && nextCsmElementIndex < elements.size()) { TextElement nextTextElement = nodeText.getTextElement(i + 1); - hasSameNextElement = isCorrespondingElement(nextTextElement, elements.get(nextCsmElementIndex), node); } - if (hasSamePreviousElement && hasSameNextElement) { potentialMatches.putIfAbsent(MatchClassification.ALL, i); } else if (hasSamePreviousElement) { @@ -859,22 +785,19 @@ private List findIndexOfCorrespondingNodeTextElement(List e } } } - // Prioritize the matches from best to worst - Optional bestMatchKey = potentialMatches.keySet().stream() - .min(Comparator.comparing(MatchClassification::getPriority)); - + Optional bestMatchKey = potentialMatches.keySet().stream().min(Comparator.comparing(MatchClassification::getPriority)); if (bestMatchKey.isPresent()) { correspondingIndices.add(potentialMatches.get(bestMatchKey.get())); } else { correspondingIndices.add(-1); } } - return correspondingIndices; } private enum MatchClassification { + ALL(1), PREVIOUS_AND_SAME(2), NEXT_AND_SAME(3), SAME_ONLY(4), ALMOST(5); private final int priority; @@ -890,21 +813,20 @@ int getPriority() { private boolean isCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) { if (csmElement instanceof CsmToken) { - CsmToken csmToken = (CsmToken)csmElement; + CsmToken csmToken = (CsmToken) csmElement; if (textElement instanceof TokenTextElement) { - TokenTextElement tokenTextElement = (TokenTextElement)textElement; + TokenTextElement tokenTextElement = (TokenTextElement) textElement; return tokenTextElement.getTokenKind() == csmToken.getTokenType() && tokenTextElement.getText().equals(csmToken.getContent(node)); } } else if (csmElement instanceof CsmChild) { - CsmChild csmChild = (CsmChild)csmElement; + CsmChild csmChild = (CsmChild) csmElement; if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement)textElement; + ChildTextElement childTextElement = (ChildTextElement) textElement; return childTextElement.getChild() == csmChild.getChild(); } } else { throw new UnsupportedOperationException(); } - return false; } @@ -912,7 +834,7 @@ private boolean isAlmostCorrespondingElement(TextElement textElement, CsmElement if (isCorrespondingElement(textElement, csmElement, node)) { return false; } - return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken)csmElement).isWhiteSpace(); + return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken) csmElement).isWhiteSpace(); } private int adjustIndentation(List indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) { @@ -923,7 +845,7 @@ private int adjustIndentation(List indentation, NodeText nodeT indentationAdj = indentationAdj.subList(0, Math.max(0, indentationAdj.size() - STANDARD_INDENTATION_SIZE)); } for (TextElement e : indentationAdj) { - if ((nodeTextIndex< nodeText.getElements().size()) && nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { + if ((nodeTextIndex < nodeText.getElements().size()) && nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { nodeTextIndex++; } else { nodeText.getElements().add(nodeTextIndex++, e); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java index 8d68a3ea82..2998317736 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java @@ -18,12 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; public interface DifferenceElement { + static DifferenceElement added(CsmElement element) { return new Added(element); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index 803119e894..7331c0acff 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -18,51 +18,49 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; -import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + class DifferenceElementCalculator { - + // internally keep track of a node position in a List public static class ChildPositionInfo { + Node node; + Integer position; + ChildPositionInfo(Node node, Integer position) { this.node = node; this.position = position; } + @Override public boolean equals(Object other) { - if ( other == null || !(other instanceof ChildPositionInfo)) + if (other == null || !(other instanceof ChildPositionInfo)) return false; - ChildPositionInfo cpi = (ChildPositionInfo)other; - // verify that the node content and the position are equal + ChildPositionInfo cpi = (ChildPositionInfo) other; + // verify that the node content and the position are equal // because we can have nodes with the same content but in different lines // in this case we consider that nodes are not equals - return this.node.equals(cpi.node) - && this.node.getRange().isPresent() && cpi.node.getRange().isPresent() - && this.node.getRange().get().contains(cpi.node.getRange().get()); + return this.node.equals(cpi.node) && this.node.getRange().isPresent() && cpi.node.getRange().isPresent() && this.node.getRange().get().contains(cpi.node.getRange().get()); } + @Override public int hashCode() { return node.hashCode() + position.hashCode(); } } - + static boolean matching(CsmElement a, CsmElement b) { if (a instanceof CsmChild) { if (b instanceof CsmChild) { @@ -76,7 +74,7 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { @@ -84,8 +82,8 @@ static boolean matching(CsmElement a, CsmElement b) { // Tokens are described by their type AND their content // and TokenContentCalculator. By using .equals(), all // three values are compared. - CsmToken childA = (CsmToken)a; - CsmToken childB = (CsmToken)b; + CsmToken childA = (CsmToken) a; + CsmToken childB = (CsmToken) b; return childA.equals(childB); } else if (b instanceof CsmChild) { return false; @@ -94,14 +92,14 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmIndent) { return b instanceof CsmIndent; } else if (a instanceof CsmUnindent) { return b instanceof CsmUnindent; } - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } private static boolean replacement(CsmElement a, CsmElement b) { @@ -116,18 +114,18 @@ private static boolean replacement(CsmElement a, CsmElement b) { } else if (b instanceof CsmToken) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { - CsmToken childA = (CsmToken)a; - CsmToken childB = (CsmToken)b; + CsmToken childA = (CsmToken) a; + CsmToken childB = (CsmToken) b; return childA.getTokenType() == childB.getTokenType(); } else if (b instanceof CsmChild) { return false; } } - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } /** @@ -135,10 +133,10 @@ private static boolean replacement(CsmElement a, CsmElement b) { */ private static List findChildrenPositions(LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel) { List positions = new ArrayList<>(); - for (int i=0;i findChildrenPositions(LexicalDifferenceCa static List calculate(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { // For performance reasons we use the positions of matching children // to guide the calculation of the difference - // + // // Suppose we have: - // qwerty[A]uiop - // qwer[A]uiop - // + // qwerty[A]uiop + // qwer[A]uiop + // // with [A] being a child and lowercase letters being tokens - // + // // We would calculate the Difference between "qwerty" and "qwer" then we know the A is kept, and then we // would calculate the difference between "uiop" and "uiop" - List childrenInOriginal = findChildrenPositions(original); List childrenInAfter = findChildrenPositions(after); - List commonChildren = new ArrayList<>(childrenInOriginal); commonChildren.retainAll(childrenInAfter); - List elements = new LinkedList<>(); - int originalIndex = 0; int afterIndex = 0; int commonChildrenIndex = 0; while (commonChildrenIndex < commonChildren.size()) { ChildPositionInfo child = commonChildren.get(commonChildrenIndex++); // search the position of the node "child" in the original list of cms element - int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); + int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); // search the position of the node "child" in the modified list of cms element - int posOfNextChildInAfter = childrenInAfter.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); - + int posOfNextChildInAfter = childrenInAfter.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) { elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter))); } @@ -186,7 +179,6 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS originalIndex = posOfNextChildInOriginal + 1; afterIndex = posOfNextChildInAfter + 1; } - if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) { elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size()))); } @@ -211,8 +203,7 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, boolean dealtWith = false; if (removedElement instanceof CsmChild) { CsmChild removedChild = (CsmChild) removedElement; - if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && - removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { + if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { NodeText nodeTextForChild = LexicalPreservingPrinter.getOrCreateNodeText(removedChild.getChild()); considerRemoval(nodeTextForChild, elements); originalIndex++; @@ -226,16 +217,12 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, return originalIndex; } - private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, - LexicalDifferenceCalculator.CalculatedSyntaxModel after) { + private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { List elements = new LinkedList<>(); - int originalIndex = 0; int afterIndex = 0; - // We move through the two CalculatedSyntaxModel, moving both forward when we have a match // and moving just one side forward when we have an element kept or removed - do { if (originalIndex < original.elements.size() && afterIndex >= after.elements.size()) { CsmElement removedElement = original.elements.get(originalIndex); @@ -246,13 +233,12 @@ private static List calculateImpl(LexicalDifferenceCalculator } else { CsmElement nextOriginal = original.elements.get(originalIndex); CsmElement nextAfter = after.elements.get(afterIndex); - if ((nextOriginal instanceof CsmMix) && (nextAfter instanceof CsmMix)) { if (((CsmMix) nextAfter).getElements().equals(((CsmMix) nextOriginal).getElements())) { // No reason to deal with a reshuffled, we are just going to keep everything as it is ((CsmMix) nextAfter).getElements().forEach(el -> elements.add(new Kept(el))); } else { - elements.add(new Reshuffled((CsmMix)nextOriginal, (CsmMix)nextAfter)); + elements.add(new Reshuffled((CsmMix) nextOriginal, (CsmMix) nextAfter)); } originalIndex++; afterIndex++; @@ -271,7 +257,6 @@ private static List calculateImpl(LexicalDifferenceCalculator if (cost(addingElements) > 0) { removingElements = calculate(original.from(originalIndex + 1), after.from(afterIndex)); } - if (removingElements == null || cost(removingElements) > cost(addingElements)) { elements.add(new Added(nextAfter)); afterIndex++; @@ -282,7 +267,6 @@ private static List calculateImpl(LexicalDifferenceCalculator } } } while (originalIndex < original.elements.size() || afterIndex < after.elements.size()); - return elements; } @@ -290,7 +274,6 @@ private static long cost(List elements) { return elements.stream().filter(e -> !(e instanceof Kept)).count(); } - /** * Remove from the difference all the elements related to indentation. * This is mainly intended for test purposes. diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java index 0f8dfae4e9..c1d1a90f21 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.TokenTypes; @@ -29,6 +28,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Kept implements DifferenceElement { + private final CsmElement element; Kept(CsmElement element) { @@ -42,11 +42,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Kept kept = (Kept) o; - return element.equals(kept.element); } @@ -65,7 +65,6 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } - throw new IllegalStateException("Kept is not a " + CsmToken.class.getSimpleName()); } @@ -74,29 +73,35 @@ public boolean isAdded() { return false; } - public boolean isIndent() { return element instanceof CsmIndent; } + public boolean isIndent() { + return element instanceof CsmIndent; + } - public boolean isUnindent() { return element instanceof CsmUnindent; } + public boolean isUnindent() { + return element instanceof CsmUnindent; + } - public boolean isToken() { return element instanceof CsmToken; } + public boolean isToken() { + return element instanceof CsmToken; + } - public boolean isChild() { return element instanceof LexicalDifferenceCalculator.CsmChild; } + public boolean isChild() { + return element instanceof LexicalDifferenceCalculator.CsmChild; + } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } - return false; } public boolean isWhiteSpace() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } - return false; } @@ -105,16 +110,14 @@ public boolean isWhiteSpaceOrComment() { CsmToken csmToken = (CsmToken) element; return TokenTypes.isWhitespaceOrComment(csmToken.getTokenType()); } - return false; } public boolean isNewLine() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } - return false; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java index 0a07dba48f..f989de5a80 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; @@ -31,23 +30,13 @@ import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.Stringable; import com.github.javaparser.printer.SourcePrinter; +import com.github.javaparser.printer.Stringable; import com.github.javaparser.printer.concretesyntaxmodel.*; -import com.github.javaparser.printer.lexicalpreservation.changes.Change; -import com.github.javaparser.printer.lexicalpreservation.changes.ListAdditionChange; -import com.github.javaparser.printer.lexicalpreservation.changes.ListRemovalChange; -import com.github.javaparser.printer.lexicalpreservation.changes.ListReplacementChange; -import com.github.javaparser.printer.lexicalpreservation.changes.NoChange; -import com.github.javaparser.printer.lexicalpreservation.changes.PropertyChange; +import com.github.javaparser.printer.lexicalpreservation.changes.*; import com.github.javaparser.utils.LineSeparator; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; +import java.util.*; import static com.github.javaparser.TokenTypes.eolTokenKind; @@ -58,6 +47,7 @@ class LexicalDifferenceCalculator { * with no condition, no lists, just tokens and node children. */ static class CalculatedSyntaxModel { + final List elements; CalculatedSyntaxModel(List elements) { @@ -70,9 +60,7 @@ public CalculatedSyntaxModel from(int index) { @Override public String toString() { - return "CalculatedSyntaxModel{" + - "elements=" + elements + - '}'; + return "CalculatedSyntaxModel{" + "elements=" + elements + '}'; } CalculatedSyntaxModel sub(int start, int end) { @@ -85,6 +73,7 @@ void removeIndentationElements() { } static class CsmChild implements CsmElement { + private final Node child; public Node getChild() { @@ -102,16 +91,16 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public String toString() { - return "child(" + child.getClass().getSimpleName()+")"; + return "child(" + child.getClass().getSimpleName() + ")"; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmChild csmChild = (CsmChild) o; - return child.equals(csmChild.child); } @@ -134,13 +123,10 @@ List calculateListAdditionDifference(ObservableProperty obser CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); CalculatedSyntaxModel after = calculatedSyntaxModelAfterListAddition(element, observableProperty, nodeList, index, nodeAdded); - List differenceElements = DifferenceElementCalculator.calculate(original, after); - // Set the line separator character tokens LineSeparator lineSeparator = container.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); replaceEolTokens(differenceElements, lineSeparator); - return differenceElements; } @@ -195,10 +181,10 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List nodeList; if (rawValue instanceof Optional) { - Optional optional = (Optional)rawValue; + Optional optional = (Optional) rawValue; if (optional.isPresent()) { if (!(optional.get() instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + optional.get().getClass().getCanonicalName()); @@ -256,7 +242,6 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List collection = (Collection) change.getValue(csmList.getProperty(), node); if (!collection.isEmpty()) { calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change); - boolean first = true; for (Iterator it = collection.iterator(); it.hasNext(); ) { if (!first) { @@ -272,7 +256,7 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List mixElements = new LinkedList<>(); csmMix.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, mixElements, change)); elements.add(new CsmMix(mixElements)); } else if (csm instanceof CsmChild) { elements.add(csm); } else { - throw new UnsupportedOperationException(csm.getClass().getSimpleName()+ " " + csm); + throw new UnsupportedOperationException(csm.getClass().getSimpleName() + " " + csm); } } public static int toToken(Modifier modifier) { - switch (modifier.getKeyword()) { + switch(modifier.getKeyword()) { case PUBLIC: return GeneratedJavaParserConstants.PUBLIC; case PRIVATE: @@ -377,10 +355,9 @@ public static int toToken(Modifier modifier) { } } - /// - /// Methods that calculate CalculatedSyntaxModel - /// - + // / + // / Methods that calculate CalculatedSyntaxModel + // / // Visible for testing CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(Node node, ObservableProperty property, Object oldValue, Object newValue) { return calculatedSyntaxModelAfterPropertyChange(ConcreteSyntaxModel.forClass(node.getClass()), node, property, oldValue, newValue); @@ -416,7 +393,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(Node container, Obs if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList)rawValue; + NodeList nodeList = (NodeList) rawValue; return calculatedSyntaxModelAfterListAddition(csm, observableProperty, nodeList, index, nodeAdded); } @@ -427,7 +404,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(Node container, Obse if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList)rawValue; + NodeList nodeList = (NodeList) rawValue; return calculatedSyntaxModelAfterListRemoval(csm, observableProperty, nodeList, index); } @@ -438,5 +415,4 @@ private CalculatedSyntaxModel calculatedSyntaxModelAfterListReplacement(CsmEleme calculatedSyntaxModelForNode(csm, container, elements, new ListReplacementChange(observableProperty, index, newValue)); return new CalculatedSyntaxModel(elements); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index f254be3175..e29341d9a9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -18,30 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.GeneratedJavaParserConstants.*; -import static com.github.javaparser.TokenTypes.eolTokenKind; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.decapitalize; -import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import com.github.javaparser.JavaToken; import com.github.javaparser.Range; import com.github.javaparser.ast.DataKey; @@ -60,14 +38,25 @@ import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.visitor.TreeVisitor; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.utils.LineSeparator; import com.github.javaparser.utils.Pair; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.util.*; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static com.github.javaparser.utils.Utils.decapitalize; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; + /** * A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when * operating on the AST and then used them to reproduce the source code @@ -85,10 +74,9 @@ public class LexicalPreservingPrinter { private static final LexicalDifferenceCalculator LEXICAL_DIFFERENCE_CALCULATOR = new LexicalDifferenceCalculator(); - // + // // Factory methods - // - + // /** * Prepares the node so it can be used in the print methods. * The correct order is: @@ -103,11 +91,9 @@ public class LexicalPreservingPrinter { */ public static N setup(N node) { assertNotNull(node); - if (observer == null) { observer = createObserver(); } - node.getTokenRange().ifPresent(r -> { storeInitialText(node); // Setup observer @@ -118,10 +104,9 @@ public static N setup(N node) { return node; } - // + // // Constructor and setup - // - + // private static AstObserver createObserver() { return new LexicalPreservingPrinter.Observer(); } @@ -139,20 +124,13 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } if (property == ObservableProperty.COMMENT) { Optional parentNode = observedNode.getParentNode(); - NodeText nodeText = parentNode - .map(parent -> getOrCreateNodeText(parentNode.get())) - // We're at the root node. - .orElse(getOrCreateNodeText(observedNode)); - + NodeText nodeText = parentNode.map(parent -> getOrCreateNodeText(parentNode.get())).orElse(getOrCreateNodeText(observedNode)); if (oldValue == null) { - int index = parentNode.isPresent() ? - // Find the position of the comment node and put in front of it the [...] - nodeText.findChild(observedNode) : - // - 0; + int index = parentNode.isPresent() ? // Find the position of the comment node and put in front of it the [...] + nodeText.findChild(observedNode) : // + 0; // Add the same indent depth of the comment to the following node fixIndentOfMovedNode(nodeText, index); - LineSeparator lineSeparator = observedNode.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); nodeText.addElement(index, makeCommentToken((Comment) newValue)); nodeText.addToken(index + 1, eolTokenKind(lineSeparator), lineSeparator.asRawString()); @@ -171,22 +149,18 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } } else { List matchingTokens = findTokenTextElementForComment((Comment) oldValue, nodeText); - if (matchingTokens.size() != 1) { throw new IllegalStateException("The matching comment to be replaced could not be found"); } - Comment newComment = (Comment) newValue; TokenTextElement matchingElement = matchingTokens.get(0); nodeText.replace(matchingElement.and(matchingElement.matchByRange()), makeCommentToken(newComment)); } } NodeText nodeText = getOrCreateNodeText(observedNode); - if (nodeText == null) { throw new NullPointerException(observedNode.getClass().getSimpleName()); } - LEXICAL_DIFFERENCE_CALCULATOR.calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue); } @@ -201,12 +175,10 @@ private TokenTextElement makeCommentToken(Comment newComment) { return new TokenTextElement(MULTI_LINE_COMMENT, "/*" + newComment.getContent() + "*/"); } throw new UnsupportedOperationException("Unknown type of comment: " + newComment.getClass().getSimpleName()); - } private int getIndexOfComment(Comment oldValue, NodeText nodeText) { List matchingTokens = findTokenTextElementForComment(oldValue, nodeText); - if (!matchingTokens.isEmpty()) { TextElement matchingElement = matchingTokens.get(0); return nodeText.findElement(matchingElement.and(matchingElement.matchByRange())); @@ -219,58 +191,30 @@ private int getIndexOfComment(Comment oldValue, NodeText nodeText) { private List findChildTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingChildElements; - - matchingChildElements = nodeText.getElements().stream() - .filter(e -> e.isChild()) - .map(c -> (ChildTextElement) c) - .filter(c -> c.isComment()) - .filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())) - .collect(toList()); - + matchingChildElements = nodeText.getElements().stream().filter(e -> e.isChild()).map(c -> (ChildTextElement) c).filter(c -> c.isComment()).filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())).collect(toList()); if (matchingChildElements.size() > 1) { // Duplicate child nodes found, refine the result - matchingChildElements = matchingChildElements.stream() - .filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())) - .collect(toList()); + matchingChildElements = matchingChildElements.stream().filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())).collect(toList()); } - if (matchingChildElements.size() != 1) { throw new IllegalStateException("The matching child text element for the comment to be removed could not be found."); } - return matchingChildElements; } private List findTokenTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingTokens; - if (oldValue instanceof JavadocComment) { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(JAVADOC_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")).collect(toList()); } else if (oldValue instanceof BlockComment) { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(MULTI_LINE_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(MULTI_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")).collect(toList()); } else { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(SINGLE_LINE_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(SINGLE_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())).collect(toList()); } - if (matchingTokens.size() > 1) { // Duplicate comments found, refine the result - matchingTokens = matchingTokens.stream() - .filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())) - .collect(toList()); + matchingTokens = matchingTokens.stream().filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())).collect(toList()); } - return matchingTokens; } @@ -278,7 +222,6 @@ private boolean isEqualRange(Optional range1, Optional range2) { if (range1.isPresent() && range2.isPresent()) { return range1.get().equals(range2.get()); } - return false; } @@ -293,7 +236,6 @@ private void fixIndentOfMovedNode(NodeText nodeText, int index) { if (index <= 0) { return; } - for (int i = index - 1; i >= 0; i--) { TextElement spaceCandidate = nodeText.getTextElement(i); if (!spaceCandidate.isSpaceOrTab()) { @@ -318,7 +260,6 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int } else { throw new UnsupportedOperationException(); } - Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -327,7 +268,6 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int public void concreteListReplacement(NodeList changedList, int index, Node oldValue, Node newValue) { NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren()); List differenceElements = LEXICAL_DIFFERENCE_CALCULATOR.calculateListReplacementDifference(findNodeListName(changedList), changedList, index, newValue); - Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -335,7 +275,6 @@ public void concreteListReplacement(NodeList changedList, int index, Node old private static void storeInitialText(Node root) { Map> tokensByNode = new IdentityHashMap<>(); - // We go over tokens and find to which nodes they belong. Note that we do not traverse the tokens as they were // on a list but as they were organized in a tree. At each time we select only the branch corresponding to the // range of interest and ignore all other branches @@ -348,9 +287,9 @@ private static void storeInitialText(Node root) { } tokensByNode.get(owner).add(token); } - // Now that we know the tokens we use them to create the initial NodeText for each node new TreeVisitor() { + @Override public void process(Node node) { if (!node.isPhantom()) { @@ -365,13 +304,12 @@ private static Optional findNodeForToken(Node node, Range tokenRange) { if (node.isPhantom()) { return Optional.empty(); } - if(!node.getRange().isPresent()) { + if (!node.getRange().isPresent()) { return Optional.empty(); } if (!node.getRange().get().contains(tokenRange)) { return Optional.empty(); } - for (Node child : node.getChildNodes()) { Optional found = findNodeForToken(child, tokenRange); if (found.isPresent()) { @@ -401,38 +339,30 @@ private static void storeInitialTextForOneNode(Node node, List nodeTo node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(toList()))); } - // + // // Iterators - // - + // private static Iterator tokensPreceeding(final Node node) { if (!node.getParentNode().isPresent()) { return new TextElementIteratorsFactory.EmptyIterator<>(); } // There is the awfully painful case of the fake types involved in variable declarators and // fields or variable declaration that are, of course, an exception... - NodeText parentNodeText = getOrCreateNodeText(node.getParentNode().get()); int index = parentNodeText.tryToFindChild(node); if (index == NodeText.NOT_FOUND) { if (node.getParentNode().get() instanceof VariableDeclarator) { return tokensPreceeding(node.getParentNode().get()); } else { - throw new IllegalArgumentException( - String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", - node, node.getParentNode().get(), parentNodeText)); + throw new IllegalArgumentException(String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", node, node.getParentNode().get(), parentNodeText)); } } - - return new TextElementIteratorsFactory.CascadingIterator<>( - TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), - () -> tokensPreceeding(node.getParentNode().get())); + return new TextElementIteratorsFactory.CascadingIterator<>(TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), () -> tokensPreceeding(node.getParentNode().get())); } - // + // // Printing methods - // - + // /** * Print a Node into a String, preserving the lexical information. */ @@ -457,14 +387,13 @@ public static void print(Node node, Writer writer) throws IOException { writer.append(text.expand()); } - // + // // Methods to handle transformations - // - + // private static void prettyPrintingTextNode(Node node, NodeText nodeText) { if (node instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) node; - switch (primitiveType.getType()) { + switch(primitiveType.getType()) { case BOOLEAN: nodeText.addToken(BOOLEAN, node.toString()); break; @@ -511,7 +440,6 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { nodeText.addToken(LexicalDifferenceCalculator.toToken(modifier), modifier.getKeyword().asString()); return; } - interpret(node, ConcreteSyntaxModel.forClass(node.getClass()), nodeText); } @@ -520,15 +448,12 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { */ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) { LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(csm, node); - List indentation = findIndentation(node); - boolean pendingIndentation = false; for (CsmElement element : calculatedSyntaxModel.elements) { if (element instanceof CsmIndent) { int indexCurrentElement = calculatedSyntaxModel.elements.indexOf(element); - if (calculatedSyntaxModel.elements.size() > indexCurrentElement && - !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { + if (calculatedSyntaxModel.elements.size() > indexCurrentElement && !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { for (int i = 0; i < Difference.STANDARD_INDENTATION_SIZE; i++) { indentation.add(new TokenTextElement(SPACE, " ")); } @@ -538,11 +463,9 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) indentation.remove(indentation.size() - 1); } } - if (pendingIndentation && !(element instanceof CsmToken && ((CsmToken) element).isNewLine())) { indentation.forEach(nodeText::addElement); } - pendingIndentation = false; if (element instanceof LexicalDifferenceCalculator.CsmChild) { nodeText.addChild(((LexicalDifferenceCalculator.CsmChild) element).getChild()); @@ -567,15 +490,13 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) // so they have to be handled in a special way if (node instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) node; - variableDeclarator.getParentNode().ifPresent(parent -> - ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { - int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); - for (int i = 0; i < extraArrayLevels; i++) { - nodeText.addElement(new TokenTextElement(LBRACKET)); - nodeText.addElement(new TokenTextElement(RBRACKET)); - } - }) - ); + variableDeclarator.getParentNode().ifPresent(parent -> ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { + int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); + for (int i = 0; i < extraArrayLevels; i++) { + nodeText.addElement(new TokenTextElement(LBRACKET)); + nodeText.addElement(new TokenTextElement(RBRACKET)); + } + })); } return nodeText; } @@ -596,8 +517,7 @@ static List findIndentation(Node node) { Iterator it = tokensPreceeding(node); while (it.hasNext()) { TokenTextElement tte = it.next(); - if (tte.getTokenKind() == SINGLE_LINE_COMMENT - || tte.isNewline()) { + if (tte.getTokenKind() == SINGLE_LINE_COMMENT || tte.isNewline()) { break; } else { followingNewlines.add(tte); @@ -612,10 +532,9 @@ static List findIndentation(Node node) { return followingNewlines; } - // + // // Helper methods - // - + // private static boolean isReturningOptionalNodeList(Method m) { if (!m.getReturnType().getCanonicalName().equals(Optional.class.getCanonicalName())) { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java index 5c20e9e49b..2b2688ee91 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -31,14 +30,14 @@ * It is basically a list of tokens and children. */ class NodeText { + private final List elements; public static final int NOT_FOUND = -1; - // + // // Constructors - // - + // NodeText(List elements) { this.elements = elements; } @@ -50,10 +49,9 @@ class NodeText { this(new LinkedList<>()); } - // + // // Adding elements - // - + // /** * Add an element at the end. */ @@ -84,10 +82,9 @@ void addToken(int index, int tokenKind, String text) { elements.add(index, new TokenTextElement(tokenKind, text)); } - // + // // Finding elements - // - + // int findElement(TextElementMatcher matcher) { return findElement(matcher, 0); } @@ -95,8 +92,7 @@ int findElement(TextElementMatcher matcher) { int findElement(TextElementMatcher matcher, int from) { int res = tryToFindElement(matcher, from); if (res == NOT_FOUND) { - throw new IllegalArgumentException( - String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); + throw new IllegalArgumentException(String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); } return res; } @@ -127,10 +123,9 @@ int tryToFindChild(Node child, int from) { return tryToFindElement(TextElementMatchers.byNode(child), from); } - // + // // Removing single elements - // - + // public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhitespace) { int i = 0; for (TextElement e : elements) { @@ -151,34 +146,30 @@ public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhite throw new IllegalArgumentException(); } - // + // // Removing sequences - // - + // void removeElement(int index) { elements.remove(index); } - // + // // Replacing elements - // - + // void replace(TextElementMatcher position, TextElement newElement) { int index = findElement(position, 0); elements.remove(index); elements.add(index, newElement); } - // + // // Other methods - // - + // /** * Generate the corresponding string. */ String expand() { StringBuffer sb = new StringBuffer(); - elements.forEach(e -> sb.append(e.expand())); return sb.toString(); } @@ -202,5 +193,4 @@ List getElements() { public String toString() { return "NodeText{" + elements + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java index 380d6c290e..db39520a50 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java @@ -18,19 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static java.util.Collections.synchronizedMap; - -import java.util.IdentityHashMap; -import java.util.Map; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.observer.AstObserver; import com.github.javaparser.ast.observer.AstObserverAdapter; import com.github.javaparser.ast.type.UnknownType; +import java.util.IdentityHashMap; +import java.util.Map; + +import static java.util.Collections.synchronizedMap; + /** * We want to recognize and ignore "phantom" nodes, like the fake type of variable in FieldDeclaration * @deprecated This class is no longer used phantom node are now an attribute of each node @@ -43,6 +42,7 @@ public class PhantomNodeLogic { private static final Map isPhantomNodeCache = synchronizedMap(new IdentityHashMap<>()); private static final AstObserver cacheCleaner = new AstObserverAdapter() { + @Override public void parentChange(Node observedNode, Node previousParent, Node newParent) { isPhantomNodeCache.remove(observedNode); @@ -56,11 +56,7 @@ static boolean isPhantomNode(Node node) { if (node instanceof UnknownType) { return true; } - boolean res = (node.getParentNode().isPresent() - && node.getParentNode().get().hasRange() - && node.hasRange() - && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) - || inPhantomNode(node, LEVELS_TO_EXPLORE)); + boolean res = (node.getParentNode().isPresent() && node.getParentNode().get().hasRange() && node.hasRange() && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) || inPhantomNode(node, LEVELS_TO_EXPLORE)); isPhantomNodeCache.put(node, res); node.register(cacheCleaner); return res; @@ -71,9 +67,7 @@ static boolean isPhantomNode(Node node) { * A node contained in a phantom node is also a phantom node. We limit how many levels up we check just for performance reasons. */ private static boolean inPhantomNode(Node node, int levels) { - return node.getParentNode().isPresent() && - (isPhantomNode(node.getParentNode().get()) - || inPhantomNode(node.getParentNode().get(), levels - 1)); + return node.getParentNode().isPresent() && (isPhantomNode(node.getParentNode().get()) || inPhantomNode(node.getParentNode().get(), levels - 1)); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java index bf8edd0406..b33c4b3bb3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; public class Removed implements DifferenceElement { + private final CsmElement element; Removed(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Removed removed = (Removed) o; - return element.equals(removed.element); } @@ -63,7 +63,6 @@ public Node getChild() { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild(); } - throw new IllegalStateException("Removed is not a " + LexicalDifferenceCalculator.CsmChild.class.getSimpleName()); } @@ -72,7 +71,6 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } - throw new IllegalStateException("Removed is not a " + CsmToken.class.getSimpleName()); } @@ -81,25 +79,27 @@ public boolean isAdded() { return false; } - public boolean isToken() { return element instanceof CsmToken; } + public boolean isToken() { + return element instanceof CsmToken; + } - public boolean isChild() { return element instanceof LexicalDifferenceCalculator.CsmChild; } + public boolean isChild() { + return element instanceof LexicalDifferenceCalculator.CsmChild; + } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } - return false; } public boolean isWhiteSpace() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } - return false; } @@ -107,13 +107,12 @@ public boolean isWhiteSpace() { public boolean isRemoved() { return true; } - + public boolean isNewLine() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } - return false; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java index a616ba0ff7..7c84ce0bea 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.JavaToken; @@ -48,6 +47,7 @@ final class RemovedGroup implements Iterable { private final Integer firstElementIndex; + private final List removedList; private boolean isProcessed = false; @@ -56,11 +56,9 @@ private RemovedGroup(Integer firstElementIndex, List removedList) { if (firstElementIndex == null) { throw new IllegalArgumentException("firstElementIndex should not be null"); } - if (removedList == null || removedList.isEmpty()) { throw new IllegalArgumentException("removedList should not be null or empty"); } - this.firstElementIndex = firstElementIndex; this.removedList = removedList; } @@ -94,9 +92,7 @@ final boolean isProcessed() { } private List getIndicesBeingRemoved() { - return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()) - .boxed() - .collect(Collectors.toList()); + return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()).boxed().collect(Collectors.toList()); } /** @@ -141,13 +137,15 @@ final Removed getLastElement() { * @return true if the RemovedGroup equates to a complete line */ final boolean isACompleteLine() { - return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) - && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); + return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); } private final Function hasOnlyWhitespaceJavaTokenInFrontFunction = begin -> hasOnlyWhiteSpaceForTokenFunction(begin, token -> token.getPreviousToken()); + private final Function hasOnlyWhitespaceJavaTokenBehindFunction = end -> hasOnlyWhiteSpaceForTokenFunction(end, token -> token.getNextToken()); + private final Function hasOnlyWhitespaceInFrontFunction = tokenRange -> hasOnlyWhitespaceJavaTokenInFrontFunction.apply(tokenRange.getBegin()); + private final Function hasOnlyWhitespaceBehindFunction = tokenRange -> hasOnlyWhitespaceJavaTokenBehindFunction.apply(tokenRange.getEnd()); private boolean hasOnlyWhitespace(Removed startElement, Function hasOnlyWhitespaceFunction) { @@ -155,7 +153,6 @@ private boolean hasOnlyWhitespace(Removed startElement, Function tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { hasOnlyWhitespace = hasOnlyWhitespaceFunction.apply(tokenRange.get()); @@ -171,7 +168,6 @@ private boolean hasOnlyWhitespace(Removed startElement, Function> tokenFunction) { Optional tokenResult = tokenFunction.apply(token); - if (tokenResult.isPresent()) { if (TokenTypes.isWhitespaceButNotEndOfLine(tokenResult.get().getKind())) { return hasOnlyWhiteSpaceForTokenFunction(tokenResult.get(), tokenFunction); @@ -181,7 +177,6 @@ private boolean hasOnlyWhiteSpaceForTokenFunction(JavaToken token, Function getIndentation() { Removed firstElement = getFirstElement(); - int indentation = 0; if (firstElement.isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) firstElement.getElement(); Node child = csmChild.getChild(); - Optional tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { JavaToken begin = tokenRange.get().getBegin(); - if (hasOnlyWhitespaceJavaTokenInFrontFunction.apply(begin)) { Optional previousToken = begin.getPreviousToken(); - - while(previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { + while (previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { indentation++; - previousToken = previousToken.get().getPreviousToken(); } - if (previousToken.isPresent()) { if (TokenTypes.isEndOfLineToken(previousToken.get().getKind())) { return Optional.of(Integer.valueOf(indentation)); @@ -224,13 +213,13 @@ final Optional getIndentation() { } } } - return Optional.empty(); } @Override public final Iterator iterator() { return new Iterator() { + private int currentIndex = 0; @Override @@ -242,7 +231,6 @@ public boolean hasNext() { public Removed next() { return removedList.get(currentIndex++); } - }; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java index b888c6fe4c..8b07c5c4a7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; @@ -28,7 +27,9 @@ * some new elements have been added or removed to the mix. */ public class Reshuffled implements DifferenceElement { + private final CsmMix previousOrder; + private final CsmMix nextOrder; Reshuffled(CsmMix previousOrder, CsmMix nextOrder) { @@ -38,17 +39,18 @@ public class Reshuffled implements DifferenceElement { @Override public String toString() { - return "Reshuffled{" + nextOrder + ", previous="+ previousOrder+ '}'; + return "Reshuffled{" + nextOrder + ", previous=" + previousOrder + '}'; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Reshuffled that = (Reshuffled) o; - - if (!previousOrder.equals(that.previousOrder)) return false; + if (!previousOrder.equals(that.previousOrder)) + return false; return nextOrder.equals(that.nextOrder); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java index 64d8f73853..215f94ad00 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; @@ -34,9 +33,7 @@ public abstract class TextElement implements TextElementMatcher { abstract boolean isToken(int tokenKind); final boolean isCommentToken() { - return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) - || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) - || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); + return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); } @Override @@ -85,11 +82,6 @@ public boolean isChild() { * @return TextElementMatcher that matches any TextElement with the same Range */ TextElementMatcher matchByRange() { - return (TextElement textElement) -> - getRange() - .flatMap(r1 -> textElement.getRange() - .map(r1::equals)) - // We're missing range information. This may happen when a node is manually instantiated. Don't be too harsh on that: - .orElse(true); + return (TextElement textElement) -> getRange().flatMap(r1 -> textElement.getRange().map(r1::equals)).orElse(true); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java index 59fa9921d8..a6572a3524 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; @@ -28,14 +27,20 @@ class TextElementIteratorsFactory { static class CascadingIterator implements Iterator { + interface Provider { + Iterator provide(); } private final Provider nextProvider; + private Iterator current; + private Iterator next; + private boolean lastReturnedFromCurrent = false; + private boolean lastReturnedFromNext = false; public CascadingIterator(Iterator current, Provider nextProvider) { @@ -43,7 +48,6 @@ public CascadingIterator(Iterator current, Provider nextProvider) { this.current = current; } - @Override public boolean hasNext() { if (current.hasNext()) { @@ -85,6 +89,7 @@ public void remove() { } static class EmptyIterator implements Iterator { + @Override public boolean hasNext() { return false; @@ -97,7 +102,9 @@ public E next() { } private static class SingleElementIterator implements Iterator { + private final E element; + private boolean returned; SingleElementIterator(E element) { @@ -117,12 +124,13 @@ public E next() { @Override public void remove() { - } } static class ComposedIterator implements Iterator { + private final List> elements; + private int currIndex; ComposedIterator(List> elements) { @@ -135,7 +143,7 @@ public boolean hasNext() { if (currIndex >= elements.size()) { return false; } - if (elements.get(currIndex).hasNext()){ + if (elements.get(currIndex).hasNext()) { return true; } currIndex++; @@ -159,14 +167,15 @@ public void remove() { private static Iterator reverseIterator(NodeText nodeText, int index) { TextElement textElement = nodeText.getTextElement(index); if (textElement instanceof TokenTextElement) { - return new SingleElementIterator((TokenTextElement)textElement) { + return new SingleElementIterator((TokenTextElement) textElement) { + @Override public void remove() { nodeText.removeElement(index); } }; } else if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement)textElement; + ChildTextElement childTextElement = (ChildTextElement) textElement; NodeText textForChild = childTextElement.getNodeTextForWrappedNode(); return reverseIterator(textForChild); } else { @@ -180,10 +189,9 @@ public static Iterator reverseIterator(NodeText nodeText) { public static Iterator partialReverseIterator(NodeText nodeText, int fromIndex) { List> elements = new LinkedList<>(); - for (int i=fromIndex;i>=0;i--) { + for (int i = fromIndex; i >= 0; i--) { elements.add(reverseIterator(nodeText, i)); } return new ComposedIterator<>(elements); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java index 09c0e48db6..23df186259 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; public interface TextElementMatcher { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java index 7e07371f9c..543123f9ca 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ static TextElementMatcher byTokenType(int tokenType) { static TextElementMatcher byNode(final Node node) { return new TextElementMatcher() { + @Override public boolean match(TextElement textElement) { return textElement.isNode(node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java index d3714adcc8..ab7334b655 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java @@ -18,17 +18,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.JavaToken; -import com.github.javaparser.Range; import com.github.javaparser.JavaToken.Kind; +import com.github.javaparser.Range; import com.github.javaparser.ast.Node; import java.util.Optional; class TokenTextElement extends TextElement { + private final JavaToken token; TokenTextElement(JavaToken token) { @@ -63,11 +63,11 @@ public JavaToken getToken() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; TokenTextElement that = (TokenTextElement) o; - return token.equals(that.token); } @@ -105,7 +105,7 @@ public boolean isSpaceOrTab() { public boolean isComment() { return token.getCategory().isComment(); } - + @Override public boolean isSeparator() { return token.getCategory().isSeparator(); @@ -120,7 +120,7 @@ public boolean isNewline() { public boolean isChildOfClass(Class nodeClass) { return false; } - + @Override public boolean isIdentifier() { return getToken().getCategory().isIdentifier(); @@ -130,7 +130,7 @@ public boolean isIdentifier() { public boolean isLiteral() { return getToken().getCategory().isLiteral(); } - + @Override public boolean isPrimitive() { return Kind.valueOf(getTokenKind()).isPrimitive(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java index 24e3b415f1..ce1d9cc2d4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java @@ -18,13 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; public class WrappingRangeIterator implements Iterator { + private final int limit; + private int currentValue = 0; public WrappingRangeIterator(int limit) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java index 12e2ee8762..7a74f31460 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -32,7 +31,7 @@ public interface Change { default boolean evaluate(CsmConditional csmConditional, Node node) { - switch (csmConditional.getCondition()) { + switch(csmConditional.getCondition()) { case FLAG: return csmConditional.getProperties().stream().anyMatch(p -> (Boolean) getValue(p, node)); case IS_NOT_EMPTY: diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java index 63a0249832..0474d52311 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,7 +32,9 @@ public class ListAdditionChange implements Change { private final ObservableProperty observableProperty; + private final int index; + private final Node nodeAdded; public ListAdditionChange(ObservableProperty observableProperty, int index, Node nodeAdded) { @@ -54,15 +55,12 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- add to the list newNodeList.add(index, nodeAdded); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java index 26f19af227..961b296195 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,6 +32,7 @@ public class ListRemovalChange implements Change { private final ObservableProperty observableProperty; + private final int index; public ListRemovalChange(ObservableProperty observableProperty, int index) { @@ -52,15 +52,13 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); - newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); // fix #2187 set the parent node in the new list + // fix #2187 set the parent node in the new list + newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- remove an item from the list newNodeList.remove(index); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java index b84c3cefc6..94f172bc76 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,7 +32,9 @@ public class ListReplacementChange implements Change { private final ObservableProperty observableProperty; + private final int index; + private final Node newValue; public ListReplacementChange(ObservableProperty observableProperty, int index, Node newValue) { @@ -54,15 +55,12 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- replace an item in the list newNodeList.set(index, newValue); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java index ef0336af9d..b19088d1ba 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java index 4b10893cf5..7d941bb39f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -30,7 +29,9 @@ public class PropertyChange implements Change { private final ObservableProperty property; + private final Object oldValue; + private final Object newValue; public PropertyChange(ObservableProperty property, Object oldValue, Object newValue) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java index 025ad44e75..2258416034 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; /** @@ -34,5 +33,4 @@ public class MethodAmbiguityException extends RuntimeException { public MethodAmbiguityException(String description) { super(description); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java index 5f64cdc10c..c4ced2145d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -28,7 +27,6 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; - import java.util.*; /** @@ -38,10 +36,15 @@ * @author Federico Tomassetti */ public class MethodUsage implements ResolvedTypeParametrized { + private ResolvedMethodDeclaration declaration; + private List paramTypes = new ArrayList<>(); + private List exceptionTypes = new ArrayList<>(); + private ResolvedType returnType; + private ResolvedTypeParametersMap typeParametersMap; public MethodUsage(ResolvedMethodDeclaration declaration) { @@ -56,19 +59,15 @@ public MethodUsage(ResolvedMethodDeclaration declaration) { returnType = declaration.getReturnType(); } - public MethodUsage(ResolvedMethodDeclaration declaration, - List paramTypes, ResolvedType returnType) { - this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), - ResolvedTypeParametersMap.empty()); + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType) { + this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), ResolvedTypeParametersMap.empty()); } - public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, - List exceptionTypes) { + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes) { this(declaration, paramTypes, returnType, exceptionTypes, ResolvedTypeParametersMap.empty()); } - private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, - List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { + private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { this.declaration = declaration; this.paramTypes = paramTypes; this.returnType = returnType; @@ -78,10 +77,7 @@ private MethodUsage(ResolvedMethodDeclaration declaration, List pa @Override public String toString() { - return "MethodUsage{" + - "declaration=" + declaration + - ", paramTypes=" + paramTypes + - '}'; + return "MethodUsage{" + "declaration=" + declaration + ", paramTypes=" + paramTypes + '}'; } public ResolvedMethodDeclaration getDeclaration() { @@ -154,11 +150,8 @@ public MethodUsage replaceTypeParameter(ResolvedTypeParameterDeclaration typePar if (type == null) { throw new IllegalArgumentException(); } - // TODO if the method declaration has a type param with that name ignore this call - MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, - typeParametersMap.toBuilder().setValue(typeParameter, type).build()); - + MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, typeParametersMap.toBuilder().setValue(typeParameter, type).build()); Map inferredTypes = new HashMap<>(); for (int i = 0; i < paramTypes.size(); i++) { ResolvedType originalParamType = paramTypes.get(i); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java index 3ab14c955b..89796b434c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java @@ -18,9 +18,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; public interface Resolvable { + T resolve(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java index ee77248581..97550cf0ad 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.resolution.types.ResolvedType; public interface SymbolResolver { + /** * For a reference it would find the corresponding * declaration. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java index b42c504fa8..6b0fc1b02b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; /** @@ -70,10 +69,6 @@ public String getName() { @Override public String toString() { - return "UnsolvedSymbolException{" + - "context='" + context + "'" + - ", name='" + name + "'" + - ", cause='" + cause + "'" + - "}"; + return "UnsolvedSymbolException{" + "context='" + context + "'" + ", name='" + name + "'" + ", cause='" + cause + "'" + "}"; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java index f71d9a2236..049436c0ea 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java index 8cb38c41ce..e236da7f63 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.AccessSpecifier; @@ -35,5 +34,4 @@ public interface HasAccessSpecifier { * The access specifier of this element. */ AccessSpecifier accessSpecifier(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java index 8d6c55d1f7..930fc06454 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.AnnotationDeclaration; @@ -28,8 +27,7 @@ /** * @author Federico Tomassetti */ -public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, - AssociableToAST { +public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, AssociableToAST { List getAnnotationMembers(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java index 1e30f166ac..93e8a02893 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.expr.Expression; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java index bf336f9241..61da9aaa9b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; @@ -35,8 +34,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { /** * This method should always return true. @@ -77,15 +75,13 @@ default boolean isClass() { */ List getAllInterfaces(); - /// - /// Constructors - /// - + // / + // / Constructors + // / /** * List of constructors available for the class. * This list should also include the default constructor. */ @Override List getConstructors(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java index 5959f1f835..e95f5c5de5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ConstructorDeclaration; @@ -28,8 +27,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, - AssociableToAST { +public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, AssociableToAST { /** * A constructor can be declared in a class or an enum. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java index 53913aa349..69ceadfb5b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java index ac474c602a..2740f064a6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java index 4c5e0be0d9..4ba91b0bf0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import java.util.List; @@ -28,8 +27,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, - HasAccessSpecifier { +public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, HasAccessSpecifier { @Override default boolean isEnum() { @@ -48,7 +46,6 @@ default boolean hasEnumConstant(String name) { } default ResolvedEnumConstantDeclaration getEnumConstant(final String name) { - return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst() - .orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); + return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst().orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java index ded5dcd459..3da467f7da 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.FieldDeclaration; @@ -49,5 +48,4 @@ default ResolvedFieldDeclaration asField() { * The type on which this field has been declared */ ResolvedTypeDeclaration declaringType(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java index 5cc22165d9..f218d605ac 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -32,8 +31,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { @Override default boolean isInterface() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java index 3fc3d801b7..0071bd14ab 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.MethodDeclaration; @@ -51,5 +50,4 @@ public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration * Is this method static? */ boolean isStatic(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java index 86c5398875..d964f7d517 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.types.ResolvedType; @@ -33,8 +32,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier { +public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier { + /** * The package name of the declaring type. */ @@ -150,7 +149,7 @@ default List getSpecifiedExceptions() { return Collections.emptyList(); } else { List exceptions = new LinkedList<>(); - for (int i=0;i getAllAncestors() { return ancestors; } - /// - /// Fields - /// - + // / + // / Fields + // / /** * Note that the type of the field should be expressed using the type variables of this particular type. * Consider for example: @@ -124,9 +121,7 @@ default List getAllAncestors() { * Bar I should get a FieldDeclaration with type String. */ default ResolvedFieldDeclaration getField(String name) { - Optional field = this.getAllFields().stream() - .filter(f -> f.getName().equals(name)) - .findFirst(); + Optional field = this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst(); if (field.isPresent()) { return field.get(); } else { @@ -169,9 +164,7 @@ default boolean hasVisibleField(String name) { * Return a list of all fields declared and the inherited ones which are not private. */ default List getVisibleFields() { - return getAllFields().stream() - .filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList()); + return getAllFields().stream().filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); } /** @@ -192,14 +185,12 @@ default List getAllStaticFields() { * Return a list of all the fields declared in this type. */ default List getDeclaredFields() { - return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName() - .equals(getQualifiedName())).collect(Collectors.toList()); + return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName().equals(getQualifiedName())).collect(Collectors.toList()); } - /// - /// Methods - /// - + // / + // / Methods + // / /** * Return a list of all the methods declared in this type declaration. */ @@ -211,10 +202,9 @@ default List getDeclaredFields() { */ Set getAllMethods(); - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * Can we assign instances of the given type to variables having the type defined * by this declaration? @@ -235,10 +225,9 @@ default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { */ boolean isAssignableBy(ResolvedReferenceTypeDeclaration other); - /// - /// Annotations - /// - + // / + // / Annotations + // / /** * Has the type at least one annotation declared having the specified qualified name? */ @@ -251,9 +240,7 @@ default boolean hasAnnotation(String qualifiedName) { if (hasDirectlyAnnotation(qualifiedName)) { return true; } - return getAllAncestors().stream() - .filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()) - .anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); + return getAllAncestors().stream().filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()).anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); } /** @@ -262,10 +249,9 @@ default boolean hasAnnotation(String qualifiedName) { */ boolean isFunctionalInterface(); - /// - /// Type parameters - /// - + // / + // / Type parameters + // / @Override default Optional findTypeParameter(String name) { for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) { @@ -281,7 +267,6 @@ default Optional findTypeParameter(String name List getConstructors(); - /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -291,10 +276,8 @@ default Optional findTypeParameter(String name * @see https://github.com/javaparser/javaparser/issues/2044 */ default boolean isJavaLangObject() { - return this.isClass() - && !isAnonymousClass() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(JAVA_LANG_OBJECT); + return this.isClass() && !isAnonymousClass() && // Consider anonymous classes + hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT); } /** @@ -302,8 +285,6 @@ && hasName() // Consider anonymous classes * @see ResolvedReferenceType#isJavaLangEnum() */ default boolean isJavaLangEnum() { - return this.isEnum() - && getQualifiedName().equals(JAVA_LANG_ENUM); + return this.isEnum() && getQualifiedName().equals(JAVA_LANG_ENUM); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java index 15f5a17a1f..3de270dc02 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -35,10 +34,9 @@ */ public interface ResolvedTypeDeclaration extends ResolvedDeclaration { - /// - /// Containment - /// - + // / + // / Containment + // / /** * Get the list of types defined inside the current type. */ @@ -51,10 +49,8 @@ default Set internalTypes() { * (Does not include internal types inside internal types). */ default ResolvedReferenceTypeDeclaration getInternalType(String name) { - Optional type = - this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); - return type.orElseThrow(() -> - new UnsolvedSymbolException("Internal type not found: " + name)); + Optional type = this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); + return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); } /** @@ -70,10 +66,9 @@ default boolean hasInternalType(String name) { */ Optional containerType(); - /// - /// Misc - /// - + // / + // / Misc + // / /** * Is this the declaration of a class? * Note that an Enum is not considered a Class in this case. @@ -194,5 +189,4 @@ default String getId() { } return qname; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index 099b3ffe6f..ce5cd8afae 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -18,10 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; - import com.github.javaparser.resolution.types.ResolvedType; import java.util.List; @@ -45,6 +43,7 @@ public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaratio */ static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List bounds) { return new ResolvedTypeParameterDeclaration() { + @Override public String getName() { return name; @@ -74,7 +73,7 @@ public String getContainerQualifiedName() { public String getContainerId() { return classQName; } - + @Override public ResolvedTypeParametrizable getContainer() { return null; @@ -157,7 +156,7 @@ default String getQualifiedName() { * The ID of the container. See TypeContainer.getId */ String getContainerId(); - + /** * The TypeParametrizable of the container. Can be either a ReferenceTypeDeclaration or a MethodLikeDeclaration */ @@ -226,7 +225,9 @@ default ResolvedType getUpperBound() { * A Bound on a Type Parameter. */ class Bound { + private boolean extendsBound; + private ResolvedType type; private Bound(boolean extendsBound, ResolvedType type) { @@ -277,20 +278,18 @@ public boolean isSuper() { @Override public String toString() { - return "Bound{" + - "extendsBound=" + extendsBound + - ", type=" + type + - '}'; + return "Bound{" + "extendsBound=" + extendsBound + ", type=" + type + '}'; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Bound bound = (Bound) o; - - if (extendsBound != bound.extendsBound) return false; + if (extendsBound != bound.extendsBound) + return false; return type != null ? type.equals(bound.type) : bound.type == null; } @@ -301,5 +300,4 @@ public int hashCode() { return result; } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java index 9b44acecd2..95dd0b317d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import java.util.List; @@ -45,5 +44,4 @@ public interface ResolvedTypeParametrizable { default boolean isGeneric() { return !getTypeParameters().isEmpty(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java index 69fb33709c..63f7e7c700 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java @@ -18,10 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; - import com.github.javaparser.resolution.types.ResolvedType; /** @@ -35,5 +33,4 @@ public interface ResolvedValueDeclaration extends ResolvedDeclaration { * Type of the declaration. */ ResolvedType getType(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java index 661b2299ef..19feb684ff 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -38,19 +37,18 @@ public ResolvedArrayType(ResolvedType baseType) { this.baseType = baseType; } - /// - /// Object methods - /// - + // / + // / Object methods + // / @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedArrayType that = (ResolvedArrayType) o; - - if (!baseType.equals(that.baseType)) return false; - + if (!baseType.equals(that.baseType)) + return false; return true; } @@ -64,10 +62,9 @@ public String toString() { return "ResolvedArrayType{" + baseType + "}"; } - /// - /// Type methods - /// - + // / + // / Type methods + // / @Override public ResolvedArrayType asArrayType() { return this; @@ -91,7 +88,7 @@ public ResolvedType getComponentType() { public boolean isAssignableBy(ResolvedType other) { if (other.isArray()) { if (baseType.isPrimitive() && other.asArrayType().getComponentType().isPrimitive()) { - return baseType.equals(other.asArrayType().getComponentType()); + return baseType.equals(other.asArrayType().getComponentType()); } return baseType.isAssignableBy(other.asArrayType().getComponentType()); } else if (other.isNull()) { @@ -109,5 +106,4 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe return new ResolvedArrayType(baseTypeReplaced); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java index b4425658f2..8c3f8f6c8a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -32,6 +31,7 @@ * @author Federico Tomassetti */ public class ResolvedIntersectionType implements ResolvedType { + private List elements; public ResolvedIntersectionType(Collection elements) { @@ -43,11 +43,11 @@ public ResolvedIntersectionType(Collection elements) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedIntersectionType that = (ResolvedIntersectionType) o; - return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } @@ -68,14 +68,11 @@ public boolean isAssignableBy(ResolvedType other) { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map inferredTypes) { - List elementsReplaced = elements.stream() - .map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)) - .collect(Collectors.toList()); + List elementsReplaced = elements.stream().map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)).collect(Collectors.toList()); if (elementsReplaced.equals(elements)) { return this; } else { return new ResolvedIntersectionType(elementsReplaced); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java index 7de9616d38..4444e924e7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java @@ -18,10 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; public class ResolvedLambdaConstraintType implements ResolvedType { + private ResolvedType bound; private ResolvedLambdaConstraintType(ResolvedType bound) { @@ -47,7 +47,7 @@ public ResolvedLambdaConstraintType asConstraintType() { return this; } - public static ResolvedLambdaConstraintType bound(ResolvedType bound){ + public static ResolvedLambdaConstraintType bound(ResolvedType bound) { return new ResolvedLambdaConstraintType(bound); } @@ -58,8 +58,6 @@ public boolean isAssignableBy(ResolvedType other) { @Override public String toString() { - return "LambdaConstraintType{" + - "bound=" + bound + - '}'; + return "LambdaConstraintType{" + "bound=" + bound + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java index d103d19c90..c887e47096 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import java.util.Arrays; @@ -30,7 +29,6 @@ */ public enum ResolvedPrimitiveType implements ResolvedType { - BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()), SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)), CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()), @@ -40,12 +38,13 @@ public enum ResolvedPrimitiveType implements ResolvedType { FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); - /// - /// Fields - /// - + // / + // / Fields + // / private String name; + private String boxTypeQName; + private List promotionTypes; ResolvedPrimitiveType(String name, String boxTypeQName, List promotionTypes) { @@ -63,19 +62,17 @@ public static ResolvedType byName(String name) { } throw new IllegalArgumentException("Name " + name); } - + /* * Returns an array containing all numeric types */ public static ResolvedPrimitiveType[] getNumericPrimitiveTypes() { - return new ResolvedPrimitiveType[] {BYTE,SHORT,CHAR,INT,LONG,FLOAT,DOUBLE}; + return new ResolvedPrimitiveType[] { BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE }; } @Override public String toString() { - return "PrimitiveTypeUsage{" + - "name='" + name + '\'' + - '}'; + return "PrimitiveTypeUsage{" + "name='" + name + '\'' + '}'; } public ResolvedPrimitiveType asPrimitive() { @@ -133,14 +130,14 @@ public String getBoxTypeQName() { public boolean isNumeric() { return this != BOOLEAN; } - + /** * Is this a boolean type? */ public boolean isBoolean() { return this == BOOLEAN; } - + /* * Binary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2) * If any operand is of a reference type, it is subjected to unboxing conversion (§5.1.8). @@ -149,44 +146,43 @@ public ResolvedPrimitiveType bnp(ResolvedPrimitiveType other) { // If either operand is of type double, the other is converted to double. if (this == ResolvedPrimitiveType.DOUBLE || other == ResolvedPrimitiveType.DOUBLE) { return ResolvedPrimitiveType.DOUBLE; - // Otherwise, if either operand is of type float, the other is converted to float. + // Otherwise, if either operand is of type float, the other is converted to float. } else if (this == ResolvedPrimitiveType.FLOAT || other == ResolvedPrimitiveType.FLOAT) { return ResolvedPrimitiveType.FLOAT; - // Otherwise, if either operand is of type long, the other is converted to long. + // Otherwise, if either operand is of type long, the other is converted to long. } else if (this == ResolvedPrimitiveType.LONG || other == ResolvedPrimitiveType.LONG) { return ResolvedPrimitiveType.LONG; } // Otherwise, both operands are converted to type int. return ResolvedPrimitiveType.INT; } - + /* * Unary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se9/html/jls-5.html#jls-5.6.1) */ public static ResolvedType unp(ResolvedType type) { boolean isUnboxable = type.isReferenceType() && type.asReferenceType().isUnboxable(); - // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). + // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). // The result is then promoted to a value of type int by a widening primitive conversion (§5.1.2) or an identity conversion (§5.1.1). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT})) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT })) { return ResolvedPrimitiveType.INT; } // Otherwise, if the operand is of compile-time type Long, Float, or Double, it is subjected to unboxing conversion (§5.1.8). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE})) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE })) { return type.asReferenceType().toUnboxedType().get(); } // Otherwise, if the operand is of compile-time type byte, short, or char, it is promoted to a value of type int by a widening primitive conversion (§5.1.2). - if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT})) { + if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT })) { return ResolvedPrimitiveType.INT; } // Otherwise, a unary numeric operand remains as is and is not converted. return type; } - + /* * Verify if the ResolvedPrimitiveType is in the list of ResolvedPrimitiveType */ public boolean in(ResolvedPrimitiveType[] types) { - return Arrays.stream(types).anyMatch(type -> this == type); + return Arrays.stream(types).anyMatch(type -> this == type); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java index aae1a1ed6f..1eda183242 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -18,19 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -43,26 +32,27 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; import com.github.javaparser.utils.Pair; +import java.util.*; +import java.util.stream.Collectors; + /** * A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values * specified for the type parameters. * * @author Federico Tomassetti */ -public abstract class ResolvedReferenceType implements ResolvedType, - ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { +public abstract class ResolvedReferenceType implements ResolvedType, ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { - // + // // Fields - // - + // protected ResolvedReferenceTypeDeclaration typeDeclaration; + protected ResolvedTypeParametersMap typeParametersMap; - // + // // Constructors - // - + // public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration) { this(typeDeclaration, deriveParams(typeDeclaration)); } @@ -75,9 +65,7 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L throw new IllegalArgumentException("You should use only Classes, Interfaces and enums"); } if (typeArguments.size() > 0 && typeArguments.size() != typeDeclaration.getTypeParameters().size()) { - throw new IllegalArgumentException(String.format( - "expected either zero type arguments or has many as defined in the declaration (%d). Found %d", - typeDeclaration.getTypeParameters().size(), typeArguments.size())); + throw new IllegalArgumentException(String.format("expected either zero type arguments or has many as defined in the declaration (%d). Found %d", typeDeclaration.getTypeParameters().size(), typeArguments.size())); } ResolvedTypeParametersMap.Builder typeParametersMapBuilder = new ResolvedTypeParametersMap.Builder(); for (int i = 0; i < typeArguments.size(); i++) { @@ -87,20 +75,20 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L this.typeDeclaration = typeDeclaration; } - // + // // Public Object methods - // - + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedReferenceType that = (ResolvedReferenceType) o; - - if (!typeDeclaration.equals(that.typeDeclaration)) return false; - if (!typeParametersMap.equals(that.typeParametersMap)) return false; - + if (!typeDeclaration.equals(that.typeDeclaration)) + return false; + if (!typeParametersMap.equals(that.typeParametersMap)) + return false; return true; } @@ -113,33 +101,28 @@ public int hashCode() { @Override public String toString() { - return "ReferenceType{" + getQualifiedName() + - ", typeParametersMap=" + typeParametersMap + - '}'; + return "ReferenceType{" + getQualifiedName() + ", typeParametersMap=" + typeParametersMap + '}'; } - /// - /// Relation with other types - /// - + // / + // / Relation with other types + // / @Override public final boolean isReferenceType() { return true; } - /// - /// Downcasting - /// - + // / + // / Downcasting + // / @Override public ResolvedReferenceType asReferenceType() { return this; } - /// - /// Naming - /// - + // / + // / Naming + // / @Override public String describe() { StringBuilder sb = new StringBuilder(); @@ -150,30 +133,25 @@ public String describe() { } if (!typeParametersMap().isEmpty()) { sb.append("<"); - sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream() - .map(tp -> typeParametersMap().getValue(tp).describe()) - .collect(Collectors.toList()))); + sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream().map(tp -> typeParametersMap().getValue(tp).describe()).collect(Collectors.toList()))); sb.append(">"); } return sb.toString(); } - /// - /// TypeParameters - /// - + // / + // / TypeParameters + // / /** * Execute a transformation on all the type parameters of this element. */ public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer); @Override - public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, - Map inferredTypes) { + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map inferredTypes) { if (replaced == null) { throw new IllegalArgumentException(); } - ResolvedReferenceType result = this; int i = 0; for (ResolvedType tp : this.typeParametersValues()) { @@ -190,34 +168,30 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe } i++; } - List values = result.typeParametersValues(); // FIXME if (values.contains(tpToReplace)) { int index = values.indexOf(tpToReplace); values.set(index, replaced); - if(result.getTypeDeclaration().isPresent()) { + if (result.getTypeDeclaration().isPresent()) { return create(result.getTypeDeclaration().get(), values); } } - return result; } - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * This method checks if ThisType t = new OtherType() would compile. */ @Override public abstract boolean isAssignableBy(ResolvedType other); - /// - /// Ancestors - /// - + // / + // / Ancestors + // / /** * Return all ancestors, that means all superclasses and interfaces. * This list should always include Object (unless this is a reference to Object). @@ -241,23 +215,16 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe public abstract List getDirectAncestors(); public final List getAllInterfacesAncestors() { - return getAllAncestors().stream() - .filter(it -> it.getTypeDeclaration().isPresent()) - .filter(it -> it.getTypeDeclaration().get().isInterface()) - .collect(Collectors.toList()); + return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isInterface()).collect(Collectors.toList()); } public final List getAllClassesAncestors() { - return getAllAncestors().stream() - .filter(it -> it.getTypeDeclaration().isPresent()) - .filter(it -> it.getTypeDeclaration().get().isClass()) - .collect(Collectors.toList()); + return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isClass()).collect(Collectors.toList()); } - /// - /// Type parameters - /// - + // / + // / Type parameters + // / /** * Get the type associated with the type parameter with the given name. * It returns Optional.empty unless the type declaration declares a type parameter with the given name. @@ -298,10 +265,9 @@ public ResolvedTypeParametersMap typeParametersMap() { return typeParametersMap; } - /// - /// Other methods introduced by ReferenceType - /// - + // / + // / Other methods introduced by ReferenceType + // / /** * Corresponding TypeDeclaration */ @@ -373,10 +339,10 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty if (typeParameterDeclaration.declaredOnMethod()) { throw new IllegalArgumentException(); } - if(!this.getTypeDeclaration().isPresent()) { - return Optional.empty(); // TODO: Consider IllegalStateException or similar + if (!this.getTypeDeclaration().isPresent()) { + // TODO: Consider IllegalStateException or similar + return Optional.empty(); } - String typeId = this.getTypeDeclaration().get().getId(); if (typeId.equals(typeParameterDeclaration.getContainerId())) { return Optional.of(this.typeParametersMap().getValue(typeParameterDeclaration)); @@ -397,17 +363,14 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty * that have been overwritten. */ public List getAllMethods() { - if(!this.getTypeDeclaration().isPresent()) { - return new ArrayList<>(); // empty list -- consider IllegalStateException or similar + if (!this.getTypeDeclaration().isPresent()) { + // empty list -- consider IllegalStateException or similar + return new ArrayList<>(); } - // Get the methods declared directly on this. - List allMethods = new LinkedList<>( - this.getTypeDeclaration().get().getDeclaredMethods() - ); + List allMethods = new LinkedList<>(this.getTypeDeclaration().get().getDeclaredMethods()); // Also get methods inherited from ancestors. getDirectAncestors().forEach(a -> allMethods.addAll(a.getAllMethods())); - return allMethods; } @@ -416,32 +379,22 @@ public List getAllMethods() { * type plus all declared fields which are not private. */ public List getAllFieldsVisibleToInheritors() { - List res = new LinkedList<>(this.getDeclaredFields().stream() - .filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList())); - - getDirectAncestors().forEach(a -> - res.addAll(a.getAllFieldsVisibleToInheritors())); - + List res = new LinkedList<>(this.getDeclaredFields().stream().filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList())); + getDirectAncestors().forEach(a -> res.addAll(a.getAllFieldsVisibleToInheritors())); return res; } public List getAllMethodsVisibleToInheritors() { - return this.getAllMethods().stream() - .filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList()); + return this.getAllMethods().stream().filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); } - // + // // Protected methods - // - + // protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParameters); protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap) { - return create(typeDeclaration, typeDeclaration.getTypeParameters().stream() - .map(typeParametersMap::getValue) - .collect(Collectors.toList())); + return create(typeDeclaration, typeDeclaration.getTypeParameters().stream().map(typeParametersMap::getValue).collect(Collectors.toList())); } protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration); @@ -483,15 +436,11 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) } } else { if (thisParam instanceof ResolvedTypeVariable && otherParam instanceof ResolvedTypeVariable) { - List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds() - .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) - .collect(Collectors.toList()); - List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds() - .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) - .collect(Collectors.toList()); + List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); + List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); return thisBounds.size() == otherBounds.size() && otherBounds.containsAll(thisBounds); } else if (!(thisParam instanceof ResolvedTypeVariable) && otherParam instanceof ResolvedTypeVariable) { - return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable)otherParam); + return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable) otherParam); } else if (thisParam instanceof ResolvedTypeVariable && !(otherParam instanceof ResolvedTypeVariable)) { return compareConsideringVariableTypeParameters(otherParam, (ResolvedTypeVariable) thisParam); } @@ -504,22 +453,18 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) return false; } - // + // // Private methods - // - + // private boolean compareConsideringVariableTypeParameters(ResolvedType referenceType, ResolvedTypeVariable typeVariable) { // verify if the ResolvedTypeVariable has only one type variable and the bound is - // not a reference type with a bound parameter + // not a reference type with a bound parameter // for example EnumSet noneOf(Class elementType) List bounds = typeVariable.asTypeVariable().asTypeParameter().getBounds(); if (bounds.size() == 1) { ResolvedType boundType = bounds.get(0).getType(); - boolean hasTypeParameter = boundType.isReferenceType() - && !boundType.asReferenceType().typeParametersMap.isEmpty(); - return hasTypeParameter - ? compareConsideringTypeParameters(boundType.asReferenceType()) - : boundType.isAssignableBy(referenceType); + boolean hasTypeParameter = boundType.isReferenceType() && !boundType.asReferenceType().typeParametersMap.isEmpty(); + return hasTypeParameter ? compareConsideringTypeParameters(boundType.asReferenceType()) : boundType.isAssignableBy(referenceType); } return false; } @@ -537,7 +482,6 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap); - /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -547,9 +491,8 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration * @see https://github.com/javaparser/javaparser/issues/2044 */ public boolean isJavaLangObject() { - return this.isReferenceType() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(java.lang.Object.class.getCanonicalName()); + return this.isReferenceType() && // Consider anonymous classes + hasName() && getQualifiedName().equals(java.lang.Object.class.getCanonicalName()); } /** @@ -557,16 +500,13 @@ && hasName() // Consider anonymous classes * @see ResolvedReferenceTypeDeclaration#isJavaLangEnum() */ public boolean isJavaLangEnum() { - return this.isReferenceType() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(java.lang.Enum.class.getCanonicalName()); - } - - - /// - /// boxing/unboxing capability - /// - + return this.isReferenceType() && // Consider anonymous classes + hasName() && getQualifiedName().equals(java.lang.Enum.class.getCanonicalName()); + } + + // / + // / boxing/unboxing capability + // / /* * Returns true if the reference type can be unboxed to the primitive type * For example : Integer to int @@ -574,7 +514,7 @@ && hasName() // Consider anonymous classes public boolean isUnboxable() { return Arrays.stream(ResolvedPrimitiveType.values()).anyMatch(pt -> getQualifiedName().equals(pt.getBoxTypeQName())); } - + /* * Returns true if the reference type can be unboxed to the specified primitive type * For example : Integer to int @@ -582,12 +522,11 @@ public boolean isUnboxable() { public boolean isUnboxableTo(ResolvedPrimitiveType primitiveType) { return primitiveType.getBoxTypeQName().equals(this.asReferenceType().describe()); } - + /* * Returns the optional corresponding primitive type */ public Optional toUnboxedType() { return Arrays.stream(ResolvedPrimitiveType.values()).filter(pt -> this.asReferenceType().getQualifiedName().equals(pt.getBoxTypeQName())).findFirst(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java index 17b1e20b21..89f5387ca9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java @@ -18,16 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; - /** *

A resolved type.

*
    @@ -50,10 +49,9 @@ */ public interface ResolvedType { - /// - /// Relation with other types - /// - + // / + // / Relation with other types + // / /** * @return true, if this type represent an array - otherwise false. */ @@ -104,7 +102,9 @@ default boolean isReference() { /** * Is this a lambda constraint type? */ - default boolean isConstraint() { return false; } + default boolean isConstraint() { + return false; + } /** * Can this be seen as a ReferenceTypeUsage? @@ -125,15 +125,14 @@ default boolean isTypeVariable() { default boolean isWildcard() { return false; } - + default boolean isInferenceVariable() { return false; } - /// - /// Downcasting - /// - + // / + // / Downcasting + // / default ResolvedArrayType asArrayType() { throw new UnsupportedOperationException(String.format("%s is not an Array", this)); } @@ -166,16 +165,14 @@ default ResolvedUnionType asUnionType() { throw new UnsupportedOperationException(String.format("%s is not a union type", this)); } - /// - /// Naming - /// - + // / + // / Naming + // / String describe(); - /// - /// TypeParameters - /// - + // / + // / TypeParameters + // / /** * Replace all variables referring to the given TypeParameter with the given value. * By replacing these values I could also infer some type equivalence. @@ -199,20 +196,18 @@ default boolean mention(List typeParameters) { throw new UnsupportedOperationException(this.getClass().getCanonicalName()); } - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * This method checks if ThisType t = new OtherType() would compile. */ boolean isAssignableBy(ResolvedType other); - + /* * Returns true if the ResolvedType is a numeric */ default boolean isNumericType() { - return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt-> rpt.isAssignableBy(this)); + return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt -> rpt.isAssignableBy(this)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java index 68d6d7719d..175736d722 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; /** @@ -26,5 +25,6 @@ */ @FunctionalInterface public interface ResolvedTypeTransformer { + ResolvedType transform(ResolvedType type); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java index 3eae604197..64faa60aa0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -51,15 +50,17 @@ public String qualifiedName() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedTypeVariable that = (ResolvedTypeVariable) o; - - if (!typeParameter.getName().equals(that.typeParameter.getName())) return false; - if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false; - if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false; - + if (!typeParameter.getName().equals(that.typeParameter.getName())) + return false; + if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) + return false; + if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) + return false; return true; } @@ -80,7 +81,7 @@ public boolean isPrimitive() { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map inferredTypes) { - if(tpToBeReplaced.getName().equals(this.typeParameter.getName())){ + if (tpToBeReplaced.getName().equals(this.typeParameter.getName())) { inferredTypes.put(this.asTypeParameter(), replaced); return replaced; } else { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java index 68098b3cd9..33e9784ff9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import java.util.*; @@ -30,6 +29,7 @@ * @author Federico Tomassetti */ public class ResolvedUnionType implements ResolvedType { + private List elements; public ResolvedUnionType(List elements) { @@ -40,24 +40,21 @@ public ResolvedUnionType(List elements) { } public Optional getCommonAncestor() { - Optional> reduce = elements.stream() - .map(ResolvedType::asReferenceType) - .map(ResolvedReferenceType::getAllAncestors) - .reduce((a, b) -> { - ArrayList common = new ArrayList<>(a); - common.retainAll(b); - return common; - }); + Optional> reduce = elements.stream().map(ResolvedType::asReferenceType).map(ResolvedReferenceType::getAllAncestors).reduce((a, b) -> { + ArrayList common = new ArrayList<>(a); + common.retainAll(b); + return common; + }); return reduce.orElse(new ArrayList<>()).stream().findFirst(); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedUnionType that = (ResolvedUnionType) o; - return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java index f7989c48fc..026ab9af0f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; /** @@ -27,6 +26,7 @@ * @author Federico Tomassetti */ public class ResolvedVoidType implements ResolvedType { + public static final ResolvedType INSTANCE = new ResolvedVoidType(); private ResolvedVoidType() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java index 16e2b19aed..bba8d293c9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -40,6 +39,7 @@ public class ResolvedWildcard implements ResolvedType { public static ResolvedWildcard UNBOUNDED = new ResolvedWildcard(null, null); private BoundType type; + private ResolvedType boundedType; private ResolvedWildcard(BoundType type, ResolvedType boundedType) { @@ -63,10 +63,7 @@ public static ResolvedWildcard extendsBound(ResolvedType type) { @Override public String toString() { - return "WildcardUsage{" + - "type=" + type + - ", boundedType=" + boundedType + - '}'; + return "WildcardUsage{" + "type=" + type + ", boundedType=" + boundedType + '}'; } public boolean isWildcard() { @@ -79,14 +76,15 @@ public ResolvedWildcard asWildcard() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ResolvedWildcard)) return false; - + if (this == o) + return true; + if (!(o instanceof ResolvedWildcard)) + return false; ResolvedWildcard that = (ResolvedWildcard) o; - - if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) return false; - if (type != that.type) return false; - + if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) + return false; + if (type != that.type) + return false; return true; } @@ -132,7 +130,7 @@ public ResolvedType getBoundedType() { @Override public boolean isAssignableBy(ResolvedType other) { if (boundedType == null) { - //return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); + // return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); return false; } else if (type == BoundType.SUPER) { return boundedType.isAssignableBy(other); @@ -176,8 +174,7 @@ public boolean isLowerBounded() { } public enum BoundType { - SUPER, - EXTENDS - } + SUPER, EXTENDS + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java index c84b3e17bb..012fd63994 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -52,7 +51,6 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { } } } - if (type.isWildcard() && type.asWildcard().isBounded()) { if (type.asWildcard().isExtends()) { return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); @@ -60,11 +58,9 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); } } - if (type.isReferenceType()) { type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType); } - return type; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java index 249c40be24..c8ecfd2523 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -35,7 +34,9 @@ public class ResolvedTypeParametersMap { public static class Builder { + private Map nameToValue; + private Map nameToDeclaration; public Builder() { @@ -43,8 +44,7 @@ public Builder() { nameToDeclaration = new HashMap<>(); } - private Builder(Map nameToValue, - Map nameToDeclaration) { + private Builder(Map nameToValue, Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -55,8 +55,7 @@ public ResolvedTypeParametersMap build() { return new ResolvedTypeParametersMap(nameToValue, nameToDeclaration); } - public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, - ResolvedType value) { + public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, ResolvedType value) { // TODO: we shouldn't just silently overwrite existing types! String qualifiedName = typeParameter.getQualifiedName(); nameToValue.put(qualifiedName, value); @@ -67,13 +66,12 @@ public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ResolvedTypeParametersMap)) return false; - + if (this == o) + return true; + if (!(o instanceof ResolvedTypeParametersMap)) + return false; ResolvedTypeParametersMap that = (ResolvedTypeParametersMap) o; - return nameToValue.equals(that.nameToValue) && nameToDeclaration.equals(that.nameToDeclaration); - } @Override @@ -83,20 +81,18 @@ public int hashCode() { @Override public String toString() { - return "TypeParametersMap{" + - "nameToValue=" + nameToValue + - '}'; + return "TypeParametersMap{" + "nameToValue=" + nameToValue + '}'; } private Map nameToValue; + private Map nameToDeclaration; public static ResolvedTypeParametersMap empty() { return new Builder().build(); } - private ResolvedTypeParametersMap(Map nameToValue, - Map nameToDeclaration) { + private ResolvedTypeParametersMap(Map nameToValue, Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -120,11 +116,11 @@ public Optional getValueBySignature(String signature) { } } - public List getNames(){ + public List getNames() { return new ArrayList<>(nameToValue.keySet()); } - public List getTypes(){ + public List getTypes() { return new ArrayList<>(nameToValue.values()); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java index ec05f7fe73..17c2cbe900 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; /** @@ -27,5 +26,6 @@ * @author Federico Tomassetti */ public interface ResolvedTypeParametrized { + ResolvedTypeParametersMap typeParametersMap(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java index 0dd222a049..178a84745f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.util.HashMap; import java.util.Map; public class ClassUtils { + /** * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java index 6d7ffd52c3..674e93bd52 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.io.File; @@ -33,6 +32,7 @@ * Utilities that can be useful when generating code. */ public final class CodeGenerationUtils { + private CodeGenerationUtils() { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java index fc759bfa3e..fc7a7991d1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.JavaParser; @@ -47,7 +46,6 @@ default Optional getRoot(Path file) { try { final JavaParser javaParser = new JavaParser(getParserConfiguration()); final ParseResult parseResult = javaParser.parse(file); - if (parseResult.isSuccessful()) { if (parseResult.getProblems().isEmpty()) { if (parseResult.getResult().isPresent()) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java index ea84d25acd..287ad7415a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java @@ -13,6 +13,7 @@ * @see https://github.com/javaparser/javaparser/issues/2647 */ public enum LineSeparator { + /** * The CR {@code \r} line ending is the default line separator for classic MacOS */ @@ -28,13 +29,7 @@ public enum LineSeparator { /** * This line ending is set to whatever the host system's line separator is */ - SYSTEM( - System.getProperty("line.separator"), - "SYSTEM : (" + System.getProperty("line.separator") - .replace("\r", "\\r") - .replace("\n", "\\n") + - ")" - ), + SYSTEM(System.getProperty("line.separator"), "SYSTEM : (" + System.getProperty("line.separator").replace("\r", "\\r").replace("\n", "\\n") + ")"), /** * The ARBITRARY line ending can be used where we do not care about the line separator, * only that we use the same one consistently @@ -56,6 +51,7 @@ public enum LineSeparator { NONE("", "NONE"); private final String text; + private final String description; LineSeparator(String text, String description) { @@ -75,7 +71,6 @@ public static LineSeparator detect(String string) { int countCr = count(string, "\r"); int countLf = count(string, "\n"); int countCrLf = count(string, "\r\n"); - return getLineEnding(countCr, countLf, countCrLf); } @@ -84,7 +79,6 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (noLineEndings) { return NONE; } - boolean crOnly = countCr > 0 && countLf == 0 && countCrLf == 0; if (crOnly) { return CR; @@ -93,13 +87,11 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (lfOnly) { return LF; } - // Note that wherever \r\n are found, there will also be an equal number of \r and \n characters found. boolean crLfOnly = countCr == countLf && countLf == countCrLf; if (crLfOnly) { return CRLF; } - // Not zero line endings, and not a single line ending, thus is mixed. return MIXED; } @@ -148,10 +140,7 @@ public boolean isStandardEol() { } public String asEscapedString() { - String result = text - .replace("\r", "\\r") - .replace("\n", "\\n"); - + String result = text.replace("\r", "\\r").replace("\n", "\\n"); return result; } @@ -161,14 +150,13 @@ public String asRawString() { // TODO: Determine if this should be used within TokenTypes.java -- thus leaving this as private for now. private Optional asJavaTokenKind() { - if(this == CR) { + if (this == CR) { return Optional.of(JavaToken.Kind.OLD_MAC_EOL); - } else if(this == LF) { + } else if (this == LF) { return Optional.of(JavaToken.Kind.UNIX_EOL); - } else if(this == CRLF) { + } else if (this == CRLF) { return Optional.of(JavaToken.Kind.WINDOWS_EOL); } - return Optional.empty(); } @@ -176,5 +164,4 @@ private Optional asJavaTokenKind() { public String toString() { return asRawString(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java index 67062f4061..296d2294a1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.io.IOException; @@ -34,10 +33,12 @@ * See a blog about this */ public class Log { + /** * This adapter logs to standard out and standard error. */ public static class StandardOutStandardErrorAdapter implements Adapter { + @Override public void info(Supplier messageSupplier) { System.out.println(messageSupplier.get()); @@ -64,7 +65,8 @@ public void error(Supplier throwableSupplier, Supplier messag } private void printStackTrace(Throwable throwable) { - try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { + try (StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw)) { throwable.printStackTrace(pw); trace(sw::toString); } catch (IOException e) { @@ -77,6 +79,7 @@ private void printStackTrace(Throwable throwable) { * This adapter logs nothing. */ public static class SilentAdapter implements Adapter { + @Override public void info(Supplier messageSupplier) { } @@ -129,7 +132,6 @@ private static Supplier makeFormattingSupplier(String format, Supplier type of object b. */ public class Pair { + public final A a; + public final B b; public Pair(A a, B b) { @@ -42,14 +43,15 @@ public Pair(A a, B b) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Pair pair = (Pair) o; - - if (!Objects.equals(a, pair.a)) return false; - if (!Objects.equals(b, pair.b)) return false; - + if (!Objects.equals(a, pair.a)) + return false; + if (!Objects.equals(b, pair.b)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java index f51eb80fe0..4016cad293 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java @@ -18,17 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import static java.nio.file.FileVisitResult.*; @@ -64,7 +59,9 @@ public ProjectRoot collect(Path path) { ProjectRoot projectRoot = new ProjectRoot(path, parserConfiguration); try { Files.walkFileTree(path, new SimpleFileVisitor() { + Path current_root; + PathMatcher javaMatcher = getPathMatcher("glob:**.java"); @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java index 840b357a3b..e14788de16 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.Position; @@ -81,10 +80,8 @@ private static int compare(Node a, Node b, boolean ignoringAnnotations) { return signLine; } } - Position aBegin = a.getBegin().get(); Position bBegin = b.getBegin().get(); - int signLine = signum(aBegin.line - bBegin.line); if (signLine == 0) { return signum(aBegin.column - bBegin.column); @@ -110,7 +107,6 @@ private static int beginLineWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.line; } - private static int beginColumnWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.column; } @@ -120,11 +116,7 @@ private static Node firstNonAnnotationNode(Node node) { if (node instanceof ClassOrInterfaceDeclaration) { // Modifiers appear before the class name -- ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.getRange().isPresent()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getName(); } else { @@ -133,11 +125,7 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof MethodDeclaration) { // Modifiers appear before the class name -- MethodDeclaration casted = (MethodDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.getRange().isPresent()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getType(); } else { @@ -146,11 +134,7 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof FieldDeclaration) { // Modifiers appear before the class name -- FieldDeclaration casted = (FieldDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.getRange().isPresent()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getVariable(0).getType(); } else { @@ -161,7 +145,6 @@ private static Node firstNonAnnotationNode(Node node) { } } - /** * Compare the position of two nodes. Optionally include annotations within the range checks. * This method takes into account whether the nodes are within the same compilation unit. @@ -179,38 +162,28 @@ public static boolean nodeContains(Node container, Node other, boolean ignoringA if (!other.getRange().isPresent()) { throw new IllegalArgumentException("Cannot compare the positions of nodes if contained node does not have a range."); } - -// // FIXME: Not all nodes seem to have the compilation unit available? -// if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { -// // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), -// // ... or both not within a CU (i.e. both are Optional.empty()) -// return false; -// } - + // // FIXME: Not all nodes seem to have the compilation unit available? + // if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { + // // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), + // // ... or both not within a CU (i.e. both are Optional.empty()) + // return false; + // } final boolean nodeCanHaveAnnotations = container instanceof NodeWithAnnotations; -// final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; + // final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) { // No special consideration required - perform simple range check. return container.containsWithinRange(other); } - if (!container.containsWithinRange(other)) { return false; } - if (!nodeCanHaveAnnotations) { return true; } - // If the node is contained, but it comes immediately after the annotations, // let's not consider it contained (i.e. it must be "strictly contained"). Node nodeWithoutAnnotations = firstNonAnnotationNode(container); - Range rangeWithoutAnnotations = container.getRange().get() - .withBegin(nodeWithoutAnnotations.getBegin().get()); - return rangeWithoutAnnotations -// .contains(other.getRange().get()); - .strictlyContains(other.getRange().get()); - + Range rangeWithoutAnnotations = container.getRange().get().withBegin(nodeWithoutAnnotations.getBegin().get()); + return rangeWithoutAnnotations.strictlyContains(other.getRange().get()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java index 9f276c0aa2..fd9b3452f3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; @@ -40,7 +39,9 @@ public class ProjectRoot { private final Path root; + private final Map cache = new ConcurrentHashMap<>(); + private final ParserConfiguration parserConfiguration; public ProjectRoot(Path root) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java index cd00bf8bfc..378e754975 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; /** @@ -27,16 +26,19 @@ *

    Java 8 offers the very nice Collectors.joining(String, String, String) which does the same thing. */ public class SeparatedItemStringBuilder { + private final String separator; + private final String postfix; + private boolean hasItems = false; + private StringBuilder builder; public SeparatedItemStringBuilder(String prefix, String separator, String postfix) { builder = new StringBuilder(prefix); this.separator = separator; this.postfix = postfix; - } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java index 0534f32b4b..d9aff77330 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java @@ -18,18 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageAbsolutePath; -import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; -import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.nio.file.FileVisitResult.CONTINUE; -import static java.nio.file.FileVisitResult.SKIP_SUBTREE; -import static java.nio.file.FileVisitResult.TERMINATE; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseProblemException; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.DefaultPrettyPrinter; import java.io.IOException; import java.nio.charset.Charset; @@ -48,12 +44,11 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.printer.DefaultPrettyPrinter; +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.CodeGenerationUtils.*; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.nio.file.FileVisitResult.*; /** * A collection of Java source files located in one directory and its subdirectories on the file system. The root directory @@ -66,9 +61,12 @@ *

*/ public class SourceRoot { + @FunctionalInterface public interface Callback { + enum Result { + SAVE, DONT_SAVE, TERMINATE } @@ -81,9 +79,13 @@ enum Result { } private final Path root; + private final Map> cache = new ConcurrentHashMap<>(); + private ParserConfiguration parserConfiguration = new ParserConfiguration(); + private Function printer = new DefaultPrettyPrinter()::print; + private static final Pattern JAVA_IDENTIFIER = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*"); /** @@ -126,8 +128,7 @@ public ParseResult tryToParse(String startPackage, String filen } final Path path = root.resolve(relativePath); Log.trace("Parsing %s", () -> path); - final ParseResult result = new JavaParser(configuration) - .parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); + final ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(path, configuration.getCharacterEncoding())); cache.put(relativePath, result); return result; @@ -158,6 +159,7 @@ public List> tryToParse(String startPackage) throws logPackage(startPackage); final Path path = packageAbsolutePath(root, startPackage); Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && file.toString().endsWith(".java")) { @@ -217,10 +219,7 @@ public List> tryToParseParallelized(String startPac if (!attrs.isDirectory() && file.toString().endsWith(".java")) { Path relative = root.relativize(file.getParent()); try { - tryToParse( - relative.toString(), - file.getFileName().toString(), - parserConfiguration); + tryToParse(relative.toString(), file.getFileName().toString(), parserConfiguration); } catch (IOException e) { Log.error(e); } @@ -273,7 +272,7 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur Log.trace("Parsing %s", () -> localPath); ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(absolutePath, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(absolutePath, configuration.getCharacterEncoding())); - switch (callback.process(localPath, absolutePath, result)) { + switch(callback.process(localPath, absolutePath, result)) { case SAVE: result.getResult().ifPresent(cu -> save(cu, absolutePath)); case DONT_SAVE: @@ -292,8 +291,7 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur * @param startPackage The package containing the file * @param filename The name of the file */ - public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback - callback) throws IOException { + public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback callback) throws IOException { assertNotNull(startPackage); assertNotNull(filename); assertNotNull(configuration); @@ -325,6 +323,7 @@ public SourceRoot parse(String startPackage, ParserConfiguration configuration, final Path path = packageAbsolutePath(root, startPackage); if (Files.exists(path)) { Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) { @@ -422,10 +421,7 @@ public SourceRoot add(String startPackage, String filename, CompilationUnit comp assertNotNull(compilationUnit); Log.trace("Adding new file %s.%s", () -> startPackage, () -> filename); final Path path = fileInPackageRelativePath(startPackage, filename); - final ParseResult parseResult = new ParseResult<>( - compilationUnit, - new ArrayList<>(), - null); + final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); cache.put(path, parseResult); return this; } @@ -439,10 +435,7 @@ public SourceRoot add(CompilationUnit compilationUnit) { if (compilationUnit.getStorage().isPresent()) { final Path path = compilationUnit.getStorage().get().getPath(); Log.trace("Adding new file %s", () -> path); - final ParseResult parseResult = new ParseResult<>( - compilationUnit, - new ArrayList<>(), - null); + final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); cache.put(path, parseResult); } else { throw new AssertionError("Files added with this method should have their path set."); @@ -526,10 +519,7 @@ public List> getCache() { * added manually. */ public List getCompilationUnits() { - return cache.values().stream() - .filter(ParseResult::isSuccessful) - .map(p -> p.getResult().get()) - .collect(Collectors.toList()); + return cache.values().stream().filter(ParseResult::isSuccessful).map(p -> p.getResult().get()).collect(Collectors.toList()); } /** @@ -577,7 +567,9 @@ public Function getPrinter() { private static class ParallelParse extends RecursiveAction { private static final long serialVersionUID = 1L; + private final Path path; + private final VisitFileCallback callback; ParallelParse(Path path, VisitFileCallback callback) { @@ -590,6 +582,7 @@ protected void compute() { final List walks = new ArrayList<>(); try { Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (!SourceRoot.isSensibleDirectoryToEnter(dir)) { @@ -613,13 +606,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { } catch (IOException e) { Log.error(e); } - for (ParallelParse w : walks) { w.join(); } } interface VisitFileCallback { + FileVisitResult process(Path file, BasicFileAttributes attrs); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java index 0156d11757..04414ad9e1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.JavaParser; @@ -42,11 +41,11 @@ /** * A collection of Java source files and its sub-directories located in a ZIP or JAR file on the file system. * Files can be parsed with a callback. - * */ public class SourceZip { private final Path zipPath; + private ParserConfiguration parserConfiguration; /** @@ -71,7 +70,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { assertNotNull(configuration); this.zipPath = zipPath.normalize(); this.parserConfiguration = configuration; - Log.info("New source zip at \"%s\"", ()->this.zipPath); + Log.info("New source zip at \"%s\"", () -> this.zipPath); } /** @@ -83,7 +82,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { * @throws IOException If an error occurs while trying to parse the given source. */ public List>> parse() throws IOException { - Log.info("Parsing zip at \"%s\"", ()-> zipPath); + Log.info("Parsing zip at \"%s\"", () -> zipPath); List>> results = new ArrayList<>(); parse((path, result) -> results.add(new Pair<>(path, result))); return results; @@ -98,14 +97,13 @@ public List>> parse() throws IOException * @throws IOException If an error occurs while trying to parse the given source. */ public SourceZip parse(Callback callback) throws IOException { - Log.info("Parsing zip at \"%s\"", ()-> zipPath); + Log.info("Parsing zip at \"%s\"", () -> zipPath); JavaParser javaParser = new JavaParser(parserConfiguration); try (ZipFile zipFile = new ZipFile(zipPath.toFile())) { for (ZipEntry entry : Collections.list(zipFile.entries())) { if (!entry.isDirectory() && entry.getName().endsWith(".java")) { - Log.info("Parsing zip entry \"%s\"", ()-> entry.getName()); - final ParseResult result = javaParser.parse(COMPILATION_UNIT, - provider(zipFile.getInputStream(entry))); + Log.info("Parsing zip entry \"%s\"", () -> entry.getName()); + final ParseResult result = javaParser.parse(COMPILATION_UNIT, provider(zipFile.getInputStream(entry))); callback.process(Paths.get(entry.getName()), result); } } @@ -136,7 +134,7 @@ public interface Callback { public Path getZipPath() { return zipPath; } - + public ParserConfiguration getParserConfiguration() { return parserConfiguration; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java index 113612edd2..e858f727f1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java @@ -79,49 +79,15 @@ public static String unescapeJavaTextBlock(final String input) { return UNESCAPE_JAVA_TEXT_BLOCK.translate(input); } - private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][]{ - {"\\b", "\b"}, - {"\\n", "\n"}, - {"\\t", "\t"}, - {"\\f", "\f"}, - {"\\r", "\r"}}); - - private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][]{ - {"\b", "\\b"}, - {"\n", "\\n"}, - {"\t", "\\t"}, - {"\f", "\\f"}, - {"\r", "\\r"}}); - - private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator( - new LookupTranslator( - new String[][]{ - {"\"", "\\\""}, - {"\\", "\\\\"}, - }), - JAVA_CTRL_CHARS_ESCAPE); - - private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator( - new OctalUnescaper(), - new UnicodeUnescaper(), - JAVA_CTRL_CHARS_UNESCAPE, - new LookupTranslator(new String[][]{ - {"\\\\", "\\"}, - {"\\\"", "\""}, - {"\\'", "'"}, - {"\\", ""}})); - - private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator( - new OctalUnescaper(), - new UnicodeUnescaper(), - JAVA_CTRL_CHARS_UNESCAPE, - new LookupTranslator(new String[][]{ - {"\\\\", "\\"}, - {"\\\"", "\""}, - {"\\'", "'"}, - {"\\", ""}, - {"\\s", " "}, - {"\\\n", ""}})); + private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][] { { "\\b", "\b" }, { "\\n", "\n" }, { "\\t", "\t" }, { "\\f", "\f" }, { "\\r", "\r" } }); + + private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][] { { "\b", "\\b" }, { "\n", "\\n" }, { "\t", "\\t" }, { "\f", "\\f" }, { "\r", "\\r" } }); + + private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator(new LookupTranslator(new String[][] { { "\"", "\\\"" }, { "\\", "\\\\" } }), JAVA_CTRL_CHARS_ESCAPE); + + private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" } })); + + private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" }, { "\\s", " " }, { "\\\n", "" } })); /** * Adapted from apache commons-lang3 project. @@ -221,8 +187,11 @@ private void translate(final CharSequence input, final Writer out) throws IOExce private static class LookupTranslator extends CharSequenceTranslator { private final HashMap lookupMap; + private final HashSet prefixSet; + private final int shortest; + private final int longest; /** @@ -271,7 +240,6 @@ protected int translate(final CharSequence input, final int index, final Writer for (int i = max; i >= shortest; i--) { final CharSequence subSeq = input.subSequence(index, index + i); final String result = lookupMap.get(subSeq.toString()); - if (result != null) { out.write(result); return i; @@ -318,7 +286,6 @@ protected int translate(final CharSequence input, final int index, final Writer } return 0; } - } /** @@ -340,23 +307,21 @@ private static class OctalUnescaper extends CharSequenceTranslator { */ @Override protected int translate(final CharSequence input, final int index, final Writer out) throws IOException { - final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ + // how many characters left, ignoring the first \ + final int remaining = input.length() - index - 1; final StringBuilder builder = new StringBuilder(); if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) { final int next = index + 1; final int next2 = index + 2; final int next3 = index + 3; - // we know this is good as we checked it in the if block above builder.append(input.charAt(next)); - if (remaining > 1 && isOctalDigit(input.charAt(next2))) { builder.append(input.charAt(next2)); if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) { builder.append(input.charAt(next3)); } } - out.write(Integer.parseInt(builder.toString(), 8)); return 1 + builder.length(); } @@ -407,15 +372,12 @@ protected int translate(final CharSequence input, final int index, final Writer while (index + i < input.length() && input.charAt(index + i) == 'u') { i++; } - if (index + i < input.length() && input.charAt(index + i) == '+') { i++; } - if (index + i + 4 <= input.length()) { // Get 4 hex digits final CharSequence unicode = input.subSequence(index + i, index + i + 4); - try { final int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); @@ -424,11 +386,9 @@ protected int translate(final CharSequence input, final int index, final Writer } return i + 4; } - throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) - + "' due to end of CharSequence"); + throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + "' due to end of CharSequence"); } return 0; } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java index 30796b984d..ee71c1fd39 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -29,7 +28,7 @@ import java.util.*; import java.util.function.Function; -import static java.util.Arrays.*; +import static java.util.Arrays.asList; /** * Any kind of utility. @@ -50,7 +49,6 @@ public class Utils { * @deprecated Renamed from {@link #EOL} to make it explicit that we're using the system's line separator. * New code should use {@link LineSeparator#SYSTEM} if referring to the current host system's line separator, * else {@link LineSeparator#CR} or {@link LineSeparator#LF} or {@link LineSeparator#CRLF} if referring to a specific style of line separator. - * */ @Deprecated public static final String SYSTEM_EOL = LineSeparator.SYSTEM.asRawString(); @@ -93,7 +91,7 @@ public static T assertPositive(T number) { public static String escapeEndOfLines(String string) { StringBuilder escapedString = new StringBuilder(); for (char c : string.toCharArray()) { - switch (c) { + switch(c) { case '\n': escapedString.append("\\n"); break; @@ -111,11 +109,9 @@ public static String readerToString(Reader reader) throws IOException { final StringBuilder result = new StringBuilder(); final char[] buffer = new char[8 * 1024]; int numChars; - while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) { result.append(buffer, 0, numChars); } - return result.toString(); } @@ -141,7 +137,6 @@ public static String screamingToCamelCase(String original) { return sb.toString(); } - /** * @param input "aCamelCaseString" * @return "A_CAMEL_CASE_STRING" @@ -199,8 +194,7 @@ private static String stringTransformer(String s, String operationDescription, F if (s.isEmpty()) { throw new IllegalArgumentException(String.format("You cannot %s an empty string", operationDescription)); } - return transformation.apply(s.substring(0, 1)) + - s.substring(1); + return transformation.apply(s.substring(0, 1)) + s.substring(1); } /** @@ -303,7 +297,6 @@ public static String removeFileExtension(String filename) { int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) return filename; - return filename.substring(0, extensionIndex); } @@ -321,11 +314,6 @@ public static String trimTrailingSpaces(String line) { * Checks, if the parent is a unary expression with a minus operator. Used to check for negative literals. */ public static boolean hasUnaryMinusAsParent(Node n) { - return n.getParentNode() - .filter(parent -> parent instanceof UnaryExpr) - .map(parent -> (UnaryExpr) parent) - .map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS) - .orElse(false); + return n.getParentNode().filter(parent -> parent instanceof UnaryExpr).map(parent -> (UnaryExpr) parent).map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS).orElse(false); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java index 05c628eba4..bbe92cc14a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java @@ -18,21 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.stream.Collectors; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.*; +import java.util.stream.Collectors; + /** * A list that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -40,14 +35,15 @@ public class VisitorList implements List { protected List innerList; + protected final GenericVisitor hashcodeVisitor; + protected final GenericVisitor equalsVisitor; /** * Pass the visitors to use for equals and hashcode. */ - public VisitorList(GenericVisitor hashcodeVisitor, - GenericVisitor equalsVisitor) { + public VisitorList(GenericVisitor hashcodeVisitor, GenericVisitor equalsVisitor) { this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; innerList = new ArrayList<>(); @@ -66,9 +62,8 @@ public void add(int index, N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) - if (add(elem)) - modified = true; + for (N elem : col) if (add(elem)) + modified = true; return modified; } @@ -98,9 +93,8 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) - if (!contains(elem)) - return false; + for (Object elem : col) if (!contains(elem)) + return false; return true; } @@ -122,6 +116,7 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { + final Iterator itr = innerList.iterator(); @Override @@ -154,6 +149,7 @@ public ListIterator listIterator() { @Override public ListIterator listIterator(int index) { return new ListIterator() { + final ListIterator itr = innerList.listIterator(index); @Override @@ -216,9 +212,8 @@ public N remove(int index) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) - if (remove(elem)) - modified = true; + for (Object elem : col) if (remove(elem)) + modified = true; return modified; } @@ -243,6 +238,7 @@ public int size() { @Override public List subList(int fromIndex, int toIndex) { return new VisitorList(hashcodeVisitor, equalsVisitor) { + { this.innerList = VisitorList.this.innerList.subList(fromIndex, toIndex); } @@ -271,6 +267,7 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java index be790952dd..8e52848fca 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -37,8 +36,11 @@ * by using another equals and hashcode visitor for those methods. */ public class VisitorMap implements Map { + private final Map innerMap = new HashMap<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; /** @@ -48,7 +50,7 @@ public VisitorMap(GenericVisitor hashcodeVisitor, GenericVisitor< this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; } - + @Override public int size() { return innerMap.size(); @@ -80,6 +82,7 @@ public V put(N key, V value) { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -127,9 +130,7 @@ public void clear() { @Override public Set keySet() { - return innerMap.keySet().stream() - .map(k -> k.overridden) - .collect(Collectors.toSet()); + return innerMap.keySet().stream().map(k -> k.overridden).collect(Collectors.toSet()); } @Override @@ -139,8 +140,6 @@ public Collection values() { @Override public Set> entrySet() { - return innerMap.entrySet().stream() - .map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())) - .collect(Collectors.toSet()); + return innerMap.entrySet().stream().map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())).collect(Collectors.toSet()); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java index d6a07601e5..2109a1f4fb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java @@ -18,20 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.stream.Collectors; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.Visitable; -import com.github.javaparser.ast.visitor.VoidVisitor; - /** * A set that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -39,7 +38,9 @@ public class VisitorSet implements Set { private final Set innerSet = new HashSet<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; /** @@ -58,9 +59,8 @@ public boolean add(N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) - if (add(elem)) - modified = true; + for (N elem : col) if (add(elem)) + modified = true; return modified; } @@ -76,9 +76,8 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) - if (!contains(elem)) - return false; + for (Object elem : col) if (!contains(elem)) + return false; return true; } @@ -90,6 +89,7 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { + final Iterator itr = innerSet.iterator(); @Override @@ -117,9 +117,8 @@ public boolean remove(Object elem) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) - if (remove(elem)) - modified = true; + for (Object elem : col) if (remove(elem)) + modified = true; return modified; } @@ -158,6 +157,7 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -187,5 +187,4 @@ public boolean equals(final Object obj) { return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); } } - } From 1e5ecb35b1cfab4850a38eb2ca8ef65d2866d15e Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 4 Mar 2021 18:13:50 +0000 Subject: [PATCH 014/280] Reverted ModifierVisitor to complain with #3011 (cherry picked from commit a661c20ecebb38da19d328debb6115ba112bca9e) --- .../ast/visitor/ModifierVisitor.java | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) 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 index 64206badd8..93c6b9135b 100644 --- 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 @@ -54,36 +54,36 @@ public class ModifierVisitor implements GenericVisitor { @Override public Visitable visit(final AnnotationDeclaration n, final A arg) { - NodeList> members = modifyList(n.getMembers(), arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList> members = modifyList(n.getMembers(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; - n.setMembers(members); + n.setAnnotations(annotations); n.setModifiers(modifiers); n.setName(name); - n.setAnnotations(annotations); + n.setMembers(members); n.setComment(comment); return n; } @Override public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { - Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null); + NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); + Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null); SimpleName name = (SimpleName) n.getName().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || type == null) return null; - n.setDefaultValue(defaultValue); + n.setAnnotations(annotations); n.setModifiers(modifiers); + n.setDefaultValue(defaultValue); n.setName(name); n.setType(type); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -237,40 +237,40 @@ public Visitable visit(final ClassExpr n, final A arg) { @Override public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList extendedTypes = modifyList(n.getExtendedTypes(), arg); NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); NodeList> members = modifyList(n.getMembers(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; + n.setAnnotations(annotations); + n.setModifiers(modifiers); n.setExtendedTypes(extendedTypes); n.setImplementedTypes(implementedTypes); n.setTypeParameters(typeParameters); n.setMembers(members); - n.setModifiers(modifiers); n.setName(name); - n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final ClassOrInterfaceType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); ClassOrInterfaceType scope = n.getScope().map(s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null); NodeList typeArguments = modifyList(n.getTypeArguments(), arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; + n.setAnnotations(annotations); n.setName(name); n.setScope(scope); n.setTypeArguments(typeArguments); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -307,25 +307,25 @@ public Visitable visit(final ConditionalExpr n, final A arg) { @Override public Visitable visit(final ConstructorDeclaration n, final A arg) { - BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); + NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); + BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList parameters = modifyList(n.getParameters(), arg); ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || name == null) return null; - n.setBody(body); + n.setAnnotations(annotations); n.setModifiers(modifiers); + 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; } @@ -379,38 +379,38 @@ public Visitable visit(final EnclosedExpr n, final A arg) { @Override public Visitable visit(final EnumConstantDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList arguments = modifyList(n.getArguments(), arg); NodeList> classBody = modifyList(n.getClassBody(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; + n.setAnnotations(annotations); n.setArguments(arguments); n.setClassBody(classBody); n.setName(name); - n.setAnnotations(annotations); n.setComment(comment); return n; } @Override public Visitable visit(final EnumDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList entries = modifyList(n.getEntries(), arg); NodeList implementedTypes = modifyList(n.getImplementedTypes(), arg); NodeList> members = modifyList(n.getMembers(), arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; + n.setAnnotations(annotations); + n.setModifiers(modifiers); n.setEntries(entries); n.setImplementedTypes(implementedTypes); n.setMembers(members); - n.setModifiers(modifiers); n.setName(name); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -456,15 +456,15 @@ public Visitable visit(final FieldAccessExpr n, final A arg) { @Override public Visitable visit(final FieldDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); NodeList modifiers = modifyList(n.getModifiers(), arg); NodeList variables = modifyList(n.getVariables(), arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (variables.isEmpty()) return null; + n.setAnnotations(annotations); n.setModifiers(modifiers); n.setVariables(variables); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -518,13 +518,13 @@ public Visitable visit(final IfStmt n, final A arg) { @Override public Visitable visit(final InitializerDeclaration n, final A arg) { - BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); NodeList annotations = modifyList(n.getAnnotations(), arg); + BlockStmt body = (BlockStmt) n.getBody().accept(this, 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.setBody(body); n.setComment(comment); return n; } @@ -621,27 +621,27 @@ public Visitable visit(final MethodCallExpr n, final A arg) { @Override public Visitable visit(final MethodDeclaration n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList modifiers = modifyList(n.getModifiers(), arg); BlockStmt body = n.getBody().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); Type type = (Type) n.getType().accept(this, arg); - NodeList modifiers = modifyList(n.getModifiers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList parameters = modifyList(n.getParameters(), arg); ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null); NodeList thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList typeParameters = modifyList(n.getTypeParameters(), arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null || name == null) return null; + n.setAnnotations(annotations); + n.setModifiers(modifiers); n.setBody(body); n.setType(type); - n.setModifiers(modifiers); n.setName(name); n.setParameters(parameters); n.setReceiverParameter(receiverParameter); n.setThrownExceptions(thrownExceptions); n.setTypeParameters(typeParameters); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -755,13 +755,13 @@ public Visitable visit(final SimpleName n, final A arg) { @Override public Visitable visit(final ArrayType n, final A arg) { - Type componentType = (Type) n.getComponentType().accept(this, arg); NodeList annotations = modifyList(n.getAnnotations(), arg); + Type componentType = (Type) n.getComponentType().accept(this, 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.setComponentType(componentType); n.setComment(comment); return n; } @@ -779,26 +779,26 @@ public Visitable visit(final ArrayCreationLevel n, final A arg) { @Override public Visitable visit(final IntersectionType n, final A arg) { - NodeList elements = modifyList(n.getElements(), arg); NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList elements = modifyList(n.getElements(), 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.setElements(elements); n.setComment(comment); return n; } @Override public Visitable visit(final UnionType n, final A arg) { - NodeList elements = modifyList(n.getElements(), arg); NodeList annotations = modifyList(n.getAnnotations(), arg); + NodeList elements = modifyList(n.getElements(), 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.setElements(elements); n.setComment(comment); return n; } @@ -928,15 +928,15 @@ public Visitable visit(final LocalClassDeclarationStmt n, final A arg) { @Override public Visitable visit(final TypeParameter n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList typeBound = modifyList(n.getTypeBound(), arg); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; + n.setAnnotations(annotations); n.setName(name); n.setTypeBound(typeBound); - n.setAnnotations(annotations); n.setComment(comment); return n; } @@ -1015,13 +1015,13 @@ public Visitable visit(final WhileStmt n, final A arg) { @Override public Visitable visit(final WildcardType n, final A arg) { + NodeList annotations = modifyList(n.getAnnotations(), arg); ReferenceType extendedType = n.getExtendedType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); ReferenceType superType = n.getSuperType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); - NodeList annotations = modifyList(n.getAnnotations(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setAnnotations(annotations); n.setExtendedType(extendedType); n.setSuperType(superType); - n.setAnnotations(annotations); n.setComment(comment); return n; } From dfbd466829fca9047b995b5bf9a28343b81d7c5a Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 27 Mar 2021 00:00:48 +0000 Subject: [PATCH 015/280] Added isReferenceType in ResolvedTypeDeclaration --- .../ResolvedReferenceTypeDeclaration.java | 17 +++++++++++------ .../declarations/ResolvedTypeDeclaration.java | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java index a47c768240..a9ca51612d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java @@ -21,18 +21,18 @@ package com.github.javaparser.resolution.declarations; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -47,6 +47,11 @@ default ResolvedReferenceTypeDeclaration asReferenceType() { return this; } + @Override + default boolean isReferenceType() { + return true; + } + /// /// Ancestors /// diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java index ae7a4a15bb..d1a2cd1720 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java @@ -103,6 +103,13 @@ default boolean isAnnotation() { return false; } + /** + * Is this the declaration of a reference type? + */ + default boolean isReferenceType() { + return false; + } + /** * Is this the declaration of a type parameter? */ From 8412f651e7750d39ef9ac79f2dedf5b588d1b33c Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 27 Mar 2021 00:03:57 +0000 Subject: [PATCH 016/280] Added isTypeParameter and asTypeParameter in ResolvedTypeParameterDeclaration --- .../declarations/ResolvedTypeParameterDeclaration.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index 099b3ffe6f..befa621eb7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -222,6 +222,16 @@ default ResolvedType getUpperBound() { throw new IllegalStateException(); } + @Override + default ResolvedTypeParameterDeclaration asTypeParameter() { + return this; + } + + @Override + default boolean isTypeParameter() { + return true; + } + /** * A Bound on a Type Parameter. */ From 88e547f1a0d498c2153b3eb9b0f93b0961730d04 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 27 Mar 2021 00:07:29 +0000 Subject: [PATCH 017/280] Added unit tests for the new lines --- .../ResolvedReferenceTypeDeclarationTest.java | 8 +++++++- .../declarations/ResolvedTypeDeclarationTest.java | 9 +++++++++ .../ResolvedTypeParameterDeclarationTest.java | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclarationTest.java index 069419e2bc..6ad958ab97 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclarationTest.java @@ -24,12 +24,18 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public interface ResolvedReferenceTypeDeclarationTest extends ResolvedTypeDeclarationTest, ResolvedTypeParametrizableTest { @Override ResolvedReferenceTypeDeclaration createValue(); + @Test + default void isReferenceTypeShouldBeTrue() { + assertTrue(createValue().isReferenceType()); + } + @Test default void getAllFieldsCantBeNull() { assertNotNull(createValue().getAllFields()); @@ -45,4 +51,4 @@ default void getConstructorsCantBeNull() { assertNotNull(createValue().getConstructors()); } -} \ No newline at end of file +} diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclarationTest.java index 23438682c6..f1d6946f4a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclarationTest.java @@ -66,6 +66,15 @@ default void whenDeclarationIsATypeParameterTheCallToTheMethodAsTypeParameterSho assertThrows(UnsupportedOperationException.class, resolvedDeclaration::asTypeParameter); } + @Test + default void whenDeclarationIsAReferenceTypeTheCallToTheMethodAsReferenceTypeShouldNotThrow() { + ResolvedTypeDeclaration resolvedDeclaration = createValue(); + if (resolvedDeclaration.isReferenceType()) + assertDoesNotThrow(resolvedDeclaration::asReferenceType); + else + assertThrows(UnsupportedOperationException.class, resolvedDeclaration::asReferenceType); + } + @Test default void qualifiedNameCantBeNull() { assertNotNull(createValue().getQualifiedName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclarationTest.java index 42766adda8..eb95d6d1e8 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclarationTest.java @@ -21,11 +21,20 @@ package com.github.javaparser.resolution.declarations; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + public interface ResolvedTypeParameterDeclarationTest extends ResolvedTypeDeclarationTest { @Override ResolvedTypeParameterDeclaration createValue(); + @Test + default void isTypeParameter_shouldBeTrue() { + assertTrue(createValue().isTypeParameter()); + } + // TODO: Test ResolvedTypeParameterDeclaration } From 66f25a9034887c22e88bff18657f2e9149c213a3 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 25 Nov 2021 22:27:45 +0000 Subject: [PATCH 018/280] Created TypeSolverBuilder --- .../typesolvers/TypeSolverBuilder.java | 327 ++++++++++++++++++ .../typesolvers/TypeSolverBuilderTest.java | 317 +++++++++++++++++ 2 files changed, 644 insertions(+) create mode 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java new file mode 100644 index 0000000000..35e94e03d8 --- /dev/null +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.resolution.typesolvers; + +import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * TypeSolverBuilder was created with the objective of simplifying + * the process of creating new type solved. Instead of invoking the + * constructor directly, the user can build it using the builder pattern. + * + *

+ * + * Example 1: + * Solve JRE types: + *
+ *

+ *     new TypeSolverBuilder()
+ *          .withCurrentJRE()
+ *          .build()
+ * 
+ * + *

+ * + * Example 2: + * Solve JRE and types defined in foo.jar: + *
+ *

+ *     new TypeSolverBuilder()
+ *          .withCurrentJRE()
+ *          .withJAR("foo.jar")
+ *          .build()
+ * 
+ * + * @author 4everTheOne + */ +public class TypeSolverBuilder { + + private final List typeSolvers = new ArrayList<>(); + + /** + * Append a costum type solver to the build. + * + * @param typeSolver The type solver to be added. + * + * @return the current builder. + */ + public TypeSolverBuilder with(@NonNull TypeSolver typeSolver) { + checkNotNull(typeSolver, "The typeSolver can't be null!"); + + typeSolvers.add(typeSolver); + return this; + } + + // Builders for Reflection + + /** + * Allow the type solver to resolve types that are + * defined in the current Java Runtime Environment (JRE). + *

+ * Some examples of those types are: + * + *

    + *
  • java.lang.Object
  • + *
  • java.lang.String
  • + *
  • java.lang.Math
  • + *
  • ...
  • + *
+ * + * @return the current builder. + * + * @see ReflectionTypeSolver + */ + public TypeSolverBuilder withCurrentJRE() { + TypeSolver javaRuntime = new ReflectionTypeSolver(); + return with(javaRuntime); + } + + /** + * Allow the type solver to resolve types that are + * defined in the current {@link ClassLoader}. + *

+ * Some examples of those types are: + * + *

    + *
  • java.lang.Object
  • + *
  • java.lang.String
  • + *
  • java.lang.Math
  • + *
  • com.github.javaparser.ast.Node
  • + *
  • com.github.javaparser.symbolsolver.resolution.typesolvers.TypeSolverBuilder
  • + *
  • ...
  • + *
+ * + * @return the current builder. + * + * @see ReflectionTypeSolver + */ + public TypeSolverBuilder withCurrentClassloader() { + TypeSolver classLoaderTypeSolver = new ReflectionTypeSolver(false); + return with(classLoaderTypeSolver); + } + + // Builders for JARS + + /** + * Allow the type solver to resolve types that are + * defined in a JAR file. + * + * @param pathToJar The path to the jar file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the Jar. + * + * @see JarTypeSolver + */ + public TypeSolverBuilder withJAR(@NonNull Path pathToJar) throws IOException { + TypeSolver jarTypeSolver = new JarTypeSolver(pathToJar); + return with(jarTypeSolver); + } + + /** + * Allow the type solver to resolve types that are + * defined in a JAR file. + * + * @param pathToJar The jar file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the Jar. + * + * @see JarTypeSolver + */ + public TypeSolverBuilder withJAR(@NonNull File pathToJar) throws IOException { + TypeSolver jarTypeSolver = new JarTypeSolver(pathToJar); + return with(jarTypeSolver); + } + + /** + * Allow the type solver to resolve types that are + * defined in a JAR file. + * + * @param pathToJar The path to the jar file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the Jar. + * + * @see JarTypeSolver + */ + public TypeSolverBuilder withJAR(@NonNull String pathToJar) throws IOException { + TypeSolver jarTypeSolver = new JarTypeSolver(pathToJar); + return with(jarTypeSolver); + } + + // Builders for AarTypeSolver + + /** + * Allow the type solver to resolve types that are + * defined in a AAR file. + * + * @param pathToAar The path to the AAR file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the AAR. + * + * @see AarTypeSolver + */ + public TypeSolverBuilder withAAR(@NonNull Path pathToAar) throws IOException { + TypeSolver aarTypeSolver = new AarTypeSolver(pathToAar); + return with(aarTypeSolver); + } + + /** + * Allow the type solver to resolve types that are + * defined in a AAR file. + * + * @param pathToAar The AAR file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the AAR. + * + * @see AarTypeSolver + */ + public TypeSolverBuilder withAAR(@NonNull File pathToAar) throws IOException { + TypeSolver aarTypeSolver = new AarTypeSolver(pathToAar); + return with(aarTypeSolver); + } + + /** + * Allow the type solver to resolve types that are + * defined in a AAR file. + * + * @param pathToAar The path to the AAR file. + * + * @return the current builder. + * + * @throws IOException If an I/O exception occurs while reading the AAR. + * + * @see AarTypeSolver + */ + public TypeSolverBuilder withAAR(@NonNull String pathToAar) throws IOException { + TypeSolver aarTypeSolver = new AarTypeSolver(pathToAar); + return with(aarTypeSolver); + } + + // Builders for JavaParserTypeSolver + + /** + * Allow the type solver to resolve types using + * external source code. + * + * @param pathToSourceCode The path to the source code. + * + * @return the current builder. + * + * @see JavaParserTypeSolver + */ + public TypeSolverBuilder withSourceCode(@NonNull Path pathToSourceCode) { + TypeSolver aarTypeSolver = new JavaParserTypeSolver(pathToSourceCode); + return with(aarTypeSolver); + } + + /** + * Allow the type solver to resolve types using + * external source code. + * + * @param pathToSourceCode The source code file. + * + * @return the current builder. + * + * @see JavaParserTypeSolver + */ + public TypeSolverBuilder withSourceCode(@NonNull File pathToSourceCode) { + TypeSolver aarTypeSolver = new JavaParserTypeSolver(pathToSourceCode); + return with(aarTypeSolver); + } + + /** + * Allow the type solver to resolve types using + * external source code. + * + * @param pathToSourceCode The path to the source code. + * + * @return the current builder. + * + * @see JavaParserTypeSolver + */ + public TypeSolverBuilder withSourceCode(@NonNull String pathToSourceCode) { + TypeSolver aarTypeSolver = new JavaParserTypeSolver(pathToSourceCode); + return with(aarTypeSolver); + } + + // Builders for ClassLoaderTypeSolver + + /** + * Allow the type solver to resolve types using + * the provided {@link ClassLoader}. + * + * @param classLoader The class loader to be registered. + * + * @return the current builder. + * + * @see ClassLoaderTypeSolver + */ + public TypeSolverBuilder withClassLoader(@NonNull ClassLoader classLoader) { + TypeSolver classLoaderTypeSolver = new ClassLoaderTypeSolver(classLoader); + return with(classLoaderTypeSolver); + } + + // build + + /** + * Convert the current build into a valid {@link TypeSolver}. + * + * @return The type solver with the requested configuration. + * + * @throws IllegalStateException if no build configuration is provided. + */ + public TypeSolver build() { + int typeSolversCount = typeSolvers.size(); + + // Check if at least one solver is present + if (typeSolversCount == 0) { + throw new IllegalStateException("At least a type solver is expected."); + } + + // Check if only one exists + if (typeSolversCount == 1) { + return typeSolvers.get(0); + } + + // Combine all type solver + return new CombinedTypeSolver(typeSolvers); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java new file mode 100644 index 0000000000..02a955ff85 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java @@ -0,0 +1,317 @@ +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.resolution.typesolvers; + +import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class TypeSolverBuilderTest { + + private final TypeSolverBuilder typeSolverBuilder = new TypeSolverBuilder(); + + /** + * Build a new type solver without any configuration, + * should throw an IllegalStateException. + */ + @Test + void testBuild_withoutConfiguration() { + assertThrows(IllegalStateException.class, typeSolverBuilder::build); + } + + /** + * Build a new type solve with a single configuration, + * should return that configuration. + */ + @Test + void testBuild_withASingleTypeSolver() { + // Prepare + TypeSolver typeSolverToRegister = mock(TypeSolver.class); + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder.with(typeSolverToRegister).build(); + + // Assert + assertEquals(typeSolverToRegister, createdTypeSolver); + } + + /** + * When multiple type solver are registered, they should be + * attached to the same parent. + */ + @Test + void testBuild_withMultipleTypeSolver() { + // Prepare + TypeSolver typeSolverA = mock(TypeSolver.class); + TypeSolver typeSolverB = mock(TypeSolver.class); + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .with(typeSolverA) + .with(typeSolverB) + .build(); + + // Verify + verify(typeSolverA).setParent(createdTypeSolver); + verifyNoMoreInteractions(typeSolverA); + + verify(typeSolverB).setParent(createdTypeSolver); + verifyNoMoreInteractions(typeSolverB); + } + + /** + * When build is set to include the current JRE, + * only the JRE types should be solved. + */ + @Test + void testBuild_withCurrentJREConfiguration() { + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withCurrentJRE() + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "java.lang.String"); + assertNotSolved(createdTypeSolver, "com.github.javaparser.ast.Node"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include the class loader, + * JRE types and other classes defined in the current + * class loader should be solved. + */ + @Test + void testBuild_withCurrentClassloaderConfiguration() { + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withCurrentClassloader() + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "java.lang.String"); + assertIsSolved(createdTypeSolver, "com.github.javaparser.ast.Node"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external JAR from a String, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withJARConfiguration_fromString() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withJAR("src/test/resources/junit-4.8.1.jar") + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "org.junit.Test"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external JAR from a Path, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withJARConfiguration_fromPath() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withJAR(Paths.get("src/test/resources/junit-4.8.1.jar")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "org.junit.Test"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external JAR from a File, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withJARConfiguration_fromFile() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withJAR(new File("src/test/resources/junit-4.8.1.jar")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "org.junit.Test"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external AAR from a String, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withAARConfiguration_fromString() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withAAR("src/test/resources/aars/support-compat-24.2.0.aar") + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "android.support.v4.app.ActivityCompat"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external AAR from a Path, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withAARConfiguration_fromPath() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withAAR(Paths.get("src/test/resources/aars/support-compat-24.2.0.aar")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "android.support.v4.app.ActivityCompat"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a external AAR from a File, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withAARConfiguration_fromFile() throws IOException { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withAAR(new File("src/test/resources/aars/support-compat-24.2.0.aar")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "android.support.v4.app.ActivityCompat"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include external source code from a String, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withSourceCodeConfiguration_fromString() { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withSourceCode("src/test/test_sourcecode/javaparser_new_src/javaparser-core") + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "com.github.javaparser.ast.Node"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include external source code from a Path, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withSourceCodeConfiguration_fromPath() { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withSourceCode(Paths.get("src/test/test_sourcecode/javaparser_new_src/javaparser-core")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "com.github.javaparser.ast.Node"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include external source code from a File, + * the classes defined inside the file should be solved. + */ + @Test + void testBuild_withSourceCodeConfiguration_fromFile() { + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withSourceCode(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core")) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "com.github.javaparser.ast.Node"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + /** + * When build is set to include a custom class loader, + * the classes defined in the class loader should be solved. + */ + @Test + void testBuild_withCustomClassLoaderInConfiguration() { + + // Prepare + ClassLoader classLoader = TypeSolverBuilderTest.class.getClassLoader(); + + // Execute + TypeSolver createdTypeSolver = typeSolverBuilder + .withClassLoader(classLoader) + .build(); + + // Assert + assertIsSolved(createdTypeSolver, "com.github.javaparser.symbolsolver.resolution.typesolvers.TypeSolverBuilderTest"); + assertNotSolved(createdTypeSolver, "com.example.a.non.existing.Class"); + } + + // Static helpers + + /** + * Assert a class can be resolved inside the current type solver. + * + * @param typeSolver The type solver to search. + * @param className The class to find. + */ + private static void assertIsSolved(TypeSolver typeSolver, String className) { + assertTrue(typeSolver.hasType(className), String.format("Unable to solve type %s", className)); + } + + /** + * Assert a class can't be resolved inside the current type solver. + * + * @param typeSolver The type solver to search. + * @param className The class to find. + */ + private static void assertNotSolved(TypeSolver typeSolver, String className) { + assertFalse(typeSolver.hasType(className), String.format("This type solver should not be able to solve type %s", className)); + } + +} \ No newline at end of file From a30a5e20678aab8034e093d75aec8cf7a6ea6c75 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 24 Sep 2022 10:31:46 +0200 Subject: [PATCH 019/280] Minor refactoring in CsmConditionnal --- .../concretesyntaxmodel/CsmConditional.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java index 3d9209a1cf..12d618860d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java @@ -21,14 +21,14 @@ package com.github.javaparser.printer.concretesyntaxmodel; +import java.util.Arrays; +import java.util.List; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.printer.SourcePrinter; -import java.util.Arrays; -import java.util.List; - public class CsmConditional implements CsmElement { private final Condition condition; private final List properties; @@ -59,28 +59,35 @@ public CsmElement getElseElement() { } public enum Condition { - IS_EMPTY, - IS_NOT_EMPTY, - IS_PRESENT, - FLAG; - - boolean evaluate(Node node, ObservableProperty property){ - if (this == IS_PRESENT) { - return !property.isNullOrNotPresent(node); - } - if (this == FLAG) { - return property.getValueAsBooleanAttribute(node); - } - if (this == IS_EMPTY) { + IS_EMPTY { + @Override + boolean evaluate(Node node, ObservableProperty property) { NodeList value = property.getValueAsMultipleReference(node); return value == null || value.isEmpty(); } - if (this == IS_NOT_EMPTY) { + }, + IS_NOT_EMPTY { + @Override + boolean evaluate(Node node, ObservableProperty property) { NodeList value = property.getValueAsMultipleReference(node); return value != null && !value.isEmpty(); } - throw new UnsupportedOperationException(name()); - } + }, + IS_PRESENT { + @Override + boolean evaluate(Node node, ObservableProperty property) { + return !property.isNullOrNotPresent(node); + } + }, + FLAG { + @Override + boolean evaluate(Node node, ObservableProperty property) { + return property.getValueAsBooleanAttribute(node); + } + }; + + abstract boolean evaluate(Node node, ObservableProperty property); + } public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement, CsmElement elseElement) { From d2a4d0ebf2bad408965ec38b70a1fc2b16c6c059 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 24 Sep 2022 10:33:12 +0200 Subject: [PATCH 020/280] Adding minor comments or remarks --- .../javaparser/printer/lexicalpreservation/Difference.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 6358dc258e..5c0d7e5a2b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -410,6 +410,9 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, if (originalElements.get(originalIndex).isWhiteSpace() && originalElements.get(originalIndex - 1).isWhiteSpace()) { // However we do not want to do that when we are about to adding or removing elements + // The intention is not very clear maybe it should clarify this with examples! + // Are we to understand that we can only do this if there is a single modification to process + // OR or if the next change is to keep the element if ((diffIndex + 1) == diffElements.size() || (diffElements.get(diffIndex + 1).isKept())) { originalElements.remove(originalIndex--); } @@ -470,7 +473,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo // If the current element is a space, remove it nodeText.removeElement(originalIndex); } else if (originalIndex >= 1 && originalElements.get(originalIndex - 1).isSpaceOrTab()) { - // If the current element is not a space itself we remove the space in front of it + // If the current element is not a space itself we remove the space in front of (before) it nodeText.removeElement(originalIndex - 1); originalIndex--; } From aee62b1f3a9b2cdee1951db04df21be6e63ca24f Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 24 Sep 2022 19:00:31 +0200 Subject: [PATCH 021/280] Minor refactoring of the method considerEnforcingIndentation --- .../lexicalpreservation/Difference.java | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 5c0d7e5a2b..98e11f92fc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -139,29 +139,53 @@ private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) { * the same as the indentation. */ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { + boolean hasOnlyWsBefore = hasOnlyWsBefore(nodeText, nodeTextIndex); + int res = nodeTextIndex; // the next position in the list (by default the current position) + if (hasOnlyWsBefore) { + res = removeExtraCharacters(nodeText, nodeTextIndex); + } + if (res < 0) { + throw new IllegalStateException(); + } + return res; + } + + /** + * + * @param nodeText Contains a list of elements to analyze + * @param nodeTextIndex Starting position in the input list + * @return The current position in the list of the elements + */ + private int removeExtraCharacters(NodeText nodeText, int nodeTextIndex) { + int pos = nodeTextIndex; + for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { + if (nodeText.getTextElement(i).isNewline()) { + break; + } + nodeText.removeElement(i); + pos = i; + } + return pos; + } + + /** + * Tries to determine if there are only spaces between the previous end of line and the index + * @param nodeText List of elements to analyze + * @param nodeTextIndex Starting position in the input list + * @return + */ + private boolean hasOnlyWsBefore(NodeText nodeText, int nodeTextIndex) { boolean hasOnlyWsBefore = true; - for (int i = nodeTextIndex; i >= 0 && hasOnlyWsBefore && i < nodeText.numberOfElements(); i--) { + for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { if (nodeText.getTextElement(i).isNewline()) { break; } if (!nodeText.getTextElement(i).isSpaceOrTab()) { hasOnlyWsBefore = false; + break; } } - int res = nodeTextIndex; - if (hasOnlyWsBefore) { - for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { - if (nodeText.getTextElement(i).isNewline()) { - break; - } - nodeText.removeElement(i); - res = i; - } - } - if (res < 0) { - throw new IllegalStateException(); - } - return res; + return hasOnlyWsBefore; } /** From 0b626ec47b07f23a876b52bd281646ada19945cc Mon Sep 17 00:00:00 2001 From: Paul Pazderski Date: Thu, 6 Oct 2022 18:34:19 +0200 Subject: [PATCH 022/280] Fix maven wrapper not found in generator scripts --- run_core_generators.sh | 2 +- run_core_metamodel_generator.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/run_core_generators.sh b/run_core_generators.sh index abb08d44c1..3ccb05c18c 100755 --- a/run_core_generators.sh +++ b/run_core_generators.sh @@ -7,7 +7,7 @@ pushd javaparser-core-generators # Generate code -./mvnw --errors --show-version -B clean package -P run-generators -DskipTests +../mvnw --errors --show-version -B clean package -P run-generators -DskipTests # Go back to previous directory popd diff --git a/run_core_metamodel_generator.sh b/run_core_metamodel_generator.sh index 7818556d49..c053209f7c 100755 --- a/run_core_metamodel_generator.sh +++ b/run_core_metamodel_generator.sh @@ -12,7 +12,7 @@ fi pushd javaparser-core-metamodel-generator # Generate code -./mvnw --errors --show-version -B clean package -P run-generators -DskipTests +../mvnw --errors --show-version -B clean package -P run-generators -DskipTests # Go back to previous directory popd From f26a8386c3dfa7f26d7e9f32ae480356488cf723 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 19 Oct 2022 21:38:41 +0200 Subject: [PATCH 023/280] [maven-release-plugin] prepare for next development iteration --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index b28f046fe8..2d58827890 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 48bd6464b4..672d77659f 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 2d66cafc4e..4d0c7efe53 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index e283c82a03..e397e9d65a 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index b6ef886555..af0a4f9512 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 7e06b8ccdb..5e482d1e8d 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 49080d208a..d8e165f052 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index eafe79380a..c4883e168c 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.7 + 3.24.8-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 0e4712a1dd..34a384bcc8 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.24.7 + 3.24.8-SNAPSHOT javaparser-parent https://github.com/javaparser From 1f56bb6639f1dd1772d9511de965d658c0ae0635 Mon Sep 17 00:00:00 2001 From: Amelia Genova Date: Sun, 23 Oct 2022 17:51:47 +1100 Subject: [PATCH 024/280] Fixed ofIfInvalid() and cleaned up code and comments for isAfter(), isBefore() and valid() in Position.java --- .../java/com/github/javaparser/Position.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index c31c5cd2fb..734476c773 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -115,12 +115,13 @@ public Position nextLine() { } /** - * Check if the position is usable. + * Check if the position is usable, + * also checks for special positions (ABSOLUTE_BEGIN_LINE and ABSOLUTE_END_LINE). * Does not know what it is pointing at, so it can't check if the position is after the end of the source. + * @return true if the position is usable or a special position. */ public boolean valid() { - // TODO / FIXME: Perhaps allow use of the "special" positions e.g. ABSOLUTE_BEGIN_LINE and ABSOLUTE_END_LINE...? - return line >= FIRST_LINE && column >= FIRST_COLUMN; + return ABSOLUTE_END_LINE == line || ABSOLUTE_BEGIN_LINE == line || line >= FIRST_LINE && column >= FIRST_COLUMN; } /** @@ -134,31 +135,26 @@ public boolean invalid() { /** * @return If this position is valid, this. * Otherwise, if the alternativePosition is valid, return that. - * Otherwise otherwise, just return this. - * TODO: Simplify/clarify. + * Otherwise, just return this. */ public Position orIfInvalid(Position alternativePosition) { assertNotNull(alternativePosition); - // TODO: Why the || ? - // ... It seems that if both this and the alternative are invalid, then we return this..? - if (valid() || alternativePosition.invalid()) { + if (this.valid()) { return this; } - return alternativePosition; + return alternativePosition.valid() ? alternativePosition : this; } + /** + * @param otherPosition the other position to compare to + * @return true if this position is after the given position + */ public boolean isAfter(Position otherPosition) { assertNotNull(otherPosition); - if (otherPosition.line == Position.ABSOLUTE_BEGIN_LINE) { - // FIXME: What if both positions are on the same line but different columns..? - return true; - } - if (line > otherPosition.line) { - return true; - } else if (line == otherPosition.line) { + if (line == otherPosition.line) { return column > otherPosition.column; } - return false; + return line > otherPosition.line || otherPosition.line == Position.ABSOLUTE_BEGIN_LINE; } @@ -167,18 +163,16 @@ public boolean isAfterOrEqual(Position otherPosition) { return isAfter(otherPosition) || equals(otherPosition); } + /** + * @param otherPosition the other position to compare to + * @return true if this position is before the given position + */ public boolean isBefore(Position otherPosition) { assertNotNull(otherPosition); - if (otherPosition.line == Position.ABSOLUTE_END_LINE) { - // FIXME: What if both positions are on the same line but different columns..? - return true; - } - if (line < otherPosition.line) { - return true; - } else if (line == otherPosition.line) { + if (line == otherPosition.line) { return column < otherPosition.column; } - return false; + return line < otherPosition.line || otherPosition.line == Position.ABSOLUTE_END_LINE; } public boolean isBeforeOrEqual(Position otherPosition) { From ebcf25f16743e14aa82a437cdc512e560f12aefe Mon Sep 17 00:00:00 2001 From: Amelia Genova Date: Sun, 23 Oct 2022 18:06:58 +1100 Subject: [PATCH 025/280] Created PositionTest.java to test the Position.Java, added unit Test for OrIfInvalid --- .../com/github/javaparser/PositionTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java new file mode 100644 index 0000000000..ea9b01c38f --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java @@ -0,0 +1,23 @@ +package com.github.javaparser; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class PositionTest { + + @Test + public void testOrIfInvalid() { + Position p1 = new Position(1, 1); + Position p2 = new Position(2, 2); + + assertEquals(p1, p1.orIfInvalid(p2)); + + Position invalid = new Position(0, 0); + Position invalid2 = new Position(0, 1); + + assertEquals(p1, invalid.orIfInvalid(p1)); + assertEquals(invalid2, invalid2.orIfInvalid(invalid)); + } + +} From 961d04e4fa9b9219e69c27efe77a819a5f5cc683 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 24 Oct 2022 21:11:29 +0200 Subject: [PATCH 026/280] Fix part of issue #3721 UnsupportedOperationException while trying to modify the type of a variable --- .../lexicalpreservation/Issue3721Test.java | 54 +++++++++++++++++++ .../lexicalpreservation/Difference.java | 3 ++ 2 files changed, 57 insertions(+) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java new file mode 100755 index 0000000000..e7cfd48421 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java @@ -0,0 +1,54 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; + +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.ast.body.VariableDeclarator; + +public class Issue3721Test extends AbstractLexicalPreservingTest { + + @Test + void issue3721() { + considerCode( + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " Object msg;\n" + + " }\n" + + "}\n"); + + String expected = + "public class Bug {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " boolean msg;\n" + + " }\n" + + "}\n"; + + + VariableDeclarator var = cu.findFirst(VariableDeclarator.class).get(); + var.setType("boolean"); + assertEqualsStringIgnoringEol(expected, cu.toString()); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 98e11f92fc..0a0ef8218a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -469,6 +469,9 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, diffIndex++; } else if (originalElement.isWhiteSpace()) { originalIndex++; + } else if (removed.isChild()) { // see issue #3721 this case is linked for example to a change of type of variable declarator + nodeText.removeElement(originalIndex); + diffIndex++; } else { throw new UnsupportedOperationException("removed " + removed.getElement() + " vs " + originalElement); } From f3df40ba46db6efbc7762f308cac6e437fbce2ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 23:04:35 +0000 Subject: [PATCH 027/280] chore(deps): bump versions-maven-plugin from 2.12.0 to 2.13.0 Bumps [versions-maven-plugin](https://github.com/mojohaus/versions-maven-plugin) from 2.12.0 to 2.13.0. - [Release notes](https://github.com/mojohaus/versions-maven-plugin/releases) - [Changelog](https://github.com/mojohaus/versions-maven-plugin/blob/master/ReleaseNotes.md) - [Commits](https://github.com/mojohaus/versions-maven-plugin/compare/versions-maven-plugin-2.12.0...2.13.0) --- updated-dependencies: - dependency-name: org.codehaus.mojo:versions-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 34a384bcc8..57f8ffef9d 100644 --- a/pom.xml +++ b/pom.xml @@ -334,7 +334,7 @@ org.codehaus.mojo versions-maven-plugin - 2.12.0 + 2.13.0 false From ace9391d07c50050f88fc5f11c4a4305a2ca40c7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:15:02 +0000 Subject: [PATCH 028/280] chore(deps): bump actions/checkout from 3.0.2 to 3.1.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.2 to 3.1.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.0.2...v3.1.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/create_github_release.yml | 2 +- .github/workflows/maven_tests.yml | 2 +- .github/workflows/prepare_release_changelog.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create_github_release.yml b/.github/workflows/create_github_release.yml index 1a44c1d750..293d631a92 100644 --- a/.github/workflows/create_github_release.yml +++ b/.github/workflows/create_github_release.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@master + uses: actions/checkout@v3.1.0 - name: Create Release id: create_release diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 8a144a18bc..4b85c44d2b 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -39,7 +39,7 @@ jobs: steps: ## Checkout the current version of the code from the repo. - name: Checkout latest code - uses: actions/checkout@v3 + uses: actions/checkout@v3.1.0 with: fetch-depth: "0" diff --git a/.github/workflows/prepare_release_changelog.yml b/.github/workflows/prepare_release_changelog.yml index 1fc617d8f3..595c5fb421 100644 --- a/.github/workflows/prepare_release_changelog.yml +++ b/.github/workflows/prepare_release_changelog.yml @@ -15,7 +15,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 # Setup Java 11 environment for the next steps - name: Setup Java From a57cd75a62d88f4dc87b23f95b5007ccb82b3378 Mon Sep 17 00:00:00 2001 From: Joseph Cox Date: Wed, 26 Oct 2022 15:37:47 +1100 Subject: [PATCH 029/280] Test format of position exception string --- .../com/github/javaparser/PositionTest.java | 18 ++++++++++++++++++ .../java/com/github/javaparser/Position.java | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java index ea9b01c38f..4ef8d2c469 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class PositionTest { @@ -20,4 +21,21 @@ public void testOrIfInvalid() { assertEquals(invalid2, invalid2.orIfInvalid(invalid)); } + @Test + public void testPositionExceptionMessage() { + try { + Position p = new Position(-10, 1); + fail("Created " + p + " without exception."); + } catch (IllegalArgumentException e) { + assertEquals("Can't position at line -10", e.getMessage()); + } + + try { + Position p = new Position(1, -10); + fail("Created " + p + " without exception."); + } catch (IllegalArgumentException e) { + assertEquals("Can't position at column -10", e.getMessage()); + } + } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index 734476c773..84ed931664 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -62,7 +62,6 @@ public class Position implements Comparable { */ public Position(int line, int column) { if (line < Position.ABSOLUTE_END_LINE) { - // TODO/FIXME: This doesn't read correctly due to use of the variable. throw new IllegalArgumentException("Can't position at line " + line); } if (column < -1) { From d18bf3fe6f03b3073a4fcc0429f4653ca9606144 Mon Sep 17 00:00:00 2001 From: Amelia Genova Date: Wed, 26 Oct 2022 22:02:42 +1100 Subject: [PATCH 030/280] added unit test for getterToPropertyName method in CodeGenerationUtilsTest.java for CodeGenerationUtils.java --- .../javaparser/utils/CodeGenerationUtilsTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java index f33ae17f30..c28a65aa42 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java @@ -42,4 +42,17 @@ void getters() { assertEquals("getIsBlue", getterName(Boolean.class, "isBlue")); } + @Test + void testGetterToPropertyName() { + assertEquals("value", getterToPropertyName("getValue")); + assertEquals("blue", getterToPropertyName("isBlue")); + assertEquals("value", getterToPropertyName("hasValue")); + try { + getterToPropertyName("value"); + fail("Expected an IllegalArgumentException to be thrown"); + } catch (IllegalArgumentException e) { + assertEquals("Unexpected getterName 'value'", e.getMessage()); + } + } + } From 1d62f7838ce29ccc501667c04f0b32cfac4657b6 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 26 Oct 2022 14:43:47 +0200 Subject: [PATCH 031/280] Centralized management of symbol solver exceptions --- .../javaparsermodel/FailureHandler.java | 79 +++++++++++++++++++ .../javaparsermodel/JavaParserFacade.java | 15 ++-- 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100755 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java new file mode 100755 index 0000000000..6d53d9edfe --- /dev/null +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2020 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.javaparsermodel; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import com.github.javaparser.resolution.UnsolvedSymbolException; + +/* + * This class allows exceptions to be handled either by casting particular exceptions + * or by throwing new runtime exceptions. + */ +public class FailureHandler { + + private static final Map, Function> FAILURE_CONVERTER = new HashMap<>(); + static { + FAILURE_CONVERTER.put(UnsolvedSymbolException.class, + (Throwable th) -> (RuntimeException)th); + } + + public RuntimeException handle(Throwable th) { + return handle(th, null); + } + + public RuntimeException handle(Throwable th, String message) { + // searching for exact mapping + Function converter = FAILURE_CONVERTER.get(findRootCause(th).getClass()); + if (converter != null) { + return converter.apply(th); + } + // handle runtime exceptions + if (RuntimeException.class.isAssignableFrom(th.getClass())) { + return (RuntimeException) th; + } + return getRuntimeExceptionFrom(findRootCause(th), message); + } + + protected final E findRootCause(Throwable failure) { + while (failure != null) { + if (isRootCause(failure)) { + return (E) failure; + } + failure = failure.getCause(); + } + return null; + } + + private boolean isRootCause(Throwable th) { + return th.getCause() == null; + } + + private RuntimeException getRuntimeExceptionFrom(Throwable th, String message) { + if (message == null || message.isEmpty()) + return new RuntimeException(findRootCause(th)); + return new RuntimeException(message, findRootCause(th)); + } + +} diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 2276af358d..0404ea1345 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -103,7 +103,7 @@ public class JavaParserFacade { private static final Map instances = new WeakHashMap<>(); private static final String JAVA_LANG_STRING = String.class.getCanonicalName(); - + /** * Note that the addition of the modifier {@code synchronized} is specific and directly in response to issue #2668. *
This MUST NOT be misinterpreted as a signal that JavaParser is safe to use within a multi-threaded environment. @@ -148,11 +148,14 @@ protected static ResolvedType solveGenericTypes(ResolvedType type, Context conte private final TypeSolver typeSolver; private final TypeExtractor typeExtractor; private final SymbolSolver symbolSolver; + + private FailureHandler failureHandler; private JavaParserFacade(TypeSolver typeSolver) { this.typeSolver = typeSolver.getRoot(); this.symbolSolver = new SymbolSolver(typeSolver); this.typeExtractor = new TypeExtractor(typeSolver, this); + this.failureHandler = new FailureHandler(); } public TypeSolver getTypeSolver() { @@ -294,11 +297,9 @@ private void solveArguments(Node node, NodeList args, boolean solveL } else { try { argumentTypes.add(JavaParserFacade.get(typeSolver).getType(parameterValue, solveLambdas)); - } catch (UnsolvedSymbolException e) { - throw e; } catch (Exception e) { - throw new RuntimeException(String.format("Unable to calculate the type of a parameter of a method call. Method call: %s, Parameter: %s", - node, parameterValue), e); + throw failureHandler.handle(e, String.format("Unable to calculate the type of a parameter of a method call. Method call: %s, Parameter: %s", + node, parameterValue)); } } i++; @@ -384,7 +385,7 @@ public ResolvedType getType(Node node) { return ReferenceTypeImpl.undeterminedParameters(resolvedReferenceTypeDeclaration, typeSolver); } } - throw e; + throw failureHandler.handle(e); } } @@ -806,7 +807,7 @@ public MethodUsage solveMethodAsUsage(MethodCallExpr call) { try { params.add(getType(param, false)); } catch (Exception e) { - throw new RuntimeException(String.format("Error calculating the type of parameter %s of method call %s", param, call), e); + throw failureHandler.handle(e, String.format("Error calculating the type of parameter %s of method call %s", param, call)); } //params.add(getTypeConcrete(param, false)); } From 4b46a4c9e8dd2983b753c9ada108691415c6b507 Mon Sep 17 00:00:00 2001 From: Amelia Genova Date: Wed, 26 Oct 2022 23:52:18 +1100 Subject: [PATCH 032/280] added unit tests for deleteToken, findFirstToken and findLastToken for JavaToken.java in JavaTokenTest.java. --- .../com/github/javaparser/JavaTokenTest.java | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java index 4316320978..835d29f34f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java @@ -21,6 +21,7 @@ package com.github.javaparser; +import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.Expression; import org.junit.jupiter.api.Test; @@ -34,9 +35,8 @@ import static com.github.javaparser.JavaToken.Category.WHITESPACE_NO_EOL; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.Range.range; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static com.github.javaparser.StaticJavaParser.parse; +import static org.junit.jupiter.api.Assertions.*; class JavaTokenTest { @@ -125,4 +125,41 @@ void test() throws NoSuchFieldException, IllegalAccessException { } } + @Test + void testDeleteToken() { + ParseResult result = new JavaParser().parse(ParseStart.EXPRESSION, provider("1+/*2*/1\n")); + TokenRange tokenRange = result.getResult().get().getTokenRange().get(); + + JavaToken tokenToBeDeleted = tokenRange.getBegin().getNextToken().get(); + tokenToBeDeleted.deleteToken(); + JavaToken nextTokenAfterDelete = tokenRange.getBegin().getNextToken().get(); + JavaToken previous = nextTokenAfterDelete.getPreviousToken().get(); + + assertNotEquals(tokenToBeDeleted, nextTokenAfterDelete); + assertEquals("/*2*/", nextTokenAfterDelete.getText()); + assertEquals("1", previous.getText()); + } + + @Test + void testFindLastToken() { + ParseResult result = new JavaParser().parse(ParseStart.EXPRESSION, provider("1 +/*2*/3 ")); + TokenRange tokenRange = result.getResult().get().getTokenRange().get(); + Iterator iterator = tokenRange.iterator(); + assertToken("", range(1, 10, 1, 10), EOF, WHITESPACE_NO_EOL, iterator.next().findLastToken()); + + // getEnd token in TokenRange is not the same as the last token from findLastToken() + // assertEquals(tokenRange.getEnd(), tokenRange.getBegin().findLastToken()); + } + + @Test + void testFindFirstToken() { + ParseResult result = new JavaParser().parse(ParseStart.EXPRESSION, provider("1 +/*2*/3+4")); + Iterator iterator = result.getResult().get().getTokenRange().get().iterator(); + iterator.next(); + iterator.next(); + iterator.next(); + assertEquals("/*2*/", iterator.next().getText()); + assertToken("1", range(1, 1, 1, 1), INTEGER_LITERAL, LITERAL, iterator.next().findFirstToken()); + } + } From 5bf3b1802e1c1a051b25c1a84cff93fd1074f766 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 27 Oct 2022 20:49:32 +0100 Subject: [PATCH 033/280] Revert "Executed generators" This reverts commit 7876a3a8e640ff74610bfac018272e3021b86f1d. --- javaparser-core/bnd.bnd | 1 - .../github/javaparser/CommentsInserter.java | 70 +- .../com/github/javaparser/HasParentNode.java | 10 +- .../com/github/javaparser/JavaParser.java | 18 +- .../com/github/javaparser/JavadocParser.java | 33 +- .../LineEndingProcessingProvider.java | 12 +- .../javaparser/ParseProblemException.java | 2 +- .../com/github/javaparser/ParseResult.java | 5 +- .../com/github/javaparser/ParseStart.java | 22 +- .../javaparser/ParserConfiguration.java | 95 +- .../java/com/github/javaparser/Position.java | 27 +- .../java/com/github/javaparser/Problem.java | 10 +- .../java/com/github/javaparser/Providers.java | 11 +- .../java/com/github/javaparser/Range.java | 17 +- .../github/javaparser/StaticJavaParser.java | 49 +- .../com/github/javaparser/TokenRange.java | 15 +- .../com/github/javaparser/TokenTypes.java | 4 +- .../UnicodeEscapeProcessingProvider.java | 1135 +++++++++-------- .../javaparser/ast/AccessSpecifier.java | 6 +- .../javaparser/ast/AllFieldsConstructor.java | 1 + .../com/github/javaparser/ast/DataKey.java | 2 +- .../com/github/javaparser/ast/Generated.java | 5 +- .../com/github/javaparser/ast/NodeList.java | 13 +- .../ast/comments/CommentsCollection.java | 26 +- .../ast/nodeTypes/NodeWithAnnotations.java | 17 +- .../ast/nodeTypes/NodeWithArguments.java | 3 +- .../ast/nodeTypes/NodeWithBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithBody.java | 6 +- .../ast/nodeTypes/NodeWithCondition.java | 2 +- .../ast/nodeTypes/NodeWithDeclaration.java | 1 + .../ast/nodeTypes/NodeWithExpression.java | 2 +- .../ast/nodeTypes/NodeWithExtends.java | 2 + .../ast/nodeTypes/NodeWithIdentifier.java | 2 +- .../ast/nodeTypes/NodeWithImplements.java | 14 +- .../ast/nodeTypes/NodeWithJavadoc.java | 7 +- .../ast/nodeTypes/NodeWithMembers.java | 53 +- .../ast/nodeTypes/NodeWithModifiers.java | 11 +- .../ast/nodeTypes/NodeWithName.java | 2 +- .../nodeTypes/NodeWithOptionalBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithOptionalLabel.java | 4 +- .../ast/nodeTypes/NodeWithOptionalScope.java | 3 +- .../ast/nodeTypes/NodeWithParameters.java | 25 +- .../ast/nodeTypes/NodeWithRange.java | 8 +- .../ast/nodeTypes/NodeWithScope.java | 1 + .../ast/nodeTypes/NodeWithSimpleName.java | 2 +- .../ast/nodeTypes/NodeWithStatements.java | 2 +- .../nodeTypes/NodeWithThrownExceptions.java | 2 +- .../ast/nodeTypes/NodeWithTokenRange.java | 3 +- .../nodeTypes/NodeWithTraversableScope.java | 1 + .../ast/nodeTypes/NodeWithType.java | 2 +- .../ast/nodeTypes/NodeWithTypeArguments.java | 2 +- .../ast/nodeTypes/NodeWithTypeParameters.java | 2 +- .../ast/nodeTypes/NodeWithVariables.java | 5 +- .../javaparser/ast/nodeTypes/SwitchNode.java | 4 +- .../modifiers/NodeWithAbstractModifier.java | 2 +- .../modifiers/NodeWithAccessModifiers.java | 1 + .../modifiers/NodeWithFinalModifier.java | 2 +- .../modifiers/NodeWithPrivateModifier.java | 2 +- .../modifiers/NodeWithProtectedModifier.java | 2 +- .../modifiers/NodeWithPublicModifier.java | 3 +- .../modifiers/NodeWithStaticModifier.java | 2 + .../modifiers/NodeWithStrictfpModifier.java | 2 +- .../javaparser/ast/observer/AstObserver.java | 5 +- .../ast/observer/AstObserverAdapter.java | 1 + .../javaparser/ast/observer/Observable.java | 1 + .../ast/observer/PropagatingAstObserver.java | 3 +- .../ast/validator/ProblemReporter.java | 2 +- .../validator/ReservedKeywordValidator.java | 3 +- .../ast/validator/SimpleValidator.java | 2 +- .../validator/SingleNodeTypeValidator.java | 3 +- .../ast/validator/TreeVisitorValidator.java | 2 +- .../ast/validator/TypedValidator.java | 7 +- .../javaparser/ast/validator/Validator.java | 2 +- .../javaparser/ast/validator/Validators.java | 2 +- .../ast/validator/VisitorValidator.java | 2 +- .../Java10PreviewValidator.java | 10 + .../Java10Validator.java | 4 + .../Java11PreviewValidator.java | 10 + .../Java11Validator.java | 4 +- .../Java12PreviewValidator.java | 6 + .../Java12Validator.java | 3 + .../Java13PreviewValidator.java | 8 +- .../Java13Validator.java | 3 + .../Java14PreviewValidator.java | 11 +- .../Java14Validator.java | 2 + .../Java15PreviewValidator.java | 8 +- .../Java15Validator.java | 5 +- .../Java16PreviewValidator.java | 5 + .../Java16Validator.java | 5 +- .../Java1_0Validator.java | 108 +- .../Java1_1Validator.java | 12 +- .../Java1_2Validator.java | 3 +- .../Java1_3Validator.java | 2 +- .../Java1_4Validator.java | 2 +- .../Java5Validator.java | 7 +- .../Java6Validator.java | 4 +- .../Java7Validator.java | 7 +- .../Java8Validator.java | 22 +- .../Java9Validator.java | 11 +- .../chunks/CommonValidators.java | 76 +- .../chunks/ModifierValidator.java | 14 +- .../NoBinaryIntegerLiteralsValidator.java | 2 +- ...UnderscoresInIntegerLiteralsValidator.java | 2 +- .../chunks/UnderscoreKeywordValidator.java | 2 +- .../chunks/VarValidator.java | 14 +- .../postprocessors/Java10PostProcessor.java | 17 +- .../postprocessors/PostProcessors.java | 2 +- .../javaparser/ast/visitor/TreeVisitor.java | 1 + .../javaparser/ast/visitor/Visitable.java | 2 +- .../github/javaparser/javadoc/Javadoc.java | 19 +- .../javaparser/javadoc/JavadocBlockTag.java | 26 +- .../description/JavadocDescription.java | 16 +- .../JavadocDescriptionElement.java | 2 +- .../javadoc/description/JavadocInlineTag.java | 27 +- .../javadoc/description/JavadocSnippet.java | 15 +- .../metamodel/BaseNodeMetaModel.java | 27 +- .../javaparser/metamodel/DerivedProperty.java | 1 + .../metamodel/InternalProperty.java | 1 + .../metamodel/NonEmptyProperty.java | 3 +- .../metamodel/OptionalProperty.java | 1 + .../metamodel/PropertyMetaModel.java | 24 +- .../printer/ConcreteSyntaxModel.java | 980 ++++++++++++-- .../printer/DefaultPrettyPrinter.java | 36 +- .../printer/DefaultPrettyPrinterVisitor.java | 314 ++++- .../github/javaparser/printer/DotPrinter.java | 38 +- .../printer/PrettyPrintVisitor.java | 312 ++++- .../javaparser/printer/PrettyPrinter.java | 20 +- .../github/javaparser/printer/Printer.java | 8 +- .../javaparser/printer/SourcePrinter.java | 52 +- .../github/javaparser/printer/Stringable.java | 1 - .../github/javaparser/printer/XmlPrinter.java | 7 +- .../javaparser/printer/YamlPrinter.java | 41 +- .../concretesyntaxmodel/CsmAttribute.java | 37 +- .../printer/concretesyntaxmodel/CsmChar.java | 2 +- .../concretesyntaxmodel/CsmComment.java | 2 + .../concretesyntaxmodel/CsmConditional.java | 15 +- .../concretesyntaxmodel/CsmElement.java | 8 +- .../concretesyntaxmodel/CsmIndent.java | 1 + .../printer/concretesyntaxmodel/CsmList.java | 6 +- .../printer/concretesyntaxmodel/CsmMix.java | 10 +- .../printer/concretesyntaxmodel/CsmNone.java | 3 + .../CsmOrphanCommentsEnding.java | 5 +- .../concretesyntaxmodel/CsmSequence.java | 2 +- .../CsmSingleReference.java | 2 +- .../concretesyntaxmodel/CsmString.java | 3 +- .../concretesyntaxmodel/CsmTextBlock.java | 6 +- .../printer/concretesyntaxmodel/CsmToken.java | 25 +- .../concretesyntaxmodel/CsmUnindent.java | 1 + .../concretesyntaxmodel/PrintingHelper.java | 3 +- .../configuration/ConfigurationOption.java | 3 +- .../DefaultConfigurationOption.java | 12 +- .../DefaultPrinterConfiguration.java | 55 +- .../printer/configuration/Indentation.java | 44 +- .../PrettyPrinterConfiguration.java | 56 +- .../configuration/PrinterConfiguration.java | 5 +- .../printer/lexicalpreservation/Added.java | 18 +- .../lexicalpreservation/ChildTextElement.java | 17 +- .../lexicalpreservation/Difference.java | 202 ++- .../DifferenceElement.java | 2 +- .../DifferenceElementCalculator.java | 91 +- .../printer/lexicalpreservation/Kept.java | 35 +- .../LexicalDifferenceCalculator.java | 84 +- .../LexicalPreservingPrinter.java | 185 ++- .../printer/lexicalpreservation/NodeText.java | 42 +- .../lexicalpreservation/PhantomNodeLogic.java | 22 +- .../printer/lexicalpreservation/Removed.java | 29 +- .../lexicalpreservation/RemovedGroup.java | 28 +- .../lexicalpreservation/Reshuffled.java | 16 +- .../lexicalpreservation/TextElement.java | 12 +- .../TextElementIteratorsFactory.java | 24 +- .../TextElementMatcher.java | 1 + .../TextElementMatchers.java | 2 +- .../lexicalpreservation/TokenTextElement.java | 18 +- .../WrappingRangeIterator.java | 3 +- .../lexicalpreservation/changes/Change.java | 3 +- .../changes/ListAdditionChange.java | 6 +- .../changes/ListRemovalChange.java | 8 +- .../changes/ListReplacementChange.java | 6 +- .../lexicalpreservation/changes/NoChange.java | 1 + .../changes/PropertyChange.java | 3 +- .../resolution/MethodAmbiguityException.java | 2 + .../javaparser/resolution/MethodUsage.java | 29 +- .../javaparser/resolution/Resolvable.java | 2 +- .../javaparser/resolution/SymbolResolver.java | 2 +- .../resolution/UnsolvedSymbolException.java | 7 +- .../declarations/AssociableToAST.java | 1 + .../declarations/HasAccessSpecifier.java | 2 + .../ResolvedAnnotationDeclaration.java | 4 +- .../ResolvedAnnotationMemberDeclaration.java | 1 + .../ResolvedClassDeclaration.java | 12 +- .../ResolvedConstructorDeclaration.java | 4 +- .../declarations/ResolvedDeclaration.java | 1 + .../ResolvedEnumConstantDeclaration.java | 1 + .../declarations/ResolvedEnumDeclaration.java | 7 +- .../ResolvedFieldDeclaration.java | 2 + .../ResolvedInterfaceDeclaration.java | 4 +- .../ResolvedMethodDeclaration.java | 2 + .../ResolvedMethodLikeDeclaration.java | 7 +- .../ResolvedParameterDeclaration.java | 1 + .../ResolvedPatternDeclaration.java | 2 + .../ResolvedReferenceTypeDeclaration.java | 85 +- .../declarations/ResolvedTypeDeclaration.java | 22 +- .../ResolvedTypeParameterDeclaration.java | 26 +- .../ResolvedTypeParametrizable.java | 2 + .../ResolvedValueDeclaration.java | 3 + .../resolution/types/ResolvedArrayType.java | 30 +- .../types/ResolvedIntersectionType.java | 15 +- .../types/ResolvedLambdaConstraintType.java | 8 +- .../types/ResolvedPrimitiveType.java | 42 +- .../types/ResolvedReferenceType.java | 225 ++-- .../resolution/types/ResolvedType.java | 51 +- .../types/ResolvedTypeTransformer.java | 2 +- .../types/ResolvedTypeVariable.java | 21 +- .../resolution/types/ResolvedUnionType.java | 23 +- .../resolution/types/ResolvedVoidType.java | 2 +- .../resolution/types/ResolvedWildcard.java | 29 +- .../ResolvedTypeParameterValueProvider.java | 4 + .../ResolvedTypeParametersMap.java | 30 +- .../ResolvedTypeParametrized.java | 2 +- .../github/javaparser/utils/ClassUtils.java | 2 +- .../javaparser/utils/CodeGenerationUtils.java | 2 +- .../javaparser/utils/CollectionStrategy.java | 2 + .../javaparser/utils/LineSeparator.java | 27 +- .../java/com/github/javaparser/utils/Log.java | 8 +- .../com/github/javaparser/utils/Pair.java | 18 +- .../utils/ParserCollectionStrategy.java | 9 +- .../javaparser/utils/PositionUtils.java | 51 +- .../github/javaparser/utils/ProjectRoot.java | 3 +- .../utils/SeparatedItemStringBuilder.java | 6 +- .../github/javaparser/utils/SourceRoot.java | 69 +- .../github/javaparser/utils/SourceZip.java | 16 +- .../javaparser/utils/StringEscapeUtils.java | 70 +- .../com/github/javaparser/utils/Utils.java | 20 +- .../github/javaparser/utils/VisitorList.java | 35 +- .../github/javaparser/utils/VisitorMap.java | 15 +- .../github/javaparser/utils/VisitorSet.java | 31 +- 236 files changed, 4211 insertions(+), 2249 deletions(-) diff --git a/javaparser-core/bnd.bnd b/javaparser-core/bnd.bnd index 9e678f6b78..9d1d1b49e2 100644 --- a/javaparser-core/bnd.bnd +++ b/javaparser-core/bnd.bnd @@ -29,7 +29,6 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core com.github.javaparser.printer.configuration, \ com.github.javaparser.printer.lexicalpreservation, \ com.github.javaparser.printer.lexicalpreservation.changes, \ - com.github.javaparser.quality, \ com.github.javaparser.resolution, \ com.github.javaparser.resolution.declarations, \ com.github.javaparser.resolution.types, \ diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java index cc0d11e0cb..5dc320f046 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -42,7 +43,6 @@ * @author Júlio Vilmar Gesser */ class CommentsInserter { - private final ParserConfiguration configuration; CommentsInserter(ParserConfiguration configuration) { @@ -56,14 +56,20 @@ class CommentsInserter { private void insertComments(CompilationUnit cu, TreeSet comments) { if (comments.isEmpty()) return; + /* I should sort all the direct children and the comments, if a comment is the first thing then it is a comment to the CompilationUnit */ + // FIXME if there is no package it could be also a comment to the following class... // so I could use some heuristics in these cases to distinguish the two // cases + List children = cu.getChildNodes(); + Comment firstComment = comments.iterator().next(); - if (cu.getPackageDeclaration().isPresent() && (children.isEmpty() || PositionUtils.areInOrder(firstComment, cu.getPackageDeclaration().get()))) { + if (cu.getPackageDeclaration().isPresent() + && (children.isEmpty() || PositionUtils.areInOrder( + firstComment, cu.getPackageDeclaration().get()))) { cu.setComment(firstComment); comments.remove(firstComment); } @@ -76,23 +82,37 @@ private void insertComments(CompilationUnit cu, TreeSet comments) { void insertComments(Node node, TreeSet commentsToAttribute) { if (commentsToAttribute.isEmpty()) return; + if (node instanceof CompilationUnit) { insertComments((CompilationUnit) node, commentsToAttribute); } + /* the comment can... 1) be inside one of the children, then the comment should be associated to this child 2) be outside all children. They could be preceding nothing, a comment or a child. If they preceed a child they are assigned to it, otherwise they remain "orphans" */ - List children = node.getChildNodes().stream().filter(n -> !(n instanceof Modifier)).collect(toList()); + + List children = node.getChildNodes().stream() + // Never attribute comments to modifiers. + .filter(n -> !(n instanceof Modifier)) + .collect(toList()); + boolean attributeToAnnotation = !(configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node child : children) { TreeSet commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION); - commentsInsideChild.addAll(commentsToAttribute.stream().filter(comment -> comment.getRange().isPresent()).filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)).collect(toList())); + commentsInsideChild.addAll( + commentsToAttribute.stream() + .filter(comment -> comment.getRange().isPresent()) + .filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)) + .collect(toList()) + ); commentsToAttribute.removeAll(commentsInsideChild); insertComments(child, commentsInsideChild); } + attributeLineCommentsOnSameLine(commentsToAttribute, children); + /* if a comment is on the line right before a node it should belong to that node*/ if (!commentsToAttribute.isEmpty()) { @@ -101,6 +121,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { commentsToAttribute.remove(commentsToAttribute.first()); } } + /* at this point I create an ordered list of all remaining comments and children */ Comment previousComment = null; @@ -109,8 +130,11 @@ void insertComments(Node node, TreeSet commentsToAttribute) { // Avoid attributing comments to a meaningless container. childrenAndComments.addAll(children); commentsToAttribute.removeAll(attributedComments); + childrenAndComments.addAll(commentsToAttribute); - PositionUtils.sortByBeginPosition(childrenAndComments, configuration.isIgnoreAnnotationsWhenAttributingComments()); + PositionUtils.sortByBeginPosition(childrenAndComments, + configuration.isIgnoreAnnotationsWhenAttributingComments()); + for (Node thing : childrenAndComments) { if (thing instanceof Comment) { previousComment = (Comment) thing; @@ -119,7 +143,8 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } else { if (previousComment != null && !thing.getComment().isPresent()) { - if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() || !thereAreLinesBetween(previousComment, thing)) { + if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() + || !thereAreLinesBetween(previousComment, thing)) { thing.setComment(previousComment); attributedComments.add(previousComment); previousComment = null; @@ -127,7 +152,9 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } } + commentsToAttribute.removeAll(attributedComments); + // all the remaining are orphan nodes for (Comment c : commentsToAttribute) { if (c.isOrphan()) { @@ -140,13 +167,20 @@ private void attributeLineCommentsOnSameLine(TreeSet commentsToAttribut /* I can attribute in line comments to elements preceeding them, if there is something contained in their line */ List attributedComments = new LinkedList<>(); - commentsToAttribute.stream().filter(comment -> comment.getRange().isPresent()).filter(Comment::isLineComment).forEach(comment -> children.stream().filter(child -> child.getRange().isPresent()).forEach(child -> { - Range commentRange = comment.getRange().get(); - Range childRange = child.getRange().get(); - if (childRange.end.line == commentRange.begin.line && attributeLineCommentToNodeOrChild(child, comment.asLineComment())) { - attributedComments.add(comment); - } - })); + commentsToAttribute.stream() + .filter(comment -> comment.getRange().isPresent()) + .filter(Comment::isLineComment) + .forEach(comment -> children.stream() + .filter(child -> child.getRange().isPresent()) + .forEach(child -> { + Range commentRange = comment.getRange().get(); + Range childRange = child.getRange().get(); + if (childRange.end.line == commentRange.begin.line + && attributeLineCommentToNodeOrChild(child, + comment.asLineComment())) { + attributedComments.add(comment); + } + })); commentsToAttribute.removeAll(attributedComments); } @@ -154,9 +188,11 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom if (!node.getRange().isPresent() || !lineComment.getRange().isPresent()) { return false; } + // The node start and end at the same line as the comment, // let's give to it the comment - if (node.getBegin().get().line == lineComment.getBegin().get().line && !node.getComment().isPresent()) { + if (node.getBegin().get().line == lineComment.getBegin().get().line + && !node.getComment().isPresent()) { if (!(node instanceof Comment)) { node.setComment(lineComment); } @@ -168,11 +204,13 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom children.addAll(node.getChildNodes()); PositionUtils.sortByBeginPosition(children); Collections.reverse(children); + for (Node child : children) { if (attributeLineCommentToNodeOrChild(child, lineComment)) { return true; } } + return false; } } @@ -189,8 +227,8 @@ private boolean thereAreLinesBetween(Node a, Node b) { } private boolean commentIsOnNextLine(Node a, Comment c) { - if (!c.getRange().isPresent() || !a.getRange().isPresent()) - return false; + if (!c.getRange().isPresent() || !a.getRange().isPresent()) return false; return c.getRange().get().end.line + 1 == a.getRange().get().begin.line; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java index 85fc685c0c..7ab0fa51d2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -18,14 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ -package com.github.javaparser; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.observer.Observable; +package com.github.javaparser; import java.util.Optional; import java.util.function.Predicate; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.Observable; + /** * An object that can have a parent node. */ @@ -37,7 +38,7 @@ public interface HasParentNode extends Observable { default boolean hasParentNode() { return getParentNode().isPresent(); } - + /** * Returns the parent node, or {@code Optional.empty} if no parent is set. */ @@ -96,4 +97,5 @@ default Optional findAncestor(Class type, Predicate predicate) { default boolean isDescendantOf(Node ancestor) { return findAncestor(Node.class, n -> n == ancestor).isPresent(); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java index 989dc5cfe9..ed576eda30 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -54,7 +55,6 @@ * @see StaticJavaParser */ public final class JavaParser { - private final ParserConfiguration configuration; private GeneratedJavaParser astParser = null; @@ -90,9 +90,10 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { } astParser.setTabSize(configuration.getTabSize()); astParser.setStoreTokens(configuration.isStoreTokens()); + ParserConfiguration.LanguageLevel languageLevel = configuration.getLanguageLevel(); if (languageLevel != null) { - if (languageLevel.isYieldSupported()) { + if(languageLevel.isYieldSupported()) { astParser.setYieldSupported(); } } @@ -112,15 +113,22 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { public ParseResult parse(ParseStart start, Provider provider) { assertNotNull(start); assertNotNull(provider); + for (PreProcessor preProcessor : configuration.getPreProcessors()) { provider = preProcessor.process(provider); } + final GeneratedJavaParser parser = getParserForProvider(provider); try { N resultNode = start.parse(parser); ParseResult result = new ParseResult<>(resultNode, parser.problems, parser.getCommentsCollection()); - configuration.getPostProcessors().forEach(postProcessor -> postProcessor.process(result, configuration)); - result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION); + + configuration.getPostProcessors() + .forEach(postProcessor -> postProcessor.process(result, configuration)); + + result.getProblems() + .sort(PROBLEM_BY_BEGIN_POSITION); + return result; } catch (Exception e) { final String message = e.getMessage() == null ? "Unknown error" : e.getMessage(); @@ -508,6 +516,7 @@ public ParseResult parseModuleDirective(String moduleDirective) return parse(MODULE_DIRECTIVE, provider(moduleDirective)); } + /** * Parses a type parameter and returns it as a TypeParameter * @@ -530,4 +539,5 @@ public ParseResult parseTypeParameter(String typeParameter) { public ParseResult parseMethodDeclaration(String methodDeclaration) { return parse(METHOD_DECLARATION, provider(methodDeclaration)); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java index 1149d8ffe5..fd7ce3086f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.JavadocBlockTag; import com.github.javaparser.javadoc.description.JavadocDescription; - import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -40,7 +40,6 @@ class JavadocParser { private static String BLOCK_TAG_PREFIX = "@"; - private static Pattern BLOCK_PATTERN = Pattern.compile("^\\s*" + BLOCK_TAG_PREFIX, Pattern.MULTILINE); public static Javadoc parse(JavadocComment comment) { @@ -49,7 +48,11 @@ public static Javadoc parse(JavadocComment comment) { public static Javadoc parse(String commentContent) { List cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, SYSTEM_EOL)); - int indexOfFirstBlockTag = cleanLines.stream().filter(JavadocParser::isABlockLine).map(cleanLines::indexOf).findFirst().orElse(-1); + int indexOfFirstBlockTag = cleanLines.stream() + .filter(JavadocParser::isABlockLine) + .map(cleanLines::indexOf) + .findFirst() + .orElse(-1); List blockLines; String descriptionText; if (indexOfFirstBlockTag == -1) { @@ -57,13 +60,21 @@ public static Javadoc parse(String commentContent) { blockLines = Collections.emptyList(); } else { descriptionText = trimRight(String.join(SYSTEM_EOL, cleanLines.subList(0, indexOfFirstBlockTag))); - // Combine cleaned lines, but only starting with the first block tag till the end - // In this combined string it is easier to handle multiple lines which actually belong together - String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()).stream().collect(Collectors.joining(SYSTEM_EOL)); - // Split up the entire tag back again, considering now that some lines belong to the same block tag. - // The pattern splits the block at each new line starting with the '@' symbol, thus the symbol - // then needs to be added again so that the block parsers handles everything correctly. - blockLines = BLOCK_PATTERN.splitAsStream(tagBlock).filter(s1 -> !s1.isEmpty()).map(s -> BLOCK_TAG_PREFIX + s).collect(Collectors.toList()); + + //Combine cleaned lines, but only starting with the first block tag till the end + //In this combined string it is easier to handle multiple lines which actually belong together + String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()) + .stream() + .collect(Collectors.joining(SYSTEM_EOL)); + + //Split up the entire tag back again, considering now that some lines belong to the same block tag. + //The pattern splits the block at each new line starting with the '@' symbol, thus the symbol + //then needs to be added again so that the block parsers handles everything correctly. + blockLines = BLOCK_PATTERN + .splitAsStream(tagBlock) + .filter(s1 -> !s1.isEmpty()) + .map(s -> BLOCK_TAG_PREFIX + s) + .collect(Collectors.toList()); } Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText)); blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l))); @@ -93,6 +104,7 @@ private static List cleanLines(String content) { if (lines.length == 0) { return Collections.emptyList(); } + List cleanedLines = Arrays.stream(lines).map(l -> { int asteriskIndex = startsWithAsterisk(l); if (asteriskIndex == -1) { @@ -101,6 +113,7 @@ private static List cleanLines(String content) { // if a line starts with space followed by an asterisk drop to the asterisk // if there is a space immediately after the asterisk drop it also if (l.length() > (asteriskIndex + 1)) { + char c = l.charAt(asteriskIndex + 1); if (c == ' ' || c == '\t') { return l.substring(asteriskIndex + 2); diff --git a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java index 55438e8b8e..f13f2145d0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java @@ -82,7 +82,11 @@ private int fillBuffer() throws IOException { } public LineSeparator getDetectedLineEnding() { - return LineSeparator.getLineEnding(eolCounts.getOrDefault(LineSeparator.CR, 0), eolCounts.getOrDefault(LineSeparator.LF, 0), eolCounts.getOrDefault(LineSeparator.CRLF, 0)); + return LineSeparator.getLineEnding( + eolCounts.getOrDefault(LineSeparator.CR, 0), + eolCounts.getOrDefault(LineSeparator.LF, 0), + eolCounts.getOrDefault(LineSeparator.CRLF, 0) + ); } private boolean isBufferEmpty() { @@ -121,11 +125,14 @@ public int read(char[] buffer, final int offset, int len) throws IOException { } else { String str = String.valueOf((char) ch); Optional lookup = LineSeparator.lookup(str); + if (lookup.isPresent()) { LineSeparator lineSeparator = lookup.get(); + // Track the number of times this character is found.. eolCounts.putIfAbsent(lineSeparator, 0); eolCounts.put(lineSeparator, eolCounts.get(lineSeparator) + 1); + // Handle line separators of length two (specifically CRLF) // TODO: Make this more generic than just CRLF (e.g. track the previous char rather than the previous line separator if (lineSeparator == LineSeparator.LF) { @@ -134,16 +141,19 @@ public int read(char[] buffer, final int offset, int len) throws IOException { eolCounts.put(LineSeparator.CRLF, eolCounts.get(LineSeparator.CRLF) + 1); } } + // If "this" (current) char is a line separator, set the next loop's "previous" to this previousLineSeparator = lineSeparator; } else { // If "this" (current) char is not a line separator, set the next loop's "previous" to null previousLineSeparator = null; } + // Move to next character buffer[pos++] = (char) ch; } } return pos - offset; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java index 4fd9f12828..88d660dd07 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import java.util.List; @@ -30,7 +31,6 @@ * Thrown when parsing problems occur during parsing with the static methods on JavaParser. */ public class ParseProblemException extends RuntimeException { - /** * The problems that were encountered during parsing */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java index fae01c39d2..7aa5f322e5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.Node; @@ -33,11 +34,8 @@ * The results given when parsing with an instance of JavaParser. */ public class ParseResult { - private final T result; - private final List problems; - private final CommentsCollection commentsCollection; /** @@ -112,7 +110,6 @@ public String toString() { * A post processor that can be added to ParserConfiguration to add some processing right after parsing. */ public interface PostProcessor { - void process(ParseResult result, ParserConfiguration configuration); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java index 7bc8bb8526..1047137def 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -48,47 +49,26 @@ */ @FunctionalInterface public interface ParseStart { - ParseStart COMPILATION_UNIT = GeneratedJavaParser::CompilationUnit; - ParseStart BLOCK = GeneratedJavaParser::BlockParseStart; - ParseStart STATEMENT = GeneratedJavaParser::BlockStatementParseStart; - ParseStart IMPORT_DECLARATION = GeneratedJavaParser::ImportDeclarationParseStart; - ParseStart EXPRESSION = GeneratedJavaParser::ExpressionParseStart; - ParseStart ANNOTATION = GeneratedJavaParser::AnnotationParseStart; - ParseStart> ANNOTATION_BODY = GeneratedJavaParser::AnnotationBodyDeclarationParseStart; - ParseStart> CLASS_BODY = GeneratedJavaParser::ClassOrInterfaceBodyDeclarationParseStart; - ParseStart CLASS_OR_INTERFACE_TYPE = GeneratedJavaParser::ClassOrInterfaceTypeParseStart; - ParseStart TYPE = GeneratedJavaParser::ResultTypeParseStart; - ParseStart TYPE_PARAMETER = GeneratedJavaParser::TypeParameterParseStart; - ParseStart VARIABLE_DECLARATION_EXPR = GeneratedJavaParser::VariableDeclarationExpressionParseStart; - ParseStart EXPLICIT_CONSTRUCTOR_INVOCATION_STMT = GeneratedJavaParser::ExplicitConstructorInvocationParseStart; - ParseStart NAME = GeneratedJavaParser::NameParseStart; - ParseStart SIMPLE_NAME = GeneratedJavaParser::SimpleNameParseStart; - ParseStart PARAMETER = GeneratedJavaParser::ParameterParseStart; - ParseStart PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart; - ParseStart> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart; - ParseStart MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart; - ParseStart MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart; - ParseStart METHOD_DECLARATION = GeneratedJavaParser::MethodDeclarationParseStart; R parse(GeneratedJavaParser parser) throws ParseException; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java index f855bbf7e3..25acd289fc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ParseResult.PostProcessor; @@ -25,13 +26,12 @@ import com.github.javaparser.UnicodeEscapeProcessingProvider.PositionMapping; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.validator.ProblemReporter; -import com.github.javaparser.ast.validator.Validator; +import com.github.javaparser.ast.validator.*; import com.github.javaparser.ast.validator.language_level_validations.*; -import com.github.javaparser.ast.validator.postprocessors.Java10PostProcessor; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.utils.LineSeparator; +import com.github.javaparser.ast.validator.postprocessors.Java10PostProcessor; import java.nio.charset.Charset; import java.util.ArrayList; @@ -49,7 +49,6 @@ public class ParserConfiguration { public enum LanguageLevel { - /** * Java 1.0 */ @@ -164,27 +163,28 @@ public enum LanguageLevel { * Does no post processing or validation. Only for people wanting the fastest parsing. */ public static LanguageLevel RAW = null; - /** * The most used Java version. */ public static LanguageLevel POPULAR = JAVA_8; - /** * The latest Java version that is available. */ public static LanguageLevel CURRENT = JAVA_15; - /** * The newest Java features supported. */ public static LanguageLevel BLEEDING_EDGE = JAVA_16_PREVIEW; final Validator validator; - final ParseResult.PostProcessor postProcessor; - private static final LanguageLevel[] yieldSupport = new LanguageLevel[] { JAVA_13, JAVA_13_PREVIEW, JAVA_14, JAVA_14_PREVIEW, JAVA_15, JAVA_15_PREVIEW, JAVA_16, JAVA_16_PREVIEW }; + private static final LanguageLevel[] yieldSupport = new LanguageLevel[]{ + JAVA_13, JAVA_13_PREVIEW, + JAVA_14, JAVA_14_PREVIEW, + JAVA_15, JAVA_15_PREVIEW, + JAVA_16, JAVA_16_PREVIEW + }; LanguageLevel(Validator validator, ParseResult.PostProcessor postProcessor) { this.validator = validator; @@ -196,36 +196,27 @@ public boolean isYieldSupported() { } } + + // TODO: Add a configurable option e.g. setDesiredLineEnding(...) to replace/swap out existing line endings private boolean detectOriginalLineSeparator = true; - private boolean storeTokens = true; - private boolean attributeComments = true; - private boolean doNotAssignCommentsPrecedingEmptyLines = true; - private boolean ignoreAnnotationsWhenAttributingComments = false; - private boolean lexicalPreservationEnabled = false; - private boolean preprocessUnicodeEscapes = false; - private SymbolResolver symbolResolver = null; - private int tabSize = 1; - private LanguageLevel languageLevel = JAVA_8; - private Charset characterEncoding = Providers.UTF8; private final List preProcessors = new ArrayList<>(); - private final List postProcessors = new ArrayList<>(); public ParserConfiguration() { - class UnicodeEscapeProcessor implements PreProcessor, PostProcessor { + class UnicodeEscapeProcessor implements PreProcessor, PostProcessor { private UnicodeEscapeProcessingProvider _unicodeDecoder; @Override @@ -238,19 +229,24 @@ public Provider process(Provider innerProvider) { } @Override - public void process(ParseResult result, ParserConfiguration configuration) { + public void process(ParseResult result, + ParserConfiguration configuration) { if (isPreprocessUnicodeEscapes()) { - result.getResult().ifPresent(root -> { - PositionMapping mapping = _unicodeDecoder.getPositionMapping(); - if (!mapping.isEmpty()) { - root.walk(node -> node.getRange().ifPresent(range -> node.setRange(mapping.transform(range)))); - } - }); + result.getResult().ifPresent( + root -> { + PositionMapping mapping = _unicodeDecoder.getPositionMapping(); + if (!mapping.isEmpty()) { + root.walk( + node -> node.getRange().ifPresent( + range -> node.setRange(mapping.transform(range)))); + } + } + ); } } } - class LineEndingProcessor implements PreProcessor, PostProcessor { + class LineEndingProcessor implements PreProcessor, PostProcessor { private LineEndingProcessingProvider _lineEndingProcessingProvider; @Override @@ -265,26 +261,36 @@ public Provider process(Provider innerProvider) { @Override public void process(ParseResult result, ParserConfiguration configuration) { if (isDetectOriginalLineSeparator()) { - result.getResult().ifPresent(rootNode -> { - LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); - // Set the line ending on the root node - rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); - // // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" - // rootNode.findAll(Node.class) - // .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); - }); + result.getResult().ifPresent( + rootNode -> { + LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); + + // Set the line ending on the root node + rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); + +// // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" +// rootNode.findAll(Node.class) +// .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); + } + ); } } } + UnicodeEscapeProcessor unicodeProcessor = new UnicodeEscapeProcessor(); preProcessors.add(unicodeProcessor); postProcessors.add(unicodeProcessor); + LineEndingProcessor lineEndingProcessor = new LineEndingProcessor(); preProcessors.add(lineEndingProcessor); postProcessors.add(lineEndingProcessor); + + postProcessors.add((result, configuration) -> { if (configuration.isAttributeComments()) { - result.ifSuccessful(resultNode -> result.getCommentsCollection().ifPresent(comments -> new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); + result.ifSuccessful(resultNode -> result + .getCommentsCollection().ifPresent(comments -> + new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); } }); postProcessors.add((result, configuration) -> { @@ -298,11 +304,13 @@ public void process(ParseResult result, ParserConfiguration conf } } }); - postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver -> result.ifSuccessful(resultNode -> { - if (resultNode instanceof CompilationUnit) { - resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); - } - }))); + postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver -> + result.ifSuccessful(resultNode -> { + if (resultNode instanceof CompilationUnit) { + resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); + } + }) + )); postProcessors.add((result, configuration) -> { if (configuration.isLexicalPreservationEnabled()) { result.ifSuccessful(LexicalPreservingPrinter::setup); @@ -448,4 +456,5 @@ public ParserConfiguration setCharacterEncoding(Charset characterEncoding) { this.characterEncoding = characterEncoding; return this; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index d730db2085..907bf351c4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -18,8 +18,11 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; +import com.github.javaparser.ast.Node; + import java.util.Objects; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -28,26 +31,23 @@ * A position in a source file. Lines and columns start counting at 1. */ public class Position implements Comparable { - public final int line; - public final int column; /** * The first line -- note that it is 1-indexed (i.e. the first line is line 1, as opposed to 0) */ public static final int FIRST_LINE = 1; - /** * The first column -- note that it is 1-indexed (i.e. the first column is column 1, as opposed to 0) */ public static final int FIRST_COLUMN = 1; - /** * The first position in the file. */ public static final Position HOME = new Position(FIRST_LINE, FIRST_COLUMN); + /** * Line numbers must be positive, thus */ @@ -55,6 +55,7 @@ public class Position implements Comparable { public static final int ABSOLUTE_END_LINE = -2; + /** * TODO: Do we refer to the characters as columns, * ...or the spaces between (thus also before/after) characters as columns? @@ -66,8 +67,8 @@ public Position(int line, int column) { } if (column < -1) { // TODO: This allows/permits column 0, which seemingly contradicts first column being 1 - // ... (see also nextLine() which indicates 1 being the first column of the next line) - // ... (see also valid() which requires a column > 0) + // ... (see also nextLine() which indicates 1 being the first column of the next line) + // ... (see also valid() which requires a column > 0) // TODO: Maybe we need an "ABSOLUTE_BEGIN_LINE" and "ABSOLUTE_END_LINE"? throw new IllegalArgumentException("Can't position at column " + column); } @@ -139,7 +140,7 @@ public boolean invalid() { public Position orIfInvalid(Position alternativePosition) { assertNotNull(alternativePosition); // TODO: Why the || ? - // ... It seems that if both this and the alternative are invalid, then we return this..? + // ... It seems that if both this and the alternative are invalid, then we return this..? if (valid() || alternativePosition.invalid()) { return this; } @@ -158,6 +159,7 @@ public boolean isAfter(Position otherPosition) { return column > otherPosition.column; } return false; + } public boolean isAfterOrEqual(Position otherPosition) { @@ -198,12 +200,13 @@ public int compareTo(Position otherPosition) { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Position otherPosition = (Position) o; - return Objects.equals(line, otherPosition.line) && Objects.equals(column, otherPosition.column); + + return Objects.equals(line, otherPosition.line) + && Objects.equals(column, otherPosition.column); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/Problem.java b/javaparser-core/src/main/java/com/github/javaparser/Problem.java index d1cbd2daeb..f881daffef 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Problem.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Problem.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import java.util.Comparator; @@ -30,15 +31,13 @@ * A problem that was encountered during parsing. */ public class Problem { - private final String message; - private final TokenRange location; - private final Throwable cause; public Problem(String message, TokenRange location, Throwable cause) { assertNotNull(message); + this.message = message; this.location = location; this.cause = cause; @@ -91,8 +90,9 @@ public Optional getCause() { * Sorts problems on position. */ public static Comparator PROBLEM_BY_BEGIN_POSITION = (a, b) -> { - final Optional aBegin = a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + final Optional aBegin= a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); final Optional bBegin = b.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + if (aBegin.isPresent() && bBegin.isPresent()) { return aBegin.get().compareTo(bBegin.get()); } @@ -104,4 +104,6 @@ public Optional getCause() { } return 0; }; + + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Providers.java b/javaparser-core/src/main/java/com/github/javaparser/Providers.java index c907fcdd6f..07a86f5683 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Providers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Providers.java @@ -18,9 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -32,7 +38,6 @@ * use UTF-8. */ public final class Providers { - public static final Charset UTF8 = Charset.forName("utf-8"); private Providers() { @@ -78,6 +83,7 @@ public static Provider provider(String source) { return new StringProvider(assertNotNull(source)); } + /** * Provide a Provider from the resource found in class loader with the provided encoding.
As resource is * accessed through a class loader, a leading "/" is not allowed in pathToResource @@ -108,7 +114,6 @@ public static Provider resourceProvider(String pathToResource) throws IOExceptio } public interface PreProcessor { - Provider process(Provider innerProvider); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Range.java b/javaparser-core/src/main/java/com/github/javaparser/Range.java index 0dfc747afe..796e026a59 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Range.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Range.java @@ -18,15 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; +import static com.github.javaparser.Position.pos; + /** * A range of characters in a source file, from "begin" to "end", including the characters at "begin" and "end". */ public class Range { - public final Position begin; - public final Position end; /** @@ -45,6 +46,7 @@ public Range(Position begin, Position end) { if (end == null) { throw new IllegalArgumentException("end can't be null"); } + // Force `begin` to be the position that is earliest within the document: if (begin.isBefore(end)) { this.begin = begin; @@ -116,6 +118,7 @@ public Range withEndLine(int endLine) { return range(begin, end.withLine(endLine)); } + /** * @param begin The value used to replace the current begin position. * @return A copy of this `Range` object, but with the begin position replaced with the given position. @@ -190,7 +193,8 @@ public boolean strictlyContains(Position position) { * Range 2: CDE */ public boolean overlapsWith(Range other) { - return (contains(other.begin) || contains(other.end)) || (other.contains(begin) || other.contains(end)); + return (contains(other.begin) || contains(other.end)) || + (other.contains(begin) || other.contains(end)); } /** @@ -211,10 +215,9 @@ public boolean isAfter(Position position) { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Range range = (Range) o; return begin.equals(range.begin) && end.equals(range.end); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java index 7e7da4fb07..abfb86cee8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -39,7 +40,6 @@ import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.quality.NotNull; -import com.github.javaparser.quality.Preconditions; import java.io.*; import java.nio.charset.Charset; @@ -49,7 +49,7 @@ * A simpler, static API than {@link JavaParser}. */ public final class StaticJavaParser { - + // use ThreadLocal to resolve possible concurrency issues. private static ThreadLocal localConfiguration = ThreadLocal.withInitial(() -> new ParserConfiguration()); @@ -68,7 +68,6 @@ public static ParserConfiguration getConfiguration() { * This is a STATIC field, so modifying it will directly change how all static parse... methods work! */ public static void setConfiguration(@NotNull ParserConfiguration configuration) { - Preconditions.checkNotNull(configuration, "Parameter configuration can't be null."); localConfiguration.set(configuration); } @@ -88,8 +87,6 @@ private static JavaParser newParser() { */ @Deprecated public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Charset encoding) { - Preconditions.checkNotNull(in, "Parameter in can't be null."); - Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(in, encoding)); } @@ -102,7 +99,6 @@ public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Char * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final InputStream in) { - Preconditions.checkNotNull(in, "Parameter in can't be null."); return handleResult(newParser().parse(in)); } @@ -119,8 +115,6 @@ public static CompilationUnit parse(@NotNull final InputStream in) { */ @Deprecated public static CompilationUnit parse(@NotNull final File file, @NotNull final Charset encoding) throws FileNotFoundException { - Preconditions.checkNotNull(file, "Parameter file can't be null."); - Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(file, encoding)); } @@ -134,7 +128,6 @@ public static CompilationUnit parse(@NotNull final File file, @NotNull final Cha * @throws FileNotFoundException the file was not found */ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoundException { - Preconditions.checkNotNull(file, "Parameter file can't be null."); return handleResult(newParser().parse(file)); } @@ -151,8 +144,6 @@ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoun */ @Deprecated public static CompilationUnit parse(@NotNull final Path path, @NotNull final Charset encoding) throws IOException { - Preconditions.checkNotNull(path, "Parameter path can't be null."); - Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(path, encoding)); } @@ -166,7 +157,6 @@ public static CompilationUnit parse(@NotNull final Path path, @NotNull final Cha * @throws IOException the path could not be accessed */ public static CompilationUnit parse(@NotNull final Path path) throws IOException { - Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parse(path)); } @@ -181,7 +171,6 @@ public static CompilationUnit parse(@NotNull final Path path) throws IOException * @throws IOException the path could not be accessed */ public static CompilationUnit parseResource(@NotNull final String path) throws IOException { - Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parseResource(path)); } @@ -199,8 +188,6 @@ public static CompilationUnit parseResource(@NotNull final String path) throws I */ @Deprecated public static CompilationUnit parseResource(@NotNull final String path, @NotNull Charset encoding) throws IOException { - Preconditions.checkNotNull(path, "Parameter path can't be null."); - Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parseResource(path, encoding)); } @@ -217,10 +204,9 @@ public static CompilationUnit parseResource(@NotNull final String path, @NotNull * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, @NotNull final String path, @NotNull Charset encoding) throws IOException { - Preconditions.checkNotNull(classLoader, "Parameter classLoader can't be null."); - Preconditions.checkNotNull(path, "Parameter path can't be null."); - Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); + public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, + @NotNull final String path, + @NotNull Charset encoding) throws IOException { return handleResult(newParser().parseResource(classLoader, path, encoding)); } @@ -233,7 +219,6 @@ public static CompilationUnit parseResource(@NotNull final ClassLoader classLoad * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final Reader reader) { - Preconditions.checkNotNull(reader, "Parameter reader can't be null."); return handleResult(newParser().parse(reader)); } @@ -246,7 +231,6 @@ public static CompilationUnit parse(@NotNull final Reader reader) { * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull String code) { - Preconditions.checkNotNull(code, "Parameter code can't be null."); return handleResult(newParser().parse(code)); } @@ -259,7 +243,6 @@ public static CompilationUnit parse(@NotNull String code) { * @throws ParseProblemException if the source code has parser errors */ public static BlockStmt parseBlock(@NotNull final String blockStatement) { - Preconditions.checkNotNull(blockStatement, "Parameter blockStatement can't be null."); return handleResult(newParser().parseBlock(blockStatement)); } @@ -272,7 +255,6 @@ public static BlockStmt parseBlock(@NotNull final String blockStatement) { * @throws ParseProblemException if the source code has parser errors */ public static Statement parseStatement(@NotNull final String statement) { - Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseStatement(statement)); } @@ -292,7 +274,6 @@ private static T handleResult(ParseResult result) { * @throws ParseProblemException if the source code has parser errors */ public static ImportDeclaration parseImport(@NotNull final String importDeclaration) { - Preconditions.checkNotNull(importDeclaration, "Parameter importDeclaration can't be null."); return handleResult(newParser().parseImport(importDeclaration)); } @@ -305,7 +286,6 @@ public static ImportDeclaration parseImport(@NotNull final String importDeclarat * @throws ParseProblemException if the source code has parser errors */ public static T parseExpression(@NotNull final String expression) { - Preconditions.checkNotNull(expression, "Parameter expression can't be null."); return handleResult(newParser().parseExpression(expression)); } @@ -318,7 +298,6 @@ public static T parseExpression(@NotNull final String exp * @throws ParseProblemException if the source code has parser errors */ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { - Preconditions.checkNotNull(annotation, "Parameter annotation can't be null."); return handleResult(newParser().parseAnnotation(annotation)); } @@ -331,7 +310,6 @@ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final String body) { - Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseAnnotationBodyDeclaration(body)); } @@ -344,7 +322,6 @@ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final S * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { - Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseBodyDeclaration(body)); } @@ -356,7 +333,6 @@ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { * @throws ParseProblemException if the source code has parser errors */ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String type) { - Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseClassOrInterfaceType(type)); } @@ -368,7 +344,6 @@ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String typ * @throws ParseProblemException if the source code has parser errors */ public static Type parseType(@NotNull String type) { - Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseType(type)); } @@ -381,7 +356,6 @@ public static Type parseType(@NotNull String type) { * @throws ParseProblemException if the source code has parser errors */ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull String declaration) { - Preconditions.checkNotNull(declaration, "Parameter declaration can't be null."); return handleResult(newParser().parseVariableDeclarationExpr(declaration)); } @@ -394,7 +368,6 @@ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull Stri * @throws ParseProblemException if the source code has parser errors */ public static Javadoc parseJavadoc(@NotNull String content) { - Preconditions.checkNotNull(content, "Parameter content can't be null."); return JavadocParser.parse(content); } @@ -406,7 +379,6 @@ public static Javadoc parseJavadoc(@NotNull String content) { * @throws ParseProblemException if the source code has parser errors */ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(@NotNull String statement) { - Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseExplicitConstructorInvocationStmt(statement)); } @@ -418,7 +390,6 @@ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocati * @throws ParseProblemException if the source code has parser errors */ public static Name parseName(@NotNull String qualifiedName) { - Preconditions.checkNotNull(qualifiedName, "Parameter qualifiedName can't be null."); return handleResult(newParser().parseName(qualifiedName)); } @@ -430,7 +401,6 @@ public static Name parseName(@NotNull String qualifiedName) { * @throws ParseProblemException if the source code has parser errors */ public static SimpleName parseSimpleName(@NotNull String name) { - Preconditions.checkNotNull(name, "Parameter name can't be null."); return handleResult(newParser().parseSimpleName(name)); } @@ -442,7 +412,6 @@ public static SimpleName parseSimpleName(@NotNull String name) { * @throws ParseProblemException if the source code has parser errors */ public static Parameter parseParameter(@NotNull String parameter) { - Preconditions.checkNotNull(parameter, "Parameter parameter can't be null."); return handleResult(newParser().parseParameter(parameter)); } @@ -454,7 +423,6 @@ public static Parameter parseParameter(@NotNull String parameter) { * @throws ParseProblemException if the source code has parser errors */ public static PackageDeclaration parsePackageDeclaration(@NotNull String packageDeclaration) { - Preconditions.checkNotNull(packageDeclaration, "Parameter packageDeclaration can't be null."); return handleResult(newParser().parsePackageDeclaration(packageDeclaration)); } @@ -466,7 +434,6 @@ public static PackageDeclaration parsePackageDeclaration(@NotNull String package * @throws ParseProblemException if the source code has parser errors */ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclaration) { - Preconditions.checkNotNull(typeDeclaration, "Parameter typeDeclaration can't be null."); return handleResult(newParser().parseTypeDeclaration(typeDeclaration)); } @@ -479,7 +446,6 @@ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclar * @see ModuleDeclaration */ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDeclaration) { - Preconditions.checkNotNull(moduleDeclaration, "Parameter moduleDeclaration can't be null."); return handleResult(newParser().parseModuleDeclaration(moduleDeclaration)); } @@ -492,10 +458,10 @@ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDec * @see ModuleDirective */ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirective) { - Preconditions.checkNotNull(moduleDirective, "Parameter moduleDirective can't be null."); return handleResult(newParser().parseModuleDirective(moduleDirective)); } + /** * Parses a type parameter and returns it as a TypeParameter * @@ -504,7 +470,6 @@ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirecti * @throws ParseProblemException if the source code has parser errors */ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { - Preconditions.checkNotNull(typeParameter, "Parameter typeParameter can't be null."); return handleResult(newParser().parseTypeParameter(typeParameter)); } @@ -517,7 +482,7 @@ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { * @see MethodDeclaration */ public static MethodDeclaration parseMethodDeclaration(@NotNull String methodDeclaration) { - Preconditions.checkNotNull(methodDeclaration, "Parameter methodDeclaration can't be null."); return handleResult(newParser().parseMethodDeclaration(methodDeclaration)); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java index 9c7889ed0d..1796581feb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java @@ -18,22 +18,21 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; +import static com.github.javaparser.utils.Utils.assertNotNull; + import java.util.Iterator; import java.util.Optional; -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * The range of tokens covered by this node. */ public class TokenRange implements Iterable { - public static final TokenRange INVALID = new TokenRange(JavaToken.INVALID, JavaToken.INVALID); private final JavaToken begin; - private final JavaToken end; public TokenRange(JavaToken begin, JavaToken end) { @@ -67,7 +66,7 @@ public TokenRange withEnd(JavaToken end) { @Override public String toString() { StringBuilder result = new StringBuilder(); - for (JavaToken t : this) { + for(JavaToken t: this) { result.append(t.getText()); } return result.toString(); @@ -76,9 +75,7 @@ public String toString() { @Override public Iterator iterator() { return new Iterator() { - private boolean hasNext = true; - private JavaToken current = begin; @Override @@ -89,14 +86,14 @@ public boolean hasNext() { @Override public JavaToken next() { JavaToken retval = current; - if (current == null) { + if(current == null){ throw new IllegalStateException("Attempting to move past end of range."); } if (current == end) { hasNext = false; } current = current.getNextToken().orElse(null); - if (current == null && hasNext) { + if(current == null && hasNext){ throw new IllegalStateException("End token is not linked to begin token."); } return retval; diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java index 36836f1260..a5554efa36 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser; import com.github.javaparser.utils.LineSeparator; @@ -28,7 +29,6 @@ * Complements GeneratedJavaParserConstants */ public class TokenTypes { - public static boolean isWhitespace(int kind) { return getCategory(kind).isWhitespace(); } @@ -96,7 +96,7 @@ public static int spaceTokenKind() { * FIXME: It appears that {@code ...} {@code ELLIPSIS} and {@code ::} {@code DOUBLECOLON} are (wrongly) listed in the "operators" section, rather than "separators" */ public static JavaToken.Category getCategory(int kind) { - switch(kind) { + switch (kind) { case WINDOWS_EOL: case UNIX_EOL: case OLD_MAC_EOL: diff --git a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java index 80c14c666d..63032c829a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java @@ -29,571 +29,572 @@ * {@link Provider} un-escaping unicode escape sequences in the input sequence. */ public class UnicodeEscapeProcessingProvider implements Provider { - - private static final char LF = '\n'; - - private static final char CR = '\r'; - - private static final char BACKSLASH = '\\'; - - private static final int EOF = -1; - - private char[] _data; - - /** - * The number of characters in {@link #_data}. - */ - private int _len = 0; - - /** - * The position in {@link #_data} where to read the next source character from. - */ - private int _pos = 0; - - private boolean _backslashSeen; - - private final LineCounter _inputLine = new LineCounter(); - - private final LineCounter _outputLine = new LineCounter(); - - private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); - - private Provider _input; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(Provider input) { - this(2048, input); - } - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { - _input = input; - _data = new char[bufferSize]; - } - - /** - * The {@link LineCounter} of the input file. - */ - public LineCounter getInputCounter() { - return _inputLine; - } - - /** - * The {@link LineCounter} of the output file. - */ - public LineCounter getOutputCounter() { - return _outputLine; - } - - @Override - public int read(char[] buffer, final int offset, int len) throws IOException { - int pos = offset; - int stop = offset + len; - while (pos < stop) { - int ch = _outputLine.process(nextOutputChar()); - if (ch < 0) { - if (pos == offset) { - // Nothing read yet, this is the end of the stream. - return EOF; - } else { - break; - } - } else { - _mappingBuilder.update(); - buffer[pos++] = (char) ch; - } - } - return pos - offset; - } - - @Override - public void close() throws IOException { - _input.close(); - } - - /** - * Produces the next un-escaped character to be written to the output. - * - * @return The next character or {@code -1} if no more characters are available. - */ - private int nextOutputChar() throws IOException { - int next = nextInputChar(); - switch(next) { - case EOF: - return EOF; - case BACKSLASH: - { - if (_backslashSeen) { - return clearBackSlashSeen(next); - } else { - return backSlashSeen(); - } - } - default: - { - // An arbitrary character. - return clearBackSlashSeen(next); - } - } - } - - private int clearBackSlashSeen(int next) { - _backslashSeen = false; - return next; - } - - private int backSlashSeen() throws IOException { - _backslashSeen = true; - int next = nextInputChar(); - switch(next) { - case EOF: - // End of file after backslash produces the backslash itself. - return BACKSLASH; - case 'u': - { - return unicodeStartSeen(); - } - default: - { - pushBack(next); - return BACKSLASH; - } - } - } - - private int unicodeStartSeen() throws IOException { - int uCnt = 1; - while (true) { - int next = nextInputChar(); - switch(next) { - case EOF: - { - pushBackUs(uCnt); - return BACKSLASH; - } - case 'u': - { - uCnt++; - continue; - } - default: - { - return readDigits(uCnt, next); - } - } - } - } - - private int readDigits(int uCnt, int next3) throws IOException { - int digit3 = digit(next3); - if (digit3 < 0) { - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - int next2 = nextInputChar(); - int digit2 = digit(next2); - if (digit2 < 0) { - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - int next1 = nextInputChar(); - int digit1 = digit(next1); - if (digit1 < 0) { - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - int next0 = nextInputChar(); - int digit0 = digit(next0); - if (digit0 < 0) { - pushBack(next0); - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; - return clearBackSlashSeen(ch); - } - - private void pushBackUs(int cnt) { - for (int n = 0; n < cnt; n++) { - pushBack('u'); - } - } - - private static int digit(int ch) { - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } - if (ch >= 'A' && ch <= 'F') { - return 10 + ch - 'A'; - } - if (ch >= 'a' && ch <= 'f') { - return 10 + ch - 'a'; - } - return -1; - } - - /** - * Processes column/line information from the input file. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextInputChar() throws IOException { - int result = nextBufferedChar(); - return _inputLine.process(result); - } - - /** - * Retrieves the next un-escaped character from the buffered {@link #_input}. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextBufferedChar() throws IOException { - while (isBufferEmpty()) { - int direct = fillBuffer(); - if (direct < 0) { - return EOF; - } - } - return _data[_pos++]; - } - - private boolean isBufferEmpty() { - return _pos >= _len; - } - - private int fillBuffer() throws IOException { - _pos = 0; - int direct = _input.read(_data, 0, _data.length); - if (direct != 0) { - _len = direct; - } - return direct; - } - - private void pushBack(int ch) { - if (ch < 0) { - return; - } - if (isBufferEmpty()) { - _pos = _data.length; - _len = _data.length; - } else if (_pos == 0) { - if (_len == _data.length) { - // Buffer is completely full, no push possible, enlarge buffer. - char[] newData = new char[_data.length + 1024]; - _len = newData.length; - _pos = newData.length - _data.length; - System.arraycopy(_data, 0, newData, _pos, _data.length); - _data = newData; - } else { - // Move contents to the right. - int cnt = _len - _pos; - _pos = _data.length - _len; - _len = _data.length; - System.arraycopy(_data, 0, _data, _pos, cnt); - } - } - _data[--_pos] = (char) ch; - } - - /** - * The {@link PositionMapping} being built during processing the file. - */ - public PositionMapping getPositionMapping() { - return _mappingBuilder.getMapping(); - } - - /** - * An algorithm mapping {@link Position} form two corresponding files. - */ - public static final class PositionMapping { - - private final List _deltas = new ArrayList<>(); - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. - */ - public PositionMapping() { - super(); - } - - /** - * Whether this is the identity transformation. - */ - public boolean isEmpty() { - return _deltas.isEmpty(); - } - - void add(int line, int column, int lineDelta, int columnDelta) { - _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); - } - - /** - * Looks up the {@link PositionUpdate} for the given Position. - */ - public PositionUpdate lookup(Position position) { - int result = Collections.binarySearch(_deltas, position); - if (result >= 0) { - return _deltas.get(result); - } else { - int insertIndex = -result - 1; - if (insertIndex == 0) { - // Before the first delta info, identity mapping. - return PositionUpdate.NONE; - } else { - // The relevant update is the one with the position smaller - // than the requested position. - return _deltas.get(insertIndex - 1); - } - } - } - - /** - * Algorithm updating a {@link Position} from one file to a - * {@link Position} in a corresponding file. - */ - public static interface PositionUpdate { - - /** - * The identity position mapping. - */ - PositionUpdate NONE = new PositionUpdate() { - - @Override - public int transformLine(int line) { - return line; - } - - @Override - public int transformColumn(int column) { - return column; - } - - @Override - public Position transform(Position pos) { - return pos; - } - }; - - /** - * Maps the given line to an original line. - */ - int transformLine(int line); - - /** - * Maps the given column to an original column. - */ - int transformColumn(int column); - - /** - * The transformed position. - */ - default Position transform(Position pos) { - int line = pos.line; - int column = pos.column; - int transformedLine = transformLine(line); - int transformedColumn = transformColumn(column); - return new Position(transformedLine, transformedColumn); - } - } - - private static final class DeltaInfo extends Position implements PositionUpdate { - - /** - * The offset to add to the {@link #line} and all following source - * positions up to the next {@link PositionUpdate}. - */ - private final int _lineDelta; - - /** - * The offset to add to the {@link #column} and all following - * source positions up to the next {@link PositionUpdate}. - */ - private final int _columnDelta; - - /** - * Creates a {@link PositionUpdate}. - */ - public DeltaInfo(int line, int column, int lineDelta, int columnDelta) { - super(line, column); - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - - @Override - public int transformLine(int sourceLine) { - return sourceLine + _lineDelta; - } - - @Override - public int transformColumn(int sourceColumn) { - return sourceColumn + _columnDelta; - } - - @Override - public String toString() { - return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; - } - } - - /** - * Transforms the given {@link Position}. - */ - public Position transform(Position pos) { - return lookup(pos).transform(pos); - } - - /** - * Transforms the given {@link Range}. - */ - public Range transform(Range range) { - Position begin = transform(range.begin); - Position end = transform(range.end); - if (begin == range.begin && end == range.end) { - // No change. - return range; - } - return new Range(begin, end); - } - } - - private static final class PositionMappingBuilder { - - private LineCounter _left; - - private LineCounter _right; - - private final PositionMapping _mapping = new PositionMapping(); - - private int _lineDelta = 0; - - private int _columnDelta = 0; - - /** - * Creates a {@link PositionMappingBuilder}. - * - * @param left The source {@link LineCounter}. - * @param right The target {@link LineCounter}. - */ - public PositionMappingBuilder(LineCounter left, LineCounter right) { - _left = left; - _right = right; - update(); - } - - /** - * The built {@link PositionMapping}. - */ - public PositionMapping getMapping() { - return _mapping; - } - - public void update() { - int lineDelta = _right.getLine() - _left.getLine(); - int columnDelta = _right.getColumn() - _left.getColumn(); - if (lineDelta != _lineDelta || columnDelta != _columnDelta) { - _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - } - } - - /** - * Processor keeping track of the current line and column in a stream of - * incoming characters. - * - * @see #process(int) - */ - public static final class LineCounter { - - /** - * Whether {@link #CR} has been seen on the input as last character. - */ - private boolean _crSeen; - - private int _line = 1; - - private int _column = 1; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. - */ - public LineCounter() { - super(); - } - - /** - * The line of the currently processed input character. - */ - public int getLine() { - return _line; - } - - /** - * The column of the currently processed input character. - */ - public int getColumn() { - return _column; - } - - /** - * The current position. - */ - public Position getPosition() { - return new Position(getLine(), getColumn()); - } - - /** - * Analyzes the given character for line feed. - */ - public int process(int ch) { - switch(ch) { - case EOF: - { - break; - } - case CR: - { - incLine(); - _crSeen = true; - break; - } - case LF: - { - // CR LF does only count as a single line terminator. - if (_crSeen) { - _crSeen = false; - } else { - incLine(); - } - break; - } - default: - { - _crSeen = false; - _column++; - } - } - return ch; - } - - private void incLine() { - _line++; - _column = 1; - } - } + + private static final char LF = '\n'; + + private static final char CR = '\r'; + + private static final char BACKSLASH = '\\'; + + private static final int EOF = -1; + + private char[] _data; + + /** + * The number of characters in {@link #_data}. + */ + private int _len = 0; + + /** + * The position in {@link #_data} where to read the next source character from. + */ + private int _pos = 0; + + private boolean _backslashSeen; + + private final LineCounter _inputLine = new LineCounter(); + + private final LineCounter _outputLine = new LineCounter(); + + private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); + + private Provider _input; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(Provider input) { + this(2048, input); + } + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { + _input = input; + _data = new char[bufferSize]; + } + + /** + * The {@link LineCounter} of the input file. + */ + public LineCounter getInputCounter() { + return _inputLine; + } + + /** + * The {@link LineCounter} of the output file. + */ + public LineCounter getOutputCounter() { + return _outputLine; + } + + @Override + public int read(char[] buffer, final int offset, int len) throws IOException { + int pos = offset; + int stop = offset + len; + while (pos < stop) { + int ch = _outputLine.process(nextOutputChar()); + if (ch < 0) { + if (pos == offset) { + // Nothing read yet, this is the end of the stream. + return EOF; + } else { + break; + } + } else { + _mappingBuilder.update(); + buffer[pos++] = (char) ch; + } + } + return pos - offset; + } + + @Override + public void close() throws IOException { + _input.close(); + } + + /** + * Produces the next un-escaped character to be written to the output. + * + * @return The next character or {@code -1} if no more characters are available. + */ + private int nextOutputChar() throws IOException { + int next = nextInputChar(); + switch (next) { + case EOF: + return EOF; + case BACKSLASH: { + if (_backslashSeen) { + return clearBackSlashSeen(next); + } else { + return backSlashSeen(); + } + } + default: { + // An arbitrary character. + return clearBackSlashSeen(next); + } + } + } + + private int clearBackSlashSeen(int next) { + _backslashSeen = false; + return next; + } + + private int backSlashSeen() throws IOException { + _backslashSeen = true; + + int next = nextInputChar(); + switch (next) { + case EOF: + // End of file after backslash produces the backslash itself. + return BACKSLASH; + case 'u': { + return unicodeStartSeen(); + } + default: { + pushBack(next); + return BACKSLASH; + } + } + } + + private int unicodeStartSeen() throws IOException { + int uCnt = 1; + while (true) { + int next = nextInputChar(); + switch (next) { + case EOF: { + pushBackUs(uCnt); + return BACKSLASH; + } + case 'u': { + uCnt++; + continue; + } + default: { + return readDigits(uCnt, next); + } + } + } + } + + private int readDigits(int uCnt, int next3) throws IOException { + int digit3 = digit(next3); + if (digit3 < 0) { + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + + int next2 = nextInputChar(); + int digit2 = digit(next2); + if (digit2 < 0) { + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + + int next1 = nextInputChar(); + int digit1 = digit(next1); + if (digit1 < 0) { + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + + int next0 = nextInputChar(); + int digit0 = digit(next0); + if (digit0 < 0) { + pushBack(next0); + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + + int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; + return clearBackSlashSeen(ch); + } + + private void pushBackUs(int cnt) { + for (int n = 0; n < cnt; n++) { + pushBack('u'); + } + } + + private static int digit(int ch) { + if (ch >= '0' && ch <= '9') { + return ch - '0'; + } + if (ch >= 'A' && ch <= 'F') { + return 10 + ch - 'A'; + } + if (ch >= 'a' && ch <= 'f') { + return 10 + ch - 'a'; + } + return -1; + } + + /** + * Processes column/line information from the input file. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextInputChar() throws IOException { + int result = nextBufferedChar(); + return _inputLine.process(result); + } + + /** + * Retrieves the next un-escaped character from the buffered {@link #_input}. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextBufferedChar() throws IOException { + while (isBufferEmpty()) { + int direct = fillBuffer(); + if (direct < 0) { + return EOF; + } + } + return _data[_pos++]; + } + + private boolean isBufferEmpty() { + return _pos >= _len; + } + + private int fillBuffer() throws IOException { + _pos = 0; + int direct = _input.read(_data, 0, _data.length); + if (direct != 0) { + _len = direct; + } + return direct; + } + + private void pushBack(int ch) { + if (ch < 0) { + return; + } + + if (isBufferEmpty()) { + _pos = _data.length; + _len = _data.length; + } else if (_pos == 0) { + if (_len == _data.length) { + // Buffer is completely full, no push possible, enlarge buffer. + char[] newData = new char[_data.length + 1024]; + _len = newData.length; + _pos = newData.length - _data.length; + System.arraycopy(_data, 0, newData, _pos, _data.length); + _data = newData; + } else { + // Move contents to the right. + int cnt = _len - _pos; + _pos = _data.length - _len; + _len = _data.length; + System.arraycopy(_data, 0, _data, _pos, cnt); + } + } + _data[--_pos] = (char) ch; + } + + /** + * The {@link PositionMapping} being built during processing the file. + */ + public PositionMapping getPositionMapping() { + return _mappingBuilder.getMapping(); + } + + /** + * An algorithm mapping {@link Position} form two corresponding files. + */ + public static final class PositionMapping { + + private final List _deltas = new ArrayList<>(); + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. + */ + public PositionMapping() { + super(); + } + + /** + * Whether this is the identity transformation. + */ + public boolean isEmpty() { + return _deltas.isEmpty(); + } + + void add(int line, int column, int lineDelta, int columnDelta) { + _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); + } + + /** + * Looks up the {@link PositionUpdate} for the given Position. + */ + public PositionUpdate lookup(Position position) { + int result = Collections.binarySearch(_deltas, position); + if (result >= 0) { + return _deltas.get(result); + } else { + int insertIndex = -result - 1; + if (insertIndex == 0) { + // Before the first delta info, identity mapping. + return PositionUpdate.NONE; + } else { + // The relevant update is the one with the position smaller + // than the requested position. + return _deltas.get(insertIndex - 1); + } + } + } + + /** + * Algorithm updating a {@link Position} from one file to a + * {@link Position} in a corresponding file. + */ + public static interface PositionUpdate { + + /** + * The identity position mapping. + */ + PositionUpdate NONE = new PositionUpdate() { + @Override + public int transformLine(int line) { + return line; + } + + @Override + public int transformColumn(int column) { + return column; + } + + @Override + public Position transform(Position pos) { + return pos; + } + }; + + /** + * Maps the given line to an original line. + */ + int transformLine(int line); + + /** + * Maps the given column to an original column. + */ + int transformColumn(int column); + + /** + * The transformed position. + */ + default Position transform(Position pos) { + int line = pos.line; + int column = pos.column; + int transformedLine = transformLine(line); + int transformedColumn = transformColumn(column); + return new Position(transformedLine, transformedColumn); + } + + } + + private static final class DeltaInfo extends Position implements PositionUpdate { + + /** + * The offset to add to the {@link #line} and all following source + * positions up to the next {@link PositionUpdate}. + */ + private final int _lineDelta; + + /** + * The offset to add to the {@link #column} and all following + * source positions up to the next {@link PositionUpdate}. + */ + private final int _columnDelta; + + /** + * Creates a {@link PositionUpdate}. + */ + public DeltaInfo(int line, int column, int lineDelta, + int columnDelta) { + super(line, column); + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + + @Override + public int transformLine(int sourceLine) { + return sourceLine + _lineDelta; + } + + @Override + public int transformColumn(int sourceColumn) { + return sourceColumn + _columnDelta; + } + + @Override + public String toString() { + return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; + } + + } + + /** + * Transforms the given {@link Position}. + */ + public Position transform(Position pos) { + return lookup(pos).transform(pos); + } + + /** + * Transforms the given {@link Range}. + */ + public Range transform(Range range) { + Position begin = transform(range.begin); + Position end = transform(range.end); + if (begin == range.begin && end == range.end) { + // No change. + return range; + } + return new Range(begin, end); + } + } + + private static final class PositionMappingBuilder { + + private LineCounter _left; + + private LineCounter _right; + + private final PositionMapping _mapping = new PositionMapping(); + + private int _lineDelta = 0; + private int _columnDelta = 0; + + /** + * Creates a {@link PositionMappingBuilder}. + * + * @param left The source {@link LineCounter}. + * @param right The target {@link LineCounter}. + */ + public PositionMappingBuilder(LineCounter left, LineCounter right) { + _left = left; + _right = right; + update(); + } + + /** + * The built {@link PositionMapping}. + */ + public PositionMapping getMapping() { + return _mapping; + } + + public void update() { + int lineDelta = _right.getLine() - _left.getLine(); + int columnDelta = _right.getColumn() - _left.getColumn(); + + if (lineDelta != _lineDelta || columnDelta != _columnDelta) { + _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); + + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + } + + } + + /** + * Processor keeping track of the current line and column in a stream of + * incoming characters. + * + * @see #process(int) + */ + public static final class LineCounter { + + /** + * Whether {@link #CR} has been seen on the input as last character. + */ + private boolean _crSeen; + + private int _line = 1; + + private int _column = 1; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. + */ + public LineCounter() { + super(); + } + + /** + * The line of the currently processed input character. + */ + public int getLine() { + return _line; + } + + /** + * The column of the currently processed input character. + */ + public int getColumn() { + return _column; + } + + /** + * The current position. + */ + public Position getPosition() { + return new Position(getLine(), getColumn()); + } + + /** + * Analyzes the given character for line feed. + */ + public int process(int ch) { + switch (ch) { + case EOF: { + break; + } + case CR: { + incLine(); + _crSeen = true; + break; + } + case LF: { + // CR LF does only count as a single line terminator. + if (_crSeen) { + _crSeen = false; + } else { + incLine(); + } + break; + } + default: { + _crSeen = false; + _column++; + } + } + return ch; + } + + private void incLine() { + _line++; + _column = 1; + } + + } + } 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 index f25f7b2d89..b16d7d6952 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast; /** @@ -29,7 +30,10 @@ */ public enum AccessSpecifier { - PUBLIC("public"), PRIVATE("private"), PROTECTED("protected"), PACKAGE_PRIVATE(""); + PUBLIC("public"), + PRIVATE("private"), + PROTECTED("protected"), + PACKAGE_PRIVATE(""); private String 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 index bc6e83b425..18efc78290 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast; import java.lang.annotation.ElementType; 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 index 7cd32c25c3..f92abef865 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast; /** @@ -40,7 +41,6 @@ * @see Node#getData(DataKey) */ public abstract class DataKey { - @Override public int hashCode() { return getClass().hashCode(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java index 423a1d116d..96b5d8c0d0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast; import java.lang.annotation.Retention; @@ -33,9 +34,9 @@ * and will be overwritten the next time the generators are run. */ @Retention(SOURCE) -@Target({ PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER }) +@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, + LOCAL_VARIABLE, PARAMETER}) public @interface Generated { - /** * The value element must have the name of the code generator. * The recommended convention is to use the fully qualified name of the diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java index adb975824b..2d7584b95b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java @@ -18,6 +18,7 @@ * 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; @@ -46,7 +47,6 @@ * @param the type of nodes contained. */ public class NodeList implements List, Iterable, HasParentNode>, Visitable, Observable { - @InternalProperty private final List innerList = new ArrayList<>(0); @@ -140,7 +140,8 @@ public Iterator 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); + 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; @@ -227,6 +228,7 @@ public NodeList addBefore(N node, N beforeThisNode) { return this; } + /** * @return the first node, or empty if the list is empty. */ @@ -565,10 +567,9 @@ public String toString() { return innerList.stream().map(Node::toString).collect(Collectors.joining(", ", "[", "]")); } - protected class NodeListIterator implements ListIterator { + protected class NodeListIterator implements ListIterator{ ListIterator iterator; - N current = null; // initialize pointer to head of the list for iteration @@ -626,12 +627,14 @@ public void remove() { public void set(N n) { int index = innerList.indexOf(current); 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); + throw new IllegalArgumentException("Illegal index. The index should be between 0 and " + innerList.size() + + " excluded. It is instead " + index); } if (n != innerList.get(index)) { notifyElementReplaced(index, n); innerList.get(index).setParentNode(null); setAsParentNodeOf(n); + iterator.set(n); } } 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 index 96eca384bc..17cfa87964 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -33,7 +34,6 @@ * The comments contained in a certain parsed piece of source code. */ public class CommentsCollection { - private final TreeSet comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); public CommentsCollection() { @@ -44,15 +44,24 @@ public CommentsCollection(Collection commentsToCopy) { } public Set getLineComments() { - return comments.stream().filter(comment -> comment instanceof LineComment).map(comment -> (LineComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream() + .filter(comment -> comment instanceof LineComment) + .map(comment -> (LineComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getBlockComments() { - return comments.stream().filter(comment -> comment instanceof BlockComment).map(comment -> (BlockComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream() + .filter(comment -> comment instanceof BlockComment) + .map(comment -> (BlockComment) comment) + .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getJavadocComments() { - return comments.stream().filter(comment -> comment instanceof JavadocComment).map(comment -> (JavadocComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + 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) { @@ -71,7 +80,9 @@ public boolean contains(Comment comment) { 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) { + if (cRange.begin.equals(commentRange.begin) && + cRange.end.line == commentRange.end.line && + Math.abs(cRange.end.column - commentRange.end.column) < 2) { return true; } } @@ -88,7 +99,10 @@ public int size() { public CommentsCollection minus(CommentsCollection other) { CommentsCollection result = new CommentsCollection(); - result.comments.addAll(comments.stream().filter(comment -> !other.contains(comment)).collect(Collectors.toList())); + result.comments.addAll( + comments.stream() + .filter(comment -> !other.contains(comment)) + .collect(Collectors.toList())); return result; } 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 index d06ba13b9c..503f98f8a7 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -37,7 +38,6 @@ * @since July 2014 */ public interface NodeWithAnnotations { - NodeList getAnnotations(); N setAnnotations(NodeList annotations); @@ -68,7 +68,8 @@ default N addAnnotation(AnnotationExpr element) { */ @SuppressWarnings("unchecked") default N addAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr( + parseName(name), new NodeList<>()); addAnnotation(annotation); return (N) this; } @@ -81,7 +82,8 @@ default N addAnnotation(String name) { */ @SuppressWarnings("unchecked") default NormalAnnotationExpr addAndGetAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr( + parseName(name), new NodeList<>()); addAnnotation(annotation); return annotation; } @@ -116,7 +118,8 @@ default NormalAnnotationExpr addAndGetAnnotation(Class cla */ @SuppressWarnings("unchecked") default N addMarkerAnnotation(String name) { - MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr(parseName(name)); + MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr( + parseName(name)); addAnnotation(markerAnnotationExpr); return (N) this; } @@ -141,7 +144,8 @@ default N addMarkerAnnotation(Class clazz) { */ @SuppressWarnings("unchecked") default N addSingleMemberAnnotation(String name, Expression expression) { - SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr(parseName(name), expression); + SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr( + parseName(name), expression); return addAnnotation(singleMemberAnnotationExpr); } @@ -175,7 +179,8 @@ default N addSingleMemberAnnotation(String name, String value) { * @param value the value, don't forget to add \"\" for a string value * @return this */ - default N addSingleMemberAnnotation(Class clazz, String value) { + default N addSingleMemberAnnotation(Class clazz, + String value) { tryAddImportToParentCompilationUnit(clazz); return addSingleMemberAnnotation(clazz.getSimpleName(), value); } 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 index 537cb3e45e..c639336183 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -30,7 +31,6 @@ * A node with arguments. */ public interface NodeWithArguments { - N setArguments(NodeList arguments); NodeList getArguments(); @@ -55,4 +55,5 @@ 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 index 1212b5b0e9..eb22b78d1e 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -27,7 +28,6 @@ * A node with a body that is a BlockStmt. */ public interface NodeWithBlockStmt { - BlockStmt getBody(); N setBody(BlockStmt 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 index 4d198d6bc4..cea664c77a 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -26,7 +27,6 @@ import com.github.javaparser.ast.stmt.Statement; public interface NodeWithBody { - Statement getBody(); N setBody(final Statement body); @@ -42,6 +42,8 @@ default BlockStmt createBlockStatementAsBody() { */ default boolean hasEmptyBody() { Statement body = getBody(); - return body.toBlockStmt().map(bs -> bs.isEmpty()).orElse(body.isEmptyStmt()); + return body.toBlockStmt().map(bs -> bs.isEmpty()) + .orElse(body.isEmptyStmt()); } + } 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 index b276d94c0e..3987d8f911 100644 --- 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 @@ -18,13 +18,13 @@ * 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; public interface NodeWithCondition { - Expression getCondition(); N setCondition(Expression condition); 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 index 874ea05000..5e04f0519b 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes; /** 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 index 7ce9d18345..647f48227b 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -29,7 +30,6 @@ * A node that has an expression in it. */ public interface NodeWithExpression { - Expression getExpression(); N setExpression(Expression 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 index f1c5482873..53ff093f0f 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -97,4 +98,5 @@ 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 index 45bb713c4b..0634b58c9f 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -25,7 +26,6 @@ import static com.github.javaparser.utils.Utils.assertNonEmpty; public interface NodeWithIdentifier { - String getIdentifier(); N setIdentifier(String 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 index f583a2d2fa..a62b012115 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -30,7 +31,6 @@ * A node that implements other types. */ public interface NodeWithImplements { - NodeList getImplementedTypes(); default ClassOrInterfaceType getImplementedTypes(int i) { @@ -38,9 +38,9 @@ default ClassOrInterfaceType getImplementedTypes(int i) { } N setImplementedTypes(NodeList implementsList); - + void tryAddImportToParentCompilationUnit(Class clazz); - + @SuppressWarnings("unchecked") default N setImplementedType(int i, ClassOrInterfaceType implement) { getImplementedTypes().set(i, implement); @@ -53,16 +53,12 @@ default N addImplementedType(ClassOrInterfaceType implement) { return (N) this; } - /** - * @deprecated use addImplementedType instead - */ + /** @deprecated use addImplementedType instead */ default N addImplements(String name) { return addImplementedType(name); } - /** - * @deprecated use addImplementedType instead - */ + /** @deprecated use addImplementedType instead */ default N addImplements(Class clazz) { return addImplementedType(clazz); } 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 index 7252ef0d9b..10941e6453 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -31,7 +32,6 @@ * A node that can be documented with a Javadoc comment. */ public interface NodeWithJavadoc { - Optional getComment(); Node setComment(Comment comment); @@ -43,7 +43,9 @@ public interface NodeWithJavadoc { * @return The JavadocComment for this node wrapped in an optional as it may be absent. */ default Optional getJavadocComment() { - return getComment().filter(comment -> comment instanceof JavadocComment).map(comment -> (JavadocComment) comment); + return getComment() + .filter(comment -> comment instanceof JavadocComment) + .map(comment -> (JavadocComment) comment); } /** @@ -85,4 +87,5 @@ default boolean removeJavaDocComment() { 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 index 53b313357c..6fd6975261 100644 --- 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 @@ -46,7 +46,6 @@ * method. */ public interface NodeWithMembers extends NodeWithSimpleName { - /** * @return all members inside the braces of this node, * like fields, methods, nested types, etc. @@ -316,7 +315,9 @@ default BlockStmt addStaticInitializer() { * @return the methods found (multiple in case of overloading) */ default List getMethodsByName(String name) { - return unmodifiableList(getMethods().stream().filter(m -> m.getNameAsString().equals(name)).collect(toList())); + return unmodifiableList(getMethods().stream() + .filter(m -> m.getNameAsString().equals(name)) + .collect(toList())); } /** @@ -325,7 +326,10 @@ default List getMethodsByName(String name) { * @return the methods found. This list is immutable. */ default List getMethods() { - return unmodifiableList(getMembers().stream().filter(m -> m instanceof MethodDeclaration).map(m -> (MethodDeclaration) m).collect(toList())); + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof MethodDeclaration) + .map(m -> (MethodDeclaration) m) + .collect(toList())); } /** @@ -344,7 +348,9 @@ default List getMethods() { * @return the methods found */ default List getMethodsByParameterTypes(String... paramTypes) { - return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); + return unmodifiableList(getMethods().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .collect(toList())); } /** @@ -356,7 +362,9 @@ default List getMethodsByParameterTypes(String... paramTypes) * @return the methods found */ default List getMethodsBySignature(String name, String... paramTypes) { - return unmodifiableList(getMethodsByName(name).stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); + return unmodifiableList(getMethodsByName(name).stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .collect(toList())); } /** @@ -372,7 +380,9 @@ default List getMethodsBySignature(String name, String... par * @return the methods found */ default List getMethodsByParameterTypes(Class... paramTypes) { - return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); + return unmodifiableList(getMethods().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .collect(toList())); } /** @@ -381,7 +391,10 @@ default List getMethodsByParameterTypes(Class... paramType * @return the constructors found. This list is immutable. */ default List getConstructors() { - return unmodifiableList(getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).collect(toList())); + return unmodifiableList(getMembers().stream() + .filter(m -> m instanceof ConstructorDeclaration) + .map(m -> (ConstructorDeclaration) m) + .collect(toList())); } /** @@ -390,7 +403,11 @@ default List getConstructors() { * @return the constructor found, if any. */ default Optional getDefaultConstructor() { - return getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).filter(cd -> cd.getParameters().isEmpty()).findFirst(); + return getMembers().stream() + .filter(m -> m instanceof ConstructorDeclaration) + .map(m -> (ConstructorDeclaration) m) + .filter(cd -> cd.getParameters().isEmpty()) + .findFirst(); } /** @@ -410,7 +427,9 @@ default Optional getDefaultConstructor() { * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(String... paramTypes) { - return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); + return getConstructors().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .findFirst(); } /** @@ -426,7 +445,9 @@ default Optional getConstructorByParameterTypes(String.. * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(Class... paramTypes) { - return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); + return getConstructors().stream() + .filter(m -> m.hasParametersOfType(paramTypes)) + .findFirst(); } /** @@ -436,7 +457,12 @@ default Optional getConstructorByParameterTypes(Class * @return null if not found, the FieldDeclaration otherwise */ default Optional getFieldByName(String name) { - return getMembers().stream().filter(m -> m instanceof FieldDeclaration).map(f -> (FieldDeclaration) f).filter(f -> f.getVariables().stream().anyMatch(var -> var.getNameAsString().equals(name))).findFirst(); + return getMembers().stream() + .filter(m -> m instanceof FieldDeclaration) + .map(f -> (FieldDeclaration) f) + .filter(f -> f.getVariables().stream() + .anyMatch(var -> var.getNameAsString().equals(name))) + .findFirst(); } /** @@ -445,7 +471,10 @@ default Optional getFieldByName(String name) { * @return the fields found. This list is immutable. */ default List getFields() { - return unmodifiableList(getMembers().stream().filter(m -> m instanceof FieldDeclaration).map(m -> (FieldDeclaration) m).collect(toList())); + 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 index 592e50ed73..02893b0d4f 100644 --- 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 @@ -18,15 +18,19 @@ * 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.AccessSpecifier; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; +import com.github.javaparser.resolution.declarations.HasAccessSpecifier; import java.util.Arrays; import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; import static com.github.javaparser.ast.NodeList.toNodeList; @@ -35,7 +39,6 @@ * Note that not all modifiers may be valid for this node. */ public interface NodeWithModifiers { - /** * Return the modifiers of this variable declaration. * Warning: modifying the returned set will not trigger observers, @@ -64,7 +67,9 @@ default N addModifier(Modifier.Keyword... newModifiers) { @SuppressWarnings("unchecked") default N removeModifier(Modifier.Keyword... modifiersToRemove) { List modifiersToRemoveAsList = Arrays.asList(modifiersToRemove); - NodeList remaining = getModifiers().stream().filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())).collect(toNodeList()); + NodeList remaining = getModifiers().stream() + .filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())) + .collect(toNodeList()); setModifiers(remaining); return (N) this; } @@ -99,7 +104,7 @@ default N setModifiers(final Modifier.Keyword... modifiers) { */ default AccessSpecifier getAccessSpecifier() { for (Modifier modifier : getModifiers()) { - switch(modifier.getKeyword()) { + switch (modifier.getKeyword()) { case PUBLIC: return AccessSpecifier.PUBLIC; case PROTECTED: 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 index 8aecc8e421..75d0b0c2eb 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -34,7 +35,6 @@ * @since 2.0.1 */ public interface NodeWithName { - Name getName(); N setName(Name name); 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 index b014cbef21..8cded1c2e5 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -29,7 +30,6 @@ * A node with a body that is a BlockStmt, which is optional. */ public interface NodeWithOptionalBlockStmt { - Optional getBody(); N setBody(BlockStmt 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 index f70876d4a1..ae1bf591a4 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -31,11 +32,10 @@ * A node that has an optional label. */ public interface NodeWithOptionalLabel { - Optional getLabel(); T setLabel(SimpleName label); - + T removeLabel(); default T setLabel(String label) { 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 index 6ac604f937..debdd3ae57 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -33,7 +34,7 @@ public interface NodeWithOptionalScope extends NodeWithTraversab Optional getScope(); N setScope(Expression scope); - + N removeScope(); default Optional traverseScope() { 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 index 5485ca9c1f..e86106f566 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -33,7 +34,6 @@ import static java.util.stream.Collectors.toList; public interface NodeWithParameters { - NodeList getParameters(); default Parameter getParameter(int i) { @@ -107,7 +107,8 @@ default Parameter addAndGetParameter(Parameter parameter) { * @return null if not found, the param found otherwise */ default Optional getParameterByName(String name) { - return getParameters().stream().filter(p -> p.getNameAsString().equals(name)).findFirst(); + return getParameters().stream() + .filter(p -> p.getNameAsString().equals(name)).findFirst(); } /** @@ -117,7 +118,8 @@ default Optional getParameterByName(String name) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(String type) { - return getParameters().stream().filter(p -> p.getType().toString().equals(type)).findFirst(); + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type)).findFirst(); } /** @@ -127,7 +129,8 @@ default Optional getParameterByType(String type) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(Class type) { - return getParameters().stream().filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); + return getParameters().stream() + .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); } /** @@ -146,7 +149,10 @@ default Optional getParameterByType(Class type) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(String... paramTypes) { - return getParameters().stream().map(p -> p.getType().asString()).collect(toList()).equals(Arrays.asList(paramTypes)); + return getParameters().stream() + .map(p -> p.getType().asString()) + .collect(toList()) + .equals(Arrays.asList(paramTypes)); } /** @@ -162,6 +168,13 @@ default boolean hasParametersOfType(String... paramTypes) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(Class... paramTypes) { - return getParameters().stream().map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElse(p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); + return getParameters().stream() + // if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter + // is "List", we want to consider it as "List", so we need to call getName() + .map(p -> p.getType().toClassOrInterfaceType() + .map(NodeWithSimpleName::getNameAsString) + .orElse(p.getType().asString())) + .collect(toList()) + .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); } } 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 index 4d3e68acbb..f344cdd5c0 100644 --- 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 @@ -18,19 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes; +import java.util.Optional; + import com.github.javaparser.Position; import com.github.javaparser.Range; import com.github.javaparser.ast.Node; -import java.util.Optional; - /** * A node that has a Range, which is every Node. */ public interface NodeWithRange { - Optional getRange(); N setRange(Range range); @@ -76,7 +76,7 @@ default boolean containsWithinRange(Node other) { } return false; } - + /* * Returns true if the node has a range */ 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 index e88d57eac0..888d0f4dba 100644 --- 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 @@ -18,6 +18,7 @@ * 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; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java index 78baf7bdaf..5718528793 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java @@ -18,6 +18,7 @@ * 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; @@ -32,7 +33,6 @@ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. */ public interface NodeWithSimpleName { - SimpleName getName(); N setName(SimpleName name); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java index d0cc4843c6..385d266b1b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -18,6 +18,7 @@ * 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; @@ -34,7 +35,6 @@ * A node that contains a list of statements. */ public interface NodeWithStatements { - NodeList getStatements(); default Statement getStatement(int i) { 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 index d273df85b6..a82a2afa6c 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -30,7 +31,6 @@ * A node that declares the types of exception it throws. */ public interface NodeWithThrownExceptions { - N setThrownExceptions(NodeList thrownExceptions); NodeList getThrownExceptions(); 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 index 8981337697..e4f465b4b9 100644 --- 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 @@ -18,6 +18,7 @@ * 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.TokenRange; @@ -26,9 +27,9 @@ /** * A node that has a Range, which is every Node. + * */ public interface NodeWithTokenRange { - Optional 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 index 4d34d49a7d..1bc2d37cb5 100644 --- 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 @@ -18,6 +18,7 @@ * 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; 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 index 27e686ba73..9e89fe02d1 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -36,7 +37,6 @@ * @since 2.3.1 */ public interface NodeWithType { - /** * Gets the type * diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java index b26195a5c7..2cac20688a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -18,6 +18,7 @@ * 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; @@ -41,7 +42,6 @@ * On other nodes it is treated the same as the first case. */ public interface NodeWithTypeArguments { - /** * @return the types that can be found in the type arguments: {@code }. */ 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 index c9041b5f9a..14d7f1095f 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -35,7 +36,6 @@ * */ public interface NodeWithTypeParameters { - NodeList getTypeParameters(); default TypeParameter getTypeParameter(int i) { 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 index b80e6fc431..78ed419b3a 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -35,7 +36,6 @@ * A node which has a list of variables. */ public interface NodeWithVariables { - NodeList getVariables(); N setVariables(NodeList variables); @@ -130,7 +130,6 @@ default Optional getMaximumCommonType() { static Optional calculateMaximumCommonType(List types) { // we use a local class because we cannot use an helper static method in an interface class Helper { - // Conceptually: given a type we start from the Element Type and get as many array levels as indicated // From the implementation point of view we start from the actual type and we remove how many array // levels as needed to get the target level of arrays @@ -148,6 +147,7 @@ private Optional toArrayLevel(Type type, int level) { return Optional.of(type); } } + Helper helper = new Helper(); int level = 0; boolean keepGoing = true; @@ -170,4 +170,5 @@ private Optional toArrayLevel(Type type, int level) { } return helper.toArrayLevel(types.get(0), --level); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java index b90446ee7c..ac688875e0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java @@ -18,6 +18,7 @@ * 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; @@ -32,7 +33,6 @@ * The common interface of {@link com.github.javaparser.ast.expr.SwitchExpr} and {@link com.github.javaparser.ast.stmt.SwitchStmt} */ public interface SwitchNode { - NodeList getEntries(); SwitchEntry getEntry(int i); @@ -57,6 +57,8 @@ public interface SwitchNode { default boolean isEmpty() { return getEntries().isEmpty(); } + + // Too bad Node isn't an interface, or this could have easily inherited all of its methods. // Add more when required. } 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 index 23161d3e79..93ff4f9e39 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be abstract. */ public interface NodeWithAbstractModifier extends NodeWithModifiers { - default boolean isAbstract() { return hasModifier(ABSTRACT); } 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 index 8e58735dff..9cb8923e41 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; 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 index 7528613fb6..78744d3e1e 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be final. */ public interface NodeWithFinalModifier extends NodeWithModifiers { - default boolean isFinal() { return hasModifier(FINAL); } 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 index 0cef1e8238..fb841e9cf6 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be private. */ public interface NodeWithPrivateModifier extends NodeWithModifiers { - default boolean isPrivate() { return hasModifier(PRIVATE); } 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 index db954188f1..9424c0aa17 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be protected. */ public interface NodeWithProtectedModifier extends NodeWithModifiers { - default boolean isProtected() { return hasModifier(PROTECTED); } 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 index 8221e94f00..a52b1405c7 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be public. */ public interface NodeWithPublicModifier extends NodeWithModifiers { - default boolean isPublic() { return hasModifier(PUBLIC); } @@ -38,4 +38,5 @@ default boolean isPublic() { 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 index a2d532b27a..409a18936e 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -38,4 +39,5 @@ default boolean isStatic() { 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 index 52bd23cbf4..3a3bf1fd3a 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * A node that can be strictfp. */ public interface NodeWithStrictfpModifier extends NodeWithModifiers { - default boolean isStrictfp() { return hasModifier(STRICTFP); } 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 index 78efdd329f..637796b768 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -32,8 +33,8 @@ public interface AstObserver { * Type of change occurring on a List */ enum ListChangeType { - - ADDITION, REMOVAL + ADDITION, + REMOVAL } /** 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 index 7fa2231739..0e14b51148 100644 --- 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 @@ -18,6 +18,7 @@ * 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; 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 index f9d366a18d..0148df7f3e 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.observer; /** 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 index 286efa924b..5cd335be09 100644 --- 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 @@ -18,6 +18,7 @@ * 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; @@ -37,7 +38,6 @@ public static PropagatingAstObserver transformInPropagatingObserver(final AstObs return (PropagatingAstObserver) observer; } return new PropagatingAstObserver() { - @Override public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { observer.propertyChange(observedNode, property, oldValue, newValue); @@ -114,4 +114,5 @@ private void considerAdding(Object element) { ((Observable) element).register(this); } } + } 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 index 09532aedbb..15f3a6b604 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.Problem; @@ -32,7 +33,6 @@ * A simple interface where validators can report found problems. */ public class ProblemReporter { - private final Consumer problemConsumer; public ProblemReporter(Consumer problemConsumer) { 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 index 5a15a28049..700825c3a7 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.expr.Name; @@ -30,9 +31,7 @@ * 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) { 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 index 5644c29132..cab40ae284 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -30,7 +31,6 @@ * and adds a problem for all nodes that pass a condition. */ public class SimpleValidator extends SingleNodeTypeValidator { - public SimpleValidator(Class type, Predicate condition, BiConsumer problemSupplier) { super(type, (node, problemReporter) -> { if (condition.test(node)) { 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 index 27069f9196..da83649a27 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -26,9 +27,7 @@ * Runs a validator on all nodes of a certain type. */ public class SingleNodeTypeValidator implements Validator { - private final Class type; - private final TypedValidator validator; public SingleNodeTypeValidator(Class type, TypedValidator validator) { 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 index 1c2fa2eda9..443240b1b7 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -26,7 +27,6 @@ * A validator that walks the whole tree, visiting every node. */ public class TreeVisitorValidator implements Validator { - private final Validator validator; public TreeVisitorValidator(Validator validator) { 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 index 3f2fbd456c..7a03dab25b 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ParseResult; @@ -29,7 +30,6 @@ * A validator that validates a known node type. */ public interface TypedValidator extends BiConsumer { - /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here @@ -38,6 +38,9 @@ public interface TypedValidator extends BiConsumer result.getResult().ifPresent(node -> accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem)))); + 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 index e4a2cb54dd..f108dfdc95 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -27,7 +28,6 @@ * It is fully up to the implementor how to do this. */ public interface Validator extends TypedValidator { - /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here 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 index 8c479ba608..e2dc370197 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -30,7 +31,6 @@ * A validator that will call a collection of validators. */ public class Validators implements Validator { - private final List validators = new ArrayList<>(); public Validators(Validator... validators) { 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 index d8f65508d8..823276fa6d 100644 --- 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 @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -29,7 +30,6 @@ * Implement the "visit" methods you want to use for validation. */ public abstract class VisitorValidator extends VoidVisitorAdapter implements Validator { - @Override public void accept(Node node, ProblemReporter problemReporter) { node.accept(this, problemReporter); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java index 9a179b32f5..5d53e0594a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java @@ -18,8 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.validator.SingleNodeTypeValidator; +import com.github.javaparser.ast.validator.Validator; +import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; + /** * This validator validates according to Java 10 syntax rules -- including incubator/preview/second preview features. * @@ -29,11 +35,15 @@ public class Java10PreviewValidator extends Java10Validator { public Java10PreviewValidator() { super(); + // Incubator // No incubator language features added within Java 10 + // Preview // No preview language features added within Java 10 + // 2nd Preview // No 2nd preview language features added within Java 10 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java index 53f92b9679..d84bc37d6e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -36,7 +37,9 @@ public class Java10Validator extends Java9Validator { public Java10Validator() { super(); + // Released Language Features + { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -44,5 +47,6 @@ public Java10Validator() { */ add(varOnlyOnLocalVariableDefinitionAndForAndTry); } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java index 49c84f6770..32b27cf8d1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java @@ -18,8 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.validator.SingleNodeTypeValidator; +import com.github.javaparser.ast.validator.Validator; +import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; + /** * This validator validates according to Java 11 syntax rules -- including incubator/preview/second preview features. * @@ -29,11 +35,15 @@ public class Java11PreviewValidator extends Java11Validator { public Java11PreviewValidator() { super(); + // Incubator // No incubator language features added within Java 11 + // Preview // No preview language features added within Java 11 + // 2nd Preview // No 2nd preview language features added within Java 11 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java index b781ed16e8..4d2d4b45ec 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -31,11 +32,11 @@ * @see
https://openjdk.java.net/projects/jdk/11/ */ public class Java11Validator extends Java10Validator { - final Validator varAlsoInLambdaParameters = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(true)); public Java11Validator() { super(); + { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -43,5 +44,6 @@ public Java11Validator() { */ replace(varOnlyOnLocalVariableDefinitionAndForAndTry, varAlsoInLambdaParameters); } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java index 69e70ee113..e3b31d54ce 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,9 +30,12 @@ public class Java12PreviewValidator extends Java12Validator { public Java12PreviewValidator() { super(); + // Incubator // No new incubator language features added within Java 12 + // Preview + { /* * Switch Expressions (Preview) - first preview within Java 12 - https://openjdk.java.net/jeps/325 @@ -44,7 +48,9 @@ public Java12PreviewValidator() { remove(noSwitchExpressions); remove(onlyOneLabelInSwitchCase); } + // 2nd Preview // No new 2nd preview language features added within Java 12 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java index 2894990c35..3e35a31349 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,7 +30,9 @@ public class Java12Validator extends Java11Validator { public Java12Validator() { super(); + // Released Language Features // No new released language features added within Java 12 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java index 1f2a6632cb..77cb55e3b6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,11 +30,13 @@ public class Java13PreviewValidator extends Java13Validator { public Java13PreviewValidator() { super(); + // Incubator // No new incubator language features added within Java 13 + // Preview - // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 - remove(noTextBlockLiteral); + remove(noTextBlockLiteral); // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 + // 2nd Preview { /* @@ -48,5 +51,6 @@ public Java13PreviewValidator() { remove(onlyOneLabelInSwitchCase); remove(noYield); } + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java index 2ada45fdc1..3075977ad8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,7 +30,9 @@ public class Java13Validator extends Java12Validator { public Java13Validator() { super(); + // Released Language Features // No new released language features added in Java 13 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java index a4c2f42716..5fb91f3ee0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,14 +30,16 @@ public class Java14PreviewValidator extends Java14Validator { public Java14PreviewValidator() { super(); + // Incubator // No new incubator language features added within Java 14 + // Preview - // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 - remove(noPatternMatchingInstanceOf); + remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 // remove(noRecordDeclaration); // Records - first preview within Java 14 - https://openjdk.java.net/jeps/359 + // 2nd Preview - // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 - remove(noTextBlockLiteral); + remove(noTextBlockLiteral); // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java index a1fc518e75..b4ee0eedcb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,6 +30,7 @@ public class Java14Validator extends Java13Validator { public Java14Validator() { super(); + // Released Language Features { /* diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java index 2313ba63ac..630020cf52 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,13 +30,16 @@ public class Java15PreviewValidator extends Java15Validator { public Java15PreviewValidator() { super(); + // Incubator // No new incubator language features added within Java 15 + // Preview // remove(noSealedClasses); // Sealed Classes - first preview within Java 15 - https://openjdk.java.net/jeps/360 + // 2nd Preview - // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 - remove(noPatternMatchingInstanceOf); + remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 // TODO: remove(noRecordDeclaration); // Records - 2nd preview within Java 15 - https://openjdk.java.net/jeps/384 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java index b01bee5418..01d1709d2a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,8 +30,8 @@ public class Java15Validator extends Java14Validator { public Java15Validator() { super(); + // Released Language Features - // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 - remove(noTextBlockLiteral); + remove(noTextBlockLiteral); // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java index b2633a0c4f..652a93dc68 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,11 +30,15 @@ public class Java16PreviewValidator extends Java16Validator { public Java16PreviewValidator() { super(); + // Incubator // No new incubator language features added in Java 16 + // Preview // No new preview language features added in Java 16 + // 2nd Preview // TODO: remove(noSealedClasses); // Sealed Classes - 2nd preview in Java 16 - https://openjdk.java.net/jeps/397 + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java index 9afad897b9..8300398d35 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** @@ -29,9 +30,9 @@ public class Java16Validator extends Java15Validator { public Java16Validator() { super(); + // Released Language Features - // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 - remove(noPatternMatchingInstanceOf); + remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 // TODO: remove(noRecordDeclaration); // Records released within Java 16 - https://openjdk.java.net/jeps/395 } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java index 34bc7a32b4..c316eea8b0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.ImportDeclaration; @@ -32,7 +33,11 @@ import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.UnionType; -import com.github.javaparser.ast.validator.*; +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.Validator; +import com.github.javaparser.ast.validator.Validators; import com.github.javaparser.ast.validator.language_level_validations.chunks.CommonValidators; import com.github.javaparser.ast.validator.language_level_validations.chunks.ModifierValidator; import com.github.javaparser.ast.validator.language_level_validations.chunks.NoBinaryIntegerLiteralsValidator; @@ -42,15 +47,20 @@ * This validator validates according to Java 1.0 syntax rules. */ public class Java1_0Validator extends Validators { - - final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(false, false, false); - - final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, n -> true, (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.")); - - final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, n -> !n.isTopLevelType(), (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.")); - - final Validator noReflection = new SimpleValidator<>(ClassExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Reflection is not supported.")); - + final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods + = new ModifierValidator(false, false, false); + final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, + n -> true, + (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.") + ); + final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, + n -> !n.isTopLevelType(), + (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.") + ); + final Validator noReflection = new SimpleValidator<>(ClassExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Reflection is not supported.") + ); final Validator noGenerics = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { if (((NodeWithTypeArguments) node).getTypeArguments().isPresent()) { @@ -63,7 +73,6 @@ public class Java1_0Validator extends Validators { } } }); - final SingleNodeTypeValidator tryWithoutResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { if (n.getCatchClauses().isEmpty() && !n.getFinallyBlock().isPresent()) { reporter.report(n, "Try has no finally and no catch."); @@ -72,40 +81,65 @@ public class Java1_0Validator extends Validators { reporter.report(n, "Catch with resource is not supported."); } }); - final Validator noAnnotations = new TreeVisitorValidator((node, reporter) -> { if (node instanceof AnnotationExpr || node instanceof AnnotationDeclaration) { reporter.report(node, "Annotations are not supported."); } }); - - final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Enumerations are not supported.")); - - final Validator noVarargs = new SimpleValidator<>(Parameter.class, Parameter::isVarArgs, (n, reporter) -> reporter.report(n, "Varargs are not supported.")); - - final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, n -> true, (n, reporter) -> reporter.report(n, "For-each loops are not supported.")); - - final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, ImportDeclaration::isStatic, (n, reporter) -> reporter.report(n, "Static imports are not supported.")); - - final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, n -> n.getLabels().size() > 1, (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.")); - - final Validator noYield = new SimpleValidator<>(YieldStmt.class, n -> true, (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.")); - + final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, + n -> true, + (n, reporter) -> reporter.report(n, "Enumerations are not supported.") + ); + final Validator noVarargs = new SimpleValidator<>(Parameter.class, + Parameter::isVarArgs, + (n, reporter) -> reporter.report(n, "Varargs are not supported.") + ); + final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, + n -> true, + (n, reporter) -> reporter.report(n, "For-each loops are not supported.") + ); + final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, + ImportDeclaration::isStatic, + (n, reporter) -> reporter.report(n, "Static imports are not supported.") + ); + final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, + n -> n.getLabels().size() > 1, + (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.") + ); + final Validator noYield = new SimpleValidator<>(YieldStmt.class, + n -> true, + (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.") + ); final Validator noBinaryIntegerLiterals = new NoBinaryIntegerLiteralsValidator(); - final Validator noUnderscoresInIntegerLiterals = new NoUnderscoresInIntegerLiteralsValidator(); + final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, + n -> true, + (n, reporter) -> reporter.report(n, "Multi-catch is not supported.") + ); + final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Lambdas are not supported.") + ); + final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, + n -> true, + (n, reporter) -> reporter.report(n, "Modules are not supported.") + ); + final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Switch expressions are not supported.") + ); + + + final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, + n -> n.getPattern().isPresent(), + (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.") + ); + + final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, + n -> true, + (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.") + ); - final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, n -> true, (n, reporter) -> reporter.report(n, "Multi-catch is not supported.")); - - final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Lambdas are not supported.")); - - final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Modules are not supported.")); - - final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Switch expressions are not supported.")); - - final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, n -> n.getPattern().isPresent(), (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.")); - - final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.")); public Java1_0Validator() { super(new CommonValidators()); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java index 9327643387..de042ca41a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -29,11 +30,12 @@ * This validator validates according to Java 1.1 syntax rules. */ public class Java1_1Validator extends Java1_0Validator { - - 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."); - })); + 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(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java index 7f89d5c14e..b842083725 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.validator.ReservedKeywordValidator; @@ -28,9 +29,7 @@ * This validator validates according to Java 1.2 syntax rules. */ public class Java1_2Validator extends Java1_1Validator { - final Validator modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(true, false, false); - final Validator strictfpNotAllowed = new ReservedKeywordValidator("strictfp"); public Java1_2Validator() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java index a5435bf9d8..aac41631eb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java1_4Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java index 04c337ea49..7206a50cbd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java5Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java index cdd11ac419..416a13228e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.Node; @@ -38,7 +39,6 @@ * This validator validates according to Java 5 syntax rules. */ public class Java5Validator extends Java1_4Validator { - final Validator genericsWithoutDiamondOperator = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { Optional> typeArguments = ((NodeWithTypeArguments) node).getTypeArguments(); @@ -65,7 +65,8 @@ public class Java5Validator extends Java1_4Validator { VariableDeclarationExpr declaration = node.getVariable(); // assert that the variable declaration expression has exactly one variable declarator if (declaration.getVariables().size() != 1) { - reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + "declarator. Given: " + declaration.getVariables().size() + "."); + reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + + "declarator. Given: " + declaration.getVariables().size() + "."); } }); @@ -77,9 +78,11 @@ public Java5Validator() { add(noPrimitiveGenericArguments); add(enumNotAllowed); add(forEachStmt); + // 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java index f87b66eea5..064974a9f8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; /** * This validator validates according to Java 6 syntax rules. */ -public class Java6Validator extends Java5Validator { - +public class Java6Validator extends Java5Validator{ public Java6Validator() { super(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java index 6adb54f392..5414b7da22 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.expr.Expression; @@ -29,9 +30,10 @@ * This validator validates according to Java 7 syntax rules. */ public class Java7Validator extends Java6Validator { - final SingleNodeTypeValidator tryWithLimitedResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() && n.getResources().isEmpty() && !n.getFinallyBlock().isPresent()) { + 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()) { @@ -40,7 +42,6 @@ public class Java7Validator extends Java6Validator { } } }); - private final SingleNodeTypeValidator multiCatch = new SingleNodeTypeValidator<>(UnionType.class, (n, reporter) -> { // Case "0 elements" is caught elsewhere. if (n.getElements().size() == 1) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java index 5be5febe52..31691c6ce5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -32,24 +33,25 @@ * @see https://openjdk.java.net/projects/jdk8/features */ public class Java8Validator extends Java7Validator { - final Validator modifiersWithoutPrivateInterfaceMethods = new ModifierValidator(true, true, false); - - 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."); + 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/language_level_validations/Java9Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java index 9392f88b7b..854e311a89 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.stmt.TryStmt; @@ -32,25 +33,27 @@ * @see https://openjdk.java.net/projects/jdk9/ */ public class Java9Validator extends Java8Validator { - final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator(); - final Validator modifiers = new ModifierValidator(true, true, true); - final SingleNodeTypeValidator tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() && n.getResources().isEmpty() && !n.getFinallyBlock().isPresent()) { + 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(); + // Released Language Features + /* * Note 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 (that is done by the Java 10 post-processor). * You can add the node by hand, but that is obscure enough to ignore. */ + add(underscoreKeywordValidator); remove(noModules); replace(modifiersWithoutPrivateInterfaceMethods, modifiers); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java index ef18eaf30f..38b15182ef 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.NodeList; @@ -35,39 +36,54 @@ * 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."); + 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()); - } + } + ), + 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(); } - // No need to check empty strings, it should be impossible to set them to "" + 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/language_level_validations/chunks/ModifierValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java index 244b2cfe82..5b81bc5fef 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Modifier; @@ -38,21 +39,17 @@ import static com.github.javaparser.ast.Modifier.Keyword.*; 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.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP }; - - private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT }; - - private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[] { PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT }; + private final Modifier.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP}; + private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; + private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[]{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) { @@ -231,4 +228,5 @@ private & NodeWithTokenRange> void validateAt reporter.report(t, builder.toString()); } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java index 642ec34a66..e2fba257be 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -27,7 +28,6 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoBinaryIntegerLiteralsValidator extends VisitorValidator { - @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java index 8a828d0edb..19fdc527c6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -27,7 +28,6 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoUnderscoresInIntegerLiteralsValidator extends VisitorValidator { - @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java index ed91401de4..b9d3503724 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -27,7 +28,6 @@ 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java index 76c51b02fe..0d2b61931b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -28,8 +29,8 @@ 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.ForEachStmt; import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.ForEachStmt; import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.ast.type.VarType; import com.github.javaparser.ast.validator.ProblemReporter; @@ -38,7 +39,6 @@ import java.util.Optional; public class VarValidator implements TypedValidator { - private boolean varAllowedInLambdaParameters; public VarValidator(boolean varAllowedInLambdaParameters) { @@ -52,7 +52,10 @@ public void accept(VarType node, ProblemReporter reporter) { if (!variableDeclarator.isPresent()) { // Java 11's var in lambda's if (varAllowedInLambdaParameters) { - boolean valid = node.findAncestor(Parameter.class).flatMap(Node::getParentNode).map((Node p) -> p instanceof LambdaExpr).orElse(false); + boolean valid = node + .findAncestor(Parameter.class) + .flatMap(Node::getParentNode) + .map((Node p) -> p instanceof LambdaExpr).orElse(false); if (valid) { return; } @@ -84,7 +87,8 @@ public void accept(VarType node, ProblemReporter reporter) { return; } container.ifPresent(c -> { - boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || c instanceof ExpressionStmt || c instanceof TryStmt; + boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || + c instanceof ExpressionStmt || c instanceof TryStmt; if (!positionIsFine) { reportIllegalPosition(node, reporter); } @@ -101,10 +105,12 @@ public void accept(VarType node, ProblemReporter reporter) { reporter.report(node, "\"var\" cannot infer array types."); } }); + } }); }); }); + } private void reportIllegalPosition(VarType n, ProblemReporter reporter) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java index 81a947acd0..01935fab75 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ast.type.ClassOrInterfaceType; @@ -29,14 +30,14 @@ * Processes the generic AST into a Java 10 AST and validates it. */ public class Java10PostProcessor extends PostProcessors { - - protected final PostProcessor varNodeCreator = (result, configuration) -> result.getResult().ifPresent(node -> { - node.findAll(ClassOrInterfaceType.class).forEach(n -> { - if (n.getNameAsString().equals("var")) { - n.replace(new VarType(n.getTokenRange().orElse(null))); - } - }); - }); + protected final PostProcessor varNodeCreator = (result, configuration) -> + result.getResult().ifPresent(node -> { + node.findAll(ClassOrInterfaceType.class).forEach(n -> { + if (n.getNameAsString().equals("var")) { + n.replace(new VarType(n.getTokenRange().orElse(null))); + } + }); + }); public Java10PostProcessor() { add(varNodeCreator); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java index 7b4a785d33..873a106a00 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ParseResult; @@ -34,7 +35,6 @@ * A post processor that will call a collection of post processors. */ public class PostProcessors implements PostProcessor { - private final List postProcessors = new ArrayList<>(); public PostProcessors(PostProcessor... postProcessors) { 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 index 4360652bf1..678b821d4c 100644 --- 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 @@ -18,6 +18,7 @@ * 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; 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 index 41daf2a0d9..23d173332a 100644 --- 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 @@ -18,10 +18,10 @@ * 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. * diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java index de662381e6..cf574cef8e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc; import com.github.javaparser.ast.comments.JavadocComment; @@ -26,7 +27,7 @@ import java.util.LinkedList; import java.util.List; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static com.github.javaparser.utils.Utils.*; /** * The structured content of a single Javadoc comment. @@ -39,7 +40,6 @@ public class Javadoc { private JavadocDescription description; - private List blockTags; public Javadoc(JavadocDescription description) { @@ -140,12 +140,13 @@ public List getBlockTags() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Javadoc document = (Javadoc) o; + return description.equals(document.description) && blockTags.equals(document.blockTags); + } @Override @@ -157,6 +158,10 @@ public int hashCode() { @Override public String toString() { - return "Javadoc{" + "description=" + description + ", blockTags=" + blockTags + '}'; + return "Javadoc{" + + "description=" + description + + ", blockTags=" + blockTags + + '}'; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java index 1a2d18d7d4..54ca9df544 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc; import com.github.javaparser.javadoc.description.JavadocDescription; @@ -44,7 +45,6 @@ public class JavadocBlockTag { * an unknown tag. */ public enum Type { - AUTHOR, DEPRECATED, EXCEPTION, @@ -77,14 +77,12 @@ static Type fromName(String tagName) { } return UNKNOWN; } + } private Type type; - private JavadocDescription content; - private Optional name = Optional.empty(); - private String tagName; public JavadocBlockTag(Type type, String content) { @@ -136,15 +134,13 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavadocBlockTag that = (JavadocBlockTag) o; - if (type != that.type) - return false; - if (!content.equals(that.content)) - return false; + + if (type != that.type) return false; + if (!content.equals(that.content)) return false; return name.equals(that.name); } @@ -158,6 +154,10 @@ public int hashCode() { @Override public String toString() { - return "JavadocBlockTag{" + "type=" + type + ", content='" + content + '\'' + ", name=" + name + '}'; + return "JavadocBlockTag{" + + "type=" + type + + ", content='" + content + '\'' + + ", name=" + name + + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java index 65196882ef..6a65e5436c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc.description; import com.github.javaparser.utils.Pair; @@ -70,6 +71,7 @@ public JavadocDescription() { public JavadocDescription(List elements) { this(); + this.elements.addAll(elements); } @@ -93,12 +95,13 @@ public boolean isEmpty() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavadocDescription that = (JavadocDescription) o; + return elements.equals(that.elements); + } @Override @@ -108,6 +111,9 @@ public int hashCode() { @Override public String toString() { - return "JavadocDescription{" + "elements=" + elements + '}'; + return "JavadocDescription{" + + "elements=" + elements + + '}'; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java index 12d2431107..7d04300a7a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc.description; /** @@ -26,6 +27,5 @@ * So for example {@code a text} or {@link String} could be valid description elements. */ public interface JavadocDescriptionElement { - String toText(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java index 7377910a86..5ebbfc9f2b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc.description; import static com.github.javaparser.utils.Utils.nextWord; @@ -49,7 +50,6 @@ public static JavadocDescriptionElement fromText(String text) { * an unknown tag. */ public enum Type { - CODE, DOC_ROOT, INHERIT_DOC, @@ -74,12 +74,11 @@ static JavadocInlineTag.Type fromName(String tagName) { } return UNKNOWN; } + } private String tagName; - private Type type; - private String content; public JavadocInlineTag(String tagName, Type type, String content) { @@ -102,20 +101,18 @@ public String getName() { @Override public String toText() { - return "{@" + tagName + this.content + "}"; + return "{@" + tagName + this.content +"}"; } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavadocInlineTag that = (JavadocInlineTag) o; - if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) - return false; - if (type != that.type) - return false; + + if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false; + if (type != that.type) return false; return content != null ? content.equals(that.content) : that.content == null; } @@ -129,6 +126,10 @@ public int hashCode() { @Override public String toString() { - return "JavadocInlineTag{" + "tagName='" + tagName + '\'' + ", type=" + type + ", content='" + content + '\'' + '}'; + return "JavadocInlineTag{" + + "tagName='" + tagName + '\'' + + ", type=" + type + + ", content='" + content + '\'' + + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java index 59e7ad4f06..8b4c545f04 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.javadoc.description; /** @@ -27,7 +28,6 @@ * before and one after the inline tag ({@link String}). */ public class JavadocSnippet implements JavadocDescriptionElement { - private String text; public JavadocSnippet(String text) { @@ -44,12 +44,13 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavadocSnippet that = (JavadocSnippet) o; + return text.equals(that.text); + } @Override @@ -59,6 +60,8 @@ public int hashCode() { @Override public String toString() { - return "JavadocSnippet{" + "text='" + text + '\'' + '}'; + return "JavadocSnippet{" + + "text='" + text + '\'' + + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java index 257d7cac06..c4b2b7316d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import com.github.javaparser.ast.AllFieldsConstructor; @@ -26,10 +27,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static com.github.javaparser.utils.Utils.decapitalize; @@ -37,23 +35,14 @@ * Meta-data about all classes in the AST. These are all Nodes, except NodeList. */ public abstract class BaseNodeMetaModel { - private final Optional superNodeMetaModel; - private final List declaredPropertyMetaModels = new ArrayList<>(); - private final List derivedPropertyMetaModels = new ArrayList<>(); - private final List constructorParameters = new ArrayList<>(); - private final Class type; - private final String name; - private final String packageName; - private final boolean isAbstract; - private final boolean hasWildcard; public BaseNodeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { @@ -168,13 +157,13 @@ public boolean isRootNode() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BaseNodeMetaModel classMetaModel = (BaseNodeMetaModel) o; - if (!type.equals(classMetaModel.type)) - return false; + + if (!type.equals(classMetaModel.type)) return false; + return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java index 39fae20950..98c90a1553 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java index 0070dbe420..d33af4fe7d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java index 1b1731f756..9ad79ee8da 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import java.lang.annotation.Retention; @@ -33,6 +34,6 @@ * (Used during generation of the meta model.) */ @Retention(RUNTIME) -@Target({ FIELD, METHOD }) +@Target({FIELD, METHOD}) public @interface NonEmptyProperty { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java index fe975b9eac..b107e2afc2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java index 1335615909..659d7e3203 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.metamodel; import com.github.javaparser.ast.Node; @@ -32,21 +33,13 @@ * Meta-data about a property of a node in the AST. */ public class PropertyMetaModel { - private final BaseNodeMetaModel containingNodeMetaModel; - private final String name; - private final Class type; - private final Optional nodeReference; - private final boolean isOptional; - private final boolean isNonEmpty; - private final boolean isNodeList; - private final boolean hasWildcard; public PropertyMetaModel(BaseNodeMetaModel containingNodeMetaModel, String name, Class type, Optional nodeReference, boolean isOptional, boolean isNonEmpty, boolean isNodeList, boolean hasWildcard) { @@ -165,15 +158,14 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PropertyMetaModel that = (PropertyMetaModel) o; - if (!name.equals(that.name)) - return false; - if (!type.equals(that.type)) - return false; + + if (!name.equals(that.name)) return false; + if (!type.equals(that.type)) return false; + return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java index 66c50da79c..0bfb7d0546 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; import com.github.javaparser.GeneratedJavaParserConstants; @@ -49,7 +50,6 @@ public class ConcreteSyntaxModel { private static final Map concreteSyntaxModelByClass = new HashMap<>(); - private static Optional initializationError; private static CsmElement modifiers() { @@ -72,128 +72,884 @@ private static CsmElement annotations() { } private static CsmElement typeParameters() { - return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT), space())); + return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), + sequence(token(GeneratedJavaParserConstants.GT), space())); } private static CsmElement typeArguments() { - return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT))); + return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), + sequence(token(GeneratedJavaParserConstants.GT))); } static { - // / - // / Body - // / - concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), token(GeneratedJavaParserConstants.AT), token(GeneratedJavaParserConstants.INTERFACE), space(), child(ObservableProperty.NAME), space(), token(LBRACE), newline(), indent(), list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), unindent(), token(RBRACE))); - concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(LPAREN), token(RPAREN), conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), semicolon())); - concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), space(), child(ObservableProperty.NAME), list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(ObservableProperty.EXTENDED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))))); - concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), typeParameters(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), space(), child(ObservableProperty.BODY))); - concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence(comment(), memberAnnotations(), child(ObservableProperty.NAME), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), unindent(), token(RBRACE), newline())))); - concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence(comment(), annotations(), modifiers(), token(GeneratedJavaParserConstants.ENUM), space(), child(ObservableProperty.NAME), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.ENTRIES, sequence(comma(), newline()), none(), none()), conditional(ObservableProperty.MEMBERS, IS_EMPTY, conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), unindent(), token(RBRACE))); - concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), annotations(), modifiers(), conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())), semicolon())); - concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence(comment(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.BODY))); - concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), mix(memberAnnotations(), modifiers()), typeParameters(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()))); - concreteSyntaxModelByClass.put(Parameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.TYPE), conditional(ObservableProperty.VAR_ARGS, FLAG, sequence(list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), token(GeneratedJavaParserConstants.ELLIPSIS))), space(), child(ObservableProperty.NAME))); - concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); - concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), // FIXME: we should introduce a derived property - // list(ObservableProperty.EXTRA_ARRAY_LEVELS), - conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER))))); - // / - // / Expressions - // / - concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence(comment(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.INDEX), token(GeneratedJavaParserConstants.RBRACKET))); - concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NEW), space(), child(ObservableProperty.ELEMENT_TYPE), list(ObservableProperty.LEVELS), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))))); - concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LBRACE), list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), orphanCommentsEnding(), token(RBRACE))); - concreteSyntaxModelByClass.put(AssignExpr.class, sequence(comment(), child(ObservableProperty.TARGET), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(BinaryExpr.class, sequence(comment(), child(ObservableProperty.LEFT), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.RIGHT))); - concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence(comment(), attribute(VALUE))); - concreteSyntaxModelByClass.put(CastExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.EXPRESSION))); - concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence(comment(), charToken(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(ClassExpr.class, sequence(comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); - concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence(comment(), child(ObservableProperty.CONDITION), space(), token(GeneratedJavaParserConstants.HOOK), space(), child(ObservableProperty.THEN_EXPR), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ELSE_EXPR))); - concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.INNER), token(GeneratedJavaParserConstants.RPAREN))); - concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence(comment(), child(SCOPE), token(GeneratedJavaParserConstants.DOT), child(ObservableProperty.NAME))); - concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence(comment(), child(ObservableProperty.EXPRESSION), space(), token(GeneratedJavaParserConstants.INSTANCEOF), space(), child(ObservableProperty.TYPE))); - concreteSyntaxModelByClass.put(PatternExpr.class, sequence(child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); - concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(LambdaExpr.class, sequence(comment(), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), list(ObservableProperty.PARAMETERS, sequence(comma(), space())), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), space(), token(GeneratedJavaParserConstants.ARROW), space(), conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)))); - concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); + + /// + /// Body + /// + + concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence( + comment(), + memberAnnotations(), + modifiers(), + token(GeneratedJavaParserConstants.AT), + token(GeneratedJavaParserConstants.INTERFACE), + space(), + child(ObservableProperty.NAME), + space(), + token(LBRACE), + newline(), + indent(), + list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), + unindent(), + token(RBRACE) + )); + + concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence( + comment(), + memberAnnotations(), + modifiers(), + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME), + token(LPAREN), + token(RPAREN), + conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), + semicolon() + )); + + concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence( + comment(), + memberAnnotations(), + modifiers(), + conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), + space(), + child(ObservableProperty.NAME), + list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), + list(ObservableProperty.EXTENDED_TYPES, + sequence(string(GeneratedJavaParserConstants.COMMA), space()), + sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), + none()), + list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence( + space(), + token(GeneratedJavaParserConstants.IMPLEMENTS), + space()), none()), + space(), + block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))) + )); + + concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence( + comment(), + memberAnnotations(), + modifiers(), + typeParameters(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence( + comment(), + memberAnnotations(), + child(ObservableProperty.NAME), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), + conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), + list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), + unindent(), + token(RBRACE), newline())) + )); + + concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence( + comment(), + annotations(), + modifiers(), + token(GeneratedJavaParserConstants.ENUM), + space(), + child(ObservableProperty.NAME), + list(ObservableProperty.IMPLEMENTED_TYPES, + sequence(comma(), space()), + sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), + none()), + space(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + indent(), + newline(), + list(ObservableProperty.ENTRIES, + sequence(comma(), newline()), + none(), + none()), + conditional(ObservableProperty.MEMBERS, IS_EMPTY, + conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), + sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), + unindent(), + token(RBRACE) + )); + + concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence( + orphanCommentsBeforeThis(), + comment(), + annotations(), + modifiers(), + conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), + space(), + list(ObservableProperty.VARIABLES, sequence(comma(), space())), + semicolon())); + + concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence( + comment(), + conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), + child(ObservableProperty.BODY))); + + concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence( + orphanCommentsBeforeThis(), + comment(), + mix(memberAnnotations(), modifiers()), + typeParameters(), + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), + list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), + conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()) + )); + + concreteSyntaxModelByClass.put(Parameter.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, space(), none(), space()), + modifiers(), + child(ObservableProperty.TYPE), + conditional(ObservableProperty.VAR_ARGS, FLAG, sequence( + list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), + token(GeneratedJavaParserConstants.ELLIPSIS))), + space(), + child(ObservableProperty.NAME))); + + concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, space(), none(), space()), + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME))); + + concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence( + comment(), + child(ObservableProperty.NAME), + // FIXME: we should introduce a derived property + // list(ObservableProperty.EXTRA_ARRAY_LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), + child(ObservableProperty.INITIALIZER))) + )); + + /// + /// Expressions + /// + + concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence( + comment(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LBRACKET), + child(ObservableProperty.INDEX), + token(GeneratedJavaParserConstants.RBRACKET) + )); + + concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.NEW), + space(), + child(ObservableProperty.ELEMENT_TYPE), + list(ObservableProperty.LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))) + )); + + concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LBRACE), + list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), + orphanCommentsEnding(), + token(RBRACE))); + + concreteSyntaxModelByClass.put(AssignExpr.class, sequence( + comment(), + child(ObservableProperty.TARGET), + space(), + attribute(ObservableProperty.OPERATOR), + space(), + child(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(BinaryExpr.class, sequence( + comment(), + child(ObservableProperty.LEFT), + space(), + attribute(ObservableProperty.OPERATOR), + space(), + child(ObservableProperty.RIGHT) + )); + + concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence( + comment(), attribute(VALUE) + )); + + concreteSyntaxModelByClass.put(CastExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.TYPE), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.EXPRESSION) + )); + + concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence( + comment(), + charToken(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(ClassExpr.class, sequence( + comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); + + concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence( + comment(), + child(ObservableProperty.CONDITION), + space(), + token(GeneratedJavaParserConstants.HOOK), + space(), + child(ObservableProperty.THEN_EXPR), + space(), + token(GeneratedJavaParserConstants.COLON), + space(), + child(ObservableProperty.ELSE_EXPR) + )); + + concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.INNER), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence( + comment(), + child(SCOPE), + token(GeneratedJavaParserConstants.DOT), + child(ObservableProperty.NAME) + )); + + concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence( + comment(), + child(ObservableProperty.EXPRESSION), + space(), + token(GeneratedJavaParserConstants.INSTANCEOF), + space(), + child(ObservableProperty.TYPE) + )); + + concreteSyntaxModelByClass.put(PatternExpr.class, sequence( + child(ObservableProperty.TYPE), + space(), + child(ObservableProperty.NAME) + )); + + concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(LambdaExpr.class, sequence( + comment(), + conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), + list(ObservableProperty.PARAMETERS, sequence(comma(), space())), + conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), + space(), + token(GeneratedJavaParserConstants.ARROW), + space(), + conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)) + )); + + concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence( + comment(), + attribute(ObservableProperty.VALUE) + )); + concreteSyntaxModelByClass.put(MarkerAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), attribute(ObservableProperty.NAME))); - concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), typeArguments(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN))); - concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence(comment(), child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOUBLECOLON), typeArguments(), attribute(ObservableProperty.IDENTIFIER))); + + concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), + child(ObservableProperty.NAME), + space(), + token(GeneratedJavaParserConstants.ASSIGN), + space(), + child(ObservableProperty.VALUE))); + + concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence( + comment(), + conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), + typeArguments(), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence( + comment(), + child(ObservableProperty.SCOPE), + token(GeneratedJavaParserConstants.DOUBLECOLON), + typeArguments(), + attribute(ObservableProperty.IDENTIFIER) + )); + concreteSyntaxModelByClass.put(Modifier.class, attribute(ObservableProperty.KEYWORD)); - concreteSyntaxModelByClass.put(Name.class, sequence(comment(), conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), attribute(ObservableProperty.IDENTIFIER), orphanCommentsEnding())); - concreteSyntaxModelByClass.put(NameExpr.class, sequence(comment(), child(ObservableProperty.NAME), orphanCommentsEnding())); - concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PAIRS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN))); - concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NULL))); - concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.NEW), space(), list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, sequence(space(), token(LBRACE), newline(), indent(), list(ObservableProperty.ANONYMOUS_CLASS_BODY, newline(), newline(), newline(), newline()), unindent(), token(RBRACE))))); + + concreteSyntaxModelByClass.put(Name.class, sequence( + comment(), + conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), + attribute(ObservableProperty.IDENTIFIER), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(NameExpr.class, sequence( + comment(), + child(ObservableProperty.NAME), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.AT), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.PAIRS, sequence(comma(), space())), + token(GeneratedJavaParserConstants.RPAREN) + )); + + concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.NULL) + )); + + concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence( + comment(), + conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), + token(GeneratedJavaParserConstants.NEW), + space(), + list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), + conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), + child(ObservableProperty.TYPE), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), + token(GeneratedJavaParserConstants.RPAREN), + conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, + sequence( + space(), token(LBRACE), newline(), indent(), + list(ObservableProperty.ANONYMOUS_CLASS_BODY, + newline(), + newline(), + newline(), + newline()), + unindent(), + token(RBRACE) + )) + )); + concreteSyntaxModelByClass.put(SimpleName.class, attribute(ObservableProperty.IDENTIFIER)); - concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.MEMBER_VALUE), token(GeneratedJavaParserConstants.RPAREN))); - concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence(comment(), stringToken(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence(comment(), textBlockToken(ObservableProperty.VALUE))); - concreteSyntaxModelByClass.put(SuperExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.SUPER))); - concreteSyntaxModelByClass.put(ThisExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.THIS))); - concreteSyntaxModelByClass.put(TypeExpr.class, sequence(comment(), child(ObservableProperty.TYPE))); - concreteSyntaxModelByClass.put(UnaryExpr.class, sequence(conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), child(ObservableProperty.EXPRESSION), conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)))); - concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.MAXIMUM_COMMON_TYPE), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())))); - // / - // / Statements - // / - concreteSyntaxModelByClass.put(AssertStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.ASSERT), space(), child(ObservableProperty.CHECK), conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.MESSAGE))), semicolon())); - concreteSyntaxModelByClass.put(BlockStmt.class, sequence(orphanCommentsBeforeThis(), comment(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), orphanCommentsEnding(), token(RBRACE))); - concreteSyntaxModelByClass.put(BreakStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.BREAK), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); - concreteSyntaxModelByClass.put(CatchClause.class, sequence(comment(), space(), token(GeneratedJavaParserConstants.CATCH), space(), token(LPAREN), child(ObservableProperty.PARAMETER), token(RPAREN), space(), child(BODY))); - concreteSyntaxModelByClass.put(ContinueStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.CONTINUE), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); - concreteSyntaxModelByClass.put(DoStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.DO), space(), child(ObservableProperty.BODY), space(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), semicolon())); - concreteSyntaxModelByClass.put(EmptyStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); - concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); - concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence(comment(), conditional(ObservableProperty.THIS, FLAG, sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), sequence(conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), typeArguments(), token(GeneratedJavaParserConstants.SUPER))), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), semicolon())); - concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence(orphanCommentsBeforeThis(), comment(), child(ObservableProperty.EXPRESSION), semicolon())); - concreteSyntaxModelByClass.put(ForEachStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.VARIABLE), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ITERABLE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); - concreteSyntaxModelByClass.put(ForStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), semicolon(), space(), child(ObservableProperty.COMPARE), semicolon(), space(), list(ObservableProperty.UPDATE, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); - concreteSyntaxModelByClass.put(IfStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.IF), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), unindent())), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, sequence(token(GeneratedJavaParserConstants.ELSE), conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.ELSE_STMT)), sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))))); - concreteSyntaxModelByClass.put(LabeledStmt.class, sequence(comment(), child(ObservableProperty.LABEL), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.STATEMENT))); - concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence(comment(), child(ObservableProperty.CLASS_DECLARATION))); - concreteSyntaxModelByClass.put(ReturnStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.RETURN), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); - concreteSyntaxModelByClass.put(YieldStmt.class, sequence(comment(), token(YIELD), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); - concreteSyntaxModelByClass.put(SwitchEntry.class, sequence(comment(), conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), newline(), indent(), list(ObservableProperty.STATEMENTS, newline(), none(), newline()), unindent())); - concreteSyntaxModelByClass.put(SwitchStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); - concreteSyntaxModelByClass.put(SwitchExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); - concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SYNCHRONIZED), space(), token(LPAREN), child(EXPRESSION), token(RPAREN), space(), child(BODY))); - concreteSyntaxModelByClass.put(ThrowStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.THROW), space(), child(ObservableProperty.EXPRESSION), semicolon())); - concreteSyntaxModelByClass.put(TryStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.TRY), space(), conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence(token(LPAREN), list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), token(RPAREN), space())), child(ObservableProperty.TRY_BLOCK), list(ObservableProperty.CATCH_CLAUSES), conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))))); - concreteSyntaxModelByClass.put(WhileStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); - // / - // / Types - // / - concreteSyntaxModelByClass.put(ArrayType.class, sequence(child(ObservableProperty.COMPONENT_TYPE), list(ObservableProperty.ANNOTATIONS), string(GeneratedJavaParserConstants.LBRACKET), string(GeneratedJavaParserConstants.RBRACKET))); - concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), list(ANNOTATIONS, space(), none(), space()), child(NAME), conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); - concreteSyntaxModelByClass.put(IntersectionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); - concreteSyntaxModelByClass.put(PrimitiveType.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS), attribute(ObservableProperty.TYPE))); - concreteSyntaxModelByClass.put(TypeParameter.class, sequence(comment(), annotations(), child(ObservableProperty.NAME), list(ObservableProperty.TYPE_BOUND, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()))); - concreteSyntaxModelByClass.put(UnionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())))); + + concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.AT), + child(ObservableProperty.NAME), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.MEMBER_VALUE), + token(GeneratedJavaParserConstants.RPAREN))); + + concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence( + comment(), + stringToken(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence( + comment(), + textBlockToken(ObservableProperty.VALUE) + )); + + concreteSyntaxModelByClass.put(SuperExpr.class, sequence( + comment(), + conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), + token(GeneratedJavaParserConstants.SUPER) + )); + + concreteSyntaxModelByClass.put(ThisExpr.class, sequence( + comment(), + conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), + token(GeneratedJavaParserConstants.THIS) + )); + + concreteSyntaxModelByClass.put(TypeExpr.class, sequence( + comment(), + child(ObservableProperty.TYPE) + )); + + concreteSyntaxModelByClass.put(UnaryExpr.class, sequence( + conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), + child(ObservableProperty.EXPRESSION), + conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)) + )); + + concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS, space(), none(), space()), + modifiers(), + child(ObservableProperty.MAXIMUM_COMMON_TYPE), + space(), + list(ObservableProperty.VARIABLES, sequence(comma(), space())) + )); + + /// + /// Statements + /// + + concreteSyntaxModelByClass.put(AssertStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.ASSERT), + space(), + child(ObservableProperty.CHECK), + conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence( + space(), + token(GeneratedJavaParserConstants.COLON), + space(), + child(ObservableProperty.MESSAGE) + )), + semicolon() + )); + + concreteSyntaxModelByClass.put(BlockStmt.class, sequence( + orphanCommentsBeforeThis(), + comment(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), + orphanCommentsEnding(), + token(RBRACE) + )); + + concreteSyntaxModelByClass.put(BreakStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.BREAK), + conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), + semicolon() + )); + + concreteSyntaxModelByClass.put(CatchClause.class, sequence( + comment(), + space(), + token(GeneratedJavaParserConstants.CATCH), + space(), + token(LPAREN), + child(ObservableProperty.PARAMETER), + token(RPAREN), + space(), + child(BODY) + )); + + concreteSyntaxModelByClass.put(ContinueStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.CONTINUE), + conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), + semicolon() + )); + + concreteSyntaxModelByClass.put(DoStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.DO), + space(), + child(ObservableProperty.BODY), + space(), + token(GeneratedJavaParserConstants.WHILE), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + token(GeneratedJavaParserConstants.RPAREN), + semicolon() + )); + + concreteSyntaxModelByClass.put(EmptyStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.SEMICOLON) + )); + + concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.SEMICOLON) + )); + + concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence( + comment(), + conditional(ObservableProperty.THIS, FLAG, + sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), + sequence( + conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), + typeArguments(), + token(GeneratedJavaParserConstants.SUPER) + )), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), + token(GeneratedJavaParserConstants.RPAREN), + semicolon() + )); + + concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence( + orphanCommentsBeforeThis(), + comment(), + child(ObservableProperty.EXPRESSION), + semicolon() + )); + + concreteSyntaxModelByClass.put(ForEachStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.FOR), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.VARIABLE), + space(), + token(GeneratedJavaParserConstants.COLON), + space(), + child(ObservableProperty.ITERABLE), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(ForStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.FOR), + space(), + token(GeneratedJavaParserConstants.LPAREN), + list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), + semicolon(), + space(), + child(ObservableProperty.COMPARE), + semicolon(), + space(), + list(ObservableProperty.UPDATE, sequence(comma(), space())), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + concreteSyntaxModelByClass.put(IfStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.IF), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + token(GeneratedJavaParserConstants.RPAREN), + conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, + sequence(space(), child(ObservableProperty.THEN_STMT), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), + sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), + unindent())), + conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, + sequence(token(GeneratedJavaParserConstants.ELSE), + conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, + sequence(space(), child(ObservableProperty.ELSE_STMT)), + sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))) + )); + + concreteSyntaxModelByClass.put(LabeledStmt.class, sequence( + comment(), + child(ObservableProperty.LABEL), + token(GeneratedJavaParserConstants.COLON), + space(), + child(ObservableProperty.STATEMENT) + )); + + concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence( + comment(), + child(ObservableProperty.CLASS_DECLARATION) + )); + + concreteSyntaxModelByClass.put(ReturnStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.RETURN), + conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), + semicolon())); + + concreteSyntaxModelByClass.put(YieldStmt.class, sequence( + comment(), + token(YIELD), + conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), + semicolon())); + + concreteSyntaxModelByClass.put(SwitchEntry.class, sequence( + comment(), + conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, + sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), + sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), + newline(), + indent(), + list(ObservableProperty.STATEMENTS, newline(), none(), newline()), + unindent() + )); + + concreteSyntaxModelByClass.put(SwitchStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.SWITCH), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.SELECTOR), + token(GeneratedJavaParserConstants.RPAREN), + space(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + list(ObservableProperty.ENTRIES, none(), indent(), unindent()), + token(GeneratedJavaParserConstants.RBRACE) + )); + + concreteSyntaxModelByClass.put(SwitchExpr.class, sequence( + comment(), + token(GeneratedJavaParserConstants.SWITCH), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.SELECTOR), + token(GeneratedJavaParserConstants.RPAREN), + space(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + list(ObservableProperty.ENTRIES, none(), indent(), unindent()), + token(GeneratedJavaParserConstants.RBRACE) + )); + + concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.SYNCHRONIZED), + space(), + token(LPAREN), + child(EXPRESSION), + token(RPAREN), + space(), + child(BODY) + )); + + concreteSyntaxModelByClass.put(ThrowStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.THROW), + space(), + child(ObservableProperty.EXPRESSION), + semicolon() + )); + + concreteSyntaxModelByClass.put(TryStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.TRY), + space(), + conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence( + token(LPAREN), + list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), + token(RPAREN), + space())), + child(ObservableProperty.TRY_BLOCK), + list(ObservableProperty.CATCH_CLAUSES), + conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))) + )); + + concreteSyntaxModelByClass.put(WhileStmt.class, sequence( + comment(), + token(GeneratedJavaParserConstants.WHILE), + space(), + token(GeneratedJavaParserConstants.LPAREN), + child(ObservableProperty.CONDITION), + token(GeneratedJavaParserConstants.RPAREN), + space(), + child(ObservableProperty.BODY) + )); + + /// + /// Types + /// + + concreteSyntaxModelByClass.put(ArrayType.class, sequence( + child(ObservableProperty.COMPONENT_TYPE), + list(ObservableProperty.ANNOTATIONS), + string(GeneratedJavaParserConstants.LBRACKET), + string(GeneratedJavaParserConstants.RBRACKET))); + + concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), + conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), + list(ANNOTATIONS, space(), none(), space()), + child(NAME), + conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, + sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), + list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); + + concreteSyntaxModelByClass.put(IntersectionType.class, sequence( + comment(), + annotations(), + list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); + + concreteSyntaxModelByClass.put(PrimitiveType.class, sequence( + comment(), + list(ObservableProperty.ANNOTATIONS), + attribute(ObservableProperty.TYPE))); + + concreteSyntaxModelByClass.put(TypeParameter.class, sequence( + comment(), + annotations(), + child(ObservableProperty.NAME), + list(ObservableProperty.TYPE_BOUND, + sequence( + space(), + token(GeneratedJavaParserConstants.BIT_AND), + space()), + sequence( + space(), + token(GeneratedJavaParserConstants.EXTENDS), + space()), + none()) + )); + + concreteSyntaxModelByClass.put(UnionType.class, sequence( + comment(), + annotations(), + list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())) + )); + concreteSyntaxModelByClass.put(UnknownType.class, none()); + concreteSyntaxModelByClass.put(VoidType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.VOID))); + concreteSyntaxModelByClass.put(VarType.class, sequence(comment(), annotations(), string(GeneratedJavaParserConstants.IDENTIFIER, "var"))); - concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); - // / - // / Top Level - // / - concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence(annotations(), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.DIMENSION), token(GeneratedJavaParserConstants.RBRACKET))); - concreteSyntaxModelByClass.put(CompilationUnit.class, sequence(comment(), child(ObservableProperty.PACKAGE_DECLARATION), list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), list(TYPES, newline(), newline(), none(), newline()), child(ObservableProperty.MODULE), orphanCommentsEnding())); - concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence(comment(), token(GeneratedJavaParserConstants.IMPORT), space(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.NAME), conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), semicolon(), orphanCommentsEnding())); - concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence(comment(), memberAnnotations(), token(GeneratedJavaParserConstants.PACKAGE), space(), child(ObservableProperty.NAME), semicolon(), newline(), newline(), orphanCommentsEnding())); - // / - // / Module info - // / - concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence(memberAnnotations(), conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), token(GeneratedJavaParserConstants.MODULE), space(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), list(ObservableProperty.DIRECTIVES), unindent(), token(GeneratedJavaParserConstants.RBRACE), newline())); - concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence(token(GeneratedJavaParserConstants.EXPORTS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); - concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence(token(GeneratedJavaParserConstants.OPENS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); - concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence(token(GeneratedJavaParserConstants.PROVIDES), space(), child(ObservableProperty.NAME), list(ObservableProperty.WITH, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), none()), semicolon(), newline())); - concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence(token(GeneratedJavaParserConstants.REQUIRES), space(), modifiers(), child(ObservableProperty.NAME), semicolon(), newline())); - concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence(token(GeneratedJavaParserConstants.USES), space(), child(ObservableProperty.NAME), semicolon(), newline())); - List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream().filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())).map(nm -> nm.getType().getSimpleName()).collect(Collectors.toList()); + + concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), + conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), + conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); + + /// + /// Top Level + /// + + concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence( + annotations(), + token(GeneratedJavaParserConstants.LBRACKET), + child(ObservableProperty.DIMENSION), + token(GeneratedJavaParserConstants.RBRACKET) + )); + + concreteSyntaxModelByClass.put(CompilationUnit.class, sequence( + comment(), + child(ObservableProperty.PACKAGE_DECLARATION), + list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), + list(TYPES, newline(), newline(), none(), newline()), + child(ObservableProperty.MODULE), + orphanCommentsEnding())); + + concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence( + comment(), + token(GeneratedJavaParserConstants.IMPORT), + space(), + conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), + child(ObservableProperty.NAME), + conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), + semicolon(), + orphanCommentsEnding() + )); + + concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence( + comment(), + memberAnnotations(), + token(GeneratedJavaParserConstants.PACKAGE), + space(), + child(ObservableProperty.NAME), + semicolon(), + newline(), + newline(), + orphanCommentsEnding())); + + /// + /// Module info + /// + + concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence( + memberAnnotations(), + conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), + token(GeneratedJavaParserConstants.MODULE), + space(), + child(ObservableProperty.NAME), + space(), + token(GeneratedJavaParserConstants.LBRACE), + newline(), + indent(), + list(ObservableProperty.DIRECTIVES), + unindent(), + token(GeneratedJavaParserConstants.RBRACE), + newline() + )); + + concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence( + token(GeneratedJavaParserConstants.EXPORTS), + space(), + child(ObservableProperty.NAME), + list(ObservableProperty.MODULE_NAMES, + sequence(comma(), space()), + sequence(space(), token(GeneratedJavaParserConstants.TO), space()), + none()), + semicolon(), + newline() + )); + + concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence( + token(GeneratedJavaParserConstants.OPENS), + space(), + child(ObservableProperty.NAME), + list(ObservableProperty.MODULE_NAMES, + sequence(comma(), space()), + sequence(space(), token(GeneratedJavaParserConstants.TO), space()), + none()), + semicolon(), + newline() + )); + + concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence( + token(GeneratedJavaParserConstants.PROVIDES), + space(), + child(ObservableProperty.NAME), + list(ObservableProperty.WITH, + sequence(comma(), space()), + sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), + none()), + semicolon(), + newline() + )); + + concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence( + token(GeneratedJavaParserConstants.REQUIRES), + space(), + modifiers(), + child(ObservableProperty.NAME), + semicolon(), + newline() + )); + + concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence( + token(GeneratedJavaParserConstants.USES), + space(), + child(ObservableProperty.NAME), + semicolon(), + newline() + )); + + List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream() + .filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())) + .map(nm -> nm.getType().getSimpleName()) + .collect(Collectors.toList()); if (unsupportedNodeClassNames.isEmpty()) { initializationError = Optional.empty(); } else { @@ -202,6 +958,7 @@ private static CsmElement typeArguments() { } private ConcreteSyntaxModel() { + } public static void genericPrettyPrint(Node node, SourcePrinter printer) { @@ -223,4 +980,5 @@ public static CsmElement forClass(Class nodeClazz) { } return concreteSyntaxModelByClass.get(nodeClazz); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java index 2ba6418d14..2f14d09bb9 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java @@ -18,66 +18,70 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; +import java.util.function.Function; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; import com.github.javaparser.printer.configuration.PrinterConfiguration; - -import java.util.function.Function; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; /** * Pretty printer for AST nodes. */ public class DefaultPrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + // visitor factory Function> visitorFactory; - - // static methods + + // static methods + private static Function> createDefaultVisitor() { PrinterConfiguration configuration = createDefaultConfiguration(); return createDefaultVisitor(configuration); } - + private static Function> createDefaultVisitor(PrinterConfiguration configuration) { return (config) -> new DefaultPrettyPrinterVisitor(config, new SourcePrinter(config)); } - + private static PrinterConfiguration createDefaultConfiguration() { return new DefaultPrinterConfiguration(); } - + // Constructors + /** * Build a new DefaultPrettyPrinter with a default configuration and a default factory */ public DefaultPrettyPrinter() { - this(createDefaultVisitor(), createDefaultConfiguration()); + this(createDefaultVisitor(), createDefaultConfiguration() ); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a default factory * @param configuration */ public DefaultPrettyPrinter(PrinterConfiguration configuration) { - this(createDefaultVisitor(configuration), configuration); + this(createDefaultVisitor(configuration), configuration ); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a factory to create a visitor to browse the nodes of the AST - * @param visitorFactory + * @param visitorFactory * @param configuration Configuration to apply */ public DefaultPrettyPrinter(Function> visitorFactory, PrinterConfiguration configuration) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + // Methods + /* * Returns the Printer configuration */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java index 2e3f603843..9432e7cd90 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java @@ -17,19 +17,136 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; +import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; +import static com.github.javaparser.utils.Utils.trimTrailingSpaces; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.ReceiverParameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.modules.*; -import com.github.javaparser.ast.nodeTypes.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.SwitchExpr; +import com.github.javaparser.ast.expr.TextBlockLiteralExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.modules.ModuleExportsDirective; +import com.github.javaparser.ast.modules.ModuleOpensDirective; +import com.github.javaparser.ast.modules.ModuleProvidesDirective; +import com.github.javaparser.ast.modules.ModuleRequiresDirective; +import com.github.javaparser.ast.modules.ModuleUsesDirective; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.nodeTypes.SwitchNode; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForEachStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntry; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.UnparsableStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.stmt.YieldStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.ConfigurationOption; @@ -37,29 +154,18 @@ import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; import com.github.javaparser.printer.configuration.PrinterConfiguration; -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.*; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - /** * Outputs the AST as formatted Java source code. + * */ public class DefaultPrettyPrinterVisitor implements VoidVisitor { - protected final PrinterConfiguration configuration; - protected final SourcePrinter printer; public DefaultPrettyPrinterVisitor(PrinterConfiguration configuration) { this(configuration, new SourcePrinter(configuration)); } - + public DefaultPrettyPrinterVisitor(PrinterConfiguration configuration, SourcePrinter printer) { this.configuration = configuration; this.printer = printer; @@ -94,7 +200,8 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, + final Void arg) { if (annotations.isEmpty()) { return; } @@ -202,13 +309,16 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } + if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } + n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } + for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -216,7 +326,9 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } + n.getModule().ifPresent(m -> m.accept(this, arg)); + printOrphanCommentsEnding(n); } @@ -229,6 +341,7 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); + printOrphanCommentsEnding(n); } @@ -237,6 +350,7 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); + printOrphanCommentsEnding(n); } @@ -249,6 +363,7 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); + printOrphanCommentsEnding(n); } @@ -263,13 +378,17 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } + n.getName().accept(this, arg); + printTypeParameters(n.getTypeParameters(), arg); + if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -280,6 +399,7 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } + if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -290,12 +410,15 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } + printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } + printOrphanCommentsEnding(n); + printer.unindent(); printer.print("}"); } @@ -316,6 +439,7 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } + boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -350,7 +474,9 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); + n.getName().accept(this, arg); + if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -393,6 +519,7 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } + type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -466,6 +593,7 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -476,6 +604,7 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } + printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -484,6 +613,7 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } + printer.print(";"); } @@ -492,9 +622,13 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); + n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { + final Type type = n.getType(); + ArrayType arrayType = null; + for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -505,6 +639,7 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); + if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -593,9 +728,12 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } + + /** * work in progress for issue-545 */ + @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -665,7 +803,7 @@ public void visit(final InstanceOfExpr n, final Void arg) { n.getExpression().accept(this, arg); printer.print(" instanceof "); n.getType().accept(this, arg); - if (n.getName().isPresent()) { + if(n.getName().isPresent()) { printer.print(" "); n.getName().get().accept(this, arg); } @@ -771,6 +909,7 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -778,24 +917,38 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (getOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN).isPresent()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() + || p.isThrowStmt() + || p.isAssertStmt() + || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) + .map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope) + .map(c::equals) + .orElse(false)) { c = p.get(); p = c.getParentNode(); } + // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } + // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { + while (node.getParentNode() + .filter(NodeWithTraversableScope.class::isInstance) + .map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope) + .map(node::equals) + .orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -803,13 +956,15 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } + // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -817,6 +972,7 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } + // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -841,6 +997,7 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); + printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -860,13 +1017,18 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } + printer.print("new "); + printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } + n.getType().accept(this, arg); + printArguments(n.getArguments(), arg); + if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -883,7 +1045,9 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } + n.getExpression().accept(this, arg); + if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -895,11 +1059,13 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); + printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -911,6 +1077,7 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); + if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -928,6 +1095,7 @@ public void visit(final ConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -935,9 +1103,11 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } + n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); + printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -955,6 +1125,7 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); + if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1029,10 +1200,12 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); + if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); + for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1134,6 +1307,7 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + if (isNullOrEmpty(n.getLabels())) { printer.print("default:"); } else { @@ -1194,8 +1368,10 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printer.print("enum "); n.getName().accept(this, arg); + if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1206,12 +1382,15 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } + printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = + // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || + // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1243,9 +1422,11 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); + if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } + if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1272,8 +1453,7 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (// block statement should start on the same line - thenBlock) + if (thenBlock) // block statement should start on the same line printer.print(") "); else { printer.println(")"); @@ -1289,8 +1469,7 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (// put chained if and start of block statement on a same level - elseIf || elseBlock) + if (elseIf || elseBlock) // put chained if and start of block statement on a same level printer.print("else "); else { printer.println("else"); @@ -1447,6 +1626,7 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1464,6 +1644,7 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1527,7 +1708,9 @@ public void visit(final LineComment n, final Void arg) { if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) { return; } - printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer + .print("// ") + .println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1536,16 +1719,13 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString()); - // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present - String[] lines = commentContent.split("\\R", -1); + String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. - printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); + printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. } - // last line is not followed by a newline, and simply terminated with `*/` - printer.print(lines[lines.length - 1]); + printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` printer.println("*/"); } @@ -1553,8 +1733,10 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); + if (printPar) { printer.print("("); } @@ -1568,6 +1750,7 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } + printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1587,6 +1770,7 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } + printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1606,9 +1790,11 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (getOption(ConfigOption.ORDER_IMPORTS).isPresent() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - // noinspection unchecked + //noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort( + comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) + .thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1632,9 +1818,11 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); + printOrphanCommentsEnding(n); } + @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1693,18 +1881,15 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) - return; - if (node instanceof Comment) - return; + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; + if (node instanceof Comment) return; + Node parent = node.getParentNode().orElse(null); - if (parent == null) - return; + if (parent == null) return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { - // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1715,26 +1900,28 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) - positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException( + "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) - return; + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; + // extract all nodes for which the position/range is indicated to avoid to skip orphan comments - List everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList()); + List everything = node.getChildNodes().stream().filter(n->n.getRange().isPresent()).collect(Collectors.toList()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } + int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -1748,17 +1935,16 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - - private void indentIf(boolean expr) { - if (expr) + private void indentIf(boolean expr){ + if(expr) printer.indent(); - } - - private void unindentIf(boolean expr) { - if (expr) + } + private void unindentIf(boolean expr){ + if(expr) printer.unindent(); } - + + private Optional getOption(ConfigOption cOption) { return configuration.get(new DefaultConfigurationOption(cOption)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java index a7dde26050..82b979cd38 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java @@ -18,26 +18,26 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +import java.util.List; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; -import java.util.List; - -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - /** * Outputs a Graphviz diagram of the AST. */ public class DotPrinter { private int nodeCount; - private final boolean outputNodeType; public DotPrinter(boolean outputNodeType) { @@ -57,26 +57,37 @@ public void output(Node node, String parentNodeName, String name, StringBuilder assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) + .collect(toList()); + String ndName = nextNodeName(); if (outputNodeType) - builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() + ")\"];"); + builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() + + ")\"];"); else builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + "\"];"); + if (parentNodeName != null) builder.append(SYSTEM_EOL + parentNodeName + " -> " + ndName + ";"); + for (PropertyMetaModel a : attributes) { String attrName = nextNodeName(); - builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" + escape(a.getValue(node).toString()) + "'\"];"); + builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" + + escape(a.getValue(node).toString()) + "'\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + attrName + ";"); + } + for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, ndName, sn.getName(), builder); } + for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { @@ -84,7 +95,8 @@ public void output(Node node, String parentNodeName, String name, StringBuilder builder.append(SYSTEM_EOL + ndLstName + " [label=\"" + escape(sl.getName()) + "\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + ndLstName + ";"); String slName = sl.getName().substring(0, sl.getName().length() - 1); - for (Node nd : nl) output(nd, ndLstName, slName, builder); + for (Node nd : nl) + output(nd, ndLstName, slName, builder); } } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index e478a1463e..d9731f6abf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -18,53 +18,158 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.isNullOrEmpty; +import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; +import static com.github.javaparser.utils.Utils.trimTrailingSpaces; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.EnumConstantDeclaration; +import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.ReceiverParameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.modules.*; -import com.github.javaparser.ast.nodeTypes.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.ast.expr.ArrayCreationExpr; +import com.github.javaparser.ast.expr.ArrayInitializerExpr; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CastExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.ClassExpr; +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.InstanceOfExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.expr.MemberValuePair; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NormalAnnotationExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.SuperExpr; +import com.github.javaparser.ast.expr.SwitchExpr; +import com.github.javaparser.ast.expr.TextBlockLiteralExpr; +import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.TypeExpr; +import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.modules.ModuleExportsDirective; +import com.github.javaparser.ast.modules.ModuleOpensDirective; +import com.github.javaparser.ast.modules.ModuleProvidesDirective; +import com.github.javaparser.ast.modules.ModuleRequiresDirective; +import com.github.javaparser.ast.modules.ModuleUsesDirective; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; +import com.github.javaparser.ast.nodeTypes.NodeWithVariables; +import com.github.javaparser.ast.nodeTypes.SwitchNode; +import com.github.javaparser.ast.stmt.AssertStmt; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.BreakStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ContinueStmt; +import com.github.javaparser.ast.stmt.DoStmt; +import com.github.javaparser.ast.stmt.EmptyStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForEachStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.LabeledStmt; +import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntry; +import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.ast.stmt.SynchronizedStmt; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.UnparsableStmt; +import com.github.javaparser.ast.stmt.WhileStmt; +import com.github.javaparser.ast.stmt.YieldStmt; +import com.github.javaparser.ast.type.ArrayType; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.IntersectionType; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.ReferenceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.type.UnionType; +import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.ast.type.WildcardType; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.*; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - /** * Outputs the AST as formatted Java source code. * This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation *

Use {@link DefaultPrettyPrinterVisitor default implementation } instead. * @author Julio Vilmar Gesser - * @deprecated This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation. + * @deprecated This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation. * This class could be removed in a future version. Use default DefaultPrettyPrinterVisitor. */ @Deprecated public class PrettyPrintVisitor implements VoidVisitor { - protected PrettyPrinterConfiguration configuration; - protected final SourcePrinter printer; public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) { this.configuration = prettyPrinterConfiguration; printer = new SourcePrinter(configuration); } - + public void setConfiguration(PrettyPrinterConfiguration prettyPrinterConfiguration) { this.configuration = prettyPrinterConfiguration; } @@ -106,7 +211,8 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, + final Void arg) { if (annotations.isEmpty()) { return; } @@ -214,13 +320,16 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } + if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } + n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } + for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -228,7 +337,9 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } + n.getModule().ifPresent(m -> m.accept(this, arg)); + printOrphanCommentsEnding(n); } @@ -241,6 +352,7 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); + printOrphanCommentsEnding(n); } @@ -249,6 +361,7 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); + printOrphanCommentsEnding(n); } @@ -261,6 +374,7 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); + printOrphanCommentsEnding(n); } @@ -275,13 +389,17 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } + n.getName().accept(this, arg); + printTypeParameters(n.getTypeParameters(), arg); + if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -292,6 +410,7 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } + if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -302,12 +421,15 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } + printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } + printOrphanCommentsEnding(n); + printer.unindent(); printer.print("}"); } @@ -328,6 +450,7 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } + boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -362,7 +485,9 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); + n.getName().accept(this, arg); + if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -405,6 +530,7 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } + type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -478,6 +604,7 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -488,6 +615,7 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } + printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -496,6 +624,7 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } + printer.print(";"); } @@ -504,9 +633,13 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); + n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { + final Type type = n.getType(); + ArrayType arrayType = null; + for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -517,6 +650,7 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); + if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -605,9 +739,12 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } + + /** * work in progress for issue-545 */ + @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -677,7 +814,7 @@ public void visit(final InstanceOfExpr n, final Void arg) { n.getExpression().accept(this, arg); printer.print(" instanceof "); n.getType().accept(this, arg); - if (n.getName().isPresent()) { + if(n.getName().isPresent()) { printer.print(" "); n.getName().get().accept(this, arg); } @@ -783,6 +920,7 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -790,24 +928,38 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (configuration.isColumnAlignFirstMethodChain()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() + || p.isThrowStmt() + || p.isAssertStmt() + || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) + .map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope) + .map(c::equals) + .orElse(false)) { c = p.get(); p = c.getParentNode(); } + // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } + // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { + while (node.getParentNode() + .filter(NodeWithTraversableScope.class::isInstance) + .map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope) + .map(node::equals) + .orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -815,13 +967,15 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } + // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast) + .flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -829,6 +983,7 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } + // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -853,6 +1008,7 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); + printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -872,13 +1028,18 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } + printer.print("new "); + printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } + n.getType().accept(this, arg); + printArguments(n.getArguments(), arg); + if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -895,7 +1056,9 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } + n.getExpression().accept(this, arg); + if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -907,11 +1070,13 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); + printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -923,6 +1088,7 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); + if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -940,6 +1106,7 @@ public void visit(final ConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -947,9 +1114,11 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } + n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); + printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -967,6 +1136,7 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); + if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1041,10 +1211,12 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); + if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); + for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1146,6 +1318,7 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + if (isNullOrEmpty(n.getLabels())) { printer.print("default:"); } else { @@ -1206,8 +1379,10 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printer.print("enum "); n.getName().accept(this, arg); + if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1218,12 +1393,15 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } + printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = + // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || + // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1255,9 +1433,11 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); + if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } + if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1284,8 +1464,7 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (// block statement should start on the same line - thenBlock) + if (thenBlock) // block statement should start on the same line printer.print(") "); else { printer.println(")"); @@ -1301,8 +1480,7 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (// put chained if and start of block statement on a same level - elseIf || elseBlock) + if (elseIf || elseBlock) // put chained if and start of block statement on a same level printer.print("else "); else { printer.println("else"); @@ -1459,6 +1637,7 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1476,6 +1655,7 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); + n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1539,7 +1719,9 @@ public void visit(final LineComment n, final Void arg) { if (configuration.isIgnoreComments()) { return; } - printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer + .print("// ") + .println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1548,16 +1730,13 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter()); - // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present - String[] lines = commentContent.split("\\R", -1); + String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. - printer.print(configuration.getEndOfLineCharacter()); + printer.print(configuration.getEndOfLineCharacter()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. } - // last line is not followed by a newline, and simply terminated with `*/` - printer.print(lines[lines.length - 1]); + printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` printer.println("*/"); } @@ -1565,8 +1744,10 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); + final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); + if (printPar) { printer.print("("); } @@ -1580,6 +1761,7 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } + printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1599,6 +1781,7 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } + printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1618,9 +1801,11 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (configuration.isOrderImports() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - // noinspection unchecked + //noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort( + comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) + .thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1644,9 +1829,11 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); + printOrphanCommentsEnding(n); } + @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1705,18 +1892,15 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (configuration.isIgnoreComments()) - return; - if (node instanceof Comment) - return; + if (configuration.isIgnoreComments()) return; + if (node instanceof Comment) return; + Node parent = node.getParentNode().orElse(null); - if (parent == null) - return; + if (parent == null) return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { - // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1727,26 +1911,28 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) - positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException( + "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (configuration.isIgnoreComments()) - return; + if (configuration.isIgnoreComments()) return; + // extract all nodes for which the position/range is indicated to avoid to skip orphan comments - List everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList()); + List everything = node.getChildNodes().stream().filter(n->n.getRange().isPresent()).collect(Collectors.toList()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } + int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -1760,14 +1946,12 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - - private void indentIf(boolean expr) { - if (expr) + private void indentIf(boolean expr){ + if(expr) printer.indent(); - } - - private void unindentIf(boolean expr) { - if (expr) + } + private void unindentIf(boolean expr){ + if(expr) printer.unindent(); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java index 23a391764f..8e56a4c54c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java @@ -18,14 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; +import java.util.function.Function; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; import com.github.javaparser.printer.configuration.PrinterConfiguration; - -import java.util.function.Function; +import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; /** * Pretty printer for AST nodes. @@ -35,24 +36,24 @@ */ @Deprecated public class PrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + private Function> visitorFactory; public PrettyPrinter() { this(new PrettyPrinterConfiguration()); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration) { this(configuration, PrettyPrintVisitor::new); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration, Function> visitorFactory) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + /* * Returns the PrettyPrinter configuration */ @@ -72,8 +73,9 @@ public Printer setConfiguration(PrinterConfiguration configuration) { @Override public String print(Node node) { - final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration) configuration); + final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration)configuration); node.accept(visitor, null); return visitor.toString(); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java index 0e3d651145..09a51e86e9 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java @@ -5,13 +5,15 @@ /** * Printer interface defines the API for a printer. - * A printer outputs the AST as formatted Java source code. + * A printer outputs the AST as formatted Java source code. + * */ public interface Printer { String print(Node node); Printer setConfiguration(PrinterConfiguration configuration); - + PrinterConfiguration getConfiguration(); -} + +} \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java index e13a7f7306..a0841da3b0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java @@ -18,51 +18,49 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; +import java.util.Deque; +import java.util.LinkedList; + import com.github.javaparser.Position; -import com.github.javaparser.printer.configuration.*; +import com.github.javaparser.printer.configuration.DefaultConfigurationOption; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; +import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; +import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.utils.Utils; -import java.util.Deque; -import java.util.LinkedList; - /** * A support class for code that outputs formatted source code. */ public class SourcePrinter { - private String endOfLineCharacter; - private Indentation indentation; private final Deque indents = new LinkedList<>(); - private final Deque reindentedIndents = new LinkedList<>(); - private String lastPrintedIndent = ""; - private final StringBuilder buf = new StringBuilder(); - - // Start before the first column - private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); - + private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); // Start before the first column private boolean indented = false; SourcePrinter() { this(new DefaultPrinterConfiguration()); } - + SourcePrinter(final PrettyPrinterConfiguration configuration) { this(configuration.getIndentation(), configuration.getEndOfLineCharacter()); } SourcePrinter(final PrinterConfiguration configuration) { - this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); + this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), + configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); } - + SourcePrinter(Indentation indentation, String eol) { this.indentation = indentation; this.endOfLineCharacter = eol; @@ -75,14 +73,16 @@ public class SourcePrinter { */ public SourcePrinter indent() { String currentIndent = indents.peek(); - switch(indentation.getType()) { + switch (indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: indents.push(currentIndent + indentation.getIndent()); break; + case TABS: indents.push(indentation.getIndent() + currentIndent); break; + default: throw new AssertionError("Unhandled indent type"); } @@ -99,19 +99,21 @@ public SourcePrinter indentWithAlignTo(int column) { } private String calculateIndentWithAlignTo(int column) { - if (column < lastPrintedIndent.length()) { + if (column < lastPrintedIndent.length()){ throw new IllegalStateException("Attempt to indent less than the previous indent."); } + StringBuilder newIndent = new StringBuilder(lastPrintedIndent); - switch(indentation.getType()) { + switch (indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: while (newIndent.length() < column) { newIndent.append(IndentType.SPACES.getCar()); } break; + case TABS: - IndentType currentIndentType = indentation.getType(); + IndentType currentIndentType = indentation.getType(); int logicalIndentLength = newIndent.length(); while ((logicalIndentLength + currentIndentType.getWidth()) <= column) { newIndent.insert(0, currentIndentType.getCar()); @@ -122,18 +124,21 @@ private String calculateIndentWithAlignTo(int column) { logicalIndentLength++; } StringBuilder fullTab = new StringBuilder(); - for (int i = 0; i < currentIndentType.getWidth(); i++) { + for(int i=0; i= currentIndentType.getWidth()) && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { + if ((newIndent.length() >= currentIndentType.getWidth()) + && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { int i = newIndent.indexOf(fullTabString); newIndent.replace(i, i + currentIndentType.getWidth(), currentIndentType.getCar().toString()); } break; + default: throw new AssertionError("Unhandled indent type"); } + return newIndent.toString(); } @@ -203,8 +208,7 @@ public SourcePrinter println(final String arg) { */ public SourcePrinter println() { buf.append(endOfLineCharacter); - // Start before the first column - cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); + cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); // Start before the first column indented = false; return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java index dc6f0ab42d..b299b2f3d6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java @@ -24,6 +24,5 @@ * Something that has a printable form. I.e., it can be converted to a user-facing String. */ public interface Stringable { - String asString(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java index 434f2526fe..7c9bc5455e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; import com.github.javaparser.ast.Node; @@ -34,7 +35,6 @@ * Outputs an XML file containing the AST meant for inspecting it. */ public class XmlPrinter { - private final boolean outputNodeType; public XmlPrinter(boolean outputNodeType) { @@ -54,20 +54,24 @@ public void output(Node node, String name, int level, StringBuilder builder) { List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); + builder.append("<").append(name); if (outputNodeType) { builder.append(attribute("type", metaModel.getTypeName())); } + for (PropertyMetaModel attributeMetaModel : attributes) { builder.append(attribute(attributeMetaModel.getName(), attributeMetaModel.getValue(node).toString())); } builder.append(">"); + for (PropertyMetaModel subNodeMetaModel : subNodes) { Node value = (Node) subNodeMetaModel.getValue(node); if (value != null) { output(value, subNodeMetaModel.getName(), level + 1, builder); } } + for (PropertyMetaModel subListMetaModel : subLists) { NodeList subList = (NodeList) subListMetaModel.getValue(node); if (subList != null && !subList.isEmpty()) { @@ -95,3 +99,4 @@ public static void print(Node node) { System.out.println(new XmlPrinter(true).output(node)); } } + diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java index 726e95d4da..1375e81e61 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java @@ -18,25 +18,25 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + +import java.util.List; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; -import java.util.List; - -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - /** * Outputs a YAML file containing the AST meant for inspecting it. */ public class YamlPrinter { private static final int NUM_SPACES_FOR_INDENT = 4; - private final boolean outputNodeType; public YamlPrinter(boolean outputNodeType) { @@ -55,41 +55,58 @@ public void output(Node node, String name, int level, StringBuilder builder) { assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) + .filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) + .collect(toList()); + if (outputNodeType) builder.append(System.lineSeparator() + indent(level) + name + "(Type=" + metaModel.getTypeName() + "): "); else builder.append(System.lineSeparator() + indent(level) + name + ": "); + level++; for (PropertyMetaModel a : attributes) { builder.append(System.lineSeparator() + indent(level) + a.getName() + ": " + escapeValue(a.getValue(node).toString())); } + for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, sn.getName(), level, builder); } + for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { builder.append(System.lineSeparator() + indent(level) + sl.getName() + ": "); String slName = sl.getName(); slName = slName.endsWith("s") ? slName.substring(0, sl.getName().length() - 1) : slName; - for (Node nd : nl) output(nd, "- " + slName, level + 1, builder); + for (Node nd : nl) + output(nd, "- " + slName, level + 1, builder); } } } private String indent(int level) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < level; i++) for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) sb.append(" "); + for (int i = 0; i < level; i++) + for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) + sb.append(" "); return sb.toString(); } private String escapeValue(String value) { - return "\"" + value.replace("\\", "\\\\").replaceAll("\"", "\\\\\"").replace("\n", "\\n").replace("\r", "\\r").replace("\f", "\\f").replace("\b", "\\b").replace("\t", "\\t") + "\""; + return "\"" + value + .replace("\\", "\\\\") + .replaceAll("\"", "\\\\\"") + .replace("\n", "\\n") + .replace("\r", "\\r") + .replace("\f", "\\f") + .replace("\b", "\\b") + .replace("\t", "\\t") + "\""; } public static void print(Node node) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java index 921c6e7c45..daafd13c00 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -29,7 +30,6 @@ import static com.github.javaparser.utils.CodeGenerationUtils.f; public class CsmAttribute implements CsmElement { - public ObservableProperty getProperty() { return property; } @@ -53,30 +53,28 @@ public void prettyPrint(Node node, SourcePrinter printer) { * @param tokenText Operator's token text */ public int getTokenType(Node node, String text, String tokenText) { - switch(property) { + switch (property) { case IDENTIFIER: return GeneratedJavaParserConstants.IDENTIFIER; - case TYPE: - { - String expectedImage = "\"" + text.toLowerCase() + "\""; - for (int i = 0; i < GeneratedJavaParserConstants.tokenImage.length; i++) { - if (GeneratedJavaParserConstants.tokenImage[i].equals(expectedImage)) { - return i; - } + case TYPE: { + String expectedImage = "\"" + text.toLowerCase() + "\""; + for (int i=0;i process(c, printer)); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java index f0c84f2507..4e4b0afb2e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -29,13 +30,9 @@ import java.util.List; public class CsmConditional implements CsmElement { - private final Condition condition; - private final List properties; - private final CsmElement thenElement; - private final CsmElement elseElement; public Condition getCondition() { @@ -48,7 +45,7 @@ public ObservableProperty getProperty() { } return properties.get(0); } - + public List getProperties() { return properties; } @@ -62,10 +59,12 @@ public CsmElement getElseElement() { } public enum Condition { + IS_EMPTY, + IS_NOT_EMPTY, + IS_PRESENT, + FLAG; - IS_EMPTY, IS_NOT_EMPTY, IS_PRESENT, FLAG; - - boolean evaluate(Node node, ObservableProperty property) { + boolean evaluate(Node node, ObservableProperty property){ if (this == IS_PRESENT) { return !property.isNullOrNotPresent(node); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java index 867e301c05..73ddc032c3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -29,8 +30,7 @@ import java.util.Arrays; import java.util.List; -import static com.github.javaparser.TokenTypes.eolTokenKind; -import static com.github.javaparser.TokenTypes.spaceTokenKind; +import static com.github.javaparser.TokenTypes.*; public interface CsmElement { @@ -96,9 +96,7 @@ static CsmElement semicolon() { return new CsmToken(GeneratedJavaParserConstants.SEMICOLON); } - static CsmElement comment() { - return new CsmComment(); - } + static CsmElement comment() { return new CsmComment(); } static CsmElement newline() { return newline(LineSeparator.SYSTEM); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java index ce0dcb2b5b..9170730d21 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java index 596872d909..30a49983f2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -30,15 +31,10 @@ import java.util.Iterator; public class CsmList implements CsmElement { - private final ObservableProperty property; - private final CsmElement separatorPost; - private final CsmElement separatorPre; - private final CsmElement preceeding; - private final CsmElement following; public ObservableProperty getProperty() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java index e2bb1dfb4d..5418e7c6ed 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -31,7 +32,6 @@ * A group of elements that could be in any order. */ public class CsmMix implements CsmElement { - private List elements; public CsmMix(List elements) { @@ -55,11 +55,11 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CsmMix csmMix = (CsmMix) o; + return elements != null ? elements.equals(csmMix.elements) : csmMix.elements == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java index 1d080d02fd..5bb932f42d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -27,5 +28,7 @@ public class CsmNone implements CsmElement { @Override public void prettyPrint(Node node, SourcePrinter printer) { + } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java index d55a9915e8..2144c3bff7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -39,6 +40,7 @@ public void prettyPrint(Node node, SourcePrinter printer) { if (everything.isEmpty()) { return; } + int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -49,8 +51,9 @@ public void prettyPrint(Node node, SourcePrinter printer) { } } for (int i = 0; i < commentsAtEnd; i++) { - Comment c = (Comment) everything.get(everything.size() - commentsAtEnd + i); + Comment c = (Comment)everything.get(everything.size() - commentsAtEnd + i); CsmComment.process(c, printer); } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java index aed7b37106..a9bb3300d0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -27,7 +28,6 @@ import java.util.Objects; public class CsmSequence implements CsmElement { - private List elements; public CsmSequence(List elements) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java index fa9a92865b..a92f003384 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -26,7 +27,6 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmSingleReference implements CsmElement { - private final ObservableProperty property; public ObservableProperty getProperty() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java index c2f4e24ad8..2b66ffcec4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -25,7 +26,6 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmString implements CsmElement { - private final ObservableProperty property; public CsmString(ObservableProperty property) { @@ -43,4 +43,5 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("CsmString(property:%s)", property); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java index 45ad100d1c..ba86ff9af6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -25,7 +26,6 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmTextBlock implements CsmElement { - private final ObservableProperty property; public CsmTextBlock(ObservableProperty property) { @@ -36,8 +36,7 @@ public CsmTextBlock(ObservableProperty property) { public void prettyPrint(Node node, SourcePrinter printer) { // Note that values within TextBlocks ALWAYS have the \n line ending, per https://openjdk.java.net/jeps/378#1--Line-terminators printer.print("\"\"\"\n"); - // TODO: Confirm if we need to force this to use {@code \n} separators - printer.print(property.getValueAsStringAttribute(node)); + printer.print(property.getValueAsStringAttribute(node)); // TODO: Confirm if we need to force this to use {@code \n} separators printer.print("\"\"\""); } @@ -45,4 +44,5 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("CsmTextBlock(property:%s)", property); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java index 7f3803ff50..bc3724e6eb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -26,19 +27,14 @@ import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.utils.LineSeparator; -import static com.github.javaparser.TokenTypes.isEndOfLineToken; -import static com.github.javaparser.TokenTypes.isWhitespaceButNotEndOfLine; +import static com.github.javaparser.TokenTypes.*; public class CsmToken implements CsmElement { - private final int tokenType; - private String content; - private TokenContentCalculator tokenContentCalculator; public interface TokenContentCalculator { - String calculate(Node node); } @@ -59,8 +55,9 @@ public CsmToken(int tokenType) { if (content.startsWith("\"")) { content = content.substring(1, content.length() - 1); } + // Replace "raw" values with escaped textual counterparts (e.g. newlines {@code \r\n}) - // and "placeholder" values ({@code }) with their textual counterparts + // and "placeholder" values ({@code }) with their textual counterparts if (isEndOfLineToken(tokenType)) { // Use the unescaped version content = LineSeparator.lookupEscaped(this.content).get().asRawString(); @@ -95,15 +92,13 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CsmToken csmToken = (CsmToken) o; - if (tokenType != csmToken.tokenType) - return false; - if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) - return false; + + if (tokenType != csmToken.tokenType) return false; + if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) return false; return tokenContentCalculator != null ? tokenContentCalculator.equals(csmToken.tokenContentCalculator) : csmToken.tokenContentCalculator == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java index 6ab7655a8d..0234eb156a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java index f114589eab..592da61bf4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.printer.Stringable; @@ -26,7 +27,7 @@ class PrintingHelper { static String printToString(Object value) { if (value instanceof Stringable) { - return ((Stringable) value).asString(); + return ((Stringable)value).asString(); } if (value instanceof Enum) { return ((Enum) value).name().toLowerCase(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java index 3a0c0b5e08..a60d0804b3 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java @@ -28,4 +28,5 @@ public interface ConfigurationOption { Boolean asBoolean(); T asValue(); -} + +} \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java index 9896308302..50070a7643 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java @@ -17,6 +17,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.configuration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; @@ -26,9 +27,7 @@ * An option is a pair of ConfigOption and a currentValue */ public class DefaultConfigurationOption implements ConfigurationOption { - ConfigOption configOption; - Object currentValue; public DefaultConfigurationOption(ConfigOption configOption) { @@ -43,8 +42,7 @@ public DefaultConfigurationOption(ConfigOption configOption, Object value) { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof DefaultConfigurationOption)) - return false; + if (o == null || !(o instanceof DefaultConfigurationOption)) return false; DefaultConfigurationOption other = (DefaultConfigurationOption) o; return configOption.equals(other.configOption); } @@ -63,7 +61,8 @@ public ConfigurationOption value(Object value) { this.currentValue = value; // verify the currentValue's type if (!(configOption.type.isAssignableFrom(value.getClass()))) { - throw new IllegalArgumentException(String.format("%s is not an instance of %s", value, configOption.type.getName())); + throw new IllegalArgumentException( + String.format("%s is not an instance of %s", value, configOption.type.getName())); } return this; } @@ -110,6 +109,7 @@ private T cast() { throw new IllegalArgumentException(String.format("The option %s has no currentValue", configOption.name())); if (configOption.type.isAssignableFrom(currentValue.getClass())) return (T) configOption.type.cast(currentValue); - throw new IllegalArgumentException(String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); + throw new IllegalArgumentException( + String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java index f62555a7a5..1a2cc7f269 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java @@ -17,38 +17,38 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ -package com.github.javaparser.printer.configuration; -import com.github.javaparser.printer.Printer; -import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.utils.Utils; +package com.github.javaparser.printer.configuration; import java.util.Arrays; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import com.github.javaparser.printer.Printer; +import com.github.javaparser.printer.configuration.Indentation.IndentType; +import com.github.javaparser.utils.Utils; + /** * Configuration options for the {@link Printer}. */ public class DefaultPrinterConfiguration implements PrinterConfiguration { - + public enum ConfigOption { - /** * Order imports alphabetically */ - ORDER_IMPORTS(Boolean.class), + ORDER_IMPORTS(Boolean.class), /** * Print comments only. It can be combined with {@code PRINT_JAVADOC} to print regular comments and javadoc. */ - PRINT_COMMENTS(Boolean.class), + PRINT_COMMENTS(Boolean.class), /** * Print javadoc comments only. It can be combined with {@code PRINT_COMMENTS} to print regular javadoc and comments */ - PRINT_JAVADOC(Boolean.class), - SPACE_AROUND_OPERATORS(Boolean.class), - COLUMN_ALIGN_PARAMETERS(Boolean.class), + PRINT_JAVADOC(Boolean.class), + SPACE_AROUND_OPERATORS(Boolean.class), + COLUMN_ALIGN_PARAMETERS(Boolean.class), COLUMN_ALIGN_FIRST_METHOD_CHAIN(Boolean.class), /** * Indent the case when it is true, don't if false @@ -91,16 +91,16 @@ public enum ConfigOption { * Indentation proprerty */ INDENTATION(Indentation.class, new Indentation(IndentType.SPACES, 4)); - + Object defaultValue; - + Class type; - + // DefaultConfigurationOption without currentValue ConfigOption(Class clazz) { this.type = clazz; } - + // DefaultConfigurationOption with initial currentValue ConfigOption(Class clazz, Object value) { this.type = clazz; @@ -109,15 +109,25 @@ public enum ConfigOption { } this.defaultValue = value; } + + } - + // contains all available options // an option contained in the set is considered as activated - private Set defaultOptions = new HashSet<>(Arrays.asList(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue))); + private Set defaultOptions = new HashSet<>(Arrays.asList( + new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), + new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), + new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), + new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), + new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), + new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), + new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue) + )); public DefaultPrinterConfiguration() { } - + /* * add the specified option if it does not exist or replace the existing option */ @@ -127,7 +137,7 @@ public PrinterConfiguration addOption(ConfigurationOption option) { defaultOptions.add(option); return this; } - + /* * remove the specified option */ @@ -136,7 +146,7 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { defaultOptions.remove(option); return this; } - + /* * True if an option is activated */ @@ -144,13 +154,13 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { public boolean isActivated(ConfigurationOption option) { return defaultOptions.contains(option); } - + /* * returns the specified option */ @Override public Optional get(ConfigurationOption option) { - return defaultOptions.stream().filter(o -> o.equals(option)).findFirst(); + return defaultOptions.stream().filter(o-> o.equals(option)).findFirst(); } /** @@ -160,4 +170,5 @@ public Optional get(ConfigurationOption option) { public Set get() { return defaultOptions; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java index a30a92ca8f..1474b4bfc2 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java @@ -17,24 +17,27 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.configuration; /** - * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). + * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). + * */ public class Indentation { - + public enum IndentType { - /** * Indent with spaces. */ SPACES(' ', 1), + /** * Indent with tabs as far as possible. * For proper aligning, the tab width is necessary and by default 4. */ TABS('\t', 4), + /** * Indent with tabs but align with spaces when wrapping and aligning * method call chains and method call parameters. @@ -57,11 +60,11 @@ public enum IndentType { * */ TABS_WITH_SPACE_ALIGN('\t', 4); - + private Character car; - + private int width; - + private IndentType(Character c, int width) { this.car = c; this.width = width; @@ -74,20 +77,21 @@ public Character getCar() { public int getWidth() { return width; } + } - + // default size - private static final int DEFAULT_SIZE = 4; - + private static final int DEFAULT_SIZE = 4; + // type of the indentation private IndentType type; - + // size of the indentation (define how many spaces or tabs is used to indent) private int size; - + // formatted indentation private String formattedIndentation = ""; - + /* * Creates an Indentation with a type and size */ @@ -96,14 +100,14 @@ public Indentation(IndentType type, int size) { this.size = size; format(); } - + /* * Creates an Indentation with the default size */ public Indentation(IndentType type) { this(type, DEFAULT_SIZE); } - + /* * set the size of the indentation (how many spaces or tabs?) */ @@ -112,11 +116,11 @@ public Indentation setSize(int size) { format(); return this; } - + public int getSize() { return size; } - + /* * set the type of the indentation (spaces, tabs...) */ @@ -125,7 +129,7 @@ public Indentation setType(IndentType type) { format(); return this; } - + public IndentType getType() { return type; } @@ -136,7 +140,7 @@ public IndentType getType() { public String getIndent() { return formattedIndentation; } - + // format the indentation string private void format() { StringBuilder indentString = new StringBuilder(); @@ -146,9 +150,9 @@ private void format() { } formattedIndentation = indentString.toString(); } - + @Override public String toString() { - return type.name() + " size=" + size; + return type.name() + " size=" + size ; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java index a8518da893..06b9407b03 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java @@ -18,16 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.configuration; -import com.github.javaparser.printer.PrettyPrinter; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation.IndentType; +import static com.github.javaparser.utils.Utils.assertNonNegative; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static com.github.javaparser.utils.Utils.assertPositive; import java.util.Optional; import java.util.Set; -import static com.github.javaparser.utils.Utils.*; +import com.github.javaparser.printer.PrettyPrinter; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; +import com.github.javaparser.printer.configuration.Indentation.IndentType; /** * Configuration options for the {@link PrettyPrinter}. @@ -37,23 +40,24 @@ */ @Deprecated public class PrettyPrinterConfiguration implements PrinterConfiguration { - + + PrinterConfiguration wrappedConfiguration; - + /* * Default constructor */ public PrettyPrinterConfiguration() { this.wrappedConfiguration = new DefaultPrinterConfiguration(); } - + /* * returns the indentation parameters */ public Indentation getIndentation() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(); } - + public PrettyPrinterConfiguration setIndentation(Indentation indentation) { wrappedConfiguration.addOption(new DefaultConfigurationOption(ConfigOption.INDENTATION, indentation)); return this; @@ -108,6 +112,8 @@ public PrettyPrinterConfiguration setIndentType(IndentType indentType) { return this; } + + /** * Get the tab width for pretty aligning. * @deprecated (@see Indentation.size) @@ -138,7 +144,7 @@ public boolean isPrintComments() { public boolean isIgnoreComments() { return !wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)).isPresent(); } - + public boolean isSpaceAroundOperators() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)).isPresent(); } @@ -159,12 +165,15 @@ public boolean isIndentCaseInSwitch() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)).isPresent(); } + /** * When true, all comments will be printed, unless printJavadoc is false, then only line and block comments will be * printed. */ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { - wrappedConfiguration = printComments ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); + wrappedConfiguration = printComments ? + addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : + removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); return this; } @@ -172,30 +181,40 @@ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { * When true, Javadoc will be printed. */ public PrettyPrinterConfiguration setPrintJavadoc(boolean printJavadoc) { - wrappedConfiguration = printJavadoc ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); + wrappedConfiguration = printJavadoc ? + addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : + removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); return this; } /** * Set if there should be spaces between operators */ - public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators) { - wrappedConfiguration = spaceAroundOperators ? addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); + public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators){ + wrappedConfiguration = spaceAroundOperators ? + addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : + removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); return this; } public PrettyPrinterConfiguration setColumnAlignParameters(boolean columnAlignParameters) { - wrappedConfiguration = columnAlignParameters ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); + wrappedConfiguration = columnAlignParameters ? + addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : + removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); return this; } public PrettyPrinterConfiguration setColumnAlignFirstMethodChain(boolean columnAlignFirstMethodChain) { - wrappedConfiguration = columnAlignFirstMethodChain ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); + wrappedConfiguration = columnAlignFirstMethodChain ? + addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : + removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); return this; } public PrettyPrinterConfiguration setIndentCaseInSwitch(boolean indentInSwitch) { - wrappedConfiguration = indentInSwitch ? addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); + wrappedConfiguration = indentInSwitch ? + addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : + removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); return this; } @@ -215,10 +234,13 @@ public PrettyPrinterConfiguration setEndOfLineCharacter(String endOfLineCharacte * When true, orders imports by alphabetically. */ public PrettyPrinterConfiguration setOrderImports(boolean orderImports) { - wrappedConfiguration = orderImports ? addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); + wrappedConfiguration = orderImports ? + addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); return this; } + + public int getMaxEnumConstantsToAlignHorizontally() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY)).get().asInteger(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java index 448cd9fff1..dd50a93829 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java @@ -13,7 +13,7 @@ public interface PrinterConfiguration { * add or update an option */ PrinterConfiguration addOption(ConfigurationOption option); - + /* * Remove an option */ @@ -33,4 +33,5 @@ public interface PrinterConfiguration { * returns all activated options */ Set get(); -} + +} \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java index afb8d93cb4..3b321de77c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; @@ -26,7 +27,6 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Added implements DifferenceElement { - private final CsmElement element; Added(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Added added = (Added) o; + return element.equals(added.element); } @@ -68,13 +68,9 @@ public boolean isRemoved() { return false; } - public boolean isIndent() { - return element instanceof CsmIndent; - } + public boolean isIndent() { return element instanceof CsmIndent; } - public boolean isUnindent() { - return element instanceof CsmUnindent; - } + public boolean isUnindent() { return element instanceof CsmUnindent; } public TextElement toTextElement() { if (element instanceof LexicalDifferenceCalculator.CsmChild) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java index c0666b5634..131144a46c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.Range; @@ -30,7 +31,6 @@ * Represent the position of a child node in the NodeText of its parent. */ class ChildTextElement extends TextElement { - private final Node child; ChildTextElement(Node child) { @@ -61,12 +61,13 @@ NodeText getNodeTextForWrappedNode() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChildTextElement that = (ChildTextElement) o; + return child.equals(that.child); + } @Override @@ -98,17 +99,17 @@ public boolean isNewline() { public boolean isComment() { return child instanceof Comment; } - + @Override public boolean isSeparator() { return false; } - + @Override public boolean isIdentifier() { return false; } - + @Override public boolean isPrimitive() { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 23d300dee1..14149f8bce 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -18,8 +18,23 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; +import static com.github.javaparser.GeneratedJavaParserConstants.LBRACE; +import static com.github.javaparser.GeneratedJavaParserConstants.RBRACE; +import static com.github.javaparser.GeneratedJavaParserConstants.SPACE; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Optional; + import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.JavaToken; import com.github.javaparser.JavaToken.Kind; @@ -29,13 +44,13 @@ import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.type.Type; -import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; +import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; +import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; +import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; +import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; -import java.util.*; - -import static com.github.javaparser.GeneratedJavaParserConstants.*; - /** * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements * to remove or to add and follow by another sequence of elements. @@ -47,29 +62,26 @@ public class Difference { public static final int STANDARD_INDENTATION_SIZE = 4; private final NodeText nodeText; - private final Node node; private final List diffElements; - private final List originalElements; - private int originalIndex = 0; - private int diffIndex = 0; private final List indentation; - private boolean addedIndentation = false; Difference(List diffElements, NodeText nodeText, Node node) { if (nodeText == null) { throw new NullPointerException("nodeText can not be null"); } + this.nodeText = nodeText; this.node = node; this.diffElements = diffElements; this.originalElements = nodeText.getElements(); + this.indentation = LexicalPreservingPrinter.findIndentation(node); } @@ -81,7 +93,7 @@ private List processIndentation(List indentation, res.clear(); afterNl = true; } else { - if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement) e).getTokenKind())) { + if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement)e).getTokenKind())) { res.add(e); } else { afterNl = false; @@ -147,17 +159,21 @@ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { void apply() { extractReshuffledDiffElements(diffElements); Map removedGroups = combineRemovedElementsToRemovedGroups(); + do { boolean isLeftOverDiffElement = applyLeftOverDiffElements(); boolean isLeftOverOriginalElement = applyLeftOverOriginalElements(); - if (!isLeftOverDiffElement && !isLeftOverOriginalElement) { + + if (!isLeftOverDiffElement && !isLeftOverOriginalElement){ DifferenceElement diffElement = diffElements.get(diffIndex); + if (diffElement instanceof Added) { applyAddedDiffElement((Added) diffElement); } else { TextElement originalElement = originalElements.get(originalIndex); boolean originalElementIsChild = originalElement instanceof ChildTextElement; boolean originalElementIsToken = originalElement instanceof TokenTextElement; + if (diffElement instanceof Kept) { applyKeptDiffElement((Kept) diffElement, originalElement, originalElementIsChild, originalElementIsToken); } else if (diffElement instanceof Removed) { @@ -175,11 +191,14 @@ private boolean applyLeftOverOriginalElements() { boolean isLeftOverElement = false; if (diffIndex >= diffElements.size() && originalIndex < originalElements.size()) { TextElement originalElement = originalElements.get(originalIndex); + if (originalElement.isWhiteSpaceOrComment()) { originalIndex++; } else { - throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " + this + " " + originalElement); + throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " + + this + " " + originalElement); } + isLeftOverElement = true; } return isLeftOverElement; @@ -191,21 +210,26 @@ private boolean applyLeftOverDiffElements() { DifferenceElement diffElement = diffElements.get(diffIndex); if (diffElement instanceof Kept) { Kept kept = (Kept) diffElement; + if (kept.isWhiteSpaceOrComment() || kept.isIndent() || kept.isUnindent()) { diffIndex++; } else { - throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " + nodeText + ". Difference: " + this); + throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " + + nodeText + ". Difference: " + this); } } else if (diffElement instanceof Added) { Added addedElement = (Added) diffElement; + nodeText.addElement(originalIndex, addedElement.toTextElement()); originalIndex++; diffIndex++; } else { throw new UnsupportedOperationException(diffElement.getClass().getSimpleName()); } + isLeftOverElement = true; } + return isLeftOverElement; } @@ -214,13 +238,17 @@ private void extractReshuffledDiffElements(List diffElements) DifferenceElement diffElement = diffElements.get(index); if (diffElement instanceof Reshuffled) { Reshuffled reshuffled = (Reshuffled) diffElement; + // First, let's see how many tokens we need to attribute to the previous version of the of the CsmMix CsmMix elementsFromPreviousOrder = reshuffled.getPreviousOrder(); CsmMix elementsFromNextOrder = reshuffled.getNextOrder(); + // This contains indexes from elementsFromNextOrder to indexes from elementsFromPreviousOrder Map correspondanceBetweenNextOrderAndPreviousOrder = getCorrespondanceBetweenNextOrderAndPreviousOrder(elementsFromPreviousOrder, elementsFromNextOrder); + // We now find out which Node Text elements corresponds to the elements in the original CSM List nodeTextIndexOfPreviousElements = findIndexOfCorrespondingNodeTextElement(elementsFromPreviousOrder.getElements(), nodeText, originalIndex, node); + Map nodeTextIndexToPreviousCSMIndex = new HashMap<>(); for (int i = 0; i < nodeTextIndexOfPreviousElements.size(); i++) { int value = nodeTextIndexOfPreviousElements.get(i); @@ -229,9 +257,11 @@ private void extractReshuffledDiffElements(List diffElements) } } int lastNodeTextIndex = nodeTextIndexOfPreviousElements.stream().max(Integer::compareTo).orElse(-1); + // Elements to be added at the end List elementsToBeAddedAtTheEnd = new LinkedList<>(); List nextOrderElements = elementsFromNextOrder.getElements(); + Map> elementsToAddBeforeGivenOriginalCSMElement = new HashMap<>(); for (int ni = 0; ni < nextOrderElements.size(); ni++) { // If it has a mapping, then it is kept @@ -254,18 +284,22 @@ private void extractReshuffledDiffElements(List diffElements) } } } + // We go over the original node text elements, in the order they appear in the NodeText. // Considering an original node text element (ONE) // * we verify if it corresponds to a CSM element. If it does not we just move on, otherwise - // we find the correspond OCE (Original CSM Element) + // we find the correspond OCE (Original CSM Element) // * we first add new elements that are marked to be added before OCE // * if OCE is marked to be present also in the "after" CSM we add a kept element, - // otherwise we add a removed element + // otherwise we add a removed element + // Remove the whole Reshuffled element diffElements.remove(index); + int diffElIterator = index; if (lastNodeTextIndex != -1) { for (int ntIndex = originalIndex; ntIndex <= lastNodeTextIndex; ntIndex++) { + if (nodeTextIndexToPreviousCSMIndex.containsKey(ntIndex)) { int indexOfOriginalCSMElement = nodeTextIndexToPreviousCSMIndex.get(ntIndex); if (elementsToAddBeforeGivenOriginalCSMElement.containsKey(indexOfOriginalCSMElement)) { @@ -273,6 +307,7 @@ private void extractReshuffledDiffElements(List diffElements) diffElements.add(diffElIterator++, new Added(elementToAdd)); } } + CsmElement originalCSMElement = elementsFromPreviousOrder.getElements().get(indexOfOriginalCSMElement); boolean toBeKept = correspondanceBetweenNextOrderAndPreviousOrder.containsValue(indexOfOriginalCSMElement); if (toBeKept) { @@ -284,6 +319,7 @@ private void extractReshuffledDiffElements(List diffElements) // else we have a simple node text element, without associated csm element, just keep ignore it } } + // Finally we look for the remaining new elements that were not yet added and // add all of them for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) { @@ -308,21 +344,25 @@ private void extractReshuffledDiffElements(List diffElements) */ private Map combineRemovedElementsToRemovedGroups() { Map> removedElementsMap = groupConsecutiveRemovedElements(); + List removedGroups = new ArrayList<>(); for (Map.Entry> entry : removedElementsMap.entrySet()) { removedGroups.add(RemovedGroup.of(entry.getKey(), entry.getValue())); } + Map map = new HashMap<>(); - for (RemovedGroup removedGroup : removedGroups) { + for (RemovedGroup removedGroup : removedGroups){ for (Removed index : removedGroup) { map.put(index, removedGroup); } } + return map; } private Map> groupConsecutiveRemovedElements() { Map> removedElementsMap = new HashMap<>(); + Integer firstElement = null; for (int i = 0; i < diffElements.size(); i++) { DifferenceElement diffElement = diffElements.get(i); @@ -330,7 +370,9 @@ private Map> groupConsecutiveRemovedElements() { if (firstElement == null) { firstElement = i; } - removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()).add((Removed) diffElement); + + removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()) + .add((Removed) diffElement); } else { firstElement = null; } @@ -352,23 +394,30 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } else { nodeText.removeElement(originalIndex); - if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1) instanceof Added)) && !removedGroup.isACompleteLine()) { + + if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1) instanceof Added)) + && !removedGroup.isACompleteLine()) { originalIndex = considerEnforcingIndentation(nodeText, originalIndex); } // If in front we have one space and before also we had space let's drop one space if (originalElements.size() > originalIndex && originalIndex > 0) { - if (originalElements.get(originalIndex).isWhiteSpace() && originalElements.get(originalIndex - 1).isWhiteSpace()) { + if (originalElements.get(originalIndex).isWhiteSpace() + && originalElements.get(originalIndex - 1).isWhiteSpace()) { // However we do not want to do that when we are about to adding or removing elements if ((diffIndex + 1) == diffElements.size() || (diffElements.get(diffIndex + 1) instanceof Kept)) { originalElements.remove(originalIndex--); } } } + diffIndex++; } - } else if (removed.isToken() && originalElementIsToken && (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // handle EOLs separately as their token kind might not be equal. This is because the 'removed' - // element always has the current operating system's EOL as type - (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() && removed.isNewLine()))) { + } else if (removed.isToken() && originalElementIsToken && + (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() + // handle EOLs separately as their token kind might not be equal. This is because the 'removed' + // element always has the current operating system's EOL as type + || (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() + && removed.isNewLine()))) { nodeText.removeElement(originalIndex); diffIndex++; } else if (originalElementIsToken && originalElement.isWhiteSpaceOrComment()) { @@ -390,6 +439,7 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } else { throw new UnsupportedOperationException("removed " + removed.getElement() + " vs " + originalElement); } + cleanTheLineOfLeftOverSpace(removedGroup, removed); } @@ -401,9 +451,13 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo // if all elements were already processed there is nothing to do return; } - if (!removedGroup.isProcessed() && removedGroup.getLastElement() == removed && removedGroup.isACompleteLine()) { + + if (!removedGroup.isProcessed() + && removedGroup.getLastElement() == removed + && removedGroup.isACompleteLine()) { Integer lastElementIndex = removedGroup.getLastElementIndex(); Optional indentation = removedGroup.getIndentation(); + if (indentation.isPresent() && !isReplaced(lastElementIndex)) { for (int i = 0; i < indentation.get(); i++) { if (originalElements.get(originalIndex).isSpaceOrTab()) { @@ -416,6 +470,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo } } } + // Mark RemovedGroup as processed removedGroup.processed(); } @@ -427,7 +482,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) { if (originalElement.isComment()) { originalIndex++; - } else if (kept.isChild() && ((CsmChild) kept.getElement()).getChild() instanceof Comment) { + } else if (kept.isChild() && ((CsmChild)kept.getElement()).getChild() instanceof Comment ) { diffIndex++; } else if (kept.isChild() && originalElementIsChild) { diffIndex++; @@ -460,6 +515,7 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea } } else if (kept.isToken() && originalElementIsToken) { TokenTextElement originalTextToken = (TokenTextElement) originalElement; + if (kept.getTokenType() == originalTextToken.getTokenKind()) { originalIndex++; diffIndex++; @@ -491,6 +547,7 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea // Nothing to do, beside considering indentation // However we want to consider the case in which the indentation was not applied, like when we have // just a left brace followed by space + diffIndex++; if (!openBraceWasOnSameLine()) { for (int i = 0; i < STANDARD_INDENTATION_SIZE && originalIndex >= 1 && nodeText.getTextElement(originalIndex - 1).isSpaceOrTab(); i++) { @@ -532,11 +589,9 @@ private boolean isNodeWithTypeArguments(DifferenceElement element) { * @return the number of token to skip in originalElements list */ private int getIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator) { - // number of token to skip - int step = 0; + int step = 0; // number of token to skip Optional next = element.getToken().getNextToken(); - if (!next.isPresent()) - return step; + if (!next.isPresent()) return step; // because there is a token, first we need to increment the number of token to skip step++; // manage nested diamond operators by incrementing the level on LT token and decrementing on GT @@ -576,7 +631,9 @@ private boolean openBraceWasOnSameLine() { } private boolean wasSpaceBetweenBraces() { - return nodeText.getTextElement(originalIndex).isToken(RBRACE) && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); + return nodeText.getTextElement(originalIndex).isToken(RBRACE) + && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) + && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); } private boolean doWeHaveLeftBraceFollowedBySpace(int index) { @@ -597,7 +654,7 @@ private int rewindSpace(int index) { private boolean nextIsRightBrace(int index) { List elements = originalElements.subList(index, originalElements.size()); - for (TextElement element : elements) { + for(TextElement element : elements) { if (!element.isSpaceOrTab()) { return element.isToken(RBRACE); } @@ -607,7 +664,7 @@ private boolean nextIsRightBrace(int index) { private void applyAddedDiffElement(Added added) { if (added.isIndent()) { - for (int i = 0; i < STANDARD_INDENTATION_SIZE; i++) { + for (int i=0;i 0) && originalElements.get(originalIndex - 1).isNewline(); @@ -629,7 +687,9 @@ private void applyAddedDiffElement(Added added) { List elements = processIndentation(indentation, originalElements.subList(0, originalIndex - 1)); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); for (TextElement e : elements) { - if (!nextIsRightBrace && e instanceof TokenTextElement && originalElements.get(originalIndex).isToken(((TokenTextElement) e).getTokenKind())) { + if (!nextIsRightBrace + && e instanceof TokenTextElement + && originalElements.get(originalIndex).isToken(((TokenTextElement)e).getTokenKind())) { originalIndex++; } else { nodeText.addElement(originalIndex++, e); @@ -659,6 +719,7 @@ private void applyAddedDiffElement(Added added) { } } } + if (!used) { // Handling trailing comments boolean sufficientTokensRemainToSkip = nodeText.numberOfElements() > originalIndex + 2; @@ -667,41 +728,37 @@ private void applyAddedDiffElement(Added added) { boolean currentIsNewline = nodeText.getTextElement(originalIndex).isNewline(); boolean isFirstElement = originalIndex == 0; boolean previousIsWhiteSpace = originalIndex > 0 && nodeText.getTextElement(originalIndex - 1).isWhiteSpace(); + if (sufficientTokensRemainToSkip && currentIsAComment) { // Need to get behind the comment: - // FIXME: Why 2? This comment and the next newline? - originalIndex += 2; - // Defer originalIndex increment - nodeText.addElement(originalIndex, addedTextElement); + originalIndex += 2; // FIXME: Why 2? This comment and the next newline? + nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment + // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - // Now we can increment - originalIndex++; + originalIndex++; // Now we can increment } else if (currentIsNewline && previousIsAComment) { /* * Manage the case where we want to add an element, after an expression which is followed by a comment on the same line. * This is not the same case as the one who handles the trailing comments, because in this case the node text element is a new line (not a comment) * For example : {@code private String a; // this is a } */ - // Insert after the new line which follows this comment. - originalIndex++; + originalIndex++; // Insert after the new line which follows this comment. + // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - // Defer originalIndex increment - nodeText.addElement(originalIndex, addedTextElement); - // Now we can increment. - originalIndex++; + nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment + originalIndex++; // Now we can increment. } else if (currentIsNewline && addedTextElement.isChild()) { // here we want to place the new child element after the current new line character. - // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) + // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) // or if the previous character is a space (it could be the case if we want to replace a statement) // Example 1 : if we insert a statement (a duplicated method call expression ) after this one value();\n\n // we want to have this result value();\n value();\n not value();\n \nvalue(); - // Example 2 : if we want to insert a statement after this one \n we want to have value();\n - // not \nvalue(); --> this case appears on member replacement for example + // Example 2 : if we want to insert a statement after this one \n we want to have value();\n + // not \nvalue(); --> this case appears on member replacement for example if (!isPreviousElementNewline && !isFirstElement && !previousIsWhiteSpace) { - // Insert after the new line - originalIndex++; + originalIndex++; // Insert after the new line } nodeText.addElement(originalIndex, addedTextElement); originalIndex++; @@ -710,6 +767,7 @@ private void applyAddedDiffElement(Added added) { originalIndex++; } } + if (addedTextElement.isNewline()) { boolean followedByUnindent = isFollowedByUnindent(diffElements, diffIndex); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); @@ -718,6 +776,7 @@ private void applyAddedDiffElement(Added added) { originalIndex = adjustIndentation(indentation, nodeText, originalIndex, followedByUnindent); } } + diffIndex++; } @@ -727,50 +786,65 @@ private String tokenDescription(int kind) { private Map getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder) { Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); + List nextOrderElements = elementsFromNextOrder.getElements(); List previousOrderElements = elementsFromPreviousOrder.getElements(); WrappingRangeIterator piNext = new WrappingRangeIterator(previousOrderElements.size()); + for (int ni = 0; ni < nextOrderElements.size(); ni++) { boolean found = false; CsmElement ne = nextOrderElements.get(ni); + for (int counter = 0; counter < previousOrderElements.size() && !found; counter++) { Integer pi = piNext.next(); CsmElement pe = previousOrderElements.get(pi); - if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) && DifferenceElementCalculator.matching(ne, pe)) { + if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) + && DifferenceElementCalculator.matching(ne, pe)) { found = true; correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi); } } } + return correspondanceBetweenNextOrderAndPreviousOrder; } private boolean isFollowedByUnindent(List diffElements, int diffIndex) { - return (diffIndex + 1) < diffElements.size() && diffElements.get(diffIndex + 1).isAdded() && diffElements.get(diffIndex + 1).getElement() instanceof CsmUnindent; + return (diffIndex + 1) < diffElements.size() + && diffElements.get(diffIndex + 1).isAdded() + && diffElements.get(diffIndex + 1).getElement() instanceof CsmUnindent; } private List findIndexOfCorrespondingNodeTextElement(List elements, NodeText nodeText, int startIndex, Node node) { List correspondingIndices = new ArrayList<>(); for (ListIterator csmElementListIterator = elements.listIterator(); csmElementListIterator.hasNext(); ) { + int previousCsmElementIndex = csmElementListIterator.previousIndex(); CsmElement csmElement = csmElementListIterator.next(); int nextCsmElementIndex = csmElementListIterator.nextIndex(); + Map potentialMatches = new EnumMap<>(MatchClassification.class); - for (int i = startIndex; i < nodeText.getElements().size(); i++) { + for (int i = startIndex; i < nodeText.getElements().size(); i++){ if (!correspondingIndices.contains(i)) { TextElement textElement = nodeText.getTextElement(i); + boolean isCorresponding = isCorrespondingElement(textElement, csmElement, node); + if (isCorresponding) { boolean hasSamePreviousElement = false; if (i > 0 && previousCsmElementIndex > -1) { TextElement previousTextElement = nodeText.getTextElement(i - 1); + hasSamePreviousElement = isCorrespondingElement(previousTextElement, elements.get(previousCsmElementIndex), node); } + boolean hasSameNextElement = false; if (i < nodeText.getElements().size() - 1 && nextCsmElementIndex < elements.size()) { TextElement nextTextElement = nodeText.getTextElement(i + 1); + hasSameNextElement = isCorrespondingElement(nextTextElement, elements.get(nextCsmElementIndex), node); } + if (hasSamePreviousElement && hasSameNextElement) { potentialMatches.putIfAbsent(MatchClassification.ALL, i); } else if (hasSamePreviousElement) { @@ -785,19 +859,22 @@ private List findIndexOfCorrespondingNodeTextElement(List e } } } + // Prioritize the matches from best to worst - Optional bestMatchKey = potentialMatches.keySet().stream().min(Comparator.comparing(MatchClassification::getPriority)); + Optional bestMatchKey = potentialMatches.keySet().stream() + .min(Comparator.comparing(MatchClassification::getPriority)); + if (bestMatchKey.isPresent()) { correspondingIndices.add(potentialMatches.get(bestMatchKey.get())); } else { correspondingIndices.add(-1); } } + return correspondingIndices; } private enum MatchClassification { - ALL(1), PREVIOUS_AND_SAME(2), NEXT_AND_SAME(3), SAME_ONLY(4), ALMOST(5); private final int priority; @@ -813,20 +890,21 @@ int getPriority() { private boolean isCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) { if (csmElement instanceof CsmToken) { - CsmToken csmToken = (CsmToken) csmElement; + CsmToken csmToken = (CsmToken)csmElement; if (textElement instanceof TokenTextElement) { - TokenTextElement tokenTextElement = (TokenTextElement) textElement; + TokenTextElement tokenTextElement = (TokenTextElement)textElement; return tokenTextElement.getTokenKind() == csmToken.getTokenType() && tokenTextElement.getText().equals(csmToken.getContent(node)); } } else if (csmElement instanceof CsmChild) { - CsmChild csmChild = (CsmChild) csmElement; + CsmChild csmChild = (CsmChild)csmElement; if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement) textElement; + ChildTextElement childTextElement = (ChildTextElement)textElement; return childTextElement.getChild() == csmChild.getChild(); } } else { throw new UnsupportedOperationException(); } + return false; } @@ -834,7 +912,7 @@ private boolean isAlmostCorrespondingElement(TextElement textElement, CsmElement if (isCorrespondingElement(textElement, csmElement, node)) { return false; } - return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken) csmElement).isWhiteSpace(); + return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken)csmElement).isWhiteSpace(); } private int adjustIndentation(List indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) { @@ -845,7 +923,7 @@ private int adjustIndentation(List indentation, NodeText nodeT indentationAdj = indentationAdj.subList(0, Math.max(0, indentationAdj.size() - STANDARD_INDENTATION_SIZE)); } for (TextElement e : indentationAdj) { - if ((nodeTextIndex < nodeText.getElements().size()) && nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { + if ((nodeTextIndex< nodeText.getElements().size()) && nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { nodeTextIndex++; } else { nodeText.getElements().add(nodeTextIndex++, e); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java index 2998317736..8d68a3ea82 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java @@ -18,12 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; public interface DifferenceElement { - static DifferenceElement added(CsmElement element) { return new Added(element); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index 7331c0acff..803119e894 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -18,49 +18,51 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; -import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; +import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; +import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; +import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; +import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - class DifferenceElementCalculator { - + // internally keep track of a node position in a List public static class ChildPositionInfo { - Node node; - Integer position; - ChildPositionInfo(Node node, Integer position) { this.node = node; this.position = position; } - @Override public boolean equals(Object other) { - if (other == null || !(other instanceof ChildPositionInfo)) + if ( other == null || !(other instanceof ChildPositionInfo)) return false; - ChildPositionInfo cpi = (ChildPositionInfo) other; - // verify that the node content and the position are equal + ChildPositionInfo cpi = (ChildPositionInfo)other; + // verify that the node content and the position are equal // because we can have nodes with the same content but in different lines // in this case we consider that nodes are not equals - return this.node.equals(cpi.node) && this.node.getRange().isPresent() && cpi.node.getRange().isPresent() && this.node.getRange().get().contains(cpi.node.getRange().get()); + return this.node.equals(cpi.node) + && this.node.getRange().isPresent() && cpi.node.getRange().isPresent() + && this.node.getRange().get().contains(cpi.node.getRange().get()); } - @Override public int hashCode() { return node.hashCode() + position.hashCode(); } } - + static boolean matching(CsmElement a, CsmElement b) { if (a instanceof CsmChild) { if (b instanceof CsmChild) { @@ -74,7 +76,7 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { @@ -82,8 +84,8 @@ static boolean matching(CsmElement a, CsmElement b) { // Tokens are described by their type AND their content // and TokenContentCalculator. By using .equals(), all // three values are compared. - CsmToken childA = (CsmToken) a; - CsmToken childB = (CsmToken) b; + CsmToken childA = (CsmToken)a; + CsmToken childB = (CsmToken)b; return childA.equals(childB); } else if (b instanceof CsmChild) { return false; @@ -92,14 +94,14 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); } } else if (a instanceof CsmIndent) { return b instanceof CsmIndent; } else if (a instanceof CsmUnindent) { return b instanceof CsmUnindent; } - throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); } private static boolean replacement(CsmElement a, CsmElement b) { @@ -114,18 +116,18 @@ private static boolean replacement(CsmElement a, CsmElement b) { } else if (b instanceof CsmToken) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { - CsmToken childA = (CsmToken) a; - CsmToken childB = (CsmToken) b; + CsmToken childA = (CsmToken)a; + CsmToken childB = (CsmToken)b; return childA.getTokenType() == childB.getTokenType(); } else if (b instanceof CsmChild) { return false; } } - throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); } /** @@ -133,10 +135,10 @@ private static boolean replacement(CsmElement a, CsmElement b) { */ private static List findChildrenPositions(LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel) { List positions = new ArrayList<>(); - for (int i = 0; i < calculatedSyntaxModel.elements.size(); i++) { + for (int i=0;i findChildrenPositions(LexicalDifferenceCa static List calculate(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { // For performance reasons we use the positions of matching children // to guide the calculation of the difference - // + // // Suppose we have: - // qwerty[A]uiop - // qwer[A]uiop - // + // qwerty[A]uiop + // qwer[A]uiop + // // with [A] being a child and lowercase letters being tokens - // + // // We would calculate the Difference between "qwerty" and "qwer" then we know the A is kept, and then we // would calculate the difference between "uiop" and "uiop" + List childrenInOriginal = findChildrenPositions(original); List childrenInAfter = findChildrenPositions(after); + List commonChildren = new ArrayList<>(childrenInOriginal); commonChildren.retainAll(childrenInAfter); + List elements = new LinkedList<>(); + int originalIndex = 0; int afterIndex = 0; int commonChildrenIndex = 0; while (commonChildrenIndex < commonChildren.size()) { ChildPositionInfo child = commonChildren.get(commonChildrenIndex++); // search the position of the node "child" in the original list of cms element - int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); + int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); // search the position of the node "child" in the modified list of cms element - int posOfNextChildInAfter = childrenInAfter.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); + int posOfNextChildInAfter = childrenInAfter.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); + if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) { elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter))); } @@ -179,6 +186,7 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS originalIndex = posOfNextChildInOriginal + 1; afterIndex = posOfNextChildInAfter + 1; } + if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) { elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size()))); } @@ -203,7 +211,8 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, boolean dealtWith = false; if (removedElement instanceof CsmChild) { CsmChild removedChild = (CsmChild) removedElement; - if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { + if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && + removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { NodeText nodeTextForChild = LexicalPreservingPrinter.getOrCreateNodeText(removedChild.getChild()); considerRemoval(nodeTextForChild, elements); originalIndex++; @@ -217,12 +226,16 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, return originalIndex; } - private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { + private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, + LexicalDifferenceCalculator.CalculatedSyntaxModel after) { List elements = new LinkedList<>(); + int originalIndex = 0; int afterIndex = 0; + // We move through the two CalculatedSyntaxModel, moving both forward when we have a match // and moving just one side forward when we have an element kept or removed + do { if (originalIndex < original.elements.size() && afterIndex >= after.elements.size()) { CsmElement removedElement = original.elements.get(originalIndex); @@ -233,12 +246,13 @@ private static List calculateImpl(LexicalDifferenceCalculator } else { CsmElement nextOriginal = original.elements.get(originalIndex); CsmElement nextAfter = after.elements.get(afterIndex); + if ((nextOriginal instanceof CsmMix) && (nextAfter instanceof CsmMix)) { if (((CsmMix) nextAfter).getElements().equals(((CsmMix) nextOriginal).getElements())) { // No reason to deal with a reshuffled, we are just going to keep everything as it is ((CsmMix) nextAfter).getElements().forEach(el -> elements.add(new Kept(el))); } else { - elements.add(new Reshuffled((CsmMix) nextOriginal, (CsmMix) nextAfter)); + elements.add(new Reshuffled((CsmMix)nextOriginal, (CsmMix)nextAfter)); } originalIndex++; afterIndex++; @@ -257,6 +271,7 @@ private static List calculateImpl(LexicalDifferenceCalculator if (cost(addingElements) > 0) { removingElements = calculate(original.from(originalIndex + 1), after.from(afterIndex)); } + if (removingElements == null || cost(removingElements) > cost(addingElements)) { elements.add(new Added(nextAfter)); afterIndex++; @@ -267,6 +282,7 @@ private static List calculateImpl(LexicalDifferenceCalculator } } } while (originalIndex < original.elements.size() || afterIndex < after.elements.size()); + return elements; } @@ -274,6 +290,7 @@ private static long cost(List elements) { return elements.stream().filter(e -> !(e instanceof Kept)).count(); } + /** * Remove from the difference all the elements related to indentation. * This is mainly intended for test purposes. diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java index c1d1a90f21..0f8dfae4e9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.TokenTypes; @@ -28,7 +29,6 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Kept implements DifferenceElement { - private final CsmElement element; Kept(CsmElement element) { @@ -42,11 +42,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Kept kept = (Kept) o; + return element.equals(kept.element); } @@ -65,6 +65,7 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } + throw new IllegalStateException("Kept is not a " + CsmToken.class.getSimpleName()); } @@ -73,35 +74,29 @@ public boolean isAdded() { return false; } - public boolean isIndent() { - return element instanceof CsmIndent; - } + public boolean isIndent() { return element instanceof CsmIndent; } - public boolean isUnindent() { - return element instanceof CsmUnindent; - } + public boolean isUnindent() { return element instanceof CsmUnindent; } - public boolean isToken() { - return element instanceof CsmToken; - } + public boolean isToken() { return element instanceof CsmToken; } - public boolean isChild() { - return element instanceof LexicalDifferenceCalculator.CsmChild; - } + public boolean isChild() { return element instanceof LexicalDifferenceCalculator.CsmChild; } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } + return false; } public boolean isWhiteSpace() { - if (isToken()) { + if(isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } + return false; } @@ -110,14 +105,16 @@ public boolean isWhiteSpaceOrComment() { CsmToken csmToken = (CsmToken) element; return TokenTypes.isWhitespaceOrComment(csmToken.getTokenType()); } + return false; } public boolean isNewLine() { - if (isToken()) { + if(isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } + return false; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java index f989de5a80..0a07dba48f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; @@ -30,13 +31,23 @@ import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.printer.Stringable; +import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.printer.concretesyntaxmodel.*; -import com.github.javaparser.printer.lexicalpreservation.changes.*; +import com.github.javaparser.printer.lexicalpreservation.changes.Change; +import com.github.javaparser.printer.lexicalpreservation.changes.ListAdditionChange; +import com.github.javaparser.printer.lexicalpreservation.changes.ListRemovalChange; +import com.github.javaparser.printer.lexicalpreservation.changes.ListReplacementChange; +import com.github.javaparser.printer.lexicalpreservation.changes.NoChange; +import com.github.javaparser.printer.lexicalpreservation.changes.PropertyChange; import com.github.javaparser.utils.LineSeparator; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; import static com.github.javaparser.TokenTypes.eolTokenKind; @@ -47,7 +58,6 @@ class LexicalDifferenceCalculator { * with no condition, no lists, just tokens and node children. */ static class CalculatedSyntaxModel { - final List elements; CalculatedSyntaxModel(List elements) { @@ -60,7 +70,9 @@ public CalculatedSyntaxModel from(int index) { @Override public String toString() { - return "CalculatedSyntaxModel{" + "elements=" + elements + '}'; + return "CalculatedSyntaxModel{" + + "elements=" + elements + + '}'; } CalculatedSyntaxModel sub(int start, int end) { @@ -73,7 +85,6 @@ void removeIndentationElements() { } static class CsmChild implements CsmElement { - private final Node child; public Node getChild() { @@ -91,16 +102,16 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public String toString() { - return "child(" + child.getClass().getSimpleName() + ")"; + return "child(" + child.getClass().getSimpleName()+")"; } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CsmChild csmChild = (CsmChild) o; + return child.equals(csmChild.child); } @@ -123,10 +134,13 @@ List calculateListAdditionDifference(ObservableProperty obser CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); CalculatedSyntaxModel after = calculatedSyntaxModelAfterListAddition(element, observableProperty, nodeList, index, nodeAdded); + List differenceElements = DifferenceElementCalculator.calculate(original, after); + // Set the line separator character tokens LineSeparator lineSeparator = container.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); replaceEolTokens(differenceElements, lineSeparator); + return differenceElements; } @@ -181,10 +195,10 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List nodeList; if (rawValue instanceof Optional) { - Optional optional = (Optional) rawValue; + Optional optional = (Optional)rawValue; if (optional.isPresent()) { if (!(optional.get() instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + optional.get().getClass().getCanonicalName()); @@ -242,6 +256,7 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List collection = (Collection) change.getValue(csmList.getProperty(), node); if (!collection.isEmpty()) { calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change); + boolean first = true; for (Iterator it = collection.iterator(); it.hasNext(); ) { if (!first) { @@ -256,7 +272,7 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List mixElements = new LinkedList<>(); csmMix.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, mixElements, change)); elements.add(new CsmMix(mixElements)); } else if (csm instanceof CsmChild) { elements.add(csm); } else { - throw new UnsupportedOperationException(csm.getClass().getSimpleName() + " " + csm); + throw new UnsupportedOperationException(csm.getClass().getSimpleName()+ " " + csm); } } public static int toToken(Modifier modifier) { - switch(modifier.getKeyword()) { + switch (modifier.getKeyword()) { case PUBLIC: return GeneratedJavaParserConstants.PUBLIC; case PRIVATE: @@ -355,9 +377,10 @@ public static int toToken(Modifier modifier) { } } - // / - // / Methods that calculate CalculatedSyntaxModel - // / + /// + /// Methods that calculate CalculatedSyntaxModel + /// + // Visible for testing CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(Node node, ObservableProperty property, Object oldValue, Object newValue) { return calculatedSyntaxModelAfterPropertyChange(ConcreteSyntaxModel.forClass(node.getClass()), node, property, oldValue, newValue); @@ -393,7 +416,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(Node container, Obs if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList) rawValue; + NodeList nodeList = (NodeList)rawValue; return calculatedSyntaxModelAfterListAddition(csm, observableProperty, nodeList, index, nodeAdded); } @@ -404,7 +427,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(Node container, Obse if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList) rawValue; + NodeList nodeList = (NodeList)rawValue; return calculatedSyntaxModelAfterListRemoval(csm, observableProperty, nodeList, index); } @@ -415,4 +438,5 @@ private CalculatedSyntaxModel calculatedSyntaxModelAfterListReplacement(CsmEleme calculatedSyntaxModelForNode(csm, container, elements, new ListReplacementChange(observableProperty, index, newValue)); return new CalculatedSyntaxModel(elements); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index e29341d9a9..f254be3175 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -18,8 +18,30 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static com.github.javaparser.utils.Utils.decapitalize; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + import com.github.javaparser.JavaToken; import com.github.javaparser.Range; import com.github.javaparser.ast.DataKey; @@ -38,25 +60,14 @@ import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.visitor.TreeVisitor; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; +import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; +import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; +import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; +import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; import com.github.javaparser.utils.LineSeparator; import com.github.javaparser.utils.Pair; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.util.*; - -import static com.github.javaparser.GeneratedJavaParserConstants.*; -import static com.github.javaparser.TokenTypes.eolTokenKind; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.decapitalize; -import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; - /** * A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when * operating on the AST and then used them to reproduce the source code @@ -74,9 +85,10 @@ public class LexicalPreservingPrinter { private static final LexicalDifferenceCalculator LEXICAL_DIFFERENCE_CALCULATOR = new LexicalDifferenceCalculator(); - // + // // Factory methods - // + // + /** * Prepares the node so it can be used in the print methods. * The correct order is: @@ -91,9 +103,11 @@ public class LexicalPreservingPrinter { */ public static N setup(N node) { assertNotNull(node); + if (observer == null) { observer = createObserver(); } + node.getTokenRange().ifPresent(r -> { storeInitialText(node); // Setup observer @@ -104,9 +118,10 @@ public static N setup(N node) { return node; } - // + // // Constructor and setup - // + // + private static AstObserver createObserver() { return new LexicalPreservingPrinter.Observer(); } @@ -124,13 +139,20 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } if (property == ObservableProperty.COMMENT) { Optional parentNode = observedNode.getParentNode(); - NodeText nodeText = parentNode.map(parent -> getOrCreateNodeText(parentNode.get())).orElse(getOrCreateNodeText(observedNode)); + NodeText nodeText = parentNode + .map(parent -> getOrCreateNodeText(parentNode.get())) + // We're at the root node. + .orElse(getOrCreateNodeText(observedNode)); + if (oldValue == null) { - int index = parentNode.isPresent() ? // Find the position of the comment node and put in front of it the [...] - nodeText.findChild(observedNode) : // - 0; + int index = parentNode.isPresent() ? + // Find the position of the comment node and put in front of it the [...] + nodeText.findChild(observedNode) : + // + 0; // Add the same indent depth of the comment to the following node fixIndentOfMovedNode(nodeText, index); + LineSeparator lineSeparator = observedNode.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); nodeText.addElement(index, makeCommentToken((Comment) newValue)); nodeText.addToken(index + 1, eolTokenKind(lineSeparator), lineSeparator.asRawString()); @@ -149,18 +171,22 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } } else { List matchingTokens = findTokenTextElementForComment((Comment) oldValue, nodeText); + if (matchingTokens.size() != 1) { throw new IllegalStateException("The matching comment to be replaced could not be found"); } + Comment newComment = (Comment) newValue; TokenTextElement matchingElement = matchingTokens.get(0); nodeText.replace(matchingElement.and(matchingElement.matchByRange()), makeCommentToken(newComment)); } } NodeText nodeText = getOrCreateNodeText(observedNode); + if (nodeText == null) { throw new NullPointerException(observedNode.getClass().getSimpleName()); } + LEXICAL_DIFFERENCE_CALCULATOR.calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue); } @@ -175,10 +201,12 @@ private TokenTextElement makeCommentToken(Comment newComment) { return new TokenTextElement(MULTI_LINE_COMMENT, "/*" + newComment.getContent() + "*/"); } throw new UnsupportedOperationException("Unknown type of comment: " + newComment.getClass().getSimpleName()); + } private int getIndexOfComment(Comment oldValue, NodeText nodeText) { List matchingTokens = findTokenTextElementForComment(oldValue, nodeText); + if (!matchingTokens.isEmpty()) { TextElement matchingElement = matchingTokens.get(0); return nodeText.findElement(matchingElement.and(matchingElement.matchByRange())); @@ -191,30 +219,58 @@ private int getIndexOfComment(Comment oldValue, NodeText nodeText) { private List findChildTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingChildElements; - matchingChildElements = nodeText.getElements().stream().filter(e -> e.isChild()).map(c -> (ChildTextElement) c).filter(c -> c.isComment()).filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())).collect(toList()); + + matchingChildElements = nodeText.getElements().stream() + .filter(e -> e.isChild()) + .map(c -> (ChildTextElement) c) + .filter(c -> c.isComment()) + .filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())) + .collect(toList()); + if (matchingChildElements.size() > 1) { // Duplicate child nodes found, refine the result - matchingChildElements = matchingChildElements.stream().filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())).collect(toList()); + matchingChildElements = matchingChildElements.stream() + .filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())) + .collect(toList()); } + if (matchingChildElements.size() != 1) { throw new IllegalStateException("The matching child text element for the comment to be removed could not be found."); } + return matchingChildElements; } private List findTokenTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingTokens; + if (oldValue instanceof JavadocComment) { - matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")).collect(toList()); + matchingTokens = nodeText.getElements().stream() + .filter(e -> e.isToken(JAVADOC_COMMENT)) + .map(e -> (TokenTextElement) e) + .filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")) + .collect(toList()); } else if (oldValue instanceof BlockComment) { - matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(MULTI_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")).collect(toList()); + matchingTokens = nodeText.getElements().stream() + .filter(e -> e.isToken(MULTI_LINE_COMMENT)) + .map(e -> (TokenTextElement) e) + .filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")) + .collect(toList()); } else { - matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(SINGLE_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())).collect(toList()); + matchingTokens = nodeText.getElements().stream() + .filter(e -> e.isToken(SINGLE_LINE_COMMENT)) + .map(e -> (TokenTextElement) e) + .filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())) + .collect(toList()); } + if (matchingTokens.size() > 1) { // Duplicate comments found, refine the result - matchingTokens = matchingTokens.stream().filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())).collect(toList()); + matchingTokens = matchingTokens.stream() + .filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())) + .collect(toList()); } + return matchingTokens; } @@ -222,6 +278,7 @@ private boolean isEqualRange(Optional range1, Optional range2) { if (range1.isPresent() && range2.isPresent()) { return range1.get().equals(range2.get()); } + return false; } @@ -236,6 +293,7 @@ private void fixIndentOfMovedNode(NodeText nodeText, int index) { if (index <= 0) { return; } + for (int i = index - 1; i >= 0; i--) { TextElement spaceCandidate = nodeText.getTextElement(i); if (!spaceCandidate.isSpaceOrTab()) { @@ -260,6 +318,7 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int } else { throw new UnsupportedOperationException(); } + Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -268,6 +327,7 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int public void concreteListReplacement(NodeList changedList, int index, Node oldValue, Node newValue) { NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren()); List differenceElements = LEXICAL_DIFFERENCE_CALCULATOR.calculateListReplacementDifference(findNodeListName(changedList), changedList, index, newValue); + Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -275,6 +335,7 @@ public void concreteListReplacement(NodeList changedList, int index, Node old private static void storeInitialText(Node root) { Map> tokensByNode = new IdentityHashMap<>(); + // We go over tokens and find to which nodes they belong. Note that we do not traverse the tokens as they were // on a list but as they were organized in a tree. At each time we select only the branch corresponding to the // range of interest and ignore all other branches @@ -287,9 +348,9 @@ private static void storeInitialText(Node root) { } tokensByNode.get(owner).add(token); } + // Now that we know the tokens we use them to create the initial NodeText for each node new TreeVisitor() { - @Override public void process(Node node) { if (!node.isPhantom()) { @@ -304,12 +365,13 @@ private static Optional findNodeForToken(Node node, Range tokenRange) { if (node.isPhantom()) { return Optional.empty(); } - if (!node.getRange().isPresent()) { + if(!node.getRange().isPresent()) { return Optional.empty(); } if (!node.getRange().get().contains(tokenRange)) { return Optional.empty(); } + for (Node child : node.getChildNodes()) { Optional found = findNodeForToken(child, tokenRange); if (found.isPresent()) { @@ -339,30 +401,38 @@ private static void storeInitialTextForOneNode(Node node, List nodeTo node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(toList()))); } - // + // // Iterators - // + // + private static Iterator tokensPreceeding(final Node node) { if (!node.getParentNode().isPresent()) { return new TextElementIteratorsFactory.EmptyIterator<>(); } // There is the awfully painful case of the fake types involved in variable declarators and // fields or variable declaration that are, of course, an exception... + NodeText parentNodeText = getOrCreateNodeText(node.getParentNode().get()); int index = parentNodeText.tryToFindChild(node); if (index == NodeText.NOT_FOUND) { if (node.getParentNode().get() instanceof VariableDeclarator) { return tokensPreceeding(node.getParentNode().get()); } else { - throw new IllegalArgumentException(String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", node, node.getParentNode().get(), parentNodeText)); + throw new IllegalArgumentException( + String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", + node, node.getParentNode().get(), parentNodeText)); } } - return new TextElementIteratorsFactory.CascadingIterator<>(TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), () -> tokensPreceeding(node.getParentNode().get())); + + return new TextElementIteratorsFactory.CascadingIterator<>( + TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), + () -> tokensPreceeding(node.getParentNode().get())); } - // + // // Printing methods - // + // + /** * Print a Node into a String, preserving the lexical information. */ @@ -387,13 +457,14 @@ public static void print(Node node, Writer writer) throws IOException { writer.append(text.expand()); } - // + // // Methods to handle transformations - // + // + private static void prettyPrintingTextNode(Node node, NodeText nodeText) { if (node instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) node; - switch(primitiveType.getType()) { + switch (primitiveType.getType()) { case BOOLEAN: nodeText.addToken(BOOLEAN, node.toString()); break; @@ -440,6 +511,7 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { nodeText.addToken(LexicalDifferenceCalculator.toToken(modifier), modifier.getKeyword().asString()); return; } + interpret(node, ConcreteSyntaxModel.forClass(node.getClass()), nodeText); } @@ -448,12 +520,15 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { */ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) { LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(csm, node); + List indentation = findIndentation(node); + boolean pendingIndentation = false; for (CsmElement element : calculatedSyntaxModel.elements) { if (element instanceof CsmIndent) { int indexCurrentElement = calculatedSyntaxModel.elements.indexOf(element); - if (calculatedSyntaxModel.elements.size() > indexCurrentElement && !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { + if (calculatedSyntaxModel.elements.size() > indexCurrentElement && + !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { for (int i = 0; i < Difference.STANDARD_INDENTATION_SIZE; i++) { indentation.add(new TokenTextElement(SPACE, " ")); } @@ -463,9 +538,11 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) indentation.remove(indentation.size() - 1); } } + if (pendingIndentation && !(element instanceof CsmToken && ((CsmToken) element).isNewLine())) { indentation.forEach(nodeText::addElement); } + pendingIndentation = false; if (element instanceof LexicalDifferenceCalculator.CsmChild) { nodeText.addChild(((LexicalDifferenceCalculator.CsmChild) element).getChild()); @@ -490,13 +567,15 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) // so they have to be handled in a special way if (node instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) node; - variableDeclarator.getParentNode().ifPresent(parent -> ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { - int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); - for (int i = 0; i < extraArrayLevels; i++) { - nodeText.addElement(new TokenTextElement(LBRACKET)); - nodeText.addElement(new TokenTextElement(RBRACKET)); - } - })); + variableDeclarator.getParentNode().ifPresent(parent -> + ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { + int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); + for (int i = 0; i < extraArrayLevels; i++) { + nodeText.addElement(new TokenTextElement(LBRACKET)); + nodeText.addElement(new TokenTextElement(RBRACKET)); + } + }) + ); } return nodeText; } @@ -517,7 +596,8 @@ static List findIndentation(Node node) { Iterator it = tokensPreceeding(node); while (it.hasNext()) { TokenTextElement tte = it.next(); - if (tte.getTokenKind() == SINGLE_LINE_COMMENT || tte.isNewline()) { + if (tte.getTokenKind() == SINGLE_LINE_COMMENT + || tte.isNewline()) { break; } else { followingNewlines.add(tte); @@ -532,9 +612,10 @@ static List findIndentation(Node node) { return followingNewlines; } - // + // // Helper methods - // + // + private static boolean isReturningOptionalNodeList(Method m) { if (!m.getReturnType().getCanonicalName().equals(Optional.class.getCanonicalName())) { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java index 2b2688ee91..5c20e9e49b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -30,14 +31,14 @@ * It is basically a list of tokens and children. */ class NodeText { - private final List elements; public static final int NOT_FOUND = -1; - // + // // Constructors - // + // + NodeText(List elements) { this.elements = elements; } @@ -49,9 +50,10 @@ class NodeText { this(new LinkedList<>()); } - // + // // Adding elements - // + // + /** * Add an element at the end. */ @@ -82,9 +84,10 @@ void addToken(int index, int tokenKind, String text) { elements.add(index, new TokenTextElement(tokenKind, text)); } - // + // // Finding elements - // + // + int findElement(TextElementMatcher matcher) { return findElement(matcher, 0); } @@ -92,7 +95,8 @@ int findElement(TextElementMatcher matcher) { int findElement(TextElementMatcher matcher, int from) { int res = tryToFindElement(matcher, from); if (res == NOT_FOUND) { - throw new IllegalArgumentException(String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); + throw new IllegalArgumentException( + String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); } return res; } @@ -123,9 +127,10 @@ int tryToFindChild(Node child, int from) { return tryToFindElement(TextElementMatchers.byNode(child), from); } - // + // // Removing single elements - // + // + public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhitespace) { int i = 0; for (TextElement e : elements) { @@ -146,30 +151,34 @@ public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhite throw new IllegalArgumentException(); } - // + // // Removing sequences - // + // + void removeElement(int index) { elements.remove(index); } - // + // // Replacing elements - // + // + void replace(TextElementMatcher position, TextElement newElement) { int index = findElement(position, 0); elements.remove(index); elements.add(index, newElement); } - // + // // Other methods - // + // + /** * Generate the corresponding string. */ String expand() { StringBuffer sb = new StringBuffer(); + elements.forEach(e -> sb.append(e.expand())); return sb.toString(); } @@ -193,4 +202,5 @@ List getElements() { public String toString() { return "NodeText{" + elements + '}'; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java index db39520a50..380d6c290e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java @@ -18,17 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.observer.AstObserver; -import com.github.javaparser.ast.observer.AstObserverAdapter; -import com.github.javaparser.ast.type.UnknownType; +import static java.util.Collections.synchronizedMap; import java.util.IdentityHashMap; import java.util.Map; -import static java.util.Collections.synchronizedMap; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.AstObserver; +import com.github.javaparser.ast.observer.AstObserverAdapter; +import com.github.javaparser.ast.type.UnknownType; /** * We want to recognize and ignore "phantom" nodes, like the fake type of variable in FieldDeclaration @@ -42,7 +43,6 @@ public class PhantomNodeLogic { private static final Map isPhantomNodeCache = synchronizedMap(new IdentityHashMap<>()); private static final AstObserver cacheCleaner = new AstObserverAdapter() { - @Override public void parentChange(Node observedNode, Node previousParent, Node newParent) { isPhantomNodeCache.remove(observedNode); @@ -56,7 +56,11 @@ static boolean isPhantomNode(Node node) { if (node instanceof UnknownType) { return true; } - boolean res = (node.getParentNode().isPresent() && node.getParentNode().get().hasRange() && node.hasRange() && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) || inPhantomNode(node, LEVELS_TO_EXPLORE)); + boolean res = (node.getParentNode().isPresent() + && node.getParentNode().get().hasRange() + && node.hasRange() + && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) + || inPhantomNode(node, LEVELS_TO_EXPLORE)); isPhantomNodeCache.put(node, res); node.register(cacheCleaner); return res; @@ -67,7 +71,9 @@ static boolean isPhantomNode(Node node) { * A node contained in a phantom node is also a phantom node. We limit how many levels up we check just for performance reasons. */ private static boolean inPhantomNode(Node node, int levels) { - return node.getParentNode().isPresent() && (isPhantomNode(node.getParentNode().get()) || inPhantomNode(node.getParentNode().get(), levels - 1)); + return node.getParentNode().isPresent() && + (isPhantomNode(node.getParentNode().get()) + || inPhantomNode(node.getParentNode().get(), levels - 1)); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java index b33c4b3bb3..bf8edd0406 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -26,7 +27,6 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; public class Removed implements DifferenceElement { - private final CsmElement element; Removed(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Removed removed = (Removed) o; + return element.equals(removed.element); } @@ -63,6 +63,7 @@ public Node getChild() { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild(); } + throw new IllegalStateException("Removed is not a " + LexicalDifferenceCalculator.CsmChild.class.getSimpleName()); } @@ -71,6 +72,7 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } + throw new IllegalStateException("Removed is not a " + CsmToken.class.getSimpleName()); } @@ -79,27 +81,25 @@ public boolean isAdded() { return false; } - public boolean isToken() { - return element instanceof CsmToken; - } + public boolean isToken() { return element instanceof CsmToken; } - public boolean isChild() { - return element instanceof LexicalDifferenceCalculator.CsmChild; - } + public boolean isChild() { return element instanceof LexicalDifferenceCalculator.CsmChild; } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } + return false; } public boolean isWhiteSpace() { - if (isToken()) { + if(isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } + return false; } @@ -107,12 +107,13 @@ public boolean isWhiteSpace() { public boolean isRemoved() { return true; } - + public boolean isNewLine() { - if (isToken()) { + if(isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } + return false; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java index 7c84ce0bea..a616ba0ff7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.JavaToken; @@ -47,7 +48,6 @@ final class RemovedGroup implements Iterable { private final Integer firstElementIndex; - private final List removedList; private boolean isProcessed = false; @@ -56,9 +56,11 @@ private RemovedGroup(Integer firstElementIndex, List removedList) { if (firstElementIndex == null) { throw new IllegalArgumentException("firstElementIndex should not be null"); } + if (removedList == null || removedList.isEmpty()) { throw new IllegalArgumentException("removedList should not be null or empty"); } + this.firstElementIndex = firstElementIndex; this.removedList = removedList; } @@ -92,7 +94,9 @@ final boolean isProcessed() { } private List getIndicesBeingRemoved() { - return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()).boxed().collect(Collectors.toList()); + return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()) + .boxed() + .collect(Collectors.toList()); } /** @@ -137,15 +141,13 @@ final Removed getLastElement() { * @return true if the RemovedGroup equates to a complete line */ final boolean isACompleteLine() { - return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); + return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) + && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); } private final Function hasOnlyWhitespaceJavaTokenInFrontFunction = begin -> hasOnlyWhiteSpaceForTokenFunction(begin, token -> token.getPreviousToken()); - private final Function hasOnlyWhitespaceJavaTokenBehindFunction = end -> hasOnlyWhiteSpaceForTokenFunction(end, token -> token.getNextToken()); - private final Function hasOnlyWhitespaceInFrontFunction = tokenRange -> hasOnlyWhitespaceJavaTokenInFrontFunction.apply(tokenRange.getBegin()); - private final Function hasOnlyWhitespaceBehindFunction = tokenRange -> hasOnlyWhitespaceJavaTokenBehindFunction.apply(tokenRange.getEnd()); private boolean hasOnlyWhitespace(Removed startElement, Function hasOnlyWhitespaceFunction) { @@ -153,6 +155,7 @@ private boolean hasOnlyWhitespace(Removed startElement, Function tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { hasOnlyWhitespace = hasOnlyWhitespaceFunction.apply(tokenRange.get()); @@ -168,6 +171,7 @@ private boolean hasOnlyWhitespace(Removed startElement, Function> tokenFunction) { Optional tokenResult = tokenFunction.apply(token); + if (tokenResult.isPresent()) { if (TokenTypes.isWhitespaceButNotEndOfLine(tokenResult.get().getKind())) { return hasOnlyWhiteSpaceForTokenFunction(tokenResult.get(), tokenFunction); @@ -177,6 +181,7 @@ private boolean hasOnlyWhiteSpaceForTokenFunction(JavaToken token, Function getIndentation() { Removed firstElement = getFirstElement(); + int indentation = 0; if (firstElement.isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) firstElement.getElement(); Node child = csmChild.getChild(); + Optional tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { JavaToken begin = tokenRange.get().getBegin(); + if (hasOnlyWhitespaceJavaTokenInFrontFunction.apply(begin)) { Optional previousToken = begin.getPreviousToken(); - while (previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { + + while(previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { indentation++; + previousToken = previousToken.get().getPreviousToken(); } + if (previousToken.isPresent()) { if (TokenTypes.isEndOfLineToken(previousToken.get().getKind())) { return Optional.of(Integer.valueOf(indentation)); @@ -213,13 +224,13 @@ final Optional getIndentation() { } } } + return Optional.empty(); } @Override public final Iterator iterator() { return new Iterator() { - private int currentIndex = 0; @Override @@ -231,6 +242,7 @@ public boolean hasNext() { public Removed next() { return removedList.get(currentIndex++); } + }; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java index 8b07c5c4a7..b888c6fe4c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; @@ -27,9 +28,7 @@ * some new elements have been added or removed to the mix. */ public class Reshuffled implements DifferenceElement { - private final CsmMix previousOrder; - private final CsmMix nextOrder; Reshuffled(CsmMix previousOrder, CsmMix nextOrder) { @@ -39,18 +38,17 @@ public class Reshuffled implements DifferenceElement { @Override public String toString() { - return "Reshuffled{" + nextOrder + ", previous=" + previousOrder + '}'; + return "Reshuffled{" + nextOrder + ", previous="+ previousOrder+ '}'; } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Reshuffled that = (Reshuffled) o; - if (!previousOrder.equals(that.previousOrder)) - return false; + + if (!previousOrder.equals(that.previousOrder)) return false; return nextOrder.equals(that.nextOrder); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java index 215f94ad00..64d8f73853 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; @@ -33,7 +34,9 @@ public abstract class TextElement implements TextElementMatcher { abstract boolean isToken(int tokenKind); final boolean isCommentToken() { - return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); + return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) + || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) + || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); } @Override @@ -82,6 +85,11 @@ public boolean isChild() { * @return TextElementMatcher that matches any TextElement with the same Range */ TextElementMatcher matchByRange() { - return (TextElement textElement) -> getRange().flatMap(r1 -> textElement.getRange().map(r1::equals)).orElse(true); + return (TextElement textElement) -> + getRange() + .flatMap(r1 -> textElement.getRange() + .map(r1::equals)) + // We're missing range information. This may happen when a node is manually instantiated. Don't be too harsh on that: + .orElse(true); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java index a6572a3524..59fa9921d8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; @@ -27,20 +28,14 @@ class TextElementIteratorsFactory { static class CascadingIterator implements Iterator { - interface Provider { - Iterator provide(); } private final Provider nextProvider; - private Iterator current; - private Iterator next; - private boolean lastReturnedFromCurrent = false; - private boolean lastReturnedFromNext = false; public CascadingIterator(Iterator current, Provider nextProvider) { @@ -48,6 +43,7 @@ public CascadingIterator(Iterator current, Provider nextProvider) { this.current = current; } + @Override public boolean hasNext() { if (current.hasNext()) { @@ -89,7 +85,6 @@ public void remove() { } static class EmptyIterator implements Iterator { - @Override public boolean hasNext() { return false; @@ -102,9 +97,7 @@ public E next() { } private static class SingleElementIterator implements Iterator { - private final E element; - private boolean returned; SingleElementIterator(E element) { @@ -124,13 +117,12 @@ public E next() { @Override public void remove() { + } } static class ComposedIterator implements Iterator { - private final List> elements; - private int currIndex; ComposedIterator(List> elements) { @@ -143,7 +135,7 @@ public boolean hasNext() { if (currIndex >= elements.size()) { return false; } - if (elements.get(currIndex).hasNext()) { + if (elements.get(currIndex).hasNext()){ return true; } currIndex++; @@ -167,15 +159,14 @@ public void remove() { private static Iterator reverseIterator(NodeText nodeText, int index) { TextElement textElement = nodeText.getTextElement(index); if (textElement instanceof TokenTextElement) { - return new SingleElementIterator((TokenTextElement) textElement) { - + return new SingleElementIterator((TokenTextElement)textElement) { @Override public void remove() { nodeText.removeElement(index); } }; } else if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement) textElement; + ChildTextElement childTextElement = (ChildTextElement)textElement; NodeText textForChild = childTextElement.getNodeTextForWrappedNode(); return reverseIterator(textForChild); } else { @@ -189,9 +180,10 @@ public static Iterator reverseIterator(NodeText nodeText) { public static Iterator partialReverseIterator(NodeText nodeText, int fromIndex) { List> elements = new LinkedList<>(); - for (int i = fromIndex; i >= 0; i--) { + for (int i=fromIndex;i>=0;i--) { elements.add(reverseIterator(nodeText, i)); } return new ComposedIterator<>(elements); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java index 23df186259..09c0e48db6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; public interface TextElementMatcher { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java index 543123f9ca..7e07371f9c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -30,7 +31,6 @@ static TextElementMatcher byTokenType(int tokenType) { static TextElementMatcher byNode(final Node node) { return new TextElementMatcher() { - @Override public boolean match(TextElement textElement) { return textElement.isNode(node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java index ab7334b655..d3714adcc8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java @@ -18,17 +18,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.JavaToken; -import com.github.javaparser.JavaToken.Kind; import com.github.javaparser.Range; +import com.github.javaparser.JavaToken.Kind; import com.github.javaparser.ast.Node; import java.util.Optional; class TokenTextElement extends TextElement { - private final JavaToken token; TokenTextElement(JavaToken token) { @@ -63,11 +63,11 @@ public JavaToken getToken() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TokenTextElement that = (TokenTextElement) o; + return token.equals(that.token); } @@ -105,7 +105,7 @@ public boolean isSpaceOrTab() { public boolean isComment() { return token.getCategory().isComment(); } - + @Override public boolean isSeparator() { return token.getCategory().isSeparator(); @@ -120,7 +120,7 @@ public boolean isNewline() { public boolean isChildOfClass(Class nodeClass) { return false; } - + @Override public boolean isIdentifier() { return getToken().getCategory().isIdentifier(); @@ -130,7 +130,7 @@ public boolean isIdentifier() { public boolean isLiteral() { return getToken().getCategory().isLiteral(); } - + @Override public boolean isPrimitive() { return Kind.valueOf(getTokenKind()).isPrimitive(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java index ce1d9cc2d4..24e3b415f1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java @@ -18,14 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; public class WrappingRangeIterator implements Iterator { - private final int limit; - private int currentValue = 0; public WrappingRangeIterator(int limit) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java index 7a74f31460..12e2ee8762 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -31,7 +32,7 @@ public interface Change { default boolean evaluate(CsmConditional csmConditional, Node node) { - switch(csmConditional.getCondition()) { + switch (csmConditional.getCondition()) { case FLAG: return csmConditional.getProperties().stream().anyMatch(p -> (Boolean) getValue(p, node)); case IS_NOT_EMPTY: diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java index 0474d52311..63a0249832 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -32,9 +33,7 @@ public class ListAdditionChange implements Change { private final ObservableProperty observableProperty; - private final int index; - private final Node nodeAdded; public ListAdditionChange(ObservableProperty observableProperty, int index, Node nodeAdded) { @@ -55,12 +54,15 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; + // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); + // Perform modification -- add to the list newNodeList.add(index, nodeAdded); + return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java index 961b296195..26f19af227 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -32,7 +33,6 @@ public class ListRemovalChange implements Change { private final ObservableProperty observableProperty; - private final int index; public ListRemovalChange(ObservableProperty observableProperty, int index) { @@ -52,13 +52,15 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; + // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); - // fix #2187 set the parent node in the new list - newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); + newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); // fix #2187 set the parent node in the new list newNodeList.addAll(currentNodeList); + // Perform modification -- remove an item from the list newNodeList.remove(index); + return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java index 94f172bc76..b84c3cefc6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -32,9 +33,7 @@ public class ListReplacementChange implements Change { private final ObservableProperty observableProperty; - private final int index; - private final Node newValue; public ListReplacementChange(ObservableProperty observableProperty, int index, Node newValue) { @@ -55,12 +54,15 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; + // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); + // Perform modification -- replace an item in the list newNodeList.set(index, newValue); + return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java index b19088d1ba..ef0336af9d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java index 7d941bb39f..4b10893cf5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -29,9 +30,7 @@ public class PropertyChange implements Change { private final ObservableProperty property; - private final Object oldValue; - private final Object newValue; public PropertyChange(ObservableProperty property, Object oldValue, Object newValue) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java index 2258416034..025ad44e75 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution; /** @@ -33,4 +34,5 @@ public class MethodAmbiguityException extends RuntimeException { public MethodAmbiguityException(String description) { super(description); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java index c4ced2145d..5f64cdc10c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -27,6 +28,7 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; + import java.util.*; /** @@ -36,15 +38,10 @@ * @author Federico Tomassetti */ public class MethodUsage implements ResolvedTypeParametrized { - private ResolvedMethodDeclaration declaration; - private List paramTypes = new ArrayList<>(); - private List exceptionTypes = new ArrayList<>(); - private ResolvedType returnType; - private ResolvedTypeParametersMap typeParametersMap; public MethodUsage(ResolvedMethodDeclaration declaration) { @@ -59,15 +56,19 @@ public MethodUsage(ResolvedMethodDeclaration declaration) { returnType = declaration.getReturnType(); } - public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType) { - this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), ResolvedTypeParametersMap.empty()); + public MethodUsage(ResolvedMethodDeclaration declaration, + List paramTypes, ResolvedType returnType) { + this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), + ResolvedTypeParametersMap.empty()); } - public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes) { + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, + List exceptionTypes) { this(declaration, paramTypes, returnType, exceptionTypes, ResolvedTypeParametersMap.empty()); } - private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { + private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, + List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { this.declaration = declaration; this.paramTypes = paramTypes; this.returnType = returnType; @@ -77,7 +78,10 @@ private MethodUsage(ResolvedMethodDeclaration declaration, List pa @Override public String toString() { - return "MethodUsage{" + "declaration=" + declaration + ", paramTypes=" + paramTypes + '}'; + return "MethodUsage{" + + "declaration=" + declaration + + ", paramTypes=" + paramTypes + + '}'; } public ResolvedMethodDeclaration getDeclaration() { @@ -150,8 +154,11 @@ public MethodUsage replaceTypeParameter(ResolvedTypeParameterDeclaration typePar if (type == null) { throw new IllegalArgumentException(); } + // TODO if the method declaration has a type param with that name ignore this call - MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, typeParametersMap.toBuilder().setValue(typeParameter, type).build()); + MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, + typeParametersMap.toBuilder().setValue(typeParameter, type).build()); + Map inferredTypes = new HashMap<>(); for (int i = 0; i < paramTypes.size(); i++) { ResolvedType originalParamType = paramTypes.get(i); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java index 89796b434c..3ab14c955b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java @@ -18,9 +18,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution; public interface Resolvable { - T resolve(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java index 97550cf0ad..ee77248581 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution; import com.github.javaparser.ast.Node; @@ -26,7 +27,6 @@ import com.github.javaparser.resolution.types.ResolvedType; public interface SymbolResolver { - /** * For a reference it would find the corresponding * declaration. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java index 6b0fc1b02b..b42c504fa8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution; /** @@ -69,6 +70,10 @@ public String getName() { @Override public String toString() { - return "UnsolvedSymbolException{" + "context='" + context + "'" + ", name='" + name + "'" + ", cause='" + cause + "'" + "}"; + return "UnsolvedSymbolException{" + + "context='" + context + "'" + + ", name='" + name + "'" + + ", cause='" + cause + "'" + + "}"; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java index 049436c0ea..f71d9a2236 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java index e236da7f63..8cb38c41ce 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.AccessSpecifier; @@ -34,4 +35,5 @@ public interface HasAccessSpecifier { * The access specifier of this element. */ AccessSpecifier accessSpecifier(); + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java index 930fc06454..8d6c55d1f7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.AnnotationDeclaration; @@ -27,7 +28,8 @@ /** * @author Federico Tomassetti */ -public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, AssociableToAST { +public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, + AssociableToAST { List getAnnotationMembers(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java index 93e8a02893..1e30f166ac 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.expr.Expression; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java index 61da9aaa9b..bf336f9241 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; @@ -34,7 +35,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { /** * This method should always return true. @@ -75,13 +77,15 @@ default boolean isClass() { */ List getAllInterfaces(); - // / - // / Constructors - // / + /// + /// Constructors + /// + /** * List of constructors available for the class. * This list should also include the default constructor. */ @Override List getConstructors(); + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java index e95f5c5de5..5959f1f835 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ConstructorDeclaration; @@ -27,7 +28,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, AssociableToAST { +public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, + AssociableToAST { /** * A constructor can be declared in a class or an enum. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java index 69ceadfb5b..53913aa349 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java index 2740f064a6..ac474c602a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java index 4ba91b0bf0..4c5e0be0d9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import java.util.List; @@ -27,7 +28,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, HasAccessSpecifier { +public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, + HasAccessSpecifier { @Override default boolean isEnum() { @@ -46,6 +48,7 @@ default boolean hasEnumConstant(String name) { } default ResolvedEnumConstantDeclaration getEnumConstant(final String name) { - return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst().orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); + return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst() + .orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java index 3da467f7da..ded5dcd459 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.FieldDeclaration; @@ -48,4 +49,5 @@ default ResolvedFieldDeclaration asField() { * The type on which this field has been declared */ ResolvedTypeDeclaration declaringType(); + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java index f218d605ac..5cc22165d9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -31,7 +32,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { @Override default boolean isInterface() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java index 0071bd14ab..3fc3d801b7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.MethodDeclaration; @@ -50,4 +51,5 @@ public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration * Is this method static? */ boolean isStatic(); + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java index d964f7d517..86c5398875 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.types.ResolvedType; @@ -32,8 +33,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier { - +public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, + ResolvedTypeParametrizable, HasAccessSpecifier { /** * The package name of the declaring type. */ @@ -149,7 +150,7 @@ default List getSpecifiedExceptions() { return Collections.emptyList(); } else { List exceptions = new LinkedList<>(); - for (int i = 0; i < getNumberOfSpecifiedExceptions(); i++) { + for (int i=0;i getAllAncestors() { return ancestors; } - // / - // / Fields - // / + /// + /// Fields + /// + /** * Note that the type of the field should be expressed using the type variables of this particular type. * Consider for example: @@ -121,7 +124,9 @@ default List getAllAncestors() { * Bar I should get a FieldDeclaration with type String. */ default ResolvedFieldDeclaration getField(String name) { - Optional field = this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst(); + Optional field = this.getAllFields().stream() + .filter(f -> f.getName().equals(name)) + .findFirst(); if (field.isPresent()) { return field.get(); } else { @@ -164,7 +169,9 @@ default boolean hasVisibleField(String name) { * Return a list of all fields declared and the inherited ones which are not private. */ default List getVisibleFields() { - return getAllFields().stream().filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); + return getAllFields().stream() + .filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE) + .collect(Collectors.toList()); } /** @@ -185,12 +192,14 @@ default List getAllStaticFields() { * Return a list of all the fields declared in this type. */ default List getDeclaredFields() { - return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName().equals(getQualifiedName())).collect(Collectors.toList()); + return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName() + .equals(getQualifiedName())).collect(Collectors.toList()); } - // / - // / Methods - // / + /// + /// Methods + /// + /** * Return a list of all the methods declared in this type declaration. */ @@ -202,9 +211,10 @@ default List getDeclaredFields() { */ Set getAllMethods(); - // / - // / Assignability - // / + /// + /// Assignability + /// + /** * Can we assign instances of the given type to variables having the type defined * by this declaration? @@ -225,9 +235,10 @@ default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { */ boolean isAssignableBy(ResolvedReferenceTypeDeclaration other); - // / - // / Annotations - // / + /// + /// Annotations + /// + /** * Has the type at least one annotation declared having the specified qualified name? */ @@ -240,7 +251,9 @@ default boolean hasAnnotation(String qualifiedName) { if (hasDirectlyAnnotation(qualifiedName)) { return true; } - return getAllAncestors().stream().filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()).anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); + return getAllAncestors().stream() + .filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()) + .anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); } /** @@ -249,9 +262,10 @@ default boolean hasAnnotation(String qualifiedName) { */ boolean isFunctionalInterface(); - // / - // / Type parameters - // / + /// + /// Type parameters + /// + @Override default Optional findTypeParameter(String name) { for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) { @@ -267,6 +281,7 @@ default Optional findTypeParameter(String name List getConstructors(); + /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -276,8 +291,10 @@ default Optional findTypeParameter(String name * @see https://github.com/javaparser/javaparser/issues/2044 */ default boolean isJavaLangObject() { - return this.isClass() && !isAnonymousClass() && // Consider anonymous classes - hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT); + return this.isClass() + && !isAnonymousClass() + && hasName() // Consider anonymous classes + && getQualifiedName().equals(JAVA_LANG_OBJECT); } /** @@ -285,6 +302,8 @@ default boolean isJavaLangObject() { * @see ResolvedReferenceType#isJavaLangEnum() */ default boolean isJavaLangEnum() { - return this.isEnum() && getQualifiedName().equals(JAVA_LANG_ENUM); + return this.isEnum() + && getQualifiedName().equals(JAVA_LANG_ENUM); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java index 3de270dc02..15f5a17a1f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -34,9 +35,10 @@ */ public interface ResolvedTypeDeclaration extends ResolvedDeclaration { - // / - // / Containment - // / + /// + /// Containment + /// + /** * Get the list of types defined inside the current type. */ @@ -49,8 +51,10 @@ default Set internalTypes() { * (Does not include internal types inside internal types). */ default ResolvedReferenceTypeDeclaration getInternalType(String name) { - Optional type = this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); - return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); + Optional type = + this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); + return type.orElseThrow(() -> + new UnsolvedSymbolException("Internal type not found: " + name)); } /** @@ -66,9 +70,10 @@ default boolean hasInternalType(String name) { */ Optional containerType(); - // / - // / Misc - // / + /// + /// Misc + /// + /** * Is this the declaration of a class? * Note that an Enum is not considered a Class in this case. @@ -189,4 +194,5 @@ default String getId() { } return qname; } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index ce5cd8afae..099b3ffe6f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -18,8 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; + import com.github.javaparser.resolution.types.ResolvedType; import java.util.List; @@ -43,7 +45,6 @@ public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaratio */ static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List bounds) { return new ResolvedTypeParameterDeclaration() { - @Override public String getName() { return name; @@ -73,7 +74,7 @@ public String getContainerQualifiedName() { public String getContainerId() { return classQName; } - + @Override public ResolvedTypeParametrizable getContainer() { return null; @@ -156,7 +157,7 @@ default String getQualifiedName() { * The ID of the container. See TypeContainer.getId */ String getContainerId(); - + /** * The TypeParametrizable of the container. Can be either a ReferenceTypeDeclaration or a MethodLikeDeclaration */ @@ -225,9 +226,7 @@ default ResolvedType getUpperBound() { * A Bound on a Type Parameter. */ class Bound { - private boolean extendsBound; - private ResolvedType type; private Bound(boolean extendsBound, ResolvedType type) { @@ -278,18 +277,20 @@ public boolean isSuper() { @Override public String toString() { - return "Bound{" + "extendsBound=" + extendsBound + ", type=" + type + '}'; + return "Bound{" + + "extendsBound=" + extendsBound + + ", type=" + type + + '}'; } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Bound bound = (Bound) o; - if (extendsBound != bound.extendsBound) - return false; + + if (extendsBound != bound.extendsBound) return false; return type != null ? type.equals(bound.type) : bound.type == null; } @@ -300,4 +301,5 @@ public int hashCode() { return result; } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java index 95dd0b317d..9b44acecd2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; import java.util.List; @@ -44,4 +45,5 @@ public interface ResolvedTypeParametrizable { default boolean isGeneric() { return !getTypeParameters().isEmpty(); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java index 63f7e7c700..69fb33709c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java @@ -18,8 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.declarations; + import com.github.javaparser.resolution.types.ResolvedType; /** @@ -33,4 +35,5 @@ public interface ResolvedValueDeclaration extends ResolvedDeclaration { * Type of the declaration. */ ResolvedType getType(); + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java index 19feb684ff..661b2299ef 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -37,18 +38,19 @@ public ResolvedArrayType(ResolvedType baseType) { this.baseType = baseType; } - // / - // / Object methods - // / + /// + /// Object methods + /// + @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResolvedArrayType that = (ResolvedArrayType) o; - if (!baseType.equals(that.baseType)) - return false; + + if (!baseType.equals(that.baseType)) return false; + return true; } @@ -62,9 +64,10 @@ public String toString() { return "ResolvedArrayType{" + baseType + "}"; } - // / - // / Type methods - // / + /// + /// Type methods + /// + @Override public ResolvedArrayType asArrayType() { return this; @@ -88,7 +91,7 @@ public ResolvedType getComponentType() { public boolean isAssignableBy(ResolvedType other) { if (other.isArray()) { if (baseType.isPrimitive() && other.asArrayType().getComponentType().isPrimitive()) { - return baseType.equals(other.asArrayType().getComponentType()); + return baseType.equals(other.asArrayType().getComponentType()); } return baseType.isAssignableBy(other.asArrayType().getComponentType()); } else if (other.isNull()) { @@ -106,4 +109,5 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe return new ResolvedArrayType(baseTypeReplaced); } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java index 8c3f8f6c8a..b4425658f2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -31,7 +32,6 @@ * @author Federico Tomassetti */ public class ResolvedIntersectionType implements ResolvedType { - private List elements; public ResolvedIntersectionType(Collection elements) { @@ -43,11 +43,11 @@ public ResolvedIntersectionType(Collection elements) { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResolvedIntersectionType that = (ResolvedIntersectionType) o; + return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } @@ -68,11 +68,14 @@ public boolean isAssignableBy(ResolvedType other) { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map inferredTypes) { - List elementsReplaced = elements.stream().map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)).collect(Collectors.toList()); + List elementsReplaced = elements.stream() + .map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)) + .collect(Collectors.toList()); if (elementsReplaced.equals(elements)) { return this; } else { return new ResolvedIntersectionType(elementsReplaced); } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java index 4444e924e7..7de9616d38 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java @@ -18,10 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; public class ResolvedLambdaConstraintType implements ResolvedType { - private ResolvedType bound; private ResolvedLambdaConstraintType(ResolvedType bound) { @@ -47,7 +47,7 @@ public ResolvedLambdaConstraintType asConstraintType() { return this; } - public static ResolvedLambdaConstraintType bound(ResolvedType bound) { + public static ResolvedLambdaConstraintType bound(ResolvedType bound){ return new ResolvedLambdaConstraintType(bound); } @@ -58,6 +58,8 @@ public boolean isAssignableBy(ResolvedType other) { @Override public String toString() { - return "LambdaConstraintType{" + "bound=" + bound + '}'; + return "LambdaConstraintType{" + + "bound=" + bound + + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java index c887e47096..d103d19c90 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import java.util.Arrays; @@ -29,6 +30,7 @@ */ public enum ResolvedPrimitiveType implements ResolvedType { + BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()), SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)), CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()), @@ -38,13 +40,12 @@ public enum ResolvedPrimitiveType implements ResolvedType { FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); - // / - // / Fields - // / - private String name; + /// + /// Fields + /// + private String name; private String boxTypeQName; - private List promotionTypes; ResolvedPrimitiveType(String name, String boxTypeQName, List promotionTypes) { @@ -62,17 +63,19 @@ public static ResolvedType byName(String name) { } throw new IllegalArgumentException("Name " + name); } - + /* * Returns an array containing all numeric types */ public static ResolvedPrimitiveType[] getNumericPrimitiveTypes() { - return new ResolvedPrimitiveType[] { BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE }; + return new ResolvedPrimitiveType[] {BYTE,SHORT,CHAR,INT,LONG,FLOAT,DOUBLE}; } @Override public String toString() { - return "PrimitiveTypeUsage{" + "name='" + name + '\'' + '}'; + return "PrimitiveTypeUsage{" + + "name='" + name + '\'' + + '}'; } public ResolvedPrimitiveType asPrimitive() { @@ -130,14 +133,14 @@ public String getBoxTypeQName() { public boolean isNumeric() { return this != BOOLEAN; } - + /** * Is this a boolean type? */ public boolean isBoolean() { return this == BOOLEAN; } - + /* * Binary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2) * If any operand is of a reference type, it is subjected to unboxing conversion (§5.1.8). @@ -146,43 +149,44 @@ public ResolvedPrimitiveType bnp(ResolvedPrimitiveType other) { // If either operand is of type double, the other is converted to double. if (this == ResolvedPrimitiveType.DOUBLE || other == ResolvedPrimitiveType.DOUBLE) { return ResolvedPrimitiveType.DOUBLE; - // Otherwise, if either operand is of type float, the other is converted to float. + // Otherwise, if either operand is of type float, the other is converted to float. } else if (this == ResolvedPrimitiveType.FLOAT || other == ResolvedPrimitiveType.FLOAT) { return ResolvedPrimitiveType.FLOAT; - // Otherwise, if either operand is of type long, the other is converted to long. + // Otherwise, if either operand is of type long, the other is converted to long. } else if (this == ResolvedPrimitiveType.LONG || other == ResolvedPrimitiveType.LONG) { return ResolvedPrimitiveType.LONG; } // Otherwise, both operands are converted to type int. return ResolvedPrimitiveType.INT; } - + /* * Unary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se9/html/jls-5.html#jls-5.6.1) */ public static ResolvedType unp(ResolvedType type) { boolean isUnboxable = type.isReferenceType() && type.asReferenceType().isUnboxable(); - // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). + // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). // The result is then promoted to a value of type int by a widening primitive conversion (§5.1.2) or an identity conversion (§5.1.1). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT })) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT})) { return ResolvedPrimitiveType.INT; } // Otherwise, if the operand is of compile-time type Long, Float, or Double, it is subjected to unboxing conversion (§5.1.8). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE })) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE})) { return type.asReferenceType().toUnboxedType().get(); } // Otherwise, if the operand is of compile-time type byte, short, or char, it is promoted to a value of type int by a widening primitive conversion (§5.1.2). - if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT })) { + if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT})) { return ResolvedPrimitiveType.INT; } // Otherwise, a unary numeric operand remains as is and is not converted. return type; } - + /* * Verify if the ResolvedPrimitiveType is in the list of ResolvedPrimitiveType */ public boolean in(ResolvedPrimitiveType[] types) { - return Arrays.stream(types).anyMatch(type -> this == type); + return Arrays.stream(types).anyMatch(type -> this == type); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java index 1eda183242..aae1a1ed6f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -18,8 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -32,27 +43,26 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; import com.github.javaparser.utils.Pair; -import java.util.*; -import java.util.stream.Collectors; - /** * A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values * specified for the type parameters. * * @author Federico Tomassetti */ -public abstract class ResolvedReferenceType implements ResolvedType, ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { +public abstract class ResolvedReferenceType implements ResolvedType, + ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { - // + // // Fields - // - protected ResolvedReferenceTypeDeclaration typeDeclaration; + // + protected ResolvedReferenceTypeDeclaration typeDeclaration; protected ResolvedTypeParametersMap typeParametersMap; - // + // // Constructors - // + // + public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration) { this(typeDeclaration, deriveParams(typeDeclaration)); } @@ -65,7 +75,9 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L throw new IllegalArgumentException("You should use only Classes, Interfaces and enums"); } if (typeArguments.size() > 0 && typeArguments.size() != typeDeclaration.getTypeParameters().size()) { - throw new IllegalArgumentException(String.format("expected either zero type arguments or has many as defined in the declaration (%d). Found %d", typeDeclaration.getTypeParameters().size(), typeArguments.size())); + throw new IllegalArgumentException(String.format( + "expected either zero type arguments or has many as defined in the declaration (%d). Found %d", + typeDeclaration.getTypeParameters().size(), typeArguments.size())); } ResolvedTypeParametersMap.Builder typeParametersMapBuilder = new ResolvedTypeParametersMap.Builder(); for (int i = 0; i < typeArguments.size(); i++) { @@ -75,20 +87,20 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L this.typeDeclaration = typeDeclaration; } - // + // // Public Object methods - // + // + @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResolvedReferenceType that = (ResolvedReferenceType) o; - if (!typeDeclaration.equals(that.typeDeclaration)) - return false; - if (!typeParametersMap.equals(that.typeParametersMap)) - return false; + + if (!typeDeclaration.equals(that.typeDeclaration)) return false; + if (!typeParametersMap.equals(that.typeParametersMap)) return false; + return true; } @@ -101,28 +113,33 @@ public int hashCode() { @Override public String toString() { - return "ReferenceType{" + getQualifiedName() + ", typeParametersMap=" + typeParametersMap + '}'; + return "ReferenceType{" + getQualifiedName() + + ", typeParametersMap=" + typeParametersMap + + '}'; } - // / - // / Relation with other types - // / + /// + /// Relation with other types + /// + @Override public final boolean isReferenceType() { return true; } - // / - // / Downcasting - // / + /// + /// Downcasting + /// + @Override public ResolvedReferenceType asReferenceType() { return this; } - // / - // / Naming - // / + /// + /// Naming + /// + @Override public String describe() { StringBuilder sb = new StringBuilder(); @@ -133,25 +150,30 @@ public String describe() { } if (!typeParametersMap().isEmpty()) { sb.append("<"); - sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream().map(tp -> typeParametersMap().getValue(tp).describe()).collect(Collectors.toList()))); + sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream() + .map(tp -> typeParametersMap().getValue(tp).describe()) + .collect(Collectors.toList()))); sb.append(">"); } return sb.toString(); } - // / - // / TypeParameters - // / + /// + /// TypeParameters + /// + /** * Execute a transformation on all the type parameters of this element. */ public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer); @Override - public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map inferredTypes) { + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, + Map inferredTypes) { if (replaced == null) { throw new IllegalArgumentException(); } + ResolvedReferenceType result = this; int i = 0; for (ResolvedType tp : this.typeParametersValues()) { @@ -168,30 +190,34 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe } i++; } + List values = result.typeParametersValues(); // FIXME if (values.contains(tpToReplace)) { int index = values.indexOf(tpToReplace); values.set(index, replaced); - if (result.getTypeDeclaration().isPresent()) { + if(result.getTypeDeclaration().isPresent()) { return create(result.getTypeDeclaration().get(), values); } } + return result; } - // / - // / Assignability - // / + /// + /// Assignability + /// + /** * This method checks if ThisType t = new OtherType() would compile. */ @Override public abstract boolean isAssignableBy(ResolvedType other); - // / - // / Ancestors - // / + /// + /// Ancestors + /// + /** * Return all ancestors, that means all superclasses and interfaces. * This list should always include Object (unless this is a reference to Object). @@ -215,16 +241,23 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe public abstract List getDirectAncestors(); public final List getAllInterfacesAncestors() { - return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isInterface()).collect(Collectors.toList()); + return getAllAncestors().stream() + .filter(it -> it.getTypeDeclaration().isPresent()) + .filter(it -> it.getTypeDeclaration().get().isInterface()) + .collect(Collectors.toList()); } public final List getAllClassesAncestors() { - return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isClass()).collect(Collectors.toList()); + return getAllAncestors().stream() + .filter(it -> it.getTypeDeclaration().isPresent()) + .filter(it -> it.getTypeDeclaration().get().isClass()) + .collect(Collectors.toList()); } - // / - // / Type parameters - // / + /// + /// Type parameters + /// + /** * Get the type associated with the type parameter with the given name. * It returns Optional.empty unless the type declaration declares a type parameter with the given name. @@ -265,9 +298,10 @@ public ResolvedTypeParametersMap typeParametersMap() { return typeParametersMap; } - // / - // / Other methods introduced by ReferenceType - // / + /// + /// Other methods introduced by ReferenceType + /// + /** * Corresponding TypeDeclaration */ @@ -339,10 +373,10 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty if (typeParameterDeclaration.declaredOnMethod()) { throw new IllegalArgumentException(); } - if (!this.getTypeDeclaration().isPresent()) { - // TODO: Consider IllegalStateException or similar - return Optional.empty(); + if(!this.getTypeDeclaration().isPresent()) { + return Optional.empty(); // TODO: Consider IllegalStateException or similar } + String typeId = this.getTypeDeclaration().get().getId(); if (typeId.equals(typeParameterDeclaration.getContainerId())) { return Optional.of(this.typeParametersMap().getValue(typeParameterDeclaration)); @@ -363,14 +397,17 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty * that have been overwritten. */ public List getAllMethods() { - if (!this.getTypeDeclaration().isPresent()) { - // empty list -- consider IllegalStateException or similar - return new ArrayList<>(); + if(!this.getTypeDeclaration().isPresent()) { + return new ArrayList<>(); // empty list -- consider IllegalStateException or similar } + // Get the methods declared directly on this. - List allMethods = new LinkedList<>(this.getTypeDeclaration().get().getDeclaredMethods()); + List allMethods = new LinkedList<>( + this.getTypeDeclaration().get().getDeclaredMethods() + ); // Also get methods inherited from ancestors. getDirectAncestors().forEach(a -> allMethods.addAll(a.getAllMethods())); + return allMethods; } @@ -379,22 +416,32 @@ public List getAllMethods() { * type plus all declared fields which are not private. */ public List getAllFieldsVisibleToInheritors() { - List res = new LinkedList<>(this.getDeclaredFields().stream().filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList())); - getDirectAncestors().forEach(a -> res.addAll(a.getAllFieldsVisibleToInheritors())); + List res = new LinkedList<>(this.getDeclaredFields().stream() + .filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE) + .collect(Collectors.toList())); + + getDirectAncestors().forEach(a -> + res.addAll(a.getAllFieldsVisibleToInheritors())); + return res; } public List getAllMethodsVisibleToInheritors() { - return this.getAllMethods().stream().filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); + return this.getAllMethods().stream() + .filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE) + .collect(Collectors.toList()); } - // + // // Protected methods - // + // + protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParameters); protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap) { - return create(typeDeclaration, typeDeclaration.getTypeParameters().stream().map(typeParametersMap::getValue).collect(Collectors.toList())); + return create(typeDeclaration, typeDeclaration.getTypeParameters().stream() + .map(typeParametersMap::getValue) + .collect(Collectors.toList())); } protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration); @@ -436,11 +483,15 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) } } else { if (thisParam instanceof ResolvedTypeVariable && otherParam instanceof ResolvedTypeVariable) { - List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); - List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); + List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds() + .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) + .collect(Collectors.toList()); + List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds() + .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) + .collect(Collectors.toList()); return thisBounds.size() == otherBounds.size() && otherBounds.containsAll(thisBounds); } else if (!(thisParam instanceof ResolvedTypeVariable) && otherParam instanceof ResolvedTypeVariable) { - return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable) otherParam); + return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable)otherParam); } else if (thisParam instanceof ResolvedTypeVariable && !(otherParam instanceof ResolvedTypeVariable)) { return compareConsideringVariableTypeParameters(otherParam, (ResolvedTypeVariable) thisParam); } @@ -453,18 +504,22 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) return false; } - // + // // Private methods - // + // + private boolean compareConsideringVariableTypeParameters(ResolvedType referenceType, ResolvedTypeVariable typeVariable) { // verify if the ResolvedTypeVariable has only one type variable and the bound is - // not a reference type with a bound parameter + // not a reference type with a bound parameter // for example EnumSet noneOf(Class elementType) List bounds = typeVariable.asTypeVariable().asTypeParameter().getBounds(); if (bounds.size() == 1) { ResolvedType boundType = bounds.get(0).getType(); - boolean hasTypeParameter = boundType.isReferenceType() && !boundType.asReferenceType().typeParametersMap.isEmpty(); - return hasTypeParameter ? compareConsideringTypeParameters(boundType.asReferenceType()) : boundType.isAssignableBy(referenceType); + boolean hasTypeParameter = boundType.isReferenceType() + && !boundType.asReferenceType().typeParametersMap.isEmpty(); + return hasTypeParameter + ? compareConsideringTypeParameters(boundType.asReferenceType()) + : boundType.isAssignableBy(referenceType); } return false; } @@ -482,6 +537,7 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap); + /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -491,8 +547,9 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration * @see https://github.com/javaparser/javaparser/issues/2044 */ public boolean isJavaLangObject() { - return this.isReferenceType() && // Consider anonymous classes - hasName() && getQualifiedName().equals(java.lang.Object.class.getCanonicalName()); + return this.isReferenceType() + && hasName() // Consider anonymous classes + && getQualifiedName().equals(java.lang.Object.class.getCanonicalName()); } /** @@ -500,13 +557,16 @@ public boolean isJavaLangObject() { * @see ResolvedReferenceTypeDeclaration#isJavaLangEnum() */ public boolean isJavaLangEnum() { - return this.isReferenceType() && // Consider anonymous classes - hasName() && getQualifiedName().equals(java.lang.Enum.class.getCanonicalName()); - } - - // / - // / boxing/unboxing capability - // / + return this.isReferenceType() + && hasName() // Consider anonymous classes + && getQualifiedName().equals(java.lang.Enum.class.getCanonicalName()); + } + + + /// + /// boxing/unboxing capability + /// + /* * Returns true if the reference type can be unboxed to the primitive type * For example : Integer to int @@ -514,7 +574,7 @@ public boolean isJavaLangEnum() { public boolean isUnboxable() { return Arrays.stream(ResolvedPrimitiveType.values()).anyMatch(pt -> getQualifiedName().equals(pt.getBoxTypeQName())); } - + /* * Returns true if the reference type can be unboxed to the specified primitive type * For example : Integer to int @@ -522,11 +582,12 @@ public boolean isUnboxable() { public boolean isUnboxableTo(ResolvedPrimitiveType primitiveType) { return primitiveType.getBoxTypeQName().equals(this.asReferenceType().describe()); } - + /* * Returns the optional corresponding primitive type */ public Optional toUnboxedType() { return Arrays.stream(ResolvedPrimitiveType.values()).filter(pt -> this.asReferenceType().getQualifiedName().equals(pt.getBoxTypeQName())).findFirst(); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java index 89f5387ca9..17b1e20b21 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java @@ -18,15 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ -package com.github.javaparser.resolution.types; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +package com.github.javaparser.resolution.types; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + /** *

A resolved type.

*
    @@ -49,9 +50,10 @@ */ public interface ResolvedType { - // / - // / Relation with other types - // / + /// + /// Relation with other types + /// + /** * @return true, if this type represent an array - otherwise false. */ @@ -102,9 +104,7 @@ default boolean isReference() { /** * Is this a lambda constraint type? */ - default boolean isConstraint() { - return false; - } + default boolean isConstraint() { return false; } /** * Can this be seen as a ReferenceTypeUsage? @@ -125,14 +125,15 @@ default boolean isTypeVariable() { default boolean isWildcard() { return false; } - + default boolean isInferenceVariable() { return false; } - // / - // / Downcasting - // / + /// + /// Downcasting + /// + default ResolvedArrayType asArrayType() { throw new UnsupportedOperationException(String.format("%s is not an Array", this)); } @@ -165,14 +166,16 @@ default ResolvedUnionType asUnionType() { throw new UnsupportedOperationException(String.format("%s is not a union type", this)); } - // / - // / Naming - // / + /// + /// Naming + /// + String describe(); - // / - // / TypeParameters - // / + /// + /// TypeParameters + /// + /** * Replace all variables referring to the given TypeParameter with the given value. * By replacing these values I could also infer some type equivalence. @@ -196,18 +199,20 @@ default boolean mention(List typeParameters) { throw new UnsupportedOperationException(this.getClass().getCanonicalName()); } - // / - // / Assignability - // / + /// + /// Assignability + /// + /** * This method checks if ThisType t = new OtherType() would compile. */ boolean isAssignableBy(ResolvedType other); - + /* * Returns true if the ResolvedType is a numeric */ default boolean isNumericType() { - return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt -> rpt.isAssignableBy(this)); + return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt-> rpt.isAssignableBy(this)); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java index 175736d722..68d6d7719d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; /** @@ -25,6 +26,5 @@ */ @FunctionalInterface public interface ResolvedTypeTransformer { - ResolvedType transform(ResolvedType type); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java index 64faa60aa0..3eae604197 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -50,17 +51,15 @@ public String qualifiedName() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResolvedTypeVariable that = (ResolvedTypeVariable) o; - if (!typeParameter.getName().equals(that.typeParameter.getName())) - return false; - if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) - return false; - if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) - return false; + + if (!typeParameter.getName().equals(that.typeParameter.getName())) return false; + if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false; + if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false; + return true; } @@ -81,7 +80,7 @@ public boolean isPrimitive() { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map inferredTypes) { - if (tpToBeReplaced.getName().equals(this.typeParameter.getName())) { + if(tpToBeReplaced.getName().equals(this.typeParameter.getName())){ inferredTypes.put(this.asTypeParameter(), replaced); return replaced; } else { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java index 33e9784ff9..68098b3cd9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import java.util.*; @@ -29,7 +30,6 @@ * @author Federico Tomassetti */ public class ResolvedUnionType implements ResolvedType { - private List elements; public ResolvedUnionType(List elements) { @@ -40,21 +40,24 @@ public ResolvedUnionType(List elements) { } public Optional getCommonAncestor() { - Optional> reduce = elements.stream().map(ResolvedType::asReferenceType).map(ResolvedReferenceType::getAllAncestors).reduce((a, b) -> { - ArrayList common = new ArrayList<>(a); - common.retainAll(b); - return common; - }); + Optional> reduce = elements.stream() + .map(ResolvedType::asReferenceType) + .map(ResolvedReferenceType::getAllAncestors) + .reduce((a, b) -> { + ArrayList common = new ArrayList<>(a); + common.retainAll(b); + return common; + }); return reduce.orElse(new ArrayList<>()).stream().findFirst(); } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResolvedUnionType that = (ResolvedUnionType) o; + return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java index 026ab9af0f..f7989c48fc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; /** @@ -26,7 +27,6 @@ * @author Federico Tomassetti */ public class ResolvedVoidType implements ResolvedType { - public static final ResolvedType INSTANCE = new ResolvedVoidType(); private ResolvedVoidType() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java index bba8d293c9..16e2b19aed 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -39,7 +40,6 @@ public class ResolvedWildcard implements ResolvedType { public static ResolvedWildcard UNBOUNDED = new ResolvedWildcard(null, null); private BoundType type; - private ResolvedType boundedType; private ResolvedWildcard(BoundType type, ResolvedType boundedType) { @@ -63,7 +63,10 @@ public static ResolvedWildcard extendsBound(ResolvedType type) { @Override public String toString() { - return "WildcardUsage{" + "type=" + type + ", boundedType=" + boundedType + '}'; + return "WildcardUsage{" + + "type=" + type + + ", boundedType=" + boundedType + + '}'; } public boolean isWildcard() { @@ -76,15 +79,14 @@ public ResolvedWildcard asWildcard() { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof ResolvedWildcard)) - return false; + if (this == o) return true; + if (!(o instanceof ResolvedWildcard)) return false; + ResolvedWildcard that = (ResolvedWildcard) o; - if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) - return false; - if (type != that.type) - return false; + + if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) return false; + if (type != that.type) return false; + return true; } @@ -130,7 +132,7 @@ public ResolvedType getBoundedType() { @Override public boolean isAssignableBy(ResolvedType other) { if (boundedType == null) { - // return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); + //return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); return false; } else if (type == BoundType.SUPER) { return boundedType.isAssignableBy(other); @@ -174,7 +176,8 @@ public boolean isLowerBounded() { } public enum BoundType { - - SUPER, EXTENDS + SUPER, + EXTENDS } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java index 012fd63994..c84b3e17bb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -51,6 +52,7 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { } } } + if (type.isWildcard() && type.asWildcard().isBounded()) { if (type.asWildcard().isExtends()) { return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); @@ -58,9 +60,11 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); } } + if (type.isReferenceType()) { type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType); } + return type; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java index c8ecfd2523..249c40be24 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -34,9 +35,7 @@ public class ResolvedTypeParametersMap { public static class Builder { - private Map nameToValue; - private Map nameToDeclaration; public Builder() { @@ -44,7 +43,8 @@ public Builder() { nameToDeclaration = new HashMap<>(); } - private Builder(Map nameToValue, Map nameToDeclaration) { + private Builder(Map nameToValue, + Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -55,7 +55,8 @@ public ResolvedTypeParametersMap build() { return new ResolvedTypeParametersMap(nameToValue, nameToDeclaration); } - public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, ResolvedType value) { + public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, + ResolvedType value) { // TODO: we shouldn't just silently overwrite existing types! String qualifiedName = typeParameter.getQualifiedName(); nameToValue.put(qualifiedName, value); @@ -66,12 +67,13 @@ public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, Resolved @Override public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof ResolvedTypeParametersMap)) - return false; + if (this == o) return true; + if (!(o instanceof ResolvedTypeParametersMap)) return false; + ResolvedTypeParametersMap that = (ResolvedTypeParametersMap) o; + return nameToValue.equals(that.nameToValue) && nameToDeclaration.equals(that.nameToDeclaration); + } @Override @@ -81,18 +83,20 @@ public int hashCode() { @Override public String toString() { - return "TypeParametersMap{" + "nameToValue=" + nameToValue + '}'; + return "TypeParametersMap{" + + "nameToValue=" + nameToValue + + '}'; } private Map nameToValue; - private Map nameToDeclaration; public static ResolvedTypeParametersMap empty() { return new Builder().build(); } - private ResolvedTypeParametersMap(Map nameToValue, Map nameToDeclaration) { + private ResolvedTypeParametersMap(Map nameToValue, + Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -116,11 +120,11 @@ public Optional getValueBySignature(String signature) { } } - public List getNames() { + public List getNames(){ return new ArrayList<>(nameToValue.keySet()); } - public List getTypes() { + public List getTypes(){ return new ArrayList<>(nameToValue.values()); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java index 17c2cbe900..ec05f7fe73 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.resolution.types.parametrization; /** @@ -26,6 +27,5 @@ * @author Federico Tomassetti */ public interface ResolvedTypeParametrized { - ResolvedTypeParametersMap typeParametersMap(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java index 178a84745f..0dd222a049 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import java.util.HashMap; import java.util.Map; public class ClassUtils { - /** * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java index 674e93bd52..6d7ffd52c3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import java.io.File; @@ -32,7 +33,6 @@ * Utilities that can be useful when generating code. */ public final class CodeGenerationUtils { - private CodeGenerationUtils() { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java index fc7a7991d1..fc759bfa3e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.JavaParser; @@ -46,6 +47,7 @@ default Optional getRoot(Path file) { try { final JavaParser javaParser = new JavaParser(getParserConfiguration()); final ParseResult parseResult = javaParser.parse(file); + if (parseResult.isSuccessful()) { if (parseResult.getProblems().isEmpty()) { if (parseResult.getResult().isPresent()) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java index 287ad7415a..ea84d25acd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java @@ -13,7 +13,6 @@ * @see https://github.com/javaparser/javaparser/issues/2647 */ public enum LineSeparator { - /** * The CR {@code \r} line ending is the default line separator for classic MacOS */ @@ -29,7 +28,13 @@ public enum LineSeparator { /** * This line ending is set to whatever the host system's line separator is */ - SYSTEM(System.getProperty("line.separator"), "SYSTEM : (" + System.getProperty("line.separator").replace("\r", "\\r").replace("\n", "\\n") + ")"), + SYSTEM( + System.getProperty("line.separator"), + "SYSTEM : (" + System.getProperty("line.separator") + .replace("\r", "\\r") + .replace("\n", "\\n") + + ")" + ), /** * The ARBITRARY line ending can be used where we do not care about the line separator, * only that we use the same one consistently @@ -51,7 +56,6 @@ public enum LineSeparator { NONE("", "NONE"); private final String text; - private final String description; LineSeparator(String text, String description) { @@ -71,6 +75,7 @@ public static LineSeparator detect(String string) { int countCr = count(string, "\r"); int countLf = count(string, "\n"); int countCrLf = count(string, "\r\n"); + return getLineEnding(countCr, countLf, countCrLf); } @@ -79,6 +84,7 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (noLineEndings) { return NONE; } + boolean crOnly = countCr > 0 && countLf == 0 && countCrLf == 0; if (crOnly) { return CR; @@ -87,11 +93,13 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (lfOnly) { return LF; } + // Note that wherever \r\n are found, there will also be an equal number of \r and \n characters found. boolean crLfOnly = countCr == countLf && countLf == countCrLf; if (crLfOnly) { return CRLF; } + // Not zero line endings, and not a single line ending, thus is mixed. return MIXED; } @@ -140,7 +148,10 @@ public boolean isStandardEol() { } public String asEscapedString() { - String result = text.replace("\r", "\\r").replace("\n", "\\n"); + String result = text + .replace("\r", "\\r") + .replace("\n", "\\n"); + return result; } @@ -150,13 +161,14 @@ public String asRawString() { // TODO: Determine if this should be used within TokenTypes.java -- thus leaving this as private for now. private Optional asJavaTokenKind() { - if (this == CR) { + if(this == CR) { return Optional.of(JavaToken.Kind.OLD_MAC_EOL); - } else if (this == LF) { + } else if(this == LF) { return Optional.of(JavaToken.Kind.UNIX_EOL); - } else if (this == CRLF) { + } else if(this == CRLF) { return Optional.of(JavaToken.Kind.WINDOWS_EOL); } + return Optional.empty(); } @@ -164,4 +176,5 @@ private Optional asJavaTokenKind() { public String toString() { return asRawString(); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java index 296d2294a1..67062f4061 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import java.io.IOException; @@ -33,12 +34,10 @@ * See a blog about this */ public class Log { - /** * This adapter logs to standard out and standard error. */ public static class StandardOutStandardErrorAdapter implements Adapter { - @Override public void info(Supplier messageSupplier) { System.out.println(messageSupplier.get()); @@ -65,8 +64,7 @@ public void error(Supplier throwableSupplier, Supplier messag } private void printStackTrace(Throwable throwable) { - try (StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw)) { + try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { throwable.printStackTrace(pw); trace(sw::toString); } catch (IOException e) { @@ -79,7 +77,6 @@ private void printStackTrace(Throwable throwable) { * This adapter logs nothing. */ public static class SilentAdapter implements Adapter { - @Override public void info(Supplier messageSupplier) { } @@ -132,6 +129,7 @@ private static Supplier makeFormattingSupplier(String format, Supplier type of object b. */ public class Pair { - public final A a; - public final B b; public Pair(A a, B b) { @@ -43,15 +42,14 @@ public Pair(A a, B b) { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Pair pair = (Pair) o; - if (!Objects.equals(a, pair.a)) - return false; - if (!Objects.equals(b, pair.b)) - return false; + + if (!Objects.equals(a, pair.a)) return false; + if (!Objects.equals(b, pair.b)) return false; + return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java index 4016cad293..f51eb80fe0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java @@ -18,12 +18,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; import java.io.IOException; -import java.nio.file.*; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import static java.nio.file.FileVisitResult.*; @@ -59,9 +64,7 @@ public ProjectRoot collect(Path path) { ProjectRoot projectRoot = new ProjectRoot(path, parserConfiguration); try { Files.walkFileTree(path, new SimpleFileVisitor() { - Path current_root; - PathMatcher javaMatcher = getPathMatcher("glob:**.java"); @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java index e14788de16..840b357a3b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.Position; @@ -80,8 +81,10 @@ private static int compare(Node a, Node b, boolean ignoringAnnotations) { return signLine; } } + Position aBegin = a.getBegin().get(); Position bBegin = b.getBegin().get(); + int signLine = signum(aBegin.line - bBegin.line); if (signLine == 0) { return signum(aBegin.column - bBegin.column); @@ -107,6 +110,7 @@ private static int beginLineWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.line; } + private static int beginColumnWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.column; } @@ -116,7 +120,11 @@ private static Node firstNonAnnotationNode(Node node) { if (node instanceof ClassOrInterfaceDeclaration) { // Modifiers appear before the class name -- ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; - Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); + Modifier earliestModifier = casted.getModifiers() + .stream() + .filter(modifier -> modifier.getRange().isPresent()) + .min(Comparator.comparing(o -> o.getRange().get().begin)) + .orElse(null); if (earliestModifier == null) { return casted.getName(); } else { @@ -125,7 +133,11 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof MethodDeclaration) { // Modifiers appear before the class name -- MethodDeclaration casted = (MethodDeclaration) node; - Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); + Modifier earliestModifier = casted.getModifiers() + .stream() + .filter(modifier -> modifier.getRange().isPresent()) + .min(Comparator.comparing(o -> o.getRange().get().begin)) + .orElse(null); if (earliestModifier == null) { return casted.getType(); } else { @@ -134,7 +146,11 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof FieldDeclaration) { // Modifiers appear before the class name -- FieldDeclaration casted = (FieldDeclaration) node; - Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.getRange().isPresent()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); + Modifier earliestModifier = casted.getModifiers() + .stream() + .filter(modifier -> modifier.getRange().isPresent()) + .min(Comparator.comparing(o -> o.getRange().get().begin)) + .orElse(null); if (earliestModifier == null) { return casted.getVariable(0).getType(); } else { @@ -145,6 +161,7 @@ private static Node firstNonAnnotationNode(Node node) { } } + /** * Compare the position of two nodes. Optionally include annotations within the range checks. * This method takes into account whether the nodes are within the same compilation unit. @@ -162,28 +179,38 @@ public static boolean nodeContains(Node container, Node other, boolean ignoringA if (!other.getRange().isPresent()) { throw new IllegalArgumentException("Cannot compare the positions of nodes if contained node does not have a range."); } - // // FIXME: Not all nodes seem to have the compilation unit available? - // if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { - // // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), - // // ... or both not within a CU (i.e. both are Optional.empty()) - // return false; - // } + +// // FIXME: Not all nodes seem to have the compilation unit available? +// if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { +// // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), +// // ... or both not within a CU (i.e. both are Optional.empty()) +// return false; +// } + final boolean nodeCanHaveAnnotations = container instanceof NodeWithAnnotations; - // final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; +// final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) { // No special consideration required - perform simple range check. return container.containsWithinRange(other); } + if (!container.containsWithinRange(other)) { return false; } + if (!nodeCanHaveAnnotations) { return true; } + // If the node is contained, but it comes immediately after the annotations, // let's not consider it contained (i.e. it must be "strictly contained"). Node nodeWithoutAnnotations = firstNonAnnotationNode(container); - Range rangeWithoutAnnotations = container.getRange().get().withBegin(nodeWithoutAnnotations.getBegin().get()); - return rangeWithoutAnnotations.strictlyContains(other.getRange().get()); + Range rangeWithoutAnnotations = container.getRange().get() + .withBegin(nodeWithoutAnnotations.getBegin().get()); + return rangeWithoutAnnotations +// .contains(other.getRange().get()); + .strictlyContains(other.getRange().get()); + } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java index fd9b3452f3..9f276c0aa2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; @@ -39,9 +40,7 @@ public class ProjectRoot { private final Path root; - private final Map cache = new ConcurrentHashMap<>(); - private final ParserConfiguration parserConfiguration; public ProjectRoot(Path root) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java index 378e754975..cd00bf8bfc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; /** @@ -26,19 +27,16 @@ *

    Java 8 offers the very nice Collectors.joining(String, String, String) which does the same thing. */ public class SeparatedItemStringBuilder { - private final String separator; - private final String postfix; - private boolean hasItems = false; - private StringBuilder builder; public SeparatedItemStringBuilder(String prefix, String separator, String postfix) { builder = new StringBuilder(prefix); this.separator = separator; this.postfix = postfix; + } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java index d9aff77330..0534f32b4b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java @@ -18,14 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.printer.DefaultPrettyPrinter; +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageAbsolutePath; +import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; +import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.nio.file.FileVisitResult.CONTINUE; +import static java.nio.file.FileVisitResult.SKIP_SUBTREE; +import static java.nio.file.FileVisitResult.TERMINATE; import java.io.IOException; import java.nio.charset.Charset; @@ -44,11 +48,12 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.utils.CodeGenerationUtils.*; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.nio.file.FileVisitResult.*; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseProblemException; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.DefaultPrettyPrinter; /** * A collection of Java source files located in one directory and its subdirectories on the file system. The root directory @@ -61,12 +66,9 @@ *

*/ public class SourceRoot { - @FunctionalInterface public interface Callback { - enum Result { - SAVE, DONT_SAVE, TERMINATE } @@ -79,13 +81,9 @@ enum Result { } private final Path root; - private final Map> cache = new ConcurrentHashMap<>(); - private ParserConfiguration parserConfiguration = new ParserConfiguration(); - private Function printer = new DefaultPrettyPrinter()::print; - private static final Pattern JAVA_IDENTIFIER = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*"); /** @@ -128,7 +126,8 @@ public ParseResult tryToParse(String startPackage, String filen } final Path path = root.resolve(relativePath); Log.trace("Parsing %s", () -> path); - final ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); + final ParseResult result = new JavaParser(configuration) + .parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(path, configuration.getCharacterEncoding())); cache.put(relativePath, result); return result; @@ -159,7 +158,6 @@ public List> tryToParse(String startPackage) throws logPackage(startPackage); final Path path = packageAbsolutePath(root, startPackage); Files.walkFileTree(path, new SimpleFileVisitor() { - @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && file.toString().endsWith(".java")) { @@ -219,7 +217,10 @@ public List> tryToParseParallelized(String startPac if (!attrs.isDirectory() && file.toString().endsWith(".java")) { Path relative = root.relativize(file.getParent()); try { - tryToParse(relative.toString(), file.getFileName().toString(), parserConfiguration); + tryToParse( + relative.toString(), + file.getFileName().toString(), + parserConfiguration); } catch (IOException e) { Log.error(e); } @@ -272,7 +273,7 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur Log.trace("Parsing %s", () -> localPath); ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(absolutePath, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(absolutePath, configuration.getCharacterEncoding())); - switch(callback.process(localPath, absolutePath, result)) { + switch (callback.process(localPath, absolutePath, result)) { case SAVE: result.getResult().ifPresent(cu -> save(cu, absolutePath)); case DONT_SAVE: @@ -291,7 +292,8 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur * @param startPackage The package containing the file * @param filename The name of the file */ - public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback callback) throws IOException { + public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback + callback) throws IOException { assertNotNull(startPackage); assertNotNull(filename); assertNotNull(configuration); @@ -323,7 +325,6 @@ public SourceRoot parse(String startPackage, ParserConfiguration configuration, final Path path = packageAbsolutePath(root, startPackage); if (Files.exists(path)) { Files.walkFileTree(path, new SimpleFileVisitor() { - @Override public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) { @@ -421,7 +422,10 @@ public SourceRoot add(String startPackage, String filename, CompilationUnit comp assertNotNull(compilationUnit); Log.trace("Adding new file %s.%s", () -> startPackage, () -> filename); final Path path = fileInPackageRelativePath(startPackage, filename); - final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); + final ParseResult parseResult = new ParseResult<>( + compilationUnit, + new ArrayList<>(), + null); cache.put(path, parseResult); return this; } @@ -435,7 +439,10 @@ public SourceRoot add(CompilationUnit compilationUnit) { if (compilationUnit.getStorage().isPresent()) { final Path path = compilationUnit.getStorage().get().getPath(); Log.trace("Adding new file %s", () -> path); - final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); + final ParseResult parseResult = new ParseResult<>( + compilationUnit, + new ArrayList<>(), + null); cache.put(path, parseResult); } else { throw new AssertionError("Files added with this method should have their path set."); @@ -519,7 +526,10 @@ public List> getCache() { * added manually. */ public List getCompilationUnits() { - return cache.values().stream().filter(ParseResult::isSuccessful).map(p -> p.getResult().get()).collect(Collectors.toList()); + return cache.values().stream() + .filter(ParseResult::isSuccessful) + .map(p -> p.getResult().get()) + .collect(Collectors.toList()); } /** @@ -567,9 +577,7 @@ public Function getPrinter() { private static class ParallelParse extends RecursiveAction { private static final long serialVersionUID = 1L; - private final Path path; - private final VisitFileCallback callback; ParallelParse(Path path, VisitFileCallback callback) { @@ -582,7 +590,6 @@ protected void compute() { final List walks = new ArrayList<>(); try { Files.walkFileTree(path, new SimpleFileVisitor() { - @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (!SourceRoot.isSensibleDirectoryToEnter(dir)) { @@ -606,13 +613,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { } catch (IOException e) { Log.error(e); } + for (ParallelParse w : walks) { w.join(); } } interface VisitFileCallback { - FileVisitResult process(Path file, BasicFileAttributes attrs); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java index 04414ad9e1..0156d11757 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.JavaParser; @@ -41,11 +42,11 @@ /** * A collection of Java source files and its sub-directories located in a ZIP or JAR file on the file system. * Files can be parsed with a callback. + * */ public class SourceZip { private final Path zipPath; - private ParserConfiguration parserConfiguration; /** @@ -70,7 +71,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { assertNotNull(configuration); this.zipPath = zipPath.normalize(); this.parserConfiguration = configuration; - Log.info("New source zip at \"%s\"", () -> this.zipPath); + Log.info("New source zip at \"%s\"", ()->this.zipPath); } /** @@ -82,7 +83,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { * @throws IOException If an error occurs while trying to parse the given source. */ public List>> parse() throws IOException { - Log.info("Parsing zip at \"%s\"", () -> zipPath); + Log.info("Parsing zip at \"%s\"", ()-> zipPath); List>> results = new ArrayList<>(); parse((path, result) -> results.add(new Pair<>(path, result))); return results; @@ -97,13 +98,14 @@ public List>> parse() throws IOException * @throws IOException If an error occurs while trying to parse the given source. */ public SourceZip parse(Callback callback) throws IOException { - Log.info("Parsing zip at \"%s\"", () -> zipPath); + Log.info("Parsing zip at \"%s\"", ()-> zipPath); JavaParser javaParser = new JavaParser(parserConfiguration); try (ZipFile zipFile = new ZipFile(zipPath.toFile())) { for (ZipEntry entry : Collections.list(zipFile.entries())) { if (!entry.isDirectory() && entry.getName().endsWith(".java")) { - Log.info("Parsing zip entry \"%s\"", () -> entry.getName()); - final ParseResult result = javaParser.parse(COMPILATION_UNIT, provider(zipFile.getInputStream(entry))); + Log.info("Parsing zip entry \"%s\"", ()-> entry.getName()); + final ParseResult result = javaParser.parse(COMPILATION_UNIT, + provider(zipFile.getInputStream(entry))); callback.process(Paths.get(entry.getName()), result); } } @@ -134,7 +136,7 @@ public interface Callback { public Path getZipPath() { return zipPath; } - + public ParserConfiguration getParserConfiguration() { return parserConfiguration; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java index e858f727f1..113612edd2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java @@ -79,15 +79,49 @@ public static String unescapeJavaTextBlock(final String input) { return UNESCAPE_JAVA_TEXT_BLOCK.translate(input); } - private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][] { { "\\b", "\b" }, { "\\n", "\n" }, { "\\t", "\t" }, { "\\f", "\f" }, { "\\r", "\r" } }); - - private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][] { { "\b", "\\b" }, { "\n", "\\n" }, { "\t", "\\t" }, { "\f", "\\f" }, { "\r", "\\r" } }); - - private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator(new LookupTranslator(new String[][] { { "\"", "\\\"" }, { "\\", "\\\\" } }), JAVA_CTRL_CHARS_ESCAPE); - - private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" } })); - - private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" }, { "\\s", " " }, { "\\\n", "" } })); + private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][]{ + {"\\b", "\b"}, + {"\\n", "\n"}, + {"\\t", "\t"}, + {"\\f", "\f"}, + {"\\r", "\r"}}); + + private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][]{ + {"\b", "\\b"}, + {"\n", "\\n"}, + {"\t", "\\t"}, + {"\f", "\\f"}, + {"\r", "\\r"}}); + + private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator( + new LookupTranslator( + new String[][]{ + {"\"", "\\\""}, + {"\\", "\\\\"}, + }), + JAVA_CTRL_CHARS_ESCAPE); + + private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator( + new OctalUnescaper(), + new UnicodeUnescaper(), + JAVA_CTRL_CHARS_UNESCAPE, + new LookupTranslator(new String[][]{ + {"\\\\", "\\"}, + {"\\\"", "\""}, + {"\\'", "'"}, + {"\\", ""}})); + + private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator( + new OctalUnescaper(), + new UnicodeUnescaper(), + JAVA_CTRL_CHARS_UNESCAPE, + new LookupTranslator(new String[][]{ + {"\\\\", "\\"}, + {"\\\"", "\""}, + {"\\'", "'"}, + {"\\", ""}, + {"\\s", " "}, + {"\\\n", ""}})); /** * Adapted from apache commons-lang3 project. @@ -187,11 +221,8 @@ private void translate(final CharSequence input, final Writer out) throws IOExce private static class LookupTranslator extends CharSequenceTranslator { private final HashMap lookupMap; - private final HashSet prefixSet; - private final int shortest; - private final int longest; /** @@ -240,6 +271,7 @@ protected int translate(final CharSequence input, final int index, final Writer for (int i = max; i >= shortest; i--) { final CharSequence subSeq = input.subSequence(index, index + i); final String result = lookupMap.get(subSeq.toString()); + if (result != null) { out.write(result); return i; @@ -286,6 +318,7 @@ protected int translate(final CharSequence input, final int index, final Writer } return 0; } + } /** @@ -307,21 +340,23 @@ private static class OctalUnescaper extends CharSequenceTranslator { */ @Override protected int translate(final CharSequence input, final int index, final Writer out) throws IOException { - // how many characters left, ignoring the first \ - final int remaining = input.length() - index - 1; + final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ final StringBuilder builder = new StringBuilder(); if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) { final int next = index + 1; final int next2 = index + 2; final int next3 = index + 3; + // we know this is good as we checked it in the if block above builder.append(input.charAt(next)); + if (remaining > 1 && isOctalDigit(input.charAt(next2))) { builder.append(input.charAt(next2)); if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) { builder.append(input.charAt(next3)); } } + out.write(Integer.parseInt(builder.toString(), 8)); return 1 + builder.length(); } @@ -372,12 +407,15 @@ protected int translate(final CharSequence input, final int index, final Writer while (index + i < input.length() && input.charAt(index + i) == 'u') { i++; } + if (index + i < input.length() && input.charAt(index + i) == '+') { i++; } + if (index + i + 4 <= input.length()) { // Get 4 hex digits final CharSequence unicode = input.subSequence(index + i, index + i + 4); + try { final int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); @@ -386,9 +424,11 @@ protected int translate(final CharSequence input, final int index, final Writer } return i + 4; } - throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + "' due to end of CharSequence"); + throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + + "' due to end of CharSequence"); } return 0; } } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java index ee71c1fd39..30796b984d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -28,7 +29,7 @@ import java.util.*; import java.util.function.Function; -import static java.util.Arrays.asList; +import static java.util.Arrays.*; /** * Any kind of utility. @@ -49,6 +50,7 @@ public class Utils { * @deprecated Renamed from {@link #EOL} to make it explicit that we're using the system's line separator. * New code should use {@link LineSeparator#SYSTEM} if referring to the current host system's line separator, * else {@link LineSeparator#CR} or {@link LineSeparator#LF} or {@link LineSeparator#CRLF} if referring to a specific style of line separator. + * */ @Deprecated public static final String SYSTEM_EOL = LineSeparator.SYSTEM.asRawString(); @@ -91,7 +93,7 @@ public static T assertPositive(T number) { public static String escapeEndOfLines(String string) { StringBuilder escapedString = new StringBuilder(); for (char c : string.toCharArray()) { - switch(c) { + switch (c) { case '\n': escapedString.append("\\n"); break; @@ -109,9 +111,11 @@ public static String readerToString(Reader reader) throws IOException { final StringBuilder result = new StringBuilder(); final char[] buffer = new char[8 * 1024]; int numChars; + while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) { result.append(buffer, 0, numChars); } + return result.toString(); } @@ -137,6 +141,7 @@ public static String screamingToCamelCase(String original) { return sb.toString(); } + /** * @param input "aCamelCaseString" * @return "A_CAMEL_CASE_STRING" @@ -194,7 +199,8 @@ private static String stringTransformer(String s, String operationDescription, F if (s.isEmpty()) { throw new IllegalArgumentException(String.format("You cannot %s an empty string", operationDescription)); } - return transformation.apply(s.substring(0, 1)) + s.substring(1); + return transformation.apply(s.substring(0, 1)) + + s.substring(1); } /** @@ -297,6 +303,7 @@ public static String removeFileExtension(String filename) { int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) return filename; + return filename.substring(0, extensionIndex); } @@ -314,6 +321,11 @@ public static String trimTrailingSpaces(String line) { * Checks, if the parent is a unary expression with a minus operator. Used to check for negative literals. */ public static boolean hasUnaryMinusAsParent(Node n) { - return n.getParentNode().filter(parent -> parent instanceof UnaryExpr).map(parent -> (UnaryExpr) parent).map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS).orElse(false); + return n.getParentNode() + .filter(parent -> parent instanceof UnaryExpr) + .map(parent -> (UnaryExpr) parent) + .map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS) + .orElse(false); } + } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java index bbe92cc14a..05c628eba4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java @@ -18,16 +18,21 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.stream.Collectors; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; -import java.util.*; -import java.util.stream.Collectors; - /** * A list that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -35,15 +40,14 @@ public class VisitorList implements List { protected List innerList; - protected final GenericVisitor hashcodeVisitor; - protected final GenericVisitor equalsVisitor; /** * Pass the visitors to use for equals and hashcode. */ - public VisitorList(GenericVisitor hashcodeVisitor, GenericVisitor equalsVisitor) { + public VisitorList(GenericVisitor hashcodeVisitor, + GenericVisitor equalsVisitor) { this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; innerList = new ArrayList<>(); @@ -62,8 +66,9 @@ public void add(int index, N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) if (add(elem)) - modified = true; + for (N elem : col) + if (add(elem)) + modified = true; return modified; } @@ -93,8 +98,9 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) if (!contains(elem)) - return false; + for (Object elem : col) + if (!contains(elem)) + return false; return true; } @@ -116,7 +122,6 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { - final Iterator itr = innerList.iterator(); @Override @@ -149,7 +154,6 @@ public ListIterator listIterator() { @Override public ListIterator listIterator(int index) { return new ListIterator() { - final ListIterator itr = innerList.listIterator(index); @Override @@ -212,8 +216,9 @@ public N remove(int index) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) if (remove(elem)) - modified = true; + for (Object elem : col) + if (remove(elem)) + modified = true; return modified; } @@ -238,7 +243,6 @@ public int size() { @Override public List subList(int fromIndex, int toIndex) { return new VisitorList(hashcodeVisitor, equalsVisitor) { - { this.innerList = VisitorList.this.innerList.subList(fromIndex, toIndex); } @@ -267,7 +271,6 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { - private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java index 8e52848fca..be790952dd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java @@ -18,6 +18,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ + package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -36,11 +37,8 @@ * by using another equals and hashcode visitor for those methods. */ public class VisitorMap implements Map { - private final Map innerMap = new HashMap<>(); - private final GenericVisitor hashcodeVisitor; - private final GenericVisitor equalsVisitor; /** @@ -50,7 +48,7 @@ public VisitorMap(GenericVisitor hashcodeVisitor, GenericVisitor< this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; } - + @Override public int size() { return innerMap.size(); @@ -82,7 +80,6 @@ public V put(N key, V value) { } private class EqualsHashcodeOverridingFacade implements Visitable { - private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -130,7 +127,9 @@ public void clear() { @Override public Set keySet() { - return innerMap.keySet().stream().map(k -> k.overridden).collect(Collectors.toSet()); + return innerMap.keySet().stream() + .map(k -> k.overridden) + .collect(Collectors.toSet()); } @Override @@ -140,6 +139,8 @@ public Collection values() { @Override public Set> entrySet() { - return innerMap.entrySet().stream().map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())).collect(Collectors.toSet()); + return innerMap.entrySet().stream() + .map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())) + .collect(Collectors.toSet()); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java index 2109a1f4fb..d6a07601e5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java @@ -18,12 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ -package com.github.javaparser.utils; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.Visitable; -import com.github.javaparser.ast.visitor.VoidVisitor; +package com.github.javaparser.utils; import java.util.Collection; import java.util.HashSet; @@ -31,6 +27,11 @@ import java.util.Set; import java.util.stream.Collectors; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + /** * A set that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -38,9 +39,7 @@ public class VisitorSet implements Set { private final Set innerSet = new HashSet<>(); - private final GenericVisitor hashcodeVisitor; - private final GenericVisitor equalsVisitor; /** @@ -59,8 +58,9 @@ public boolean add(N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) if (add(elem)) - modified = true; + for (N elem : col) + if (add(elem)) + modified = true; return modified; } @@ -76,8 +76,9 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) if (!contains(elem)) - return false; + for (Object elem : col) + if (!contains(elem)) + return false; return true; } @@ -89,7 +90,6 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { - final Iterator itr = innerSet.iterator(); @Override @@ -117,8 +117,9 @@ public boolean remove(Object elem) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) if (remove(elem)) - modified = true; + for (Object elem : col) + if (remove(elem)) + modified = true; return modified; } @@ -157,7 +158,6 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { - private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -187,4 +187,5 @@ public boolean equals(final Object obj) { return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); } } + } From b7737a037e623b9125bb1b60f10d273398f77536 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 27 Oct 2022 21:15:22 +0100 Subject: [PATCH 034/280] Executed Metamodel Core Generator and Core Generator --- javaparser-core/bnd.bnd | 1 + .../github/javaparser/CommentsInserter.java | 87 +- .../com/github/javaparser/HasParentNode.java | 19 +- .../com/github/javaparser/JavaParser.java | 24 +- .../java/com/github/javaparser/JavaToken.java | 8 +- .../com/github/javaparser/JavadocParser.java | 33 +- .../LineEndingProcessingProvider.java | 12 +- .../javaparser/ParseProblemException.java | 2 +- .../com/github/javaparser/ParseResult.java | 5 +- .../com/github/javaparser/ParseStart.java | 22 +- .../javaparser/ParserConfiguration.java | 89 +- .../java/com/github/javaparser/Position.java | 27 +- .../java/com/github/javaparser/Problem.java | 10 +- .../java/com/github/javaparser/Processor.java | 2 +- .../java/com/github/javaparser/Providers.java | 11 +- .../java/com/github/javaparser/Range.java | 19 +- .../github/javaparser/StaticJavaParser.java | 49 +- .../com/github/javaparser/TokenRange.java | 15 +- .../com/github/javaparser/TokenTypes.java | 4 +- .../UnicodeEscapeProcessingProvider.java | 1135 ++++++++--------- .../javaparser/ast/AccessSpecifier.java | 6 +- .../javaparser/ast/AllFieldsConstructor.java | 1 - .../com/github/javaparser/ast/DataKey.java | 2 +- .../com/github/javaparser/ast/Generated.java | 5 +- .../com/github/javaparser/ast/NodeList.java | 13 +- .../ast/comments/CommentsCollection.java | 26 +- .../ast/expr/ArrayCreationExpr.java | 8 +- .../ast/nodeTypes/NodeWithAnnotations.java | 17 +- .../ast/nodeTypes/NodeWithArguments.java | 3 +- .../ast/nodeTypes/NodeWithBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithBody.java | 6 +- .../ast/nodeTypes/NodeWithCondition.java | 2 +- .../ast/nodeTypes/NodeWithDeclaration.java | 1 - .../ast/nodeTypes/NodeWithExpression.java | 2 +- .../ast/nodeTypes/NodeWithExtends.java | 2 - .../ast/nodeTypes/NodeWithIdentifier.java | 2 +- .../ast/nodeTypes/NodeWithImplements.java | 14 +- .../ast/nodeTypes/NodeWithJavadoc.java | 7 +- .../ast/nodeTypes/NodeWithMembers.java | 53 +- .../ast/nodeTypes/NodeWithModifiers.java | 7 +- .../ast/nodeTypes/NodeWithName.java | 2 +- .../nodeTypes/NodeWithOptionalBlockStmt.java | 2 +- .../ast/nodeTypes/NodeWithOptionalLabel.java | 4 +- .../ast/nodeTypes/NodeWithOptionalScope.java | 3 +- .../ast/nodeTypes/NodeWithParameters.java | 27 +- .../ast/nodeTypes/NodeWithRange.java | 8 +- .../ast/nodeTypes/NodeWithScope.java | 1 - .../ast/nodeTypes/NodeWithSimpleName.java | 2 +- .../ast/nodeTypes/NodeWithStatements.java | 2 +- .../nodeTypes/NodeWithThrownExceptions.java | 2 +- .../ast/nodeTypes/NodeWithTokenRange.java | 3 +- .../nodeTypes/NodeWithTraversableScope.java | 1 - .../ast/nodeTypes/NodeWithType.java | 2 +- .../ast/nodeTypes/NodeWithTypeArguments.java | 2 +- .../ast/nodeTypes/NodeWithTypeParameters.java | 2 +- .../ast/nodeTypes/NodeWithVariables.java | 5 +- .../javaparser/ast/nodeTypes/SwitchNode.java | 4 +- .../modifiers/NodeWithAbstractModifier.java | 2 +- .../modifiers/NodeWithAccessModifiers.java | 1 - .../modifiers/NodeWithFinalModifier.java | 1 - .../modifiers/NodeWithPrivateModifier.java | 2 +- .../modifiers/NodeWithProtectedModifier.java | 2 +- .../modifiers/NodeWithPublicModifier.java | 3 +- .../modifiers/NodeWithStaticModifier.java | 2 - .../modifiers/NodeWithStrictfpModifier.java | 2 +- .../javaparser/ast/observer/AstObserver.java | 5 +- .../ast/observer/AstObserverAdapter.java | 1 - .../javaparser/ast/observer/Observable.java | 1 - .../ast/observer/PropagatingAstObserver.java | 3 +- .../github/javaparser/ast/type/ArrayType.java | 20 +- .../ast/type/ClassOrInterfaceType.java | 11 +- .../com/github/javaparser/ast/type/Type.java | 12 +- .../ast/validator/ProblemReporter.java | 2 +- .../RecordAsTypeIdentifierNotAllowed.java | 8 +- .../validator/ReservedKeywordValidator.java | 3 +- .../ast/validator/SimpleValidator.java | 2 +- .../validator/SingleNodeTypeValidator.java | 3 +- .../ast/validator/TreeVisitorValidator.java | 2 +- .../ast/validator/TypedValidator.java | 7 +- .../javaparser/ast/validator/Validator.java | 2 +- .../javaparser/ast/validator/Validators.java | 2 +- .../ast/validator/VisitorValidator.java | 2 +- .../Java10PreviewValidator.java | 10 - .../Java10Validator.java | 4 - .../Java11PreviewValidator.java | 10 - .../Java11Validator.java | 4 +- .../Java12PreviewValidator.java | 6 - .../Java12Validator.java | 3 - .../Java13PreviewValidator.java | 8 +- .../Java13Validator.java | 3 - .../Java14PreviewValidator.java | 11 +- .../Java14Validator.java | 3 - .../Java15PreviewValidator.java | 7 +- .../Java15Validator.java | 5 +- .../Java16PreviewValidator.java | 5 - .../Java16Validator.java | 5 +- .../Java17PreviewValidator.java | 5 - .../Java17Validator.java | 3 - .../Java1_0Validator.java | 121 +- .../Java1_1Validator.java | 12 +- .../Java1_2Validator.java | 3 +- .../Java1_3Validator.java | 2 +- .../Java1_4Validator.java | 2 +- .../Java5Validator.java | 7 +- .../Java6Validator.java | 4 +- .../Java7Validator.java | 7 +- .../Java8Validator.java | 22 +- .../Java9Validator.java | 11 +- .../chunks/CommonValidators.java | 76 +- .../chunks/ModifierValidator.java | 14 +- .../NoBinaryIntegerLiteralsValidator.java | 2 +- ...UnderscoresInIntegerLiteralsValidator.java | 2 +- .../chunks/RecordDeclarationValidator.java | 25 +- .../chunks/UnderscoreKeywordValidator.java | 2 +- .../chunks/VarValidator.java | 14 +- .../postprocessors/Java10PostProcessor.java | 3 +- .../postprocessors/Java11PostProcessor.java | 1 - .../postprocessors/Java12PostProcessor.java | 1 - .../postprocessors/Java13PostProcessor.java | 1 - .../postprocessors/Java14PostProcessor.java | 1 - .../postprocessors/Java15PostProcessor.java | 1 - .../postprocessors/Java16PostProcessor.java | 1 - .../postprocessors/Java17PostProcessor.java | 1 - .../postprocessors/PostProcessors.java | 2 +- .../javaparser/ast/visitor/TreeVisitor.java | 1 - .../javaparser/ast/visitor/Visitable.java | 2 +- .../github/javaparser/javadoc/Javadoc.java | 19 +- .../javaparser/javadoc/JavadocBlockTag.java | 26 +- .../description/JavadocDescription.java | 16 +- .../JavadocDescriptionElement.java | 2 +- .../javadoc/description/JavadocInlineTag.java | 27 +- .../javadoc/description/JavadocSnippet.java | 15 +- .../metamodel/BaseNodeMetaModel.java | 27 +- .../javaparser/metamodel/DerivedProperty.java | 1 - .../metamodel/InternalProperty.java | 1 - .../metamodel/NonEmptyProperty.java | 3 +- .../metamodel/OptionalProperty.java | 1 - .../metamodel/PropertyMetaModel.java | 24 +- .../printer/ConcreteSyntaxModel.java | 1054 ++------------- .../printer/DefaultPrettyPrinter.java | 32 +- .../printer/DefaultPrettyPrinterVisitor.java | 321 +---- .../github/javaparser/printer/DotPrinter.java | 38 +- .../printer/PrettyPrintVisitor.java | 280 +--- .../javaparser/printer/PrettyPrinter.java | 20 +- .../github/javaparser/printer/Printer.java | 8 +- .../javaparser/printer/SourcePrinter.java | 52 +- .../github/javaparser/printer/Stringable.java | 1 + .../github/javaparser/printer/XmlPrinter.java | 7 +- .../javaparser/printer/YamlPrinter.java | 41 +- .../concretesyntaxmodel/CsmAttribute.java | 43 +- .../printer/concretesyntaxmodel/CsmChar.java | 6 +- .../concretesyntaxmodel/CsmComment.java | 2 - .../concretesyntaxmodel/CsmConditional.java | 36 +- .../concretesyntaxmodel/CsmElement.java | 8 +- .../concretesyntaxmodel/CsmIndent.java | 1 - .../printer/concretesyntaxmodel/CsmList.java | 14 +- .../printer/concretesyntaxmodel/CsmMix.java | 10 +- .../printer/concretesyntaxmodel/CsmNone.java | 3 - .../CsmOrphanCommentsEnding.java | 5 +- .../concretesyntaxmodel/CsmSequence.java | 10 +- .../CsmSingleReference.java | 5 +- .../concretesyntaxmodel/CsmString.java | 5 +- .../concretesyntaxmodel/CsmTextBlock.java | 8 +- .../printer/concretesyntaxmodel/CsmToken.java | 28 +- .../concretesyntaxmodel/CsmUnindent.java | 1 - .../concretesyntaxmodel/PrintingHelper.java | 3 +- .../configuration/ConfigurationOption.java | 3 +- .../DefaultConfigurationOption.java | 12 +- .../DefaultPrinterConfiguration.java | 55 +- .../printer/configuration/Indentation.java | 44 +- .../PrettyPrinterConfiguration.java | 56 +- .../configuration/PrinterConfiguration.java | 5 +- .../printer/lexicalpreservation/Added.java | 31 +- .../lexicalpreservation/ChildTextElement.java | 23 +- .../lexicalpreservation/Difference.java | 265 ++-- .../DifferenceElement.java | 12 +- .../DifferenceElementCalculator.java | 91 +- .../printer/lexicalpreservation/Kept.java | 36 +- .../LexicalDifferenceCalculator.java | 92 +- .../LexicalPreservingPrinter.java | 194 +-- .../printer/lexicalpreservation/NodeText.java | 42 +- .../lexicalpreservation/PhantomNodeLogic.java | 22 +- .../printer/lexicalpreservation/Removed.java | 27 +- .../lexicalpreservation/RemovedGroup.java | 43 +- .../lexicalpreservation/Reshuffled.java | 40 +- .../lexicalpreservation/TextElement.java | 19 +- .../TextElementIteratorsFactory.java | 24 +- .../TextElementMatcher.java | 1 - .../TextElementMatchers.java | 2 +- .../lexicalpreservation/TokenTextElement.java | 22 +- .../WrappingRangeIterator.java | 3 +- .../lexicalpreservation/changes/Change.java | 3 +- .../changes/ListAdditionChange.java | 6 +- .../changes/ListRemovalChange.java | 8 +- .../changes/ListReplacementChange.java | 6 +- .../lexicalpreservation/changes/NoChange.java | 1 - .../changes/PropertyChange.java | 3 +- .../resolution/MethodAmbiguityException.java | 2 - .../javaparser/resolution/MethodUsage.java | 29 +- .../javaparser/resolution/Resolvable.java | 2 +- .../javaparser/resolution/SymbolResolver.java | 2 +- .../resolution/UnsolvedSymbolException.java | 7 +- .../declarations/AssociableToAST.java | 1 - .../declarations/HasAccessSpecifier.java | 2 - .../ResolvedAnnotationDeclaration.java | 10 +- .../ResolvedAnnotationMemberDeclaration.java | 1 - .../ResolvedClassDeclaration.java | 12 +- .../ResolvedConstructorDeclaration.java | 4 +- .../declarations/ResolvedDeclaration.java | 1 - .../ResolvedEnumConstantDeclaration.java | 1 - .../declarations/ResolvedEnumDeclaration.java | 7 +- .../ResolvedFieldDeclaration.java | 4 +- .../ResolvedInterfaceDeclaration.java | 4 +- .../ResolvedMethodDeclaration.java | 2 - .../ResolvedMethodLikeDeclaration.java | 7 +- .../ResolvedParameterDeclaration.java | 1 - .../ResolvedPatternDeclaration.java | 2 - .../ResolvedReferenceTypeDeclaration.java | 132 +- .../declarations/ResolvedTypeDeclaration.java | 22 +- .../ResolvedTypeParameterDeclaration.java | 38 +- .../ResolvedTypeParametrizable.java | 2 - .../ResolvedValueDeclaration.java | 3 - .../resolution/types/ResolvedArrayType.java | 42 +- .../types/ResolvedIntersectionType.java | 15 +- .../types/ResolvedLambdaConstraintType.java | 8 +- .../types/ResolvedPrimitiveType.java | 42 +- .../types/ResolvedReferenceType.java | 251 ++-- .../resolution/types/ResolvedType.java | 75 +- .../types/ResolvedTypeTransformer.java | 2 +- .../types/ResolvedTypeVariable.java | 35 +- .../resolution/types/ResolvedUnionType.java | 23 +- .../resolution/types/ResolvedVoidType.java | 8 +- .../resolution/types/ResolvedWildcard.java | 29 +- .../ResolvedTypeParameterValueProvider.java | 4 - .../ResolvedTypeParametersMap.java | 30 +- .../ResolvedTypeParametrized.java | 2 +- .../github/javaparser/utils/ClassUtils.java | 2 +- .../javaparser/utils/CodeGenerationUtils.java | 2 +- .../javaparser/utils/CollectionStrategy.java | 15 +- .../javaparser/utils/LineSeparator.java | 27 +- .../java/com/github/javaparser/utils/Log.java | 8 +- .../com/github/javaparser/utils/Pair.java | 18 +- .../utils/ParserCollectionStrategy.java | 3 +- .../javaparser/utils/PositionUtils.java | 52 +- .../github/javaparser/utils/ProjectRoot.java | 3 +- .../utils/SeparatedItemStringBuilder.java | 6 +- .../github/javaparser/utils/SourceRoot.java | 71 +- .../github/javaparser/utils/SourceZip.java | 16 +- .../javaparser/utils/StringEscapeUtils.java | 70 +- .../com/github/javaparser/utils/Utils.java | 20 +- .../github/javaparser/utils/VisitorList.java | 35 +- .../github/javaparser/utils/VisitorMap.java | 15 +- .../github/javaparser/utils/VisitorSet.java | 31 +- 253 files changed, 2500 insertions(+), 4512 deletions(-) diff --git a/javaparser-core/bnd.bnd b/javaparser-core/bnd.bnd index 9d1d1b49e2..9e678f6b78 100644 --- a/javaparser-core/bnd.bnd +++ b/javaparser-core/bnd.bnd @@ -29,6 +29,7 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core com.github.javaparser.printer.configuration, \ com.github.javaparser.printer.lexicalpreservation, \ com.github.javaparser.printer.lexicalpreservation.changes, \ + com.github.javaparser.quality, \ com.github.javaparser.resolution, \ com.github.javaparser.resolution.declarations, \ com.github.javaparser.resolution.types, \ diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java index f546510e54..dfdaf6ccd0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java @@ -18,17 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; -import static java.util.stream.Collectors.toList; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.TreeSet; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; @@ -36,6 +27,14 @@ import com.github.javaparser.ast.comments.LineComment; import com.github.javaparser.utils.PositionUtils; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeSet; + +import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION; +import static java.util.stream.Collectors.toList; + /** * Assigns comments to nodes of the AST. * @@ -43,6 +42,7 @@ * @author Júlio Vilmar Gesser */ class CommentsInserter { + private final ParserConfiguration configuration; CommentsInserter(ParserConfiguration configuration) { @@ -56,20 +56,14 @@ class CommentsInserter { private void insertComments(CompilationUnit cu, TreeSet comments) { if (comments.isEmpty()) return; - /* I should sort all the direct children and the comments, if a comment is the first thing then it is a comment to the CompilationUnit */ - // FIXME if there is no package it could be also a comment to the following class... // so I could use some heuristics in these cases to distinguish the two // cases - List children = cu.getChildNodes(); - Comment firstComment = comments.iterator().next(); - if (cu.getPackageDeclaration().isPresent() - && (children.isEmpty() || PositionUtils.areInOrder( - firstComment, cu.getPackageDeclaration().get()))) { + if (cu.getPackageDeclaration().isPresent() && (children.isEmpty() || PositionUtils.areInOrder(firstComment, cu.getPackageDeclaration().get()))) { cu.setComment(firstComment); comments.remove(firstComment); } @@ -82,37 +76,24 @@ private void insertComments(CompilationUnit cu, TreeSet comments) { void insertComments(Node node, TreeSet commentsToAttribute) { if (commentsToAttribute.isEmpty()) return; - if (node instanceof CompilationUnit) { insertComments((CompilationUnit) node, commentsToAttribute); } - /* the comment can... 1) be inside one of the children, then the comment should be associated to this child 2) be outside all children. They could be preceding nothing, a comment or a child. If they preceed a child they are assigned to it, otherwise they remain "orphans" */ - - List children = node.getChildNodes().stream() - // Never attribute comments to modifiers. - .filter(n -> !(n instanceof Modifier)) - .collect(toList()); - + List children = node.getChildNodes().stream().// Never attribute comments to modifiers. + filter(n -> !(n instanceof Modifier)).collect(toList()); boolean attributeToAnnotation = !(configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node child : children) { TreeSet commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION); - commentsInsideChild.addAll( - commentsToAttribute.stream() - .filter(comment -> comment.hasRange()) - .filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)) - .collect(toList()) - ); + commentsInsideChild.addAll(commentsToAttribute.stream().filter(comment -> comment.hasRange()).filter(comment -> PositionUtils.nodeContains(child, comment, !attributeToAnnotation)).collect(toList())); commentsToAttribute.removeAll(commentsInsideChild); insertComments(child, commentsInsideChild); } - attributeLineCommentsOnSameLine(commentsToAttribute, children); - /* if a comment is on the line right before a node it should belong to that node*/ if (!commentsToAttribute.isEmpty()) { @@ -121,7 +102,6 @@ void insertComments(Node node, TreeSet commentsToAttribute) { commentsToAttribute.remove(commentsToAttribute.first()); } } - /* at this point I create an ordered list of all remaining comments and children */ Comment previousComment = null; @@ -130,11 +110,8 @@ void insertComments(Node node, TreeSet commentsToAttribute) { // Avoid attributing comments to a meaningless container. childrenAndComments.addAll(children); commentsToAttribute.removeAll(attributedComments); - childrenAndComments.addAll(commentsToAttribute); - PositionUtils.sortByBeginPosition(childrenAndComments, - configuration.isIgnoreAnnotationsWhenAttributingComments()); - + PositionUtils.sortByBeginPosition(childrenAndComments, configuration.isIgnoreAnnotationsWhenAttributingComments()); for (Node thing : childrenAndComments) { if (thing instanceof Comment) { previousComment = (Comment) thing; @@ -143,8 +120,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } else { if (previousComment != null && !thing.getComment().isPresent()) { - if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() - || !thereAreLinesBetween(previousComment, thing)) { + if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines() || !thereAreLinesBetween(previousComment, thing)) { thing.setComment(previousComment); attributedComments.add(previousComment); previousComment = null; @@ -152,9 +128,7 @@ void insertComments(Node node, TreeSet commentsToAttribute) { } } } - commentsToAttribute.removeAll(attributedComments); - // all the remaining are orphan nodes for (Comment c : commentsToAttribute) { if (c.isOrphan()) { @@ -167,20 +141,13 @@ private void attributeLineCommentsOnSameLine(TreeSet commentsToAttribut /* I can attribute in line comments to elements preceeding them, if there is something contained in their line */ List attributedComments = new LinkedList<>(); - commentsToAttribute.stream() - .filter(comment -> comment.hasRange()) - .filter(Comment::isLineComment) - .forEach(comment -> children.stream() - .filter(child -> child.hasRange()) - .forEach(child -> { - Range commentRange = comment.getRange().get(); - Range childRange = child.getRange().get(); - if (childRange.end.line == commentRange.begin.line - && attributeLineCommentToNodeOrChild(child, - comment.asLineComment())) { - attributedComments.add(comment); - } - })); + commentsToAttribute.stream().filter(comment -> comment.hasRange()).filter(Comment::isLineComment).forEach(comment -> children.stream().filter(child -> child.hasRange()).forEach(child -> { + Range commentRange = comment.getRange().get(); + Range childRange = child.getRange().get(); + if (childRange.end.line == commentRange.begin.line && attributeLineCommentToNodeOrChild(child, comment.asLineComment())) { + attributedComments.add(comment); + } + })); commentsToAttribute.removeAll(attributedComments); } @@ -188,11 +155,9 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom if (!node.hasRange() || !lineComment.hasRange()) { return false; } - // The node start and end at the same line as the comment, // let's give to it the comment - if (node.getBegin().get().line == lineComment.getBegin().get().line - && !node.getComment().isPresent()) { + if (node.getBegin().get().line == lineComment.getBegin().get().line && !node.getComment().isPresent()) { if (!(node instanceof Comment)) { node.setComment(lineComment); } @@ -204,13 +169,11 @@ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineCom children.addAll(node.getChildNodes()); PositionUtils.sortByBeginPosition(children); Collections.reverse(children); - for (Node child : children) { if (attributeLineCommentToNodeOrChild(child, lineComment)) { return true; } } - return false; } @@ -226,8 +189,8 @@ private boolean thereAreLinesBetween(Node a, Node b) { } private boolean commentIsOnNextLine(Node a, Comment c) { - if (!c.hasRange() || !a.hasRange()) return false; + if (!c.hasRange() || !a.hasRange()) + return false; return c.getRange().get().end.line + 1 == a.getRange().get().begin.line; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java index a0fbd28582..cde44d20f2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -18,16 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.observer.Observable; + import java.util.Arrays; import java.util.Optional; import java.util.function.Predicate; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.observer.Observable; - /** * An object that can have a parent node. */ @@ -39,7 +38,7 @@ public interface HasParentNode extends Observable { default boolean hasParentNode() { return getParentNode().isPresent(); } - + /** * Returns the parent node, or {@code Optional.empty} if no parent is set. */ @@ -82,7 +81,7 @@ default Optional findAncestor(Class... types) { default Optional findAncestor(Class type, Predicate predicate) { return findAncestor(predicate, type); } - + /** * Walks the parents of this node and returns the first node that matches one of types {@code types}, or * {@code empty()} if none is found. The given type may also be an interface type, such as one of the @@ -90,11 +89,10 @@ default Optional findAncestor(Class type, Predicate predicate) { * @param */ default Optional findAncestor(Predicate predicate, Class... types) { - if (!hasParentNode()) return Optional.empty(); + if (!hasParentNode()) + return Optional.empty(); Node parent = getParentNode().get(); - Optional> oType = Arrays.stream(types) - .filter(type -> type.isAssignableFrom(parent.getClass()) && predicate.test(type.cast(parent))) - .findFirst(); + Optional> oType = Arrays.stream(types).filter(type -> type.isAssignableFrom(parent.getClass()) && predicate.test(type.cast(parent))).findFirst(); if (oType.isPresent()) { return Optional.of(oType.get().cast(parent)); } @@ -112,5 +110,4 @@ default Optional findAncestor(Predicate predicate, Class... types) default boolean isDescendantOf(Node ancestor) { return findAncestor(n -> n == ancestor, Node.class).isPresent(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java index 798fb4965f..3bcf5f909e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -44,13 +43,13 @@ import java.nio.file.Path; import java.util.List; import java.util.function.Supplier; -import java.util.stream.Collectors; import static com.github.javaparser.ParseStart.*; import static com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION; -import static com.github.javaparser.Providers.*; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.Providers.resourceProvider; import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.*; +import static java.util.stream.Collectors.toList; /** * Parse Java source code and creates Abstract Syntax Trees. @@ -59,6 +58,7 @@ * @see StaticJavaParser */ public final class JavaParser { + private final ParserConfiguration configuration; private GeneratedJavaParser astParser = null; @@ -94,10 +94,9 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { } astParser.setTabSize(configuration.getTabSize()); astParser.setStoreTokens(configuration.isStoreTokens()); - ParserConfiguration.LanguageLevel languageLevel = configuration.getLanguageLevel(); if (languageLevel != null) { - if(languageLevel.isYieldSupported()) { + if (languageLevel.isYieldSupported()) { astParser.setYieldSupported(); } } @@ -117,25 +116,18 @@ private GeneratedJavaParser getParserForProvider(Provider provider) { public ParseResult parse(ParseStart start, Provider provider) { assertNotNull(start); assertNotNull(provider); - List processors = configuration.getProcessors().stream().map(Supplier::get).collect(toList()); - for (Processor processor : processors) { provider = processor.preProcess(provider); } - final GeneratedJavaParser parser = getParserForProvider(provider); try { N resultNode = start.parse(parser); ParseResult result = new ParseResult<>(resultNode, parser.problems, parser.getCommentsCollection()); - for (Processor processor : processors) { - processor.postProcess(result, configuration); + processor.postProcess(result, configuration); } - - result.getProblems() - .sort(PROBLEM_BY_BEGIN_POSITION); - + result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION); return result; } catch (Exception e) { final String message = e.getMessage() == null ? "Unknown error" : e.getMessage(); @@ -523,7 +515,6 @@ public ParseResult parseModuleDirective(String moduleDirective) return parse(MODULE_DIRECTIVE, provider(moduleDirective)); } - /** * Parses a type parameter and returns it as a TypeParameter * @@ -546,5 +537,4 @@ public ParseResult parseTypeParameter(String typeParameter) { public ParseResult parseMethodDeclaration(String methodDeclaration) { return parse(METHOD_DECLARATION, provider(methodDeclaration)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java b/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java index 69567f9046..fe80909ffb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java @@ -20,14 +20,14 @@ */ package com.github.javaparser; -import static com.github.javaparser.utils.CodeGenerationUtils.f; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static com.github.javaparser.utils.Utils.assertNotNull; +import com.github.javaparser.ast.Generated; import java.util.List; import java.util.Optional; -import com.github.javaparser.ast.Generated; +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; /** * A token from a parsed source file. diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java index 3cd5eec477..5286cc2a0f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.JavadocBlockTag; import com.github.javaparser.javadoc.description.JavadocDescription; + import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -40,6 +40,7 @@ class JavadocParser { private static String BLOCK_TAG_PREFIX = "@"; + private static Pattern BLOCK_PATTERN = Pattern.compile("^\\s*" + BLOCK_TAG_PREFIX, Pattern.MULTILINE); public static Javadoc parse(JavadocComment comment) { @@ -48,11 +49,7 @@ public static Javadoc parse(JavadocComment comment) { public static Javadoc parse(String commentContent) { List cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, SYSTEM_EOL)); - int indexOfFirstBlockTag = cleanLines.stream() - .filter(JavadocParser::isABlockLine) - .map(cleanLines::indexOf) - .findFirst() - .orElse(-1); + int indexOfFirstBlockTag = cleanLines.stream().filter(JavadocParser::isABlockLine).map(cleanLines::indexOf).findFirst().orElse(-1); List blockLines; String descriptionText; if (indexOfFirstBlockTag == -1) { @@ -60,21 +57,13 @@ public static Javadoc parse(String commentContent) { blockLines = Collections.emptyList(); } else { descriptionText = trimRight(String.join(SYSTEM_EOL, cleanLines.subList(0, indexOfFirstBlockTag))); - - //Combine cleaned lines, but only starting with the first block tag till the end - //In this combined string it is easier to handle multiple lines which actually belong together - String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()) - .stream() - .collect(Collectors.joining(SYSTEM_EOL)); - - //Split up the entire tag back again, considering now that some lines belong to the same block tag. - //The pattern splits the block at each new line starting with the '@' symbol, thus the symbol - //then needs to be added again so that the block parsers handles everything correctly. - blockLines = BLOCK_PATTERN - .splitAsStream(tagBlock) - .filter(s1 -> !s1.isEmpty()) - .map(s -> BLOCK_TAG_PREFIX + s) - .collect(Collectors.toList()); + // Combine cleaned lines, but only starting with the first block tag till the end + // In this combined string it is easier to handle multiple lines which actually belong together + String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()).stream().collect(Collectors.joining(SYSTEM_EOL)); + // Split up the entire tag back again, considering now that some lines belong to the same block tag. + // The pattern splits the block at each new line starting with the '@' symbol, thus the symbol + // then needs to be added again so that the block parsers handles everything correctly. + blockLines = BLOCK_PATTERN.splitAsStream(tagBlock).filter(s1 -> !s1.isEmpty()).map(s -> BLOCK_TAG_PREFIX + s).collect(Collectors.toList()); } Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText)); blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l))); @@ -104,7 +93,6 @@ private static List cleanLines(String content) { if (lines.length == 0) { return Collections.emptyList(); } - List cleanedLines = Arrays.stream(lines).map(l -> { int asteriskIndex = startsWithAsterisk(l); if (asteriskIndex == -1) { @@ -113,7 +101,6 @@ private static List cleanLines(String content) { // if a line starts with space followed by an asterisk drop to the asterisk // if there is a space immediately after the asterisk drop it also if (l.length() > (asteriskIndex + 1)) { - char c = l.charAt(asteriskIndex + 1); if (c == ' ' || c == '\t') { return l.substring(asteriskIndex + 2); diff --git a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java index 7269ba06be..075187ae7e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/LineEndingProcessingProvider.java @@ -82,11 +82,7 @@ private int fillBuffer() throws IOException { } public LineSeparator getDetectedLineEnding() { - return LineSeparator.getLineEnding( - eolCounts.getOrDefault(LineSeparator.CR, 0), - eolCounts.getOrDefault(LineSeparator.LF, 0), - eolCounts.getOrDefault(LineSeparator.CRLF, 0) - ); + return LineSeparator.getLineEnding(eolCounts.getOrDefault(LineSeparator.CR, 0), eolCounts.getOrDefault(LineSeparator.LF, 0), eolCounts.getOrDefault(LineSeparator.CRLF, 0)); } private boolean isBufferEmpty() { @@ -125,14 +121,11 @@ public int read(char[] buffer, final int offset, int len) throws IOException { } else { String str = String.valueOf((char) ch); Optional lookup = LineSeparator.lookup(str); - if (lookup.isPresent()) { LineSeparator lineSeparator = lookup.get(); - // Track the number of times this character is found.. eolCounts.putIfAbsent(lineSeparator, 0); eolCounts.put(lineSeparator, eolCounts.get(lineSeparator) + 1); - // Handle line separators of length two (specifically CRLF) // TODO: Make this more generic than just CRLF (e.g. track the previous char rather than the previous line separator if (lineSeparator == LineSeparator.LF) { @@ -141,19 +134,16 @@ public int read(char[] buffer, final int offset, int len) throws IOException { eolCounts.put(LineSeparator.CRLF, eolCounts.get(LineSeparator.CRLF) + 1); } } - // If "this" (current) char is a line separator, set the next loop's "previous" to this previousLineSeparator = lineSeparator; } else { // If "this" (current) char is not a line separator, set the next loop's "previous" to null previousLineSeparator = null; } - // Move to next character buffer[pos++] = (char) ch; } } return pos - offset; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java index dba1fe596b..4b4c390022 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import java.util.List; @@ -31,6 +30,7 @@ * Thrown when parsing problems occur during parsing with the static methods on JavaParser. */ public class ParseProblemException extends RuntimeException { + /** * The problems that were encountered during parsing */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java index 79b27d4ff4..99639258d4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.comments.CommentsCollection; @@ -33,8 +32,11 @@ * The results given when parsing with an instance of JavaParser. */ public class ParseResult { + private final T result; + private final List problems; + private final CommentsCollection commentsCollection; /** @@ -104,5 +106,4 @@ public String toString() { } return message.toString(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java index 179f06f6fa..ae7b375418 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -49,26 +48,47 @@ */ @FunctionalInterface public interface ParseStart { + ParseStart COMPILATION_UNIT = GeneratedJavaParser::CompilationUnit; + ParseStart BLOCK = GeneratedJavaParser::BlockParseStart; + ParseStart STATEMENT = GeneratedJavaParser::BlockStatementParseStart; + ParseStart IMPORT_DECLARATION = GeneratedJavaParser::ImportDeclarationParseStart; + ParseStart EXPRESSION = GeneratedJavaParser::ExpressionParseStart; + ParseStart ANNOTATION = GeneratedJavaParser::AnnotationParseStart; + ParseStart> ANNOTATION_BODY = GeneratedJavaParser::AnnotationBodyDeclarationParseStart; + ParseStart> CLASS_BODY = GeneratedJavaParser::ClassOrInterfaceBodyDeclarationParseStart; + ParseStart CLASS_OR_INTERFACE_TYPE = GeneratedJavaParser::ClassOrInterfaceTypeParseStart; + ParseStart TYPE = GeneratedJavaParser::ResultTypeParseStart; + ParseStart TYPE_PARAMETER = GeneratedJavaParser::TypeParameterParseStart; + ParseStart VARIABLE_DECLARATION_EXPR = GeneratedJavaParser::VariableDeclarationExpressionParseStart; + ParseStart EXPLICIT_CONSTRUCTOR_INVOCATION_STMT = GeneratedJavaParser::ExplicitConstructorInvocationParseStart; + ParseStart NAME = GeneratedJavaParser::NameParseStart; + ParseStart SIMPLE_NAME = GeneratedJavaParser::SimpleNameParseStart; + ParseStart PARAMETER = GeneratedJavaParser::ParameterParseStart; + ParseStart PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart; + ParseStart> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart; + ParseStart MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart; + ParseStart MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart; + ParseStart METHOD_DECLARATION = GeneratedJavaParser::MethodDeclarationParseStart; R parse(GeneratedJavaParser parser) throws ParseException; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java index 3309632a78..e6051ef74e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.UnicodeEscapeProcessingProvider.PositionMapping; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.validator.*; +import com.github.javaparser.ast.validator.ProblemReporter; +import com.github.javaparser.ast.validator.Validator; import com.github.javaparser.ast.validator.language_level_validations.*; import com.github.javaparser.ast.validator.postprocessors.*; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; @@ -48,6 +48,7 @@ public class ParserConfiguration { public enum LanguageLevel { + /** * Java 1.0 */ @@ -171,29 +172,27 @@ public enum LanguageLevel { * Does no post processing or validation. Only for people wanting the fastest parsing. */ public static LanguageLevel RAW = null; + /** * The most used Java version. */ public static LanguageLevel POPULAR = JAVA_11; + /** * The latest Java version that is available. */ public static LanguageLevel CURRENT = JAVA_16; + /** * The newest Java features supported. */ public static LanguageLevel BLEEDING_EDGE = JAVA_17_PREVIEW; final Validator validator; + final PostProcessors postProcessor; - private static final LanguageLevel[] yieldSupport = new LanguageLevel[]{ - JAVA_13, JAVA_13_PREVIEW, - JAVA_14, JAVA_14_PREVIEW, - JAVA_15, JAVA_15_PREVIEW, - JAVA_16, JAVA_16_PREVIEW, - JAVA_17, JAVA_17_PREVIEW - }; + private static final LanguageLevel[] yieldSupport = new LanguageLevel[] { JAVA_13, JAVA_13_PREVIEW, JAVA_14, JAVA_14_PREVIEW, JAVA_15, JAVA_15_PREVIEW, JAVA_16, JAVA_16_PREVIEW, JAVA_17, JAVA_17_PREVIEW }; LanguageLevel(Validator validator, PostProcessors postProcessor) { this.validator = validator; @@ -205,23 +204,33 @@ public boolean isYieldSupported() { } } - // TODO: Add a configurable option e.g. setDesiredLineEnding(...) to replace/swap out existing line endings private boolean detectOriginalLineSeparator = true; + private boolean storeTokens = true; + private boolean attributeComments = true; + private boolean doNotAssignCommentsPrecedingEmptyLines = true; + private boolean ignoreAnnotationsWhenAttributingComments = false; + private boolean lexicalPreservationEnabled = false; + private boolean preprocessUnicodeEscapes = false; + private SymbolResolver symbolResolver = null; + private int tabSize = 1; + private LanguageLevel languageLevel = POPULAR; + private Charset characterEncoding = Providers.UTF8; private final List> processors = new ArrayList<>(); private class UnicodeEscapeProcessor extends Processor { + private UnicodeEscapeProcessingProvider _unicodeDecoder; @Override @@ -236,21 +245,18 @@ public Provider preProcess(Provider innerProvider) { @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { if (isPreprocessUnicodeEscapes()) { - result.getResult().ifPresent( - root -> { - PositionMapping mapping = _unicodeDecoder.getPositionMapping(); - if (!mapping.isEmpty()) { - root.walk( - node -> node.getRange().ifPresent( - range -> node.setRange(mapping.transform(range)))); - } - } - ); + result.getResult().ifPresent(root -> { + PositionMapping mapping = _unicodeDecoder.getPositionMapping(); + if (!mapping.isEmpty()) { + root.walk(node -> node.getRange().ifPresent(range -> node.setRange(mapping.transform(range)))); + } + }); } } } private class LineEndingProcessor extends Processor { + private LineEndingProcessingProvider _lineEndingProcessingProvider; @Override @@ -265,39 +271,32 @@ public Provider preProcess(Provider innerProvider) { @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { if (isDetectOriginalLineSeparator()) { - result.getResult().ifPresent( - rootNode -> { - LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); - - // Set the line ending on the root node - rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); - -// // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" -// rootNode.findAll(Node.class) -// .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); - } - ); + result.getResult().ifPresent(rootNode -> { + LineSeparator detectedLineSeparator = _lineEndingProcessingProvider.getDetectedLineEnding(); + // Set the line ending on the root node + rootNode.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator); + // // Set the line ending on all children of the root node -- FIXME: Should ignore """textblocks""" + // rootNode.findAll(Node.class) + // .forEach(node -> node.setData(Node.LINE_SEPARATOR_KEY, detectedLineSeparator)); + }); } } } - public ParserConfiguration() { processors.add(() -> ParserConfiguration.this.new UnicodeEscapeProcessor()); - processors.add(() -> ParserConfiguration.this.new LineEndingProcessor()); - processors.add(() -> new Processor() { + @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { if (configuration.isAttributeComments()) { - result.ifSuccessful(resultNode -> result - .getCommentsCollection().ifPresent(comments -> - new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); + result.ifSuccessful(resultNode -> result.getCommentsCollection().ifPresent(comments -> new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments()))); } } }); processors.add(() -> new Processor() { + @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { LanguageLevel languageLevel = getLanguageLevel(); @@ -312,17 +311,18 @@ public void postProcess(ParseResult result, ParserConfiguration } }); processors.add(() -> new Processor() { + @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { - configuration.getSymbolResolver().ifPresent(symbolResolver -> - result.ifSuccessful(resultNode -> { - if (resultNode instanceof CompilationUnit) { - resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); - } - })); + configuration.getSymbolResolver().ifPresent(symbolResolver -> result.ifSuccessful(resultNode -> { + if (resultNode instanceof CompilationUnit) { + resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver); + } + })); } }); processors.add(() -> new Processor() { + @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { if (configuration.isLexicalPreservationEnabled()) { @@ -466,5 +466,4 @@ public ParserConfiguration setCharacterEncoding(Charset characterEncoding) { this.characterEncoding = characterEncoding; return this; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index c31c5cd2fb..6bb18ff941 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -18,11 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import com.github.javaparser.ast.Node; - import java.util.Objects; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -31,23 +28,26 @@ * A position in a source file. Lines and columns start counting at 1. */ public class Position implements Comparable { + public final int line; + public final int column; /** * The first line -- note that it is 1-indexed (i.e. the first line is line 1, as opposed to 0) */ public static final int FIRST_LINE = 1; + /** * The first column -- note that it is 1-indexed (i.e. the first column is column 1, as opposed to 0) */ public static final int FIRST_COLUMN = 1; + /** * The first position in the file. */ public static final Position HOME = new Position(FIRST_LINE, FIRST_COLUMN); - /** * Line numbers must be positive, thus */ @@ -55,7 +55,6 @@ public class Position implements Comparable { public static final int ABSOLUTE_END_LINE = -2; - /** * TODO: Do we refer to the characters as columns, * ...or the spaces between (thus also before/after) characters as columns? @@ -67,8 +66,8 @@ public Position(int line, int column) { } if (column < -1) { // TODO: This allows/permits column 0, which seemingly contradicts first column being 1 - // ... (see also nextLine() which indicates 1 being the first column of the next line) - // ... (see also valid() which requires a column > 0) + // ... (see also nextLine() which indicates 1 being the first column of the next line) + // ... (see also valid() which requires a column > 0) // TODO: Maybe we need an "ABSOLUTE_BEGIN_LINE" and "ABSOLUTE_END_LINE"? throw new IllegalArgumentException("Can't position at column " + column); } @@ -140,7 +139,7 @@ public boolean invalid() { public Position orIfInvalid(Position alternativePosition) { assertNotNull(alternativePosition); // TODO: Why the || ? - // ... It seems that if both this and the alternative are invalid, then we return this..? + // ... It seems that if both this and the alternative are invalid, then we return this..? if (valid() || alternativePosition.invalid()) { return this; } @@ -159,7 +158,6 @@ public boolean isAfter(Position otherPosition) { return column > otherPosition.column; } return false; - } public boolean isAfterOrEqual(Position otherPosition) { @@ -200,13 +198,12 @@ public int compareTo(Position otherPosition) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Position otherPosition = (Position) o; - - return Objects.equals(line, otherPosition.line) - && Objects.equals(column, otherPosition.column); + return Objects.equals(line, otherPosition.line) && Objects.equals(column, otherPosition.column); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/Problem.java b/javaparser-core/src/main/java/com/github/javaparser/Problem.java index 51af761266..b80187463c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Problem.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Problem.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import java.util.Comparator; @@ -31,13 +30,15 @@ * A problem that was encountered during parsing. */ public class Problem { + private final String message; + private final TokenRange location; + private final Throwable cause; public Problem(String message, TokenRange location, Throwable cause) { assertNotNull(message); - this.message = message; this.location = location; this.cause = cause; @@ -90,9 +91,8 @@ public Optional getCause() { * Sorts problems on position. */ public static Comparator PROBLEM_BY_BEGIN_POSITION = (a, b) -> { - final Optional aBegin= a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); + final Optional aBegin = a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); final Optional bBegin = b.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin)); - if (aBegin.isPresent() && bBegin.isPresent()) { return aBegin.get().compareTo(bBegin.get()); } @@ -104,6 +104,4 @@ public Optional getCause() { } return 0; }; - - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Processor.java b/javaparser-core/src/main/java/com/github/javaparser/Processor.java index eb693373e3..2230000033 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Processor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Processor.java @@ -3,11 +3,11 @@ import com.github.javaparser.ast.Node; public class Processor { + /** * Makes the parser do a post-parsing step before the result is returned to the user. */ public void postProcess(ParseResult result, ParserConfiguration configuration) { - } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/Providers.java b/javaparser-core/src/main/java/com/github/javaparser/Providers.java index 10858c51d8..985c85f1da 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Providers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Providers.java @@ -18,15 +18,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; +import java.io.*; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -38,6 +32,7 @@ * use UTF-8. */ public final class Providers { + public static final Charset UTF8 = Charset.forName("utf-8"); private Providers() { @@ -83,7 +78,6 @@ public static Provider provider(String source) { return new StringProvider(assertNotNull(source)); } - /** * Provide a Provider from the resource found in class loader with the provided encoding.
As resource is * accessed through a class loader, a leading "/" is not allowed in pathToResource @@ -112,5 +106,4 @@ public static Provider resourceProvider(String pathToResource, Charset encoding) public static Provider resourceProvider(String pathToResource) throws IOException { return resourceProvider(pathToResource, UTF8); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Range.java b/javaparser-core/src/main/java/com/github/javaparser/Range.java index 595cd9ac43..88e345f0e2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Range.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Range.java @@ -18,14 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; /** * A range of characters in a source file, from "begin" to "end", including the characters at "begin" and "end". */ public class Range { + public final Position begin; + public final Position end; /** @@ -44,7 +45,6 @@ public Range(Position begin, Position end) { if (end == null) { throw new IllegalArgumentException("end can't be null"); } - // Force `begin` to be the position that is earliest within the document: if (begin.isBefore(end)) { this.begin = begin; @@ -116,7 +116,6 @@ public Range withEndLine(int endLine) { return range(begin, end.withLine(endLine)); } - /** * @param begin The value used to replace the current begin position. * @return A copy of this `Range` object, but with the begin position replaced with the given position. @@ -191,8 +190,7 @@ public boolean strictlyContains(Position position) { * Range 2: CDE */ public boolean overlapsWith(Range other) { - return (contains(other.begin) || contains(other.end)) || - (other.contains(begin) || other.contains(end)); + return (contains(other.begin) || contains(other.end)) || (other.contains(begin) || other.contains(end)); } /** @@ -202,7 +200,7 @@ public boolean overlapsWith(Range other) { public boolean isBefore(Position position) { return end.isBefore(position); } - + /** * @param other The range to compare against. * @return True if the end of this range is before (but not equal to) the given position to compare against. @@ -218,7 +216,7 @@ public boolean isBefore(Range other) { public boolean isAfter(Position position) { return begin.isAfter(position); } - + /** * @param other The range to compare against. * @return True if the start of this range is after (but not equal to) the given position to compare against. @@ -229,9 +227,10 @@ public boolean isAfter(Range other) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Range range = (Range) o; return begin.equals(range.begin) && end.equals(range.end); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java index 6078903276..3106e59bb7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.ast.CompilationUnit; @@ -40,6 +39,7 @@ import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.quality.NotNull; +import com.github.javaparser.quality.Preconditions; import java.io.*; import java.nio.charset.Charset; @@ -49,7 +49,7 @@ * A simpler, static API than {@link JavaParser}. */ public final class StaticJavaParser { - + // use ThreadLocal to resolve possible concurrency issues. private static ThreadLocal localConfiguration = ThreadLocal.withInitial(() -> new ParserConfiguration()); @@ -78,6 +78,7 @@ public static ParserConfiguration getParserConfiguration() { * This is a STATIC field, so modifying it will directly change how all static parse... methods work! */ public static void setConfiguration(@NotNull ParserConfiguration configuration) { + Preconditions.checkNotNull(configuration, "Parameter configuration can't be null."); localConfiguration.set(configuration); } @@ -97,6 +98,8 @@ private static JavaParser newParser() { */ @Deprecated public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Charset encoding) { + Preconditions.checkNotNull(in, "Parameter in can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(in, encoding)); } @@ -109,6 +112,7 @@ public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Char * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final InputStream in) { + Preconditions.checkNotNull(in, "Parameter in can't be null."); return handleResult(newParser().parse(in)); } @@ -125,6 +129,8 @@ public static CompilationUnit parse(@NotNull final InputStream in) { */ @Deprecated public static CompilationUnit parse(@NotNull final File file, @NotNull final Charset encoding) throws FileNotFoundException { + Preconditions.checkNotNull(file, "Parameter file can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(file, encoding)); } @@ -138,6 +144,7 @@ public static CompilationUnit parse(@NotNull final File file, @NotNull final Cha * @throws FileNotFoundException the file was not found */ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoundException { + Preconditions.checkNotNull(file, "Parameter file can't be null."); return handleResult(newParser().parse(file)); } @@ -154,6 +161,8 @@ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoun */ @Deprecated public static CompilationUnit parse(@NotNull final Path path, @NotNull final Charset encoding) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parse(path, encoding)); } @@ -167,6 +176,7 @@ public static CompilationUnit parse(@NotNull final Path path, @NotNull final Cha * @throws IOException the path could not be accessed */ public static CompilationUnit parse(@NotNull final Path path) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parse(path)); } @@ -181,6 +191,7 @@ public static CompilationUnit parse(@NotNull final Path path) throws IOException * @throws IOException the path could not be accessed */ public static CompilationUnit parseResource(@NotNull final String path) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); return handleResult(newParser().parseResource(path)); } @@ -198,6 +209,8 @@ public static CompilationUnit parseResource(@NotNull final String path) throws I */ @Deprecated public static CompilationUnit parseResource(@NotNull final String path, @NotNull Charset encoding) throws IOException { + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parseResource(path, encoding)); } @@ -214,9 +227,10 @@ public static CompilationUnit parseResource(@NotNull final String path, @NotNull * @deprecated set the encoding in the {@link ParserConfiguration} */ @Deprecated - public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, - @NotNull final String path, - @NotNull Charset encoding) throws IOException { + public static CompilationUnit parseResource(@NotNull final ClassLoader classLoader, @NotNull final String path, @NotNull Charset encoding) throws IOException { + Preconditions.checkNotNull(classLoader, "Parameter classLoader can't be null."); + Preconditions.checkNotNull(path, "Parameter path can't be null."); + Preconditions.checkNotNull(encoding, "Parameter encoding can't be null."); return handleResult(newParser().parseResource(classLoader, path, encoding)); } @@ -229,6 +243,7 @@ public static CompilationUnit parseResource(@NotNull final ClassLoader classLoad * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull final Reader reader) { + Preconditions.checkNotNull(reader, "Parameter reader can't be null."); return handleResult(newParser().parse(reader)); } @@ -241,6 +256,7 @@ public static CompilationUnit parse(@NotNull final Reader reader) { * @throws ParseProblemException if the source code has parser errors */ public static CompilationUnit parse(@NotNull String code) { + Preconditions.checkNotNull(code, "Parameter code can't be null."); return handleResult(newParser().parse(code)); } @@ -253,6 +269,7 @@ public static CompilationUnit parse(@NotNull String code) { * @throws ParseProblemException if the source code has parser errors */ public static BlockStmt parseBlock(@NotNull final String blockStatement) { + Preconditions.checkNotNull(blockStatement, "Parameter blockStatement can't be null."); return handleResult(newParser().parseBlock(blockStatement)); } @@ -265,6 +282,7 @@ public static BlockStmt parseBlock(@NotNull final String blockStatement) { * @throws ParseProblemException if the source code has parser errors */ public static Statement parseStatement(@NotNull final String statement) { + Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseStatement(statement)); } @@ -284,6 +302,7 @@ private static T handleResult(ParseResult result) { * @throws ParseProblemException if the source code has parser errors */ public static ImportDeclaration parseImport(@NotNull final String importDeclaration) { + Preconditions.checkNotNull(importDeclaration, "Parameter importDeclaration can't be null."); return handleResult(newParser().parseImport(importDeclaration)); } @@ -296,6 +315,7 @@ public static ImportDeclaration parseImport(@NotNull final String importDeclarat * @throws ParseProblemException if the source code has parser errors */ public static T parseExpression(@NotNull final String expression) { + Preconditions.checkNotNull(expression, "Parameter expression can't be null."); return handleResult(newParser().parseExpression(expression)); } @@ -308,6 +328,7 @@ public static T parseExpression(@NotNull final String exp * @throws ParseProblemException if the source code has parser errors */ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { + Preconditions.checkNotNull(annotation, "Parameter annotation can't be null."); return handleResult(newParser().parseAnnotation(annotation)); } @@ -320,6 +341,7 @@ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final String body) { + Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseAnnotationBodyDeclaration(body)); } @@ -332,6 +354,7 @@ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final S * @throws ParseProblemException if the source code has parser errors */ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { + Preconditions.checkNotNull(body, "Parameter body can't be null."); return handleResult(newParser().parseBodyDeclaration(body)); } @@ -343,6 +366,7 @@ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { * @throws ParseProblemException if the source code has parser errors */ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String type) { + Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseClassOrInterfaceType(type)); } @@ -354,6 +378,7 @@ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String typ * @throws ParseProblemException if the source code has parser errors */ public static Type parseType(@NotNull String type) { + Preconditions.checkNotNull(type, "Parameter type can't be null."); return handleResult(newParser().parseType(type)); } @@ -366,6 +391,7 @@ public static Type parseType(@NotNull String type) { * @throws ParseProblemException if the source code has parser errors */ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull String declaration) { + Preconditions.checkNotNull(declaration, "Parameter declaration can't be null."); return handleResult(newParser().parseVariableDeclarationExpr(declaration)); } @@ -378,6 +404,7 @@ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull Stri * @throws ParseProblemException if the source code has parser errors */ public static Javadoc parseJavadoc(@NotNull String content) { + Preconditions.checkNotNull(content, "Parameter content can't be null."); return JavadocParser.parse(content); } @@ -389,6 +416,7 @@ public static Javadoc parseJavadoc(@NotNull String content) { * @throws ParseProblemException if the source code has parser errors */ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(@NotNull String statement) { + Preconditions.checkNotNull(statement, "Parameter statement can't be null."); return handleResult(newParser().parseExplicitConstructorInvocationStmt(statement)); } @@ -400,6 +428,7 @@ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocati * @throws ParseProblemException if the source code has parser errors */ public static Name parseName(@NotNull String qualifiedName) { + Preconditions.checkNotNull(qualifiedName, "Parameter qualifiedName can't be null."); return handleResult(newParser().parseName(qualifiedName)); } @@ -411,6 +440,7 @@ public static Name parseName(@NotNull String qualifiedName) { * @throws ParseProblemException if the source code has parser errors */ public static SimpleName parseSimpleName(@NotNull String name) { + Preconditions.checkNotNull(name, "Parameter name can't be null."); return handleResult(newParser().parseSimpleName(name)); } @@ -422,6 +452,7 @@ public static SimpleName parseSimpleName(@NotNull String name) { * @throws ParseProblemException if the source code has parser errors */ public static Parameter parseParameter(@NotNull String parameter) { + Preconditions.checkNotNull(parameter, "Parameter parameter can't be null."); return handleResult(newParser().parseParameter(parameter)); } @@ -433,6 +464,7 @@ public static Parameter parseParameter(@NotNull String parameter) { * @throws ParseProblemException if the source code has parser errors */ public static PackageDeclaration parsePackageDeclaration(@NotNull String packageDeclaration) { + Preconditions.checkNotNull(packageDeclaration, "Parameter packageDeclaration can't be null."); return handleResult(newParser().parsePackageDeclaration(packageDeclaration)); } @@ -444,6 +476,7 @@ public static PackageDeclaration parsePackageDeclaration(@NotNull String package * @throws ParseProblemException if the source code has parser errors */ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclaration) { + Preconditions.checkNotNull(typeDeclaration, "Parameter typeDeclaration can't be null."); return handleResult(newParser().parseTypeDeclaration(typeDeclaration)); } @@ -456,6 +489,7 @@ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclar * @see ModuleDeclaration */ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDeclaration) { + Preconditions.checkNotNull(moduleDeclaration, "Parameter moduleDeclaration can't be null."); return handleResult(newParser().parseModuleDeclaration(moduleDeclaration)); } @@ -468,10 +502,10 @@ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDec * @see ModuleDirective */ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirective) { + Preconditions.checkNotNull(moduleDirective, "Parameter moduleDirective can't be null."); return handleResult(newParser().parseModuleDirective(moduleDirective)); } - /** * Parses a type parameter and returns it as a TypeParameter * @@ -480,6 +514,7 @@ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirecti * @throws ParseProblemException if the source code has parser errors */ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { + Preconditions.checkNotNull(typeParameter, "Parameter typeParameter can't be null."); return handleResult(newParser().parseTypeParameter(typeParameter)); } @@ -492,7 +527,7 @@ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { * @see MethodDeclaration */ public static MethodDeclaration parseMethodDeclaration(@NotNull String methodDeclaration) { + Preconditions.checkNotNull(methodDeclaration, "Parameter methodDeclaration can't be null."); return handleResult(newParser().parseMethodDeclaration(methodDeclaration)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java index 38390dcfd7..36aec1a1cb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java @@ -18,21 +18,22 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; -import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Iterator; import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; + /** * The range of tokens covered by this node. */ public class TokenRange implements Iterable { + public static final TokenRange INVALID = new TokenRange(JavaToken.INVALID, JavaToken.INVALID); private final JavaToken begin; + private final JavaToken end; public TokenRange(JavaToken begin, JavaToken end) { @@ -66,7 +67,7 @@ public TokenRange withEnd(JavaToken end) { @Override public String toString() { StringBuilder result = new StringBuilder(); - for(JavaToken t: this) { + for (JavaToken t : this) { result.append(t.getText()); } return result.toString(); @@ -75,7 +76,9 @@ public String toString() { @Override public Iterator iterator() { return new Iterator() { + private boolean hasNext = true; + private JavaToken current = begin; @Override @@ -86,14 +89,14 @@ public boolean hasNext() { @Override public JavaToken next() { JavaToken retval = current; - if(current == null){ + if (current == null) { throw new IllegalStateException("Attempting to move past end of range."); } if (current == end) { hasNext = false; } current = current.getNextToken().orElse(null); - if(current == null && hasNext){ + if (current == null && hasNext) { throw new IllegalStateException("End token is not linked to begin token."); } return retval; diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java index 1b503dc43f..76a616811c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser; import com.github.javaparser.utils.LineSeparator; @@ -29,6 +28,7 @@ * Complements GeneratedJavaParserConstants */ public class TokenTypes { + public static boolean isWhitespace(int kind) { return getCategory(kind).isWhitespace(); } @@ -95,7 +95,7 @@ public static int spaceTokenKind() { * The JLS. */ public static JavaToken.Category getCategory(int kind) { - switch (kind) { + switch(kind) { case WINDOWS_EOL: case UNIX_EOL: case OLD_MAC_EOL: diff --git a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java index 9496fd12ff..4b4c3e5158 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/UnicodeEscapeProcessingProvider.java @@ -29,572 +29,571 @@ * {@link Provider} un-escaping unicode escape sequences in the input sequence. */ public class UnicodeEscapeProcessingProvider implements Provider { - - private static final char LF = '\n'; - - private static final char CR = '\r'; - - private static final char BACKSLASH = '\\'; - - private static final int EOF = -1; - - private char[] _data; - - /** - * The number of characters in {@link #_data}. - */ - private int _len = 0; - - /** - * The position in {@link #_data} where to read the next source character from. - */ - private int _pos = 0; - - private boolean _backslashSeen; - - private final LineCounter _inputLine = new LineCounter(); - - private final LineCounter _outputLine = new LineCounter(); - - private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); - - private Provider _input; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(Provider input) { - this(2048, input); - } - - /** - * Creates a {@link UnicodeEscapeProcessingProvider}. - */ - public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { - _input = input; - _data = new char[bufferSize]; - } - - /** - * The {@link LineCounter} of the input file. - */ - public LineCounter getInputCounter() { - return _inputLine; - } - - /** - * The {@link LineCounter} of the output file. - */ - public LineCounter getOutputCounter() { - return _outputLine; - } - - @Override - public int read(char[] buffer, final int offset, int len) throws IOException { - int pos = offset; - int stop = offset + len; - while (pos < stop) { - int ch = _outputLine.process(nextOutputChar()); - if (ch < 0) { - if (pos == offset) { - // Nothing read yet, this is the end of the stream. - return EOF; - } else { - break; - } - } else { - _mappingBuilder.update(); - buffer[pos++] = (char) ch; - } - } - return pos - offset; - } - - @Override - public void close() throws IOException { - _input.close(); - } - - /** - * Produces the next un-escaped character to be written to the output. - * - * @return The next character or {@code -1} if no more characters are available. - */ - private int nextOutputChar() throws IOException { - int next = nextInputChar(); - switch (next) { - case EOF: - return EOF; - case BACKSLASH: { - if (_backslashSeen) { - return clearBackSlashSeen(next); - } else { - return backSlashSeen(); - } - } - default: { - // An arbitrary character. - return clearBackSlashSeen(next); - } - } - } - - private int clearBackSlashSeen(int next) { - _backslashSeen = false; - return next; - } - - private int backSlashSeen() throws IOException { - _backslashSeen = true; - - int next = nextInputChar(); - switch (next) { - case EOF: - // End of file after backslash produces the backslash itself. - return BACKSLASH; - case 'u': { - return unicodeStartSeen(); - } - default: { - pushBack(next); - return BACKSLASH; - } - } - } - - private int unicodeStartSeen() throws IOException { - int uCnt = 1; - while (true) { - int next = nextInputChar(); - switch (next) { - case EOF: { - pushBackUs(uCnt); - return BACKSLASH; - } - case 'u': { - uCnt++; - continue; - } - default: { - return readDigits(uCnt, next); - } - } - } - } - - private int readDigits(int uCnt, int next3) throws IOException { - int digit3 = digit(next3); - if (digit3 < 0) { - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next2 = nextInputChar(); - int digit2 = digit(next2); - if (digit2 < 0) { - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next1 = nextInputChar(); - int digit1 = digit(next1); - if (digit1 < 0) { - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int next0 = nextInputChar(); - int digit0 = digit(next0); - if (digit0 < 0) { - pushBack(next0); - pushBack(next1); - pushBack(next2); - pushBack(next3); - pushBackUs(uCnt); - return BACKSLASH; - } - - int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; - return clearBackSlashSeen(ch); - } - - private void pushBackUs(int cnt) { - for (int n = 0; n < cnt; n++) { - pushBack('u'); - } - } - - private static int digit(int ch) { - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } - if (ch >= 'A' && ch <= 'F') { - return 10 + ch - 'A'; - } - if (ch >= 'a' && ch <= 'f') { - return 10 + ch - 'a'; - } - return -1; - } - - /** - * Processes column/line information from the input file. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextInputChar() throws IOException { - int result = nextBufferedChar(); - return _inputLine.process(result); - } - - /** - * Retrieves the next un-escaped character from the buffered {@link #_input}. - * - * @return The next character or {@code -1} if no more input is available. - */ - private int nextBufferedChar() throws IOException { - while (isBufferEmpty()) { - int direct = fillBuffer(); - if (direct < 0) { - return EOF; - } - } - return _data[_pos++]; - } - - private boolean isBufferEmpty() { - return _pos >= _len; - } - - private int fillBuffer() throws IOException { - _pos = 0; - int direct = _input.read(_data, 0, _data.length); - if (direct != 0) { - _len = direct; - } - return direct; - } - - private void pushBack(int ch) { - if (ch < 0) { - return; - } - - if (isBufferEmpty()) { - _pos = _data.length; - _len = _data.length; - } else if (_pos == 0) { - if (_len == _data.length) { - // Buffer is completely full, no push possible, enlarge buffer. - char[] newData = new char[_data.length + 1024]; - _len = newData.length; - _pos = newData.length - _data.length; - System.arraycopy(_data, 0, newData, _pos, _data.length); - _data = newData; - } else { - // Move contents to the right. - int cnt = _len - _pos; - _pos = _data.length - _len; - _len = _data.length; - System.arraycopy(_data, 0, _data, _pos, cnt); - } - } - _data[--_pos] = (char) ch; - } - - /** - * The {@link PositionMapping} being built during processing the file. - */ - public PositionMapping getPositionMapping() { - return _mappingBuilder.getMapping(); - } - - /** - * An algorithm mapping {@link Position} form two corresponding files. - */ - public static final class PositionMapping { - - private final List _deltas = new ArrayList<>(); - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. - */ - public PositionMapping() { - super(); - } - - /** - * Whether this is the identity transformation. - */ - public boolean isEmpty() { - return _deltas.isEmpty(); - } - - void add(int line, int column, int lineDelta, int columnDelta) { - _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); - } - - /** - * Looks up the {@link PositionUpdate} for the given Position. - */ - public PositionUpdate lookup(Position position) { - int result = Collections.binarySearch(_deltas, position); - if (result >= 0) { - return _deltas.get(result); - } else { - int insertIndex = -result - 1; - if (insertIndex == 0) { - // Before the first delta info, identity mapping. - return PositionUpdate.NONE; - } else { - // The relevant update is the one with the position smaller - // than the requested position. - return _deltas.get(insertIndex - 1); - } - } - } - - /** - * Algorithm updating a {@link Position} from one file to a - * {@link Position} in a corresponding file. - */ - public static interface PositionUpdate { - - /** - * The identity position mapping. - */ - PositionUpdate NONE = new PositionUpdate() { - @Override - public int transformLine(int line) { - return line; - } - - @Override - public int transformColumn(int column) { - return column; - } - - @Override - public Position transform(Position pos) { - return pos; - } - }; - - /** - * Maps the given line to an original line. - */ - int transformLine(int line); - - /** - * Maps the given column to an original column. - */ - int transformColumn(int column); - - /** - * The transformed position. - */ - default Position transform(Position pos) { - int line = pos.line; - int column = pos.column; - int transformedLine = transformLine(line); - int transformedColumn = transformColumn(column); - return new Position(transformedLine, transformedColumn); - } - - } - - private static final class DeltaInfo extends Position implements PositionUpdate { - - /** - * The offset to add to the {@link #line} and all following source - * positions up to the next {@link PositionUpdate}. - */ - private final int _lineDelta; - - /** - * The offset to add to the {@link #column} and all following - * source positions up to the next {@link PositionUpdate}. - */ - private final int _columnDelta; - - /** - * Creates a {@link PositionUpdate}. - */ - public DeltaInfo(int line, int column, int lineDelta, - int columnDelta) { - super(line, column); - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - - @Override - public int transformLine(int sourceLine) { - return sourceLine + _lineDelta; - } - - @Override - public int transformColumn(int sourceColumn) { - return sourceColumn + _columnDelta; - } - - @Override - public String toString() { - return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; - } - - } - - /** - * Transforms the given {@link Position}. - */ - public Position transform(Position pos) { - return lookup(pos).transform(pos); - } - - /** - * Transforms the given {@link Range}. - */ - public Range transform(Range range) { - Position begin = transform(range.begin); - Position end = transform(range.end); - if (begin == range.begin && end == range.end) { - // No change. - return range; - } - return new Range(begin, end); - } - } - - private static final class PositionMappingBuilder { - - private LineCounter _left; - - private LineCounter _right; - - private final PositionMapping _mapping = new PositionMapping(); - - private int _lineDelta = 0; - private int _columnDelta = 0; - - /** - * Creates a {@link PositionMappingBuilder}. - * - * @param left The source {@link LineCounter}. - * @param right The target {@link LineCounter}. - */ - public PositionMappingBuilder(LineCounter left, LineCounter right) { - _left = left; - _right = right; - update(); - } - - /** - * The built {@link PositionMapping}. - */ - public PositionMapping getMapping() { - return _mapping; - } - - public void update() { - int lineDelta = _right.getLine() - _left.getLine(); - int columnDelta = _right.getColumn() - _left.getColumn(); - - if (lineDelta != _lineDelta || columnDelta != _columnDelta) { - _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); - - _lineDelta = lineDelta; - _columnDelta = columnDelta; - } - } - - } - - /** - * Processor keeping track of the current line and column in a stream of - * incoming characters. - * - * @see #process(int) - */ - public static final class LineCounter { - - /** - * Whether {@link #CR} has been seen on the input as last character. - */ - private boolean _crSeen; - - private int _line = 1; - - private int _column = 1; - - /** - * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. - */ - public LineCounter() { - super(); - } - - /** - * The line of the currently processed input character. - */ - public int getLine() { - return _line; - } - - /** - * The column of the currently processed input character. - */ - public int getColumn() { - return _column; - } - - /** - * The current position. - */ - public Position getPosition() { - return new Position(getLine(), getColumn()); - } - - /** - * Analyzes the given character for line feed. - */ - public int process(int ch) { - switch (ch) { - case EOF: { - break; - } - case CR: { - incLine(); - _crSeen = true; - break; - } - case LF: { - // CR LF does only count as a single line terminator. - if (_crSeen) { - _crSeen = false; - } else { - incLine(); - } - break; - } - default: { - _crSeen = false; - _column++; - } - } - return ch; - } - - private void incLine() { - _line++; - _column = 1; - } - - } - + + private static final char LF = '\n'; + + private static final char CR = '\r'; + + private static final char BACKSLASH = '\\'; + + private static final int EOF = -1; + + private char[] _data; + + /** + * The number of characters in {@link #_data}. + */ + private int _len = 0; + + /** + * The position in {@link #_data} where to read the next source character from. + */ + private int _pos = 0; + + private boolean _backslashSeen; + + private final LineCounter _inputLine = new LineCounter(); + + private final LineCounter _outputLine = new LineCounter(); + + private final PositionMappingBuilder _mappingBuilder = new PositionMappingBuilder(_outputLine, _inputLine); + + private Provider _input; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(Provider input) { + this(2048, input); + } + + /** + * Creates a {@link UnicodeEscapeProcessingProvider}. + */ + public UnicodeEscapeProcessingProvider(int bufferSize, Provider input) { + _input = input; + _data = new char[bufferSize]; + } + + /** + * The {@link LineCounter} of the input file. + */ + public LineCounter getInputCounter() { + return _inputLine; + } + + /** + * The {@link LineCounter} of the output file. + */ + public LineCounter getOutputCounter() { + return _outputLine; + } + + @Override + public int read(char[] buffer, final int offset, int len) throws IOException { + int pos = offset; + int stop = offset + len; + while (pos < stop) { + int ch = _outputLine.process(nextOutputChar()); + if (ch < 0) { + if (pos == offset) { + // Nothing read yet, this is the end of the stream. + return EOF; + } else { + break; + } + } else { + _mappingBuilder.update(); + buffer[pos++] = (char) ch; + } + } + return pos - offset; + } + + @Override + public void close() throws IOException { + _input.close(); + } + + /** + * Produces the next un-escaped character to be written to the output. + * + * @return The next character or {@code -1} if no more characters are available. + */ + private int nextOutputChar() throws IOException { + int next = nextInputChar(); + switch(next) { + case EOF: + return EOF; + case BACKSLASH: + { + if (_backslashSeen) { + return clearBackSlashSeen(next); + } else { + return backSlashSeen(); + } + } + default: + { + // An arbitrary character. + return clearBackSlashSeen(next); + } + } + } + + private int clearBackSlashSeen(int next) { + _backslashSeen = false; + return next; + } + + private int backSlashSeen() throws IOException { + _backslashSeen = true; + int next = nextInputChar(); + switch(next) { + case EOF: + // End of file after backslash produces the backslash itself. + return BACKSLASH; + case 'u': + { + return unicodeStartSeen(); + } + default: + { + pushBack(next); + return BACKSLASH; + } + } + } + + private int unicodeStartSeen() throws IOException { + int uCnt = 1; + while (true) { + int next = nextInputChar(); + switch(next) { + case EOF: + { + pushBackUs(uCnt); + return BACKSLASH; + } + case 'u': + { + uCnt++; + continue; + } + default: + { + return readDigits(uCnt, next); + } + } + } + } + + private int readDigits(int uCnt, int next3) throws IOException { + int digit3 = digit(next3); + if (digit3 < 0) { + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next2 = nextInputChar(); + int digit2 = digit(next2); + if (digit2 < 0) { + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next1 = nextInputChar(); + int digit1 = digit(next1); + if (digit1 < 0) { + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int next0 = nextInputChar(); + int digit0 = digit(next0); + if (digit0 < 0) { + pushBack(next0); + pushBack(next1); + pushBack(next2); + pushBack(next3); + pushBackUs(uCnt); + return BACKSLASH; + } + int ch = digit3 << 12 | digit2 << 8 | digit1 << 4 | digit0; + return clearBackSlashSeen(ch); + } + + private void pushBackUs(int cnt) { + for (int n = 0; n < cnt; n++) { + pushBack('u'); + } + } + + private static int digit(int ch) { + if (ch >= '0' && ch <= '9') { + return ch - '0'; + } + if (ch >= 'A' && ch <= 'F') { + return 10 + ch - 'A'; + } + if (ch >= 'a' && ch <= 'f') { + return 10 + ch - 'a'; + } + return -1; + } + + /** + * Processes column/line information from the input file. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextInputChar() throws IOException { + int result = nextBufferedChar(); + return _inputLine.process(result); + } + + /** + * Retrieves the next un-escaped character from the buffered {@link #_input}. + * + * @return The next character or {@code -1} if no more input is available. + */ + private int nextBufferedChar() throws IOException { + while (isBufferEmpty()) { + int direct = fillBuffer(); + if (direct < 0) { + return EOF; + } + } + return _data[_pos++]; + } + + private boolean isBufferEmpty() { + return _pos >= _len; + } + + private int fillBuffer() throws IOException { + _pos = 0; + int direct = _input.read(_data, 0, _data.length); + if (direct != 0) { + _len = direct; + } + return direct; + } + + private void pushBack(int ch) { + if (ch < 0) { + return; + } + if (isBufferEmpty()) { + _pos = _data.length; + _len = _data.length; + } else if (_pos == 0) { + if (_len == _data.length) { + // Buffer is completely full, no push possible, enlarge buffer. + char[] newData = new char[_data.length + 1024]; + _len = newData.length; + _pos = newData.length - _data.length; + System.arraycopy(_data, 0, newData, _pos, _data.length); + _data = newData; + } else { + // Move contents to the right. + int cnt = _len - _pos; + _pos = _data.length - _len; + _len = _data.length; + System.arraycopy(_data, 0, _data, _pos, cnt); + } + } + _data[--_pos] = (char) ch; + } + + /** + * The {@link PositionMapping} being built during processing the file. + */ + public PositionMapping getPositionMapping() { + return _mappingBuilder.getMapping(); + } + + /** + * An algorithm mapping {@link Position} form two corresponding files. + */ + public static final class PositionMapping { + + private final List _deltas = new ArrayList<>(); + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.PositionMapping}. + */ + public PositionMapping() { + super(); + } + + /** + * Whether this is the identity transformation. + */ + public boolean isEmpty() { + return _deltas.isEmpty(); + } + + void add(int line, int column, int lineDelta, int columnDelta) { + _deltas.add(new DeltaInfo(line, column, lineDelta, columnDelta)); + } + + /** + * Looks up the {@link PositionUpdate} for the given Position. + */ + public PositionUpdate lookup(Position position) { + int result = Collections.binarySearch(_deltas, position); + if (result >= 0) { + return _deltas.get(result); + } else { + int insertIndex = -result - 1; + if (insertIndex == 0) { + // Before the first delta info, identity mapping. + return PositionUpdate.NONE; + } else { + // The relevant update is the one with the position smaller + // than the requested position. + return _deltas.get(insertIndex - 1); + } + } + } + + /** + * Algorithm updating a {@link Position} from one file to a + * {@link Position} in a corresponding file. + */ + public static interface PositionUpdate { + + /** + * The identity position mapping. + */ + PositionUpdate NONE = new PositionUpdate() { + + @Override + public int transformLine(int line) { + return line; + } + + @Override + public int transformColumn(int column) { + return column; + } + + @Override + public Position transform(Position pos) { + return pos; + } + }; + + /** + * Maps the given line to an original line. + */ + int transformLine(int line); + + /** + * Maps the given column to an original column. + */ + int transformColumn(int column); + + /** + * The transformed position. + */ + default Position transform(Position pos) { + int line = pos.line; + int column = pos.column; + int transformedLine = transformLine(line); + int transformedColumn = transformColumn(column); + return new Position(transformedLine, transformedColumn); + } + } + + private static final class DeltaInfo extends Position implements PositionUpdate { + + /** + * The offset to add to the {@link #line} and all following source + * positions up to the next {@link PositionUpdate}. + */ + private final int _lineDelta; + + /** + * The offset to add to the {@link #column} and all following + * source positions up to the next {@link PositionUpdate}. + */ + private final int _columnDelta; + + /** + * Creates a {@link PositionUpdate}. + */ + public DeltaInfo(int line, int column, int lineDelta, int columnDelta) { + super(line, column); + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + + @Override + public int transformLine(int sourceLine) { + return sourceLine + _lineDelta; + } + + @Override + public int transformColumn(int sourceColumn) { + return sourceColumn + _columnDelta; + } + + @Override + public String toString() { + return "(" + line + ", " + column + ": " + _lineDelta + ", " + _columnDelta + ")"; + } + } + + /** + * Transforms the given {@link Position}. + */ + public Position transform(Position pos) { + return lookup(pos).transform(pos); + } + + /** + * Transforms the given {@link Range}. + */ + public Range transform(Range range) { + Position begin = transform(range.begin); + Position end = transform(range.end); + if (begin == range.begin && end == range.end) { + // No change. + return range; + } + return new Range(begin, end); + } + } + + private static final class PositionMappingBuilder { + + private LineCounter _left; + + private LineCounter _right; + + private final PositionMapping _mapping = new PositionMapping(); + + private int _lineDelta = 0; + + private int _columnDelta = 0; + + /** + * Creates a {@link PositionMappingBuilder}. + * + * @param left The source {@link LineCounter}. + * @param right The target {@link LineCounter}. + */ + public PositionMappingBuilder(LineCounter left, LineCounter right) { + _left = left; + _right = right; + update(); + } + + /** + * The built {@link PositionMapping}. + */ + public PositionMapping getMapping() { + return _mapping; + } + + public void update() { + int lineDelta = _right.getLine() - _left.getLine(); + int columnDelta = _right.getColumn() - _left.getColumn(); + if (lineDelta != _lineDelta || columnDelta != _columnDelta) { + _mapping.add(_left.getLine(), _left.getColumn(), lineDelta, columnDelta); + _lineDelta = lineDelta; + _columnDelta = columnDelta; + } + } + } + + /** + * Processor keeping track of the current line and column in a stream of + * incoming characters. + * + * @see #process(int) + */ + public static final class LineCounter { + + /** + * Whether {@link #CR} has been seen on the input as last character. + */ + private boolean _crSeen; + + private int _line = 1; + + private int _column = 1; + + /** + * Creates a {@link UnicodeEscapeProcessingProvider.LineCounter}. + */ + public LineCounter() { + super(); + } + + /** + * The line of the currently processed input character. + */ + public int getLine() { + return _line; + } + + /** + * The column of the currently processed input character. + */ + public int getColumn() { + return _column; + } + + /** + * The current position. + */ + public Position getPosition() { + return new Position(getLine(), getColumn()); + } + + /** + * Analyzes the given character for line feed. + */ + public int process(int ch) { + switch(ch) { + case EOF: + { + break; + } + case CR: + { + incLine(); + _crSeen = true; + break; + } + case LF: + { + // CR LF does only count as a single line terminator. + if (_crSeen) { + _crSeen = false; + } else { + incLine(); + } + break; + } + default: + { + _crSeen = false; + _column++; + } + } + return ch; + } + + private void incLine() { + _line++; + _column = 1; + } + } } 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 index 98b5676a2c..28768ca6f8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; /** @@ -30,10 +29,7 @@ */ public enum AccessSpecifier { - PUBLIC("public"), - PRIVATE("private"), - PROTECTED("protected"), - NONE(""); + PUBLIC("public"), PRIVATE("private"), PROTECTED("protected"), NONE(""); private String 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 index 142406ab27..adc126d6c2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; import java.lang.annotation.ElementType; 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 index 222a4a7dea..93be5f6186 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; /** @@ -41,6 +40,7 @@ * @see Node#getData(DataKey) */ public abstract class DataKey { + @Override public int hashCode() { return getClass().hashCode(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java index c2c8f68232..107646193f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Generated.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast; import java.lang.annotation.Retention; @@ -34,9 +33,9 @@ * and will be overwritten the next time the generators are run. */ @Retention(SOURCE) -@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, - LOCAL_VARIABLE, PARAMETER}) +@Target({ PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER }) public @interface Generated { + /** * The value element must have the name of the code generator. * The recommended convention is to use the fully qualified name of the diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java index f2d10f790c..6d916e7282 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java @@ -18,7 +18,6 @@ * 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; @@ -47,6 +46,7 @@ * @param the type of nodes contained. */ public class NodeList implements List, Iterable, HasParentNode>, Visitable, Observable { + @InternalProperty private final List innerList = new ArrayList<>(0); @@ -140,8 +140,7 @@ public Iterator 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); + 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; @@ -228,7 +227,6 @@ public NodeList addBefore(N node, N beforeThisNode) { return this; } - /** * @return the first node, or empty if the list is empty. */ @@ -567,9 +565,10 @@ public String toString() { return innerList.stream().map(Node::toString).collect(Collectors.joining(", ", "[", "]")); } - protected class NodeListIterator implements ListIterator{ + protected class NodeListIterator implements ListIterator { ListIterator iterator; + N current = null; // initialize pointer to head of the list for iteration @@ -627,14 +626,12 @@ public void remove() { public void set(N n) { int index = innerList.indexOf(current); 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); + throw new IllegalArgumentException("Illegal index. The index should be between 0 and " + innerList.size() + " excluded. It is instead " + index); } if (n != innerList.get(index)) { notifyElementReplaced(index, n); innerList.get(index).setParentNode(null); setAsParentNodeOf(n); - iterator.set(n); } } 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 index 316d20bc68..b8119b8eea 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,6 +33,7 @@ * The comments contained in a certain parsed piece of source code. */ public class CommentsCollection { + private final TreeSet comments = new TreeSet<>(NODE_BY_BEGIN_POSITION); public CommentsCollection() { @@ -44,24 +44,15 @@ public CommentsCollection(Collection commentsToCopy) { } public Set getLineComments() { - return comments.stream() - .filter(comment -> comment instanceof LineComment) - .map(comment -> (LineComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream().filter(comment -> comment instanceof LineComment).map(comment -> (LineComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getBlockComments() { - return comments.stream() - .filter(comment -> comment instanceof BlockComment) - .map(comment -> (BlockComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + return comments.stream().filter(comment -> comment instanceof BlockComment).map(comment -> (BlockComment) comment).collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); } public Set getJavadocComments() { - return comments.stream() - .filter(comment -> comment instanceof JavadocComment) - .map(comment -> (JavadocComment) comment) - .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION))); + 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) { @@ -80,9 +71,7 @@ public boolean contains(Comment comment) { 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) { + if (cRange.begin.equals(commentRange.begin) && cRange.end.line == commentRange.end.line && Math.abs(cRange.end.column - commentRange.end.column) < 2) { return true; } } @@ -99,10 +88,7 @@ public int size() { public CommentsCollection minus(CommentsCollection other) { CommentsCollection result = new CommentsCollection(); - result.comments.addAll( - comments.stream() - .filter(comment -> !other.contains(comment)) - .collect(Collectors.toList())); + result.comments.addAll(comments.stream().filter(comment -> !other.contains(comment)).collect(Collectors.toList())); return result; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java index 1b8f2ecfa0..1e0cdc178c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java @@ -33,8 +33,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.NonEmptyProperty; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.StaticJavaParser.parseType; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -148,13 +150,9 @@ public ArrayCreationExpr setLevels(final NodeList levels) { return this; } notifyPropertyChange(ObservableProperty.LEVELS, this.levels, levels); - if (this.levels != null) { + if (this.levels != null) this.levels.setParentNode(null); - } this.levels = levels; - if (this.levels.isEmpty()) { - this.levels = new NodeList<>(new ArrayCreationLevel()); - } setAsParentNodeOf(levels); return 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 index c713711707..885f36dfae 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -38,6 +37,7 @@ * @since July 2014 */ public interface NodeWithAnnotations { + NodeList getAnnotations(); N setAnnotations(NodeList annotations); @@ -68,8 +68,7 @@ default N addAnnotation(AnnotationExpr element) { */ @SuppressWarnings("unchecked") default N addAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr( - parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); addAnnotation(annotation); return (N) this; } @@ -82,8 +81,7 @@ default N addAnnotation(String name) { */ @SuppressWarnings("unchecked") default NormalAnnotationExpr addAndGetAnnotation(String name) { - NormalAnnotationExpr annotation = new NormalAnnotationExpr( - parseName(name), new NodeList<>()); + NormalAnnotationExpr annotation = new NormalAnnotationExpr(parseName(name), new NodeList<>()); addAnnotation(annotation); return annotation; } @@ -118,8 +116,7 @@ default NormalAnnotationExpr addAndGetAnnotation(Class cla */ @SuppressWarnings("unchecked") default N addMarkerAnnotation(String name) { - MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr( - parseName(name)); + MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr(parseName(name)); addAnnotation(markerAnnotationExpr); return (N) this; } @@ -144,8 +141,7 @@ default N addMarkerAnnotation(Class clazz) { */ @SuppressWarnings("unchecked") default N addSingleMemberAnnotation(String name, Expression expression) { - SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr( - parseName(name), expression); + SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr(parseName(name), expression); return addAnnotation(singleMemberAnnotationExpr); } @@ -179,8 +175,7 @@ default N addSingleMemberAnnotation(String name, String value) { * @param value the value, don't forget to add \"\" for a string value * @return this */ - default N addSingleMemberAnnotation(Class clazz, - String value) { + default N addSingleMemberAnnotation(Class clazz, String value) { tryAddImportToParentCompilationUnit(clazz); return addSingleMemberAnnotation(clazz.getSimpleName(), value); } 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 index 6b48f0e5dc..a08739a75a 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node with arguments. */ public interface NodeWithArguments { + N setArguments(NodeList arguments); NodeList getArguments(); @@ -55,5 +55,4 @@ 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 index c43900b68c..cb71f070bd 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -28,6 +27,7 @@ * A node with a body that is a BlockStmt. */ public interface NodeWithBlockStmt { + BlockStmt getBody(); N setBody(BlockStmt 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 index 191e469bdc..600bb28ff0 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -27,6 +26,7 @@ import com.github.javaparser.ast.stmt.Statement; public interface NodeWithBody { + Statement getBody(); N setBody(final Statement body); @@ -42,8 +42,6 @@ default BlockStmt createBlockStatementAsBody() { */ default boolean hasEmptyBody() { Statement body = getBody(); - return body.toBlockStmt().map(bs -> bs.isEmpty()) - .orElse(body.isEmptyStmt()); + return body.toBlockStmt().map(bs -> bs.isEmpty()).orElse(body.isEmptyStmt()); } - } 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 index 8186504017..825c612487 100644 --- 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 @@ -18,13 +18,13 @@ * 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; public interface NodeWithCondition { + Expression getCondition(); N setCondition(Expression condition); 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 index 940052d8ea..2f9581d7a4 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes; /** 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 index c78e30d4d2..7257520ad4 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -30,6 +29,7 @@ * A node that has an expression in it. */ public interface NodeWithExpression { + Expression getExpression(); N setExpression(Expression 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 index 542d875fe4..34c2442423 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -98,5 +97,4 @@ 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 index 7bb71c5352..b2f23c83a3 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -26,6 +25,7 @@ import static com.github.javaparser.utils.Utils.assertNonEmpty; public interface NodeWithIdentifier { + String getIdentifier(); N setIdentifier(String 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 index 885861acf2..fdbbe63844 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node that implements other types. */ public interface NodeWithImplements { + NodeList getImplementedTypes(); default ClassOrInterfaceType getImplementedTypes(int i) { @@ -38,9 +38,9 @@ default ClassOrInterfaceType getImplementedTypes(int i) { } N setImplementedTypes(NodeList implementsList); - + void tryAddImportToParentCompilationUnit(Class clazz); - + @SuppressWarnings("unchecked") default N setImplementedType(int i, ClassOrInterfaceType implement) { getImplementedTypes().set(i, implement); @@ -53,12 +53,16 @@ default N addImplementedType(ClassOrInterfaceType implement) { return (N) this; } - /** @deprecated use addImplementedType instead */ + /** + * @deprecated use addImplementedType instead + */ default N addImplements(String name) { return addImplementedType(name); } - /** @deprecated use addImplementedType instead */ + /** + * @deprecated use addImplementedType instead + */ default N addImplements(Class clazz) { return addImplementedType(clazz); } 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 index ddb7f0a02d..956a2f5b90 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -32,6 +31,7 @@ * A node that can be documented with a Javadoc comment. */ public interface NodeWithJavadoc { + Optional getComment(); Node setComment(Comment comment); @@ -43,9 +43,7 @@ public interface NodeWithJavadoc { * @return The JavadocComment for this node wrapped in an optional as it may be absent. */ default Optional getJavadocComment() { - return getComment() - .filter(comment -> comment instanceof JavadocComment) - .map(comment -> (JavadocComment) comment); + return getComment().filter(comment -> comment instanceof JavadocComment).map(comment -> (JavadocComment) comment); } /** @@ -87,5 +85,4 @@ default boolean removeJavaDocComment() { 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 index f72c3a96fd..f46527f3ca 100644 --- 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 @@ -46,6 +46,7 @@ * method. */ public interface NodeWithMembers extends NodeWithSimpleName { + /** * @return all members inside the braces of this node, * like fields, methods, nested types, etc. @@ -315,9 +316,7 @@ default BlockStmt addStaticInitializer() { * @return the methods found (multiple in case of overloading) */ default List getMethodsByName(String name) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.getNameAsString().equals(name)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.getNameAsString().equals(name)).collect(toList())); } /** @@ -326,10 +325,7 @@ default List getMethodsByName(String name) { * @return the methods found. This list is immutable. */ default List getMethods() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof MethodDeclaration) - .map(m -> (MethodDeclaration) m) - .collect(toList())); + return unmodifiableList(getMembers().stream().filter(m -> m instanceof MethodDeclaration).map(m -> (MethodDeclaration) m).collect(toList())); } /** @@ -348,9 +344,7 @@ default List getMethods() { * @return the methods found */ default List getMethodsByParameterTypes(String... paramTypes) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -362,9 +356,7 @@ default List getMethodsByParameterTypes(String... paramTypes) * @return the methods found */ default List getMethodsBySignature(String name, String... paramTypes) { - return unmodifiableList(getMethodsByName(name).stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethodsByName(name).stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -380,9 +372,7 @@ default List getMethodsBySignature(String name, String... par * @return the methods found */ default List getMethodsByParameterTypes(Class... paramTypes) { - return unmodifiableList(getMethods().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .collect(toList())); + return unmodifiableList(getMethods().stream().filter(m -> m.hasParametersOfType(paramTypes)).collect(toList())); } /** @@ -393,10 +383,7 @@ default List getMethodsByParameterTypes(Class... paramType * @return the constructors found. This list is immutable. */ default List getConstructors() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof ConstructorDeclaration) - .map(m -> (ConstructorDeclaration) m) - .collect(toList())); + return unmodifiableList(getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).collect(toList())); } /** @@ -405,11 +392,7 @@ default List getConstructors() { * @return the constructor found, if any. */ default Optional getDefaultConstructor() { - return getMembers().stream() - .filter(m -> m instanceof ConstructorDeclaration) - .map(m -> (ConstructorDeclaration) m) - .filter(cd -> cd.getParameters().isEmpty()) - .findFirst(); + return getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).filter(cd -> cd.getParameters().isEmpty()).findFirst(); } /** @@ -429,9 +412,7 @@ default Optional getDefaultConstructor() { * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(String... paramTypes) { - return getConstructors().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .findFirst(); + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); } /** @@ -447,9 +428,7 @@ default Optional getConstructorByParameterTypes(String.. * @return the constructor found, if any. */ default Optional getConstructorByParameterTypes(Class... paramTypes) { - return getConstructors().stream() - .filter(m -> m.hasParametersOfType(paramTypes)) - .findFirst(); + return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst(); } /** @@ -459,12 +438,7 @@ default Optional getConstructorByParameterTypes(Class * @return null if not found, the FieldDeclaration otherwise */ default Optional getFieldByName(String name) { - return getMembers().stream() - .filter(m -> m instanceof FieldDeclaration) - .map(f -> (FieldDeclaration) f) - .filter(f -> f.getVariables().stream() - .anyMatch(var -> var.getNameAsString().equals(name))) - .findFirst(); + return getMembers().stream().filter(m -> m instanceof FieldDeclaration).map(f -> (FieldDeclaration) f).filter(f -> f.getVariables().stream().anyMatch(var -> var.getNameAsString().equals(name))).findFirst(); } /** @@ -473,10 +447,7 @@ default Optional getFieldByName(String name) { * @return the fields found. This list is immutable. */ default List getFields() { - return unmodifiableList(getMembers().stream() - .filter(m -> m instanceof FieldDeclaration) - .map(m -> (FieldDeclaration) m) - .collect(toList())); + 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 index 264512bb03..d67a012127 100644 --- 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 @@ -18,7 +18,6 @@ * 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.AccessSpecifier; @@ -65,9 +64,7 @@ default N addModifier(Modifier.Keyword... newModifiers) { @SuppressWarnings("unchecked") default N removeModifier(Modifier.Keyword... modifiersToRemove) { List modifiersToRemoveAsList = Arrays.asList(modifiersToRemove); - NodeList remaining = getModifiers().stream() - .filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())) - .collect(toNodeList()); + NodeList remaining = getModifiers().stream().filter(existingModifier -> !modifiersToRemoveAsList.contains(existingModifier.getKeyword())).collect(toNodeList()); setModifiers(remaining); return (N) this; } @@ -106,7 +103,7 @@ default N setModifiers(final Modifier.Keyword... modifiers) { */ default AccessSpecifier getAccessSpecifier() { for (Modifier modifier : getModifiers()) { - switch (modifier.getKeyword()) { + switch(modifier.getKeyword()) { case PUBLIC: return AccessSpecifier.PUBLIC; case PROTECTED: 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 index 919a90536e..3dcefa89c6 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -35,6 +34,7 @@ * @since 2.0.1 */ public interface NodeWithName { + Name getName(); N setName(Name name); 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 index 05c8958254..12013c44ce 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -30,6 +29,7 @@ * A node with a body that is a BlockStmt, which is optional. */ public interface NodeWithOptionalBlockStmt { + Optional getBody(); N setBody(BlockStmt 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 index ee6d8c78c5..4e24302231 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -32,10 +31,11 @@ * A node that has an optional label. */ public interface NodeWithOptionalLabel { + Optional getLabel(); T setLabel(SimpleName label); - + T removeLabel(); default T setLabel(String label) { 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 index 8345b188a4..c441bdf7ed 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,7 +33,7 @@ public interface NodeWithOptionalScope extends NodeWithTraversab Optional getScope(); N setScope(Expression scope); - + N removeScope(); default Optional traverseScope() { 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 index 4fc4b5e799..7acf7b06ef 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -34,6 +33,7 @@ import static java.util.stream.Collectors.toList; public interface NodeWithParameters { + NodeList getParameters(); default Parameter getParameter(int i) { @@ -107,8 +107,7 @@ default Parameter addAndGetParameter(Parameter parameter) { * @return null if not found, the param found otherwise */ default Optional getParameterByName(String name) { - return getParameters().stream() - .filter(p -> p.getNameAsString().equals(name)).findFirst(); + return getParameters().stream().filter(p -> p.getNameAsString().equals(name)).findFirst(); } /** @@ -118,8 +117,7 @@ default Optional getParameterByName(String name) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(String type) { - return getParameters().stream() - .filter(p -> p.getType().toString().equals(type)).findFirst(); + return getParameters().stream().filter(p -> p.getType().toString().equals(type)).findFirst(); } /** @@ -129,8 +127,7 @@ default Optional getParameterByType(String type) { * @return null if not found, the param found otherwise */ default Optional getParameterByType(Class type) { - return getParameters().stream() - .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); + return getParameters().stream().filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst(); } /** @@ -149,10 +146,7 @@ default Optional getParameterByType(Class type) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(String... paramTypes) { - return getParameters().stream() - .map(p -> p.getType().asString()) - .collect(toList()) - .equals(Arrays.asList(paramTypes)); + return getParameters().stream().map(p -> p.getType().asString()).collect(toList()).equals(Arrays.asList(paramTypes)); } /** @@ -168,13 +162,8 @@ default boolean hasParametersOfType(String... paramTypes) { * @return {@code true} if all parameters match one by one, in the given order. */ default boolean hasParametersOfType(Class... paramTypes) { - return getParameters().stream() - // if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter - // is "List", we want to consider it as "List", so we need to call getName() - .map(p -> p.getType().toClassOrInterfaceType() - .map(NodeWithSimpleName::getNameAsString) - .orElse(p.getType().asString())) - .collect(toList()) - .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); + return getParameters().stream().// if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter + // is "List", we want to consider it as "List", so we need to call getName() + map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElse(p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList())); } } 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 index 1606f61775..fdce9d12f8 100644 --- 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 @@ -18,19 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes; -import java.util.Optional; - import com.github.javaparser.Position; import com.github.javaparser.Range; import com.github.javaparser.ast.Node; +import java.util.Optional; + /** * A node that has a Range, which is every Node. */ public interface NodeWithRange { + Optional getRange(); N setRange(Range range); @@ -76,7 +76,7 @@ default boolean containsWithinRange(Node other) { } return false; } - + /* * Returns true if the node has a range */ 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 index 56960f15fe..4a82c83a6c 100644 --- 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 @@ -18,7 +18,6 @@ * 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; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java index 98d71e727d..74d12053b7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java @@ -18,7 +18,6 @@ * 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; @@ -33,6 +32,7 @@ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method. */ public interface NodeWithSimpleName { + SimpleName getName(); N setName(SimpleName name); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java index 6ccf4ebd1c..88f7190dfe 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java @@ -18,7 +18,6 @@ * 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; @@ -35,6 +34,7 @@ * A node that contains a list of statements. */ public interface NodeWithStatements { + NodeList getStatements(); default Statement getStatement(int i) { 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 index 812707dcce..fd8b680354 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -31,6 +30,7 @@ * A node that declares the types of exception it throws. */ public interface NodeWithThrownExceptions { + N setThrownExceptions(NodeList thrownExceptions); NodeList getThrownExceptions(); 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 index 89d022eeeb..4a5024c79a 100644 --- 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 @@ -18,7 +18,6 @@ * 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.TokenRange; @@ -27,9 +26,9 @@ /** * A node that has a Range, which is every Node. - * */ public interface NodeWithTokenRange { + Optional 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 index d109c9333e..cd03695e30 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 13ee673477..fe2e924e66 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -37,6 +36,7 @@ * @since 2.3.1 */ public interface NodeWithType { + /** * Gets the type * diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java index f0f28007ac..4d058e79a9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java @@ -18,7 +18,6 @@ * 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; @@ -42,6 +41,7 @@ * On other nodes it is treated the same as the first case. */ public interface NodeWithTypeArguments { + /** * @return the types that can be found in the type arguments: {@code }. */ 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 index fe0e9d6e04..bf95e89606 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -36,6 +35,7 @@ * */ public interface NodeWithTypeParameters { + NodeList getTypeParameters(); default TypeParameter getTypeParameter(int i) { 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 index ca4d75dcd7..2059c914ec 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -36,6 +35,7 @@ * A node which has a list of variables. */ public interface NodeWithVariables { + NodeList getVariables(); N setVariables(NodeList variables); @@ -130,6 +130,7 @@ default Optional getMaximumCommonType() { static Optional calculateMaximumCommonType(List types) { // we use a local class because we cannot use an helper static method in an interface class Helper { + // Conceptually: given a type we start from the Element Type and get as many array levels as indicated // From the implementation point of view we start from the actual type and we remove how many array // levels as needed to get the target level of arrays @@ -147,7 +148,6 @@ private Optional toArrayLevel(Type type, int level) { return Optional.of(type); } } - Helper helper = new Helper(); int level = 0; boolean keepGoing = true; @@ -170,5 +170,4 @@ private Optional toArrayLevel(Type type, int level) { } return helper.toArrayLevel(types.get(0), --level); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java index b010fab7a7..86ce1f0aec 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/SwitchNode.java @@ -18,7 +18,6 @@ * 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; @@ -33,6 +32,7 @@ * The common interface of {@link com.github.javaparser.ast.expr.SwitchExpr} and {@link com.github.javaparser.ast.stmt.SwitchStmt} */ public interface SwitchNode { + NodeList getEntries(); SwitchEntry getEntry(int i); @@ -57,8 +57,6 @@ public interface SwitchNode { default boolean isEmpty() { return getEntries().isEmpty(); } - - // Too bad Node isn't an interface, or this could have easily inherited all of its methods. // Add more when required. } 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 index c7b396162d..6d47d348a5 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be abstract. */ public interface NodeWithAbstractModifier extends NodeWithModifiers { + default boolean isAbstract() { return hasModifier(ABSTRACT); } 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 index 7f15def6a8..a9ad505d5a 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; 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 index a6af85f4ae..2b82aeaf25 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; 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 index dcb49f4c23..b215b6cc27 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be private. */ public interface NodeWithPrivateModifier extends NodeWithModifiers { + default boolean isPrivate() { return hasModifier(PRIVATE); } 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 index 8c5a9fe5b8..d3ed0d18cb 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be protected. */ public interface NodeWithProtectedModifier extends NodeWithModifiers { + default boolean isProtected() { return hasModifier(PROTECTED); } 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 index 4c5e92aae7..f49aef2a17 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be public. */ public interface NodeWithPublicModifier extends NodeWithModifiers { + default boolean isPublic() { return hasModifier(PUBLIC); } @@ -38,5 +38,4 @@ default boolean isPublic() { 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 index c3a3cd24e0..a71f2c6dcf 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -43,5 +42,4 @@ default boolean isStatic() { 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 index 4dd2399c4c..f094aeedae 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.nodeTypes.modifiers; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * A node that can be strictfp. */ public interface NodeWithStrictfpModifier extends NodeWithModifiers { + default boolean isStrictfp() { return hasModifier(STRICTFP); } 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 index 65ec926452..1bd81029e6 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -33,8 +32,8 @@ public interface AstObserver { * Type of change occurring on a List */ enum ListChangeType { - ADDITION, - REMOVAL + + ADDITION, REMOVAL } /** 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 index cf6c14ea23..3284ea875d 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 262eac8fc9..19f2598630 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.observer; /** 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 index 3dcc93c3a5..2f808d8011 100644 --- 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 @@ -18,7 +18,6 @@ * 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; @@ -38,6 +37,7 @@ public static PropagatingAstObserver transformInPropagatingObserver(final AstObs return (PropagatingAstObserver) observer; } return new PropagatingAstObserver() { + @Override public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) { observer.propertyChange(observedNode, property, oldValue, newValue); @@ -114,5 +114,4 @@ private void considerAdding(Object element) { ((Observable) element).register(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 index a70111b74a..2a6267e94a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java @@ -20,14 +20,6 @@ */ package com.github.javaparser.ast.type; -import static com.github.javaparser.ast.NodeList.nodeList; -import static com.github.javaparser.utils.Utils.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; @@ -44,6 +36,14 @@ import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.utils.Pair; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +import static com.github.javaparser.ast.NodeList.nodeList; +import static com.github.javaparser.utils.Utils.assertNotNull; + /** * To indicate that a type is an array, it gets wrapped in an ArrayType for every array level it has. * So, int[][] becomes ArrayType(ArrayType(int)). @@ -294,7 +294,7 @@ public void ifArrayType(Consumer action) { public Optional toArrayType() { return Optional.of(this); } - + /** * Finds the element type, meaning: the type without ArrayTypes around it. *

@@ -304,7 +304,7 @@ public Optional toArrayType() { public Type getElementType() { return this.getComponentType().getElementType(); } - + /** * returns the array level that is 0 for non array type. */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java index 2d4eba5c4a..5cfbbac5b9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -20,10 +20,6 @@ */ package com.github.javaparser.ast.type; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.joining; -import java.util.Optional; -import java.util.function.Consumer; import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; @@ -42,6 +38,13 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.resolution.types.ResolvedType; + +import java.util.Optional; +import java.util.function.Consumer; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; + /** * A class or an interface type. *
{@code Object} 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 index 446389c2dd..34b0c31e00 100644 --- 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 @@ -20,12 +20,6 @@ */ package com.github.javaparser.ast.type; -import static com.github.javaparser.utils.CodeGenerationUtils.f; -import static com.github.javaparser.utils.Utils.assertNotNull; - -import java.util.Optional; -import java.util.function.Consumer; - import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; @@ -39,6 +33,12 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.types.ResolvedType; +import java.util.Optional; +import java.util.function.Consumer; + +import static com.github.javaparser.utils.CodeGenerationUtils.f; +import static com.github.javaparser.utils.Utils.assertNotNull; + /** * Base class for types. * 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 index 7ebb286bd9..943fd0eb8b 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.Problem; @@ -33,6 +32,7 @@ * A simple interface where validators can report found problems. */ public class ProblemReporter { + private final Consumer problemConsumer; public ProblemReporter(Consumer problemConsumer) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/RecordAsTypeIdentifierNotAllowed.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/RecordAsTypeIdentifierNotAllowed.java index 5af8ddcc38..5a7f0b5272 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/RecordAsTypeIdentifierNotAllowed.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/RecordAsTypeIdentifierNotAllowed.java @@ -18,24 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.RecordDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.expr.SimpleName; -import static com.github.javaparser.utils.CodeGenerationUtils.f; - /** * Validates that "record" cannot be used as identifier for type declarations (e.g., classes, enums, and records). * For details, see JEP 395 */ public class RecordAsTypeIdentifierNotAllowed extends VisitorValidator { + private final String error; public RecordAsTypeIdentifierNotAllowed() { @@ -63,7 +58,6 @@ private boolean validUsage(Node node) { return true; } Node parent = node.getParentNode().get(); - return !(parent instanceof TypeDeclaration); } } 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 index d462237e5e..22b3612308 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.expr.Name; @@ -31,7 +30,9 @@ * 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) { 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 index 1c94e4a4b2..0265b215fd 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ * and adds a problem for all nodes that pass a condition. */ public class SimpleValidator extends SingleNodeTypeValidator { + public SimpleValidator(Class type, Predicate condition, BiConsumer problemSupplier) { super(type, (node, problemReporter) -> { if (condition.test(node)) { 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 index ead67c6fed..2036697dc3 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -27,7 +26,9 @@ * Runs a validator on all nodes of a certain type. */ public class SingleNodeTypeValidator implements Validator { + private final Class type; + private final TypedValidator validator; public SingleNodeTypeValidator(Class type, TypedValidator validator) { 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 index 6e5493c58c..e7e4147ce1 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ * A validator that walks the whole tree, visiting every node. */ public class TreeVisitorValidator implements Validator { + private final Validator validator; public TreeVisitorValidator(Validator validator) { 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 index 00b2da7936..f2e8796c80 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ParseResult; @@ -32,6 +31,7 @@ * A validator that validates a known node type. */ public interface TypedValidator extends BiConsumer { + /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here @@ -41,11 +41,10 @@ public interface TypedValidator extends BiConsumer result, ParserConfiguration configuration) { - result.getResult().ifPresent(node -> - accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem))) - ); + 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 index 13ff510d13..5027f5df43 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -28,6 +27,7 @@ * It is fully up to the implementor how to do this. */ public interface Validator extends TypedValidator { + /** * @param node the node that wants to be validated * @param problemReporter when found, validation errors can be reported here 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 index 2f07364f87..e8b4ac56d3 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ * A validator that will call a collection of validators. */ public class Validators implements Validator { + private final List validators = new ArrayList<>(); public Validators(Validator... validators) { 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 index e02e7769a0..6b90297fe0 100644 --- 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 @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator; import com.github.javaparser.ast.Node; @@ -30,6 +29,7 @@ * Implement the "visit" methods you want to use for validation. */ public abstract class VisitorValidator extends VoidVisitorAdapter implements Validator { + @Override public void accept(Node node, ProblemReporter problemReporter) { node.accept(this, problemReporter); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java index 4034bc4a79..ffaba3d958 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10PreviewValidator.java @@ -18,14 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.validator.SingleNodeTypeValidator; -import com.github.javaparser.ast.validator.Validator; -import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; - /** * This validator validates according to Java 10 syntax rules -- including incubator/preview/second preview features. * @@ -35,15 +29,11 @@ public class Java10PreviewValidator extends Java10Validator { public Java10PreviewValidator() { super(); - // Incubator // No incubator language features added within Java 10 - // Preview // No preview language features added within Java 10 - // 2nd Preview // No 2nd preview language features added within Java 10 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java index d531698aea..a8d26d0159 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java10Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -37,9 +36,7 @@ public class Java10Validator extends Java9Validator { public Java10Validator() { super(); - // Released Language Features - { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -47,6 +44,5 @@ public Java10Validator() { */ add(varOnlyOnLocalVariableDefinitionAndForAndTry); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java index c03fe99272..6dda255bf5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11PreviewValidator.java @@ -18,14 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.validator.SingleNodeTypeValidator; -import com.github.javaparser.ast.validator.Validator; -import com.github.javaparser.ast.validator.language_level_validations.chunks.VarValidator; - /** * This validator validates according to Java 11 syntax rules -- including incubator/preview/second preview features. * @@ -35,15 +29,11 @@ public class Java11PreviewValidator extends Java11Validator { public Java11PreviewValidator() { super(); - // Incubator // No incubator language features added within Java 11 - // Preview // No preview language features added within Java 11 - // 2nd Preview // No 2nd preview language features added within Java 11 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java index fe49af8f33..51ffb153cf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java11Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.type.VarType; @@ -32,11 +31,11 @@ * @see https://openjdk.java.net/projects/jdk/11/ */ public class Java11Validator extends Java10Validator { + final Validator varAlsoInLambdaParameters = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(true)); public Java11Validator() { super(); - { /* * Java 10 released local variable type inference in for and try-with (JEP286). @@ -44,6 +43,5 @@ public Java11Validator() { */ replace(varOnlyOnLocalVariableDefinitionAndForAndTry, varAlsoInLambdaParameters); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java index 4f07d22d01..be766b275c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,12 +29,9 @@ public class Java12PreviewValidator extends Java12Validator { public Java12PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 12 - // Preview - { /* * Switch Expressions (Preview) - first preview within Java 12 - https://openjdk.java.net/jeps/325 @@ -48,9 +44,7 @@ public Java12PreviewValidator() { remove(noSwitchExpressions); remove(onlyOneLabelInSwitchCase); } - // 2nd Preview // No new 2nd preview language features added within Java 12 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java index 742a6de327..ecf722f982 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java12Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,7 @@ public class Java12Validator extends Java11Validator { public Java12Validator() { super(); - // Released Language Features // No new released language features added within Java 12 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java index 7df3928b88..906b0106dc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,13 +29,11 @@ public class Java13PreviewValidator extends Java13Validator { public Java13PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 13 - // Preview - remove(noTextBlockLiteral); // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 - + // Text Block Literals - first preview within Java 13 - https://openjdk.java.net/jeps/355 + remove(noTextBlockLiteral); // 2nd Preview { /* @@ -51,6 +48,5 @@ public Java13PreviewValidator() { remove(onlyOneLabelInSwitchCase); remove(noYield); } - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java index 66a557bfdc..ff0441e37e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java13Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,7 @@ public class Java13Validator extends Java12Validator { public Java13Validator() { super(); - // Released Language Features // No new released language features added in Java 13 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java index 778ba1c0d0..0db9cba294 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,21 +29,19 @@ public class Java14PreviewValidator extends Java14Validator { public Java14PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 14 - // Preview - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof - first preview within Java 14 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); { // first preview within Java 14 - https://openjdk.java.net/jeps/359 remove(noRecordDeclaration); add(recordAsTypeIdentifierNotAllowed); add(recordDeclarationValidator); } - // 2nd Preview - remove(noTextBlockLiteral); // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 - + // Text Block Literals - 2nd preview within Java 14 - https://openjdk.java.net/jeps/378 + remove(noTextBlockLiteral); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java index ae104fbd01..39762357ca 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java14Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.RecordDeclaration; @@ -49,10 +48,8 @@ public class Java14Validator extends Java13Validator { final Validator recordDeclarationValidator = new SingleNodeTypeValidator<>(RecordDeclaration.class, new RecordDeclarationValidator()); - public Java14Validator() { super(); - // Released Language Features { /* diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java index 0c2dfb8c38..caf86b0be9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,15 +29,13 @@ public class Java15PreviewValidator extends Java15Validator { public Java15PreviewValidator() { super(); - // Incubator // No new incubator language features added within Java 15 - // Preview // remove(noSealedClasses); // Sealed Classes - first preview within Java 15 - https://openjdk.java.net/jeps/360 - // 2nd Preview - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof - 2nd preview in Java 15 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); { // Records - 2nd preview within Java 15 - https://openjdk.java.net/jeps/384 remove(noRecordDeclaration); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java index 9086f7fb19..dda357d57d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java15Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,8 +29,8 @@ public class Java15Validator extends Java14Validator { public Java15Validator() { super(); - // Released Language Features - remove(noTextBlockLiteral); // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 + // Text Block Literals - released within Java 15 - https://openjdk.java.net/jeps/378 + remove(noTextBlockLiteral); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java index f9228d40d3..f38329cf73 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,15 +29,11 @@ public class Java16PreviewValidator extends Java16Validator { public Java16PreviewValidator() { super(); - // Incubator // No new incubator language features added in Java 16 - // Preview // No new preview language features added in Java 16 - // 2nd Preview // TODO: remove(noSealedClasses); // Sealed Classes - 2nd preview in Java 16 - https://openjdk.java.net/jeps/397 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java index 83a0be6eb4..484bbd9944 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java16Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,9 @@ public class Java16Validator extends Java15Validator { public Java16Validator() { super(); - // Released Language Features - remove(noPatternMatchingInstanceOf); // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 + // Pattern Matching for instanceof released within Java 16 - https://openjdk.java.net/jeps/305 + remove(noPatternMatchingInstanceOf); { // Records released within Java 16 - https://openjdk.java.net/jeps/395 remove(noRecordDeclaration); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17PreviewValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17PreviewValidator.java index 0beebf0496..2fcd4ae89e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17PreviewValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17PreviewValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,15 +29,11 @@ public class Java17PreviewValidator extends Java17Validator { public Java17PreviewValidator() { super(); - // Incubator // No new incubator language features added in Java 17 - // Preview // No new preview language features added in Java 17 - // 2nd Preview // No new 2nd preview language features added in Java 17 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17Validator.java index 03d1c5cf6a..2bfe70b28a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java17Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** @@ -30,9 +29,7 @@ public class Java17Validator extends Java16Validator { public Java17Validator() { super(); - // Released Language Features // No new released language features added in Java 17 - } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java index 0855a59106..11d41749e5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_0Validator.java @@ -18,27 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; -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.Parameter; -import com.github.javaparser.ast.body.RecordDeclaration; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.expr.*; 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.*; import com.github.javaparser.ast.type.UnionType; -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.Validator; -import com.github.javaparser.ast.validator.Validators; +import com.github.javaparser.ast.validator.*; import com.github.javaparser.ast.validator.language_level_validations.chunks.CommonValidators; import com.github.javaparser.ast.validator.language_level_validations.chunks.ModifierValidator; import com.github.javaparser.ast.validator.language_level_validations.chunks.NoBinaryIntegerLiteralsValidator; @@ -48,20 +39,15 @@ * This validator validates according to Java 1.0 syntax rules. */ public class Java1_0Validator extends Validators { - final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods - = new ModifierValidator(false, false, false); - final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.") - ); - final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, - n -> !n.isTopLevelType(), - (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.") - ); - final Validator noReflection = new SimpleValidator<>(ClassExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Reflection is not supported.") - ); + + final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(false, false, false); + + final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class, n -> true, (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.")); + + final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class, n -> !n.isTopLevelType(), (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.")); + + final Validator noReflection = new SimpleValidator<>(ClassExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Reflection is not supported.")); + final Validator noGenerics = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { if (((NodeWithTypeArguments) node).getTypeArguments().isPresent()) { @@ -74,6 +60,7 @@ public class Java1_0Validator extends Validators { } } }); + final SingleNodeTypeValidator tryWithoutResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { if (n.getCatchClauses().isEmpty() && !n.getFinallyBlock().isPresent()) { reporter.report(n, "Try has no finally and no catch."); @@ -82,70 +69,42 @@ public class Java1_0Validator extends Validators { reporter.report(n, "Catch with resource is not supported."); } }); + final Validator noAnnotations = new TreeVisitorValidator((node, reporter) -> { if (node instanceof AnnotationExpr || node instanceof AnnotationDeclaration) { reporter.report(node, "Annotations are not supported."); } }); - final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, - n -> true, - (n, reporter) -> reporter.report(n, "Enumerations are not supported.") - ); - final Validator noVarargs = new SimpleValidator<>(Parameter.class, - Parameter::isVarArgs, - (n, reporter) -> reporter.report(n, "Varargs are not supported.") - ); - final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "For-each loops are not supported.") - ); - final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, - ImportDeclaration::isStatic, - (n, reporter) -> reporter.report(n, "Static imports are not supported.") - ); - final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, - n -> n.getLabels().size() > 1, - (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.") - ); - final Validator noYield = new SimpleValidator<>(YieldStmt.class, - n -> true, - (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.") - ); + + final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Enumerations are not supported.")); + + final Validator noVarargs = new SimpleValidator<>(Parameter.class, Parameter::isVarArgs, (n, reporter) -> reporter.report(n, "Varargs are not supported.")); + + final Validator noForEach = new SimpleValidator<>(ForEachStmt.class, n -> true, (n, reporter) -> reporter.report(n, "For-each loops are not supported.")); + + final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class, ImportDeclaration::isStatic, (n, reporter) -> reporter.report(n, "Static imports are not supported.")); + + final Validator onlyOneLabelInSwitchCase = new SimpleValidator<>(SwitchEntry.class, n -> n.getLabels().size() > 1, (n, reporter) -> reporter.report(n.getLabels().getParentNode().get(), "Only one label allowed in a switch-case.")); + + final Validator noYield = new SimpleValidator<>(YieldStmt.class, n -> true, (n, reporter) -> reporter.report(n, "Only labels allowed in break statements.")); + final Validator noBinaryIntegerLiterals = new NoBinaryIntegerLiteralsValidator(); + final Validator noUnderscoresInIntegerLiterals = new NoUnderscoresInIntegerLiteralsValidator(); - final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, - n -> true, - (n, reporter) -> reporter.report(n, "Multi-catch is not supported.") - ); - final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Lambdas are not supported.") - ); - final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, - n -> true, - (n, reporter) -> reporter.report(n, "Modules are not supported.") - ); - final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Switch expressions are not supported.") - ); - - - final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, - n -> n.getPattern().isPresent(), - (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.") - ); - - final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, - n -> true, - (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.") - ); - - final Validator noRecordDeclaration = new SimpleValidator<>(RecordDeclaration.class, - n -> true, - (n, reporter) -> reporter.report(n, "Record Declarations are not supported.") - ); + final Validator noMultiCatch = new SimpleValidator<>(UnionType.class, n -> true, (n, reporter) -> reporter.report(n, "Multi-catch is not supported.")); + + final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Lambdas are not supported.")); + + final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Modules are not supported.")); + + final Validator noSwitchExpressions = new SimpleValidator<>(SwitchExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Switch expressions are not supported.")); + + final Validator noPatternMatchingInstanceOf = new SimpleValidator<>(InstanceOfExpr.class, n -> n.getPattern().isPresent(), (n, reporter) -> reporter.report(n, "Use of patterns with instanceof is not supported.")); + + final Validator noTextBlockLiteral = new SimpleValidator<>(TextBlockLiteralExpr.class, n -> true, (n, reporter) -> reporter.report(n, "Text Block Literals are not supported.")); + + final Validator noRecordDeclaration = new SimpleValidator<>(RecordDeclaration.class, n -> true, (n, reporter) -> reporter.report(n, "Record Declarations are not supported.")); public Java1_0Validator() { super(new CommonValidators()); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java index 8fa3abb29c..f45e86eb5d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_1Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -30,12 +29,11 @@ * This validator validates according to Java 1.1 syntax rules. */ public class Java1_1Validator extends Java1_0Validator { - 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."); - }) - ); + + 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(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java index ea42e1a530..47063476ad 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_2Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.validator.ReservedKeywordValidator; @@ -29,7 +28,9 @@ * This validator validates according to Java 1.2 syntax rules. */ public class Java1_2Validator extends Java1_1Validator { + final Validator modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(true, false, false); + final Validator strictfpNotAllowed = new ReservedKeywordValidator("strictfp"); public Java1_2Validator() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java index 23fb9e857a..bda2acad8b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_3Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java1_4Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java index 7b81d569f5..9a7c573a28 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java1_4Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * 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/language_level_validations/Java5Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java index 8b644f6750..bed0901ced 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java5Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.Node; @@ -39,6 +38,7 @@ * This validator validates according to Java 5 syntax rules. */ public class Java5Validator extends Java1_4Validator { + final Validator genericsWithoutDiamondOperator = new TreeVisitorValidator((node, reporter) -> { if (node instanceof NodeWithTypeArguments) { Optional> typeArguments = ((NodeWithTypeArguments) node).getTypeArguments(); @@ -65,8 +65,7 @@ public class Java5Validator extends Java1_4Validator { VariableDeclarationExpr declaration = node.getVariable(); // assert that the variable declaration expression has exactly one variable declarator if (declaration.getVariables().size() != 1) { - reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + - "declarator. Given: " + declaration.getVariables().size() + "."); + reporter.report(node, "A foreach statement's variable declaration must have exactly one variable " + "declarator. Given: " + declaration.getVariables().size() + "."); } }); @@ -78,11 +77,9 @@ public Java5Validator() { add(noPrimitiveGenericArguments); add(enumNotAllowed); add(forEachStmt); - // 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java index 6db8eff2cb..1a8646da63 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java6Validator.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; /** * This validator validates according to Java 6 syntax rules. */ -public class Java6Validator extends Java5Validator{ +public class Java6Validator extends Java5Validator { + public Java6Validator() { super(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java index fdd8719e44..28de0aae43 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java7Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.expr.Expression; @@ -30,10 +29,9 @@ * This validator validates according to Java 7 syntax rules. */ public class Java7Validator extends Java6Validator { + final SingleNodeTypeValidator tryWithLimitedResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() - && n.getResources().isEmpty() - && !n.getFinallyBlock().isPresent()) { + 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()) { @@ -42,6 +40,7 @@ public class Java7Validator extends Java6Validator { } } }); + private final SingleNodeTypeValidator multiCatch = new SingleNodeTypeValidator<>(UnionType.class, (n, reporter) -> { // Case "0 elements" is caught elsewhere. if (n.getElements().size() == 1) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java index 20324ed7cf..5141527590 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java8Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -33,25 +32,24 @@ * @see https://openjdk.java.net/projects/jdk8/features */ public class Java8Validator extends Java7Validator { + final Validator modifiersWithoutPrivateInterfaceMethods = new ModifierValidator(true, true, false); - 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."); - } - }); + + 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/language_level_validations/Java9Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java index c93c09ffd2..97b7f6cea5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/Java9Validator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations; import com.github.javaparser.ast.stmt.TryStmt; @@ -33,27 +32,25 @@ * @see https://openjdk.java.net/projects/jdk9/ */ public class Java9Validator extends Java8Validator { + final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator(); + final Validator modifiers = new ModifierValidator(true, true, true); + final SingleNodeTypeValidator tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> { - if (n.getCatchClauses().isEmpty() - && n.getResources().isEmpty() - && !n.getFinallyBlock().isPresent()) { + 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(); - // Released Language Features - /* * Note 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 (that is done by the Java 10 post-processor). * You can add the node by hand, but that is obscure enough to ignore. */ - add(underscoreKeywordValidator); remove(noModules); replace(modifiersWithoutPrivateInterfaceMethods, modifiers); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java index 78a8c791a2..28c78317b5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/CommonValidators.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.NodeList; @@ -36,54 +35,39 @@ * 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(); + 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."); } - 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 "" + }); + } + }), 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/language_level_validations/chunks/ModifierValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java index 09e7e1751a..bb53d2ab4e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/ModifierValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Modifier; @@ -39,17 +38,21 @@ import static com.github.javaparser.ast.Modifier.Keyword.*; 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.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP}; - private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[]{PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; - private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[]{PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT}; + + private final Modifier.Keyword[] interfaceWithNothingSpecial = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP }; + + private final Modifier.Keyword[] interfaceWithStaticAndDefault = new Modifier.Keyword[] { PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT }; + + private final Modifier.Keyword[] interfaceWithStaticAndDefaultAndPrivate = new Modifier.Keyword[] { 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) { @@ -228,5 +231,4 @@ private & NodeWithTokenRange> void validateAt reporter.report(t, builder.toString()); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java index c88674574c..7e39bf73dd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoBinaryIntegerLiteralsValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -28,6 +27,7 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoBinaryIntegerLiteralsValidator extends VisitorValidator { + @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java index 909f0c0878..6bbae7931c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/NoUnderscoresInIntegerLiteralsValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.expr.IntegerLiteralExpr; @@ -28,6 +27,7 @@ import com.github.javaparser.ast.validator.VisitorValidator; public class NoUnderscoresInIntegerLiteralsValidator extends VisitorValidator { + @Override public void visit(IntegerLiteralExpr n, ProblemReporter arg) { validate(n, arg); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/RecordDeclarationValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/RecordDeclarationValidator.java index 8a6af341de..c5e5cb992b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/RecordDeclarationValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/RecordDeclarationValidator.java @@ -21,10 +21,7 @@ private void forbidAbstractModifier(RecordDeclaration n, ProblemReporter reporte } private void forbidNonStaticFieldsInRecords(RecordDeclaration n, ProblemReporter reporter) { - long nonStaticFieldCount = n.getFields().stream() - .filter(fieldDeclaration -> !fieldDeclaration.isStatic()) - .count(); - + long nonStaticFieldCount = n.getFields().stream().filter(fieldDeclaration -> !fieldDeclaration.isStatic()).count(); if (nonStaticFieldCount > 0) { reporter.report(n, "Record Declarations must have zero non-static fields."); } @@ -59,21 +56,11 @@ private void forbidNonStaticFieldsInRecords(RecordDeclaration n, ProblemReporter */ private void validateRecordComponentAccessorMethods(RecordDeclaration n, ProblemReporter reporter) { n.getParameters().forEach(parameter -> { - n.getMethodsByName(parameter.getNameAsString()) - .stream() - .filter(methodDeclaration -> methodDeclaration.getParameters().isEmpty()) - .forEach(methodDeclaration -> { - if (!methodDeclaration.getType().equals(parameter.getType())) { - reporter.report( - n, - String.format( - "Incorrect component accessor return type. Expected: '%s', found: '%s'.", - parameter.getTypeAsString(), - methodDeclaration.getTypeAsString() - ) - ); - } - }); + n.getMethodsByName(parameter.getNameAsString()).stream().filter(methodDeclaration -> methodDeclaration.getParameters().isEmpty()).forEach(methodDeclaration -> { + if (!methodDeclaration.getType().equals(parameter.getType())) { + reporter.report(n, String.format("Incorrect component accessor return type. Expected: '%s', found: '%s'.", parameter.getTypeAsString(), methodDeclaration.getTypeAsString())); + } + }); }); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java index 46cce4e387..b2d159f44d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/UnderscoreKeywordValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -28,6 +27,7 @@ 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); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java index 8a4492ecb4..687df1e19b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/language_level_validations/chunks/VarValidator.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.language_level_validations.chunks; import com.github.javaparser.ast.Node; @@ -29,8 +28,8 @@ 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.stmt.ForStmt; import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.ast.type.VarType; import com.github.javaparser.ast.validator.ProblemReporter; @@ -39,6 +38,7 @@ import java.util.Optional; public class VarValidator implements TypedValidator { + private boolean varAllowedInLambdaParameters; public VarValidator(boolean varAllowedInLambdaParameters) { @@ -52,10 +52,7 @@ public void accept(VarType node, ProblemReporter reporter) { if (!variableDeclarator.isPresent()) { // Java 11's var in lambda's if (varAllowedInLambdaParameters) { - boolean valid = node - .findAncestor(Parameter.class) - .flatMap(Node::getParentNode) - .map((Node p) -> p instanceof LambdaExpr).orElse(false); + boolean valid = node.findAncestor(Parameter.class).flatMap(Node::getParentNode).map((Node p) -> p instanceof LambdaExpr).orElse(false); if (valid) { return; } @@ -87,8 +84,7 @@ public void accept(VarType node, ProblemReporter reporter) { return; } container.ifPresent(c -> { - boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || - c instanceof ExpressionStmt || c instanceof TryStmt; + boolean positionIsFine = c instanceof ForStmt || c instanceof ForEachStmt || c instanceof ExpressionStmt || c instanceof TryStmt; if (!positionIsFine) { reportIllegalPosition(node, reporter); } @@ -105,12 +101,10 @@ public void accept(VarType node, ProblemReporter reporter) { reporter.report(node, "\"var\" cannot infer array types."); } }); - } }); }); }); - } private void reportIllegalPosition(VarType n, ProblemReporter reporter) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java index 4db3586a49..61bf8c5500 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ParseResult; @@ -32,7 +31,9 @@ * Processes the generic AST into a Java 10 AST and validates it. */ public class Java10PostProcessor extends PostProcessors { + protected final Processor varNodeCreator = new Processor() { + @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { result.getResult().ifPresent(node -> { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java11PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java11PostProcessor.java index e485466f19..1e137b1928 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java11PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java11PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java12PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java12PostProcessor.java index 0815f7ba17..2313dd5809 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java12PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java12PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java13PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java13PostProcessor.java index 9ec2f1f444..4d0b1c04d6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java13PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java13PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java14PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java14PostProcessor.java index 5ac8aa3ca0..f05ace6cb3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java14PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java14PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java15PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java15PostProcessor.java index 3c7ca11bf1..78de13b249 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java15PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java15PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java16PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java16PostProcessor.java index 9b64ce6bcf..5b1b4ab431 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java16PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java16PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java17PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java17PostProcessor.java index da861ee236..e1b643ee6b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java17PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java17PostProcessor.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java index 1c64c9bfee..6f1990781e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/PostProcessors.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.ast.validator.postprocessors; import com.github.javaparser.ParseResult; @@ -34,6 +33,7 @@ * A post processor that will call a collection of post processors. */ public class PostProcessors { + private final List postProcessors = new ArrayList<>(); public PostProcessors(Processor... postProcessors) { 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 index 949d7275c3..04a615e229 100644 --- 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 @@ -18,7 +18,6 @@ * 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; 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 index 3b39eb6255..31510ee004 100644 --- 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 @@ -18,10 +18,10 @@ * 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. * diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java index d1bc8be711..8ce687e91e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc; import com.github.javaparser.ast.comments.JavadocComment; @@ -27,7 +26,7 @@ import java.util.LinkedList; import java.util.List; -import static com.github.javaparser.utils.Utils.*; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; /** * The structured content of a single Javadoc comment. @@ -40,6 +39,7 @@ public class Javadoc { private JavadocDescription description; + private List blockTags; public Javadoc(JavadocDescription description) { @@ -140,13 +140,12 @@ public List getBlockTags() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Javadoc document = (Javadoc) o; - return description.equals(document.description) && blockTags.equals(document.blockTags); - } @Override @@ -158,10 +157,6 @@ public int hashCode() { @Override public String toString() { - return "Javadoc{" + - "description=" + description + - ", blockTags=" + blockTags + - '}'; + return "Javadoc{" + "description=" + description + ", blockTags=" + blockTags + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java index ae6fd624c5..9765e42cf6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc; import com.github.javaparser.javadoc.description.JavadocDescription; @@ -45,6 +44,7 @@ public class JavadocBlockTag { * an unknown tag. */ public enum Type { + AUTHOR, DEPRECATED, EXCEPTION, @@ -77,12 +77,14 @@ static Type fromName(String tagName) { } return UNKNOWN; } - } private Type type; + private JavadocDescription content; + private Optional name = Optional.empty(); + private String tagName; public JavadocBlockTag(Type type, String content) { @@ -134,13 +136,15 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocBlockTag that = (JavadocBlockTag) o; - - if (type != that.type) return false; - if (!content.equals(that.content)) return false; + if (type != that.type) + return false; + if (!content.equals(that.content)) + return false; return name.equals(that.name); } @@ -154,10 +158,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocBlockTag{" + - "type=" + type + - ", content='" + content + '\'' + - ", name=" + name + - '}'; + return "JavadocBlockTag{" + "type=" + type + ", content='" + content + '\'' + ", name=" + name + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java index a7e0babf19..c87ad33ace 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; import com.github.javaparser.utils.Pair; @@ -71,7 +70,6 @@ public JavadocDescription() { public JavadocDescription(List elements) { this(); - this.elements.addAll(elements); } @@ -95,13 +93,12 @@ public boolean isEmpty() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocDescription that = (JavadocDescription) o; - return elements.equals(that.elements); - } @Override @@ -111,9 +108,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocDescription{" + - "elements=" + elements + - '}'; + return "JavadocDescription{" + "elements=" + elements + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java index c25cad958c..d9d9d9dec1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; /** @@ -27,5 +26,6 @@ * So for example {@code a text} or {@link String} could be valid description elements. */ public interface JavadocDescriptionElement { + String toText(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java index e2bf8a33a0..b875c131ea 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; import static com.github.javaparser.utils.Utils.nextWord; @@ -50,6 +49,7 @@ public static JavadocDescriptionElement fromText(String text) { * an unknown tag. */ public enum Type { + CODE, DOC_ROOT, INHERIT_DOC, @@ -74,11 +74,12 @@ static JavadocInlineTag.Type fromName(String tagName) { } return UNKNOWN; } - } private String tagName; + private Type type; + private String content; public JavadocInlineTag(String tagName, Type type, String content) { @@ -101,18 +102,20 @@ public String getName() { @Override public String toText() { - return "{@" + tagName + this.content +"}"; + return "{@" + tagName + this.content + "}"; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocInlineTag that = (JavadocInlineTag) o; - - if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false; - if (type != that.type) return false; + if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) + return false; + if (type != that.type) + return false; return content != null ? content.equals(that.content) : that.content == null; } @@ -126,10 +129,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocInlineTag{" + - "tagName='" + tagName + '\'' + - ", type=" + type + - ", content='" + content + '\'' + - '}'; + return "JavadocInlineTag{" + "tagName='" + tagName + '\'' + ", type=" + type + ", content='" + content + '\'' + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java index 884b4eb374..9c65c9aecb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.javadoc.description; /** @@ -28,6 +27,7 @@ * before and one after the inline tag ({@link String}). */ public class JavadocSnippet implements JavadocDescriptionElement { + private String text; public JavadocSnippet(String text) { @@ -44,13 +44,12 @@ public String toText() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; JavadocSnippet that = (JavadocSnippet) o; - return text.equals(that.text); - } @Override @@ -60,8 +59,6 @@ public int hashCode() { @Override public String toString() { - return "JavadocSnippet{" + - "text='" + text + '\'' + - '}'; + return "JavadocSnippet{" + "text='" + text + '\'' + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java index 73beea8c09..d11036b77a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import com.github.javaparser.ast.AllFieldsConstructor; @@ -27,7 +26,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; import static com.github.javaparser.utils.Utils.decapitalize; @@ -35,14 +37,23 @@ * Meta-data about all classes in the AST. These are all Nodes, except NodeList. */ public abstract class BaseNodeMetaModel { + private final Optional superNodeMetaModel; + private final List declaredPropertyMetaModels = new ArrayList<>(); + private final List derivedPropertyMetaModels = new ArrayList<>(); + private final List constructorParameters = new ArrayList<>(); + private final Class type; + private final String name; + private final String packageName; + private final boolean isAbstract; + private final boolean hasWildcard; public BaseNodeMetaModel(Optional superNodeMetaModel, Class type, String name, String packageName, boolean isAbstract, boolean hasWildcard) { @@ -157,13 +168,13 @@ public boolean isRootNode() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; BaseNodeMetaModel classMetaModel = (BaseNodeMetaModel) o; - - if (!type.equals(classMetaModel.type)) return false; - + if (!type.equals(classMetaModel.type)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java index dffb9d1d9b..5ae1498abb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java index a369e35566..2321aaa067 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java index d5be7c3286..87bcf49872 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; @@ -34,6 +33,6 @@ * (Used during generation of the meta model.) */ @Retention(RUNTIME) -@Target({FIELD, METHOD}) +@Target({ FIELD, METHOD }) public @interface NonEmptyProperty { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java index 4032b4e0a8..14142f1f55 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import java.lang.annotation.Retention; diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java index 3f59d67df5..3f6e8d79cc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.metamodel; import com.github.javaparser.ast.Node; @@ -33,13 +32,21 @@ * Meta-data about a property of a node in the AST. */ public class PropertyMetaModel { + private final BaseNodeMetaModel containingNodeMetaModel; + private final String name; + private final Class type; + private final Optional nodeReference; + private final boolean isOptional; + private final boolean isNonEmpty; + private final boolean isNodeList; + private final boolean hasWildcard; public PropertyMetaModel(BaseNodeMetaModel containingNodeMetaModel, String name, Class type, Optional nodeReference, boolean isOptional, boolean isNonEmpty, boolean isNodeList, boolean hasWildcard) { @@ -158,14 +165,15 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; PropertyMetaModel that = (PropertyMetaModel) o; - - if (!name.equals(that.name)) return false; - if (!type.equals(that.type)) return false; - + if (!name.equals(that.name)) + return false; + if (!type.equals(that.type)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java index 8760715ef6..6dca85259b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java @@ -18,40 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.GeneratedJavaParserConstants.*; -import static com.github.javaparser.ast.observer.ObservableProperty.*; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.FLAG; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.IS_EMPTY; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.IS_NOT_EMPTY; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.IS_PRESENT; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.*; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - import com.github.javaparser.GeneratedJavaParserConstants; -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.*; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.modules.ModuleDeclaration; -import com.github.javaparser.ast.modules.ModuleExportsDirective; -import com.github.javaparser.ast.modules.ModuleOpensDirective; -import com.github.javaparser.ast.modules.ModuleProvidesDirective; -import com.github.javaparser.ast.modules.ModuleRequiresDirective; -import com.github.javaparser.ast.modules.ModuleUsesDirective; +import com.github.javaparser.ast.modules.*; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.*; @@ -60,6 +34,14 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.ast.observer.ObservableProperty.*; +import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.*; +import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.*; + /** * The Concrete Syntax Model for a single node type. It knows the syntax used to represent a certain element in Java * code. @@ -67,6 +49,7 @@ public class ConcreteSyntaxModel { private static final Map concreteSyntaxModelByClass = new HashMap<>(); + private static Optional initializationError; private static CsmElement modifiers() { @@ -89,918 +72,131 @@ private static CsmElement annotations() { } private static CsmElement typeParameters() { - return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), - sequence(token(GeneratedJavaParserConstants.GT), space())); + return list(ObservableProperty.TYPE_PARAMETERS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT), space())); } private static CsmElement typeArguments() { - return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), - sequence(token(GeneratedJavaParserConstants.GT))); + return list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LT), sequence(token(GeneratedJavaParserConstants.GT))); } static { - - /// - /// Body - /// - - concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - token(GeneratedJavaParserConstants.AT), - token(GeneratedJavaParserConstants.INTERFACE), - space(), - child(ObservableProperty.NAME), - space(), - token(LBRACE), - newline(), - indent(), - list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), - unindent(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME), - token(LPAREN), - token(RPAREN), - conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), - semicolon() - )); - - concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), - space(), - child(ObservableProperty.NAME), - list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), - list(ObservableProperty.EXTENDED_TYPES, - sequence(string(GeneratedJavaParserConstants.COMMA), space()), - sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), - none()), - list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence( - space(), - token(GeneratedJavaParserConstants.IMPLEMENTS), - space()), none()), - space(), - block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))) - )); - - concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - typeParameters(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(RecordDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - token(GeneratedJavaParserConstants.RECORD), - space(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), - list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence( - space(), - token(GeneratedJavaParserConstants.IMPLEMENTS), - space()), none()), - space(), - block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))) - )); - - concreteSyntaxModelByClass.put(CompactConstructorDeclaration.class, sequence( - comment(), - memberAnnotations(), - modifiers(), - typeParameters(), - child(ObservableProperty.NAME), - list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence( - comment(), - memberAnnotations(), - child(ObservableProperty.NAME), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), - conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), - list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), - unindent(), - token(RBRACE), newline())) - )); - - concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence( - comment(), - annotations(), - modifiers(), - token(GeneratedJavaParserConstants.ENUM), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.IMPLEMENTED_TYPES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), - none()), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - indent(), - newline(), - list(ObservableProperty.ENTRIES, - sequence(comma(), newline()), - none(), - none()), - conditional(ObservableProperty.MEMBERS, IS_EMPTY, - conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), - sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), - unindent(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence( - orphanCommentsBeforeThis(), - comment(), - mix(annotations(), modifiers()), - conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), - space(), - list(ObservableProperty.VARIABLES, sequence(comma(), space())), - semicolon())); - - concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence( - comment(), - conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), - child(ObservableProperty.BODY))); - - concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence( - orphanCommentsBeforeThis(), - comment(), - mix(memberAnnotations(), modifiers()), - typeParameters(), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), - list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), - conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()) - )); - - concreteSyntaxModelByClass.put(Parameter.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - modifiers(), - child(ObservableProperty.TYPE), - conditional(ObservableProperty.VAR_ARGS, FLAG, sequence( - list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), - token(GeneratedJavaParserConstants.ELLIPSIS))), - space(), - child(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence( - comment(), - child(ObservableProperty.NAME), - // FIXME: we should introduce a derived property - // list(ObservableProperty.EXTRA_ARRAY_LEVELS), - conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), - child(ObservableProperty.INITIALIZER))) - )); - - /// - /// Expressions - /// - - concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence( - comment(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LBRACKET), - child(ObservableProperty.INDEX), - token(GeneratedJavaParserConstants.RBRACKET) - )); - - concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.NEW), - space(), - child(ObservableProperty.ELEMENT_TYPE), - list(ObservableProperty.LEVELS), - conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))) - )); - - concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LBRACE), - list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), - orphanCommentsEnding(), - token(RBRACE))); - - concreteSyntaxModelByClass.put(AssignExpr.class, sequence( - comment(), - child(ObservableProperty.TARGET), - space(), - attribute(ObservableProperty.OPERATOR), - space(), - child(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(BinaryExpr.class, sequence( - comment(), - child(ObservableProperty.LEFT), - space(), - attribute(ObservableProperty.OPERATOR), - space(), - child(ObservableProperty.RIGHT) - )); - - concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence( - comment(), attribute(VALUE) - )); - - concreteSyntaxModelByClass.put(CastExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.TYPE), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.EXPRESSION) - )); - - concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence( - comment(), - charToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(ClassExpr.class, sequence( - comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); - - concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence( - comment(), - child(ObservableProperty.CONDITION), - space(), - token(GeneratedJavaParserConstants.HOOK), - space(), - child(ObservableProperty.THEN_EXPR), - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.ELSE_EXPR) - )); - - concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.INNER), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence( - comment(), - child(SCOPE), - token(GeneratedJavaParserConstants.DOT), - child(ObservableProperty.NAME) - )); - - concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence( - comment(), - child(ObservableProperty.EXPRESSION), - space(), - token(GeneratedJavaParserConstants.INSTANCEOF), - space(), - child(ObservableProperty.TYPE) - )); - - concreteSyntaxModelByClass.put(PatternExpr.class, sequence( - child(ObservableProperty.TYPE), - space(), - child(ObservableProperty.NAME) - )); - - concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(LambdaExpr.class, sequence( - comment(), - conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), - list(ObservableProperty.PARAMETERS, sequence(comma(), space())), - conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), - space(), - token(GeneratedJavaParserConstants.ARROW), - space(), - conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)) - )); - - concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence( - comment(), - attribute(ObservableProperty.VALUE) - )); - + // / + // / Body + // / + concreteSyntaxModelByClass.put(AnnotationDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), token(GeneratedJavaParserConstants.AT), token(GeneratedJavaParserConstants.INTERFACE), space(), child(ObservableProperty.NAME), space(), token(LBRACE), newline(), indent(), list(ObservableProperty.MEMBERS, newline(), none(), none(), newline()), unindent(), token(RBRACE))); + concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(LPAREN), token(RPAREN), conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants._DEFAULT), space(), child(DEFAULT_VALUE))), semicolon())); + concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)), space(), child(ObservableProperty.NAME), list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(ObservableProperty.EXTENDED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))))); + concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), typeParameters(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(RecordDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), token(GeneratedJavaParserConstants.RECORD), space(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), newline(), newline()))))); + concreteSyntaxModelByClass.put(CompactConstructorDeclaration.class, sequence(comment(), memberAnnotations(), modifiers(), typeParameters(), child(ObservableProperty.NAME), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence(comment(), memberAnnotations(), child(ObservableProperty.NAME), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)), conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), newline()), unindent(), token(RBRACE), newline())))); + concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence(comment(), annotations(), modifiers(), token(GeneratedJavaParserConstants.ENUM), space(), child(ObservableProperty.NAME), list(ObservableProperty.IMPLEMENTED_TYPES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()), none()), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), newline(), list(ObservableProperty.ENTRIES, sequence(comma(), newline()), none(), none()), conditional(ObservableProperty.MEMBERS, IS_EMPTY, conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()), sequence(semicolon(), newline(), newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), newline()))), unindent(), token(RBRACE))); + concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), mix(annotations(), modifiers()), conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())), semicolon())); + concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence(comment(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence(orphanCommentsBeforeThis(), comment(), mix(memberAnnotations(), modifiers()), typeParameters(), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())), list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()), conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon()))); + concreteSyntaxModelByClass.put(Parameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.TYPE), conditional(ObservableProperty.VAR_ARGS, FLAG, sequence(list(ObservableProperty.VAR_ARGS_ANNOTATIONS, space(), none(), none()), token(GeneratedJavaParserConstants.ELLIPSIS))), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), // FIXME: we should introduce a derived property + // list(ObservableProperty.EXTRA_ARRAY_LEVELS), + conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER))))); + // / + // / Expressions + // / + concreteSyntaxModelByClass.put(ArrayAccessExpr.class, sequence(comment(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.INDEX), token(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NEW), space(), child(ObservableProperty.ELEMENT_TYPE), list(ObservableProperty.LEVELS), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER))))); + concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LBRACE), list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()), orphanCommentsEnding(), token(RBRACE))); + concreteSyntaxModelByClass.put(AssignExpr.class, sequence(comment(), child(ObservableProperty.TARGET), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(BinaryExpr.class, sequence(comment(), child(ObservableProperty.LEFT), space(), attribute(ObservableProperty.OPERATOR), space(), child(ObservableProperty.RIGHT))); + concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence(comment(), attribute(VALUE))); + concreteSyntaxModelByClass.put(CastExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.EXPRESSION))); + concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence(comment(), charToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(ClassExpr.class, sequence(comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS))); + concreteSyntaxModelByClass.put(ConditionalExpr.class, sequence(comment(), child(ObservableProperty.CONDITION), space(), token(GeneratedJavaParserConstants.HOOK), space(), child(ObservableProperty.THEN_EXPR), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ELSE_EXPR))); + concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.INNER), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(FieldAccessExpr.class, sequence(comment(), child(SCOPE), token(GeneratedJavaParserConstants.DOT), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence(comment(), child(ObservableProperty.EXPRESSION), space(), token(GeneratedJavaParserConstants.INSTANCEOF), space(), child(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(PatternExpr.class, sequence(child(ObservableProperty.TYPE), space(), child(ObservableProperty.NAME))); + concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(LambdaExpr.class, sequence(comment(), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)), list(ObservableProperty.PARAMETERS, sequence(comma(), space())), conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)), space(), token(GeneratedJavaParserConstants.ARROW), space(), conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY)))); + concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence(comment(), attribute(ObservableProperty.VALUE))); concreteSyntaxModelByClass.put(MarkerAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), attribute(ObservableProperty.NAME))); - - concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), - child(ObservableProperty.NAME), - space(), - token(GeneratedJavaParserConstants.ASSIGN), - space(), - child(ObservableProperty.VALUE))); - - concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence( - comment(), - conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), - typeArguments(), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence( - comment(), - child(ObservableProperty.SCOPE), - token(GeneratedJavaParserConstants.DOUBLECOLON), - typeArguments(), - attribute(ObservableProperty.IDENTIFIER) - )); - + concreteSyntaxModelByClass.put(MemberValuePair.class, sequence(comment(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), typeArguments(), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence(comment(), child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOUBLECOLON), typeArguments(), attribute(ObservableProperty.IDENTIFIER))); concreteSyntaxModelByClass.put(Modifier.class, attribute(ObservableProperty.KEYWORD)); - - concreteSyntaxModelByClass.put(Name.class, sequence( - comment(), - conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), - attribute(ObservableProperty.IDENTIFIER), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(NameExpr.class, sequence( - comment(), - child(ObservableProperty.NAME), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.AT), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.PAIRS, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN) - )); - - concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.NULL) - )); - - concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence( - comment(), - conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.NEW), - space(), - list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), - conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), - child(ObservableProperty.TYPE), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), - token(GeneratedJavaParserConstants.RPAREN), - conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, - sequence( - space(), token(LBRACE), newline(), indent(), - list(ObservableProperty.ANONYMOUS_CLASS_BODY, - newline(), - newline(), - newline(), - newline()), - unindent(), - token(RBRACE) - )) - )); - + concreteSyntaxModelByClass.put(Name.class, sequence(comment(), conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))), attribute(ObservableProperty.IDENTIFIER), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(NameExpr.class, sequence(comment(), child(ObservableProperty.NAME), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.PAIRS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.NULL))); + concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence(comment(), conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.NEW), space(), list(ObservableProperty.TYPE_ARGUMENTS, sequence(comma(), space()), token(LT), token(GT)), conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT, sequence(space(), token(LBRACE), newline(), indent(), list(ObservableProperty.ANONYMOUS_CLASS_BODY, newline(), newline(), newline(), newline()), unindent(), token(RBRACE))))); concreteSyntaxModelByClass.put(SimpleName.class, attribute(ObservableProperty.IDENTIFIER)); - - concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.AT), - child(ObservableProperty.NAME), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.MEMBER_VALUE), - token(GeneratedJavaParserConstants.RPAREN))); - - concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence( - comment(), - stringToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence( - comment(), - textBlockToken(ObservableProperty.VALUE) - )); - - concreteSyntaxModelByClass.put(SuperExpr.class, sequence( - comment(), - conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.SUPER) - )); - - concreteSyntaxModelByClass.put(ThisExpr.class, sequence( - comment(), - conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), - token(GeneratedJavaParserConstants.THIS) - )); - - concreteSyntaxModelByClass.put(TypeExpr.class, sequence( - comment(), - child(ObservableProperty.TYPE) - )); - - concreteSyntaxModelByClass.put(UnaryExpr.class, sequence( - conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), - child(ObservableProperty.EXPRESSION), - conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)) - )); - - concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS, space(), none(), space()), - modifiers(), - child(ObservableProperty.MAXIMUM_COMMON_TYPE), - space(), - list(ObservableProperty.VARIABLES, sequence(comma(), space())) - )); - - /// - /// Statements - /// - - concreteSyntaxModelByClass.put(AssertStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.ASSERT), - space(), - child(ObservableProperty.CHECK), - conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence( - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.MESSAGE) - )), - semicolon() - )); - - concreteSyntaxModelByClass.put(BlockStmt.class, sequence( - orphanCommentsBeforeThis(), - comment(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), - orphanCommentsEnding(), - token(RBRACE) - )); - - concreteSyntaxModelByClass.put(BreakStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.BREAK), - conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), - semicolon() - )); - - concreteSyntaxModelByClass.put(CatchClause.class, sequence( - comment(), - space(), - token(GeneratedJavaParserConstants.CATCH), - space(), - token(LPAREN), - child(ObservableProperty.PARAMETER), - token(RPAREN), - space(), - child(BODY) - )); - - concreteSyntaxModelByClass.put(ContinueStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.CONTINUE), - conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), - semicolon() - )); - - concreteSyntaxModelByClass.put(DoStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.DO), - space(), - child(ObservableProperty.BODY), - space(), - token(GeneratedJavaParserConstants.WHILE), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - semicolon() - )); - - concreteSyntaxModelByClass.put(EmptyStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SEMICOLON) - )); - - concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SEMICOLON) - )); - - concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence( - comment(), - conditional(ObservableProperty.THIS, FLAG, - sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), - sequence( - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), - typeArguments(), - token(GeneratedJavaParserConstants.SUPER) - )), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN), - semicolon() - )); - - concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence( - orphanCommentsBeforeThis(), - comment(), - child(ObservableProperty.EXPRESSION), - semicolon() - )); - - concreteSyntaxModelByClass.put(ForEachStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.FOR), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.VARIABLE), - space(), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.ITERABLE), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(ForStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.FOR), - space(), - token(GeneratedJavaParserConstants.LPAREN), - list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), - semicolon(), - space(), - child(ObservableProperty.COMPARE), - semicolon(), - space(), - list(ObservableProperty.UPDATE, sequence(comma(), space())), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - concreteSyntaxModelByClass.put(IfStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.IF), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, - sequence(space(), child(ObservableProperty.THEN_STMT), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), - sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), - unindent())), - conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, - sequence(token(GeneratedJavaParserConstants.ELSE), - conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, - sequence(space(), child(ObservableProperty.ELSE_STMT)), - sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))) - )); - - concreteSyntaxModelByClass.put(LabeledStmt.class, sequence( - comment(), - child(ObservableProperty.LABEL), - token(GeneratedJavaParserConstants.COLON), - space(), - child(ObservableProperty.STATEMENT) - )); - - concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence( - comment(), - child(ObservableProperty.CLASS_DECLARATION) - )); - - concreteSyntaxModelByClass.put(LocalRecordDeclarationStmt.class, sequence( - comment(), - child(ObservableProperty.RECORD_DECLARATION) - )); - - concreteSyntaxModelByClass.put(ReturnStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.RETURN), - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), - semicolon())); - - concreteSyntaxModelByClass.put(YieldStmt.class, sequence( - comment(), - token(YIELD), - conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), - semicolon())); - - concreteSyntaxModelByClass.put(SwitchEntry.class, sequence( - comment(), - conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, - sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), - sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), - newline(), - indent(), - list(ObservableProperty.STATEMENTS, newline(), none(), newline()), - unindent() - )); - - concreteSyntaxModelByClass.put(SwitchStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SWITCH), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.SELECTOR), - token(GeneratedJavaParserConstants.RPAREN), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.ENTRIES, none(), indent(), unindent()), - token(GeneratedJavaParserConstants.RBRACE) - )); - - concreteSyntaxModelByClass.put(SwitchExpr.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SWITCH), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.SELECTOR), - token(GeneratedJavaParserConstants.RPAREN), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - list(ObservableProperty.ENTRIES, none(), indent(), unindent()), - token(GeneratedJavaParserConstants.RBRACE) - )); - - concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.SYNCHRONIZED), - space(), - token(LPAREN), - child(EXPRESSION), - token(RPAREN), - space(), - child(BODY) - )); - - concreteSyntaxModelByClass.put(ThrowStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.THROW), - space(), - child(ObservableProperty.EXPRESSION), - semicolon() - )); - - concreteSyntaxModelByClass.put(TryStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.TRY), - space(), - conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence( - token(LPAREN), - list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), - token(RPAREN), - space())), - child(ObservableProperty.TRY_BLOCK), - list(ObservableProperty.CATCH_CLAUSES), - conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))) - )); - - concreteSyntaxModelByClass.put(WhileStmt.class, sequence( - comment(), - token(GeneratedJavaParserConstants.WHILE), - space(), - token(GeneratedJavaParserConstants.LPAREN), - child(ObservableProperty.CONDITION), - token(GeneratedJavaParserConstants.RPAREN), - space(), - child(ObservableProperty.BODY) - )); - - /// - /// Types - /// - - concreteSyntaxModelByClass.put(ArrayType.class, sequence( - child(ObservableProperty.COMPONENT_TYPE), - list(ObservableProperty.ANNOTATIONS), - string(GeneratedJavaParserConstants.LBRACKET), - string(GeneratedJavaParserConstants.RBRACKET))); - - concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), - conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), - list(ANNOTATIONS, space(), none(), space()), - child(NAME), - conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, - sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), - list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); - - concreteSyntaxModelByClass.put(IntersectionType.class, sequence( - comment(), - annotations(), - list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); - - concreteSyntaxModelByClass.put(PrimitiveType.class, sequence( - comment(), - list(ObservableProperty.ANNOTATIONS), - attribute(ObservableProperty.TYPE))); - - concreteSyntaxModelByClass.put(TypeParameter.class, sequence( - comment(), - annotations(), - child(ObservableProperty.NAME), - list(ObservableProperty.TYPE_BOUND, - sequence( - space(), - token(GeneratedJavaParserConstants.BIT_AND), - space()), - sequence( - space(), - token(GeneratedJavaParserConstants.EXTENDS), - space()), - none()) - )); - - concreteSyntaxModelByClass.put(UnionType.class, sequence( - comment(), - annotations(), - list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())) - )); - + concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), child(ObservableProperty.NAME), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.MEMBER_VALUE), token(GeneratedJavaParserConstants.RPAREN))); + concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence(comment(), stringToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(TextBlockLiteralExpr.class, sequence(comment(), textBlockToken(ObservableProperty.VALUE))); + concreteSyntaxModelByClass.put(SuperExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.SUPER))); + concreteSyntaxModelByClass.put(ThisExpr.class, sequence(comment(), conditional(TYPE_NAME, IS_PRESENT, sequence(child(TYPE_NAME), token(GeneratedJavaParserConstants.DOT))), token(GeneratedJavaParserConstants.THIS))); + concreteSyntaxModelByClass.put(TypeExpr.class, sequence(comment(), child(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(UnaryExpr.class, sequence(conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)), child(ObservableProperty.EXPRESSION), conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR)))); + concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS, space(), none(), space()), modifiers(), child(ObservableProperty.MAXIMUM_COMMON_TYPE), space(), list(ObservableProperty.VARIABLES, sequence(comma(), space())))); + // / + // / Statements + // / + concreteSyntaxModelByClass.put(AssertStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.ASSERT), space(), child(ObservableProperty.CHECK), conditional(ObservableProperty.MESSAGE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.MESSAGE))), semicolon())); + concreteSyntaxModelByClass.put(BlockStmt.class, sequence(orphanCommentsBeforeThis(), comment(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())), orphanCommentsEnding(), token(RBRACE))); + concreteSyntaxModelByClass.put(BreakStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.BREAK), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); + concreteSyntaxModelByClass.put(CatchClause.class, sequence(comment(), space(), token(GeneratedJavaParserConstants.CATCH), space(), token(LPAREN), child(ObservableProperty.PARAMETER), token(RPAREN), space(), child(BODY))); + concreteSyntaxModelByClass.put(ContinueStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.CONTINUE), conditional(ObservableProperty.LABEL, IS_PRESENT, sequence(space(), child(ObservableProperty.LABEL))), semicolon())); + concreteSyntaxModelByClass.put(DoStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.DO), space(), child(ObservableProperty.BODY), space(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), semicolon())); + concreteSyntaxModelByClass.put(EmptyStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); + concreteSyntaxModelByClass.put(UnparsableStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SEMICOLON))); + concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, sequence(comment(), conditional(ObservableProperty.THIS, FLAG, sequence(typeArguments(), token(GeneratedJavaParserConstants.THIS)), sequence(conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(child(ObservableProperty.EXPRESSION), token(GeneratedJavaParserConstants.DOT))), typeArguments(), token(GeneratedJavaParserConstants.SUPER))), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.ARGUMENTS, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), semicolon())); + concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence(orphanCommentsBeforeThis(), comment(), child(ObservableProperty.EXPRESSION), semicolon())); + concreteSyntaxModelByClass.put(ForEachStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.VARIABLE), space(), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.ITERABLE), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(ForStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.FOR), space(), token(GeneratedJavaParserConstants.LPAREN), list(ObservableProperty.INITIALIZATION, sequence(comma(), space())), semicolon(), space(), child(ObservableProperty.COMPARE), semicolon(), space(), list(ObservableProperty.UPDATE, sequence(comma(), space())), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + concreteSyntaxModelByClass.put(IfStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.IF), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())), sequence(newline(), indent(), child(ObservableProperty.THEN_STMT), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()), unindent())), conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, sequence(token(GeneratedJavaParserConstants.ELSE), conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG, sequence(space(), child(ObservableProperty.ELSE_STMT)), sequence(newline(), indent(), child(ObservableProperty.ELSE_STMT), unindent())))))); + concreteSyntaxModelByClass.put(LabeledStmt.class, sequence(comment(), child(ObservableProperty.LABEL), token(GeneratedJavaParserConstants.COLON), space(), child(ObservableProperty.STATEMENT))); + concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, sequence(comment(), child(ObservableProperty.CLASS_DECLARATION))); + concreteSyntaxModelByClass.put(LocalRecordDeclarationStmt.class, sequence(comment(), child(ObservableProperty.RECORD_DECLARATION))); + concreteSyntaxModelByClass.put(ReturnStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.RETURN), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); + concreteSyntaxModelByClass.put(YieldStmt.class, sequence(comment(), token(YIELD), conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))), semicolon())); + concreteSyntaxModelByClass.put(SwitchEntry.class, sequence(comment(), conditional(ObservableProperty.LABELS, IS_NOT_EMPTY, sequence(token(GeneratedJavaParserConstants.CASE), space(), list(ObservableProperty.LABELS), token(GeneratedJavaParserConstants.COLON)), sequence(token(GeneratedJavaParserConstants._DEFAULT), token(GeneratedJavaParserConstants.COLON))), newline(), indent(), list(ObservableProperty.STATEMENTS, newline(), none(), newline()), unindent())); + concreteSyntaxModelByClass.put(SwitchStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); + concreteSyntaxModelByClass.put(SwitchExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.SWITCH), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.SELECTOR), token(GeneratedJavaParserConstants.RPAREN), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), list(ObservableProperty.ENTRIES, none(), indent(), unindent()), token(GeneratedJavaParserConstants.RBRACE))); + concreteSyntaxModelByClass.put(SynchronizedStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.SYNCHRONIZED), space(), token(LPAREN), child(EXPRESSION), token(RPAREN), space(), child(BODY))); + concreteSyntaxModelByClass.put(ThrowStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.THROW), space(), child(ObservableProperty.EXPRESSION), semicolon())); + concreteSyntaxModelByClass.put(TryStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.TRY), space(), conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, sequence(token(LPAREN), list(ObservableProperty.RESOURCES, sequence(semicolon(), newline()), indent(), unindent()), token(RPAREN), space())), child(ObservableProperty.TRY_BLOCK), list(ObservableProperty.CATCH_CLAUSES), conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.FINALLY), space(), child(ObservableProperty.FINALLY_BLOCK))))); + concreteSyntaxModelByClass.put(WhileStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.WHILE), space(), token(GeneratedJavaParserConstants.LPAREN), child(ObservableProperty.CONDITION), token(GeneratedJavaParserConstants.RPAREN), space(), child(ObservableProperty.BODY))); + // / + // / Types + // / + concreteSyntaxModelByClass.put(ArrayType.class, sequence(child(ObservableProperty.COMPONENT_TYPE), list(ObservableProperty.ANNOTATIONS), string(GeneratedJavaParserConstants.LBRACKET), string(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(), conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))), list(ANNOTATIONS, space(), none(), space()), child(NAME), conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG, sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)), list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT))))); + concreteSyntaxModelByClass.put(IntersectionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space())))); + concreteSyntaxModelByClass.put(PrimitiveType.class, sequence(comment(), list(ObservableProperty.ANNOTATIONS), attribute(ObservableProperty.TYPE))); + concreteSyntaxModelByClass.put(TypeParameter.class, sequence(comment(), annotations(), child(ObservableProperty.NAME), list(ObservableProperty.TYPE_BOUND, sequence(space(), token(GeneratedJavaParserConstants.BIT_AND), space()), sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()), none()))); + concreteSyntaxModelByClass.put(UnionType.class, sequence(comment(), annotations(), list(ObservableProperty.ELEMENTS, sequence(space(), token(GeneratedJavaParserConstants.BIT_OR), space())))); concreteSyntaxModelByClass.put(UnknownType.class, none()); - concreteSyntaxModelByClass.put(VoidType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.VOID))); - concreteSyntaxModelByClass.put(VarType.class, sequence(comment(), annotations(), string(GeneratedJavaParserConstants.IDENTIFIER, "var"))); - - concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), - conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), - conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); - - /// - /// Top Level - /// - - concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence( - annotations(), - token(GeneratedJavaParserConstants.LBRACKET), - child(ObservableProperty.DIMENSION), - token(GeneratedJavaParserConstants.RBRACKET) - )); - - concreteSyntaxModelByClass.put(CompilationUnit.class, sequence( - comment(), - child(ObservableProperty.PACKAGE_DECLARATION), - list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), - list(TYPES, newline(), newline(), none(), newline()), - child(ObservableProperty.MODULE), - orphanCommentsEnding())); - - concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence( - comment(), - token(GeneratedJavaParserConstants.IMPORT), - space(), - conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), - child(ObservableProperty.NAME), - conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), - semicolon(), - orphanCommentsEnding() - )); - - concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence( - comment(), - memberAnnotations(), - token(GeneratedJavaParserConstants.PACKAGE), - space(), - child(ObservableProperty.NAME), - semicolon(), - newline(), - newline(), - orphanCommentsEnding())); - - /// - /// Module info - /// - - concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence( - memberAnnotations(), - conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), - token(GeneratedJavaParserConstants.MODULE), - space(), - child(ObservableProperty.NAME), - space(), - token(GeneratedJavaParserConstants.LBRACE), - newline(), - indent(), - list(ObservableProperty.DIRECTIVES), - unindent(), - token(GeneratedJavaParserConstants.RBRACE), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence( - token(GeneratedJavaParserConstants.EXPORTS), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.MODULE_NAMES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.TO), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence( - token(GeneratedJavaParserConstants.OPENS), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.MODULE_NAMES, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.TO), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence( - token(GeneratedJavaParserConstants.PROVIDES), - space(), - child(ObservableProperty.NAME), - list(ObservableProperty.WITH, - sequence(comma(), space()), - sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), - none()), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence( - token(GeneratedJavaParserConstants.REQUIRES), - space(), - modifiers(), - child(ObservableProperty.NAME), - semicolon(), - newline() - )); - - concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence( - token(GeneratedJavaParserConstants.USES), - space(), - child(ObservableProperty.NAME), - semicolon(), - newline() - )); - - List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream() - .filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())) - .map(nm -> nm.getType().getSimpleName()) - .collect(Collectors.toList()); + concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK), conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), child(EXTENDED_TYPE))), conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), child(SUPER_TYPE))))); + // / + // / Top Level + // / + concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence(annotations(), token(GeneratedJavaParserConstants.LBRACKET), child(ObservableProperty.DIMENSION), token(GeneratedJavaParserConstants.RBRACKET))); + concreteSyntaxModelByClass.put(CompilationUnit.class, sequence(comment(), child(ObservableProperty.PACKAGE_DECLARATION), list(ObservableProperty.IMPORTS, newline(), none(), sequence(newline(), newline())), list(TYPES, newline(), newline(), none(), newline()), child(ObservableProperty.MODULE), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence(comment(), token(GeneratedJavaParserConstants.IMPORT), space(), conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())), child(ObservableProperty.NAME), conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))), semicolon(), orphanCommentsEnding())); + concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence(comment(), memberAnnotations(), token(GeneratedJavaParserConstants.PACKAGE), space(), child(ObservableProperty.NAME), semicolon(), newline(), newline(), orphanCommentsEnding())); + // / + // / Module info + // / + concreteSyntaxModelByClass.put(ModuleDeclaration.class, sequence(memberAnnotations(), conditional(ObservableProperty.OPEN, FLAG, sequence(token(GeneratedJavaParserConstants.OPEN), space())), token(GeneratedJavaParserConstants.MODULE), space(), child(ObservableProperty.NAME), space(), token(GeneratedJavaParserConstants.LBRACE), newline(), indent(), list(ObservableProperty.DIRECTIVES), unindent(), token(GeneratedJavaParserConstants.RBRACE), newline())); + concreteSyntaxModelByClass.put(ModuleExportsDirective.class, sequence(token(GeneratedJavaParserConstants.EXPORTS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleOpensDirective.class, sequence(token(GeneratedJavaParserConstants.OPENS), space(), child(ObservableProperty.NAME), list(ObservableProperty.MODULE_NAMES, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.TO), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleProvidesDirective.class, sequence(token(GeneratedJavaParserConstants.PROVIDES), space(), child(ObservableProperty.NAME), list(ObservableProperty.WITH, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.WITH), space()), none()), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleRequiresDirective.class, sequence(token(GeneratedJavaParserConstants.REQUIRES), space(), modifiers(), child(ObservableProperty.NAME), semicolon(), newline())); + concreteSyntaxModelByClass.put(ModuleUsesDirective.class, sequence(token(GeneratedJavaParserConstants.USES), space(), child(ObservableProperty.NAME), semicolon(), newline())); + List unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream().filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType())).map(nm -> nm.getType().getSimpleName()).collect(Collectors.toList()); if (unsupportedNodeClassNames.isEmpty()) { initializationError = Optional.empty(); } else { @@ -1009,7 +205,6 @@ private static CsmElement typeArguments() { } private ConcreteSyntaxModel() { - } public static void genericPrettyPrint(Node node, SourcePrinter printer) { @@ -1031,5 +226,4 @@ public static CsmElement forClass(Class nodeClazz) { } return concreteSyntaxModelByClass.get(nodeClazz); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java index 3d59cf0592..9efc60c2d6 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java @@ -18,65 +18,61 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.function.Function; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import java.util.function.Function; + /** * Pretty printer for AST nodes. */ public class DefaultPrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + // visitor factory Function> visitorFactory; - - // static methods - + + // static methods private static Function> createDefaultVisitor() { return (config) -> new DefaultPrettyPrinterVisitor(config, new SourcePrinter(config)); } - + private static PrinterConfiguration createDefaultConfiguration() { return new DefaultPrinterConfiguration(); } - - // Constructors + // Constructors /** * Build a new DefaultPrettyPrinter with a default configuration and a default factory */ public DefaultPrettyPrinter() { - this(createDefaultConfiguration() ); + this(createDefaultConfiguration()); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a default factory * @param configuration */ public DefaultPrettyPrinter(PrinterConfiguration configuration) { - this(createDefaultVisitor(), configuration ); + this(createDefaultVisitor(), configuration); } - + /** * Build a new DefaultPrettyPrinter with a configuration and a factory to create a visitor to browse the nodes of the AST - * @param visitorFactory + * @param visitorFactory * @param configuration Configuration to apply */ public DefaultPrettyPrinter(Function> visitorFactory, PrinterConfiguration configuration) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + // Methods - /* * Returns the Printer configuration */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java index 671d9f8804..078077d9ed 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java @@ -17,138 +17,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.isNullOrEmpty; -import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; -import static com.github.javaparser.utils.Utils.trimTrailingSpaces; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; - -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.CompactConstructorDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.ReceiverParameter; -import com.github.javaparser.ast.body.RecordDeclaration; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; +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.AnnotationExpr; -import com.github.javaparser.ast.expr.ArrayAccessExpr; -import com.github.javaparser.ast.expr.ArrayCreationExpr; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.SuperExpr; -import com.github.javaparser.ast.expr.SwitchExpr; -import com.github.javaparser.ast.expr.TextBlockLiteralExpr; -import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.ast.expr.TypeExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.modules.ModuleDeclaration; -import com.github.javaparser.ast.modules.ModuleExportsDirective; -import com.github.javaparser.ast.modules.ModuleOpensDirective; -import com.github.javaparser.ast.modules.ModuleProvidesDirective; -import com.github.javaparser.ast.modules.ModuleRequiresDirective; -import com.github.javaparser.ast.modules.ModuleUsesDirective; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithVariables; -import com.github.javaparser.ast.nodeTypes.SwitchNode; -import com.github.javaparser.ast.stmt.AssertStmt; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.BreakStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ContinueStmt; -import com.github.javaparser.ast.stmt.DoStmt; -import com.github.javaparser.ast.stmt.EmptyStmt; -import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForEachStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.LabeledStmt; -import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; -import com.github.javaparser.ast.stmt.LocalRecordDeclarationStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntry; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.stmt.SynchronizedStmt; -import com.github.javaparser.ast.stmt.ThrowStmt; -import com.github.javaparser.ast.stmt.TryStmt; -import com.github.javaparser.ast.stmt.UnparsableStmt; -import com.github.javaparser.ast.stmt.WhileStmt; -import com.github.javaparser.ast.stmt.YieldStmt; -import com.github.javaparser.ast.type.ArrayType; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.IntersectionType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.ReferenceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.type.UnionType; -import com.github.javaparser.ast.type.UnknownType; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.nodeTypes.*; +import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.type.*; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.ConfigurationOption; @@ -156,12 +37,22 @@ import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.*; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + /** * Outputs the AST as formatted Java source code. - * */ public class DefaultPrettyPrinterVisitor implements VoidVisitor { + protected final PrinterConfiguration configuration; + protected final SourcePrinter printer; public DefaultPrettyPrinterVisitor(PrinterConfiguration configuration) { @@ -202,8 +93,7 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, - final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { if (annotations.isEmpty()) { return; } @@ -311,16 +201,13 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } - if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } - n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } - for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -328,9 +215,7 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } - n.getModule().ifPresent(m -> m.accept(this, arg)); - printOrphanCommentsEnding(n); } @@ -343,7 +228,6 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); - printOrphanCommentsEnding(n); } @@ -352,7 +236,6 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - printOrphanCommentsEnding(n); } @@ -365,7 +248,6 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); - printOrphanCommentsEnding(n); } @@ -382,17 +264,13 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } - n.getName().accept(this, arg); - printTypeParameters(n.getTypeParameters(), arg); - if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -403,7 +281,6 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -414,15 +291,12 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -433,13 +307,9 @@ public void visit(RecordDeclaration n, Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("record "); - n.getName().accept(this, arg); - printTypeParameters(n.getTypeParameters(), arg); - printer.print("("); if (!isNullOrEmpty(n.getParameters())) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -451,7 +321,6 @@ public void visit(RecordDeclaration n, Void arg) { } } printer.print(")"); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -462,15 +331,12 @@ public void visit(RecordDeclaration n, Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -491,7 +357,6 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } - boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -526,9 +391,7 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); - n.getName().accept(this, arg); - if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -571,7 +434,6 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } - type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -645,7 +507,6 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -656,7 +517,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } - printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -665,7 +525,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } - printer.print(";"); } @@ -674,13 +533,9 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { - final Type type = n.getType(); - ArrayType arrayType = null; - for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -691,7 +546,6 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); - if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -780,12 +634,9 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } - - /** * work in progress for issue-545 */ - @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -962,7 +813,6 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -970,38 +820,24 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (getOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN).isPresent()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() - || p.isThrowStmt() - || p.isAssertStmt() - || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(c::equals) - .orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { c = p.get(); p = c.getParentNode(); } - // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } - // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode() - .filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(node::equals) - .orElse(false)) { + while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -1009,15 +845,13 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } - // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -1025,7 +859,6 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } - // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -1050,7 +883,6 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); - printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -1070,18 +902,13 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } - printer.print("new "); - printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } - n.getType().accept(this, arg); - printArguments(n.getArguments(), arg); - if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -1098,9 +925,7 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } - n.getExpression().accept(this, arg); - if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -1112,13 +937,11 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -1136,7 +959,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1157,13 +979,11 @@ public void visit(final CompactConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1181,7 +1001,6 @@ public void visit(final CompactConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -1189,11 +1008,9 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); - printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -1211,7 +1028,6 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1286,12 +1102,10 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); - if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); - for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1400,9 +1214,8 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - - final String separator = (n.getType() == SwitchEntry.Type.STATEMENT_GROUP) ? ":" : " ->"; // old/new switch - + // old/new switch + final String separator = (n.getType() == SwitchEntry.Type.STATEMENT_GROUP) ? ":" : " ->"; if (isNullOrEmpty(n.getLabels())) { printer.print("default" + separator); } else { @@ -1463,10 +1276,8 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("enum "); n.getName().accept(this, arg); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1477,15 +1288,12 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = - // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || - // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > getOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY).get().asInteger() || // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1517,11 +1325,9 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); - if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } - if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1548,7 +1354,8 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (thenBlock) // block statement should start on the same line + if (// block statement should start on the same line + thenBlock) printer.print(") "); else { printer.println(")"); @@ -1564,7 +1371,8 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (elseIf || elseBlock) // put chained if and start of block statement on a same level + if (// put chained if and start of block statement on a same level + elseIf || elseBlock) printer.print("else "); else { printer.println("else"); @@ -1721,7 +1529,6 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1739,7 +1546,6 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1803,9 +1609,7 @@ public void visit(final LineComment n, final Void arg) { if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) { return; } - printer - .print("// ") - .println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1814,13 +1618,16 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString()); - String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + String[] lines = commentContent.split("\\R", -1); printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asValue()); } - printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` + // last line is not followed by a newline, and simply terminated with `*/` + printer.print(lines[lines.length - 1]); printer.println("*/"); } @@ -1828,10 +1635,8 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); - if (printPar) { printer.print("("); } @@ -1845,7 +1650,6 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } - printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1865,7 +1669,6 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } - printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1885,11 +1688,9 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (getOption(ConfigOption.ORDER_IMPORTS).isPresent() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - //noinspection unchecked + // noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort( - comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) - .thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1913,11 +1714,9 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); - printOrphanCommentsEnding(n); } - @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1976,15 +1775,18 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; - if (node instanceof Comment) return; - + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) + return; + if (node instanceof Comment) + return; Node parent = node.getParentNode().orElse(null); - if (parent == null) return; + if (parent == null) + return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { + // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1995,27 +1797,25 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) + positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException( - "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " - + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return; - + if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) + return; List everything = new ArrayList<>(node.getChildNodes()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -2029,15 +1829,16 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - private void indentIf(boolean expr){ - if(expr) + + private void indentIf(boolean expr) { + if (expr) printer.indent(); - } - private void unindentIf(boolean expr){ - if(expr) - printer.unindent(); } + private void unindentIf(boolean expr) { + if (expr) + printer.unindent(); + } private Optional getOption(ConfigOption cOption) { return configuration.get(new DefaultConfigurationOption(cOption)); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java index 25f5119887..002325bfb6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java @@ -18,26 +18,26 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import java.util.List; + +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + /** * Outputs a Graphviz diagram of the AST. */ public class DotPrinter { private int nodeCount; + private final boolean outputNodeType; public DotPrinter(boolean outputNodeType) { @@ -57,37 +57,26 @@ public void output(Node node, String parentNodeName, String name, StringBuilder assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) - .collect(toList()); - + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); String ndName = nextNodeName(); if (outputNodeType) - builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() - + ")\"];"); + builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + " (" + metaModel.getTypeName() + ")\"];"); else builder.append(SYSTEM_EOL + ndName + " [label=\"" + escape(name) + "\"];"); - if (parentNodeName != null) builder.append(SYSTEM_EOL + parentNodeName + " -> " + ndName + ";"); - for (PropertyMetaModel a : attributes) { String attrName = nextNodeName(); - builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" - + escape(a.getValue(node).toString()) + "'\"];"); + builder.append(SYSTEM_EOL + attrName + " [label=\"" + escape(a.getName()) + "='" + escape(a.getValue(node).toString()) + "'\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + attrName + ";"); - } - for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, ndName, sn.getName(), builder); } - for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { @@ -95,8 +84,7 @@ public void output(Node node, String parentNodeName, String name, StringBuilder builder.append(SYSTEM_EOL + ndLstName + " [label=\"" + escape(sl.getName()) + "\"];"); builder.append(SYSTEM_EOL + ndName + " -> " + ndLstName + ";"); String slName = sl.getName().substring(0, sl.getName().length() - 1); - for (Node nd : nl) - output(nd, ndLstName, slName, builder); + for (Node nd : nl) output(nd, ndLstName, slName, builder); } } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index 0dcb238906..1c260aad81 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -18,104 +18,33 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; -import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; -import static com.github.javaparser.utils.Utils.isNullOrEmpty; -import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock; -import static com.github.javaparser.utils.Utils.trimTrailingSpaces; -import static java.util.Comparator.comparingInt; -import static java.util.stream.Collectors.joining; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.*; 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.AnnotationExpr; -import com.github.javaparser.ast.expr.ArrayAccessExpr; -import com.github.javaparser.ast.expr.ArrayCreationExpr; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.CharLiteralExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.DoubleLiteralExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.LongLiteralExpr; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.SuperExpr; -import com.github.javaparser.ast.expr.SwitchExpr; -import com.github.javaparser.ast.expr.TextBlockLiteralExpr; -import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.ast.expr.TypeExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.modules.ModuleDeclaration; -import com.github.javaparser.ast.modules.ModuleExportsDirective; -import com.github.javaparser.ast.modules.ModuleOpensDirective; -import com.github.javaparser.ast.modules.ModuleProvidesDirective; -import com.github.javaparser.ast.modules.ModuleRequiresDirective; -import com.github.javaparser.ast.modules.ModuleUsesDirective; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithVariables; -import com.github.javaparser.ast.nodeTypes.SwitchNode; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.*; +import com.github.javaparser.ast.nodeTypes.*; import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.ArrayType; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.IntersectionType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.ReferenceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.type.UnionType; -import com.github.javaparser.ast.type.UnknownType; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.type.*; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; +import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; +import static com.github.javaparser.utils.Utils.*; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.joining; + /** * Outputs the AST as formatted Java source code. * This class is no longer acceptable to use because it is not sufficiently configurable and it is too tied to a specific implementation @@ -126,7 +55,9 @@ */ @Deprecated public class PrettyPrintVisitor implements VoidVisitor { + protected PrettyPrinterConfiguration configuration; + protected final SourcePrinter printer; public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) { @@ -175,8 +106,7 @@ protected void printMemberAnnotations(final NodeList annotations } } - protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, - final Void arg) { + protected void printAnnotations(final NodeList annotations, boolean prefixWithASpace, final Void arg) { if (annotations.isEmpty()) { return; } @@ -284,16 +214,13 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println("???"); return; } - if (n.getPackageDeclaration().isPresent()) { n.getPackageDeclaration().get().accept(this, arg); } - n.getImports().accept(this, arg); if (!n.getImports().isEmpty()) { printer.println(); } - for (final Iterator> i = n.getTypes().iterator(); i.hasNext(); ) { i.next().accept(this, arg); printer.println(); @@ -301,9 +228,7 @@ public void visit(final CompilationUnit n, final Void arg) { printer.println(); } } - n.getModule().ifPresent(m -> m.accept(this, arg)); - printOrphanCommentsEnding(n); } @@ -316,7 +241,6 @@ public void visit(final PackageDeclaration n, final Void arg) { n.getName().accept(this, arg); printer.println(";"); printer.println(); - printOrphanCommentsEnding(n); } @@ -325,7 +249,6 @@ public void visit(final NameExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - printOrphanCommentsEnding(n); } @@ -338,7 +261,6 @@ public void visit(final Name n, final Void arg) { printer.print("."); } printer.print(n.getIdentifier()); - printOrphanCommentsEnding(n); } @@ -353,17 +275,13 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - if (n.isInterface()) { printer.print("interface "); } else { printer.print("class "); } - n.getName().accept(this, arg); - printTypeParameters(n.getTypeParameters(), arg); - if (!n.getExtendedTypes().isEmpty()) { printer.print(" extends "); for (final Iterator i = n.getExtendedTypes().iterator(); i.hasNext(); ) { @@ -374,7 +292,6 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -385,15 +302,12 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -404,11 +318,8 @@ public void visit(RecordDeclaration n, Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("record "); - n.getName().accept(this, arg); - printer.print("("); if (!isNullOrEmpty(n.getParameters())) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -420,9 +331,7 @@ public void visit(RecordDeclaration n, Void arg) { } } printer.print(")"); - printTypeParameters(n.getTypeParameters(), arg); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -433,15 +342,12 @@ public void visit(RecordDeclaration n, Void arg) { } } } - printer.println(" {"); printer.indent(); if (!isNullOrEmpty(n.getMembers())) { printMembers(n.getMembers(), arg); } - printOrphanCommentsEnding(n); - printer.unindent(); printer.print("}"); } @@ -462,7 +368,6 @@ public void visit(final JavadocComment n, final Void arg) { line = trimTrailingSpaces(line); strippedLines.add(line); } - boolean skippingLeadingEmptyLines = true; boolean prependEmptyLine = false; boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" ")); @@ -497,9 +402,7 @@ public void visit(final ClassOrInterfaceType n, final Void arg) { printer.print("."); } printAnnotations(n.getAnnotations(), false, arg); - n.getName().accept(this, arg); - if (n.isUsingDiamondOperator()) { printer.print("<>"); } else { @@ -542,7 +445,6 @@ public void visit(final ArrayType n, final Void arg) { arrayTypeBuffer.add(arrayType); type = arrayType.getComponentType(); } - type.accept(this, arg); for (ArrayType arrayType : arrayTypeBuffer) { printAnnotations(arrayType.getAnnotations(), true, arg); @@ -616,7 +518,6 @@ public void visit(final UnknownType n, final Void arg) { @Override public void visit(final FieldDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -627,7 +528,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print("???"); } } - printer.print(" "); for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator var = i.next(); @@ -636,7 +536,6 @@ public void visit(final FieldDeclaration n, final Void arg) { printer.print(", "); } } - printer.print(";"); } @@ -645,13 +544,9 @@ public void visit(final VariableDeclarator n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); n.getName().accept(this, arg); - n.findAncestor(NodeWithVariables.class).ifPresent(ancestor -> ((NodeWithVariables) ancestor).getMaximumCommonType().ifPresent(commonType -> { - final Type type = n.getType(); - ArrayType arrayType = null; - for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) { if (arrayType == null) { arrayType = (ArrayType) type; @@ -662,7 +557,6 @@ public void visit(final VariableDeclarator n, final Void arg) { printer.print("[]"); } })); - if (n.getInitializer().isPresent()) { printer.print(" = "); n.getInitializer().get().accept(this, arg); @@ -751,12 +645,9 @@ public void visit(final AssignExpr n, final Void arg) { n.getValue().accept(this, arg); } - - /** * work in progress for issue-545 */ - @Override public void visit(final BinaryExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); @@ -933,7 +824,6 @@ public void visit(final SuperExpr n, final Void arg) { public void visit(final MethodCallExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - // determine whether we do reindenting for aligmnent at all // - is it enabled? // - are we in a statement where we want the alignment? @@ -941,38 +831,24 @@ public void visit(final MethodCallExpr n, final Void arg) { AtomicBoolean columnAlignFirstMethodChain = new AtomicBoolean(); if (configuration.isColumnAlignFirstMethodChain()) { // pick the kind of expressions where vertically aligning method calls is okay. - if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() - || p.isThrowStmt() - || p.isAssertStmt() - || p.isExpressionStmt()).orElse(false)) { + if (n.findAncestor(Statement.class).map(p -> p.isReturnStmt() || p.isThrowStmt() || p.isAssertStmt() || p.isExpressionStmt()).orElse(false)) { // search for first parent that does not have its child as scope Node c = n; Optional p = c.getParentNode(); - while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(c::equals) - .orElse(false)) { + while (p.isPresent() && p.filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(c::equals).orElse(false)) { c = p.get(); p = c.getParentNode(); } - // check if the parent is a method call and thus we are in an argument list columnAlignFirstMethodChain.set(!p.filter(MethodCallExpr.class::isInstance).isPresent()); } } - // we are at the last method call of a call chain // this means we do not start reindenting for alignment or we undo it AtomicBoolean lastMethodInCallChain = new AtomicBoolean(true); if (columnAlignFirstMethodChain.get()) { Node node = n; - while (node.getParentNode() - .filter(NodeWithTraversableScope.class::isInstance) - .map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope) - .map(node::equals) - .orElse(false)) { + while (node.getParentNode().filter(NodeWithTraversableScope.class::isInstance).map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope).map(node::equals).orElse(false)) { node = node.getParentNode().orElseThrow(AssertionError::new); if (node instanceof MethodCallExpr) { lastMethodInCallChain.set(false); @@ -980,15 +856,13 @@ public void visit(final MethodCallExpr n, final Void arg) { } } } - // search whether there is a method call with scope in the scope already // this means that we probably started reindenting for alignment there AtomicBoolean methodCallWithScopeInScope = new AtomicBoolean(); if (columnAlignFirstMethodChain.get()) { Optional s = n.getScope(); while (s.filter(NodeWithTraversableScope.class::isInstance).isPresent()) { - Optional parentScope = s.map(NodeWithTraversableScope.class::cast) - .flatMap(NodeWithTraversableScope::traverseScope); + Optional parentScope = s.map(NodeWithTraversableScope.class::cast).flatMap(NodeWithTraversableScope::traverseScope); if (s.filter(MethodCallExpr.class::isInstance).isPresent() && parentScope.isPresent()) { methodCallWithScopeInScope.set(true); break; @@ -996,7 +870,6 @@ public void visit(final MethodCallExpr n, final Void arg) { s = parentScope; } } - // we have a scope // this means we are not the first method in the chain n.getScope().ifPresent(scope -> { @@ -1021,7 +894,6 @@ public void visit(final MethodCallExpr n, final Void arg) { } printer.print("."); }); - printTypeArgs(n, arg); n.getName().accept(this, arg); printer.duplicateIndent(); @@ -1041,18 +913,13 @@ public void visit(final ObjectCreationExpr n, final Void arg) { n.getScope().get().accept(this, arg); printer.print("."); } - printer.print("new "); - printTypeArgs(n, arg); if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) { printer.print(" "); } - n.getType().accept(this, arg); - printArguments(n.getArguments(), arg); - if (n.getAnonymousClassBody().isPresent()) { printer.println(" {"); printer.indent(); @@ -1069,9 +936,7 @@ public void visit(final UnaryExpr n, final Void arg) { if (n.getOperator().isPrefix()) { printer.print(n.getOperator().asString()); } - n.getExpression().accept(this, arg); - if (n.getOperator().isPostfix()) { printer.print(n.getOperator().asString()); } @@ -1083,13 +948,11 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -1101,7 +964,6 @@ public void visit(final ConstructorDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1116,20 +978,17 @@ public void visit(final ConstructorDeclaration n, final Void arg) { n.getBody().accept(this, arg); } - @Override public void visit(final CompactConstructorDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1147,7 +1006,6 @@ public void visit(final CompactConstructorDeclaration n, final Void arg) { @Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); - printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); @@ -1155,11 +1013,9 @@ public void visit(final MethodDeclaration n, final Void arg) { if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); - printer.print("("); n.getReceiverParameter().ifPresent(rp -> { rp.accept(this, arg); @@ -1177,7 +1033,6 @@ public void visit(final MethodDeclaration n, final Void arg) { } } printer.print(")"); - if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator i = n.getThrownExceptions().iterator(); i.hasNext(); ) { @@ -1252,12 +1107,10 @@ public void visit(final VariableDeclarationExpr n, final Void arg) { printAnnotations(n.getAnnotations(), false, arg); } printModifiers(n.getModifiers()); - if (!n.getVariables().isEmpty()) { n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg)); } printer.print(" "); - for (final Iterator i = n.getVariables().iterator(); i.hasNext(); ) { final VariableDeclarator v = i.next(); v.accept(this, arg); @@ -1366,8 +1219,8 @@ private void printSwitchNode(SwitchNode n, Void arg) { public void visit(final SwitchEntry n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - - final String separator = (n.getType() == SwitchEntry.Type.STATEMENT_GROUP) ? ":" : " ->"; // old/new switch + // old/new switch + final String separator = (n.getType() == SwitchEntry.Type.STATEMENT_GROUP) ? ":" : " ->"; if (isNullOrEmpty(n.getLabels())) { printer.print("default" + separator); } else { @@ -1428,10 +1281,8 @@ public void visit(final EnumDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("enum "); n.getName().accept(this, arg); - if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); for (final Iterator i = n.getImplementedTypes().iterator(); i.hasNext(); ) { @@ -1442,15 +1293,12 @@ public void visit(final EnumDeclaration n, final Void arg) { } } } - printer.println(" {"); printer.indent(); if (n.getEntries().isNonEmpty()) { - final boolean alignVertically = - // Either we hit the constant amount limit in the configurations, or... - n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || - // any of the constants has a comment. - n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); + final boolean alignVertically = // Either we hit the constant amount limit in the configurations, or... + n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() || // any of the constants has a comment. + n.getEntries().stream().anyMatch(e -> e.getComment().isPresent()); printer.println(); for (final Iterator i = n.getEntries().iterator(); i.hasNext(); ) { final EnumConstantDeclaration e = i.next(); @@ -1482,11 +1330,9 @@ public void visit(final EnumConstantDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); n.getName().accept(this, arg); - if (!n.getArguments().isEmpty()) { printArguments(n.getArguments(), arg); } - if (!n.getClassBody().isEmpty()) { printer.println(" {"); printer.indent(); @@ -1513,7 +1359,8 @@ public void visit(final IfStmt n, final Void arg) { printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; - if (thenBlock) // block statement should start on the same line + if (// block statement should start on the same line + thenBlock) printer.print(") "); else { printer.println(")"); @@ -1529,7 +1376,8 @@ public void visit(final IfStmt n, final Void arg) { printer.println(); final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt; final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt; - if (elseIf || elseBlock) // put chained if and start of block statement on a same level + if (// put chained if and start of block statement on a same level + elseIf || elseBlock) printer.print("else "); else { printer.println("else"); @@ -1686,7 +1534,6 @@ public void visit(final AnnotationDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - printer.print("@interface "); n.getName().accept(this, arg); printer.println(" {"); @@ -1704,7 +1551,6 @@ public void visit(final AnnotationMemberDeclaration n, final Void arg) { printComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); - n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); @@ -1768,9 +1614,7 @@ public void visit(final LineComment n, final Void arg) { if (configuration.isIgnoreComments()) { return; } - printer - .print("// ") - .println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); } @Override @@ -1779,13 +1623,16 @@ public void visit(final BlockComment n, final Void arg) { return; } final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter()); - String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present + String[] lines = commentContent.split("\\R", -1); printer.print("/*"); for (int i = 0; i < (lines.length - 1); i++) { printer.print(lines[i]); - printer.print(configuration.getEndOfLineCharacter()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call. + printer.print(configuration.getEndOfLineCharacter()); } - printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/` + // last line is not followed by a newline, and simply terminated with `*/` + printer.print(lines[lines.length - 1]); printer.println("*/"); } @@ -1793,10 +1640,8 @@ public void visit(final BlockComment n, final Void arg) { public void visit(LambdaExpr n, Void arg) { printOrphanCommentsBeforeThisChildNode(n); printComment(n.getComment(), arg); - final NodeList parameters = n.getParameters(); final boolean printPar = n.isEnclosingParameters(); - if (printPar) { printer.print("("); } @@ -1810,7 +1655,6 @@ public void visit(LambdaExpr n, Void arg) { if (printPar) { printer.print(")"); } - printer.print(" -> "); final Statement body = n.getBody(); if (body instanceof ExpressionStmt) { @@ -1830,7 +1674,6 @@ public void visit(MethodReferenceExpr n, Void arg) { if (scope != null) { n.getScope().accept(this, arg); } - printer.print("::"); printTypeArgs(n, arg); if (identifier != null) { @@ -1850,11 +1693,9 @@ public void visit(TypeExpr n, Void arg) { @Override public void visit(NodeList n, Void arg) { if (configuration.isOrderImports() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) { - //noinspection unchecked + // noinspection unchecked NodeList modifiableList = new NodeList<>(n); - modifiableList.sort( - comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1) - .thenComparing(NodeWithName::getNameAsString)); + modifiableList.sort(comparingInt((ImportDeclaration i) -> i.isStatic() ? 0 : 1).thenComparing(NodeWithName::getNameAsString)); for (Object node : modifiableList) { ((Node) node).accept(this, arg); } @@ -1878,11 +1719,9 @@ public void visit(final ImportDeclaration n, final Void arg) { printer.print(".*"); } printer.println(";"); - printOrphanCommentsEnding(n); } - @Override public void visit(ModuleDeclaration n, Void arg) { printMemberAnnotations(n.getAnnotations(), arg); @@ -1941,15 +1780,18 @@ public void visit(UnparsableStmt n, Void arg) { } private void printOrphanCommentsBeforeThisChildNode(final Node node) { - if (configuration.isIgnoreComments()) return; - if (node instanceof Comment) return; - + if (configuration.isIgnoreComments()) + return; + if (node instanceof Comment) + return; Node parent = node.getParentNode().orElse(null); - if (parent == null) return; + if (parent == null) + return; List everything = new ArrayList<>(parent.getChildNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; - for (int i = 0; i < everything.size(); ++i) { // indexOf is by equality, so this is used to index by identity + for (int i = 0; i < everything.size(); ++i) { + // indexOf is by equality, so this is used to index by identity if (everything.get(i) == node) { positionOfTheChild = i; break; @@ -1960,28 +1802,26 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) { } int positionOfPreviousChild = -1; for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) { - if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; + if (!(everything.get(i) instanceof Comment)) + positionOfPreviousChild = i; } for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) { Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) - throw new RuntimeException( - "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " - + positionOfPreviousChild + ", position of child " + positionOfTheChild); + throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild); nodeToPrint.accept(this, null); } } private void printOrphanCommentsEnding(final Node node) { - if (configuration.isIgnoreComments()) return; - + if (configuration.isIgnoreComments()) + return; // extract all nodes for which the position/range is indicated to avoid to skip orphan comments - List everything = node.getChildNodes().stream().filter(n->n.hasRange()).collect(Collectors.toList()); + List everything = node.getChildNodes().stream().filter(n -> n.hasRange()).collect(Collectors.toList()); sortByBeginPosition(everything); if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -1995,12 +1835,14 @@ private void printOrphanCommentsEnding(final Node node) { everything.get(everything.size() - commentsAtEnd + i).accept(this, null); } } - private void indentIf(boolean expr){ - if(expr) + + private void indentIf(boolean expr) { + if (expr) printer.indent(); - } - private void unindentIf(boolean expr){ - if(expr) + } + + private void unindentIf(boolean expr) { + if (expr) printer.unindent(); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java index e3f3787693..f596d4a6dd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java @@ -18,15 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.function.Function; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import com.github.javaparser.printer.configuration.PrinterConfiguration; + +import java.util.function.Function; /** * Pretty printer for AST nodes. @@ -36,24 +35,24 @@ */ @Deprecated public class PrettyPrinter implements Printer { - + private PrinterConfiguration configuration; - + private Function> visitorFactory; public PrettyPrinter() { this(new PrettyPrinterConfiguration()); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration) { this(configuration, PrettyPrintVisitor::new); } - + public PrettyPrinter(PrettyPrinterConfiguration configuration, Function> visitorFactory) { this.configuration = configuration; this.visitorFactory = visitorFactory; } - + /* * Returns the PrettyPrinter configuration */ @@ -73,9 +72,8 @@ public Printer setConfiguration(PrinterConfiguration configuration) { @Override public String print(Node node) { - final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration)configuration); + final VoidVisitor visitor = visitorFactory.apply((PrettyPrinterConfiguration) configuration); node.accept(visitor, null); return visitor.toString(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java index 09a51e86e9..0e3d651145 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java @@ -5,15 +5,13 @@ /** * Printer interface defines the API for a printer. - * A printer outputs the AST as formatted Java source code. - * + * A printer outputs the AST as formatted Java source code. */ public interface Printer { String print(Node node); Printer setConfiguration(PrinterConfiguration configuration); - - PrinterConfiguration getConfiguration(); -} \ No newline at end of file + PrinterConfiguration getConfiguration(); +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java index af52236387..4c2fd77924 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java @@ -18,49 +18,51 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import java.util.Deque; -import java.util.LinkedList; - import com.github.javaparser.Position; -import com.github.javaparser.printer.configuration.DefaultConfigurationOption; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; +import com.github.javaparser.printer.configuration.*; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; -import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.utils.Utils; +import java.util.Deque; +import java.util.LinkedList; + /** * A support class for code that outputs formatted source code. */ public class SourcePrinter { + private String endOfLineCharacter; + private Indentation indentation; private final Deque indents = new LinkedList<>(); + private final Deque reindentedIndents = new LinkedList<>(); + private String lastPrintedIndent = ""; + private final StringBuilder buf = new StringBuilder(); - private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); // Start before the first column + + // Start before the first column + private Position cursor = new Position(Position.FIRST_LINE, Position.FIRST_COLUMN - 1); + private boolean indented = false; SourcePrinter() { this(new DefaultPrinterConfiguration()); } - + SourcePrinter(final PrettyPrinterConfiguration configuration) { this(configuration.getIndentation(), configuration.getEndOfLineCharacter()); } SourcePrinter(final PrinterConfiguration configuration) { - this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), - configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); + this(configuration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(), configuration.get(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER)).get().asString()); } - + SourcePrinter(Indentation indentation, String eol) { this.indentation = indentation; this.endOfLineCharacter = eol; @@ -73,16 +75,14 @@ public class SourcePrinter { */ public SourcePrinter indent() { String currentIndent = indents.peek(); - switch (indentation.getType()) { + switch(indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: indents.push(currentIndent + indentation.getIndent()); break; - case TABS: indents.push(indentation.getIndent() + currentIndent); break; - default: throw new AssertionError("Unhandled indent type"); } @@ -99,21 +99,19 @@ public SourcePrinter indentWithAlignTo(int column) { } private String calculateIndentWithAlignTo(int column) { - if (column < lastPrintedIndent.length()){ + if (column < lastPrintedIndent.length()) { throw new IllegalStateException("Attempt to indent less than the previous indent."); } - StringBuilder newIndent = new StringBuilder(lastPrintedIndent); - switch (indentation.getType()) { + switch(indentation.getType()) { case SPACES: case TABS_WITH_SPACE_ALIGN: while (newIndent.length() < column) { newIndent.append(IndentType.SPACES.getCar()); } break; - case TABS: - IndentType currentIndentType = indentation.getType(); + IndentType currentIndentType = indentation.getType(); int logicalIndentLength = newIndent.length(); while ((logicalIndentLength + currentIndentType.getWidth()) <= column) { newIndent.insert(0, currentIndentType.getCar()); @@ -124,21 +122,18 @@ private String calculateIndentWithAlignTo(int column) { logicalIndentLength++; } StringBuilder fullTab = new StringBuilder(); - for(int i=0; i= currentIndentType.getWidth()) - && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { + if ((newIndent.length() >= currentIndentType.getWidth()) && newIndent.substring(newIndent.length() - currentIndentType.getWidth()).equals(fullTabString)) { int i = newIndent.indexOf(fullTabString); newIndent.replace(i, i + currentIndentType.getWidth(), currentIndentType.getCar().toString()); } break; - default: throw new AssertionError("Unhandled indent type"); } - return newIndent.toString(); } @@ -208,7 +203,8 @@ public SourcePrinter println(final String arg) { */ public SourcePrinter println() { buf.append(endOfLineCharacter); - cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); // Start before the first column + // Start before the first column + cursor = new Position(cursor.line + 1, Position.FIRST_COLUMN - 1); indented = false; return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java index b76fa64e97..16dfc27f59 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Stringable.java @@ -24,5 +24,6 @@ * Something that has a printable form. I.e., it can be converted to a user-facing String. */ public interface Stringable { + String asString(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java index 6c09e35bff..3c6406a89e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; import com.github.javaparser.ast.Node; @@ -35,6 +34,7 @@ * Outputs an XML file containing the AST meant for inspecting it. */ public class XmlPrinter { + private final boolean outputNodeType; public XmlPrinter(boolean outputNodeType) { @@ -54,24 +54,20 @@ public void output(Node node, String name, int level, StringBuilder builder) { List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); - builder.append("<").append(name); if (outputNodeType) { builder.append(attribute("type", metaModel.getTypeName())); } - for (PropertyMetaModel attributeMetaModel : attributes) { builder.append(attribute(attributeMetaModel.getName(), attributeMetaModel.getValue(node).toString())); } builder.append(">"); - for (PropertyMetaModel subNodeMetaModel : subNodes) { Node value = (Node) subNodeMetaModel.getValue(node); if (value != null) { output(value, subNodeMetaModel.getName(), level + 1, builder); } } - for (PropertyMetaModel subListMetaModel : subLists) { NodeList subList = (NodeList) subListMetaModel.getValue(node); if (subList != null && !subList.isEmpty()) { @@ -99,4 +95,3 @@ public static void print(Node node) { System.out.println(new XmlPrinter(true).output(node)); } } - diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java index 97f8a3b25f..16ce5e53f5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java @@ -18,25 +18,25 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.toList; - -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.metamodel.NodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import java.util.List; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.toList; + /** * Outputs a YAML file containing the AST meant for inspecting it. */ public class YamlPrinter { private static final int NUM_SPACES_FOR_INDENT = 4; + private final boolean outputNodeType; public YamlPrinter(boolean outputNodeType) { @@ -55,58 +55,41 @@ public void output(Node node, String name, int level, StringBuilder builder) { assertNotNull(node); NodeMetaModel metaModel = node.getMetaModel(); List allPropertyMetaModels = metaModel.getAllPropertyMetaModels(); - List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode) - .filter(PropertyMetaModel::isSingular).collect(toList()); - List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList) - .collect(toList()); - + List attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList()); + List subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList()); + List subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList()); if (outputNodeType) builder.append(System.lineSeparator() + indent(level) + name + "(Type=" + metaModel.getTypeName() + "): "); else builder.append(System.lineSeparator() + indent(level) + name + ": "); - level++; for (PropertyMetaModel a : attributes) { builder.append(System.lineSeparator() + indent(level) + a.getName() + ": " + escapeValue(a.getValue(node).toString())); } - for (PropertyMetaModel sn : subNodes) { Node nd = (Node) sn.getValue(node); if (nd != null) output(nd, sn.getName(), level, builder); } - for (PropertyMetaModel sl : subLists) { NodeList nl = (NodeList) sl.getValue(node); if (nl != null && nl.isNonEmpty()) { builder.append(System.lineSeparator() + indent(level) + sl.getName() + ": "); String slName = sl.getName(); slName = slName.endsWith("s") ? slName.substring(0, sl.getName().length() - 1) : slName; - for (Node nd : nl) - output(nd, "- " + slName, level + 1, builder); + for (Node nd : nl) output(nd, "- " + slName, level + 1, builder); } } } private String indent(int level) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < level; i++) - for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) - sb.append(" "); + for (int i = 0; i < level; i++) for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++) sb.append(" "); return sb.toString(); } private String escapeValue(String value) { - return "\"" + value - .replace("\\", "\\\\") - .replaceAll("\"", "\\\\\"") - .replace("\n", "\\n") - .replace("\r", "\\r") - .replace("\f", "\\f") - .replace("\b", "\\b") - .replace("\t", "\\t") + "\""; + return "\"" + value.replace("\\", "\\\\").replaceAll("\"", "\\\\\"").replace("\n", "\\n").replace("\r", "\\r").replace("\f", "\\f").replace("\b", "\\b").replace("\t", "\\t") + "\""; } public static void print(Node node) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java index ba1e4306d9..0cd5996db6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java @@ -18,18 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; -import static com.github.javaparser.utils.CodeGenerationUtils.f; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.printer.SourcePrinter; +import static com.github.javaparser.utils.CodeGenerationUtils.f; + public class CsmAttribute implements CsmElement { + public ObservableProperty getProperty() { return property; } @@ -53,28 +53,30 @@ public void prettyPrint(Node node, SourcePrinter printer) { * @param tokenText Operator's token text */ public int getTokenType(Node node, String text, String tokenText) { - switch (property) { + switch(property) { case IDENTIFIER: return GeneratedJavaParserConstants.IDENTIFIER; - case TYPE: { - String expectedImage = "\"" + text.toLowerCase() + "\""; - for (int i=0;i process(c, printer)); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java index 12d618860d..85620cb186 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java @@ -18,21 +18,24 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; -import java.util.Arrays; -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.printer.SourcePrinter; +import java.util.Arrays; +import java.util.List; + public class CsmConditional implements CsmElement { + private final Condition condition; + private final List properties; + private final CsmElement thenElement; + private final CsmElement elseElement; public Condition getCondition() { @@ -45,7 +48,7 @@ public ObservableProperty getProperty() { } return properties.get(0); } - + public List getProperties() { return properties; } @@ -59,35 +62,40 @@ public CsmElement getElseElement() { } public enum Condition { + IS_EMPTY { + @Override boolean evaluate(Node node, ObservableProperty property) { NodeList value = property.getValueAsMultipleReference(node); return value == null || value.isEmpty(); } - }, - IS_NOT_EMPTY { + } + , IS_NOT_EMPTY { + @Override boolean evaluate(Node node, ObservableProperty property) { NodeList value = property.getValueAsMultipleReference(node); return value != null && !value.isEmpty(); } - }, - IS_PRESENT { + } + , IS_PRESENT { + @Override boolean evaluate(Node node, ObservableProperty property) { return !property.isNullOrNotPresent(node); } - }, - FLAG { + } + , FLAG { + @Override boolean evaluate(Node node, ObservableProperty property) { return property.getValueAsBooleanAttribute(node); } - }; - - abstract boolean evaluate(Node node, ObservableProperty property); + } + ; + abstract boolean evaluate(Node node, ObservableProperty property); } public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement, CsmElement elseElement) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java index ac5deab359..baa37d994d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; @@ -30,7 +29,8 @@ import java.util.Arrays; import java.util.List; -import static com.github.javaparser.TokenTypes.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.TokenTypes.spaceTokenKind; public interface CsmElement { @@ -96,7 +96,9 @@ static CsmElement semicolon() { return new CsmToken(GeneratedJavaParserConstants.SEMICOLON); } - static CsmElement comment() { return new CsmComment(); } + static CsmElement comment() { + return new CsmComment(); + } static CsmElement newline() { return newline(LineSeparator.SYSTEM); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java index f60bd39e67..307c574cca 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java index 9d2947380b..9bf77e67a6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java @@ -18,23 +18,27 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; -import java.util.Collection; -import java.util.Iterator; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.printer.ConcreteSyntaxModel; import com.github.javaparser.printer.SourcePrinter; +import java.util.Collection; +import java.util.Iterator; + public class CsmList implements CsmElement { + private final ObservableProperty property; + private final CsmElement separatorPost; + private final CsmElement separatorPre; + private final CsmElement preceeding; + private final CsmElement following; public ObservableProperty getProperty() { @@ -117,7 +121,7 @@ public void prettyPrint(Node node, SourcePrinter printer) { } } } - + @Override public String toString() { return String.format("%s(property:%s)", this.getClass().getSimpleName(), getProperty()); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java index 73e0d0c94f..a7068c7d43 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -32,6 +31,7 @@ * A group of elements that could be in any order. */ public class CsmMix implements CsmElement { + private List elements; public CsmMix(List elements) { @@ -55,11 +55,11 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmMix csmMix = (CsmMix) o; - return elements != null ? elements.equals(csmMix.elements) : csmMix.elements == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java index eba29c5552..6e13755b21 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -28,7 +27,5 @@ public class CsmNone implements CsmElement { @Override public void prettyPrint(Node node, SourcePrinter printer) { - } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java index 12f971f373..cc38642beb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -40,7 +39,6 @@ public void prettyPrint(Node node, SourcePrinter printer) { if (everything.isEmpty()) { return; } - int commentsAtEnd = 0; boolean findingComments = true; while (findingComments && commentsAtEnd < everything.size()) { @@ -51,9 +49,8 @@ public void prettyPrint(Node node, SourcePrinter printer) { } } for (int i = 0; i < commentsAtEnd; i++) { - Comment c = (Comment)everything.get(everything.size() - commentsAtEnd + i); + Comment c = (Comment) everything.get(everything.size() - commentsAtEnd + i); CsmComment.process(c, printer); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java index 473c8c4e0b..836f8f7aa3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java @@ -18,17 +18,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.SourcePrinter; + import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import com.github.javaparser.ast.Node; -import com.github.javaparser.printer.SourcePrinter; - public class CsmSequence implements CsmElement { + private List elements; public CsmSequence(List elements) { @@ -49,7 +49,7 @@ public List getElements() { public void prettyPrint(Node node, SourcePrinter printer) { elements.forEach(e -> e.prettyPrint(node, printer)); } - + @Override public String toString() { return elements.stream().map(e -> e.toString()).collect(Collectors.joining(",", "CsmSequence[", "]")); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java index b1594d6751..81385374fc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmSingleReference implements CsmElement { + private final ObservableProperty property; public ObservableProperty getProperty() { @@ -44,10 +44,9 @@ public void prettyPrint(Node node, SourcePrinter printer) { ConcreteSyntaxModel.genericPrettyPrint(child, printer); } } - + @Override public String toString() { return String.format("%s(property:%s)", this.getClass().getSimpleName(), getProperty()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java index e1287ffd21..54f7632def 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -26,12 +25,13 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmString implements CsmElement { + private final ObservableProperty property; public CsmString(ObservableProperty property) { this.property = property; } - + public ObservableProperty getProperty() { return property; } @@ -47,5 +47,4 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("%s(property:%s)", this.getClass().getSimpleName(), getProperty()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java index a301b335b5..53b7b172d1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; @@ -26,12 +25,13 @@ import com.github.javaparser.printer.SourcePrinter; public class CsmTextBlock implements CsmElement { + private final ObservableProperty property; public CsmTextBlock(ObservableProperty property) { this.property = property; } - + public ObservableProperty getProperty() { return property; } @@ -40,7 +40,8 @@ public ObservableProperty getProperty() { public void prettyPrint(Node node, SourcePrinter printer) { // Note that values within TextBlocks ALWAYS have the \n line ending, per https://openjdk.java.net/jeps/378#1--Line-terminators printer.print("\"\"\"\n"); - printer.print(property.getValueAsStringAttribute(node)); // TODO: Confirm if we need to force this to use {@code \n} separators + // TODO: Confirm if we need to force this to use {@code \n} separators + printer.print(property.getValueAsStringAttribute(node)); printer.print("\"\"\""); } @@ -48,5 +49,4 @@ public void prettyPrint(Node node, SourcePrinter printer) { public String toString() { return String.format("%s(property:%s)", this.getClass().getSimpleName(), getProperty()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java index a640dfea57..dca6ba7357 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java @@ -18,24 +18,27 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; -import static com.github.javaparser.TokenTypes.isEndOfLineToken; -import static com.github.javaparser.TokenTypes.isWhitespaceButNotEndOfLine; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.TokenTypes; import com.github.javaparser.ast.Node; import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.utils.LineSeparator; +import static com.github.javaparser.TokenTypes.isEndOfLineToken; +import static com.github.javaparser.TokenTypes.isWhitespaceButNotEndOfLine; + public class CsmToken implements CsmElement { + private final int tokenType; + private String content; + private TokenContentCalculator tokenContentCalculator; public interface TokenContentCalculator { + String calculate(Node node); } @@ -56,9 +59,8 @@ public CsmToken(int tokenType) { if (content.startsWith("\"")) { content = content.substring(1, content.length() - 1); } - // Replace "raw" values with escaped textual counterparts (e.g. newlines {@code \r\n}) - // and "placeholder" values ({@code }) with their textual counterparts + // and "placeholder" values ({@code }) with their textual counterparts if (isEndOfLineToken(tokenType)) { // Use the unescaped version content = LineSeparator.lookupEscaped(this.content).get().asRawString(); @@ -93,13 +95,15 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmToken csmToken = (CsmToken) o; - - if (tokenType != csmToken.tokenType) return false; - if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) return false; + if (tokenType != csmToken.tokenType) + return false; + if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) + return false; return tokenContentCalculator != null ? tokenContentCalculator.equals(csmToken.tokenContentCalculator) : csmToken.tokenContentCalculator == null; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java index 9b04f498c1..c8ad498ecc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java index 9e9a575c2d..3444a29f74 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.printer.Stringable; @@ -27,7 +26,7 @@ class PrintingHelper { static String printToString(Object value) { if (value instanceof Stringable) { - return ((Stringable)value).asString(); + return ((Stringable) value).asString(); } if (value instanceof Enum) { return ((Enum) value).name().toLowerCase(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java index a60d0804b3..3a0c0b5e08 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java @@ -28,5 +28,4 @@ public interface ConfigurationOption { Boolean asBoolean(); T asValue(); - -} \ No newline at end of file +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java index cba94327f4..e748a377fb 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java @@ -17,7 +17,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; @@ -27,7 +26,9 @@ * An option is a pair of ConfigOption and a currentValue */ public class DefaultConfigurationOption implements ConfigurationOption { + ConfigOption configOption; + Object currentValue; public DefaultConfigurationOption(ConfigOption configOption) { @@ -42,7 +43,8 @@ public DefaultConfigurationOption(ConfigOption configOption, Object value) { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof DefaultConfigurationOption)) return false; + if (o == null || !(o instanceof DefaultConfigurationOption)) + return false; DefaultConfigurationOption other = (DefaultConfigurationOption) o; return configOption.equals(other.configOption); } @@ -61,8 +63,7 @@ public ConfigurationOption value(Object value) { this.currentValue = value; // verify the currentValue's type if (!(configOption.type.isAssignableFrom(value.getClass()))) { - throw new IllegalArgumentException( - String.format("%s is not an instance of %s", value, configOption.type.getName())); + throw new IllegalArgumentException(String.format("%s is not an instance of %s", value, configOption.type.getName())); } return this; } @@ -109,7 +110,6 @@ private T cast() { throw new IllegalArgumentException(String.format("The option %s has no currentValue", configOption.name())); if (configOption.type.isAssignableFrom(currentValue.getClass())) return (T) configOption.type.cast(currentValue); - throw new IllegalArgumentException( - String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); + throw new IllegalArgumentException(String.format("%s cannot be cast to %s", currentValue, configOption.type.getName())); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java index 3dadb3c084..806de04dd5 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java @@ -17,38 +17,38 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; +import com.github.javaparser.printer.Printer; +import com.github.javaparser.printer.configuration.Indentation.IndentType; +import com.github.javaparser.utils.Utils; + import java.util.Arrays; import java.util.HashSet; import java.util.Optional; import java.util.Set; -import com.github.javaparser.printer.Printer; -import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.utils.Utils; - /** * Configuration options for the {@link Printer}. */ public class DefaultPrinterConfiguration implements PrinterConfiguration { - + public enum ConfigOption { + /** * Order imports alphabetically */ - ORDER_IMPORTS(Boolean.class), + ORDER_IMPORTS(Boolean.class), /** * Print comments only. It can be combined with {@code PRINT_JAVADOC} to print regular comments and javadoc. */ - PRINT_COMMENTS(Boolean.class), + PRINT_COMMENTS(Boolean.class), /** * Print javadoc comments only. It can be combined with {@code PRINT_COMMENTS} to print regular javadoc and comments */ - PRINT_JAVADOC(Boolean.class), - SPACE_AROUND_OPERATORS(Boolean.class), - COLUMN_ALIGN_PARAMETERS(Boolean.class), + PRINT_JAVADOC(Boolean.class), + SPACE_AROUND_OPERATORS(Boolean.class), + COLUMN_ALIGN_PARAMETERS(Boolean.class), COLUMN_ALIGN_FIRST_METHOD_CHAIN(Boolean.class), /** * Indent the case when it is true, don't if false @@ -91,16 +91,16 @@ public enum ConfigOption { * Indentation proprerty */ INDENTATION(Indentation.class, new Indentation(IndentType.SPACES, 4)); - + Object defaultValue; - + Class type; - + // DefaultConfigurationOption without currentValue ConfigOption(Class clazz) { this.type = clazz; } - + // DefaultConfigurationOption with initial currentValue ConfigOption(Class clazz, Object value) { this.type = clazz; @@ -109,25 +109,15 @@ public enum ConfigOption { } this.defaultValue = value; } - - } - + // contains all available options // an option contained in the set is considered as activated - private Set defaultOptions = new HashSet<>(Arrays.asList( - new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), - new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), - new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), - new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), - new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), - new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), - new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue) - )); + private Set defaultOptions = new HashSet<>(Arrays.asList(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS, ConfigOption.PRINT_COMMENTS.defaultValue), new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC, ConfigOption.PRINT_JAVADOC.defaultValue), new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS, ConfigOption.SPACE_AROUND_OPERATORS.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH, ConfigOption.INDENT_CASE_IN_SWITCH.defaultValue), new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY, ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY.defaultValue), new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ConfigOption.END_OF_LINE_CHARACTER.defaultValue), new DefaultConfigurationOption(ConfigOption.INDENTATION, ConfigOption.INDENTATION.defaultValue))); public DefaultPrinterConfiguration() { } - + /* * add the specified option if it does not exist or replace the existing option */ @@ -137,7 +127,7 @@ public PrinterConfiguration addOption(ConfigurationOption option) { defaultOptions.add(option); return this; } - + /* * remove the specified option */ @@ -146,7 +136,7 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { defaultOptions.remove(option); return this; } - + /* * True if an option is activated */ @@ -154,13 +144,13 @@ public PrinterConfiguration removeOption(ConfigurationOption option) { public boolean isActivated(ConfigurationOption option) { return defaultOptions.contains(option); } - + /* * returns the specified option */ @Override public Optional get(ConfigurationOption option) { - return defaultOptions.stream().filter(o-> o.equals(option)).findFirst(); + return defaultOptions.stream().filter(o -> o.equals(option)).findFirst(); } /** @@ -170,5 +160,4 @@ public Optional get(ConfigurationOption option) { public Set get() { return defaultOptions; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java index 5ebc772ee7..3523a3bea3 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java @@ -17,27 +17,24 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; /** - * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). - * + * This class defines the characteristics of an indentation: the type (space, tabs..) and the size (How many characters must be used to indent the code). */ public class Indentation { - + public enum IndentType { + /** * Indent with spaces. */ SPACES(' ', 1), - /** * Indent with tabs as far as possible. * For proper aligning, the tab width is necessary and by default 4. */ TABS('\t', 4), - /** * Indent with tabs but align with spaces when wrapping and aligning * method call chains and method call parameters. @@ -60,11 +57,11 @@ public enum IndentType { * */ TABS_WITH_SPACE_ALIGN('\t', 4); - + private Character car; - + private int width; - + private IndentType(Character c, int width) { this.car = c; this.width = width; @@ -77,21 +74,20 @@ public Character getCar() { public int getWidth() { return width; } - } - + // default size - private static final int DEFAULT_SIZE = 4; - + private static final int DEFAULT_SIZE = 4; + // type of the indentation private IndentType type; - + // size of the indentation (define how many spaces or tabs is used to indent) private int size; - + // formatted indentation private String formattedIndentation = ""; - + /* * Creates an Indentation with a type and size */ @@ -100,14 +96,14 @@ public Indentation(IndentType type, int size) { this.size = size; format(); } - + /* * Creates an Indentation with the default size */ public Indentation(IndentType type) { this(type, DEFAULT_SIZE); } - + /* * set the size of the indentation (how many spaces or tabs?) */ @@ -116,11 +112,11 @@ public Indentation setSize(int size) { format(); return this; } - + public int getSize() { return size; } - + /* * set the type of the indentation (spaces, tabs...) */ @@ -129,7 +125,7 @@ public Indentation setType(IndentType type) { format(); return this; } - + public IndentType getType() { return type; } @@ -140,7 +136,7 @@ public IndentType getType() { public String getIndent() { return formattedIndentation; } - + // format the indentation string private void format() { StringBuilder indentString = new StringBuilder(); @@ -150,9 +146,9 @@ private void format() { } formattedIndentation = indentString.toString(); } - + @Override public String toString() { - return type.name() + " size=" + size ; + return type.name() + " size=" + size; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java index c509525026..253ba0b3ab 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrettyPrinterConfiguration.java @@ -18,19 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.configuration; -import static com.github.javaparser.utils.Utils.assertNonNegative; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.assertPositive; +import com.github.javaparser.printer.PrettyPrinter; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; +import com.github.javaparser.printer.configuration.Indentation.IndentType; import java.util.Optional; import java.util.Set; -import com.github.javaparser.printer.PrettyPrinter; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation.IndentType; +import static com.github.javaparser.utils.Utils.*; /** * Configuration options for the {@link PrettyPrinter}. @@ -40,24 +37,23 @@ */ @Deprecated public class PrettyPrinterConfiguration implements PrinterConfiguration { - - + PrinterConfiguration wrappedConfiguration; - + /* * Default constructor */ public PrettyPrinterConfiguration() { this.wrappedConfiguration = new DefaultPrinterConfiguration(); } - + /* * returns the indentation parameters */ public Indentation getIndentation() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENTATION)).get().asValue(); } - + public PrettyPrinterConfiguration setIndentation(Indentation indentation) { wrappedConfiguration.addOption(new DefaultConfigurationOption(ConfigOption.INDENTATION, indentation)); return this; @@ -112,8 +108,6 @@ public PrettyPrinterConfiguration setIndentType(IndentType indentType) { return this; } - - /** * Get the tab width for pretty aligning. * @deprecated (@see Indentation.size) @@ -144,7 +138,7 @@ public boolean isPrintComments() { public boolean isIgnoreComments() { return !wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)).isPresent(); } - + public boolean isSpaceAroundOperators() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)).isPresent(); } @@ -165,15 +159,12 @@ public boolean isIndentCaseInSwitch() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)).isPresent(); } - /** * When true, all comments will be printed, unless printJavadoc is false, then only line and block comments will be * printed. */ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { - wrappedConfiguration = printComments ? - addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); + wrappedConfiguration = printComments ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); return this; } @@ -181,40 +172,30 @@ public PrettyPrinterConfiguration setPrintComments(boolean printComments) { * When true, Javadoc will be printed. */ public PrettyPrinterConfiguration setPrintJavadoc(boolean printJavadoc) { - wrappedConfiguration = printJavadoc ? - addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : - removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); + wrappedConfiguration = printJavadoc ? addOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)) : removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC)); return this; } /** * Set if there should be spaces between operators */ - public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators){ - wrappedConfiguration = spaceAroundOperators ? - addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); + public PrettyPrinterConfiguration setSpaceAroundOperators(boolean spaceAroundOperators) { + wrappedConfiguration = spaceAroundOperators ? addOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)) : removeOption(new DefaultConfigurationOption(ConfigOption.SPACE_AROUND_OPERATORS)); return this; } public PrettyPrinterConfiguration setColumnAlignParameters(boolean columnAlignParameters) { - wrappedConfiguration = columnAlignParameters ? - addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : - removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); + wrappedConfiguration = columnAlignParameters ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_PARAMETERS)); return this; } public PrettyPrinterConfiguration setColumnAlignFirstMethodChain(boolean columnAlignFirstMethodChain) { - wrappedConfiguration = columnAlignFirstMethodChain ? - addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : - removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); + wrappedConfiguration = columnAlignFirstMethodChain ? addOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)) : removeOption(new DefaultConfigurationOption(ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN)); return this; } public PrettyPrinterConfiguration setIndentCaseInSwitch(boolean indentInSwitch) { - wrappedConfiguration = indentInSwitch ? - addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : - removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); + wrappedConfiguration = indentInSwitch ? addOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)) : removeOption(new DefaultConfigurationOption(ConfigOption.INDENT_CASE_IN_SWITCH)); return this; } @@ -234,13 +215,10 @@ public PrettyPrinterConfiguration setEndOfLineCharacter(String endOfLineCharacte * When true, orders imports by alphabetically. */ public PrettyPrinterConfiguration setOrderImports(boolean orderImports) { - wrappedConfiguration = orderImports ? - addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); + wrappedConfiguration = orderImports ? addOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)) : removeOption(new DefaultConfigurationOption(ConfigOption.ORDER_IMPORTS)); return this; } - - public int getMaxEnumConstantsToAlignHorizontally() { return wrappedConfiguration.get(new DefaultConfigurationOption(ConfigOption.MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY)).get().asInteger(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java index dd50a93829..448cd9fff1 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java @@ -13,7 +13,7 @@ public interface PrinterConfiguration { * add or update an option */ PrinterConfiguration addOption(ConfigurationOption option); - + /* * Remove an option */ @@ -33,5 +33,4 @@ public interface PrinterConfiguration { * returns all activated options */ Set get(); - -} \ No newline at end of file +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java index 2d1f5aeb17..8dbc3833c4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Added implements DifferenceElement { + private final CsmElement element; Added(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Added added = (Added) o; - return element.equals(added.element); } @@ -67,17 +67,23 @@ public boolean isAdded() { public boolean isRemoved() { return false; } - + @Override public boolean isKept() { return false; } - public boolean isIndent() { return element instanceof CsmIndent; } + public boolean isIndent() { + return element instanceof CsmIndent; + } - public boolean isUnindent() { return element instanceof CsmUnindent; } - - private boolean isToken() { return element instanceof CsmToken; } + public boolean isUnindent() { + return element instanceof CsmUnindent; + } + + private boolean isToken() { + return element instanceof CsmToken; + } public TextElement toTextElement() { if (element instanceof LexicalDifferenceCalculator.CsmChild) { @@ -88,7 +94,7 @@ public TextElement toTextElement() { throw new UnsupportedOperationException(element.getClass().getSimpleName()); } } - + /* * If the {@code DifferenceElement} wraps an EOL token then this method returns a new wrapped {@code CsmElement} * with the specified line separator. The line separator parameter must be a CsmToken with a valid line separator. @@ -97,12 +103,11 @@ public TextElement toTextElement() { public DifferenceElement replaceEolTokens(CsmElement lineSeparator) { return isNewLineToken() ? new Added(lineSeparator) : this; } - + /* * Return true if the wrapped {@code CsmElement} is a new line token */ private boolean isNewLineToken() { return isToken() && ((CsmToken) element).isNewLine(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java index ef91bac851..148768bb7e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java @@ -18,19 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.Optional; - import com.github.javaparser.Range; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.comments.Comment; +import java.util.Optional; + /** * Represent the position of a child node in the NodeText of its parent. */ class ChildTextElement extends TextElement { + private final Node child; ChildTextElement(Node child) { @@ -61,13 +61,12 @@ NodeText getNodeTextForWrappedNode() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ChildTextElement that = (ChildTextElement) o; - return child.equals(that.child); - } @Override @@ -99,22 +98,22 @@ public boolean isNewline() { public boolean isComment() { return child instanceof Comment; } - + @Override public boolean isSeparator() { return false; } - + @Override public boolean isIdentifier() { return false; } - + @Override public boolean isKeyword() { return false; } - + @Override public boolean isPrimitive() { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 0a0ef8218a..c10c8820cd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -18,15 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.GeneratedJavaParserConstants.LBRACE; -import static com.github.javaparser.GeneratedJavaParserConstants.RBRACE; -import static com.github.javaparser.GeneratedJavaParserConstants.SPACE; - -import java.util.*; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.JavaToken; import com.github.javaparser.JavaToken.Kind; @@ -38,13 +31,13 @@ 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.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; +import java.util.*; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; + /** * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements * to remove or to add and follow by another sequence of elements. @@ -56,26 +49,29 @@ public class Difference { public static final int STANDARD_INDENTATION_SIZE = 4; private final NodeText nodeText; + private final Node node; private final List diffElements; + private final List originalElements; + private int originalIndex = 0; + private int diffIndex = 0; private final List indentation; + private boolean addedIndentation = false; Difference(List diffElements, NodeText nodeText, Node node) { if (nodeText == null) { throw new NullPointerException("nodeText can not be null"); } - this.nodeText = nodeText; this.node = node; this.diffElements = diffElements; this.originalElements = nodeText.getElements(); - this.indentation = LexicalPreservingPrinter.findIndentation(node); } @@ -85,8 +81,11 @@ public class Difference { private List processIndentation(List indentation, List prevElements) { List res = new LinkedList<>(indentation); int index = lastIndexOfEol(prevElements); - if (index < 0) return res; // no EOL found - res.clear(); // initialize previous indentation + // no EOL found + if (index < 0) + return res; + // initialize previous indentation + res.clear(); // search for consecutive space characters for (int i = (index + 1); i < prevElements.size(); i++) { TextElement elem = prevElements.get(i); @@ -98,15 +97,15 @@ private List processIndentation(List indentation, } return res; } - + /* * Returns the position of the last new line character or -1 if there is no eol in the specified list of TextElement */ int lastIndexOfEol(List source) { ListIterator listIterator = source.listIterator(source.size()); - int lastIndex = source.size() -1; + int lastIndex = source.size() - 1; while (listIterator.hasPrevious()) { - TextElement elem = (TextElement)listIterator.previous(); + TextElement elem = (TextElement) listIterator.previous(); if (elem.isNewline()) { return lastIndex; } @@ -140,7 +139,8 @@ private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) { */ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { boolean hasOnlyWsBefore = hasOnlyWsBefore(nodeText, nodeTextIndex); - int res = nodeTextIndex; // the next position in the list (by default the current position) + // the next position in the list (by default the current position) + int res = nodeTextIndex; if (hasOnlyWsBefore) { res = removeExtraCharacters(nodeText, nodeTextIndex); } @@ -151,9 +151,8 @@ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { } /** - * * @param nodeText Contains a list of elements to analyze - * @param nodeTextIndex Starting position in the input list + * @param nodeTextIndex Starting position in the input list * @return The current position in the list of the elements */ private int removeExtraCharacters(NodeText nodeText, int nodeTextIndex) { @@ -195,21 +194,17 @@ private boolean hasOnlyWsBefore(NodeText nodeText, int nodeTextIndex) { void apply() { extractReshuffledDiffElements(diffElements); Map removedGroups = combineRemovedElementsToRemovedGroups(); - do { boolean isLeftOverDiffElement = applyLeftOverDiffElements(); boolean isLeftOverOriginalElement = applyLeftOverOriginalElements(); - - if (!isLeftOverDiffElement && !isLeftOverOriginalElement){ + if (!isLeftOverDiffElement && !isLeftOverOriginalElement) { DifferenceElement diffElement = diffElements.get(diffIndex); - if (diffElement.isAdded()) { applyAddedDiffElement((Added) diffElement); } else { TextElement originalElement = originalElements.get(originalIndex); boolean originalElementIsChild = originalElement instanceof ChildTextElement; boolean originalElementIsToken = originalElement instanceof TokenTextElement; - if (diffElement.isKept()) { applyKeptDiffElement((Kept) diffElement, originalElement, originalElementIsChild, originalElementIsToken); } else if (diffElement.isRemoved()) { @@ -227,14 +222,11 @@ private boolean applyLeftOverOriginalElements() { boolean isLeftOverElement = false; if (diffIndex >= diffElements.size() && originalIndex < originalElements.size()) { TextElement originalElement = originalElements.get(originalIndex); - if (originalElement.isWhiteSpaceOrComment()) { originalIndex++; } else { - throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " - + this + " " + originalElement); + throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: " + this + " " + originalElement); } - isLeftOverElement = true; } return isLeftOverElement; @@ -248,7 +240,6 @@ private boolean applyLeftOverDiffElements() { diffIndex++; } else if (diffElement.isAdded()) { Added addedElement = (Added) diffElement; - nodeText.addElement(originalIndex, addedElement.toTextElement()); originalIndex++; diffIndex++; @@ -256,10 +247,8 @@ private boolean applyLeftOverDiffElements() { // let's forget this element diffIndex++; } - isLeftOverElement = true; } - return isLeftOverElement; } @@ -268,17 +257,13 @@ private void extractReshuffledDiffElements(List diffElements) DifferenceElement diffElement = diffElements.get(index); if (diffElement instanceof Reshuffled) { Reshuffled reshuffled = (Reshuffled) diffElement; - // First, let's see how many tokens we need to attribute to the previous version of the of the CsmMix CsmMix elementsFromPreviousOrder = reshuffled.getPreviousOrder(); CsmMix elementsFromNextOrder = reshuffled.getNextOrder(); - // This contains indexes from elementsFromNextOrder to indexes from elementsFromPreviousOrder Map correspondanceBetweenNextOrderAndPreviousOrder = getCorrespondanceBetweenNextOrderAndPreviousOrder(elementsFromPreviousOrder, elementsFromNextOrder); - // We now find out which Node Text elements corresponds to the elements in the original CSM List nodeTextIndexOfPreviousElements = findIndexOfCorrespondingNodeTextElement(elementsFromPreviousOrder.getElements(), nodeText, originalIndex, node); - Map nodeTextIndexToPreviousCSMIndex = new HashMap<>(); for (int i = 0; i < nodeTextIndexOfPreviousElements.size(); i++) { int value = nodeTextIndexOfPreviousElements.get(i); @@ -287,11 +272,9 @@ private void extractReshuffledDiffElements(List diffElements) } } int lastNodeTextIndex = nodeTextIndexOfPreviousElements.stream().max(Integer::compareTo).orElse(-1); - // Elements to be added at the end List elementsToBeAddedAtTheEnd = new LinkedList<>(); List nextOrderElements = elementsFromNextOrder.getElements(); - Map> elementsToAddBeforeGivenOriginalCSMElement = new HashMap<>(); for (int ni = 0; ni < nextOrderElements.size(); ni++) { // If it has a mapping, then it is kept @@ -314,22 +297,18 @@ private void extractReshuffledDiffElements(List diffElements) } } } - // We go over the original node text elements, in the order they appear in the NodeText. // Considering an original node text element (ONE) // * we verify if it corresponds to a CSM element. If it does not we just move on, otherwise - // we find the correspond OCE (Original CSM Element) + // we find the correspond OCE (Original CSM Element) // * we first add new elements that are marked to be added before OCE // * if OCE is marked to be present also in the "after" CSM we add a kept element, - // otherwise we add a removed element - + // otherwise we add a removed element // Remove the whole Reshuffled element diffElements.remove(index); - int diffElIterator = index; if (lastNodeTextIndex != -1) { for (int ntIndex = originalIndex; ntIndex <= lastNodeTextIndex; ntIndex++) { - if (nodeTextIndexToPreviousCSMIndex.containsKey(ntIndex)) { int indexOfOriginalCSMElement = nodeTextIndexToPreviousCSMIndex.get(ntIndex); if (elementsToAddBeforeGivenOriginalCSMElement.containsKey(indexOfOriginalCSMElement)) { @@ -337,7 +316,6 @@ private void extractReshuffledDiffElements(List diffElements) diffElements.add(diffElIterator++, new Added(elementToAdd)); } } - CsmElement originalCSMElement = elementsFromPreviousOrder.getElements().get(indexOfOriginalCSMElement); boolean toBeKept = correspondanceBetweenNextOrderAndPreviousOrder.containsValue(indexOfOriginalCSMElement); if (toBeKept) { @@ -349,7 +327,6 @@ private void extractReshuffledDiffElements(List diffElements) // else we have a simple node text element, without associated csm element, just keep ignore it } } - // Finally we look for the remaining new elements that were not yet added and // add all of them for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) { @@ -374,25 +351,21 @@ private void extractReshuffledDiffElements(List diffElements) */ private Map combineRemovedElementsToRemovedGroups() { Map> removedElementsMap = groupConsecutiveRemovedElements(); - List removedGroups = new ArrayList<>(); for (Map.Entry> entry : removedElementsMap.entrySet()) { removedGroups.add(RemovedGroup.of(entry.getKey(), entry.getValue())); } - Map map = new HashMap<>(); - for (RemovedGroup removedGroup : removedGroups){ + for (RemovedGroup removedGroup : removedGroups) { for (Removed index : removedGroup) { map.put(index, removedGroup); } } - return map; } private Map> groupConsecutiveRemovedElements() { Map> removedElementsMap = new HashMap<>(); - Integer firstElement = null; for (int i = 0; i < diffElements.size(); i++) { DifferenceElement diffElement = diffElements.get(i); @@ -400,9 +373,7 @@ private Map> groupConsecutiveRemovedElements() { if (firstElement == null) { firstElement = i; } - - removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()) - .add((Removed) diffElement); + removedElementsMap.computeIfAbsent(firstElement, key -> new ArrayList<>()).add((Removed) diffElement); } else { firstElement = null; } @@ -424,15 +395,12 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } else { nodeText.removeElement(originalIndex); - - if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1).isAdded())) - && !removedGroup.isACompleteLine()) { + if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1).isAdded())) && !removedGroup.isACompleteLine()) { originalIndex = considerEnforcingIndentation(nodeText, originalIndex); } // If in front we have one space and before also we had space let's drop one space if (originalElements.size() > originalIndex && originalIndex > 0) { - if (originalElements.get(originalIndex).isWhiteSpace() - && originalElements.get(originalIndex - 1).isWhiteSpace()) { + if (originalElements.get(originalIndex).isWhiteSpace() && originalElements.get(originalIndex - 1).isWhiteSpace()) { // However we do not want to do that when we are about to adding or removing elements // The intention is not very clear maybe it should clarify this with examples! // Are we to understand that we can only do this if there is a single modification to process @@ -442,15 +410,11 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } } - diffIndex++; } - } else if (removed.isToken() && originalElementIsToken && - (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() - // handle EOLs separately as their token kind might not be equal. This is because the 'removed' - // element always has the current operating system's EOL as type - || (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() - && removed.isNewLine()))) { + } else if (removed.isToken() && originalElementIsToken && (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // handle EOLs separately as their token kind might not be equal. This is because the 'removed' + // element always has the current operating system's EOL as type + (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() && removed.isNewLine()))) { nodeText.removeElement(originalIndex); diffIndex++; } else if (originalElementIsToken && originalElement.isWhiteSpaceOrComment()) { @@ -469,13 +433,13 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, diffIndex++; } else if (originalElement.isWhiteSpace()) { originalIndex++; - } else if (removed.isChild()) { // see issue #3721 this case is linked for example to a change of type of variable declarator + } else if (removed.isChild()) { + // see issue #3721 this case is linked for example to a change of type of variable declarator nodeText.removeElement(originalIndex); diffIndex++; } else { throw new UnsupportedOperationException("removed " + removed.getElement() + " vs " + originalElement); } - cleanTheLineOfLeftOverSpace(removedGroup, removed); } @@ -487,13 +451,9 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo // if all elements were already processed there is nothing to do return; } - - if (!removedGroup.isProcessed() - && removedGroup.getLastElement() == removed - && removedGroup.isACompleteLine()) { + if (!removedGroup.isProcessed() && removedGroup.getLastElement() == removed && removedGroup.isACompleteLine()) { Integer lastElementIndex = removedGroup.getLastElementIndex(); Optional indentation = removedGroup.getIndentation(); - if (indentation.isPresent() && !isReplaced(lastElementIndex)) { for (int i = 0; i < indentation.get(); i++) { if (originalElements.get(originalIndex).isSpaceOrTab()) { @@ -506,7 +466,6 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo } } } - // Mark RemovedGroup as processed removedGroup.processed(); } @@ -518,7 +477,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) { if (originalElement.isComment()) { originalIndex++; - } else if (kept.isChild() && ((CsmChild)kept.getElement()).getChild() instanceof Comment ) { + } else if (kept.isChild() && ((CsmChild) kept.getElement()).getChild() instanceof Comment) { diffIndex++; } else if (kept.isChild() && originalElementIsChild) { diffIndex++; @@ -538,17 +497,18 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea int step = getIndexToNextTokenElement((TokenTextElement) originalElement, 0); originalIndex += step; originalIndex++; - } else if (originalElement.isIdentifier() && isTypeWithFullyQualifiedName(kept)) { - diffIndex++; - // skip all token related to node with the fully qualified name - // for example: - // java.lang.Object is represented in originalElement as a list of tokens "java", ".", "lang", ".", "Object". - // So we have to skip 5 tokens. - int step = getIndexToNextTokenElement((TokenTextElement) originalElement, kept); - originalIndex += step; - originalIndex++; // positioning on the next token + } else if (originalElement.isIdentifier() && isTypeWithFullyQualifiedName(kept)) { + diffIndex++; + // skip all token related to node with the fully qualified name + // for example: + // java.lang.Object is represented in originalElement as a list of tokens "java", ".", "lang", ".", "Object". + // So we have to skip 5 tokens. + int step = getIndexToNextTokenElement((TokenTextElement) originalElement, kept); + originalIndex += step; + // positioning on the next token + originalIndex++; } else if ((originalElement.isIdentifier() || originalElement.isKeyword()) && isArrayType(kept)) { - int tokenToSkip = getIndexToNextTokenElementInArrayType((TokenTextElement)originalElement, getArrayLevel(kept)); + int tokenToSkip = getIndexToNextTokenElementInArrayType((TokenTextElement) originalElement, getArrayLevel(kept)); diffIndex++; originalIndex += tokenToSkip; originalIndex++; @@ -565,7 +525,6 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea } } else if (kept.isToken() && originalElementIsToken) { TokenTextElement originalTextToken = (TokenTextElement) originalElement; - if (kept.getTokenType() == originalTextToken.getTokenKind()) { originalIndex++; diffIndex++; @@ -601,16 +560,14 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea } } - /* * Returns the array level if the DifferenceElement is a CsmChild representing an ArrayType else 0 */ private int getArrayLevel(DifferenceElement element) { CsmElement csmElem = element.getElement(); - if (csmElem instanceof LexicalDifferenceCalculator.CsmChild && - ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild() instanceof ArrayType) { + if (csmElem instanceof LexicalDifferenceCalculator.CsmChild && ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild() instanceof ArrayType) { Node child = ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild(); - return ((ArrayType)child).getArrayLevel(); + return ((ArrayType) child).getArrayLevel(); } return 0; } @@ -620,10 +577,9 @@ private int getArrayLevel(DifferenceElement element) { */ private boolean isArrayType(DifferenceElement element) { CsmElement csmElem = element.getElement(); - return csmElem instanceof LexicalDifferenceCalculator.CsmChild && - ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild() instanceof ArrayType; + return csmElem instanceof LexicalDifferenceCalculator.CsmChild && ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild() instanceof ArrayType; } - + /* * Returns true if the DifferenceElement is a CsmChild which represents a type with fully qualified name */ @@ -654,17 +610,23 @@ private boolean isNodeWithTypeArguments(DifferenceElement element) { * a ClassOrInterfaceType with a list of tokens like "java", ".", "lang", ".", "Object" */ private int getIndexToNextTokenElement(TokenTextElement element, DifferenceElement kept) { - int step = 0; // number of token to skip - if (!isTypeWithFullyQualifiedName(kept)) return 0; // verify if the DifferenceElement is a ClassOrInterfaceType with a fully qualified name + // number of token to skip + int step = 0; + // verify if the DifferenceElement is a ClassOrInterfaceType with a fully qualified name + if (!isTypeWithFullyQualifiedName(kept)) + return 0; CsmChild child = (CsmChild) kept.getElement(); // split the type fully qualified node name to an array of tokens String[] parts = ((ClassOrInterfaceType) child.getChild()).getNameWithScope().split("\\."); JavaToken token = element.getToken(); for (String part : parts) { if (part.equals(token.asString())) { - token = token.getNextToken().get(); // get 'dot' token - if (!token.asString().equals(".")) break; - token = token.getNextToken().get(); // get the next part + // get 'dot' token + token = token.getNextToken().get(); + if (!token.asString().equals(".")) + break; + // get the next part + token = token.getNextToken().get(); step += 2; continue; } @@ -674,7 +636,7 @@ private int getIndexToNextTokenElement(TokenTextElement element, DifferenceEleme } return step; } - + /* * Returns the number of tokens to skip in originalElements list to synchronize it with the DiffElements list * This is due to the fact that types are considered as token in the originalElements list. @@ -691,9 +653,11 @@ private int getIndexToNextTokenElement(TokenTextElement element, DifferenceEleme * @return the number of token to skip in originalElements list */ private int getIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator) { - int step = 0; // number of token to skip + // number of token to skip + int step = 0; Optional next = element.getToken().getNextToken(); - if (!next.isPresent()) return step; + if (!next.isPresent()) + return step; // because there is a token, first we need to increment the number of token to skip step++; // manage nested diamond operators by incrementing the level on LT token and decrementing on GT @@ -718,9 +682,11 @@ private int getIndexToNextTokenElement(TokenTextElement element, int nestedDiamo * Returns the number of tokens to skip in originalElements list to synchronize it with the DiffElements list */ private int getIndexToNextTokenElementInArrayType(TokenTextElement element, int arrayLevel) { - int step = 0; // number of token to skip + // number of token to skip + int step = 0; Optional next = element.getToken().getNextToken(); - if (!next.isPresent()) return step; + if (!next.isPresent()) + return step; // because there is a token, first we need to increment the number of token to skip step++; // manage array Level by decrementing the level on right bracket token @@ -765,9 +731,7 @@ private boolean openBraceWasOnSameLine() { } private boolean wasSpaceBetweenBraces() { - return nodeText.getTextElement(originalIndex).isToken(RBRACE) - && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) - && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); + return nodeText.getTextElement(originalIndex).isToken(RBRACE) && doWeHaveLeftBraceFollowedBySpace(originalIndex - 1) && (diffIndex < 2 || !diffElements.get(diffIndex - 2).isRemoved()); } private boolean doWeHaveLeftBraceFollowedBySpace(int index) { @@ -788,7 +752,7 @@ private int rewindSpace(int index) { private boolean nextIsRightBrace(int index) { List elements = originalElements.subList(index, originalElements.size()); - for(TextElement element : elements) { + for (TextElement element : elements) { if (!element.isSpaceOrTab()) { return element.isToken(RBRACE); } @@ -798,7 +762,7 @@ private boolean nextIsRightBrace(int index) { private void applyAddedDiffElement(Added added) { if (added.isIndent()) { - for (int i=0;i 0) && originalElements.get(originalIndex - 1).isNewline(); @@ -821,9 +784,7 @@ private void applyAddedDiffElement(Added added) { List elements = processIndentation(indentation, originalElements.subList(0, originalIndex - 1)); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); for (TextElement e : elements) { - if (!nextIsRightBrace - && e instanceof TokenTextElement - && originalElements.get(originalIndex).isToken(((TokenTextElement)e).getTokenKind())) { + if (!nextIsRightBrace && e instanceof TokenTextElement && originalElements.get(originalIndex).isToken(((TokenTextElement) e).getTokenKind())) { originalIndex++; } else { nodeText.addElement(originalIndex++, e); @@ -853,7 +814,6 @@ private void applyAddedDiffElement(Added added) { } } } - if (!used) { // Handling trailing comments boolean sufficientTokensRemainToSkip = nodeText.numberOfElements() > originalIndex + 2; @@ -862,37 +822,41 @@ private void applyAddedDiffElement(Added added) { boolean currentIsNewline = nodeText.getTextElement(originalIndex).isNewline(); boolean isFirstElement = originalIndex == 0; boolean previousIsWhiteSpace = originalIndex > 0 && nodeText.getTextElement(originalIndex - 1).isWhiteSpace(); - if (sufficientTokensRemainToSkip && currentIsAComment) { // Need to get behind the comment: - originalIndex += 2; // FIXME: Why 2? This comment and the next newline? - nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment - + // FIXME: Why 2? This comment and the next newline? + originalIndex += 2; + // Defer originalIndex increment + nodeText.addElement(originalIndex, addedTextElement); // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - originalIndex++; // Now we can increment + // Now we can increment + originalIndex++; } else if (currentIsNewline && previousIsAComment) { /* * Manage the case where we want to add an element, after an expression which is followed by a comment on the same line. * This is not the same case as the one who handles the trailing comments, because in this case the node text element is a new line (not a comment) * For example : {@code private String a; // this is a } */ - originalIndex++; // Insert after the new line which follows this comment. - + // Insert after the new line which follows this comment. + originalIndex++; // We want to adjust the indentation while considering the new element that we added originalIndex = adjustIndentation(indentation, nodeText, originalIndex, false); - nodeText.addElement(originalIndex, addedTextElement); // Defer originalIndex increment - originalIndex++; // Now we can increment. + // Defer originalIndex increment + nodeText.addElement(originalIndex, addedTextElement); + // Now we can increment. + originalIndex++; } else if (currentIsNewline && addedTextElement.isChild()) { // here we want to place the new child element after the current new line character. - // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) + // Except if indentation has been inserted just before this step (in the case where isPreviousElementNewline is true) // or if the previous character is a space (it could be the case if we want to replace a statement) // Example 1 : if we insert a statement (a duplicated method call expression ) after this one value();\n\n // we want to have this result value();\n value();\n not value();\n \nvalue(); - // Example 2 : if we want to insert a statement after this one \n we want to have value();\n - // not \nvalue(); --> this case appears on member replacement for example + // Example 2 : if we want to insert a statement after this one \n we want to have value();\n + // not \nvalue(); --> this case appears on member replacement for example if (!isPreviousElementNewline && !isFirstElement && !previousIsWhiteSpace) { - originalIndex++; // Insert after the new line + // Insert after the new line + originalIndex++; } nodeText.addElement(originalIndex, addedTextElement); originalIndex++; @@ -901,7 +865,6 @@ private void applyAddedDiffElement(Added added) { originalIndex++; } } - if (addedTextElement.isNewline()) { boolean followedByUnindent = isFollowedByUnindent(diffElements, diffIndex); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); @@ -910,7 +873,6 @@ private void applyAddedDiffElement(Added added) { originalIndex = adjustIndentation(indentation, nodeText, originalIndex, followedByUnindent); } } - diffIndex++; } @@ -920,26 +882,21 @@ private String tokenDescription(int kind) { private Map getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder) { Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); - List nextOrderElements = elementsFromNextOrder.getElements(); List previousOrderElements = elementsFromPreviousOrder.getElements(); WrappingRangeIterator piNext = new WrappingRangeIterator(previousOrderElements.size()); - for (int ni = 0; ni < nextOrderElements.size(); ni++) { boolean found = false; CsmElement ne = nextOrderElements.get(ni); - for (int counter = 0; counter < previousOrderElements.size() && !found; counter++) { Integer pi = piNext.next(); CsmElement pe = previousOrderElements.get(pi); - if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) - && DifferenceElementCalculator.matching(ne, pe)) { + if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) && DifferenceElementCalculator.matching(ne, pe)) { found = true; correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi); } } } - return correspondanceBetweenNextOrderAndPreviousOrder; } @@ -948,41 +905,31 @@ private Map getCorrespondanceBetweenNextOrderAndPreviousOrder( */ private boolean isFollowedByUnindent(List diffElements, int diffIndex) { int nextIndexValue = diffIndex + 1; - return (nextIndexValue) < diffElements.size() - && diffElements.get(nextIndexValue).isAdded() - && diffElements.get(nextIndexValue).getElement() instanceof CsmUnindent; + return (nextIndexValue) < diffElements.size() && diffElements.get(nextIndexValue).isAdded() && diffElements.get(nextIndexValue).getElement() instanceof CsmUnindent; } private List findIndexOfCorrespondingNodeTextElement(List elements, NodeText nodeText, int startIndex, Node node) { List correspondingIndices = new ArrayList<>(); for (ListIterator csmElementListIterator = elements.listIterator(); csmElementListIterator.hasNext(); ) { - int previousCsmElementIndex = csmElementListIterator.previousIndex(); CsmElement csmElement = csmElementListIterator.next(); int nextCsmElementIndex = csmElementListIterator.nextIndex(); - Map potentialMatches = new EnumMap<>(MatchClassification.class); - for (int i = startIndex; i < nodeText.numberOfElements(); i++){ + for (int i = startIndex; i < nodeText.numberOfElements(); i++) { if (!correspondingIndices.contains(i)) { TextElement textElement = nodeText.getTextElement(i); - boolean isCorresponding = isCorrespondingElement(textElement, csmElement, node); - if (isCorresponding) { boolean hasSamePreviousElement = false; if (i > 0 && previousCsmElementIndex > -1) { TextElement previousTextElement = nodeText.getTextElement(i - 1); - hasSamePreviousElement = isCorrespondingElement(previousTextElement, elements.get(previousCsmElementIndex), node); } - boolean hasSameNextElement = false; if (i < nodeText.numberOfElements() - 1 && nextCsmElementIndex < elements.size()) { TextElement nextTextElement = nodeText.getTextElement(i + 1); - hasSameNextElement = isCorrespondingElement(nextTextElement, elements.get(nextCsmElementIndex), node); } - if (hasSamePreviousElement && hasSameNextElement) { potentialMatches.putIfAbsent(MatchClassification.ALL, i); } else if (hasSamePreviousElement) { @@ -997,22 +944,19 @@ private List findIndexOfCorrespondingNodeTextElement(List e } } } - // Prioritize the matches from best to worst - Optional bestMatchKey = potentialMatches.keySet().stream() - .min(Comparator.comparing(MatchClassification::getPriority)); - + Optional bestMatchKey = potentialMatches.keySet().stream().min(Comparator.comparing(MatchClassification::getPriority)); if (bestMatchKey.isPresent()) { correspondingIndices.add(potentialMatches.get(bestMatchKey.get())); } else { correspondingIndices.add(-1); } } - return correspondingIndices; } private enum MatchClassification { + ALL(1), PREVIOUS_AND_SAME(2), NEXT_AND_SAME(3), SAME_ONLY(4), ALMOST(5); private final int priority; @@ -1028,21 +972,20 @@ int getPriority() { private boolean isCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) { if (csmElement instanceof CsmToken) { - CsmToken csmToken = (CsmToken)csmElement; + CsmToken csmToken = (CsmToken) csmElement; if (textElement instanceof TokenTextElement) { - TokenTextElement tokenTextElement = (TokenTextElement)textElement; + TokenTextElement tokenTextElement = (TokenTextElement) textElement; return tokenTextElement.getTokenKind() == csmToken.getTokenType() && tokenTextElement.getText().equals(csmToken.getContent(node)); } } else if (csmElement instanceof CsmChild) { - CsmChild csmChild = (CsmChild)csmElement; + CsmChild csmChild = (CsmChild) csmElement; if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement)textElement; + ChildTextElement childTextElement = (ChildTextElement) textElement; return childTextElement.getChild() == csmChild.getChild(); } } else { throw new UnsupportedOperationException(); } - return false; } @@ -1050,7 +993,7 @@ private boolean isAlmostCorrespondingElement(TextElement textElement, CsmElement if (isCorrespondingElement(textElement, csmElement, node)) { return false; } - return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken)csmElement).isWhiteSpace(); + return textElement.isWhiteSpace() && csmElement instanceof CsmToken && ((CsmToken) csmElement).isWhiteSpace(); } private int adjustIndentation(List indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) { @@ -1061,7 +1004,7 @@ private int adjustIndentation(List indentation, NodeText nodeT indentationAdj = indentationAdj.subList(0, Math.max(0, indentationAdj.size() - STANDARD_INDENTATION_SIZE)); } for (TextElement e : indentationAdj) { - if ((nodeTextIndex< nodeText.numberOfElements()) && nodeText.getTextElement(nodeTextIndex).isSpaceOrTab()) { + if ((nodeTextIndex < nodeText.numberOfElements()) && nodeText.getTextElement(nodeTextIndex).isSpaceOrTab()) { nodeTextIndex++; } else { nodeText.getElements().add(nodeTextIndex++, e); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java index f4a782ce08..7d80347889 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElement.java @@ -18,12 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; public interface DifferenceElement { + static DifferenceElement added(CsmElement element) { return new Added(element); } @@ -44,13 +44,13 @@ static DifferenceElement kept(CsmElement element) { boolean isAdded(); boolean isRemoved(); - + boolean isKept(); - - default boolean isChild() { - return getElement() instanceof LexicalDifferenceCalculator.CsmChild; + + default boolean isChild() { + return getElement() instanceof LexicalDifferenceCalculator.CsmChild; } - + /* * If the {@code DifferenceElement} wraps an EOL token then this method returns a new wrapped {@code CsmElement} * with the specified line separator. The line separator parameter must be a {@code CsmToken} with a valid line diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index d624c040cc..099e5403db 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -18,51 +18,49 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; -import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + class DifferenceElementCalculator { - + // internally keep track of a node position in a List public static class ChildPositionInfo { + Node node; + Integer position; + ChildPositionInfo(Node node, Integer position) { this.node = node; this.position = position; } + @Override public boolean equals(Object other) { - if ( other == null || !(other instanceof ChildPositionInfo)) + if (other == null || !(other instanceof ChildPositionInfo)) return false; - ChildPositionInfo cpi = (ChildPositionInfo)other; - // verify that the node content and the position are equal + ChildPositionInfo cpi = (ChildPositionInfo) other; + // verify that the node content and the position are equal // because we can have nodes with the same content but in different lines // in this case we consider that nodes are not equals - return this.node.equals(cpi.node) - && this.node.hasRange() && cpi.node.hasRange() - && this.node.getRange().get().contains(cpi.node.getRange().get()); + return this.node.equals(cpi.node) && this.node.hasRange() && cpi.node.hasRange() && this.node.getRange().get().contains(cpi.node.getRange().get()); } + @Override public int hashCode() { return node.hashCode() + position.hashCode(); } } - + static boolean matching(CsmElement a, CsmElement b) { if (a instanceof CsmChild) { if (b instanceof CsmChild) { @@ -76,7 +74,7 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { @@ -84,8 +82,8 @@ static boolean matching(CsmElement a, CsmElement b) { // Tokens are described by their type AND their content // and TokenContentCalculator. By using .equals(), all // three values are compared. - CsmToken childA = (CsmToken)a; - CsmToken childB = (CsmToken)b; + CsmToken childA = (CsmToken) a; + CsmToken childB = (CsmToken) b; return childA.equals(childB); } else if (b instanceof CsmChild) { return false; @@ -94,14 +92,14 @@ static boolean matching(CsmElement a, CsmElement b) { } else if (b instanceof CsmUnindent) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmIndent) { return b instanceof CsmIndent; } else if (a instanceof CsmUnindent) { return b instanceof CsmUnindent; } - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } private static boolean replacement(CsmElement a, CsmElement b) { @@ -116,18 +114,18 @@ private static boolean replacement(CsmElement a, CsmElement b) { } else if (b instanceof CsmToken) { return false; } else { - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } } else if (a instanceof CsmToken) { if (b instanceof CsmToken) { - CsmToken childA = (CsmToken)a; - CsmToken childB = (CsmToken)b; + CsmToken childA = (CsmToken) a; + CsmToken childB = (CsmToken) b; return childA.getTokenType() == childB.getTokenType(); } else if (b instanceof CsmChild) { return false; } } - throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName()); + throw new UnsupportedOperationException(a.getClass().getSimpleName() + " " + b.getClass().getSimpleName()); } /** @@ -135,10 +133,10 @@ private static boolean replacement(CsmElement a, CsmElement b) { */ private static List findChildrenPositions(LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel) { List positions = new ArrayList<>(); - for (int i=0;i findChildrenPositions(LexicalDifferenceCa static List calculate(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { // For performance reasons we use the positions of matching children // to guide the calculation of the difference - // + // // Suppose we have: - // qwerty[A]uiop - // qwer[A]uiop - // + // qwerty[A]uiop + // qwer[A]uiop + // // with [A] being a child and lowercase letters being tokens - // + // // We would calculate the Difference between "qwerty" and "qwer" then we know the A is kept, and then we // would calculate the difference between "uiop" and "uiop" - List childrenInOriginal = findChildrenPositions(original); List childrenInAfter = findChildrenPositions(after); - List commonChildren = new ArrayList<>(childrenInOriginal); commonChildren.retainAll(childrenInAfter); - List elements = new LinkedList<>(); - int originalIndex = 0; int afterIndex = 0; int commonChildrenIndex = 0; while (commonChildrenIndex < commonChildren.size()) { ChildPositionInfo child = commonChildren.get(commonChildrenIndex++); // search the position of the node "child" in the original list of cms element - int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); + int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); // search the position of the node "child" in the modified list of cms element - int posOfNextChildInAfter = childrenInAfter.stream().filter(i->i.equals(child)).map(i->i.position).findFirst().get(); - + int posOfNextChildInAfter = childrenInAfter.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) { elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter))); } @@ -186,7 +179,6 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS originalIndex = posOfNextChildInOriginal + 1; afterIndex = posOfNextChildInAfter + 1; } - if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) { elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size()))); } @@ -211,8 +203,7 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, boolean dealtWith = false; if (removedElement instanceof CsmChild) { CsmChild removedChild = (CsmChild) removedElement; - if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && - removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { + if (removedChild.getChild() instanceof Type && removedChild.getChild().getParentNode().isPresent() && removedChild.getChild().getParentNode().get() instanceof VariableDeclarator) { NodeText nodeTextForChild = LexicalPreservingPrinter.getOrCreateNodeText(removedChild.getChild()); considerRemoval(nodeTextForChild, elements); originalIndex++; @@ -226,16 +217,12 @@ private static int considerRemoval(CsmElement removedElement, int originalIndex, return originalIndex; } - private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, - LexicalDifferenceCalculator.CalculatedSyntaxModel after) { + private static List calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) { List elements = new LinkedList<>(); - int originalIndex = 0; int afterIndex = 0; - // We move through the two CalculatedSyntaxModel, moving both forward when we have a match // and moving just one side forward when we have an element kept or removed - do { if (originalIndex < original.elements.size() && afterIndex >= after.elements.size()) { CsmElement removedElement = original.elements.get(originalIndex); @@ -246,13 +233,12 @@ private static List calculateImpl(LexicalDifferenceCalculator } else { CsmElement nextOriginal = original.elements.get(originalIndex); CsmElement nextAfter = after.elements.get(afterIndex); - if ((nextOriginal instanceof CsmMix) && (nextAfter instanceof CsmMix)) { if (((CsmMix) nextAfter).getElements().equals(((CsmMix) nextOriginal).getElements())) { // No reason to deal with a reshuffled, we are just going to keep everything as it is ((CsmMix) nextAfter).getElements().forEach(el -> elements.add(new Kept(el))); } else { - elements.add(new Reshuffled((CsmMix)nextOriginal, (CsmMix)nextAfter)); + elements.add(new Reshuffled((CsmMix) nextOriginal, (CsmMix) nextAfter)); } originalIndex++; afterIndex++; @@ -271,7 +257,6 @@ private static List calculateImpl(LexicalDifferenceCalculator if (cost(addingElements) > 0) { removingElements = calculate(original.from(originalIndex + 1), after.from(afterIndex)); } - if (removingElements == null || cost(removingElements) > cost(addingElements)) { elements.add(new Added(nextAfter)); afterIndex++; @@ -282,7 +267,6 @@ private static List calculateImpl(LexicalDifferenceCalculator } } } while (originalIndex < original.elements.size() || afterIndex < after.elements.size()); - return elements; } @@ -290,7 +274,6 @@ private static long cost(List elements) { return elements.stream().filter(e -> !(e instanceof Kept)).count(); } - /** * Remove from the difference all the elements related to indentation. * This is mainly intended for test purposes. diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java index 9a58329df9..50337dd5a6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Kept.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.TokenTypes; @@ -29,6 +28,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; public class Kept implements DifferenceElement { + private final CsmElement element; Kept(CsmElement element) { @@ -42,11 +42,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Kept kept = (Kept) o; - return element.equals(kept.element); } @@ -65,7 +65,6 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } - throw new IllegalStateException("Kept is not a " + CsmToken.class.getSimpleName()); } @@ -73,38 +72,42 @@ public int getTokenType() { public boolean isAdded() { return false; } - + @Override public boolean isRemoved() { return false; } - + @Override public boolean isKept() { return true; } - public boolean isIndent() { return element instanceof CsmIndent; } + public boolean isIndent() { + return element instanceof CsmIndent; + } - public boolean isUnindent() { return element instanceof CsmUnindent; } + public boolean isUnindent() { + return element instanceof CsmUnindent; + } - public boolean isToken() { return element instanceof CsmToken; } + public boolean isToken() { + return element instanceof CsmToken; + } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } - return false; } public boolean isWhiteSpace() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } - return false; } @@ -113,17 +116,14 @@ public boolean isWhiteSpaceOrComment() { CsmToken csmToken = (CsmToken) element; return TokenTypes.isWhitespaceOrComment(csmToken.getTokenType()); } - return false; } public boolean isNewLine() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } - return false; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java index d9e6f1f9a3..e5bc930435 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java @@ -18,18 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.TokenTypes.eolTokenKind; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; @@ -43,14 +33,13 @@ import com.github.javaparser.printer.SourcePrinter; import com.github.javaparser.printer.Stringable; import com.github.javaparser.printer.concretesyntaxmodel.*; -import com.github.javaparser.printer.lexicalpreservation.changes.Change; -import com.github.javaparser.printer.lexicalpreservation.changes.ListAdditionChange; -import com.github.javaparser.printer.lexicalpreservation.changes.ListRemovalChange; -import com.github.javaparser.printer.lexicalpreservation.changes.ListReplacementChange; -import com.github.javaparser.printer.lexicalpreservation.changes.NoChange; -import com.github.javaparser.printer.lexicalpreservation.changes.PropertyChange; +import com.github.javaparser.printer.lexicalpreservation.changes.*; import com.github.javaparser.utils.LineSeparator; +import java.util.*; + +import static com.github.javaparser.TokenTypes.eolTokenKind; + class LexicalDifferenceCalculator { /** @@ -58,6 +47,7 @@ class LexicalDifferenceCalculator { * with no condition, no lists, just tokens and node children. */ static class CalculatedSyntaxModel { + final List elements; CalculatedSyntaxModel(List elements) { @@ -70,9 +60,7 @@ public CalculatedSyntaxModel from(int index) { @Override public String toString() { - return "CalculatedSyntaxModel{" + - "elements=" + elements + - '}'; + return "CalculatedSyntaxModel{" + "elements=" + elements + '}'; } CalculatedSyntaxModel sub(int start, int end) { @@ -85,6 +73,7 @@ void removeIndentationElements() { } static class CsmChild implements CsmElement { + private final Node child; public Node getChild() { @@ -102,16 +91,16 @@ public void prettyPrint(Node node, SourcePrinter printer) { @Override public String toString() { - return "child(" + child.getClass().getSimpleName()+")"; + return "child(" + child.getClass().getSimpleName() + ")"; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; CsmChild csmChild = (CsmChild) o; - return child.equals(csmChild.child); } @@ -134,13 +123,10 @@ List calculateListAdditionDifference(ObservableProperty obser CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container); CalculatedSyntaxModel after = calculatedSyntaxModelAfterListAddition(element, observableProperty, nodeList, index, nodeAdded); - List differenceElements = DifferenceElementCalculator.calculate(original, after); - // Set the line separator character tokens LineSeparator lineSeparator = container.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); replaceEolTokens(differenceElements, lineSeparator); - return differenceElements; } @@ -154,14 +140,14 @@ private void replaceEolTokens(List differenceElements, LineSe differenceElements.set(i, differenceElement.replaceEolTokens(eol)); } } - + /* * Returns a new line token */ private CsmElement getNewLineToken(LineSeparator lineSeparator) { return CsmElement.newline(lineSeparator); } - + List calculateListReplacementDifference(ObservableProperty observableProperty, NodeList nodeList, int index, Node newValue) { Node container = nodeList.getParentNodeForChildren(); CsmElement element = ConcreteSyntaxModel.forClass(container.getClass()); @@ -200,10 +186,10 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List nodeList; if (rawValue instanceof Optional) { - Optional optional = (Optional)rawValue; + Optional optional = (Optional) rawValue; if (optional.isPresent()) { if (!(optional.get() instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + optional.get().getClass().getCanonicalName()); @@ -261,7 +247,6 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List collection = (Collection) change.getValue(csmList.getProperty(), node); if (!collection.isEmpty()) { calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change); - boolean first = true; for (Iterator it = collection.iterator(); it.hasNext(); ) { if (!first) { @@ -277,7 +261,7 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List mixElements = new LinkedList<>(); csmMix.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, mixElements, change)); elements.add(new CsmMix(mixElements)); } else if (csm instanceof CsmChild) { elements.add(csm); } else { - throw new UnsupportedOperationException(csm.getClass().getSimpleName()+ " " + csm); + throw new UnsupportedOperationException(csm.getClass().getSimpleName() + " " + csm); } } public static int toToken(Modifier modifier) { - switch (modifier.getKeyword()) { + switch(modifier.getKeyword()) { case PUBLIC: return GeneratedJavaParserConstants.PUBLIC; case PRIVATE: @@ -382,10 +360,9 @@ public static int toToken(Modifier modifier) { } } - /// - /// Methods that calculate CalculatedSyntaxModel - /// - + // / + // / Methods that calculate CalculatedSyntaxModel + // / // Visible for testing CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(Node node, ObservableProperty property, Object oldValue, Object newValue) { return calculatedSyntaxModelAfterPropertyChange(ConcreteSyntaxModel.forClass(node.getClass()), node, property, oldValue, newValue); @@ -421,7 +398,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(Node container, Obs if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList)rawValue; + NodeList nodeList = (NodeList) rawValue; return calculatedSyntaxModelAfterListAddition(csm, observableProperty, nodeList, index, nodeAdded); } @@ -432,7 +409,7 @@ CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(Node container, Obse if (!(rawValue instanceof NodeList)) { throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName()); } - NodeList nodeList = (NodeList)rawValue; + NodeList nodeList = (NodeList) rawValue; return calculatedSyntaxModelAfterListRemoval(csm, observableProperty, nodeList, index); } @@ -443,5 +420,4 @@ private CalculatedSyntaxModel calculatedSyntaxModelAfterListReplacement(CsmEleme calculatedSyntaxModelForNode(csm, container, elements, new ListReplacementChange(observableProperty, index, newValue)); return new CalculatedSyntaxModel(elements); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index fdc7cc6c9f..3670b05aea 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -18,30 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.GeneratedJavaParserConstants.*; -import static com.github.javaparser.TokenTypes.eolTokenKind; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.decapitalize; -import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import com.github.javaparser.JavaToken; import com.github.javaparser.Range; import com.github.javaparser.ast.DataKey; @@ -60,22 +38,34 @@ import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.visitor.TreeVisitor; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; -import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; -import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; -import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; +import com.github.javaparser.printer.concretesyntaxmodel.*; import com.github.javaparser.utils.LineSeparator; import com.github.javaparser.utils.Pair; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.util.*; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static com.github.javaparser.utils.Utils.decapitalize; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; + /** * A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when * operating on the AST and then used them to reproduce the source code * in its original formatting including the AST changes. */ public class LexicalPreservingPrinter { - + private static String JAVA_UTIL_OPTIONAL = Optional.class.getCanonicalName(); + private static String JAVAPARSER_AST_NODELIST = NodeList.class.getCanonicalName(); private static AstObserver observer; @@ -88,10 +78,9 @@ public class LexicalPreservingPrinter { private static final LexicalDifferenceCalculator LEXICAL_DIFFERENCE_CALCULATOR = new LexicalDifferenceCalculator(); - // + // // Factory methods - // - + // /** * Prepares the node so it can be used in the print methods. * The correct order is: @@ -106,11 +95,9 @@ public class LexicalPreservingPrinter { */ public static N setup(N node) { assertNotNull(node); - if (observer == null) { observer = createObserver(); } - node.getTokenRange().ifPresent(r -> { storeInitialText(node); // Setup observer @@ -121,10 +108,9 @@ public static N setup(N node) { return node; } - // + // // Constructor and setup - // - + // private static AstObserver createObserver() { return new LexicalPreservingPrinter.Observer(); } @@ -142,20 +128,14 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } if (property == ObservableProperty.COMMENT) { Optional parentNode = observedNode.getParentNode(); - NodeText nodeText = parentNode - .map(parent -> getOrCreateNodeText(parentNode.get())) - // We're at the root node. - .orElse(getOrCreateNodeText(observedNode)); - + NodeText nodeText = parentNode.map(parent -> getOrCreateNodeText(parentNode.get())).// We're at the root node. + orElse(getOrCreateNodeText(observedNode)); if (oldValue == null) { - int index = parentNode.isPresent() ? - // Find the position of the comment node and put in front of it the [...] - nodeText.findChild(observedNode) : - // - 0; + int index = parentNode.isPresent() ? // Find the position of the comment node and put in front of it the [...] + nodeText.findChild(observedNode) : // + 0; // Add the same indent depth of the comment to the following node fixIndentOfMovedNode(nodeText, index); - LineSeparator lineSeparator = observedNode.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); nodeText.addElement(index, makeCommentToken((Comment) newValue)); nodeText.addToken(index + 1, eolTokenKind(lineSeparator), lineSeparator.asRawString()); @@ -174,22 +154,18 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } } else { List matchingTokens = findTokenTextElementForComment((Comment) oldValue, nodeText); - if (matchingTokens.size() != 1) { throw new IllegalStateException("The matching comment to be replaced could not be found"); } - Comment newComment = (Comment) newValue; TokenTextElement matchingElement = matchingTokens.get(0); nodeText.replace(matchingElement.and(matchingElement.matchByRange()), makeCommentToken(newComment)); } } NodeText nodeText = getOrCreateNodeText(observedNode); - if (nodeText == null) { throw new NullPointerException(observedNode.getClass().getSimpleName()); } - LEXICAL_DIFFERENCE_CALCULATOR.calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue); } @@ -204,12 +180,10 @@ private TokenTextElement makeCommentToken(Comment newComment) { return new TokenTextElement(MULTI_LINE_COMMENT, "/*" + newComment.getContent() + "*/"); } throw new UnsupportedOperationException("Unknown type of comment: " + newComment.getClass().getSimpleName()); - } private int getIndexOfComment(Comment oldValue, NodeText nodeText) { List matchingTokens = findTokenTextElementForComment(oldValue, nodeText); - if (!matchingTokens.isEmpty()) { TextElement matchingElement = matchingTokens.get(0); return nodeText.findElement(matchingElement.and(matchingElement.matchByRange())); @@ -222,58 +196,30 @@ private int getIndexOfComment(Comment oldValue, NodeText nodeText) { private List findChildTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingChildElements; - - matchingChildElements = nodeText.getElements().stream() - .filter(e -> e.isChild()) - .map(c -> (ChildTextElement) c) - .filter(c -> c.isComment()) - .filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())) - .collect(toList()); - + matchingChildElements = nodeText.getElements().stream().filter(e -> e.isChild()).map(c -> (ChildTextElement) c).filter(c -> c.isComment()).filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())).collect(toList()); if (matchingChildElements.size() > 1) { // Duplicate child nodes found, refine the result - matchingChildElements = matchingChildElements.stream() - .filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())) - .collect(toList()); + matchingChildElements = matchingChildElements.stream().filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())).collect(toList()); } - if (matchingChildElements.size() != 1) { throw new IllegalStateException("The matching child text element for the comment to be removed could not be found."); } - return matchingChildElements; } private List findTokenTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingTokens; - if (oldValue instanceof JavadocComment) { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(JAVADOC_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/**" + oldValue.getContent() + "*/")).collect(toList()); } else if (oldValue instanceof BlockComment) { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(MULTI_LINE_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(MULTI_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals("/*" + oldValue.getContent() + "*/")).collect(toList()); } else { - matchingTokens = nodeText.getElements().stream() - .filter(e -> e.isToken(SINGLE_LINE_COMMENT)) - .map(e -> (TokenTextElement) e) - .filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())) - .collect(toList()); + matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(SINGLE_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().trim().equals(("//" + oldValue.getContent()).trim())).collect(toList()); } - if (matchingTokens.size() > 1) { // Duplicate comments found, refine the result - matchingTokens = matchingTokens.stream() - .filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())) - .collect(toList()); + matchingTokens = matchingTokens.stream().filter(t -> isEqualRange(t.getToken().getRange(), oldValue.getRange())).collect(toList()); } - return matchingTokens; } @@ -281,7 +227,6 @@ private boolean isEqualRange(Optional range1, Optional range2) { if (range1.isPresent() && range2.isPresent()) { return range1.get().equals(range2.get()); } - return false; } @@ -296,9 +241,7 @@ private void fixIndentOfMovedNode(NodeText nodeText, int index) { if (index <= 0) { return; } - TextElement currentSpaceCandidate = null; - for (int i = index - 1; i >= 0; i--) { TextElement spaceCandidate = nodeText.getTextElement(i); if (spaceCandidate.isSpaceOrTab()) { @@ -309,10 +252,10 @@ private void fixIndentOfMovedNode(NodeText nodeText, int index) { if (spaceCandidate.isNewline() && i != index - 1) { for (int j = 0; j < (index - 1) - i; j++) { if (currentSpaceCandidate != null) { - // use the current (or last) indentation character + // use the current (or last) indentation character nodeText.addElement(index, new TokenTextElement(JavaToken.Kind.SPACE.getKind(), currentSpaceCandidate.expand())); } else { - // use the default indentation character + // use the default indentation character nodeText.addElement(index, new TokenTextElement(JavaToken.Kind.SPACE.getKind())); } } @@ -333,7 +276,6 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int } else { throw new UnsupportedOperationException(); } - Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -342,7 +284,6 @@ public void concreteListChange(NodeList changedList, ListChangeType type, int public void concreteListReplacement(NodeList changedList, int index, Node oldValue, Node newValue) { NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren()); List differenceElements = LEXICAL_DIFFERENCE_CALCULATOR.calculateListReplacementDifference(findNodeListName(changedList), changedList, index, newValue); - Difference difference = new Difference(differenceElements, nodeText, changedList.getParentNodeForChildren()); difference.apply(); } @@ -350,7 +291,6 @@ public void concreteListReplacement(NodeList changedList, int index, Node old private static void storeInitialText(Node root) { Map> tokensByNode = new IdentityHashMap<>(); - // We go over tokens and find to which nodes they belong. Note that we do not traverse the tokens as they were // on a list but as they were organized in a tree. At each time we select only the branch corresponding to the // range of interest and ignore all other branches @@ -363,9 +303,9 @@ private static void storeInitialText(Node root) { } tokensByNode.get(owner).add(token); } - // Now that we know the tokens we use them to create the initial NodeText for each node new TreeVisitor() { + @Override public void process(Node node) { if (!node.isPhantom()) { @@ -380,13 +320,12 @@ private static Optional findNodeForToken(Node node, Range tokenRange) { if (node.isPhantom()) { return Optional.empty(); } - if(!node.hasRange()) { + if (!node.hasRange()) { return Optional.empty(); } if (!node.getRange().get().contains(tokenRange)) { return Optional.empty(); } - for (Node child : node.getChildNodes()) { Optional found = findNodeForToken(child, tokenRange); if (found.isPresent()) { @@ -416,38 +355,30 @@ private static void storeInitialTextForOneNode(Node node, List nodeTo node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(toList()))); } - // + // // Iterators - // - + // private static Iterator tokensPreceeding(final Node node) { if (!node.getParentNode().isPresent()) { return new TextElementIteratorsFactory.EmptyIterator<>(); } // There is the awfully painful case of the fake types involved in variable declarators and // fields or variable declaration that are, of course, an exception... - NodeText parentNodeText = getOrCreateNodeText(node.getParentNode().get()); int index = parentNodeText.tryToFindChild(node); if (index == NodeText.NOT_FOUND) { if (node.getParentNode().get() instanceof VariableDeclarator) { return tokensPreceeding(node.getParentNode().get()); } else { - throw new IllegalArgumentException( - String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", - node, node.getParentNode().get(), parentNodeText)); + throw new IllegalArgumentException(String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", node, node.getParentNode().get(), parentNodeText)); } } - - return new TextElementIteratorsFactory.CascadingIterator<>( - TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), - () -> tokensPreceeding(node.getParentNode().get())); + return new TextElementIteratorsFactory.CascadingIterator<>(TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), () -> tokensPreceeding(node.getParentNode().get())); } - // + // // Printing methods - // - + // /** * Print a Node into a String, preserving the lexical information. */ @@ -472,14 +403,13 @@ public static void print(Node node, Writer writer) throws IOException { writer.append(text.expand()); } - // + // // Methods to handle transformations - // - + // private static void prettyPrintingTextNode(Node node, NodeText nodeText) { if (node instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) node; - switch (primitiveType.getType()) { + switch(primitiveType.getType()) { case BOOLEAN: nodeText.addToken(BOOLEAN, node.toString()); break; @@ -526,7 +456,6 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { nodeText.addToken(LexicalDifferenceCalculator.toToken(modifier), modifier.getKeyword().asString()); return; } - interpret(node, ConcreteSyntaxModel.forClass(node.getClass()), nodeText); } @@ -535,15 +464,12 @@ private static void prettyPrintingTextNode(Node node, NodeText nodeText) { */ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) { LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(csm, node); - List indentation = findIndentation(node); - boolean pendingIndentation = false; for (CsmElement element : calculatedSyntaxModel.elements) { if (element instanceof CsmIndent) { int indexCurrentElement = calculatedSyntaxModel.elements.indexOf(element); - if (calculatedSyntaxModel.elements.size() > indexCurrentElement && - !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { + if (calculatedSyntaxModel.elements.size() > indexCurrentElement && !(calculatedSyntaxModel.elements.get(indexCurrentElement + 1) instanceof CsmUnindent)) { for (int i = 0; i < Difference.STANDARD_INDENTATION_SIZE; i++) { indentation.add(new TokenTextElement(SPACE, " ")); } @@ -553,11 +479,9 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) indentation.remove(indentation.size() - 1); } } - if (pendingIndentation && !(element instanceof CsmToken && ((CsmToken) element).isNewLine())) { indentation.forEach(nodeText::addElement); } - pendingIndentation = false; if (element instanceof LexicalDifferenceCalculator.CsmChild) { nodeText.addChild(((LexicalDifferenceCalculator.CsmChild) element).getChild()); @@ -582,15 +506,13 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) // so they have to be handled in a special way if (node instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) node; - variableDeclarator.getParentNode().ifPresent(parent -> - ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { - int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); - for (int i = 0; i < extraArrayLevels; i++) { - nodeText.addElement(new TokenTextElement(LBRACKET)); - nodeText.addElement(new TokenTextElement(RBRACKET)); - } - }) - ); + variableDeclarator.getParentNode().ifPresent(parent -> ((NodeWithVariables) parent).getMaximumCommonType().ifPresent(mct -> { + int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel(); + for (int i = 0; i < extraArrayLevels; i++) { + nodeText.addElement(new TokenTextElement(LBRACKET)); + nodeText.addElement(new TokenTextElement(RBRACKET)); + } + })); } return nodeText; } @@ -611,8 +533,7 @@ static List findIndentation(Node node) { Iterator it = tokensPreceeding(node); while (it.hasNext()) { TokenTextElement tte = it.next(); - if (tte.getTokenKind() == SINGLE_LINE_COMMENT - || tte.isNewline()) { + if (tte.getTokenKind() == SINGLE_LINE_COMMENT || tte.isNewline()) { break; } else { followingNewlines.add(tte); @@ -627,10 +548,9 @@ static List findIndentation(Node node) { return followingNewlines; } - // + // // Helper methods - // - + // private static boolean isReturningOptionalNodeList(Method m) { if (!m.getReturnType().getCanonicalName().equals(JAVA_UTIL_OPTIONAL)) { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java index 2a2343c089..31ca91f665 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -31,14 +30,14 @@ * It is basically a list of tokens and children. */ class NodeText { + private final List elements; public static final int NOT_FOUND = -1; - // + // // Constructors - // - + // NodeText(List elements) { this.elements = elements; } @@ -50,10 +49,9 @@ class NodeText { this(new LinkedList<>()); } - // + // // Adding elements - // - + // /** * Add an element at the end. */ @@ -84,10 +82,9 @@ void addToken(int index, int tokenKind, String text) { elements.add(index, new TokenTextElement(tokenKind, text)); } - // + // // Finding elements - // - + // int findElement(TextElementMatcher matcher) { return findElement(matcher, 0); } @@ -95,8 +92,7 @@ int findElement(TextElementMatcher matcher) { int findElement(TextElementMatcher matcher, int from) { int res = tryToFindElement(matcher, from); if (res == NOT_FOUND) { - throw new IllegalArgumentException( - String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); + throw new IllegalArgumentException(String.format("I could not find child '%s' from position %d. Elements: %s", matcher, from, elements)); } return res; } @@ -127,10 +123,9 @@ int tryToFindChild(Node child, int from) { return tryToFindElement(TextElementMatchers.byNode(child), from); } - // + // // Removing single elements - // - + // public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhitespace) { int i = 0; for (TextElement e : elements) { @@ -151,34 +146,30 @@ public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhite throw new IllegalArgumentException(); } - // + // // Removing sequences - // - + // void removeElement(int index) { elements.remove(index); } - // + // // Replacing elements - // - + // void replace(TextElementMatcher position, TextElement newElement) { int index = findElement(position, 0); elements.remove(index); elements.add(index, newElement); } - // + // // Other methods - // - + // /** * Generate the corresponding string. */ String expand() { StringBuffer sb = new StringBuffer(); - elements.forEach(e -> sb.append(e.expand())); return sb.toString(); } @@ -202,5 +193,4 @@ List getElements() { public String toString() { return "NodeText{" + elements + '}'; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java index b40c08724e..580e06db97 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java @@ -18,19 +18,18 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import static java.util.Collections.synchronizedMap; - -import java.util.IdentityHashMap; -import java.util.Map; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.observer.AstObserver; import com.github.javaparser.ast.observer.AstObserverAdapter; import com.github.javaparser.ast.type.UnknownType; +import java.util.IdentityHashMap; +import java.util.Map; + +import static java.util.Collections.synchronizedMap; + /** * We want to recognize and ignore "phantom" nodes, like the fake type of variable in FieldDeclaration * @deprecated This class is no longer used phantom node are now an attribute of each node @@ -43,6 +42,7 @@ public class PhantomNodeLogic { private static final Map isPhantomNodeCache = synchronizedMap(new IdentityHashMap<>()); private static final AstObserver cacheCleaner = new AstObserverAdapter() { + @Override public void parentChange(Node observedNode, Node previousParent, Node newParent) { isPhantomNodeCache.remove(observedNode); @@ -56,11 +56,7 @@ static boolean isPhantomNode(Node node) { if (node instanceof UnknownType) { return true; } - boolean res = (node.getParentNode().isPresent() - && node.getParentNode().get().hasRange() - && node.hasRange() - && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) - || inPhantomNode(node, LEVELS_TO_EXPLORE)); + boolean res = (node.getParentNode().isPresent() && node.getParentNode().get().hasRange() && node.hasRange() && !node.getParentNode().get().getRange().get().contains(node.getRange().get()) || inPhantomNode(node, LEVELS_TO_EXPLORE)); isPhantomNodeCache.put(node, res); node.register(cacheCleaner); return res; @@ -71,9 +67,7 @@ static boolean isPhantomNode(Node node) { * A node contained in a phantom node is also a phantom node. We limit how many levels up we check just for performance reasons. */ private static boolean inPhantomNode(Node node, int levels) { - return node.getParentNode().isPresent() && - (isPhantomNode(node.getParentNode().get()) - || inPhantomNode(node.getParentNode().get(), levels - 1)); + return node.getParentNode().isPresent() && (isPhantomNode(node.getParentNode().get()) || inPhantomNode(node.getParentNode().get(), levels - 1)); } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java index 7edd0bc0cb..8815cff52b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Removed.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; public class Removed implements DifferenceElement { + private final CsmElement element; Removed(CsmElement element) { @@ -40,11 +40,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Removed removed = (Removed) o; - return element.equals(removed.element); } @@ -63,7 +63,6 @@ public Node getChild() { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild(); } - throw new IllegalStateException("Removed is not a " + LexicalDifferenceCalculator.CsmChild.class.getSimpleName()); } @@ -72,7 +71,6 @@ public int getTokenType() { CsmToken csmToken = (CsmToken) element; return csmToken.getTokenType(); } - throw new IllegalStateException("Removed is not a " + CsmToken.class.getSimpleName()); } @@ -80,43 +78,42 @@ public int getTokenType() { public boolean isAdded() { return false; } - + @Override public boolean isRemoved() { return true; } - + @Override public boolean isKept() { return false; } - public boolean isToken() { return element instanceof CsmToken; } + public boolean isToken() { + return element instanceof CsmToken; + } public boolean isPrimitiveType() { if (isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) element; return csmChild.getChild() instanceof PrimitiveType; } - return false; } public boolean isWhiteSpace() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isWhiteSpace(); } - return false; } public boolean isNewLine() { - if(isToken()) { + if (isToken()) { CsmToken csmToken = (CsmToken) element; return csmToken.isNewLine(); } - return false; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java index f258f21903..2f34b70232 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java @@ -18,9 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; +import com.github.javaparser.JavaToken; +import com.github.javaparser.TokenRange; +import com.github.javaparser.TokenTypes; +import com.github.javaparser.ast.Node; +import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; + import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -28,12 +33,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import com.github.javaparser.JavaToken; -import com.github.javaparser.TokenRange; -import com.github.javaparser.TokenTypes; -import com.github.javaparser.ast.Node; -import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; - /** * This class represents a group of {@link Removed} elements. * The {@link Removed} elements are ideally consecutive for the methods in this class to work correctly. @@ -48,6 +47,7 @@ final class RemovedGroup implements Iterable { private final Integer firstElementIndex; + private final List removedList; private boolean isProcessed = false; @@ -56,11 +56,9 @@ private RemovedGroup(Integer firstElementIndex, List removedList) { if (firstElementIndex == null) { throw new IllegalArgumentException("firstElementIndex should not be null"); } - if (removedList == null || removedList.isEmpty()) { throw new IllegalArgumentException("removedList should not be null or empty"); } - this.firstElementIndex = firstElementIndex; this.removedList = removedList; } @@ -94,9 +92,7 @@ final boolean isProcessed() { } private List getIndicesBeingRemoved() { - return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()) - .boxed() - .collect(Collectors.toList()); + return IntStream.range(firstElementIndex, firstElementIndex + removedList.size()).boxed().collect(Collectors.toList()); } /** @@ -141,13 +137,15 @@ final Removed getLastElement() { * @return true if the RemovedGroup equates to a complete line */ final boolean isACompleteLine() { - return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) - && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); + return hasOnlyWhitespace(getFirstElement(), hasOnlyWhitespaceInFrontFunction) && hasOnlyWhitespace(getLastElement(), hasOnlyWhitespaceBehindFunction); } private final Function hasOnlyWhitespaceJavaTokenInFrontFunction = begin -> hasOnlyWhiteSpaceForTokenFunction(begin, token -> token.getPreviousToken()); + private final Function hasOnlyWhitespaceJavaTokenBehindFunction = end -> hasOnlyWhiteSpaceForTokenFunction(end, token -> token.getNextToken()); + private final Function hasOnlyWhitespaceInFrontFunction = tokenRange -> hasOnlyWhitespaceJavaTokenInFrontFunction.apply(tokenRange.getBegin()); + private final Function hasOnlyWhitespaceBehindFunction = tokenRange -> hasOnlyWhitespaceJavaTokenBehindFunction.apply(tokenRange.getEnd()); private boolean hasOnlyWhitespace(Removed startElement, Function hasOnlyWhitespaceFunction) { @@ -155,7 +153,6 @@ private boolean hasOnlyWhitespace(Removed startElement, Function tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { hasOnlyWhitespace = hasOnlyWhitespaceFunction.apply(tokenRange.get()); @@ -171,7 +168,6 @@ private boolean hasOnlyWhitespace(Removed startElement, Function> tokenFunction) { Optional tokenResult = tokenFunction.apply(token); - if (tokenResult.isPresent()) { if (TokenTypes.isWhitespaceButNotEndOfLine(tokenResult.get().getKind())) { return hasOnlyWhiteSpaceForTokenFunction(tokenResult.get(), tokenFunction); @@ -181,7 +177,6 @@ private boolean hasOnlyWhiteSpaceForTokenFunction(JavaToken token, Function getIndentation() { Removed firstElement = null; int indentation = 0; - // search for the first element which is not a new line Iterator it = iterator(); - while(it.hasNext() ) { + while (it.hasNext()) { firstElement = (Removed) it.next(); if (firstElement.isNewLine()) continue; break; } - if (firstElement.isChild()) { LexicalDifferenceCalculator.CsmChild csmChild = (LexicalDifferenceCalculator.CsmChild) firstElement.getElement(); Node child = csmChild.getChild(); - Optional tokenRange = child.getTokenRange(); if (tokenRange.isPresent()) { JavaToken begin = tokenRange.get().getBegin(); - if (hasOnlyWhitespaceJavaTokenInFrontFunction.apply(begin)) { Optional previousToken = begin.getPreviousToken(); - - while(previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { + while (previousToken.isPresent() && (TokenTypes.isWhitespaceButNotEndOfLine(previousToken.get().getKind()))) { indentation++; - previousToken = previousToken.get().getPreviousToken(); } - if (previousToken.isPresent()) { if (TokenTypes.isEndOfLineToken(previousToken.get().getKind())) { return Optional.of(Integer.valueOf(indentation)); @@ -240,13 +228,13 @@ final Optional getIndentation() { } } } - return Optional.empty(); } @Override public final Iterator iterator() { return new Iterator() { + private int currentIndex = 0; @Override @@ -258,7 +246,6 @@ public boolean hasNext() { public Removed next() { return removedList.get(currentIndex++); } - }; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java index b4b442c117..8271250451 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Reshuffled.java @@ -18,22 +18,23 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.List; -import java.util.stream.Collectors; - import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmMix; import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; +import java.util.List; +import java.util.stream.Collectors; + /** * Elements in a CsmMix have been reshuffled. It could also mean that * some new elements have been added or removed to the mix. */ public class Reshuffled implements DifferenceElement { + private final CsmMix previousOrder; + private final CsmMix nextOrder; Reshuffled(CsmMix previousOrder, CsmMix nextOrder) { @@ -43,17 +44,18 @@ public class Reshuffled implements DifferenceElement { @Override public String toString() { - return "Reshuffled{" + nextOrder + ", previous="+ previousOrder+ '}'; + return "Reshuffled{" + nextOrder + ", previous=" + previousOrder + '}'; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Reshuffled that = (Reshuffled) o; - - if (!previousOrder.equals(that.previousOrder)) return false; + if (!previousOrder.equals(that.previousOrder)) + return false; return nextOrder.equals(that.nextOrder); } @@ -86,12 +88,12 @@ public boolean isAdded() { public boolean isRemoved() { return false; } - + @Override public boolean isKept() { return false; } - + /* * If the {@code DifferenceElement} wraps an EOL token then this method returns a new {@code DifferenceElement} * with all eof token replaced by the specified line separator. The line separator parameter must be a CsmToken with a valid line separator. @@ -102,22 +104,22 @@ public DifferenceElement replaceEolTokens(CsmElement lineSeparator) { CsmMix modifiedPreviousOrder = new CsmMix(replaceTokens(previousOrder.getElements(), lineSeparator)); return new Reshuffled(modifiedPreviousOrder, modifiedNextOrder); } - + /* * Replaces all eol tokens in the list by the specified line separator token */ private List replaceTokens(List elements, CsmElement lineSeparator) { - return elements.stream() - .map(element -> isNewLineToken(element) ? lineSeparator : element) - .collect(Collectors.toList()); + return elements.stream().map(element -> isNewLineToken(element) ? lineSeparator : element).collect(Collectors.toList()); } - + /* * Return true if the wrapped {@code CsmElement} is a new line token */ private boolean isNewLineToken(CsmElement element) { return isToken(element) && ((CsmToken) element).isNewLine(); } - - private boolean isToken(CsmElement element) { return element instanceof CsmToken; } + + private boolean isToken(CsmElement element) { + return element instanceof CsmToken; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java index 53e712c9c4..aaf35b48ee 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java @@ -18,15 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.Optional; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.Range; import com.github.javaparser.ast.Node; +import java.util.Optional; + public abstract class TextElement implements TextElementMatcher { abstract String expand(); @@ -34,9 +33,7 @@ public abstract class TextElement implements TextElementMatcher { abstract boolean isToken(int tokenKind); final boolean isCommentToken() { - return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) - || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) - || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); + return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT) || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT) || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT); } @Override @@ -59,7 +56,7 @@ public boolean match(TextElement textElement) { public abstract boolean isSeparator(); public abstract boolean isIdentifier(); - + public abstract boolean isKeyword(); public abstract boolean isPrimitive(); @@ -87,11 +84,7 @@ public boolean isChild() { * @return TextElementMatcher that matches any TextElement with the same Range */ TextElementMatcher matchByRange() { - return (TextElement textElement) -> - getRange() - .flatMap(r1 -> textElement.getRange() - .map(r1::equals)) - // We're missing range information. This may happen when a node is manually instantiated. Don't be too harsh on that: - .orElse(true); + return (TextElement textElement) -> getRange().flatMap(r1 -> textElement.getRange().map(r1::equals)).// We're missing range information. This may happen when a node is manually instantiated. Don't be too harsh on that: + orElse(true); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java index 392f969283..fedd4dd471 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; @@ -28,14 +27,20 @@ class TextElementIteratorsFactory { static class CascadingIterator implements Iterator { + interface Provider { + Iterator provide(); } private final Provider nextProvider; + private Iterator current; + private Iterator next; + private boolean lastReturnedFromCurrent = false; + private boolean lastReturnedFromNext = false; public CascadingIterator(Iterator current, Provider nextProvider) { @@ -43,7 +48,6 @@ public CascadingIterator(Iterator current, Provider nextProvider) { this.current = current; } - @Override public boolean hasNext() { if (current.hasNext()) { @@ -85,6 +89,7 @@ public void remove() { } static class EmptyIterator implements Iterator { + @Override public boolean hasNext() { return false; @@ -97,7 +102,9 @@ public E next() { } private static class SingleElementIterator implements Iterator { + private final E element; + private boolean returned; SingleElementIterator(E element) { @@ -117,12 +124,13 @@ public E next() { @Override public void remove() { - } } static class ComposedIterator implements Iterator { + private final List> elements; + private int currIndex; ComposedIterator(List> elements) { @@ -135,7 +143,7 @@ public boolean hasNext() { if (currIndex >= elements.size()) { return false; } - if (elements.get(currIndex).hasNext()){ + if (elements.get(currIndex).hasNext()) { return true; } currIndex++; @@ -159,14 +167,15 @@ public void remove() { private static Iterator reverseIterator(NodeText nodeText, int index) { TextElement textElement = nodeText.getTextElement(index); if (textElement instanceof TokenTextElement) { - return new SingleElementIterator((TokenTextElement)textElement) { + return new SingleElementIterator((TokenTextElement) textElement) { + @Override public void remove() { nodeText.removeElement(index); } }; } else if (textElement instanceof ChildTextElement) { - ChildTextElement childTextElement = (ChildTextElement)textElement; + ChildTextElement childTextElement = (ChildTextElement) textElement; NodeText textForChild = childTextElement.getNodeTextForWrappedNode(); return reverseIterator(textForChild); } else { @@ -180,10 +189,9 @@ public static Iterator reverseIterator(NodeText nodeText) { public static Iterator partialReverseIterator(NodeText nodeText, int fromIndex) { List> elements = new LinkedList<>(); - for (int i=fromIndex;i>=0;i--) { + for (int i = fromIndex; i >= 0; i--) { elements.add(reverseIterator(nodeText, i)); } return new ComposedIterator<>(elements); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java index 13f5dd0d13..fc9f2b4552 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; public interface TextElementMatcher { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java index 1e26906bab..08e5961aff 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; @@ -31,6 +30,7 @@ static TextElementMatcher byTokenType(int tokenType) { static TextElementMatcher byNode(final Node node) { return new TextElementMatcher() { + @Override public boolean match(TextElement textElement) { return textElement.isNode(node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java index 95cf5a9a34..e88fa1ed28 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java @@ -18,17 +18,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; -import java.util.Optional; - import com.github.javaparser.JavaToken; import com.github.javaparser.JavaToken.Kind; import com.github.javaparser.Range; import com.github.javaparser.ast.Node; +import java.util.Optional; + class TokenTextElement extends TextElement { + private final JavaToken token; TokenTextElement(JavaToken token) { @@ -63,11 +63,11 @@ public JavaToken getToken() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; TokenTextElement that = (TokenTextElement) o; - return token.equals(that.token); } @@ -105,7 +105,7 @@ public boolean isSpaceOrTab() { public boolean isComment() { return token.getCategory().isComment(); } - + @Override public boolean isSeparator() { return token.getCategory().isSeparator(); @@ -120,12 +120,12 @@ public boolean isNewline() { public boolean isChildOfClass(Class nodeClass) { return false; } - + @Override public boolean isIdentifier() { return getToken().getCategory().isIdentifier(); } - + @Override public boolean isKeyword() { return getToken().getCategory().isKeyword(); @@ -135,7 +135,7 @@ public boolean isKeyword() { public boolean isLiteral() { return getToken().getCategory().isLiteral(); } - + @Override public boolean isPrimitive() { return Kind.valueOf(getTokenKind()).isPrimitive(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java index e9314c9f0d..f9411f971d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java @@ -18,13 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation; import java.util.Iterator; public class WrappingRangeIterator implements Iterator { + private final int limit; + private int currentValue = 0; public WrappingRangeIterator(int limit) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java index 2a98838436..2163ceb44d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -32,7 +31,7 @@ public interface Change { default boolean evaluate(CsmConditional csmConditional, Node node) { - switch (csmConditional.getCondition()) { + switch(csmConditional.getCondition()) { case FLAG: return csmConditional.getProperties().stream().anyMatch(p -> (Boolean) getValue(p, node)); case IS_NOT_EMPTY: diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java index e247aef510..c8c4bf6de9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,7 +32,9 @@ public class ListAdditionChange implements Change { private final ObservableProperty observableProperty; + private final int index; + private final Node nodeAdded; public ListAdditionChange(ObservableProperty observableProperty, int index, Node nodeAdded) { @@ -54,15 +55,12 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- add to the list newNodeList.add(index, nodeAdded); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java index af9b40e58c..24267275ee 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,6 +32,7 @@ public class ListRemovalChange implements Change { private final ObservableProperty observableProperty; + private final int index; public ListRemovalChange(ObservableProperty observableProperty, int index) { @@ -52,15 +52,13 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); - newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); // fix #2187 set the parent node in the new list + // fix #2187 set the parent node in the new list + newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- remove an item from the list newNodeList.remove(index); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java index baa157a18d..e4a3ab1754 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -33,7 +32,9 @@ public class ListReplacementChange implements Change { private final ObservableProperty observableProperty; + private final int index; + private final Node newValue; public ListReplacementChange(ObservableProperty observableProperty, int index, Node newValue) { @@ -54,15 +55,12 @@ public Object getValue(ObservableProperty property, Node node) { throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName()); } NodeList currentNodeList = (NodeList) currentRawValue; - // Note: When adding to a node list children get assigned the list's parent, thus we must set the list's parent before adding children (#2592). NodeList newNodeList = new NodeList<>(); newNodeList.setParentNode(currentNodeList.getParentNodeForChildren()); newNodeList.addAll(currentNodeList); - // Perform modification -- replace an item in the list newNodeList.set(index, newValue); - return newNodeList; } else { return new NoChange().getValue(property, node); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java index 8670a94ac1..87706e5d10 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java index 81ab31a8f4..69edddae50 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.printer.lexicalpreservation.changes; import com.github.javaparser.ast.Node; @@ -30,7 +29,9 @@ public class PropertyChange implements Change { private final ObservableProperty property; + private final Object oldValue; + private final Object newValue; public PropertyChange(ObservableProperty property, Object oldValue, Object newValue) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java index 34556997bf..eca64fef23 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; /** @@ -34,5 +33,4 @@ public class MethodAmbiguityException extends RuntimeException { public MethodAmbiguityException(String description) { super(description); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java index 84bec1d99d..9f764a099a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -28,7 +27,6 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; - import java.util.*; /** @@ -38,10 +36,15 @@ * @author Federico Tomassetti */ public class MethodUsage implements ResolvedTypeParametrized { + private ResolvedMethodDeclaration declaration; + private List paramTypes = new ArrayList<>(); + private List exceptionTypes = new ArrayList<>(); + private ResolvedType returnType; + private ResolvedTypeParametersMap typeParametersMap; public MethodUsage(ResolvedMethodDeclaration declaration) { @@ -56,19 +59,15 @@ public MethodUsage(ResolvedMethodDeclaration declaration) { returnType = declaration.getReturnType(); } - public MethodUsage(ResolvedMethodDeclaration declaration, - List paramTypes, ResolvedType returnType) { - this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), - ResolvedTypeParametersMap.empty()); + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType) { + this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(), ResolvedTypeParametersMap.empty()); } - public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, - List exceptionTypes) { + public MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes) { this(declaration, paramTypes, returnType, exceptionTypes, ResolvedTypeParametersMap.empty()); } - private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, - List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { + private MethodUsage(ResolvedMethodDeclaration declaration, List paramTypes, ResolvedType returnType, List exceptionTypes, ResolvedTypeParametersMap typeParametersMap) { this.declaration = declaration; this.paramTypes = paramTypes; this.returnType = returnType; @@ -78,10 +77,7 @@ private MethodUsage(ResolvedMethodDeclaration declaration, List pa @Override public String toString() { - return "MethodUsage{" + - "declaration=" + declaration + - ", paramTypes=" + paramTypes + - '}'; + return "MethodUsage{" + "declaration=" + declaration + ", paramTypes=" + paramTypes + '}'; } public ResolvedMethodDeclaration getDeclaration() { @@ -154,11 +150,8 @@ public MethodUsage replaceTypeParameter(ResolvedTypeParameterDeclaration typePar if (type == null) { throw new IllegalArgumentException(); } - // TODO if the method declaration has a type param with that name ignore this call - MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, - typeParametersMap.toBuilder().setValue(typeParameter, type).build()); - + MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, typeParametersMap.toBuilder().setValue(typeParameter, type).build()); Map inferredTypes = new HashMap<>(); for (int i = 0; i < paramTypes.size(); i++) { ResolvedType originalParamType = paramTypes.get(i); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java index 57fd12de6a..934358b9f3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java @@ -18,9 +18,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; public interface Resolvable { + T resolve(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java index 45648a801e..f6fde474a3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; import com.github.javaparser.ast.Node; @@ -27,6 +26,7 @@ import com.github.javaparser.resolution.types.ResolvedType; public interface SymbolResolver { + /** * For a reference it would find the corresponding * declaration. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java index 7dba04de7e..807765c84e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution; /** @@ -70,10 +69,6 @@ public String getName() { @Override public String toString() { - return "UnsolvedSymbolException{" + - "context='" + context + "'" + - ", name='" + name + "'" + - ", cause='" + cause + "'" + - "}"; + return "UnsolvedSymbolException{" + "context='" + context + "'" + ", name='" + name + "'" + ", cause='" + cause + "'" + "}"; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java index ba0d835025..a079f13896 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java index 8a6a11a7d4..278e2962a7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.AccessSpecifier; @@ -35,5 +34,4 @@ public interface HasAccessSpecifier { * The access specifier of this element. */ AccessSpecifier accessSpecifier(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java index cb0f764f0d..1df78f4e9f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java @@ -18,18 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; -import java.util.List; - import com.github.javaparser.ast.body.AnnotationDeclaration; +import java.util.List; + /** * @author Federico Tomassetti */ -public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, - AssociableToAST { +public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration, AssociableToAST { @Override default boolean isAnnotation() { @@ -42,6 +40,6 @@ default ResolvedAnnotationDeclaration asAnnotation() { } List getAnnotationMembers(); - + boolean isInheritable(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java index 3efca83c81..9f74727e15 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.expr.Expression; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java index cd854c0730..739e6cfd55 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.Node; @@ -35,8 +34,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { /** * This method should always return true. @@ -77,15 +75,13 @@ default boolean isClass() { */ List getAllInterfaces(); - /// - /// Constructors - /// - + // / + // / Constructors + // / /** * List of constructors available for the class. * This list should also include the default constructor. */ @Override List getConstructors(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java index bcbc281894..6fd37d23f6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ConstructorDeclaration; @@ -28,8 +27,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, - AssociableToAST { +public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration, AssociableToAST { /** * A constructor can be declared in a class or an enum. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java index 604b5ed33b..f63ee52801 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java index 1b2e044446..cc418cf70a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java index 67e3a564db..a0f15394b7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import java.util.List; @@ -28,8 +27,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, - HasAccessSpecifier { +public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, HasAccessSpecifier { @Override default boolean isEnum() { @@ -48,7 +46,6 @@ default boolean hasEnumConstant(String name) { } default ResolvedEnumConstantDeclaration getEnumConstant(final String name) { - return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst() - .orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); + return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst().orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java index e8df99dd58..521916a309 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.FieldDeclaration; @@ -34,7 +33,7 @@ public interface ResolvedFieldDeclaration extends ResolvedValueDeclaration, HasA * Is the field static? */ boolean isStatic(); - + /** * Is the field volatile? */ @@ -54,5 +53,4 @@ default ResolvedFieldDeclaration asField() { * The type on which this field has been declared */ ResolvedTypeDeclaration declaringType(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java index 442adfa2a4..83dbc5f8af 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -32,8 +31,7 @@ * * @author Federico Tomassetti */ -public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { +public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier, AssociableToAST { @Override default boolean isInterface() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java index d4f3261339..bd860f0c38 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.ast.body.MethodDeclaration; @@ -51,5 +50,4 @@ public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration * Is this method static? */ boolean isStatic(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java index 6452ad8153..26e0e2a5d6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.types.ResolvedType; @@ -33,8 +32,8 @@ * * @author Federico Tomassetti */ -public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, - ResolvedTypeParametrizable, HasAccessSpecifier { +public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration, ResolvedTypeParametrizable, HasAccessSpecifier { + /** * The package name of the declaring type. */ @@ -150,7 +149,7 @@ default List getSpecifiedExceptions() { return Collections.emptyList(); } else { List exceptions = new LinkedList<>(); - for (int i=0;i getAncestors() { /** * The list of all the ancestors of the current declaration, direct and indirect. * This list does not contains duplicates with the exact same type parameters. - * For example - * if A inherits from B, and B inherits from C and implements D, and C inherits from E + * For example + * if A inherits from B, and B inherits from C and implements D, and C inherits from E * By default the traversal is depth first */ default List getAllAncestors() { return getAllAncestors(depthFirstFunc); } - + /** * The list of all the ancestors of the current declaration, direct and indirect. * This list does not contains duplicates with the exact same type parameters. - * For example - * if A inherits from B, and B inherits from C and implements D, and C inherits from E + * For example + * if A inherits from B, and B inherits from C and implements D, and C inherits from E * Apply the specified traversal */ default List getAllAncestors(Function> traverser) { return traverser.apply(this); } - + /* * depth first search all ancestors * In the example above, this method returns B,C,E,D @@ -134,7 +125,7 @@ default List getAllAncestors(Function getAllAncestors(Function ancestors = new HashSet<>(); // We want to avoid infinite recursion in case of Object having Object as ancestor if (!rrtd.isJavaLangObject()) { - // init direct ancestors - Deque queuedAncestors = new LinkedList(rrtd.getAncestors()); - ancestors.addAll(queuedAncestors); - while (!queuedAncestors.isEmpty()) { - ResolvedReferenceType queuedAncestor = queuedAncestors.removeFirst(); - queuedAncestor.getTypeDeclaration() - .ifPresent(rtd -> new LinkedHashSet(queuedAncestor.getDirectAncestors()).stream() - .forEach(ancestor -> { - // add this ancestor to the queue (for a deferred search) - queuedAncestors.add(ancestor); - // add this ancestor to the list of ancestors - ancestors.add(ancestor); - })); - } - } - return new ArrayList(ancestors); + // init direct ancestors + Deque queuedAncestors = new LinkedList(rrtd.getAncestors()); + ancestors.addAll(queuedAncestors); + while (!queuedAncestors.isEmpty()) { + ResolvedReferenceType queuedAncestor = queuedAncestors.removeFirst(); + queuedAncestor.getTypeDeclaration().ifPresent(rtd -> new LinkedHashSet(queuedAncestor.getDirectAncestors()).stream().forEach(ancestor -> { + // add this ancestor to the queue (for a deferred search) + queuedAncestors.add(ancestor); + // add this ancestor to the list of ancestors + ancestors.add(ancestor); + })); + } + } + return new ArrayList(ancestors); }; - /// - /// Fields - /// - + // / + // / Fields + // / /** * Note that the type of the field should be expressed using the type variables of this particular type. * Consider for example: @@ -177,9 +165,7 @@ default List getAllAncestors(Function field = this.getAllFields().stream() - .filter(f -> f.getName().equals(name)) - .findFirst(); + Optional field = this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst(); if (field.isPresent()) { return field.get(); } else { @@ -222,9 +208,7 @@ default boolean hasVisibleField(String name) { * Return a list of all fields declared and the inherited ones which are not private. */ default List getVisibleFields() { - return getAllFields().stream() - .filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList()); + return getAllFields().stream().filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); } /** @@ -245,14 +229,12 @@ default List getAllStaticFields() { * Return a list of all the fields declared in this type. */ default List getDeclaredFields() { - return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName() - .equals(getQualifiedName())).collect(Collectors.toList()); + return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName().equals(getQualifiedName())).collect(Collectors.toList()); } - /// - /// Methods - /// - + // / + // / Methods + // / /** * Return a list of all the methods declared in this type declaration. */ @@ -264,10 +246,9 @@ default List getDeclaredFields() { */ Set getAllMethods(); - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * Can we assign instances of the given type to variables having the type defined * by this declaration? @@ -288,10 +269,9 @@ default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { */ boolean isAssignableBy(ResolvedReferenceTypeDeclaration other); - /// - /// Annotations - /// - + // / + // / Annotations + // / /** * Has the type at least one annotation declared having the specified qualified name? */ @@ -304,9 +284,7 @@ default boolean hasAnnotation(String qualifiedName) { if (hasDirectlyAnnotation(qualifiedName)) { return true; } - return getAllAncestors().stream() - .filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()) - .anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); + return getAllAncestors().stream().filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()).anyMatch(it -> it.asReferenceType().getTypeDeclaration().get().hasDirectlyAnnotation(qualifiedName)); } /** @@ -315,10 +293,9 @@ default boolean hasAnnotation(String qualifiedName) { */ boolean isFunctionalInterface(); - /// - /// Type parameters - /// - + // / + // / Type parameters + // / @Override default Optional findTypeParameter(String name) { for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) { @@ -334,7 +311,6 @@ default Optional findTypeParameter(String name List getConstructors(); - /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -344,10 +320,8 @@ default Optional findTypeParameter(String name * @see https://github.com/javaparser/javaparser/issues/2044 */ default boolean isJavaLangObject() { - return this.isClass() - && !isAnonymousClass() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(JAVA_LANG_OBJECT); + return this.isClass() && !isAnonymousClass() && // Consider anonymous classes + hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT); } /** @@ -355,8 +329,6 @@ && hasName() // Consider anonymous classes * @see ResolvedReferenceType#isJavaLangEnum() */ default boolean isJavaLangEnum() { - return this.isEnum() - && getQualifiedName().equals(JAVA_LANG_ENUM); + return this.isEnum() && getQualifiedName().equals(JAVA_LANG_ENUM); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java index 03ade6a6fa..a8edac9ae7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -35,10 +34,9 @@ */ public interface ResolvedTypeDeclaration extends ResolvedDeclaration { - /// - /// Containment - /// - + // / + // / Containment + // / /** * Get the list of types defined inside the current type. */ @@ -51,10 +49,8 @@ default Set internalTypes() { * (Does not include internal types inside internal types). */ default ResolvedReferenceTypeDeclaration getInternalType(String name) { - Optional type = - this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); - return type.orElseThrow(() -> - new UnsolvedSymbolException("Internal type not found: " + name)); + Optional type = this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst(); + return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); } /** @@ -70,10 +66,9 @@ default boolean hasInternalType(String name) { */ Optional containerType(); - /// - /// Misc - /// - + // / + // / Misc + // / /** * Is this the declaration of a class? * Note that an Enum is not considered a Class in this case. @@ -208,5 +203,4 @@ default String getId() { } return qname; } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index 1478b6f4f1..8709effd39 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -18,16 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import com.github.javaparser.resolution.types.ResolvedType; import java.util.List; import java.util.Optional; -import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.resolution.types.ResolvedType; - /** * Declaration of a type parameter. * For example: @@ -46,6 +44,7 @@ public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaratio */ static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List bounds) { return new ResolvedTypeParameterDeclaration() { + @Override public String getName() { return name; @@ -75,7 +74,7 @@ public String getContainerQualifiedName() { public String getContainerId() { return classQName; } - + @Override public ResolvedTypeParametrizable getContainer() { return null; @@ -163,7 +162,7 @@ default String getQualifiedName() { * The ID of the container. See TypeContainer.getId */ String getContainerId(); - + /** * The TypeParametrizable of the container. Can be either a ReferenceTypeDeclaration or a MethodLikeDeclaration */ @@ -227,31 +226,33 @@ default ResolvedType getUpperBound() { } throw new IllegalStateException(); } - + /** * Return true if the Type variable is bounded */ default boolean isBounded() { return !isUnbounded(); } - + /** * Return true if the Type variable is unbounded */ default boolean isUnbounded() { return getBounds().isEmpty(); } - + /* * Return an Object ResolvedType */ ResolvedReferenceType object(); - + /** * A Bound on a Type Parameter. */ class Bound { + private boolean extendsBound; + private ResolvedType type; private Bound(boolean extendsBound, ResolvedType type) { @@ -302,20 +303,18 @@ public boolean isSuper() { @Override public String toString() { - return "Bound{" + - "extendsBound=" + extendsBound + - ", type=" + type + - '}'; + return "Bound{" + "extendsBound=" + extendsBound + ", type=" + type + '}'; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Bound bound = (Bound) o; - - if (extendsBound != bound.extendsBound) return false; + if (extendsBound != bound.extendsBound) + return false; return type != null ? type.equals(bound.type) : bound.type == null; } @@ -326,5 +325,4 @@ public int hashCode() { return result; } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java index d9a27c34a0..b50c35342b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; import java.util.List; @@ -45,5 +44,4 @@ public interface ResolvedTypeParametrizable { default boolean isGeneric() { return !getTypeParameters().isEmpty(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java index d827662bcc..43b18c40fc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java @@ -18,10 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.declarations; - import com.github.javaparser.resolution.types.ResolvedType; /** @@ -35,5 +33,4 @@ public interface ResolvedValueDeclaration extends ResolvedDeclaration { * Type of the declaration. */ ResolvedType getType(); - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java index a7235e1ea3..7e01607e18 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java @@ -18,13 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; -import java.util.Map; - import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import java.util.Map; + /** * Array Type. * @@ -38,19 +37,18 @@ public ResolvedArrayType(ResolvedType baseType) { this.baseType = baseType; } - /// - /// Object methods - /// - + // / + // / Object methods + // / @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedArrayType that = (ResolvedArrayType) o; - - if (!baseType.equals(that.baseType)) return false; - + if (!baseType.equals(that.baseType)) + return false; return true; } @@ -64,10 +62,9 @@ public String toString() { return "ResolvedArrayType{" + baseType + "}"; } - /// - /// Type methods - /// - + // / + // / Type methods + // / @Override public ResolvedArrayType asArrayType() { return this; @@ -91,7 +88,7 @@ public ResolvedType getComponentType() { public boolean isAssignableBy(ResolvedType other) { if (other.isArray()) { if (baseType.isPrimitive() && other.asArrayType().getComponentType().isPrimitive()) { - return baseType.equals(other.asArrayType().getComponentType()); + return baseType.equals(other.asArrayType().getComponentType()); } return baseType.isAssignableBy(other.asArrayType().getComponentType()); } else if (other.isNull()) { @@ -109,14 +106,13 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe return new ResolvedArrayType(baseTypeReplaced); } } - - /// - /// Erasure - /// + + // / + // / Erasure + // / // The erasure of an array type T[] is |T|[]. @Override public ResolvedType erasure() { return new ResolvedArrayType(baseType.erasure()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java index 73c5167cf1..0d3e06905d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -32,6 +31,7 @@ * @author Federico Tomassetti */ public class ResolvedIntersectionType implements ResolvedType { + private List elements; public ResolvedIntersectionType(Collection elements) { @@ -43,11 +43,11 @@ public ResolvedIntersectionType(Collection elements) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedIntersectionType that = (ResolvedIntersectionType) o; - return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } @@ -68,14 +68,11 @@ public boolean isAssignableBy(ResolvedType other) { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map inferredTypes) { - List elementsReplaced = elements.stream() - .map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)) - .collect(Collectors.toList()); + List elementsReplaced = elements.stream().map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes)).collect(Collectors.toList()); if (elementsReplaced.equals(elements)) { return this; } else { return new ResolvedIntersectionType(elementsReplaced); } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java index 455429d88f..02b860499c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java @@ -18,10 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; public class ResolvedLambdaConstraintType implements ResolvedType { + private ResolvedType bound; private ResolvedLambdaConstraintType(ResolvedType bound) { @@ -47,7 +47,7 @@ public ResolvedLambdaConstraintType asConstraintType() { return this; } - public static ResolvedLambdaConstraintType bound(ResolvedType bound){ + public static ResolvedLambdaConstraintType bound(ResolvedType bound) { return new ResolvedLambdaConstraintType(bound); } @@ -58,8 +58,6 @@ public boolean isAssignableBy(ResolvedType other) { @Override public String toString() { - return "LambdaConstraintType{" + - "bound=" + bound + - '}'; + return "LambdaConstraintType{" + "bound=" + bound + '}'; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java index c25b3d5397..bfab10fc3d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import java.util.Arrays; @@ -30,7 +29,6 @@ */ public enum ResolvedPrimitiveType implements ResolvedType { - BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()), SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)), CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()), @@ -40,12 +38,13 @@ public enum ResolvedPrimitiveType implements ResolvedType { FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); - /// - /// Fields - /// - + // / + // / Fields + // / private String name; + private String boxTypeQName; + private List promotionTypes; ResolvedPrimitiveType(String name, String boxTypeQName, List promotionTypes) { @@ -63,19 +62,17 @@ public static ResolvedType byName(String name) { } throw new IllegalArgumentException("Name " + name); } - + /* * Returns an array containing all numeric types */ public static ResolvedPrimitiveType[] getNumericPrimitiveTypes() { - return new ResolvedPrimitiveType[] {BYTE,SHORT,CHAR,INT,LONG,FLOAT,DOUBLE}; + return new ResolvedPrimitiveType[] { BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE }; } @Override public String toString() { - return "PrimitiveTypeUsage{" + - "name='" + name + '\'' + - '}'; + return "PrimitiveTypeUsage{" + "name='" + name + '\'' + '}'; } public ResolvedPrimitiveType asPrimitive() { @@ -133,14 +130,14 @@ public String getBoxTypeQName() { public boolean isNumeric() { return this != BOOLEAN; } - + /** * Is this a boolean type? */ public boolean isBoolean() { return this == BOOLEAN; } - + /* * Binary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2) * If any operand is of a reference type, it is subjected to unboxing conversion (§5.1.8). @@ -149,44 +146,43 @@ public ResolvedPrimitiveType bnp(ResolvedPrimitiveType other) { // If either operand is of type double, the other is converted to double. if (this == ResolvedPrimitiveType.DOUBLE || other == ResolvedPrimitiveType.DOUBLE) { return ResolvedPrimitiveType.DOUBLE; - // Otherwise, if either operand is of type float, the other is converted to float. + // Otherwise, if either operand is of type float, the other is converted to float. } else if (this == ResolvedPrimitiveType.FLOAT || other == ResolvedPrimitiveType.FLOAT) { return ResolvedPrimitiveType.FLOAT; - // Otherwise, if either operand is of type long, the other is converted to long. + // Otherwise, if either operand is of type long, the other is converted to long. } else if (this == ResolvedPrimitiveType.LONG || other == ResolvedPrimitiveType.LONG) { return ResolvedPrimitiveType.LONG; } // Otherwise, both operands are converted to type int. return ResolvedPrimitiveType.INT; } - + /* * Unary primitive promotion (see https://docs.oracle.com/javase/specs/jls/se9/html/jls-5.html#jls-5.6.1) */ public static ResolvedType unp(ResolvedType type) { boolean isUnboxable = type.isReferenceType() && type.asReferenceType().isUnboxable(); - // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). + // If the operand is of compile-time type Byte, Short, Character, or Integer, it is subjected to unboxing conversion (§5.1.8). // The result is then promoted to a value of type int by a widening primitive conversion (§5.1.2) or an identity conversion (§5.1.1). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT})) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.SHORT, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.INT })) { return ResolvedPrimitiveType.INT; } // Otherwise, if the operand is of compile-time type Long, Float, or Double, it is subjected to unboxing conversion (§5.1.8). - if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE})) { + if (isUnboxable && type.asReferenceType().toUnboxedType().get().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.LONG, ResolvedPrimitiveType.FLOAT, ResolvedPrimitiveType.DOUBLE })) { return type.asReferenceType().toUnboxedType().get(); } // Otherwise, if the operand is of compile-time type byte, short, or char, it is promoted to a value of type int by a widening primitive conversion (§5.1.2). - if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] {ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT})) { + if (type.isPrimitive() && type.asPrimitive().in(new ResolvedPrimitiveType[] { ResolvedPrimitiveType.BYTE, ResolvedPrimitiveType.CHAR, ResolvedPrimitiveType.SHORT })) { return ResolvedPrimitiveType.INT; } // Otherwise, a unary numeric operand remains as is and is not converted. return type; } - + /* * Verify if the ResolvedPrimitiveType is in the list of ResolvedPrimitiveType */ public boolean in(ResolvedPrimitiveType... types) { - return Arrays.stream(types).anyMatch(type -> this == type); + return Arrays.stream(types).anyMatch(type -> this == type); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java index 8319a0e303..ffc8d61792 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -18,19 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -43,29 +32,31 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; import com.github.javaparser.utils.Pair; +import java.util.*; +import java.util.stream.Collectors; + /** * A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values * specified for the type parameters. * * @author Federico Tomassetti */ -public abstract class ResolvedReferenceType implements ResolvedType, - ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { - +public abstract class ResolvedReferenceType implements ResolvedType, ResolvedTypeParametrized, ResolvedTypeParameterValueProvider { + protected static String JAVA_LANG_ENUM = java.lang.Enum.class.getCanonicalName(); + protected static String JAVA_LANG_OBJECT = java.lang.Object.class.getCanonicalName(); - // + // // Fields - // - + // protected ResolvedReferenceTypeDeclaration typeDeclaration; + protected ResolvedTypeParametersMap typeParametersMap; - // + // // Constructors - // - + // public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration) { this(typeDeclaration, deriveParams(typeDeclaration)); } @@ -78,9 +69,7 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L throw new IllegalArgumentException("You should use only Classes, Interfaces and enums"); } if (typeArguments.size() > 0 && typeArguments.size() != typeDeclaration.getTypeParameters().size()) { - throw new IllegalArgumentException(String.format( - "expected either zero type arguments or has many as defined in the declaration (%d). Found %d", - typeDeclaration.getTypeParameters().size(), typeArguments.size())); + throw new IllegalArgumentException(String.format("expected either zero type arguments or has many as defined in the declaration (%d). Found %d", typeDeclaration.getTypeParameters().size(), typeArguments.size())); } ResolvedTypeParametersMap.Builder typeParametersMapBuilder = new ResolvedTypeParametersMap.Builder(); for (int i = 0; i < typeArguments.size(); i++) { @@ -90,20 +79,20 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L this.typeDeclaration = typeDeclaration; } - // + // // Public Object methods - // - + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedReferenceType that = (ResolvedReferenceType) o; - - if (!typeDeclaration.equals(that.typeDeclaration)) return false; - if (!typeParametersMap.equals(that.typeParametersMap)) return false; - + if (!typeDeclaration.equals(that.typeDeclaration)) + return false; + if (!typeParametersMap.equals(that.typeParametersMap)) + return false; return true; } @@ -116,33 +105,28 @@ public int hashCode() { @Override public String toString() { - return "ReferenceType{" + getQualifiedName() + - ", typeParametersMap=" + typeParametersMap + - '}'; + return "ReferenceType{" + getQualifiedName() + ", typeParametersMap=" + typeParametersMap + '}'; } - /// - /// Relation with other types - /// - + // / + // / Relation with other types + // / @Override public final boolean isReferenceType() { return true; } - /// - /// Downcasting - /// - + // / + // / Downcasting + // / @Override public ResolvedReferenceType asReferenceType() { return this; } - /// - /// Naming - /// - + // / + // / Naming + // / @Override public String describe() { StringBuilder sb = new StringBuilder(); @@ -153,30 +137,25 @@ public String describe() { } if (!typeParametersMap().isEmpty()) { sb.append("<"); - sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream() - .map(tp -> typeParametersMap().getValue(tp).describe()) - .collect(Collectors.toList()))); + sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream().map(tp -> typeParametersMap().getValue(tp).describe()).collect(Collectors.toList()))); sb.append(">"); } return sb.toString(); } - /// - /// TypeParameters - /// - + // / + // / TypeParameters + // / /** * Execute a transformation on all the type parameters of this element. */ public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer); @Override - public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, - Map inferredTypes) { + public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map inferredTypes) { if (replaced == null) { throw new IllegalArgumentException(); } - ResolvedReferenceType result = this; int i = 0; for (ResolvedType tp : this.typeParametersValues()) { @@ -193,34 +172,30 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe } i++; } - List values = result.typeParametersValues(); // FIXME if (values.contains(tpToReplace)) { int index = values.indexOf(tpToReplace); values.set(index, replaced); - if(result.getTypeDeclaration().isPresent()) { + if (result.getTypeDeclaration().isPresent()) { return create(result.getTypeDeclaration().get(), values); } } - return result; } - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * This method checks if ThisType t = new OtherType() would compile. */ @Override public abstract boolean isAssignableBy(ResolvedType other); - /// - /// Ancestors - /// - + // / + // / Ancestors + // / /** * Return all ancestors, that means all superclasses and interfaces. * This list should always include Object (unless this is a reference to Object). @@ -244,23 +219,16 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe public abstract List getDirectAncestors(); public final List getAllInterfacesAncestors() { - return getAllAncestors().stream() - .filter(it -> it.getTypeDeclaration().isPresent()) - .filter(it -> it.getTypeDeclaration().get().isInterface()) - .collect(Collectors.toList()); + return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isInterface()).collect(Collectors.toList()); } public final List getAllClassesAncestors() { - return getAllAncestors().stream() - .filter(it -> it.getTypeDeclaration().isPresent()) - .filter(it -> it.getTypeDeclaration().get().isClass()) - .collect(Collectors.toList()); + return getAllAncestors().stream().filter(it -> it.getTypeDeclaration().isPresent()).filter(it -> it.getTypeDeclaration().get().isClass()).collect(Collectors.toList()); } - /// - /// Type parameters - /// - + // / + // / Type parameters + // / /** * Get the type associated with the type parameter with the given name. * It returns Optional.empty unless the type declaration declares a type parameter with the given name. @@ -301,10 +269,9 @@ public ResolvedTypeParametersMap typeParametersMap() { return typeParametersMap; } - /// - /// Other methods introduced by ReferenceType - /// - + // / + // / Other methods introduced by ReferenceType + // / /** * Corresponding TypeDeclaration */ @@ -376,10 +343,10 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty if (typeParameterDeclaration.declaredOnMethod()) { throw new IllegalArgumentException(); } - if(!this.getTypeDeclaration().isPresent()) { - return Optional.empty(); // TODO: Consider IllegalStateException or similar + if (!this.getTypeDeclaration().isPresent()) { + // TODO: Consider IllegalStateException or similar + return Optional.empty(); } - String typeId = this.getTypeDeclaration().get().getId(); if (typeId.equals(typeParameterDeclaration.getContainerId())) { return Optional.of(this.typeParametersMap().getValue(typeParameterDeclaration)); @@ -403,17 +370,14 @@ public Optional typeParamValue(ResolvedTypeParameterDeclaration ty * that have been overwritten. */ public List getAllMethods() { - if(!this.getTypeDeclaration().isPresent()) { - return new ArrayList<>(); // empty list -- consider IllegalStateException or similar + if (!this.getTypeDeclaration().isPresent()) { + // empty list -- consider IllegalStateException or similar + return new ArrayList<>(); } - // Get the methods declared directly on this. - List allMethods = new LinkedList<>( - this.getTypeDeclaration().get().getDeclaredMethods() - ); + List allMethods = new LinkedList<>(this.getTypeDeclaration().get().getDeclaredMethods()); // Also get methods inherited from ancestors. getDirectAncestors().forEach(a -> allMethods.addAll(a.getAllMethods())); - return allMethods; } @@ -422,32 +386,22 @@ public List getAllMethods() { * type plus all declared fields which are not private. */ public List getAllFieldsVisibleToInheritors() { - List res = new LinkedList<>(this.getDeclaredFields().stream() - .filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList())); - - getDirectAncestors().forEach(a -> - res.addAll(a.getAllFieldsVisibleToInheritors())); - + List res = new LinkedList<>(this.getDeclaredFields().stream().filter(f -> f.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList())); + getDirectAncestors().forEach(a -> res.addAll(a.getAllFieldsVisibleToInheritors())); return res; } public List getAllMethodsVisibleToInheritors() { - return this.getAllMethods().stream() - .filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE) - .collect(Collectors.toList()); + return this.getAllMethods().stream().filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE).collect(Collectors.toList()); } - // + // // Protected methods - // - + // protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParameters); protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap) { - return create(typeDeclaration, typeDeclaration.getTypeParameters().stream() - .map(typeParametersMap::getValue) - .collect(Collectors.toList())); + return create(typeDeclaration, typeDeclaration.getTypeParameters().stream().map(typeParametersMap::getValue).collect(Collectors.toList())); } protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration); @@ -489,15 +443,11 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) } } else { if (thisParam instanceof ResolvedTypeVariable && otherParam instanceof ResolvedTypeVariable) { - List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds() - .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) - .collect(Collectors.toList()); - List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds() - .stream().map(ResolvedTypeParameterDeclaration.Bound::getType) - .collect(Collectors.toList()); + List thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); + List otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds().stream().map(ResolvedTypeParameterDeclaration.Bound::getType).collect(Collectors.toList()); return thisBounds.size() == otherBounds.size() && otherBounds.containsAll(thisBounds); } else if (!(thisParam instanceof ResolvedTypeVariable) && otherParam instanceof ResolvedTypeVariable) { - return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable)otherParam); + return compareConsideringVariableTypeParameters(thisParam, (ResolvedTypeVariable) otherParam); } else if (thisParam instanceof ResolvedTypeVariable && !(otherParam instanceof ResolvedTypeVariable)) { return compareConsideringVariableTypeParameters(otherParam, (ResolvedTypeVariable) thisParam); } @@ -510,22 +460,18 @@ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) return false; } - // + // // Private methods - // - + // private boolean compareConsideringVariableTypeParameters(ResolvedType referenceType, ResolvedTypeVariable typeVariable) { // verify if the ResolvedTypeVariable has only one type variable and the bound is - // not a reference type with a bound parameter + // not a reference type with a bound parameter // for example EnumSet noneOf(Class elementType) List bounds = typeVariable.asTypeVariable().asTypeParameter().getBounds(); if (bounds.size() == 1) { ResolvedType boundType = bounds.get(0).getType(); - boolean hasTypeParameter = boundType.isReferenceType() - && !boundType.asReferenceType().typeParametersMap.isEmpty(); - return hasTypeParameter - ? compareConsideringTypeParameters(boundType.asReferenceType()) - : boundType.isAssignableBy(referenceType); + boolean hasTypeParameter = boundType.isReferenceType() && !boundType.asReferenceType().typeParametersMap.isEmpty(); + return hasTypeParameter ? compareConsideringTypeParameters(boundType.asReferenceType()) : boundType.isAssignableBy(referenceType); } return false; } @@ -543,7 +489,6 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap); - /** * We don't make this _ex_plicit in the data representation because that would affect codegen * and make everything generate like {@code } instead of {@code } @@ -553,9 +498,8 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration * @see https://github.com/javaparser/javaparser/issues/2044 */ public boolean isJavaLangObject() { - return this.isReferenceType() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(JAVA_LANG_OBJECT); + return this.isReferenceType() && // Consider anonymous classes + hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT); } /** @@ -563,16 +507,13 @@ && hasName() // Consider anonymous classes * @see ResolvedReferenceTypeDeclaration#isJavaLangEnum() */ public boolean isJavaLangEnum() { - return this.isReferenceType() - && hasName() // Consider anonymous classes - && getQualifiedName().equals(JAVA_LANG_ENUM); - } - - - /// - /// boxing/unboxing capability - /// - + return this.isReferenceType() && // Consider anonymous classes + hasName() && getQualifiedName().equals(JAVA_LANG_ENUM); + } + + // / + // / boxing/unboxing capability + // / /* * Returns true if the reference type can be unboxed to the primitive type * For example : Integer to int @@ -580,7 +521,7 @@ && hasName() // Consider anonymous classes public boolean isUnboxable() { return Arrays.stream(ResolvedPrimitiveType.values()).anyMatch(pt -> getQualifiedName().equals(pt.getBoxTypeQName())); } - + /* * Returns true if the reference type can be unboxed to the specified primitive type * For example : Integer to int @@ -588,41 +529,35 @@ public boolean isUnboxable() { public boolean isUnboxableTo(ResolvedPrimitiveType primitiveType) { return primitiveType.getBoxTypeQName().equals(this.asReferenceType().describe()); } - + /* * Returns the optional corresponding primitive type */ public Optional toUnboxedType() { return Arrays.stream(ResolvedPrimitiveType.values()).filter(pt -> this.asReferenceType().getQualifiedName().equals(pt.getBoxTypeQName())).findFirst(); } - - - /// - /// Erasure - /// + + // / + // / Erasure + // / // The erasure of a parameterized type (§4.5) G is |G|. @Override public ResolvedType erasure() { - if (!typeDeclaration.isGeneric()) return this; + if (!typeDeclaration.isGeneric()) + return this; return create(typeDeclaration, erasureOfParamaters(typeParametersMap)); } - + private List erasureOfParamaters(ResolvedTypeParametersMap typeParametersMap) { List erasedParameters = new ArrayList(); if (!typeParametersMap.isEmpty()) { // add erased type except java.lang.object - erasedParameters.addAll( - typeParametersMap.getTypes().stream() - .filter(type -> !type.isReferenceType()) - .map(type -> type.erasure()) - .filter(erasedType -> !(isJavaObject(erasedType))) - .collect(Collectors.toList())); + erasedParameters.addAll(typeParametersMap.getTypes().stream().filter(type -> !type.isReferenceType()).map(type -> type.erasure()).filter(erasedType -> !(isJavaObject(erasedType))).collect(Collectors.toList())); } return erasedParameters; } - + private boolean isJavaObject(ResolvedType rt) { return rt.isReferenceType() && rt.asReferenceType().isJavaLangObject(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java index 6500d6da0e..8c982e3107 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java @@ -18,16 +18,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; - /** *

A resolved type.

*
    @@ -50,10 +49,9 @@ */ public interface ResolvedType { - /// - /// Relation with other types - /// - + // / + // / Relation with other types + // / /** * @return true, if this type represent an array - otherwise false. */ @@ -104,7 +102,9 @@ default boolean isReference() { /** * Is this a lambda constraint type? */ - default boolean isConstraint() { return false; } + default boolean isConstraint() { + return false; + } /** * Can this be seen as a ReferenceTypeUsage? @@ -125,15 +125,14 @@ default boolean isTypeVariable() { default boolean isWildcard() { return false; } - + default boolean isInferenceVariable() { return false; } - /// - /// Downcasting - /// - + // / + // / Downcasting + // / default ResolvedArrayType asArrayType() { throw new UnsupportedOperationException(String.format("%s is not an Array", this)); } @@ -166,16 +165,14 @@ default ResolvedUnionType asUnionType() { throw new UnsupportedOperationException(String.format("%s is not a union type", this)); } - /// - /// Naming - /// - + // / + // / Naming + // / String describe(); - /// - /// TypeParameters - /// - + // / + // / TypeParameters + // / /** * Replace all variables referring to the given TypeParameter with the given value. * By replacing these values I could also infer some type equivalence. @@ -199,42 +196,38 @@ default boolean mention(List typeParameters) { throw new UnsupportedOperationException(this.getClass().getCanonicalName()); } - /// - /// Assignability - /// - + // / + // / Assignability + // / /** * This method checks if ThisType t = new OtherType() would compile. */ boolean isAssignableBy(ResolvedType other); - + /* * Returns true if the ResolvedType is a numeric */ default boolean isNumericType() { - return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt-> rpt.isAssignableBy(this)); + return Arrays.stream(ResolvedPrimitiveType.getNumericPrimitiveTypes()).anyMatch(rpt -> rpt.isAssignableBy(this)); } - - /// - /// Erasure - /// + + // / + // / Erasure + // / // Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that - /// are never parameterized types or type variables). We write |T| for the erasure of type T. The erasure mapping - /// is defined as follows: - // + // / are never parameterized types or type variables). We write |T| for the erasure of type T. The erasure mapping + // / is defined as follows: + // // The erasure of a parameterized type (§4.5) G is |G|. - // + // // The erasure of a nested type T.C is |T|.C. - // + // // The erasure of an array type T[] is |T|[]. - // + // // The erasure of a type variable (§4.4) is the erasure of its leftmost bound. - // + // // The erasure of every other type is the type itself. - default ResolvedType erasure() { return this; } - - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java index b6e340d657..71033f16ac 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; /** @@ -26,5 +25,6 @@ */ @FunctionalInterface public interface ResolvedTypeTransformer { + ResolvedType transform(ResolvedType type); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java index 65beafd4c9..6808effa47 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -18,14 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; + import java.util.List; import java.util.Map; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; - /** * From JLS 4.4: A type variable is introduced by the declaration of a type parameter of a generic class, * interface, method, or constructor (§8.1.2, §9.1.2, §8.4.4, §8.8.4). @@ -51,15 +50,17 @@ public String qualifiedName() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedTypeVariable that = (ResolvedTypeVariable) o; - - if (!typeParameter.getName().equals(that.typeParameter.getName())) return false; - if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false; - if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false; - + if (!typeParameter.getName().equals(that.typeParameter.getName())) + return false; + if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) + return false; + if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) + return false; return true; } @@ -80,7 +81,7 @@ public boolean isPrimitive() { @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map inferredTypes) { - if(tpToBeReplaced.getName().equals(this.typeParameter.getName())){ + if (tpToBeReplaced.getName().equals(this.typeParameter.getName())) { inferredTypes.put(this.asTypeParameter(), replaced); return replaced; } else { @@ -126,12 +127,12 @@ public boolean isAssignableBy(ResolvedType other) { public boolean mention(List typeParameters) { return typeParameters.contains(typeParameter); } - - /// - /// Erasure - /// + + // / + // / Erasure + // / // The erasure of a type variable (§4.4) is the erasure of its leftmost bound. - // + // @Override public ResolvedType erasure() { if (typeParameter.isBounded()) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java index 6e53501247..304c895612 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import java.util.*; @@ -30,6 +29,7 @@ * @author Federico Tomassetti */ public class ResolvedUnionType implements ResolvedType { + private List elements; public ResolvedUnionType(List elements) { @@ -40,24 +40,21 @@ public ResolvedUnionType(List elements) { } public Optional getCommonAncestor() { - Optional> reduce = elements.stream() - .map(ResolvedType::asReferenceType) - .map(ResolvedReferenceType::getAllAncestors) - .reduce((a, b) -> { - ArrayList common = new ArrayList<>(a); - common.retainAll(b); - return common; - }); + Optional> reduce = elements.stream().map(ResolvedType::asReferenceType).map(ResolvedReferenceType::getAllAncestors).reduce((a, b) -> { + ArrayList common = new ArrayList<>(a); + common.retainAll(b); + return common; + }); return reduce.orElse(new ArrayList<>()).stream().findFirst(); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ResolvedUnionType that = (ResolvedUnionType) o; - return new HashSet<>(elements).equals(new HashSet<>(that.elements)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java index 7c5fb1d04b..3b9c427228 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; /** @@ -27,6 +26,7 @@ * @author Federico Tomassetti */ public class ResolvedVoidType implements ResolvedType { + public static final ResolvedType INSTANCE = new ResolvedVoidType(); private ResolvedVoidType() { @@ -43,12 +43,12 @@ public boolean isAssignableBy(ResolvedType other) { // """ // Note that the Java programming language does not allow a "cast to void" - void is not a type - so the // traditional C trick of writing an expression statement such as: - // + // // (void)... ; // incorrect! - // + // // does not work. // """ - // + // // In short, nothing can be assign to "void". return false; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java index ac5fa55669..cb887ad7aa 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -40,6 +39,7 @@ public class ResolvedWildcard implements ResolvedType { public static ResolvedWildcard UNBOUNDED = new ResolvedWildcard(null, null); private BoundType type; + private ResolvedType boundedType; private ResolvedWildcard(BoundType type, ResolvedType boundedType) { @@ -63,10 +63,7 @@ public static ResolvedWildcard extendsBound(ResolvedType type) { @Override public String toString() { - return "WildcardUsage{" + - "type=" + type + - ", boundedType=" + boundedType + - '}'; + return "WildcardUsage{" + "type=" + type + ", boundedType=" + boundedType + '}'; } public boolean isWildcard() { @@ -79,14 +76,15 @@ public ResolvedWildcard asWildcard() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ResolvedWildcard)) return false; - + if (this == o) + return true; + if (!(o instanceof ResolvedWildcard)) + return false; ResolvedWildcard that = (ResolvedWildcard) o; - - if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) return false; - if (type != that.type) return false; - + if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) + return false; + if (type != that.type) + return false; return true; } @@ -132,7 +130,7 @@ public ResolvedType getBoundedType() { @Override public boolean isAssignableBy(ResolvedType other) { if (boundedType == null) { - //return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); + // return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName()); return false; } else if (type == BoundType.SUPER) { return boundedType.isAssignableBy(other); @@ -176,8 +174,7 @@ public boolean isLowerBounded() { } public enum BoundType { - SUPER, - EXTENDS - } + SUPER, EXTENDS + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java index 96b8f52703..7a4b2ca887 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -52,7 +51,6 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { } } } - if (type.isWildcard() && type.asWildcard().isBounded()) { if (type.asWildcard().isExtends()) { return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); @@ -60,11 +58,9 @@ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); } } - if (type.isReferenceType()) { type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType); } - return type; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java index 26dd75e219..7357af672c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -35,7 +34,9 @@ public class ResolvedTypeParametersMap { public static class Builder { + private Map nameToValue; + private Map nameToDeclaration; public Builder() { @@ -43,8 +44,7 @@ public Builder() { nameToDeclaration = new HashMap<>(); } - private Builder(Map nameToValue, - Map nameToDeclaration) { + private Builder(Map nameToValue, Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -55,8 +55,7 @@ public ResolvedTypeParametersMap build() { return new ResolvedTypeParametersMap(nameToValue, nameToDeclaration); } - public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, - ResolvedType value) { + public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, ResolvedType value) { // TODO: we shouldn't just silently overwrite existing types! String qualifiedName = typeParameter.getQualifiedName(); nameToValue.put(qualifiedName, value); @@ -67,13 +66,12 @@ public Builder setValue(ResolvedTypeParameterDeclaration typeParameter, @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ResolvedTypeParametersMap)) return false; - + if (this == o) + return true; + if (!(o instanceof ResolvedTypeParametersMap)) + return false; ResolvedTypeParametersMap that = (ResolvedTypeParametersMap) o; - return nameToValue.equals(that.nameToValue) && nameToDeclaration.equals(that.nameToDeclaration); - } @Override @@ -83,20 +81,18 @@ public int hashCode() { @Override public String toString() { - return "TypeParametersMap{" + - "nameToValue=" + nameToValue + - '}'; + return "TypeParametersMap{" + "nameToValue=" + nameToValue + '}'; } private Map nameToValue; + private Map nameToDeclaration; public static ResolvedTypeParametersMap empty() { return new Builder().build(); } - private ResolvedTypeParametersMap(Map nameToValue, - Map nameToDeclaration) { + private ResolvedTypeParametersMap(Map nameToValue, Map nameToDeclaration) { this.nameToValue = new HashMap<>(); this.nameToValue.putAll(nameToValue); this.nameToDeclaration = new HashMap<>(); @@ -120,11 +116,11 @@ public Optional getValueBySignature(String signature) { } } - public List getNames(){ + public List getNames() { return new ArrayList<>(nameToValue.keySet()); } - public List getTypes(){ + public List getTypes() { return new ArrayList<>(nameToValue.values()); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java index a9c9f797f4..8026582e9e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.resolution.types.parametrization; /** @@ -27,5 +26,6 @@ * @author Federico Tomassetti */ public interface ResolvedTypeParametrized { + ResolvedTypeParametersMap typeParametersMap(); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java index 0abad05da9..32020f1c72 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java @@ -18,13 +18,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.util.HashMap; import java.util.Map; public class ClassUtils { + /** * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java index 8e704061f0..2774fe9edc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.io.File; @@ -33,6 +32,7 @@ * Utilities that can be useful when generating code. */ public final class CodeGenerationUtils { + private CodeGenerationUtils() { } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java index a169393837..a1d42e8f37 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CollectionStrategy.java @@ -18,21 +18,20 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; -import java.io.IOException; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.util.Optional; - import com.github.javaparser.JavaParser; import com.github.javaparser.ParseProblemException; import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.util.Optional; + /** * A strategy for discovering the structure of a project. * Implementations could read a pom.xml, a Gradle build file, a makefile... @@ -47,8 +46,6 @@ default Optional getRoot(Path file) { try { final JavaParser javaParser = new JavaParser(getParserConfiguration()); final ParseResult parseResult = javaParser.parse(file); - - if (parseResult.isSuccessful()) { if (parseResult.getResult().isPresent()) { final Optional storage = parseResult.getResult().flatMap(CompilationUnit::getStorage); diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java index ea84d25acd..287ad7415a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/LineSeparator.java @@ -13,6 +13,7 @@ * @see https://github.com/javaparser/javaparser/issues/2647 */ public enum LineSeparator { + /** * The CR {@code \r} line ending is the default line separator for classic MacOS */ @@ -28,13 +29,7 @@ public enum LineSeparator { /** * This line ending is set to whatever the host system's line separator is */ - SYSTEM( - System.getProperty("line.separator"), - "SYSTEM : (" + System.getProperty("line.separator") - .replace("\r", "\\r") - .replace("\n", "\\n") + - ")" - ), + SYSTEM(System.getProperty("line.separator"), "SYSTEM : (" + System.getProperty("line.separator").replace("\r", "\\r").replace("\n", "\\n") + ")"), /** * The ARBITRARY line ending can be used where we do not care about the line separator, * only that we use the same one consistently @@ -56,6 +51,7 @@ public enum LineSeparator { NONE("", "NONE"); private final String text; + private final String description; LineSeparator(String text, String description) { @@ -75,7 +71,6 @@ public static LineSeparator detect(String string) { int countCr = count(string, "\r"); int countLf = count(string, "\n"); int countCrLf = count(string, "\r\n"); - return getLineEnding(countCr, countLf, countCrLf); } @@ -84,7 +79,6 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (noLineEndings) { return NONE; } - boolean crOnly = countCr > 0 && countLf == 0 && countCrLf == 0; if (crOnly) { return CR; @@ -93,13 +87,11 @@ public static LineSeparator getLineEnding(int countCr, int countLf, int countCrL if (lfOnly) { return LF; } - // Note that wherever \r\n are found, there will also be an equal number of \r and \n characters found. boolean crLfOnly = countCr == countLf && countLf == countCrLf; if (crLfOnly) { return CRLF; } - // Not zero line endings, and not a single line ending, thus is mixed. return MIXED; } @@ -148,10 +140,7 @@ public boolean isStandardEol() { } public String asEscapedString() { - String result = text - .replace("\r", "\\r") - .replace("\n", "\\n"); - + String result = text.replace("\r", "\\r").replace("\n", "\\n"); return result; } @@ -161,14 +150,13 @@ public String asRawString() { // TODO: Determine if this should be used within TokenTypes.java -- thus leaving this as private for now. private Optional asJavaTokenKind() { - if(this == CR) { + if (this == CR) { return Optional.of(JavaToken.Kind.OLD_MAC_EOL); - } else if(this == LF) { + } else if (this == LF) { return Optional.of(JavaToken.Kind.UNIX_EOL); - } else if(this == CRLF) { + } else if (this == CRLF) { return Optional.of(JavaToken.Kind.WINDOWS_EOL); } - return Optional.empty(); } @@ -176,5 +164,4 @@ private Optional asJavaTokenKind() { public String toString() { return asRawString(); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java index 69560a36e4..3c1d7fa6aa 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import java.io.IOException; @@ -34,10 +33,12 @@ * See a blog about this */ public class Log { + /** * This adapter logs to standard out and standard error. */ public static class StandardOutStandardErrorAdapter implements Adapter { + @Override public void info(Supplier messageSupplier) { System.out.println(messageSupplier.get()); @@ -64,7 +65,8 @@ public void error(Supplier throwableSupplier, Supplier messag } private void printStackTrace(Throwable throwable) { - try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { + try (StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw)) { throwable.printStackTrace(pw); trace(sw::toString); } catch (IOException e) { @@ -77,6 +79,7 @@ private void printStackTrace(Throwable throwable) { * This adapter logs nothing. */ public static class SilentAdapter implements Adapter { + @Override public void info(Supplier messageSupplier) { } @@ -129,7 +132,6 @@ private static Supplier makeFormattingSupplier(String format, Supplier type of object b. */ public class Pair { + public final A a; + public final B b; public Pair(A a, B b) { @@ -42,14 +43,15 @@ public Pair(A a, B b) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Pair pair = (Pair) o; - - if (!Objects.equals(a, pair.a)) return false; - if (!Objects.equals(b, pair.b)) return false; - + if (!Objects.equals(a, pair.a)) + return false; + if (!Objects.equals(b, pair.b)) + return false; return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java index ce6abb1acc..938db6a2fb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ParserCollectionStrategy.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; @@ -60,7 +59,9 @@ public ProjectRoot collect(Path path) { ProjectRoot projectRoot = new ProjectRoot(path, parserConfiguration); try { Files.walkFileTree(path, new SimpleFileVisitor() { + Path current_root; + final PathMatcher javaMatcher = getPathMatcher("glob:**.java"); @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java index 313030ab09..c072d8a384 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.Position; @@ -81,10 +80,8 @@ private static int compare(Node a, Node b, boolean ignoringAnnotations) { return signLine; } } - Position aBegin = a.getBegin().get(); Position bBegin = b.getBegin().get(); - int signLine = signum(aBegin.line - bBegin.line); if (signLine == 0) { return signum(aBegin.column - bBegin.column); @@ -110,7 +107,6 @@ private static int beginLineWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.line; } - private static int beginColumnWithoutConsideringAnnotation(Node node) { return firstNonAnnotationNode(node).getRange().get().begin.column; } @@ -120,11 +116,7 @@ private static Node firstNonAnnotationNode(Node node) { if (node instanceof ClassOrInterfaceDeclaration) { // Modifiers appear before the class name -- ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.hasRange()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.hasRange()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getName(); } else { @@ -133,11 +125,7 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof MethodDeclaration) { // Modifiers appear before the class name -- MethodDeclaration casted = (MethodDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.hasRange()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.hasRange()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getType(); } else { @@ -146,11 +134,7 @@ private static Node firstNonAnnotationNode(Node node) { } else if (node instanceof FieldDeclaration) { // Modifiers appear before the class name -- FieldDeclaration casted = (FieldDeclaration) node; - Modifier earliestModifier = casted.getModifiers() - .stream() - .filter(modifier -> modifier.hasRange()) - .min(Comparator.comparing(o -> o.getRange().get().begin)) - .orElse(null); + Modifier earliestModifier = casted.getModifiers().stream().filter(modifier -> modifier.hasRange()).min(Comparator.comparing(o -> o.getRange().get().begin)).orElse(null); if (earliestModifier == null) { return casted.getVariable(0).getType(); } else { @@ -161,7 +145,6 @@ private static Node firstNonAnnotationNode(Node node) { } } - /** * Compare the position of two nodes. Optionally include annotations within the range checks. * This method takes into account whether the nodes are within the same compilation unit. @@ -179,38 +162,29 @@ public static boolean nodeContains(Node container, Node other, boolean ignoringA if (!other.hasRange()) { throw new IllegalArgumentException("Cannot compare the positions of nodes if contained node does not have a range."); } - -// // FIXME: Not all nodes seem to have the compilation unit available? -// if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { -// // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), -// // ... or both not within a CU (i.e. both are Optional.empty()) -// return false; -// } - + // // FIXME: Not all nodes seem to have the compilation unit available? + // if (!Objects.equals(container.findCompilationUnit(), other.findCompilationUnit())) { + // // Allow the check to complete if they are both within a known CU (i.e. the CUs are the same), + // // ... or both not within a CU (i.e. both are Optional.empty()) + // return false; + // } final boolean nodeCanHaveAnnotations = container instanceof NodeWithAnnotations; -// final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; + // final boolean hasAnnotations = PositionUtils.getLastAnnotation(container) != null; if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) { // No special consideration required - perform simple range check. return container.containsWithinRange(other); } - if (!container.containsWithinRange(other)) { return false; } - if (!nodeCanHaveAnnotations) { return true; } - // If the node is contained, but it comes immediately after the annotations, // let's not consider it contained (i.e. it must be "strictly contained"). Node nodeWithoutAnnotations = firstNonAnnotationNode(container); - Range rangeWithoutAnnotations = container.getRange().get() - .withBegin(nodeWithoutAnnotations.getBegin().get()); - return rangeWithoutAnnotations -// .contains(other.getRange().get()); - .strictlyContains(other.getRange().get()); - + Range rangeWithoutAnnotations = container.getRange().get().withBegin(nodeWithoutAnnotations.getBegin().get()); + return rangeWithoutAnnotations.// .contains(other.getRange().get()); + strictlyContains(other.getRange().get()); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java index 6c9921a91d..acc9edfd8f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ProjectRoot.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ParserConfiguration; @@ -40,7 +39,9 @@ public class ProjectRoot { private final Path root; + private final Map cache = new ConcurrentHashMap<>(); + private final ParserConfiguration parserConfiguration; public ProjectRoot(Path root) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java index 9f1581b00e..97a1780494 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; /** @@ -27,16 +26,19 @@ *

    Java 8 offers the very nice Collectors.joining(String, String, String) which does the same thing. */ public class SeparatedItemStringBuilder { + private final String separator; + private final String postfix; + private boolean hasItems = false; + private StringBuilder builder; public SeparatedItemStringBuilder(String prefix, String separator, String postfix) { builder = new StringBuilder(prefix); this.separator = separator; this.postfix = postfix; - } /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java index f2161bf847..4dfe4cc854 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java @@ -18,18 +18,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageAbsolutePath; -import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; -import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.nio.file.FileVisitResult.CONTINUE; -import static java.nio.file.FileVisitResult.SKIP_SUBTREE; -import static java.nio.file.FileVisitResult.TERMINATE; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseProblemException; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.printer.DefaultPrettyPrinter; import java.io.IOException; import java.nio.charset.Charset; @@ -48,12 +44,11 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.printer.DefaultPrettyPrinter; +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.CodeGenerationUtils.*; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.nio.file.FileVisitResult.*; /** * A collection of Java source files located in one directory and its subdirectories on the file system. The root directory @@ -66,9 +61,12 @@ *

*/ public class SourceRoot { + @FunctionalInterface public interface Callback { + enum Result { + SAVE, DONT_SAVE, TERMINATE } @@ -81,9 +79,13 @@ enum Result { } private final Path root; + private final Map> cache = new ConcurrentHashMap<>(); + private ParserConfiguration parserConfiguration = new ParserConfiguration(); + private Function printer = new DefaultPrettyPrinter()::print; + private static final Pattern JAVA_IDENTIFIER = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*"); /** @@ -126,8 +128,7 @@ public ParseResult tryToParse(String startPackage, String filen } final Path path = root.resolve(relativePath); Log.trace("Parsing %s", () -> path); - final ParseResult result = new JavaParser(configuration) - .parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); + final ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(path, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(path, configuration.getCharacterEncoding())); cache.put(relativePath, result); return result; @@ -158,6 +159,7 @@ public List> tryToParse(String startPackage) throws logPackage(startPackage); final Path path = packageAbsolutePath(root, startPackage); Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && file.toString().endsWith(".java")) { @@ -175,7 +177,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th return getCache(); } - boolean isSensibleDirectoryToEnter(Path dir) throws IOException { + boolean isSensibleDirectoryToEnter(Path dir) throws IOException { final String dirToEnter = dir.getFileName().toString(); // Don't enter directories that cannot be packages. final boolean directoryIsAValidJavaIdentifier = JAVA_IDENTIFIER.matcher(dirToEnter).matches(); @@ -218,10 +220,7 @@ public List> tryToParseParallelized(String startPac if (!attrs.isDirectory() && file.toString().endsWith(".java")) { Path relative = root.relativize(file.getParent()); try { - tryToParse( - relative.toString(), - file.getFileName().toString(), - parserConfiguration); + tryToParse(relative.toString(), file.getFileName().toString(), parserConfiguration); } catch (IOException e) { Log.error(e); } @@ -274,7 +273,7 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur Log.trace("Parsing %s", () -> localPath); ParseResult result = new JavaParser(configuration).parse(COMPILATION_UNIT, provider(absolutePath, configuration.getCharacterEncoding())); result.getResult().ifPresent(cu -> cu.setStorage(absolutePath, configuration.getCharacterEncoding())); - switch (callback.process(localPath, absolutePath, result)) { + switch(callback.process(localPath, absolutePath, result)) { case SAVE: result.getResult().ifPresent(cu -> save(cu, absolutePath)); case DONT_SAVE: @@ -293,8 +292,7 @@ private FileVisitResult callback(Path absolutePath, ParserConfiguration configur * @param startPackage The package containing the file * @param filename The name of the file */ - public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback - callback) throws IOException { + public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, Callback callback) throws IOException { assertNotNull(startPackage); assertNotNull(filename); assertNotNull(configuration); @@ -326,6 +324,7 @@ public SourceRoot parse(String startPackage, ParserConfiguration configuration, final Path path = packageAbsolutePath(root, startPackage); if (Files.exists(path)) { Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) { @@ -423,10 +422,7 @@ public SourceRoot add(String startPackage, String filename, CompilationUnit comp assertNotNull(compilationUnit); Log.trace("Adding new file %s.%s", () -> startPackage, () -> filename); final Path path = fileInPackageRelativePath(startPackage, filename); - final ParseResult parseResult = new ParseResult<>( - compilationUnit, - new ArrayList<>(), - null); + final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); cache.put(path, parseResult); return this; } @@ -440,10 +436,7 @@ public SourceRoot add(CompilationUnit compilationUnit) { if (compilationUnit.getStorage().isPresent()) { final Path path = compilationUnit.getStorage().get().getPath(); Log.trace("Adding new file %s", () -> path); - final ParseResult parseResult = new ParseResult<>( - compilationUnit, - new ArrayList<>(), - null); + final ParseResult parseResult = new ParseResult<>(compilationUnit, new ArrayList<>(), null); cache.put(path, parseResult); } else { throw new AssertionError("Files added with this method should have their path set."); @@ -527,10 +520,7 @@ public List> getCache() { * added manually. */ public List getCompilationUnits() { - return cache.values().stream() - .filter(ParseResult::isSuccessful) - .map(p -> p.getResult().get()) - .collect(Collectors.toList()); + return cache.values().stream().filter(ParseResult::isSuccessful).map(p -> p.getResult().get()).collect(Collectors.toList()); } /** @@ -578,7 +568,9 @@ public Function getPrinter() { private static class ParallelParse extends RecursiveAction { private static final long serialVersionUID = 1L; + private final SourceRoot root; + private final VisitFileCallback callback; ParallelParse(Path path, VisitFileCallback callback) { @@ -592,6 +584,7 @@ protected void compute() { Path path = root.getRoot(); try { Files.walkFileTree(path, new SimpleFileVisitor() { + @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (!root.isSensibleDirectoryToEnter(dir)) { @@ -615,13 +608,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { } catch (IOException e) { Log.error(e); } - for (ParallelParse w : walks) { w.join(); } } interface VisitFileCallback { + FileVisitResult process(Path file, BasicFileAttributes attrs); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java index 5891a2ee5b..633e661482 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.JavaParser; @@ -42,11 +41,11 @@ /** * A collection of Java source files and its sub-directories located in a ZIP or JAR file on the file system. * Files can be parsed with a callback. - * */ public class SourceZip { private final Path zipPath; + private ParserConfiguration parserConfiguration; /** @@ -71,7 +70,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { assertNotNull(configuration); this.zipPath = zipPath.normalize(); this.parserConfiguration = configuration; - Log.info("New source zip at \"%s\"", ()->this.zipPath); + Log.info("New source zip at \"%s\"", () -> this.zipPath); } /** @@ -83,7 +82,7 @@ public SourceZip(Path zipPath, ParserConfiguration configuration) { * @throws IOException If an error occurs while trying to parse the given source. */ public List>> parse() throws IOException { - Log.info("Parsing zip at \"%s\"", ()-> zipPath); + Log.info("Parsing zip at \"%s\"", () -> zipPath); List>> results = new ArrayList<>(); parse((path, result) -> results.add(new Pair<>(path, result))); return results; @@ -98,14 +97,13 @@ public List>> parse() throws IOException * @throws IOException If an error occurs while trying to parse the given source. */ public SourceZip parse(Callback callback) throws IOException { - Log.info("Parsing zip at \"%s\"", ()-> zipPath); + Log.info("Parsing zip at \"%s\"", () -> zipPath); JavaParser javaParser = new JavaParser(parserConfiguration); try (ZipFile zipFile = new ZipFile(zipPath.toFile())) { for (ZipEntry entry : Collections.list(zipFile.entries())) { if (!entry.isDirectory() && entry.getName().endsWith(".java")) { - Log.info("Parsing zip entry \"%s\"", ()-> entry.getName()); - final ParseResult result = javaParser.parse(COMPILATION_UNIT, - provider(zipFile.getInputStream(entry))); + Log.info("Parsing zip entry \"%s\"", () -> entry.getName()); + final ParseResult result = javaParser.parse(COMPILATION_UNIT, provider(zipFile.getInputStream(entry))); callback.process(Paths.get(entry.getName()), result); } } @@ -136,7 +134,7 @@ public interface Callback { public Path getZipPath() { return zipPath; } - + public ParserConfiguration getParserConfiguration() { return parserConfiguration; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java index 7e1445e163..7ffa20ef19 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java @@ -79,49 +79,15 @@ public static String unescapeJavaTextBlock(final String input) { return UNESCAPE_JAVA_TEXT_BLOCK.translate(input); } - private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][]{ - {"\\b", "\b"}, - {"\\n", "\n"}, - {"\\t", "\t"}, - {"\\f", "\f"}, - {"\\r", "\r"}}); - - private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][]{ - {"\b", "\\b"}, - {"\n", "\\n"}, - {"\t", "\\t"}, - {"\f", "\\f"}, - {"\r", "\\r"}}); - - private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator( - new LookupTranslator( - new String[][]{ - {"\"", "\\\""}, - {"\\", "\\\\"}, - }), - JAVA_CTRL_CHARS_ESCAPE); - - private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator( - new OctalUnescaper(), - new UnicodeUnescaper(), - JAVA_CTRL_CHARS_UNESCAPE, - new LookupTranslator(new String[][]{ - {"\\\\", "\\"}, - {"\\\"", "\""}, - {"\\'", "'"}, - {"\\", ""}})); - - private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator( - new OctalUnescaper(), - new UnicodeUnescaper(), - JAVA_CTRL_CHARS_UNESCAPE, - new LookupTranslator(new String[][]{ - {"\\\\", "\\"}, - {"\\\"", "\""}, - {"\\'", "'"}, - {"\\", ""}, - {"\\s", " "}, - {"\\\n", ""}})); + private static final LookupTranslator JAVA_CTRL_CHARS_UNESCAPE = new LookupTranslator(new String[][] { { "\\b", "\b" }, { "\\n", "\n" }, { "\\t", "\t" }, { "\\f", "\f" }, { "\\r", "\r" } }); + + private static final LookupTranslator JAVA_CTRL_CHARS_ESCAPE = new LookupTranslator(new String[][] { { "\b", "\\b" }, { "\n", "\\n" }, { "\t", "\\t" }, { "\f", "\\f" }, { "\r", "\\r" } }); + + private static final CharSequenceTranslator ESCAPE_JAVA = new AggregateTranslator(new LookupTranslator(new String[][] { { "\"", "\\\"" }, { "\\", "\\\\" } }), JAVA_CTRL_CHARS_ESCAPE); + + private static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" } })); + + private static final CharSequenceTranslator UNESCAPE_JAVA_TEXT_BLOCK = new AggregateTranslator(new OctalUnescaper(), new UnicodeUnescaper(), JAVA_CTRL_CHARS_UNESCAPE, new LookupTranslator(new String[][] { { "\\\\", "\\" }, { "\\\"", "\"" }, { "\\'", "'" }, { "\\", "" }, { "\\s", " " }, { "\\\n", "" } })); /** * Adapted from apache commons-lang3 project. @@ -221,8 +187,11 @@ private void translate(final CharSequence input, final Writer out) throws IOExce private static class LookupTranslator extends CharSequenceTranslator { private final HashMap lookupMap; + private final HashSet prefixSet; + private final int shortest; + private final int longest; /** @@ -271,7 +240,6 @@ protected int translate(final CharSequence input, final int index, final Writer for (int i = max; i >= shortest; i--) { final CharSequence subSeq = input.subSequence(index, index + i); final String result = lookupMap.get(subSeq.toString()); - if (result != null) { out.write(result); return i; @@ -318,7 +286,6 @@ protected int translate(final CharSequence input, final int index, final Writer } return 0; } - } /** @@ -340,23 +307,21 @@ private static class OctalUnescaper extends CharSequenceTranslator { */ @Override protected int translate(final CharSequence input, final int index, final Writer out) throws IOException { - final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ + // how many characters left, ignoring the first \ + final int remaining = input.length() - index - 1; final StringBuilder builder = new StringBuilder(); if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) { final int next = index + 1; final int next2 = index + 2; final int next3 = index + 3; - // we know this is good as we checked it in the if block above builder.append(input.charAt(next)); - if (remaining > 1 && isOctalDigit(input.charAt(next2))) { builder.append(input.charAt(next2)); if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) { builder.append(input.charAt(next3)); } } - out.write(Integer.parseInt(builder.toString(), 8)); return 1 + builder.length(); } @@ -407,15 +372,12 @@ protected int translate(final CharSequence input, final int index, final Writer while (index + i < input.length() && input.charAt(index + i) == 'u') { i++; } - if (index + i < input.length() && input.charAt(index + i) == '+') { i++; } - if (index + i + 4 <= input.length()) { // Get 4 hex digits final CharSequence unicode = input.subSequence(index + i, index + i + 4); - try { final int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); @@ -424,11 +386,9 @@ protected int translate(final CharSequence input, final int index, final Writer } return i + 4; } - throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) - + "' due to end of CharSequence"); + throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + "' due to end of CharSequence"); } return 0; } } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java index 04786f897d..26611a298d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -29,7 +28,7 @@ import java.util.*; import java.util.function.Function; -import static java.util.Arrays.*; +import static java.util.Arrays.asList; /** * Any kind of utility. @@ -50,7 +49,6 @@ public class Utils { * @deprecated Renamed from {@link #EOL} to make it explicit that we're using the system's line separator. * New code should use {@link LineSeparator#SYSTEM} if referring to the current host system's line separator, * else {@link LineSeparator#CR} or {@link LineSeparator#LF} or {@link LineSeparator#CRLF} if referring to a specific style of line separator. - * */ @Deprecated public static final String SYSTEM_EOL = LineSeparator.SYSTEM.asRawString(); @@ -93,7 +91,7 @@ public static T assertPositive(T number) { public static String escapeEndOfLines(String string) { StringBuilder escapedString = new StringBuilder(); for (char c : string.toCharArray()) { - switch (c) { + switch(c) { case '\n': escapedString.append("\\n"); break; @@ -111,11 +109,9 @@ public static String readerToString(Reader reader) throws IOException { final StringBuilder result = new StringBuilder(); final char[] buffer = new char[8 * 1024]; int numChars; - while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) { result.append(buffer, 0, numChars); } - return result.toString(); } @@ -141,7 +137,6 @@ public static String screamingToCamelCase(String original) { return sb.toString(); } - /** * @param input "aCamelCaseString" * @return "A_CAMEL_CASE_STRING" @@ -199,8 +194,7 @@ private static String stringTransformer(String s, String operationDescription, F if (s.isEmpty()) { throw new IllegalArgumentException(String.format("You cannot %s an empty string", operationDescription)); } - return transformation.apply(s.substring(0, 1)) + - s.substring(1); + return transformation.apply(s.substring(0, 1)) + s.substring(1); } /** @@ -303,7 +297,6 @@ public static String removeFileExtension(String filename) { int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) return filename; - return filename.substring(0, extensionIndex); } @@ -321,11 +314,6 @@ public static String trimTrailingSpaces(String line) { * Checks, if the parent is a unary expression with a minus operator. Used to check for negative literals. */ public static boolean hasUnaryMinusAsParent(Node n) { - return n.getParentNode() - .filter(parent -> parent instanceof UnaryExpr) - .map(parent -> (UnaryExpr) parent) - .map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS) - .orElse(false); + return n.getParentNode().filter(parent -> parent instanceof UnaryExpr).map(parent -> (UnaryExpr) parent).map(unaryExpr -> unaryExpr.getOperator() == UnaryExpr.Operator.MINUS).orElse(false); } - } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java index be651ecb72..5927df6360 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java @@ -18,21 +18,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.stream.Collectors; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.*; +import java.util.stream.Collectors; + /** * A list that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -40,14 +35,15 @@ public class VisitorList implements List { protected List innerList; + protected final GenericVisitor hashcodeVisitor; + protected final GenericVisitor equalsVisitor; /** * Pass the visitors to use for equals and hashcode. */ - public VisitorList(GenericVisitor hashcodeVisitor, - GenericVisitor equalsVisitor) { + public VisitorList(GenericVisitor hashcodeVisitor, GenericVisitor equalsVisitor) { this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; innerList = new ArrayList<>(); @@ -66,9 +62,8 @@ public void add(int index, N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) - if (add(elem)) - modified = true; + for (N elem : col) if (add(elem)) + modified = true; return modified; } @@ -98,9 +93,8 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) - if (!contains(elem)) - return false; + for (Object elem : col) if (!contains(elem)) + return false; return true; } @@ -122,6 +116,7 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { + final Iterator itr = innerList.iterator(); @Override @@ -154,6 +149,7 @@ public ListIterator listIterator() { @Override public ListIterator listIterator(int index) { return new ListIterator() { + final ListIterator itr = innerList.listIterator(index); @Override @@ -216,9 +212,8 @@ public N remove(int index) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) - if (remove(elem)) - modified = true; + for (Object elem : col) if (remove(elem)) + modified = true; return modified; } @@ -243,6 +238,7 @@ public int size() { @Override public List subList(int fromIndex, int toIndex) { return new VisitorList(hashcodeVisitor, equalsVisitor) { + { this.innerList = VisitorList.this.innerList.subList(fromIndex, toIndex); } @@ -271,6 +267,7 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java index 500dbb1e8c..da62cde295 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java @@ -18,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; import com.github.javaparser.ast.Node; @@ -37,8 +36,11 @@ * by using another equals and hashcode visitor for those methods. */ public class VisitorMap implements Map { + private final Map innerMap = new HashMap<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; /** @@ -48,7 +50,7 @@ public VisitorMap(GenericVisitor hashcodeVisitor, GenericVisitor< this.hashcodeVisitor = hashcodeVisitor; this.equalsVisitor = equalsVisitor; } - + @Override public int size() { return innerMap.size(); @@ -80,6 +82,7 @@ public V put(N key, V value) { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -127,9 +130,7 @@ public void clear() { @Override public Set keySet() { - return innerMap.keySet().stream() - .map(k -> k.overridden) - .collect(Collectors.toSet()); + return innerMap.keySet().stream().map(k -> k.overridden).collect(Collectors.toSet()); } @Override @@ -139,8 +140,6 @@ public Collection values() { @Override public Set> entrySet() { - return innerMap.entrySet().stream() - .map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())) - .collect(Collectors.toSet()); + return innerMap.entrySet().stream().map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue())).collect(Collectors.toSet()); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java index b233b426bc..89896be297 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java @@ -18,20 +18,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ - package com.github.javaparser.utils; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitor; + import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.stream.Collectors; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.Visitable; -import com.github.javaparser.ast.visitor.VoidVisitor; - /** * A set that overrides the equals and hashcode calculation of the added nodes * by using another equals and hashcode visitor for those methods. @@ -39,7 +38,9 @@ public class VisitorSet implements Set { private final Set innerSet = new HashSet<>(); + private final GenericVisitor hashcodeVisitor; + private final GenericVisitor equalsVisitor; /** @@ -58,9 +59,8 @@ public boolean add(N elem) { @Override public boolean addAll(Collection col) { boolean modified = false; - for (N elem : col) - if (add(elem)) - modified = true; + for (N elem : col) if (add(elem)) + modified = true; return modified; } @@ -76,9 +76,8 @@ public boolean contains(Object elem) { @Override public boolean containsAll(Collection col) { - for (Object elem : col) - if (!contains(elem)) - return false; + for (Object elem : col) if (!contains(elem)) + return false; return true; } @@ -90,6 +89,7 @@ public boolean isEmpty() { @Override public Iterator iterator() { return new Iterator() { + final Iterator itr = innerSet.iterator(); @Override @@ -117,9 +117,8 @@ public boolean remove(Object elem) { @Override public boolean removeAll(Collection col) { boolean modified = false; - for (Object elem : col) - if (remove(elem)) - modified = true; + for (Object elem : col) if (remove(elem)) + modified = true; return modified; } @@ -158,6 +157,7 @@ public String toString() { } private class EqualsHashcodeOverridingFacade implements Visitable { + private final N overridden; EqualsHashcodeOverridingFacade(N overridden) { @@ -187,5 +187,4 @@ public boolean equals(final Object obj) { return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden); } } - } From 37d411b240bc25d1f3ae2e0cd2bcf8b9d44d5496 Mon Sep 17 00:00:00 2001 From: Joseph Cox Date: Sun, 30 Oct 2022 10:12:35 +1100 Subject: [PATCH 035/280] Accurate test name, change to use assertThrows --- .../com/github/javaparser/PositionTest.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java index 4ef8d2c469..f6e9a06157 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java @@ -1,5 +1,6 @@ package com.github.javaparser; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -22,20 +23,14 @@ public void testOrIfInvalid() { } @Test - public void testPositionExceptionMessage() { - try { - Position p = new Position(-10, 1); - fail("Created " + p + " without exception."); - } catch (IllegalArgumentException e) { - assertEquals("Can't position at line -10", e.getMessage()); - } - - try { - Position p = new Position(1, -10); - fail("Created " + p + " without exception."); - } catch (IllegalArgumentException e) { - assertEquals("Can't position at column -10", e.getMessage()); - } + public void testPositionExceptionFormat() { + IllegalArgumentException thrown1 = Assertions.assertThrows(IllegalArgumentException.class, () -> new Position(-10, 1)); + + assertEquals("Can't position at line -10", thrown1.getMessage()); + + IllegalArgumentException thrown2 = Assertions.assertThrows(IllegalArgumentException.class, () -> new Position(1, -10)); + + assertEquals("Can't position at column -10", thrown2.getMessage()); } } From 0bcce161abd0a8745a6e259f72e2425b414b0f21 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:13:29 +0100 Subject: [PATCH 036/280] Improved SymbolReference class --- .../model/resolution/SymbolReference.java | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index c5f70ff1cc..2c1e9a090f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.model.resolution; +import com.github.javaparser.quality.Nullable; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import java.util.Optional; @@ -33,9 +34,9 @@ */ public class SymbolReference { - private Optional correspondingDeclaration; + private final S correspondingDeclaration; - private SymbolReference(Optional correspondingDeclaration) { + private SymbolReference(@Nullable S correspondingDeclaration) { this.correspondingDeclaration = correspondingDeclaration; } @@ -43,14 +44,25 @@ private SymbolReference(Optional correspondingDeclaration) { * Create a solve reference to the given symbol. */ public static SymbolReference solved(S2 symbolDeclaration) { - return new SymbolReference(Optional.of(symbolDeclaration)); + return new SymbolReference<>(symbolDeclaration); + } + + /** + * Create a reference for an unsolved symbol. + * + * @return The created unsolved symbol reference. + * + * @param The symbol reference type. + */ + public static SymbolReference unsolved() { + return new SymbolReference<>(null); } /** * Create an unsolved reference specifying the type of the value expected. */ public static SymbolReference unsolved(Class clazz) { - return new SymbolReference<>(Optional.empty()); + return new SymbolReference<>(null); } @Override @@ -58,29 +70,45 @@ public String toString() { return "SymbolReference{" + correspondingDeclaration + "}"; } + /** + * Get the declaration associated with the Symbol. + * + * @return an {@link Optional} with a present value if the symbol is solved, otherwise an empty {@link Optional}. + */ + public Optional getDeclaration() { + return Optional.ofNullable(correspondingDeclaration); + } + /** * The corresponding declaration. If not solve this throws UnsupportedOperationException. - * // TODO: Convert this to returning Optional. + * + * @deprecated This function is deprecated. Please consider using {@link #getDeclaration()} */ + @Deprecated public S getCorrespondingDeclaration() { - if (!isSolved()) { - throw new UnsupportedOperationException("CorrespondingDeclaration not available for unsolved symbol."); + + Optional declaration = getDeclaration(); + if (declaration.isPresent()) { + return declaration.get(); } - return correspondingDeclaration.get(); + + throw new UnsupportedOperationException("CorrespondingDeclaration not available for unsolved symbol."); } /** * Is the reference solved? + * + * @deprecated To check if the reference is solved, please consider using {@link #getDeclaration()} + * followed by {@link Optional#isPresent()}. */ + @Deprecated public boolean isSolved() { - return correspondingDeclaration.isPresent(); + return getDeclaration().isPresent(); } public static SymbolReference adapt(SymbolReference ref, Class clazz) { - if (ref.isSolved()) { - return SymbolReference.solved(ref.getCorrespondingDeclaration()); - } else { - return SymbolReference.unsolved(clazz); - } + return ref.getDeclaration() + .>map(SymbolReference::solved) + .orElseGet(() -> SymbolReference.unsolved(clazz)); } } From a01bf0facc5fc94a24de436a484b2b5c1c4a6c65 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:14:00 +0100 Subject: [PATCH 037/280] Moved toString method to the end of class --- .../symbolsolver/model/resolution/SymbolReference.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index 2c1e9a090f..9e69fb5e27 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -65,11 +65,6 @@ public static SymbolReference u return new SymbolReference<>(null); } - @Override - public String toString() { - return "SymbolReference{" + correspondingDeclaration + "}"; - } - /** * Get the declaration associated with the Symbol. * @@ -106,6 +101,11 @@ public boolean isSolved() { return getDeclaration().isPresent(); } + @Override + public String toString() { + return "SymbolReference{" + correspondingDeclaration + "}"; + } + public static SymbolReference adapt(SymbolReference ref, Class clazz) { return ref.getDeclaration() .>map(SymbolReference::solved) From f944fdaaf35a7bb1b1f495a6365178bb20132afa Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:24:12 +0100 Subject: [PATCH 038/280] Moved static methods to the beginning of class --- .../model/resolution/SymbolReference.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index 9e69fb5e27..287fb87904 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -34,12 +34,6 @@ */ public class SymbolReference { - private final S correspondingDeclaration; - - private SymbolReference(@Nullable S correspondingDeclaration) { - this.correspondingDeclaration = correspondingDeclaration; - } - /** * Create a solve reference to the given symbol. */ @@ -60,9 +54,44 @@ public static SymbolReference unsolved() { /** * Create an unsolved reference specifying the type of the value expected. + * + * @deprecated Consider using {@link #unsolved()} instead. */ + @Deprecated public static SymbolReference unsolved(Class clazz) { - return new SymbolReference<>(null); + return unsolved(); + } + + /** + * Adapt a {@link SymbolReference} into another {@link SymbolReference}. + * + * @param ref The reference to be adapted. + * @param clazz The final type to be used. + * + * @return The adapted symbol reference. + * + * @param The Symbol Reference before adapting. + * @param The Symbol Reference after adapting. + */ + public static SymbolReference adapt(SymbolReference ref, Class clazz) { + + Optional declaration = ref.getDeclaration(); + if (declaration.isPresent()) { + + I symbol = declaration.get(); + if (clazz.isInstance(symbol)) { + return solved(clazz.cast(symbol)); + } + + } + + return unsolved(); + } + + private final S correspondingDeclaration; + + private SymbolReference(@Nullable S correspondingDeclaration) { + this.correspondingDeclaration = correspondingDeclaration; } /** @@ -106,9 +135,4 @@ public String toString() { return "SymbolReference{" + correspondingDeclaration + "}"; } - public static SymbolReference adapt(SymbolReference ref, Class clazz) { - return ref.getDeclaration() - .>map(SymbolReference::solved) - .orElseGet(() -> SymbolReference.unsolved(clazz)); - } } From e19d4e9e4c5e1bbdcfc58e848e5c25e0f92ecf38 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:35:52 +0100 Subject: [PATCH 039/280] Added unit tests for class --- .../model/resolution/SymbolReferenceTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java new file mode 100644 index 0000000000..43de07a1a8 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java @@ -0,0 +1,68 @@ +package com.github.javaparser.symbolsolver.model.resolution; + +import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class SymbolReferenceTest { + + private final TypeSolver typeSolver = new ReflectionTypeSolver(); + + @Test + void testResolvedSymbol() { + ResolvedDeclaration resolvedDeclaration = new ReflectionClassDeclaration(String.class, typeSolver); + SymbolReference symbol = SymbolReference.solved(resolvedDeclaration); + + assertNotNull(symbol); + assertNotNull(symbol.getDeclaration()); + assertTrue(symbol.getDeclaration().isPresent()); + } + + @Test + void testUnresolvedSymbol() { + SymbolReference symbol = SymbolReference.unsolved(); + + assertNotNull(symbol); + assertNotNull(symbol.getDeclaration()); + assertFalse(symbol.getDeclaration().isPresent()); + } + + @Test + void testAdaptSymbolForSubClass() { + ResolvedDeclaration resolvedDeclaration = new ReflectionClassDeclaration(String.class, typeSolver); + SymbolReference symbol = SymbolReference.solved(resolvedDeclaration); + SymbolReference adaptedSymbol = SymbolReference.adapt(symbol, ResolvedClassDeclaration.class); + + assertNotNull(adaptedSymbol); + assertNotNull(adaptedSymbol.getDeclaration()); + assertTrue(adaptedSymbol.getDeclaration().isPresent()); + } + + @Test + void testAdaptSymbolForInvalidSubClass() { + ResolvedClassDeclaration resolvedDeclaration = new ReflectionClassDeclaration(String.class, typeSolver); + SymbolReference symbol = SymbolReference.solved(resolvedDeclaration); + SymbolReference adaptedSymbol = SymbolReference.adapt(symbol, ResolvedParameterDeclaration.class); + + assertNotNull(adaptedSymbol); + assertNotNull(adaptedSymbol.getDeclaration()); + assertFalse(adaptedSymbol.getDeclaration().isPresent()); + } + + @Test + void testAdaptSymbolForSuperClass() { + ResolvedClassDeclaration resolvedDeclaration = new ReflectionClassDeclaration(String.class, typeSolver); + SymbolReference symbol = SymbolReference.solved(resolvedDeclaration); + SymbolReference adaptedSymbol = SymbolReference.adapt(symbol, ResolvedDeclaration.class); + + assertNotNull(adaptedSymbol); + assertNotNull(adaptedSymbol.getDeclaration()); + assertTrue(adaptedSymbol.getDeclaration().isPresent()); + } + +} \ No newline at end of file From f713aacbcf8ae413e362189e7a5e96f4b5925715 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:40:38 +0100 Subject: [PATCH 040/280] Simplified usage of unsolved --- .../symbolsolver/core/resolution/Context.java | 13 ++-- .../javaparsermodel/JavaParserFacade.java | 59 ++++----------- .../contexts/AbstractJavaParserContext.java | 24 +++---- .../contexts/BlockStmtContext.java | 12 ++-- .../contexts/CompilationUnitContext.java | 28 +++----- .../contexts/FieldAccessContext.java | 22 +++--- .../contexts/InstanceOfExprContext.java | 2 +- .../JavaParserTypeDeclarationAdapter.java | 10 +-- .../contexts/MethodCallExprContext.java | 26 ++----- .../contexts/MethodReferenceExprContext.java | 17 ++--- .../contexts/StatementContext.java | 16 ++--- .../declarations/JavaParserTypeAdapter.java | 16 +---- .../JavassistClassDeclaration.java | 11 +-- .../JavassistEnumDeclaration.java | 13 +--- .../JavassistInterfaceDeclaration.java | 18 ++--- .../ReflectionClassDeclaration.java | 17 ++--- .../ReflectionEnumDeclaration.java | 2 +- .../ReflectionInterfaceDeclaration.java | 2 +- .../ConstructorResolutionLogic.java | 14 ++-- .../resolution/MethodResolutionLogic.java | 32 +++------ .../symbolsolver/resolution/SymbolSolver.java | 18 ++--- .../typesolvers/ClassLoaderTypeSolver.java | 10 +-- .../typesolvers/CombinedTypeSolver.java | 8 +-- .../resolution/typesolvers/JarTypeSolver.java | 15 +--- .../typesolvers/JavaParserTypeSolver.java | 2 +- .../typesolvers/MemoryTypeSolver.java | 2 +- .../symbolsolver/Issue1364Test.java | 15 ++-- .../symbolsolver/Issue1814Test.java | 13 ++-- .../symbolsolver/resolution/ContextTest.java | 72 +++++-------------- .../typesolvers/CombinedTypeSolverTest.java | 15 +--- 30 files changed, 160 insertions(+), 364 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index ead2294151..4050821930 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -26,12 +26,7 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext; import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; @@ -96,7 +91,7 @@ default SymbolReference solveType(String name) { default SymbolReference solveTypeInParentContext(String name) { Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } // Delegate solving to the parent context. @@ -118,7 +113,7 @@ default SymbolReference solveSymbol(String n default SymbolReference solveSymbolInParentContext(String name) { Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } // Delegate solving to the parent context. @@ -354,7 +349,7 @@ default SymbolReference solveMethod(String name, List default SymbolReference solveMethodInParentContext(String name, List argumentsTypes, boolean staticOnly) { Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } // Delegate solving to the parent context. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 0404ea1345..1f3c7dc4fb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -21,55 +21,19 @@ package com.github.javaparser.symbolsolver.javaparsermodel; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.solved; -import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.unsolved; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.WeakHashMap; -import java.util.stream.Collectors; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.DataKey; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; -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.type.UnionType; -import com.github.javaparser.ast.type.VarType; -import com.github.javaparser.ast.type.WildcardType; +import com.github.javaparser.ast.type.*; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.resolution.types.ResolvedArrayType; -import com.github.javaparser.resolution.types.ResolvedPrimitiveType; -import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.resolution.types.ResolvedUnionType; -import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.resolution.types.ResolvedWildcard; +import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; @@ -86,6 +50,13 @@ import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.utils.Log; +import java.util.*; +import java.util.stream.Collectors; + +import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.solved; +import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.unsolved; + /** * Class to be used by final users to solve symbols for JavaParser ASTs. * @@ -198,7 +169,7 @@ public SymbolReference solve(ExplicitConstructor // Constructor invocation must exist within a class (not interface). Optional optAncestorClassOrInterfaceNode = explicitConstructorInvocationStmt.findAncestor(ClassOrInterfaceDeclaration.class); if (!optAncestorClassOrInterfaceNode.isPresent()) { - return unsolved(ResolvedConstructorDeclaration.class); + return unsolved(); } ClassOrInterfaceDeclaration classOrInterfaceNode = optAncestorClassOrInterfaceNode.get(); @@ -219,7 +190,7 @@ public SymbolReference solve(ExplicitConstructor } } if (typeDecl == null) { - return unsolved(ResolvedConstructorDeclaration.class); + return unsolved(); } // Solve each of the arguments being passed into this constructor invocation. @@ -277,7 +248,7 @@ public SymbolReference solve(ObjectCreationExpr } } if (typeDecl == null) { - return unsolved(ResolvedConstructorDeclaration.class); + return unsolved(); } SymbolReference res = ConstructorResolutionLogic.findMostApplicable(typeDecl.getConstructors(), argumentTypes, typeSolver); for (LambdaArgumentTypePlaceholder placeholder : placeholders) { @@ -338,7 +309,7 @@ public SymbolReference solve(AnnotationExpr annot ResolvedAnnotationDeclaration annotationDeclaration = (ResolvedAnnotationDeclaration) typeDeclarationSymbolReference.getCorrespondingDeclaration(); return solved(annotationDeclaration); } else { - return unsolved(ResolvedAnnotationDeclaration.class); + return unsolved(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 209ad6e75d..a7978d1111 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -21,21 +21,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; -import static java.util.Collections.singletonList; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -55,6 +42,11 @@ import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; +import java.util.*; + +import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static java.util.Collections.singletonList; + /** * @author Federico Tomassetti */ @@ -77,7 +69,7 @@ public static SymbolReference solveWith(SymbolDeclarat return SymbolReference.solved(decl); } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } /// @@ -157,7 +149,7 @@ protected Node getScope(Node node) { public SymbolReference solveSymbolInParentContext(String name) { Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } // First check if there are any pattern expressions available to this node. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java index 4a202dfef2..39ffac21c0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java @@ -21,11 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.VariableDeclarationExpr; @@ -38,6 +33,11 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + public class BlockStmtContext extends AbstractJavaParserContext { public BlockStmtContext(BlockStmt wrappedNode, TypeSolver typeSolver) { @@ -74,7 +74,7 @@ private List localVariablesDeclaredIn(Statement statement) { public SymbolReference solveSymbol(String name) { Optional optionalParent = getParent(); if (!optionalParent.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } if (wrappedNode.getStatements().size() > 0) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index 87b04ae1d1..61f88d1df3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -22,12 +22,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; - -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; @@ -37,12 +31,7 @@ import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.resolution.declarations.AssociableToAST; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; @@ -54,6 +43,11 @@ import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -122,7 +116,7 @@ public SymbolReference solveSymbol(String na } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } @Override @@ -234,7 +228,7 @@ public SymbolReference solveType(String name) { if (isQualifiedName(name)) { return SymbolReference.adapt(typeSolver.tryToSolveType(name), ResolvedTypeDeclaration.class); } else { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } @@ -280,7 +274,7 @@ public SymbolReference solveMethod(String name, List< && this.wrappedNode.getTypes().stream().anyMatch(it -> it.getName().getIdentifier().equals(toSimpleName(importString)))) { // We are using a static import on a type defined in this file. It means the value was not found at // a lower level so this will fail - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } ResolvedTypeDeclaration ref = typeSolver.solveType(importString); @@ -301,13 +295,13 @@ public SymbolReference solveMethod(String name, List< if (method.isSolved()) { return method; } else { - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } } } } } - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index 16d9f1c5b4..f4b3f09c26 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -21,22 +21,10 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.FieldAccessExpr; import com.github.javaparser.ast.expr.ThisExpr; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -47,6 +35,12 @@ import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; + /** * @author Federico Tomassetti */ @@ -136,6 +130,6 @@ public SymbolReference solveField(String name) { } catch (Throwable t) { } } - return SymbolReference.unsolved(ResolvedFieldDeclaration.class); + return SymbolReference.unsolved(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java index c63f6b3996..065d7aed04 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java @@ -35,7 +35,7 @@ public SymbolReference solveSymbol(String na Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } Context parentContext = optionalParentContext.get(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index b71c67fcd6..29b31a3334 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -22,7 +22,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node.TreeTraversal; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.nodeTypes.NodeWithExtends; @@ -30,12 +29,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.resolution.declarations.HasAccessSpecifier; -import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -237,6 +231,6 @@ public SymbolReference solveConstructor(List { /// @@ -180,7 +164,7 @@ public SymbolReference solveMethod(String name, List< } } - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } /// diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 1131a90c3b..aaf5307606 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -28,8 +28,11 @@ import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.resolution.declarations.*; -import com.github.javaparser.resolution.types.*; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; @@ -39,13 +42,7 @@ import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; @@ -95,7 +92,7 @@ public SymbolReference solveMethod(String name, List< } } - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } /// diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index 6fc98ef14f..fbc423e20a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -21,11 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; -import java.util.Optional; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ConstructorDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; @@ -44,6 +39,11 @@ import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; +import java.util.Optional; + /** * @author Federico Tomassetti */ @@ -56,7 +56,7 @@ public StatementContext(N wrappedNode, TypeSolver typeSolver) { public static SymbolReference solveInBlock(String name, TypeSolver typeSolver, Statement stmt) { Optional optionalParentNode = stmt.getParentNode(); if(!optionalParentNode.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } Node parentOfWrappedNode = optionalParentNode.get(); @@ -225,7 +225,7 @@ private SymbolReference solveSymbol(String n Optional optionalParentNode = wrappedNode.getParentNode(); if(!optionalParentNode.isPresent()) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } Node parentOfWrappedNode = optionalParentNode.get(); @@ -246,7 +246,7 @@ private SymbolReference solveSymbol(String n // Further below is a more detailed explanation for why we may want to disable this visitation of adjacent statements // to prevent revisiting the same contexts over and over again. if (!iterateAdjacentStmts) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } NodeWithStatements nodeWithStmt = (NodeWithStatements) parentOfWrappedNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index bb46b432ba..f3973028a5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -23,12 +23,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -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.body.VariableDeclarator; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.nodeTypes.NodeWithMembers; import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; @@ -45,12 +40,7 @@ import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; -import java.util.ArrayList; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; /** * @author Federico Tomassetti @@ -160,7 +150,7 @@ public SymbolReference solveType(String name) { } } } - return SymbolReference.unsolved(ResolvedTypeDeclaration.class); + return SymbolReference.unsolved(); } public Optional containerType() { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index 3037e940bc..cefb10a4b4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -25,12 +25,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -153,12 +148,12 @@ public SymbolReference solveSymbol(String na } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } private SymbolReference solveSymbolForFQN(String symbolName, String fqn) { if (fqn == null) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } ResolvedReferenceTypeDeclaration fqnTypeDeclaration = typeSolver.solveType(fqn); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index be8a23d7a8..109377a5cf 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -24,14 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -209,12 +202,12 @@ public SymbolReference solveSymbol(String na } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } private SymbolReference solveSymbolForFQN(String symbolName, String fqn) { if (fqn == null) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } ResolvedReferenceTypeDeclaration fqnTypeDeclaration = typeSolver.solveType(fqn); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index d7afce8920..a489b7b3d6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -25,13 +25,7 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -45,11 +39,7 @@ import javassist.CtClass; import javassist.CtField; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -185,12 +175,12 @@ public SymbolReference solveSymbol(String na } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } private SymbolReference solveSymbolForFQN(String symbolName, String fqn) { if (fqn == null) { - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } ResolvedReferenceTypeDeclaration fqnTypeDeclaration = typeSolver.solveType(fqn); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 5a50ed1b2a..cd90acaf9c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -24,12 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -47,11 +42,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -203,7 +194,7 @@ public SymbolReference solveMethod(String name, List< // MethodResolutionLogic.findMostApplicable method returns very early // when candidateSolvedMethods is empty. if (candidateSolvedMethods.isEmpty()) { - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } return MethodResolutionLogic.findMostApplicable(candidateSolvedMethods, name, argumentsTypes, typeSolver); } @@ -312,7 +303,7 @@ public SymbolReference solveSymbol(String na return SymbolReference.solved(new ReflectionFieldDeclaration(field, typeSolver)); } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index e621e24eba..c16e6a94b7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -213,7 +213,7 @@ public SymbolReference solveSymbol(String na ResolvedEnumConstantDeclaration enumConstant = getEnumConstant(name); return SymbolReference.solved(enumConstant); } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index aa1ff44bb9..e213e290c6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -251,7 +251,7 @@ public SymbolReference solveSymbol(String na return SymbolReference.solved(new ReflectionFieldDeclaration(field, typeSolver)); } } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java index 038a760849..d49e495b64 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java @@ -21,12 +21,6 @@ package com.github.javaparser.symbolsolver.resolution; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -35,6 +29,12 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + /** * @author Fred Lefévère-Laoide */ @@ -164,7 +164,7 @@ public static SymbolReference findMostApplicable List constructors, List argumentsTypes, TypeSolver typeSolver, boolean wildcardTolerance) { List applicableConstructors = constructors.stream().filter((m) -> isApplicable(m, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList()); if (applicableConstructors.isEmpty()) { - return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); + return SymbolReference.unsolved(); } if (applicableConstructors.size() == 1) { return SymbolReference.solved(applicableConstructors.get(0)); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index 0faad96205..bfc3b8aa2c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -21,35 +21,21 @@ package com.github.javaparser.symbolsolver.resolution; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.types.ResolvedArrayType; -import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.resolution.types.ResolvedWildcard; +import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -556,7 +542,7 @@ public static SymbolReference findMostApplicable(List // If no applicable methods found, return as unsolved. if (applicableMethods.isEmpty()) { - return SymbolReference.unsolved(ResolvedMethodDeclaration.class); + return SymbolReference.unsolved(); } // If there are multiple possible methods found, null arguments can help to eliminate some matches. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 854e951602..b2e0d6443f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -21,15 +21,11 @@ package com.github.javaparser.symbolsolver.resolution; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -39,18 +35,14 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.javassistmodel.JavassistClassDeclaration; -import com.github.javaparser.symbolsolver.javassistmodel.JavassistEnumDeclaration; -import com.github.javaparser.symbolsolver.javassistmodel.JavassistInterfaceDeclaration; import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; + +import java.util.List; +import java.util.Optional; /** * @author Federico Tomassetti @@ -139,7 +131,7 @@ public SymbolReference solveSymbolInType(Res if (typeDeclaration instanceof SymbolResolutionCapability) { return ((SymbolResolutionCapability) typeDeclaration).solveSymbol(name, typeSolver); } - return SymbolReference.unsolved(ResolvedValueDeclaration.class); + return SymbolReference.unsolved(); } /** @@ -156,6 +148,6 @@ public SymbolReference solveTypeInType(ResolvedTypeDecl if (typeDeclaration instanceof JavaParserInterfaceDeclaration) { return ((JavaParserInterfaceDeclaration) typeDeclaration).solveType(name); } - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java index c94cbfb515..d6888f2d1e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java @@ -86,12 +86,12 @@ public SymbolReference tryToSolveType(String n // java.lang.NoClassDefFoundError: com/github/javaparser/printer/ConcreteSyntaxModel // (wrong name: com/github/javaparser/printer/concretesyntaxmodel) // note that this exception seems to be thrown only on certain platform (mac yes, linux no) - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } catch (ClassNotFoundException e) { // it could be an inner class int lastDot = name.lastIndexOf('.'); if (lastDot == -1) { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } else { String parentName = name.substring(0, lastDot); String childName = name.substring(lastDot + 1); @@ -101,14 +101,14 @@ public SymbolReference tryToSolveType(String n .internalTypes() .stream().filter(it -> it.getName().equals(childName)).findFirst(); return innerClass.map(SymbolReference::solved) - .orElseGet(() -> SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class)); + .orElseGet(() -> SymbolReference.unsolved()); } else { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } } } else { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java index e0ba88c30a..c5e42e1656 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java @@ -28,11 +28,7 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.function.Predicate; /** @@ -175,7 +171,7 @@ public SymbolReference tryToSolveType(String n } // When unable to solve, cache the value with unsolved symbol - SymbolReference unsolvedSymbol = SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + SymbolReference unsolvedSymbol = SymbolReference.unsolved(); typeCache.put(name, unsolvedSymbol); return unsolvedSymbol; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java index b8b4c2e7ee..abdfbbdd80 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java @@ -29,18 +29,9 @@ import javassist.ClassPool; import javassist.NotFoundException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.nio.file.Path; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -267,7 +258,7 @@ public SymbolReference tryToSolveType(String n String storedKey = knownClasses.get(name); // If the name is not registered in the list we can safely say is not solvable here if (storedKey == null) { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } try { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java index 941f9d7ce8..083fe73471 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java @@ -307,7 +307,7 @@ private SymbolReference tryToSolveTypeUncached } } - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java index ae996c63ca..94342109b6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java @@ -92,7 +92,7 @@ public SymbolReference tryToSolveType(String n if (declarationMap.containsKey(name)) { return SymbolReference.solved(declarationMap.get(name)); } else { - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java index 720a82e327..6d4329f7a0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java @@ -21,11 +21,7 @@ package com.github.javaparser.symbolsolver; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParseStart; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.Providers; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; @@ -39,13 +35,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.time.Duration; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import java.time.Duration; -import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; +import static org.junit.jupiter.api.Assertions.*; /** * @author Dominik Hardtke @@ -76,7 +69,7 @@ public SymbolReference tryToSolveType(String n return SymbolReference.solved(new JavaParserClassDeclaration(fakeObject, this)); } - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } }; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java index 5a33524cb7..f74df3f13c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java @@ -21,7 +21,10 @@ package com.github.javaparser.symbolsolver; -import com.github.javaparser.*; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParseStart; +import com.github.javaparser.Providers; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -37,12 +40,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.time.Duration; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.time.Duration; -import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; +import static org.junit.jupiter.api.Assertions.*; /** * @author Dominik Hardtke @@ -80,7 +81,7 @@ public SymbolReference tryToSolveType(String n return SymbolReference.solved(new JavaParserClassDeclaration(clazz, this)); } - return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); + return SymbolReference.unsolved(); } }; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index b74f03f8c2..9a407c4008 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -21,59 +21,16 @@ package com.github.javaparser.symbolsolver.resolution; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParseStart; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.StringProvider; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.InstanceOfExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.ast.expr.UnaryExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ForEachStmt; -import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.stmt.*; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; @@ -85,12 +42,21 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.*; import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class ContextTest extends AbstractSymbolResolutionTest { @@ -233,7 +199,7 @@ void resolveReferenceToClassInJavaLang() { when(stringDecl.getQualifiedName()).thenReturn("java.lang.String"); TypeSolver typeSolver = mock(TypeSolver.class); when(typeSolver.getSolvedJavaLangObject()).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); - when(typeSolver.tryToSolveType("me.tomassetti.symbolsolver.javaparser.String")).thenReturn(SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class)); + when(typeSolver.tryToSolveType("me.tomassetti.symbolsolver.javaparser.String")).thenReturn(SymbolReference.unsolved()); when(typeSolver.getRoot()).thenReturn(typeSolver); when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); when(typeSolver.tryToSolveType("java.lang.String")).thenReturn(SymbolReference.solved(stringDecl)); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java index 0d17c9bfd8..28b3a206f8 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java @@ -39,17 +39,8 @@ import java.util.List; import java.util.function.Predicate; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; class CombinedTypeSolverTest extends AbstractTypeSolverTest { @@ -99,7 +90,7 @@ void testExceptionFilter(Exception toBeThrownException, Predicate fil TypeSolver secondaryTypeSolver = mock(TypeSolver.class); when(secondaryTypeSolver.getSolvedJavaLangObject()).thenReturn(new ReflectionClassDeclaration(Object.class, secondaryTypeSolver)); when(secondaryTypeSolver.tryToSolveType(any(String.class))) - .thenReturn(SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class)); + .thenReturn(SymbolReference.unsolved()); try { new CombinedTypeSolver(filter, erroringTypeSolver, secondaryTypeSolver) From 043937f7e555b87237c110c1dd50305cf2a22af6 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 01:18:38 +0000 Subject: [PATCH 041/280] Rolled back imports for tests --- .../com/github/javaparser/symbolsolver/Issue1814Test.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java index f74df3f13c..54c835e998 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java @@ -21,10 +21,7 @@ package com.github.javaparser.symbolsolver; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParseStart; -import com.github.javaparser.Providers; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; From cb2b845b86b5a2dda126d4e27fd0a761dc72745c Mon Sep 17 00:00:00 2001 From: Amelia Genova Date: Sun, 30 Oct 2022 12:24:36 +1100 Subject: [PATCH 042/280] fixed exception tests to assertThrows. --- .../javaparser/utils/CodeGenerationUtilsTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java index c28a65aa42..30ebadd24f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java @@ -47,12 +47,10 @@ void testGetterToPropertyName() { assertEquals("value", getterToPropertyName("getValue")); assertEquals("blue", getterToPropertyName("isBlue")); assertEquals("value", getterToPropertyName("hasValue")); - try { - getterToPropertyName("value"); - fail("Expected an IllegalArgumentException to be thrown"); - } catch (IllegalArgumentException e) { - assertEquals("Unexpected getterName 'value'", e.getMessage()); - } + + IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, + () -> getterToPropertyName("value")); + assertEquals("Unexpected getterName 'value'", thrown.getMessage()); } } From d7a5e3e2bf0cfc76c7255c669b6f02f40f242598 Mon Sep 17 00:00:00 2001 From: Joseph Cox Date: Sun, 30 Oct 2022 12:31:12 +1100 Subject: [PATCH 043/280] Fit code style --- .../src/test/java/com/github/javaparser/PositionTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java index f6e9a06157..0aad0fa43d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; public class PositionTest { @@ -24,11 +23,13 @@ public void testOrIfInvalid() { @Test public void testPositionExceptionFormat() { - IllegalArgumentException thrown1 = Assertions.assertThrows(IllegalArgumentException.class, () -> new Position(-10, 1)); + IllegalArgumentException thrown1 = Assertions.assertThrows(IllegalArgumentException.class, + () -> new Position(-10, 1)); assertEquals("Can't position at line -10", thrown1.getMessage()); - IllegalArgumentException thrown2 = Assertions.assertThrows(IllegalArgumentException.class, () -> new Position(1, -10)); + IllegalArgumentException thrown2 = Assertions.assertThrows(IllegalArgumentException.class, + () -> new Position(1, -10)); assertEquals("Can't position at column -10", thrown2.getMessage()); } From 838c1803ef90d166c48d84923bc97c36a6066ace Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 17:57:43 +0000 Subject: [PATCH 044/280] Added additional tests --- .../model/resolution/SymbolReferenceTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java index 43de07a1a8..3b7a95a514 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java @@ -65,4 +65,23 @@ void testAdaptSymbolForSuperClass() { assertTrue(adaptedSymbol.getDeclaration().isPresent()); } + @Test + void testIsSolvedWithResolvedSymbol() { + ResolvedClassDeclaration resolvedDeclaration = new ReflectionClassDeclaration(String.class, typeSolver); + SymbolReference symbol = SymbolReference.solved(resolvedDeclaration); + + assertNotNull(symbol); + assertTrue(symbol.isSolved()); + assertEquals(resolvedDeclaration, symbol.getCorrespondingDeclaration()); + } + + @Test + void testIsSolvedWithUnresolvedSymbol() { + SymbolReference symbol = SymbolReference.unsolved(); + + assertNotNull(symbol); + assertFalse(symbol.isSolved()); + assertThrows(UnsupportedOperationException.class, symbol::getCorrespondingDeclaration); + } + } \ No newline at end of file From 0b3441a4d17546631431df71922f86f6dbf447d7 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 30 Oct 2022 17:57:58 +0000 Subject: [PATCH 045/280] Removed deprecated warning --- .../symbolsolver/model/resolution/SymbolReference.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index 287fb87904..80c3581fae 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -105,10 +105,7 @@ public Optional getDeclaration() { /** * The corresponding declaration. If not solve this throws UnsupportedOperationException. - * - * @deprecated This function is deprecated. Please consider using {@link #getDeclaration()} */ - @Deprecated public S getCorrespondingDeclaration() { Optional declaration = getDeclaration(); @@ -121,11 +118,7 @@ public S getCorrespondingDeclaration() { /** * Is the reference solved? - * - * @deprecated To check if the reference is solved, please consider using {@link #getDeclaration()} - * followed by {@link Optional#isPresent()}. */ - @Deprecated public boolean isSolved() { return getDeclaration().isPresent(); } From c4e42df47eead9cbd9341305afe02ec533857b7c Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Mon, 31 Oct 2022 08:55:07 +0000 Subject: [PATCH 046/280] Simplified solved symbol method --- .../symbolsolver/model/resolution/SymbolReference.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index 80c3581fae..bbd74f0b5c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -35,9 +35,13 @@ public class SymbolReference { /** - * Create a solve reference to the given symbol. + * Create a reference for a solved symbol. + * + * @return The created solved symbol reference. + * + * @param The symbol reference type. */ - public static SymbolReference solved(S2 symbolDeclaration) { + public static SymbolReference solved(S symbolDeclaration) { return new SymbolReference<>(symbolDeclaration); } From 01b704b2467223b8b415a46c1e519a74b806cb7b Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Mon, 31 Oct 2022 08:59:07 +0000 Subject: [PATCH 047/280] Revert "Simplified solved symbol method" This reverts commit c4e42df47eead9cbd9341305afe02ec533857b7c. --- .../symbolsolver/model/resolution/SymbolReference.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java index bbd74f0b5c..80c3581fae 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java @@ -35,13 +35,9 @@ public class SymbolReference { /** - * Create a reference for a solved symbol. - * - * @return The created solved symbol reference. - * - * @param The symbol reference type. + * Create a solve reference to the given symbol. */ - public static SymbolReference solved(S symbolDeclaration) { + public static SymbolReference solved(S2 symbolDeclaration) { return new SymbolReference<>(symbolDeclaration); } From e4bbc3b72754f751798158707395a3360d3e5286 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 31 Oct 2022 15:14:33 +0100 Subject: [PATCH 048/280] Remove or comment system.out.println statement in unit tests --- .../com/github/javaparser/Issue3064Test.java | 8 +- .../com/github/javaparser/JavaTokenTest.java | 21 ++-- .../LineSeparatorProcessorTest.java | 23 ++-- .../ast/visitor/ModifierVisitorTest.java | 18 ++-- .../ast/visitor/TreeVisitorTest.java | 17 +-- .../javaparser/issues/Issue2627Test.java | 101 ++++++++---------- .../javaparser/issues/Issue3255Test.java | 12 +-- .../printer/DefaultPrettyPrinterTest.java | 2 - .../javaparser/printer/PrettyPrinterTest.java | 1 - .../AnnotationSpaceTest.java | 7 +- .../lexicalpreservation/Issue1634Test.java | 10 +- .../lexicalpreservation/Issue2592Test.java | 22 ++-- .../lexicalpreservation/Issue2620Test.java | 21 ++-- .../PrettyPrinterIssue2351Test.java | 1 - .../utils/ParserCollectionStrategyTest.java | 28 +++-- .../symbolsolver/Issue1511Test.java | 16 +-- .../symbolsolver/Issue1526Test.java | 18 ++-- .../symbolsolver/Issue2044Test.java | 2 - .../symbolsolver/Issue2162Test.java | 20 ++-- .../symbolsolver/Issue2595Test.java | 23 ++-- .../symbolsolver/Issue2602Test.java | 16 +-- .../symbolsolver/Issue2740Test.java | 2 - .../symbolsolver/Issue2781Test.java | 1 - .../symbolsolver/Issue2909Test.java | 1 - .../model/typesystem/ReferenceTypeTest.java | 2 - .../ReflectionClassDeclarationTest.java | 13 +-- .../symbolsolver/resolution/ContextTest.java | 67 +++++++----- .../resolution/InstanceOfTest.java | 28 ----- .../MethodReferenceResolutionTest.java | 21 ++-- .../resolution/VariadicResolutionTest.java | 16 +-- .../MethodCallExprContextResolutionTest.java | 3 - 31 files changed, 241 insertions(+), 300 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java index a1043d7b5c..f84b42b640 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java @@ -1,11 +1,12 @@ package com.github.javaparser; -import com.github.javaparser.ast.CompilationUnit; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.StringReader; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + +import com.github.javaparser.ast.CompilationUnit; public class Issue3064Test { @@ -24,7 +25,6 @@ public void test0() { ParseResult unitOpt = parser.parse(new StringReader(str)); unitOpt.getProblems().stream().forEach(p -> System.err.println(p.toString())); CompilationUnit unit = unitOpt.getResult().orElseThrow(() -> new IllegalStateException("Could not parse file")); - System.out.println(unit.toString()); assertEquals(str, unit.toString()); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java index 4316320978..2ff98e811f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java @@ -21,12 +21,6 @@ package com.github.javaparser; -import com.github.javaparser.ast.expr.Expression; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Field; -import java.util.Iterator; - import static com.github.javaparser.GeneratedJavaParserConstants.*; import static com.github.javaparser.JavaToken.Category.COMMENT; import static com.github.javaparser.JavaToken.Category.LITERAL; @@ -38,6 +32,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.lang.reflect.Field; +import java.util.Iterator; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.ast.expr.Expression; + class JavaTokenTest { @Test @@ -108,10 +109,10 @@ void test() throws NoSuchFieldException, IllegalAccessException { // Optional printing -- for debugging purposes. - System.out.println(i + " - " + - jpTokenName + " (" + jpTokenNumber + ") - " + - javaCcTokenName + " (" + javaccTokenNumber + ")" - ); +// System.out.println(i + " - " + +// jpTokenName + " (" + jpTokenNumber + ") - " + +// javaCcTokenName + " (" + javaccTokenNumber + ")" +// ); assertEquals(jpTokenName, javaCcTokenName); assertEquals( diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java index a283018135..f279a1fc17 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java @@ -1,5 +1,13 @@ package com.github.javaparser; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; @@ -10,11 +18,6 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import com.github.javaparser.utils.LineSeparator; -import org.junit.jupiter.api.Test; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; public class LineSeparatorProcessorTest { @@ -58,12 +61,12 @@ public void doTest(LineSeparator lineSeparator) { cd.get().getMembers().addFirst(fd); // should be printed like this - System.out.println("\n\nOriginal:\n" + original); - System.out.println("\n\nExpected:\n" + expected); +// System.out.println("\n\nOriginal:\n" + original); +// System.out.println("\n\nExpected:\n" + expected); // but the result is final String actual = LexicalPreservingPrinter.print(cu); - System.out.println("\n\nActual:\n" + actual); +// System.out.println("\n\nActual:\n" + actual); // The LineEndingProcessingProvider sets the line ending to the root node. @@ -71,8 +74,8 @@ public void doTest(LineSeparator lineSeparator) { LineSeparator lineSeparator_cu = cu.getLineEndingStyle(); LineSeparator lineSeparator_fd = fd.getLineEndingStyle(); - System.out.println("lineSeparator_cu.describe() = " + lineSeparator_cu.describe()); - System.out.println("lineSeparator_fd.describe() = " + lineSeparator_fd.describe()); +// System.out.println("lineSeparator_cu.describe() = " + lineSeparator_cu.describe()); +// System.out.println("lineSeparator_fd.describe() = " + lineSeparator_fd.describe()); // Assert that it has been detected and injected correctly. LineSeparator detectedLineSeparator = LineSeparator.detect(actual); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java index c6071eefe5..ee718ceec8 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java @@ -21,6 +21,14 @@ package com.github.javaparser.ast.visitor; +import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; @@ -30,13 +38,6 @@ import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; -import org.junit.jupiter.api.Test; - -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; class ModifierVisitorTest { @Test @@ -140,6 +141,7 @@ void issue2124() { "}"); LexicalPreservingPrinter.setup(cu); cu.accept(modifier, null); - System.out.println(LexicalPreservingPrinter.print(cu)); + //there should be no exception + LexicalPreservingPrinter.print(cu); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java index b2ebb7ca88..ed5845bfcc 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java @@ -21,19 +21,20 @@ package com.github.javaparser.ast.visitor; +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.ArrayInitializerExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.SimpleName; -import org.junit.jupiter.api.Test; - -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; class TreeVisitorTest { @Test @@ -69,7 +70,7 @@ public void process(Node node) { } }; visitor.visitPreOrder(expression); - System.out.println(result); +// System.out.println(result); } @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java index 8b3c39b423..4f154964f3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java @@ -1,24 +1,19 @@ package com.github.javaparser.issues; -import com.github.javaparser.JavaToken; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + import com.github.javaparser.Range; import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.TokenRange; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.comments.Comment; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue2627Test { @@ -58,7 +53,6 @@ private void assertMethodInExpectedLines(CompilationUnit cu, String name, int ex private void assertNodeInExpectedLines(Node node, int expectedStartLine, int expectedEndLine) { Range range = node.getRange().get(); - System.out.println("range = " + range); assertEquals(expectedStartLine, range.begin.line); assertEquals(expectedEndLine, range.end.line); @@ -71,50 +65,39 @@ private MethodDeclaration getFirstMethodDeclarationByName(CompilationUnit cu, St .get(); } - @Test - public void cuLength_minimal() throws IOException { - CompilationUnit cu = StaticJavaParser.parseResource(RESOURCE_PATH_STRING_MINIMAL); - - final Range cuRange = cu.getRange().get(); - System.out.println("cu.getRange().get() = " + cuRange); - - int lineCount = cuRange.end.line - cuRange.begin.line; - System.out.println("lineCount = " + lineCount); - - assertNodeInExpectedLines(cu, 1, 265); - } - - @Test - public void commentPositions_minimal() throws IOException { - CompilationUnit cu = StaticJavaParser.parseResource(RESOURCE_PATH_STRING_MINIMAL); - - List allComments = cu.getAllComments(); - for (int i = 0; i < allComments.size(); i++) { - Comment comment = allComments.get(i); - Optional optionalRange = comment.getRange(); - if (optionalRange.isPresent()) { - Range range = optionalRange.get(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(i + ": "); - System.out.println("range = " + range); - System.out.println("comment = " + "\n" + comment.getContent()); - final TokenRange tokens = comment.getTokenRange().get(); - int tokenIndex = 0; - for (JavaToken token : tokens) { - System.out.println("token " + tokenIndex + " = " + token); - tokenIndex++; - } - System.out.println(tokens); - } - } - - -// assertNodeInExpectedLines(cu, 1, 288); - } +// @Test +// public void cuLength_minimal() throws IOException { +// CompilationUnit cu = StaticJavaParser.parseResource(RESOURCE_PATH_STRING_MINIMAL); +// +// final Range cuRange = cu.getRange().get(); +// +// int lineCount = cuRange.end.line - cuRange.begin.line; +// +// } + +// @Test +// public void commentPositions_minimal() throws IOException { +// CompilationUnit cu = StaticJavaParser.parseResource(RESOURCE_PATH_STRING_MINIMAL); +// +// List allComments = cu.getAllComments(); +// for (int i = 0; i < allComments.size(); i++) { +// Comment comment = allComments.get(i); +// Optional optionalRange = comment.getRange(); +// if (optionalRange.isPresent()) { +// Range range = optionalRange.get(); +// final TokenRange tokens = comment.getTokenRange().get(); +// int tokenIndex = 0; +// for (JavaToken token : tokens) { +// System.out.println("token " + tokenIndex + " = " + token); +// tokenIndex++; +// } +// System.out.println(tokens); +// } +// } +// +// +//// assertNodeInExpectedLines(cu, 1, 288); +// } @ParameterizedTest @MethodSource("arguments_minimal") diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java index 02279394be..9ca37cb389 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java @@ -1,13 +1,14 @@ package com.github.javaparser.issues; +import static com.github.javaparser.utils.TestParser.parseStatement; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.utils.LineSeparator; -import org.junit.jupiter.api.Test; - -import static com.github.javaparser.utils.TestParser.parseStatement; -import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3255Test { @@ -26,7 +27,6 @@ public void test() { assertEquals(0, parseResult.getProblems().size()); CompilationUnit compilationUnit = parseResult.getResult().get(); - System.out.println(compilationUnit); } @Test @@ -42,7 +42,6 @@ public void test2() { assertEquals(0, parseResult.getProblems().size()); CompilationUnit compilationUnit = parseResult.getResult().get(); - System.out.println(compilationUnit); } @Test @@ -62,7 +61,6 @@ public void recordIsAValidVariableNameWhenUsedInAClass() { assertEquals(0, parseResult.getProblems().size()); CompilationUnit compilationUnit = parseResult.getResult().get(); - System.out.println(compilationUnit); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java index d7f3e34677..0612c13ecd 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java @@ -189,7 +189,6 @@ void prettyAlignMethodCallChains_enabled() { ""; String printed = getDefaultPrinter(configuration).print(parse(code)); - System.out.println(printed); assertEquals(expected, printed); } @@ -520,7 +519,6 @@ public void testIssue2578() { TypeDeclaration td = cu.findFirst(TypeDeclaration.class).get(); assertEquals(2, td.getAllContainedComments().size()); td.setPublic(true); // --- simple AST change ----- - System.out.println(cu.toString()); // orphan and /*orphan*/ must be printed assertEquals(2, td.getAllContainedComments().size()); // the orphaned comments exist } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java index 84b0fa4efa..863eb9b043 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java @@ -532,7 +532,6 @@ public void testIssue2578() { TypeDeclaration td = cu.findFirst(TypeDeclaration.class).get(); assertEquals(2, td.getAllContainedComments().size()); td.setPublic(true); // --- simple AST change ----- - System.out.println(cu.toString()); // orphan and /*orphan*/ must be printed assertEquals(2, td.getAllContainedComments().size()); // the orphaned comments exist } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java index 6f265fddc4..7ffb75c58e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java @@ -23,12 +23,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Optional; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MarkerAnnotationExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import java.util.Optional; -import org.junit.jupiter.api.Test; public class AnnotationSpaceTest { /** Tests that inserted annotations on types are followed by a space. */ @@ -45,7 +47,6 @@ public void test() { Optional type = cu.findFirst(ClassOrInterfaceType.class); type.get().addAnnotation(new MarkerAnnotationExpr("Nullable")); String result = LexicalPreservingPrinter.print(cu); - System.out.println(result); // Verify that there's a space between the annotation and the String type. assertTrue(result.contains("@Nullable String")); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java index f59896607b..a5e7b6c26f 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java @@ -1,5 +1,7 @@ package com.github.javaparser.printer.lexicalpreservation; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.Test; import com.github.javaparser.StaticJavaParser; @@ -13,6 +15,12 @@ public class Issue1634Test extends AbstractLexicalPreservingTest { public void testWithLexicalPreservationEnabled() { String actual = "package com.wangym.test;\nclass A{ }"; + + String expected = + "package com.wangym.test;\n" + + "import lombok.Data;\n" + + "\n" + + "class A{ }"; CompilationUnit cu = StaticJavaParser.parse(actual); LexicalPreservingPrinter.setup(cu); @@ -21,6 +29,6 @@ public void testWithLexicalPreservationEnabled() { String str = "lombok.Data"; imports.add(new ImportDeclaration(str, false, false)); - System.out.println(LexicalPreservingPrinter.print(cu)); + assertEquals(expected, LexicalPreservingPrinter.print(cu)); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java index b053f5f5ac..1905d87f82 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java @@ -1,16 +1,16 @@ package com.github.javaparser.printer.lexicalpreservation; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; -import org.junit.jupiter.api.Test; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue2592Test { @@ -34,8 +34,6 @@ public void testLPP() { LexicalPreservingPrinter.setup(cu); //all parameters have parent nodes here - System.out.println(""); - md.get().getParameters().forEach(p -> System.out.println(p + " parent " + p.getParentNode().isPresent())); assertTrue(md.get().getParameters().stream().allMatch(p -> p.getParentNode().isPresent())); @@ -46,21 +44,17 @@ public void testLPP() { assertTrue(md.get().getParameters().stream().allMatch(p -> p.getParentNode().isPresent())); - System.out.println(""); - md.get().getParameters().forEach(p -> System.out.println(p + " parent " + p.getParentNode().isPresent())); +// md.get().getParameters().forEach(p -> System.out.println(p + " parent " + p.getParentNode().isPresent())); Parameter p1 = md.get().getParameter(0); Parameter p2 = new Parameter(p1.getModifiers(), p1.getType(), new SimpleName("a_renamed")); //here we replace a parameter boolean isReplaced = md.get().replace(p1, p2); assertTrue(isReplaced); //the replacement seemed to work - System.out.println(""); - System.out.println(cu.toString()); //this looks right //...however when we replaced the parent nodes (for the replaced node AND the added node (after the replaced node) now null - System.out.println(""); - md.get().getParameters().forEach(p -> System.out.println(p + " parent " + p.getParentNode().isPresent())); +// md.get().getParameters().forEach(p -> System.out.println(p + " parent " + p.getParentNode().isPresent())); assertTrue(md.get().getParameters().stream().allMatch(p -> p.getParentNode().isPresent())); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java index 904a281014..ae3e57b7cd 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java @@ -21,6 +21,14 @@ package com.github.javaparser.printer.lexicalpreservation; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.Optional; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; @@ -30,13 +38,6 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.utils.LineSeparator; -import org.junit.jupiter.api.Test; - -import java.util.Optional; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; public class Issue2620Test { @@ -94,12 +95,12 @@ public void doTest(LineSeparator eol) { cd.get().getMembers().addFirst(fd); // should be printed like this - System.out.println("\n\nOriginal:\n" + original); - System.out.println("\n\nExpected:\n" + expected); +// System.out.println("\n\nOriginal:\n" + original); +// System.out.println("\n\nExpected:\n" + expected); // but the result is final String actual = LexicalPreservingPrinter.print(cu); - System.out.println("\n\nActual:\n" + actual); +// System.out.println("\n\nActual:\n" + actual); LineSeparator detectedLineSeparator = LineSeparator.detect(actual); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java index 0064872fd4..0a67dd70e1 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java @@ -41,7 +41,6 @@ void printingEnum2() { considerCode(def2); Optional decl = cu.findFirst(EnumDeclaration.class); if (decl.isPresent()) decl.get().addEnumConstant("SOMETHING"); - System.out.println(LexicalPreservingPrinter.print(cu)); assertTrue(decl.get().getEntries().size() == 2); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java index 4237a13e41..e02650e4e5 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java @@ -21,22 +21,20 @@ package com.github.javaparser.utils; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ParserConfiguration.LanguageLevel; -import com.github.javaparser.ast.CompilationUnit; -import org.junit.jupiter.api.Test; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; +import static com.github.javaparser.utils.CodeGenerationUtils.mavenModuleRoot; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; -import static com.github.javaparser.utils.CodeGenerationUtils.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; class ParserCollectionStrategyTest { @@ -99,10 +97,10 @@ void rootsAreFound_parentOfMultipleSourceRootsWithAndWithoutModuleInfo() { List sourceRoots = projectRoot.getSourceRoots(); - for (SourceRoot sourceRoot : sourceRoots) { - sourceRoot.getRoot().normalize().endsWith("with_module_info"); - System.out.println(sourceRoot); - } +// for (SourceRoot sourceRoot : sourceRoots) { +// sourceRoot.getRoot().normalize().endsWith("with_module_info"); +// System.out.println(sourceRoot); +// } assertEquals(3, sourceRoots.size()); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1511Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1511Test.java index b86db4ea66..5478cb1eb0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1511Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1511Test.java @@ -21,6 +21,14 @@ package com.github.javaparser.symbolsolver; +import static com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest.adaptPath; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.FileNotFoundException; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; @@ -31,13 +39,6 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; -import org.junit.jupiter.api.Test; - -import java.io.FileNotFoundException; -import java.nio.file.Path; - -import static com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest.adaptPath; -import static org.junit.jupiter.api.Assertions.assertEquals; /** * IndexOutOfBoundsException when attempting to resolve super() #1511 @@ -80,7 +81,6 @@ public void exploratory_resolveAndGetSuperClass() { CompilationUnit foo = javaParser.parse("class A {}").getResult().orElseThrow(IllegalStateException::new); ResolvedReferenceType a = foo.getClassByName("A").orElseThrow(IllegalStateException::new).resolve().asClass().getSuperClass().get(); - System.out.println("a = " + a); assertEquals("java.lang.Object", a.getQualifiedName()); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1526Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1526Test.java index 48db1361e8..7f44c12d49 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1526Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1526Test.java @@ -21,6 +21,15 @@ package com.github.javaparser.symbolsolver; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import java.io.IOException; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ast.CompilationUnit; @@ -30,14 +39,6 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.nio.file.Path; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assumptions.assumeTrue; /** @@ -83,7 +84,6 @@ private void doTest(Path root, Path file) throws IOException { cu.getResult().get().findAll(MethodCallExpr.class) .forEach(methodCallExpr -> { - System.out.println(methodCallExpr); methodCallExpr.resolve(); methodCallExpr.calculateResolvedType(); }); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java index 570a2a3a42..aa9a8e03ba 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java @@ -131,10 +131,8 @@ private void doTest(String x) { JavaParser javaParser = new JavaParser(configuration); ParseResult result = javaParser.parse(ParseStart.COMPILATION_UNIT, provider(x)); - System.out.println(result.isSuccessful()); result.ifSuccessful(compilationUnit -> { final List methodDeclarations = compilationUnit.findAll(MethodDeclaration.class); - System.out.println(methodDeclarations.size()); methodDeclarations.forEach(methodDeclaration -> { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java index ffab7f4d4b..e059ce0451 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java @@ -21,6 +21,16 @@ package com.github.javaparser.symbolsolver; +import static com.github.javaparser.Providers.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParseStart; @@ -32,13 +42,6 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assertions.*; /** * @see https://github.com/javaparser/javaparser/issues/2162 @@ -103,8 +106,7 @@ public void setUp() { ); - System.out.println("parseResult = " + parseResult); - parseResult.getProblems().forEach(problem -> System.out.println("problem.getVerboseMessage() = " + problem.getVerboseMessage())); +// parseResult.getProblems().forEach(problem -> System.out.println("problem.getVerboseMessage() = " + problem.getVerboseMessage())); assertTrue(parseResult.isSuccessful()); assertEquals(0, parseResult.getProblems().size(), "Expected zero errors when attempting to parse the input code."); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java index c83de02d65..0d3a66c980 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java @@ -1,5 +1,13 @@ package com.github.javaparser.symbolsolver; +import static com.github.javaparser.Providers.provider; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import java.util.List; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParseStart; @@ -9,13 +17,6 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assumptions.assumeFalse; -import static org.junit.jupiter.api.Assumptions.assumeTrue; public class Issue2595Test { @@ -142,17 +143,9 @@ private void parse(String sourceCode) { assumeTrue(result.getResult().isPresent()); CompilationUnit cu = result.getResult().get(); -// System.out.println(cu); List methodCalls = cu.findAll(MethodCallExpr.class); assumeFalse(methodCalls.isEmpty()); - for (int i = methodCalls.size() - 1; i >= 0; i--) { - MethodCallExpr methodCallExpr = methodCalls.get(i); - System.out.println(); - System.out.println("methodCallExpr = " + methodCallExpr); - System.out.println("methodCallExpr.resolve() = " + methodCallExpr.resolve()); - System.out.println("methodCallExpr.calculateResolvedType() = " + methodCallExpr.calculateResolvedType()); - } } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2602Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2602Test.java index 4c92cbd82c..ee4c929695 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2602Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2602Test.java @@ -1,5 +1,13 @@ package com.github.javaparser.symbolsolver; +import static com.github.javaparser.Providers.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParseStart; @@ -11,11 +19,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assertions.*; public class Issue2602Test extends AbstractSymbolResolutionTest { @@ -47,8 +50,7 @@ public void setUp() { ); - System.out.println("parseResult = " + parseResult); - parseResult.getProblems().forEach(problem -> System.out.println("problem.getVerboseMessage() = " + problem.getVerboseMessage())); +// parseResult.getProblems().forEach(problem -> System.out.println("problem.getVerboseMessage() = " + problem.getVerboseMessage())); assertTrue(parseResult.isSuccessful()); assertEquals(0, parseResult.getProblems().size(), "Expected zero errors when attempting to parse the input code."); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java index 8b4ebdc43a..534b5597f1 100755 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java @@ -43,9 +43,7 @@ void test() { CompilationUnit cu = StaticJavaParser.parse(code); List methodCallExpr = cu.findAll(MethodCallExpr.class); for (MethodCallExpr expr : methodCallExpr) { - System.out.println("trying to solde " + expr.toString()); ResolvedMethodDeclaration rd = expr.resolve(); - System.out.println(String.format("%s solved to %s", expr.toString(), rd.getQualifiedSignature())); } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java index 0fd8011599..59bac72dab 100755 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java @@ -42,7 +42,6 @@ void test() throws FileNotFoundException { constructorDeclaration.findAll(MethodCallExpr.class).forEach(methodCallExpr -> { //Exception in thread "main" java.lang.StackOverflowError ResolvedMethodDeclaration rmd = methodCallExpr.resolve(); - System.out.println(rmd.getQualifiedName()); }); }); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java index da69dc0a27..21a86d7682 100755 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java @@ -118,7 +118,6 @@ void testInDepth() { CompilationUnit cu = StaticJavaParser.parse(s); List exprs = cu.findAll(ThisExpr.class); exprs.forEach(expr-> { - System.out.println(String.format("%s is resolved to %s", expr.toString(), expr.calculateResolvedType().describe())); assertEquals("test.Program.FarOuterClass.OuterClass",expr.calculateResolvedType().describe()); }); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index 5c5ebd402a..08e6cdfcdb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -807,7 +807,6 @@ void testDirectAncestorsOfClassWithInterfaces() { // FIXME: Remove this temporary fix which varies the test based on the detected JDK which is running these tests. TestJdk currentJdk = TestJdk.getCurrentHostJdk(); - System.out.println("currentJdk = " + currentJdk); if (currentJdk.getMajorVersion() < 12) { // JDK 12 introduced "java.lang.constant.Constable" assertThat(ancestors, containsInAnyOrder( @@ -818,7 +817,6 @@ void testDirectAncestorsOfClassWithInterfaces() { )); } else { // JDK 12 introduced "java.lang.constant.Constable" - System.out.println("ancestors = " + ancestors); assertThat(ancestors, containsInAnyOrder( "java.lang.CharSequence", "java.lang.Object", diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java index da5062d5a1..212042f4e0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java @@ -27,16 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.Serializable; -import java.util.AbstractCollection; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.RandomAccess; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -425,7 +416,7 @@ void testGetInterfacesWithoutParameters() { @Test void testGetInterfacesWithParameters() { ReflectionClassDeclaration constructorDeclaration = (ReflectionClassDeclaration) typeResolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); - System.out.println(constructorDeclaration.getInterfaces().stream().map(t -> t.getQualifiedName()).collect(Collectors.toList())); +// System.out.println(constructorDeclaration.getInterfaces().stream().map(t -> t.getQualifiedName()).collect(Collectors.toList())); assertEquals(8, constructorDeclaration.getInterfaces().size()); ResolvedReferenceType interfaze; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 9a407c4008..08df65e928 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -21,13 +21,45 @@ package com.github.javaparser.symbolsolver.resolution; -import com.github.javaparser.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParseStart; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.StringProvider; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.*; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.ForEachStmt; +import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; @@ -42,21 +74,12 @@ import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.typesolvers.*; +import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class ContextTest extends AbstractSymbolResolutionTest { @@ -1298,7 +1321,6 @@ void instanceOfPatternExprResolution1() { Context context = JavaParserFactory.getContext(nameExpr, typeSolver); SymbolReference symbolReference = context.solveSymbol("s"); - System.out.println("symbolReference = " + symbolReference); assertTrue(symbolReference.isSolved(), "symbol not solved"); ResolvedDeclaration correspondingDeclaration = symbolReference.getCorrespondingDeclaration(); @@ -1326,7 +1348,6 @@ void instanceOfPatternExprResolution1_negated() { Context context = JavaParserFactory.getContext(nameExpr, typeSolver); SymbolReference symbolReference = context.solveSymbol("s"); - System.out.println("symbolReference = " + symbolReference); assertFalse(symbolReference.isSolved(), "symbol supposed to be not solved"); } @@ -1348,7 +1369,6 @@ void instanceOfPatternExprResolution2() { Context context = JavaParserFactory.getContext(nameExpr, typeSolver); SymbolReference symbolReference = context.solveSymbol("s"); - System.out.println("symbolReference = " + symbolReference); assertFalse(symbolReference.isSolved(), "symbol supposed to be not solved"); } @@ -1367,7 +1387,6 @@ void instanceOfPattern_ifBlock1() { IfStmt ifStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.STATEMENT).asIfStmt(); List methodCallExprs = ifStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(1, methodCallExprs.size()); MethodCallExpr methodCallExpr = methodCallExprs.get(0); @@ -1388,7 +1407,6 @@ void instanceOfPattern_ifBlock1_noBraces() { IfStmt ifStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.STATEMENT).asIfStmt(); List methodCallExprs = ifStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(1, methodCallExprs.size()); MethodCallExpr methodCallExpr = methodCallExprs.get(0); @@ -1409,7 +1427,6 @@ void instanceOfPattern_ifBlock1_negatedCondition() { IfStmt ifStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.STATEMENT).asIfStmt(); List methodCallExprs = ifStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(1, methodCallExprs.size()); MethodCallExpr methodCallExpr = methodCallExprs.get(0); @@ -1429,7 +1446,6 @@ void instanceOfPattern_ifBlock1_noBraces_negatedCondition() { IfStmt ifStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.STATEMENT).asIfStmt(); List methodCallExprs = ifStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(1, methodCallExprs.size()); MethodCallExpr methodCallExpr = methodCallExprs.get(0); @@ -1454,7 +1470,6 @@ void instanceOfPattern_ifElseBlock1() { BlockStmt blockStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.BLOCK).asBlockStmt(); List methodCallExprs = blockStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(2, methodCallExprs.size()); // The first one should resolve to the standard variable (the list) @@ -1492,7 +1507,6 @@ void instanceOfPattern_ifElseBlock2() { BlockStmt blockStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.BLOCK).asBlockStmt(); List methodCallExprs = blockStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(4, methodCallExprs.size()); // The first one should resolve to the standard variable (the list) @@ -1544,7 +1558,6 @@ void instanceOfPattern_ifElseBlock3() { BlockStmt blockStmt = parse(ParserConfiguration.LanguageLevel.JAVA_14_PREVIEW, x, ParseStart.BLOCK).asBlockStmt(); List methodCallExprs = blockStmt.findAll(MethodCallExpr.class); - System.out.println("methodCallExprs = " + methodCallExprs); assertEquals(4, methodCallExprs.size()); // The first one should resolve to the standard variable (the list) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java index 2702f28f27..36802c882f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java @@ -232,8 +232,6 @@ public void variableInBlock_shouldNotResolveOnFollowingLines() { // Expected to not be able to resolve s, as out of scope within an else block. assertThrows(UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); }); } @@ -252,9 +250,6 @@ public void variableInBlock_mustNotResolveBeforeDeclaration() { UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); - System.out.println("erroneously solved:: outOfScopeMethodCall = " + outOfScopeMethodCall); }, "Error: Variable defined within a pattern expression is used before it is declared - should not be resolved, but is." ); @@ -275,7 +270,6 @@ public void logicalAndShouldResolve() { // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = inScopeMethodCall.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); assertEquals("java.lang.String.contains(java.lang.CharSequence)", resolve.getQualifiedSignature()); assertEquals("boolean", resolve.getReturnType().describe()); @@ -306,9 +300,6 @@ public void logicalOrShouldNotResolve() { UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); - System.out.println("erroneously solved:: outOfScopeMethodCall = " + outOfScopeMethodCall); }, "Error: Variable defined within a pattern expression should not be available on the right hand side of an || operator." ); @@ -333,7 +324,6 @@ public void condition_rightBranch_logicalAndShouldResolveWithCorrectBreakdowns() // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = inScopeMethodCall.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); assertEquals("java.lang.String.contains(java.lang.CharSequence)", resolve.getQualifiedSignature()); assertEquals("boolean", resolve.getReturnType().describe()); @@ -372,7 +362,6 @@ public void condition_rightBranch_nameExprResolves() { NameExpr nameExpr = nameExprs.get(0); ResolvedValueDeclaration resolvedNameExpr = nameExpr.resolve(); - System.out.println(resolvedNameExpr); } @@ -395,10 +384,8 @@ public void condition_rightBranch_methodCallResolves() { MethodCallExpr methodCallExpr = methodCallExprs.get(0); ResolvedType resolvedType = methodCallExpr.calculateResolvedType(); - System.out.println("resolvedType = " + resolvedType); ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve(); - System.out.println("resolvedMethodDeclaration = " + resolvedMethodDeclaration); } @@ -413,8 +400,6 @@ public void condition_leftBranchMethodCall_doesNotResolve() { // Expected to not be able to resolve s, as out of scope within an else block. assertThrows(UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); }); } } @@ -443,9 +428,6 @@ public void givenInstanceOfPattern_whenSolvingInvalidNotInScope_thenFails() { // Expected to not be able to resolve s, as out of scope within an else block. assertThrows(UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); - System.out.println("erroneously solved:: outOfScopeMethodCall = " + outOfScopeMethodCall); }); } @@ -461,7 +443,6 @@ public void givenInstanceOfPattern_whenSolvingValidInScope_thenSuccessful() { // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = inScopeMethodCall.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); assertEquals("java.lang.String.contains(java.lang.CharSequence)", resolve.getQualifiedSignature()); assertEquals("boolean", resolve.getReturnType().describe()); @@ -490,7 +471,6 @@ public void givenInstanceOfPattern_andField_else_skipBraces_thenResolvesToPatter // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = methodCallExprInElse.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); // The method call in the else block should be in scope of the pattern (String) due to the negated condition assertEquals("java.lang.String.contains(java.lang.CharSequence)", resolve.getQualifiedSignature()); @@ -511,7 +491,6 @@ public void givenInstanceOfPattern_andField_skipBraces_thenResolvesToPattern() { // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); // Should resolve to the field (List.contains()), not the pattern expression (String.contains()) assertEquals("java.util.List.contains(java.lang.Object)", resolve.getQualifiedSignature()); @@ -532,7 +511,6 @@ public void givenInstanceOfPattern_andField_thenResolvesToField() { // Resolving the method call .contains() final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - System.out.println("resolve.getQualifiedSignature() = " + resolve.getQualifiedSignature()); // Should resolve to the field (List.contains()), not the pattern expression (String.contains()) assertEquals("java.util.List.contains(java.lang.Object)", resolve.getQualifiedSignature()); @@ -555,8 +533,6 @@ public void test_shouldFail() { // Expected to not be able to resolve s, as out of scope within an else block. assertThrows(UnsolvedSymbolException.class, () -> { final ResolvedMethodDeclaration resolve = outOfScopeMethodCall.resolve(); - // Note: Only printed if the above line doesn't error... - System.out.println("resolve = " + resolve); }); } @@ -571,7 +547,6 @@ public void test() { MethodDeclaration methodDeclaration = getMethodByName("localVariable_shouldNotResolve"); List nameExprs = methodDeclaration.findAll(NameExpr.class); - System.out.println("nameExprs = " + nameExprs); assertEquals(2, nameExprs.size()); @@ -579,9 +554,6 @@ public void test() { ResolvedValueDeclaration resolvedNameExpr = nameExpr.resolve(); ResolvedType resolvedNameExprType = nameExpr.calculateResolvedType(); - System.out.println("resolvedNameExpr = " + resolvedNameExpr); - System.out.println("resolvedNameExprType = " + resolvedNameExprType); - } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java index 177e468bbd..2b11baf035 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java @@ -21,6 +21,13 @@ package com.github.javaparser.symbolsolver.resolution; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -34,12 +41,6 @@ import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; class MethodReferenceResolutionTest extends AbstractResolutionTest { @@ -443,10 +444,7 @@ public void issue2657Test_StringValueOfInStream() { for (MethodCallExpr expr : methodCallExpr) { try { ResolvedMethodDeclaration rd = expr.resolve(); - System.out.println("\t Solved : " + rd.getQualifiedSignature()); } catch (UnsolvedSymbolException e) { - System.out.println("\t UNSOLVED: " + expr.toString()); - e.printStackTrace(); errorCount++; } } @@ -482,7 +480,6 @@ public void instanceMethodReferenceTest() { for (MethodCallExpr expr : methodCallExpr) { ResolvedMethodDeclaration rd = expr.resolve(); - System.out.println("\t Solved : " + rd.getQualifiedSignature()); } assertEquals(0, errorCount, "Expected zero UnsolvedSymbolException s"); @@ -525,7 +522,6 @@ public void unboundNonStaticMethodsTest() { for (MethodCallExpr expr : methodCallExpr) { ResolvedMethodDeclaration rd = expr.resolve(); - System.out.println("\t Solved : " + rd.getQualifiedSignature()); } assertEquals(0, errorCount, "Expected zero UnsolvedSymbolException s"); @@ -560,10 +556,7 @@ public void testIssue3289() { for (MethodReferenceExpr expr : methodeRefExpr) { try { ResolvedMethodDeclaration md = expr.resolve(); - System.out.println("\t Solved : " + md.getQualifiedSignature()); } catch (UnsolvedSymbolException e) { - System.out.println("\t UNSOLVED: " + expr.toString()); - e.printStackTrace(); errorCount++; } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java index 63de7e3537..48978818bc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java @@ -21,6 +21,14 @@ package com.github.javaparser.symbolsolver.resolution; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; @@ -36,13 +44,6 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration; -import org.junit.jupiter.api.Test; - -import java.nio.file.Path; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; class VariadicResolutionTest extends AbstractResolutionTest { @@ -113,7 +114,6 @@ void selectMostSpecificVariadic() { assertThrows(RuntimeException.class, () -> { MethodUsage call5 = javaParserFacade.solveMethodAsUsage(calls.get(4)); - System.out.println("call5.returnType().describe() = " + call5.returnType().describe()); }); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index ced13595fe..10a61a1d4d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -185,10 +185,7 @@ public void testResolveChainedCallOnReflectionType() throws Exception { for (MethodCallExpr expr : methodCallExpr) { try { ResolvedMethodDeclaration rd = expr.resolve(); - System.out.println("\t Solved : " + rd.getQualifiedSignature()); } catch (UnsolvedSymbolException e) { - System.out.println("\t UNSOLVED: " + expr.toString()); - e.printStackTrace(); errorCount++; } } From 9ceae788a251ba322ac31d48ead96357fe61e986 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Mon, 31 Oct 2022 21:07:14 +0000 Subject: [PATCH 049/280] Updated Badge for Build and Coverage --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 1ee974978b..5cae8f098d 100644 --- a/readme.md +++ b/readme.md @@ -7,8 +7,8 @@ # JavaParser [![Maven Central](https://img.shields.io/maven-central/v/com.github.javaparser/javaparser-core.svg)](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.javaparser%22%20AND%20a%3A%22javaparser-core%22) -[![Build Status](https://travis-ci.org/javaparser/javaparser.svg?branch=master)](https://travis-ci.org/javaparser/javaparser) -[![Coverage Status](https://coveralls.io/repos/javaparser/javaparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/javaparser/javaparser?branch=master) +[![Build Status](https://github.com/javaparser/javaparser/actions/workflows/maven_tests.yml/badge.svg?branch=master)](https://github.com/javaparser/javaparser/actions/workflows/maven_tests.yml) +[![Coverage Status](https://codecov.io/gh/javaparser/javaparser/branch/master/graphs/badge.svg?branch=master)](https://app.codecov.io/gh/javaparser/javaparser?branch=master) [![Join the chat at https://gitter.im/javaparser/javaparser](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/javaparser/javaparser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![License LGPL-3/Apache-2.0](https://img.shields.io/badge/license-LGPL--3%2FApache--2.0-blue.svg)](LICENSE) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2667378.svg)](https://doi.org/10.5281/zenodo.2667378) From 7004e4dc43ee471e54e1ea7225882f04f1fc5088 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 1 Nov 2022 10:22:05 +0100 Subject: [PATCH 050/280] Fix issue #3728 ParseProblemException --- .../version/Java10PostProcessorTest.java | 26 +++++++++++------ .../postprocessors/Java10PostProcessor.java | 28 ++++++++++++++++--- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java index 7cd6d5b5e9..10b104308e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java @@ -21,19 +21,20 @@ package com.github.javaparser.version; +import static com.github.javaparser.ParseStart.STATEMENT; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_10; +import static com.github.javaparser.Providers.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.VarType; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_10; -import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assertions.assertEquals; class Java10PostProcessorTest { public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLanguageLevel(JAVA_10)); @@ -46,4 +47,13 @@ void varIsAType() { assertEquals(1, allVarTypes.size()); } + + @Test + void expressionThatShouldNotBeInterpretedAsAVarType() { + ParseResult result = javaParser.parse(STATEMENT, provider("var.class.getName();")); + + List allVarTypes = result.getResult().get().findAll(VarType.class); + + assertEquals(0, allVarTypes.size()); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java index 61bf8c5500..d851c43b3c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java @@ -20,10 +20,15 @@ */ package com.github.javaparser.ast.validator.postprocessors; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.Processor; import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.ClassExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.VarType; @@ -31,20 +36,35 @@ * Processes the generic AST into a Java 10 AST and validates it. */ public class Java10PostProcessor extends PostProcessors { + + // List of parent contexts in which a var type must not be detected. + // for example: in this statement var.class.getCanonicalName(), var must not be considered as a VarType + private static List FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE = new ArrayList<>(); + static { + FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.addAll(Arrays.asList(ClassExpr.class)); + } protected final Processor varNodeCreator = new Processor() { @Override public void postProcess(ParseResult result, ParserConfiguration configuration) { result.getResult().ifPresent(node -> { - node.findAll(ClassOrInterfaceType.class).forEach(n -> { - if (n.getNameAsString().equals("var")) { - n.replace(new VarType(n.getTokenRange().orElse(null))); - } + node.findAll(ClassOrInterfaceType.class) + .forEach(n -> { + if (n.getNameAsString().equals("var") + && !matchForbiddenContext(n)) { + n.replace(new VarType(n.getTokenRange().orElse(null))); + } }); }); } + + private boolean matchForbiddenContext(ClassOrInterfaceType cit) { + return cit.getParentNode().isPresent() + && FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.stream().anyMatch(cl -> cl.isInstance(cit.getParentNode().get())); + } }; + public Java10PostProcessor() { add(varNodeCreator); From fe6c122cb023cdd72d427d59e4a84ef55f60d8dc Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Tue, 1 Nov 2022 12:14:24 +0000 Subject: [PATCH 051/280] Updated workflow to only run one job at time --- .github/workflows/maven_tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 4b85c44d2b..11a7a7e766 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -18,6 +18,12 @@ on: # Enable manual triggering (important for contributors to enable a check on their fork) workflow_dispatch: +# If a build is running in the current branch, and the branch is updated, we cancel the previous build and start +# a new one with the updated changes. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: maven_test: strategy: From 74aca9e35b244d79cd33b88249e91db0c0429579 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Tue, 1 Nov 2022 23:12:32 +0000 Subject: [PATCH 052/280] Added test for Issue 3099 --- .../symbolsolver/Issue3099Test.java | 78 +++++++++++++++++++ .../issue3099/com/example/Alpha.java | 26 +++++++ .../resources/issue3099/com/example/Beta.java | 30 +++++++ 3 files changed, 134 insertions(+) create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3099Test.java create mode 100644 javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Alpha.java create mode 100644 javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Beta.java diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3099Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3099Test.java new file mode 100644 index 0000000000..ea35ac1d94 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3099Test.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; +import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class Issue3099Test extends AbstractResolutionTest { + + @Test + void illegalArgumentExceptionWhenSolvingName() throws IOException { + + // Setup symbol solver + JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(adaptPath("src/test/resources/issue3099/")); + StaticJavaParser.getConfiguration() + .setSymbolResolver(new JavaSymbolSolver( + new CombinedTypeSolver(new ReflectionTypeSolver(), javaParserTypeSolver)) + ); + + // Parse the File + Path filePath = adaptPath("src/test/resources/issue3099/com/example/Beta.java"); + CompilationUnit cu = StaticJavaParser.parse(filePath); + + // Get the expected inner class + List classes = cu.findAll(ClassOrInterfaceDeclaration.class); + assertEquals(2, classes.size()); + ResolvedReferenceTypeDeclaration innerInterface = classes.get(1).resolve(); + assertTrue(innerInterface.isInterface()); + + // Check if the value is present + Optional resolvedType = cu.findFirst(VariableDeclarator.class) + .map(VariableDeclarator::getType) + .map(Type::resolve) + .filter(ResolvedType::isReferenceType) + .map(ResolvedType::asReferenceType); + assertTrue(resolvedType.isPresent()); + assertEquals(innerInterface, resolvedType.get().getTypeDeclaration().orElse(null)); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Alpha.java b/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Alpha.java new file mode 100644 index 0000000000..83d2b7c917 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Alpha.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.example; + +interface Alpha { + interface CustomInterface {} +} diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Beta.java b/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Beta.java new file mode 100644 index 0000000000..393165f983 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/resources/issue3099/com/example/Beta.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.example; + +class Beta implements Alpha.CustomInterface { + + public interface CustomInterface {} + + private final CustomInterface instanceOfBetaInnerClass; + +} From 4549a58efd47cbbd2ea36df1886546895943781e Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Tue, 1 Nov 2022 23:13:41 +0000 Subject: [PATCH 053/280] Updated Context class to support resolution of type parameters --- .../symbolsolver/core/resolution/Context.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index 4050821930..fa9c94e00a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.quality.Nullable; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; @@ -82,20 +83,71 @@ default Optional solveGenericTypeInParentContext(String name) { * * @param name For example, solving {@code List} or {@code java.util.List}. * @return The declaration associated with the given type name. + * + * @deprecated Consider using method {@link #solveType(String, List)} that also consider the type arguments. + * If you want to keep to use the new function, but keep the same behavior consider passing type + * arguments as {@code null}. */ + @Deprecated default SymbolReference solveType(String name) { + return solveType(name, null); + } + + /** + * Method used to solve a name with an expected list of type arguments. + *
+ * This method differs from {@link Context#solveType(String)} by taking the type arguments in consideration. + * For example, lets imagine that we have a project containing the following classes: + *
    + *
  • com/example/Alpha.java
  • + *
  • com/example/Beta.java
  • + *
+ * Where Alpha creates a inner interface called CustomInterface and Beta implements Alpha.CustomInterface and + * also declares a inner interface called CustomInterface with type arguments. Using this method we can + * specify which type arguments we are expecting and will be resolved with the type matching that declaration. + * + * @param name The name to be solved. + * @param typeArguments The list of expected type arguments. + * + * @return The declaration associated with the given type name. + */ + default SymbolReference solveType(String name, @Nullable List typeArguments) { // Default to solving within the parent context. - return solveTypeInParentContext(name); + return solveTypeInParentContext(name, typeArguments); } + /** + * Solve a name in the parent context. + * + * @param name The name to be solved. + * + * @return The declaration associated with the given type name. + * + * @deprecated Consider using method {@link #solveTypeInParentContext(String, List)} that also consider the type arguments. + * If you want to keep to use the new function, but keep the same behavior consider passing type + * arguments as {@code null}. + */ + @Deprecated default SymbolReference solveTypeInParentContext(String name) { + return solveTypeInParentContext(name, null); + } + + /** + * Solve a name with type arguments in the parent context. + * + * @param name The name to be solved. + * @param typeArguments The list of expected type arguments. + * + * @return The declaration associated with the given type name. + */ + default SymbolReference solveTypeInParentContext(String name, @Nullable List typeArguments) { Optional optionalParentContext = getParent(); if (!optionalParentContext.isPresent()) { return SymbolReference.unsolved(); } // Delegate solving to the parent context. - return optionalParentContext.get().solveType(name); + return optionalParentContext.get().solveType(name, typeArguments); } /* Symbol resolution */ From e347b67f81f4f332a0a9d1b46fae61bd7f3a4026 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Tue, 1 Nov 2022 23:17:18 +0000 Subject: [PATCH 054/280] Updated context methods that solveType(String) to use solveType(String, List) --- .../AbstractMethodLikeDeclarationContext.java | 4 +- .../AnnotationDeclarationContext.java | 4 +- .../AnonymousClassDeclarationContext.java | 12 ++-- .../ClassOrInterfaceDeclarationContext.java | 12 ++-- ...sOrInterfaceDeclarationExtendsContext.java | 7 +- .../contexts/CompilationUnitContext.java | 2 +- .../contexts/EnumDeclarationContext.java | 4 +- .../contexts/FieldAccessContext.java | 4 +- .../JavaParserTypeDeclarationAdapter.java | 66 +++++++++++++++---- .../contexts/ObjectCreationContext.java | 4 +- 10 files changed, 81 insertions(+), 38 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java index 6a3b8af92f..d1cb11b8f7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java @@ -97,7 +97,7 @@ public final Optional solveSymbolAsValue(String name) { } @Override - public final SymbolReference solveType(String name) { + public final SymbolReference solveType(String name, List typeArguments) { // TODO: Is null check required? if (wrappedNode.getTypeParameters() != null) { for (TypeParameter tp : wrappedNode.getTypeParameters()) { @@ -119,7 +119,7 @@ public final SymbolReference solveType(String name) { } } - return solveTypeInParentContext(name); + return solveTypeInParentContext(name, typeArguments); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java index d189976790..b92bcbb450 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java @@ -59,8 +59,8 @@ public SymbolReference solveSymbol(String na } @Override - public SymbolReference solveType(String name) { - return javaParserTypeDeclarationAdapter.solveType(name); + public SymbolReference solveType(String name, List resolvedTypes) { + return javaParserTypeDeclarationAdapter.solveType(name, resolvedTypes); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java index e66894b1a2..c2c53554f1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java @@ -21,10 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; @@ -46,6 +42,10 @@ import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.google.common.base.Preconditions; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + /** * A symbol resolution context for an object creation node. */ @@ -122,7 +122,7 @@ public SymbolReference solveMethod(String name, } @Override - public SymbolReference solveType(String name) { + public SymbolReference solveType(String name, List typeArguments) { List typeDeclarations = myDeclaration.findMembersOfKind(TypeDeclaration.class); Optional> exactMatch = @@ -193,7 +193,7 @@ public SymbolReference solveType(String name) { } } - return solveTypeInParentContext(name); + return solveTypeInParentContext(name, typeArguments); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java index d6c7f1440a..b9b1f1be93 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java @@ -21,10 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.TypeParameter; @@ -42,6 +38,10 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + /** * @author Federico Tomassetti */ @@ -102,8 +102,8 @@ public Optional solveGenericType(String name) { } @Override - public SymbolReference solveType(String name) { - return javaParserTypeDeclarationAdapter.solveType(name); + public SymbolReference solveType(String name, List typeArguments) { + return javaParserTypeDeclarationAdapter.solveType(name, typeArguments); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java index 62b344c7c3..155a058e05 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java @@ -24,10 +24,13 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import java.util.List; + /** * Limited version of ClassOrInterfaceDeclarationContext that only resolves type parameters for use by * extends and implements part of declaration. @@ -38,13 +41,13 @@ public ClassOrInterfaceDeclarationExtendsContext(ClassOrInterfaceDeclaration wra } @Override - public SymbolReference solveType(String name) { + public SymbolReference solveType(String name, List typeArguments) { for (TypeParameter typeParameter : wrappedNode.getTypeParameters()) { if (typeParameter.getName().getId().equals(name)) { return SymbolReference.solved(new JavaParserTypeParameter(typeParameter, typeSolver)); } } - return super.solveType(name); + return super.solveType(name, typeArguments); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index 61f88d1df3..e7d3786116 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -120,7 +120,7 @@ public SymbolReference solveSymbol(String na } @Override - public SymbolReference solveType(String name) { + public SymbolReference solveType(String name, List typeArguments) { if (wrappedNode.getTypes() != null) { // Look for types in this compilation unit. For instance, if the given name is "A", there may be a class or diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java index 9060e03353..1d7211c24e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java @@ -68,8 +68,8 @@ public SymbolReference solveSymbol(String na } @Override - public SymbolReference solveType(String name) { - return javaParserTypeDeclarationAdapter.solveType(name); + public SymbolReference solveType(String name, List resolvedTypes) { + return javaParserTypeDeclarationAdapter.solveType(name, resolvedTypes); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index f4b3f09c26..af2987a6be 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -69,8 +69,8 @@ public SymbolReference solveSymbol(String na } @Override - public SymbolReference solveType(String name) { - return JavaParserFactory.getContext(demandParentNode(wrappedNode), typeSolver).solveType(name); + public SymbolReference solveType(String name, List typeArguments) { + return JavaParserFactory.getContext(demandParentNode(wrappedNode), typeSolver).solveType(name, typeArguments); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 29b31a3334..0f776edc41 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -22,12 +22,15 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.nodeTypes.NodeWithExtends; import com.github.javaparser.ast.nodeTypes.NodeWithImplements; +import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -65,53 +68,63 @@ public JavaParserTypeDeclarationAdapter(com.github.javaparser.ast.body.TypeDecla this.context = context; } + /** + * @deprecated Consider using {@link #solveType(String, List)} to consider type arguments. + */ + @Deprecated public SymbolReference solveType(String name) { + return solveType(name, null); + } + + public SymbolReference solveType(String name, List typeArguments) { if (this.wrappedNode.getName().getId().equals(name)) { return SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration(wrappedNode)); } // Internal classes for (BodyDeclaration member : this.wrappedNode.getMembers()) { - if (member instanceof TypeDeclaration) { - TypeDeclaration internalType = (TypeDeclaration) member; - if (internalType.getName().getId().equals(name)) { + if (member.isTypeDeclaration()) { + TypeDeclaration internalType = member.asTypeDeclaration(); + if (internalType.getName().getId().equals(name) && compareTypeParameters(internalType, typeArguments)) { return SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration(internalType)); } else if (name.startsWith(wrappedNode.getName().getId() + "." + internalType.getName().getId())) { - return JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(wrappedNode.getName().getId().length() + 1)); + return JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(wrappedNode.getName().getId().length() + 1), typeArguments); } else if (name.startsWith(internalType.getName().getId() + ".")) { - return JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(internalType.getName().getId().length() + 1)); + return JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(internalType.getName().getId().length() + 1), typeArguments); } } } + // Check if is a type parameter if (wrappedNode instanceof NodeWithTypeParameters) { NodeWithTypeParameters nodeWithTypeParameters = (NodeWithTypeParameters) wrappedNode; for (TypeParameter astTpRaw : nodeWithTypeParameters.getTypeParameters()) { - TypeParameter astTp = astTpRaw; - if (astTp.getName().getId().equals(name)) { - return SymbolReference.solved(new JavaParserTypeParameter(astTp, typeSolver)); + if (astTpRaw.getName().getId().equals(name)) { + return SymbolReference.solved(new JavaParserTypeParameter(astTpRaw, typeSolver)); } } } + // Check if the node implements other types if (wrappedNode instanceof NodeWithImplements) { NodeWithImplements nodeWithImplements = (NodeWithImplements) wrappedNode; for (ClassOrInterfaceType implementedType : nodeWithImplements.getImplementedTypes()) { if (implementedType.getName().getId().equals(name)) { return context.getParent() .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) - .solveType(implementedType.getNameWithScope()); + .solveType(implementedType.getNameWithScope(), typeArguments); } } } + // Check if the node implements other types if (wrappedNode instanceof NodeWithExtends) { NodeWithExtends nodeWithExtends = (NodeWithExtends) wrappedNode; for (ClassOrInterfaceType extendedType : nodeWithExtends.getExtendedTypes()) { - if (extendedType.getName().getId().equals(name)) { + if (extendedType.getName().getId().equals(name) && compareTypeArguments(extendedType, typeArguments)) { return context.getParent() - .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) - .solveType(extendedType.getNameWithScope()); + .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) + .solveType(extendedType.getNameWithScope(), typeArguments); } } } @@ -125,7 +138,34 @@ public SymbolReference solveType(String name) { // Else check parents return context.getParent() .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) - .solveType(name); + .solveType(name, typeArguments); + } + + private > boolean compareTypes(List types, + List resolvedTypeArguments) { + // If the user want's to solve the type without having prior knowledge of the type arguments. + if (resolvedTypeArguments == null) { + return true; + } + + return types.size() == resolvedTypeArguments.size(); + } + + private > boolean compareTypeArguments(T type, List resolvedTypeArguments) { + return compareTypes(type.getTypeArguments().orElse(new NodeList<>()), resolvedTypeArguments); + } + + private > boolean compareTypeParameters(T type, + List resolvedTypeArguments) { + return compareTypes(type.getTypeParameters(), resolvedTypeArguments); + } + + private boolean compareTypeParameters(TypeDeclaration typeDeclaration, List resolvedTypeArguments) { + if (typeDeclaration instanceof NodeWithTypeParameters) { + return compareTypeParameters((NodeWithTypeParameters) typeDeclaration, resolvedTypeArguments); + } else { + return true; + } } /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java index bd21d84f7c..b78931bca3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java @@ -48,7 +48,7 @@ public ObjectCreationContext(ObjectCreationExpr wrappedNode, TypeSolver typeSolv } @Override - public SymbolReference solveType(String name) { + public SymbolReference solveType(String name, List typeArguments) { if (wrappedNode.hasScope()) { Expression scope = wrappedNode.getScope().get(); ResolvedType scopeType = JavaParserFacade.get(typeSolver).getType(scope); @@ -67,7 +67,7 @@ public SymbolReference solveType(String name) { while (parentNode instanceof ObjectCreationExpr) { parentNode = demandParentNode(parentNode); } - return JavaParserFactory.getContext(parentNode, typeSolver).solveType(name); + return JavaParserFactory.getContext(parentNode, typeSolver).solveType(name, typeArguments); } @Override From e844b57ef4ee41f2e2894be1c9487f5172a2158c Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Tue, 1 Nov 2022 23:18:38 +0000 Subject: [PATCH 055/280] Added additional tests for method solveType in ClassOrInterfaceDeclarationContext --- ...lassOrInterfaceDeclarationContextTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java new file mode 100644 index 0000000000..d9073f5dab --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2021 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.javaparsermodel.contexts; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.types.ResolvedPrimitiveType; +import com.github.javaparser.symbolsolver.JavaSymbolSolver; +import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ClassOrInterfaceDeclarationContextTest { + + private final TypeSolver typeSolver = new ReflectionTypeSolver(); + private JavaParser javaParser; + + @BeforeEach + void beforeEach() { + ParserConfiguration parserConfiguration = new ParserConfiguration(); + parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver)); + javaParser = new JavaParser(); + } + + @Test + void testSolveWithoutTypeArguments() { + CompilationUnit alphaCU = parse("class Alpha { class Foo {} }"); + ClassOrInterfaceDeclaration alpha = Navigator.demandClass(alphaCU, "Alpha"); + ClassOrInterfaceDeclarationContext alphaContext = new ClassOrInterfaceDeclarationContext(alpha, typeSolver); + + assertTrue(alphaContext.solveType("Foo").isSolved()); + assertTrue(alphaContext.solveType("Foo", Collections.emptyList()).isSolved()); + assertFalse(alphaContext.solveType("Foo", Collections.singletonList(ResolvedPrimitiveType.INT)).isSolved()); + } + + @Test + void testSolveWithTypeArguments() { + CompilationUnit betaCU = parse("class Beta { class Foo {} }"); + ClassOrInterfaceDeclaration beta = Navigator.demandClassOrInterface(betaCU, "Beta"); + ClassOrInterfaceDeclarationContext betaContext = new ClassOrInterfaceDeclarationContext(beta, typeSolver); + + assertTrue(betaContext.solveType("Foo").isSolved()); + assertFalse(betaContext.solveType("Foo", Collections.emptyList()).isSolved()); + assertTrue(betaContext.solveType("Foo", Collections.singletonList(ResolvedPrimitiveType.INT)).isSolved()); + } + + private CompilationUnit parse(String sourceCode) { + return javaParser.parse(sourceCode).getResult().orElseThrow(AssertionError::new); + } + +} From 6da3f99b1e335c861b02ea897811f27220ad5c4e Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Wed, 2 Nov 2022 08:49:21 +0000 Subject: [PATCH 056/280] Updated comment to match behavior --- .../contexts/JavaParserTypeDeclarationAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 0f776edc41..4a34bcf268 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -117,7 +117,7 @@ public SymbolReference solveType(String name, List nodeWithExtends = (NodeWithExtends) wrappedNode; for (ClassOrInterfaceType extendedType : nodeWithExtends.getExtendedTypes()) { From d7a83612e1fa0c3c93ebac243a768339346382b5 Mon Sep 17 00:00:00 2001 From: Joseph Cox <100454338+TheJosephCCox@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:45:14 +1100 Subject: [PATCH 057/280] Change test to paramaterized --- .../symbolsolver/Issue1945Test.java | 103 ++++++++++-------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java index a309a08dda..a463e5c1bd 100755 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Map; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; @@ -17,69 +17,78 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class Issue1945Test extends AbstractResolutionTest { - @Test() - void test() { - String code = "import issue1945.implementations.Sheep;\n" + - "import issue1945.interfaces.HairType;\n" + - "import issue1945.interfaces.HairTypeRenderer;\n" + - "import issue1945.interfaces.HairyAnimal;\n" + - "\n" + - "public class MainIssue1945 {\n" + - " \n" + - " private final HairyAnimal sheep = new Sheep();\n" + - " \n" + - " public void chokes3() {\n" + - " HairType hairType = sheep.getHairType();\n" + - " hairType.getRenderer().renderHair(sheep.getHairType(), sheep);\n" + -" hairType.getRenderer();\n" + - - " }\n" + - " \n" + - " public void chokes() {\n" + - " sheep.getHairType().getRenderer().renderHair(sheep.getHairType(), sheep);\n" + - " }\n" + - " \n" + - " public void chokes2() {\n" + - " HairType hairType = sheep.getHairType();\n" + - " hairType.getRenderer().renderHair(hairType, sheep);\n" + - " }\n" + - "}"; - - ParserConfiguration config = new ParserConfiguration(); - Path srcDir = adaptPath("src/test/resources/issue1945"); - CombinedTypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JavaParserTypeSolver(srcDir)); - - config.setSymbolResolver(new JavaSymbolSolver(typeSolver)); - StaticJavaParser.setConfiguration(config); - - // results by MathodCallExpr - Map resultsQualifiedName = new HashMap<>(); + private final static String code = "import issue1945.implementations.Sheep;\n" + + "import issue1945.interfaces.HairType;\n" + + "import issue1945.interfaces.HairTypeRenderer;\n" + + "import issue1945.interfaces.HairyAnimal;\n" + + "\n" + + "public class MainIssue1945 {\n" + + " \n" + + " private final HairyAnimal sheep = new Sheep();\n" + + " \n" + + " public void chokes3() {\n" + + " HairType hairType = sheep.getHairType();\n" + + " hairType.getRenderer().renderHair(sheep.getHairType(), sheep);\n" + + " hairType.getRenderer();\n" + + + " }\n" + + " \n" + + " public void chokes() {\n" + + " sheep.getHairType().getRenderer().renderHair(sheep.getHairType(), sheep);\n" + + " }\n" + + " \n" + + " public void chokes2() {\n" + + " HairType hairType = sheep.getHairType();\n" + + " hairType.getRenderer().renderHair(hairType, sheep);\n" + + " }\n" + + "}"; + + // Expected Result MethodCallExpr in parsed code + private final static Map resultsQualifiedName = new HashMap<>(); + + private final static Map resultsResolvedType = new HashMap<>(); + + @BeforeAll + static void init() { resultsQualifiedName.put("sheep.getHairType()", "issue1945.interfaces.HairyAnimal.getHairType"); resultsQualifiedName.put("hairType.getRenderer().renderHair(sheep.getHairType(), sheep)", "issue1945.interfaces.HairTypeRenderer.renderHair"); resultsQualifiedName.put("hairType.getRenderer()", "issue1945.interfaces.HairType.getRenderer"); resultsQualifiedName.put("sheep.getHairType().getRenderer().renderHair(sheep.getHairType(), sheep)", "issue1945.interfaces.HairTypeRenderer.renderHair"); resultsQualifiedName.put("sheep.getHairType().getRenderer()", "issue1945.interfaces.HairType.getRenderer"); resultsQualifiedName.put("hairType.getRenderer().renderHair(hairType, sheep)", "issue1945.interfaces.HairTypeRenderer.renderHair"); - Map resultsResolvedType = new HashMap<>(); + resultsResolvedType.put("sheep.getHairType()", "issue1945.interfaces.HairType"); resultsResolvedType.put("hairType.getRenderer().renderHair(sheep.getHairType(), sheep)", "void"); resultsResolvedType.put("hairType.getRenderer()", "R"); resultsResolvedType.put("sheep.getHairType().getRenderer().renderHair(sheep.getHairType(), sheep)", "void"); resultsResolvedType.put("sheep.getHairType().getRenderer()", "R"); resultsResolvedType.put("hairType.getRenderer().renderHair(hairType, sheep)", "void"); + } - CompilationUnit cu = StaticJavaParser.parse(code); - List nodes = cu.findAll(MethodCallExpr.class); - for (MethodCallExpr expr : nodes) { - String qName = expr.resolve().getQualifiedName(); - String resolvedType = expr.calculateResolvedType().describe(); - assertEquals(resultsQualifiedName.get(expr.toString()), qName); - assertEquals(resultsResolvedType.get(expr.toString()), resolvedType); - } + private static List parsedCodeMethodCalls() { + Path srcDir = adaptPath("src/test/resources/issue1945"); + + CombinedTypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JavaParserTypeSolver(srcDir)); + ParserConfiguration config = new ParserConfiguration(); + config.setSymbolResolver(new JavaSymbolSolver(typeSolver)); + StaticJavaParser.setConfiguration(config); + CompilationUnit cu = StaticJavaParser.parse(code); + + return cu.findAll(MethodCallExpr.class); } + @ParameterizedTest + @MethodSource("parsedCodeMethodCalls") + void test(MethodCallExpr expr) { + String qName = expr.resolve().getQualifiedName(); + String resolvedType = expr.calculateResolvedType().describe(); + assertEquals(resultsQualifiedName.get(expr.toString()), qName); + assertEquals(resultsResolvedType.get(expr.toString()), resolvedType); + } } From 72f780b8bb1e545bd2e3c9cd3aa196d11486f409 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 13 Nov 2022 20:16:16 +0000 Subject: [PATCH 058/280] Added JavaParserAdapter --- .../javaparser/JavaParserAdapterTest.java | 267 ++++++++++++++++++ .../github/javaparser/JavaParserAdapter.java | 178 ++++++++++++ 2 files changed, 445 insertions(+) create mode 100644 javaparser-core-testing/src/test/java/com/github/javaparser/JavaParserAdapterTest.java create mode 100644 javaparser-core/src/main/java/com/github/javaparser/JavaParserAdapter.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaParserAdapterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaParserAdapterTest.java new file mode 100644 index 0000000000..afa4fda1f7 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaParserAdapterTest.java @@ -0,0 +1,267 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.modules.ModuleDirective; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.ByteArrayInputStream; +import java.io.CharArrayReader; +import java.io.InputStream; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + + +class JavaParserAdapterTest { + + private final JavaParser javaParser = Mockito.spy(JavaParser.class); + + private final JavaParserAdapter adapter = new JavaParserAdapter(javaParser); + + @Test + void of_withValidParser() { + JavaParserAdapter actualAdapter = JavaParserAdapter.of(javaParser); + assertSame(javaParser, actualAdapter.getParser()); + assertSame(javaParser.getParserConfiguration(), adapter.getParserConfiguration()); + } + + @Test + void parse_withSourceCode() { + + CompilationUnit cu = adapter.parse("class A {}"); + + Optional classA = cu.findFirst(ClassOrInterfaceDeclaration.class); + assertTrue(classA.isPresent()); + assertEquals("A", classA.get().getNameAsString()); + + Mockito.verify(javaParser).parse("class A {}"); + } + + @Test + void parse_withInvalidSourceCode() { + assertThrows(ParseProblemException.class, () -> adapter.parse("class A")); + } + + @Test + void parse_withSourceCodeFromInputStream() { + + InputStream is = new ByteArrayInputStream("class A {}".getBytes(StandardCharsets.UTF_8)); + + CompilationUnit cu = adapter.parse(is); + + Optional classA = cu.findFirst(ClassOrInterfaceDeclaration.class); + assertTrue(classA.isPresent()); + assertEquals("A", classA.get().getNameAsString()); + + Mockito.verify(javaParser).parse(is); + } + + @Test + void parse_withSourceCodeFromReader() { + + Reader reader = new CharArrayReader("class A {}".toCharArray()); + + CompilationUnit cu = adapter.parse(reader); + + Optional classA = cu.findFirst(ClassOrInterfaceDeclaration.class); + assertTrue(classA.isPresent()); + assertEquals("A", classA.get().getNameAsString()); + + Mockito.verify(javaParser).parse(reader); + } + + @Test + void parseBlock_withValidSource() { + BlockStmt block = adapter.parseBlock("{ System.out.println(\"Hello world!\"); }"); + + assertEquals(1, block.getStatements().size()); + + Mockito.verify(javaParser).parseBlock("{ System.out.println(\"Hello world!\"); }"); + } + + @Test + void parseStatement_withValidSource() { + Statement statement = adapter.parseStatement("break;"); + + assertTrue(statement.isBreakStmt()); + + Mockito.verify(javaParser).parseStatement("break;"); + } + + @Test + void parseImport_withValidSource() { + ImportDeclaration importDecl = adapter.parseImport("import java.util.Optional;"); + + assertEquals("Optional", importDecl.getName().getIdentifier()); + + Mockito.verify(javaParser).parseImport("import java.util.Optional;"); + } + + @Test + void parseExpression_withValidSource() { + Expression expression = adapter.parseExpression("System.out.println(\"Hello world!\")"); + + assertTrue(expression.isMethodCallExpr()); + + Mockito.verify(javaParser).parseExpression("System.out.println(\"Hello world!\")"); + } + + @Test + void parseAnnotation_withValidSource() { + AnnotationExpr annotation = adapter.parseAnnotation("@Test"); + + assertEquals("Test", annotation.getNameAsString()); + + Mockito.verify(javaParser).parseAnnotation("@Test"); + } + + @Test + void parseAnnotationBodyDeclaration_withValidSource() { + BodyDeclaration annotationBody = adapter.parseAnnotationBodyDeclaration("@interface Test{}"); + + assertTrue(annotationBody.isAnnotationDeclaration()); + + Mockito.verify(javaParser).parseAnnotationBodyDeclaration("@interface Test{}"); + } + + @Test + void parseBodyDeclaration_withValidSource() { + BodyDeclaration interfaceBody = adapter.parseBodyDeclaration("interface CustomInterface {}"); + + assertTrue(interfaceBody.isClassOrInterfaceDeclaration()); + + Mockito.verify(javaParser).parseBodyDeclaration("interface CustomInterface {}"); + } + + @Test + void parseClassOrInterfaceType_withValidSource() { + ClassOrInterfaceType customType = adapter.parseClassOrInterfaceType("CustomInterface"); + + assertTrue(customType.isClassOrInterfaceType()); + + Mockito.verify(javaParser).parseClassOrInterfaceType("CustomInterface"); + } + + @Test + void parseType_withValidSource() { + Type customType = adapter.parseType("int"); + + assertTrue(customType.isPrimitiveType()); + + Mockito.verify(javaParser).parseType("int"); + } + + @Test + void parseVariableDeclarationExpr_withValidSource() { + VariableDeclarationExpr variable = adapter.parseVariableDeclarationExpr("final int x = 0"); + + assertTrue(variable.isFinal()); + + Mockito.verify(javaParser).parseVariableDeclarationExpr("final int x = 0"); + } + + @Test + void parseExplicitConstructorInvocationStmt_withValidSource() { + ExplicitConstructorInvocationStmt statement = adapter.parseExplicitConstructorInvocationStmt("super();"); + + assertTrue(statement.getArguments().isEmpty()); + + Mockito.verify(javaParser).parseExplicitConstructorInvocationStmt("super();"); + } + + @Test + void parseName_withValidSource() { + Name name = adapter.parseName("com.github.javaparser.JavaParser"); + + assertEquals("JavaParser", name.getIdentifier()); + + Mockito.verify(javaParser).parseName("com.github.javaparser.JavaParser"); + } + + @Test + void parseSimpleName_withValidSource() { + SimpleName name = adapter.parseSimpleName("JavaParser"); + + assertEquals("JavaParser", name.getIdentifier()); + + Mockito.verify(javaParser).parseSimpleName("JavaParser"); + } + + @Test + void parseParameter_withValidSource() { + Parameter parameter = adapter.parseParameter("String foo"); + + assertEquals("foo", parameter.getNameAsString()); + + Mockito.verify(javaParser).parseParameter("String foo"); + } + + @Test + void parsePackageDeclaration_withValidSource() { + PackageDeclaration packageDeclaration = adapter.parsePackageDeclaration("package com.github.javaparser;"); + + assertEquals("com.github.javaparser", packageDeclaration.getNameAsString()); + + Mockito.verify(javaParser).parsePackageDeclaration("package com.github.javaparser;"); + } + + @Test + void parseTypeDeclaration_withValidSource() { + TypeDeclaration typeDeclaration = adapter.parseTypeDeclaration("class A {}"); + + assertEquals("A", typeDeclaration.getNameAsString()); + + Mockito.verify(javaParser).parseTypeDeclaration("class A {}"); + } + + @Test + void parseModuleDeclaration_withValidSource() { + ModuleDeclaration moduleDeclaration = adapter.parseModuleDeclaration("module X {}"); + + assertEquals("X", moduleDeclaration.getNameAsString()); + + Mockito.verify(javaParser).parseModuleDeclaration("module X {}"); + } + + @Test + void parseModuleDirective_withValidSource() { + ModuleDirective moduleDirective = adapter.parseModuleDirective("opens X;"); + + assertTrue(moduleDirective.isModuleOpensDirective()); + + Mockito.verify(javaParser).parseModuleDirective("opens X;"); + } + + @Test + void parseTypeParameter_withValidSource() { + TypeParameter typeParameter = adapter.parseTypeParameter("T extends Object"); + + assertEquals("T", typeParameter.getNameAsString()); + + Mockito.verify(javaParser).parseTypeParameter("T extends Object"); + } + + @Test + void parseMethodDeclaration_withValidSource() { + MethodDeclaration methodDeclaration = adapter.parseMethodDeclaration("void test() {}"); + + assertEquals("test", methodDeclaration.getNameAsString()); + + Mockito.verify(javaParser).parseMethodDeclaration("void test() {}"); + } + +} \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParserAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParserAdapter.java new file mode 100644 index 0000000000..bcee313244 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParserAdapter.java @@ -0,0 +1,178 @@ +package com.github.javaparser; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.body.BodyDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.modules.ModuleDeclaration; +import com.github.javaparser.ast.modules.ModuleDirective; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.javadoc.Javadoc; + +import java.io.*; +import java.nio.file.Path; +import java.util.Objects; + +public class JavaParserAdapter { + + /** + * Wraps the {@link JavaParser}. + * + * @param parser The java parser to be used. + * + * @return The created QuickJavaParser. + */ + public static JavaParserAdapter of(JavaParser parser) { + return new JavaParserAdapter(parser); + } + + private final JavaParser parser; + + public JavaParserAdapter(JavaParser parser) { + this.parser = Objects.requireNonNull(parser, "A non-null parser should be provided."); + } + + public JavaParser getParser() { + return parser; + } + + /** + * Helper function to handle the result in a simpler way. + * + * @param result The result to be handled. + * + * @param The return type. + * + * @return The parsed value. + */ + private T handleResult(ParseResult result) { + if (result.isSuccessful()) { + return result.getResult().orElse(null); + } + + throw new ParseProblemException(result.getProblems()); + } + + public ParserConfiguration getParserConfiguration() { + return parser.getParserConfiguration(); + } + + public CompilationUnit parse(InputStream in) { + return handleResult(getParser().parse(in)); + } + + public CompilationUnit parse(File file) throws FileNotFoundException { + return handleResult(getParser().parse(file)); + } + + public CompilationUnit parse(Path path) throws IOException { + return handleResult(getParser().parse(path)); + } + + public CompilationUnit parse(Reader reader) { + return handleResult(getParser().parse(reader)); + } + + public CompilationUnit parse(String code) { + return handleResult(getParser().parse(code)); + } + + public CompilationUnit parseResource(String path) throws IOException { + return handleResult(getParser().parseResource(path)); + } + + public BlockStmt parseBlock(String blockStatement) { + return handleResult(getParser().parseBlock(blockStatement)); + } + + public Statement parseStatement(String statement) { + return handleResult(getParser().parseStatement(statement)); + } + + public ImportDeclaration parseImport(String importDeclaration) { + return handleResult(getParser().parseImport(importDeclaration)); + } + + public T parseExpression(String expression) { + return handleResult(getParser().parseExpression(expression)); + } + + public AnnotationExpr parseAnnotation(String annotation) { + return handleResult(getParser().parseAnnotation(annotation)); + } + + public BodyDeclaration parseAnnotationBodyDeclaration(String body) { + return handleResult(getParser().parseAnnotationBodyDeclaration(body)); + } + + public BodyDeclaration parseBodyDeclaration(String body) { + return handleResult(getParser().parseBodyDeclaration(body)); + } + + public ClassOrInterfaceType parseClassOrInterfaceType(String type) { + return handleResult(getParser().parseClassOrInterfaceType(type)); + } + + public Type parseType(String type) { + return handleResult(getParser().parseType(type)); + } + + public VariableDeclarationExpr parseVariableDeclarationExpr(String declaration) { + return handleResult(getParser().parseVariableDeclarationExpr(declaration)); + } + + public Javadoc parseJavadoc(String content) { + return JavadocParser.parse(content); + } + + public ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) { + return handleResult(getParser().parseExplicitConstructorInvocationStmt(statement)); + } + + public Name parseName(String qualifiedName) { + return handleResult(getParser().parseName(qualifiedName)); + } + + public SimpleName parseSimpleName(String name) { + return handleResult(getParser().parseSimpleName(name)); + } + + public Parameter parseParameter(String parameter) { + return handleResult(getParser().parseParameter(parameter)); + } + + public PackageDeclaration parsePackageDeclaration(String packageDeclaration) { + return handleResult(getParser().parsePackageDeclaration(packageDeclaration)); + } + + public TypeDeclaration parseTypeDeclaration(String typeDeclaration) { + return handleResult(getParser().parseTypeDeclaration(typeDeclaration)); + } + + public ModuleDeclaration parseModuleDeclaration(String moduleDeclaration) { + return handleResult(getParser().parseModuleDeclaration(moduleDeclaration)); + } + + public ModuleDirective parseModuleDirective(String moduleDirective) { + return handleResult(getParser().parseModuleDirective(moduleDirective)); + } + + public TypeParameter parseTypeParameter(String typeParameter) { + return handleResult(getParser().parseTypeParameter(typeParameter)); + } + + public MethodDeclaration parseMethodDeclaration(String methodDeclaration) { + return handleResult(getParser().parseMethodDeclaration(methodDeclaration)); + } + +} From 22e98bdb8d03577f3893fdf9484dd8cf70847dc3 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 13 Nov 2022 20:25:20 +0000 Subject: [PATCH 059/280] Adapted StaticJavaParser to use JavaParserAdapter --- .../github/javaparser/StaticJavaParser.java | 90 ++++++++++--------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java index 3106e59bb7..2d032cd146 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java +++ b/javaparser-core/src/main/java/com/github/javaparser/StaticJavaParser.java @@ -51,10 +51,7 @@ public final class StaticJavaParser { // use ThreadLocal to resolve possible concurrency issues. - private static ThreadLocal localConfiguration = ThreadLocal.withInitial(() -> new ParserConfiguration()); - - private StaticJavaParser() { - } + private static final ThreadLocal localConfiguration = ThreadLocal.withInitial(ParserConfiguration::new); /** * Get the configuration for the parse... methods. Deprecated method. @@ -82,10 +79,6 @@ public static void setConfiguration(@NotNull ParserConfiguration configuration) localConfiguration.set(configuration); } - private static JavaParser newParser() { - return new JavaParser(getConfiguration()); - } - /** * Parses the Java code contained in the {@link InputStream} and returns a * {@link CompilationUnit} that represents it. @@ -113,7 +106,7 @@ public static CompilationUnit parse(@NotNull final InputStream in, @NotNull Char */ public static CompilationUnit parse(@NotNull final InputStream in) { Preconditions.checkNotNull(in, "Parameter in can't be null."); - return handleResult(newParser().parse(in)); + return newParserAdapted().parse(in); } /** @@ -145,7 +138,7 @@ public static CompilationUnit parse(@NotNull final File file, @NotNull final Cha */ public static CompilationUnit parse(@NotNull final File file) throws FileNotFoundException { Preconditions.checkNotNull(file, "Parameter file can't be null."); - return handleResult(newParser().parse(file)); + return newParserAdapted().parse(file); } /** @@ -177,7 +170,7 @@ public static CompilationUnit parse(@NotNull final Path path, @NotNull final Cha */ public static CompilationUnit parse(@NotNull final Path path) throws IOException { Preconditions.checkNotNull(path, "Parameter path can't be null."); - return handleResult(newParser().parse(path)); + return newParserAdapted().parse(path); } /** @@ -192,7 +185,7 @@ public static CompilationUnit parse(@NotNull final Path path) throws IOException */ public static CompilationUnit parseResource(@NotNull final String path) throws IOException { Preconditions.checkNotNull(path, "Parameter path can't be null."); - return handleResult(newParser().parseResource(path)); + return newParserAdapted().parseResource(path); } /** @@ -244,7 +237,7 @@ public static CompilationUnit parseResource(@NotNull final ClassLoader classLoad */ public static CompilationUnit parse(@NotNull final Reader reader) { Preconditions.checkNotNull(reader, "Parameter reader can't be null."); - return handleResult(newParser().parse(reader)); + return newParserAdapted().parse(reader); } /** @@ -257,7 +250,7 @@ public static CompilationUnit parse(@NotNull final Reader reader) { */ public static CompilationUnit parse(@NotNull String code) { Preconditions.checkNotNull(code, "Parameter code can't be null."); - return handleResult(newParser().parse(code)); + return newParserAdapted().parse(code); } /** @@ -270,7 +263,7 @@ public static CompilationUnit parse(@NotNull String code) { */ public static BlockStmt parseBlock(@NotNull final String blockStatement) { Preconditions.checkNotNull(blockStatement, "Parameter blockStatement can't be null."); - return handleResult(newParser().parseBlock(blockStatement)); + return newParserAdapted().parseBlock(blockStatement); } /** @@ -283,14 +276,7 @@ public static BlockStmt parseBlock(@NotNull final String blockStatement) { */ public static Statement parseStatement(@NotNull final String statement) { Preconditions.checkNotNull(statement, "Parameter statement can't be null."); - return handleResult(newParser().parseStatement(statement)); - } - - private static T handleResult(ParseResult result) { - if (result.isSuccessful()) { - return result.getResult().get(); - } - throw new ParseProblemException(result.getProblems()); + return newParserAdapted().parseStatement(statement); } /** @@ -303,7 +289,7 @@ private static T handleResult(ParseResult result) { */ public static ImportDeclaration parseImport(@NotNull final String importDeclaration) { Preconditions.checkNotNull(importDeclaration, "Parameter importDeclaration can't be null."); - return handleResult(newParser().parseImport(importDeclaration)); + return newParserAdapted().parseImport(importDeclaration); } /** @@ -316,7 +302,7 @@ public static ImportDeclaration parseImport(@NotNull final String importDeclarat */ public static T parseExpression(@NotNull final String expression) { Preconditions.checkNotNull(expression, "Parameter expression can't be null."); - return handleResult(newParser().parseExpression(expression)); + return newParserAdapted().parseExpression(expression); } /** @@ -329,7 +315,7 @@ public static T parseExpression(@NotNull final String exp */ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { Preconditions.checkNotNull(annotation, "Parameter annotation can't be null."); - return handleResult(newParser().parseAnnotation(annotation)); + return newParserAdapted().parseAnnotation(annotation); } /** @@ -342,7 +328,7 @@ public static AnnotationExpr parseAnnotation(@NotNull final String annotation) { */ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final String body) { Preconditions.checkNotNull(body, "Parameter body can't be null."); - return handleResult(newParser().parseAnnotationBodyDeclaration(body)); + return newParserAdapted().parseAnnotationBodyDeclaration(body); } /** @@ -355,7 +341,7 @@ public static BodyDeclaration parseAnnotationBodyDeclaration(@NotNull final S */ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { Preconditions.checkNotNull(body, "Parameter body can't be null."); - return handleResult(newParser().parseBodyDeclaration(body)); + return newParserAdapted().parseBodyDeclaration(body); } /** @@ -367,7 +353,7 @@ public static BodyDeclaration parseBodyDeclaration(@NotNull String body) { */ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String type) { Preconditions.checkNotNull(type, "Parameter type can't be null."); - return handleResult(newParser().parseClassOrInterfaceType(type)); + return newParserAdapted().parseClassOrInterfaceType(type); } /** @@ -379,7 +365,7 @@ public static ClassOrInterfaceType parseClassOrInterfaceType(@NotNull String typ */ public static Type parseType(@NotNull String type) { Preconditions.checkNotNull(type, "Parameter type can't be null."); - return handleResult(newParser().parseType(type)); + return newParserAdapted().parseType(type); } /** @@ -392,7 +378,7 @@ public static Type parseType(@NotNull String type) { */ public static VariableDeclarationExpr parseVariableDeclarationExpr(@NotNull String declaration) { Preconditions.checkNotNull(declaration, "Parameter declaration can't be null."); - return handleResult(newParser().parseVariableDeclarationExpr(declaration)); + return newParserAdapted().parseVariableDeclarationExpr(declaration); } /** @@ -417,7 +403,7 @@ public static Javadoc parseJavadoc(@NotNull String content) { */ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(@NotNull String statement) { Preconditions.checkNotNull(statement, "Parameter statement can't be null."); - return handleResult(newParser().parseExplicitConstructorInvocationStmt(statement)); + return newParserAdapted().parseExplicitConstructorInvocationStmt(statement); } /** @@ -429,7 +415,7 @@ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocati */ public static Name parseName(@NotNull String qualifiedName) { Preconditions.checkNotNull(qualifiedName, "Parameter qualifiedName can't be null."); - return handleResult(newParser().parseName(qualifiedName)); + return newParserAdapted().parseName(qualifiedName); } /** @@ -441,7 +427,7 @@ public static Name parseName(@NotNull String qualifiedName) { */ public static SimpleName parseSimpleName(@NotNull String name) { Preconditions.checkNotNull(name, "Parameter name can't be null."); - return handleResult(newParser().parseSimpleName(name)); + return newParserAdapted().parseSimpleName(name); } /** @@ -453,7 +439,7 @@ public static SimpleName parseSimpleName(@NotNull String name) { */ public static Parameter parseParameter(@NotNull String parameter) { Preconditions.checkNotNull(parameter, "Parameter parameter can't be null."); - return handleResult(newParser().parseParameter(parameter)); + return newParserAdapted().parseParameter(parameter); } /** @@ -465,7 +451,7 @@ public static Parameter parseParameter(@NotNull String parameter) { */ public static PackageDeclaration parsePackageDeclaration(@NotNull String packageDeclaration) { Preconditions.checkNotNull(packageDeclaration, "Parameter packageDeclaration can't be null."); - return handleResult(newParser().parsePackageDeclaration(packageDeclaration)); + return newParserAdapted().parsePackageDeclaration(packageDeclaration); } /** @@ -477,7 +463,7 @@ public static PackageDeclaration parsePackageDeclaration(@NotNull String package */ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclaration) { Preconditions.checkNotNull(typeDeclaration, "Parameter typeDeclaration can't be null."); - return handleResult(newParser().parseTypeDeclaration(typeDeclaration)); + return newParserAdapted().parseTypeDeclaration(typeDeclaration); } /** @@ -490,7 +476,7 @@ public static TypeDeclaration parseTypeDeclaration(@NotNull String typeDeclar */ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDeclaration) { Preconditions.checkNotNull(moduleDeclaration, "Parameter moduleDeclaration can't be null."); - return handleResult(newParser().parseModuleDeclaration(moduleDeclaration)); + return newParserAdapted().parseModuleDeclaration(moduleDeclaration); } /** @@ -503,7 +489,7 @@ public static ModuleDeclaration parseModuleDeclaration(@NotNull String moduleDec */ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirective) { Preconditions.checkNotNull(moduleDirective, "Parameter moduleDirective can't be null."); - return handleResult(newParser().parseModuleDirective(moduleDirective)); + return newParserAdapted().parseModuleDirective(moduleDirective); } /** @@ -515,7 +501,7 @@ public static ModuleDirective parseModuleDirective(@NotNull String moduleDirecti */ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { Preconditions.checkNotNull(typeParameter, "Parameter typeParameter can't be null."); - return handleResult(newParser().parseTypeParameter(typeParameter)); + return newParserAdapted().parseTypeParameter(typeParameter); } /** @@ -528,6 +514,28 @@ public static TypeParameter parseTypeParameter(@NotNull String typeParameter) { */ public static MethodDeclaration parseMethodDeclaration(@NotNull String methodDeclaration) { Preconditions.checkNotNull(methodDeclaration, "Parameter methodDeclaration can't be null."); - return handleResult(newParser().parseMethodDeclaration(methodDeclaration)); + return newParserAdapted().parseMethodDeclaration(methodDeclaration); } + + // Private methods + + private static JavaParser newParser() { + return new JavaParser(getParserConfiguration()); + } + + private static JavaParserAdapter newParserAdapted() { + return new JavaParserAdapter(newParser()); + } + + @Deprecated + private static T handleResult(ParseResult result) { + if (result.isSuccessful()) { + return result.getResult().get(); + } + throw new ParseProblemException(result.getProblems()); + } + + private StaticJavaParser() { + } + } From ab3f2273e6c4a954e1276120025db8c713372f3d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 14 Nov 2022 13:28:33 +0100 Subject: [PATCH 060/280] Fix issue #1827 Issue resolving a constructor of a class using generics --- .../model/typesystem/ReferenceTypeImpl.java | 4 +- .../symbolsolver/Issue1827Test.java | 50 +++++++++++ .../model/typesystem/LazyTypeTest.java | 82 +++++++++++++++++++ 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100755 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java create mode 100755 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index 6445556277..acad918f8d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -117,8 +117,8 @@ public boolean isAssignableBy(ResolvedType other) { if (other instanceof LambdaArgumentTypePlaceholder) { return FunctionalInterfaceLogic.isFunctionalInterfaceType(this); } - if (other instanceof ReferenceTypeImpl) { - ReferenceTypeImpl otherRef = (ReferenceTypeImpl) other; + if (other.isReferenceType()) { + ResolvedReferenceType otherRef = other.asReferenceType(); if (compareConsideringTypeParameters(otherRef)) { return true; } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java new file mode 100755 index 0000000000..bdc3ebbd97 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java @@ -0,0 +1,50 @@ +package com.github.javaparser.symbolsolver; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; + +public class Issue1827Test extends AbstractResolutionTest { + + @Test + public void solveParametrizedParametersConstructor() { + + String src = "public class ParametrizedParametersConstructor {\n" + + " public void foo() {\n" + + " EClass arg = new EClass();\n" + + " ParametrizedClass pc = new ParametrizedClass<>(arg, arg);\n" + + " }\n" + + "\n" + + " class EClass implements BaseType {\n" + + " }\n" + + "}\n" + + "\n" + + "class ParametrizedClass {\n" + + " public ParametrizedClass(BaseType arg1, BaseType arg2) {\n" + + " }\n" + + "}\n" + + "\n" + + "interface BaseType {\n" + + "}"; + + TypeSolver typeSolver = new ReflectionTypeSolver(); + JavaSymbolSolver symbolSolver = new JavaSymbolSolver(typeSolver); + StaticJavaParser + .getConfiguration() + .setSymbolResolver(symbolSolver); + CompilationUnit cu = StaticJavaParser.parse(src); + ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ParametrizedParametersConstructor"); + ObjectCreationExpr oce = clazz.findAll(ObjectCreationExpr.class).get(1); // new ParametrizedClass<>(arg, arg) + assertDoesNotThrow(() -> oce.resolve()); + } + +} diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java new file mode 100755 index 0000000000..a78349e0c9 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.model.typesystem; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; +import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; + +class LazyTypeTest extends AbstractSymbolResolutionTest { + + private ResolvedType foo; + private ResolvedType bar; + private ResolvedType baz; + private ResolvedType lazyFoo; + private ResolvedType lazyBar; + private ResolvedType lazyBaz; + private TypeSolver typeSolver; + + class Foo {} + + class Bar {} + + class Baz extends Foo {} + + @BeforeEach + void setup() { + typeSolver = new ReflectionTypeSolver(); + foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); + bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver), typeSolver); + baz = new ReferenceTypeImpl(new ReflectionClassDeclaration(Baz.class, typeSolver), typeSolver); + lazyFoo = lazy(foo); + lazyBar = lazy(bar); + lazyBaz = lazy(baz); + } + + private ResolvedType lazy(ResolvedType type) { + return new LazyType(v -> type); + } + + @Test + void testIsAssignable() { + assertEquals(true, foo.isAssignableBy(foo)); + assertEquals(true, foo.isAssignableBy(baz)); + assertEquals(false, foo.isAssignableBy(bar)); + + assertEquals(true, lazyFoo.isAssignableBy(lazyFoo)); + assertEquals(true, lazyFoo.isAssignableBy(lazyBaz)); + assertEquals(false, lazyFoo.isAssignableBy(lazyBar)); + + assertEquals(true, foo.isAssignableBy(lazyFoo)); + assertEquals(true, foo.isAssignableBy(lazyBaz)); + assertEquals(false, foo.isAssignableBy(lazyBar)); + + } + +} From a6a63cc4f294cc53fcc405d570dd21d9940772e9 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 17 Nov 2022 16:45:38 +0100 Subject: [PATCH 061/280] Update changelog --- changelog.md | 64 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index de6238da8f..e908e4d7ca 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ -Next Release (Version 3.24.8) +Next Release (Version 3.24.9) ------------------ -[issues resolved](https://github.com/javaparser/javaparser/milestone/192?closed=1) +[issues resolved](https://github.com/javaparser/javaparser/milestone/193?closed=1) ### Added ### Changed @@ -9,8 +9,56 @@ Next Release (Version 3.24.8) ### Fixed ### Security -Next Release (Version 3.24.7) ------------------- +Version 3.24.8 +-------------- +[issues resolved](https://github.com/javaparser/javaparser/milestone/192?closed=1) + +### Added + +* [Fixes #3099] Added ability to solve type with a list of expected type arguments (PR [#3213](https://github.com/javaparser/javaparser/pull/3213) by [@4everTheOne](https://github.com/4everTheOne)) +* [Suggestion] NonNull generator for parameters (PR [#3127](https://github.com/javaparser/javaparser/pull/3127) by [@4everTheOne](https://github.com/4everTheOne)) + +### Changed + +* Updated workflow to only run one job per PR (PR [#3744](https://github.com/javaparser/javaparser/pull/3744) by [@4everTheOne](https://github.com/4everTheOne)) +* Remove or comment system.out.println statement in unit tests (PR [#3741](https://github.com/javaparser/javaparser/pull/3741) by [@jlerbsc](https://github.com/jlerbsc)) +* Added Optional method in SymbolReference (PR [#3740](https://github.com/javaparser/javaparser/pull/3740) by [@4everTheOne](https://github.com/4everTheOne)) +* Centralized management of symbol solver exceptions to prevent exception type Erasion (PR [#3731](https://github.com/javaparser/javaparser/pull/3731) by [@jlerbsc](https://github.com/jlerbsc)) + +### Fixed + +* Fix issue #1827 Issue resolving a constructor of a class using generics (PR [#3752](https://github.com/javaparser/javaparser/pull/3752) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix issue #3728 ParseProblemException (PR [#3743](https://github.com/javaparser/javaparser/pull/3743) by [@jlerbsc](https://github.com/jlerbsc)) +* Updated Badge for Build and Coverage (PR [#3742](https://github.com/javaparser/javaparser/pull/3742) by [@4everTheOne](https://github.com/4everTheOne)) +* Position (PR [#3734](https://github.com/javaparser/javaparser/pull/3734) by [@ameliagenova](https://github.com/ameliagenova)) +* Fix part of issue #3721 UnsupportedOperationException while trying to modify the type of a variable (PR [#3726](https://github.com/javaparser/javaparser/pull/3726) by [@jlerbsc](https://github.com/jlerbsc)) +* Implemented isReferenceType in `ResolvedTypeDeclaration` and isTypeParameter in `ResolvedTypeParameterDeclaration` (PR [#3206](https://github.com/javaparser/javaparser/pull/3206) by [@4everTheOne](https://github.com/4everTheOne)) + +### Developer Changes + +* chore(deps): bump versions-maven-plugin from 2.12.0 to 2.13.0 (PR [#3727](https://github.com/javaparser/javaparser/pull/3727) by [@dependabot[bot]](https://github.com/apps/dependabot)) +* Fix maven wrapper not found in generator scripts (PR [#3717](https://github.com/javaparser/javaparser/pull/3717) by [@PPazderski](https://github.com/PPazderski)) +* chore(deps): bump actions/checkout from 3.0.2 to 3.1.0 (PR [#3716](https://github.com/javaparser/javaparser/pull/3716) by [@dependabot[bot]](https://github.com/apps/dependabot)) + +### Uncategorised + +* Change issue 1945 test to paramaterized (PR [#3739](https://github.com/javaparser/javaparser/pull/3739) by [@flanbino](https://github.com/flanbino)) +* More unit tests for JavaToken and CodeGenerationUtils (PR [#3736](https://github.com/javaparser/javaparser/pull/3736) by [@ameliagenova](https://github.com/ameliagenova)) + +### :heart: Contributors + +Thank You to all contributors who worked on this release! + +* [@flanbino](https://github.com/flanbino) +* [@PPazderski](https://github.com/PPazderski) +* [@ameliagenova](https://github.com/ameliagenova) +* [@jlerbsc](https://github.com/jlerbsc) +* [@4everTheOne](https://github.com/4everTheOne) + + + +Version 3.24.7 +-------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/191?closed=1) ### Highlights @@ -45,8 +93,8 @@ Thank You to all contributors who worked on this release! * [@jlerbsc](https://github.com/jlerbsc) -Next Release (Version 3.24.6) ------------------- +Version 3.24.6 +-------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/190?closed=1) ### API or Behaviour Change @@ -123,8 +171,8 @@ Thank You to all contributors who worked on this release! * [@4everTheOne](https://github.com/4everTheOne) -Next Release (Version 3.24.4) - Repeat of 3.24.3 ------------------- +Version 3.24.4 - Repeat of 3.24.3 +--------------------------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/190?closed=1) GPG Fingerprint: `253E8E4C6FB28D11748115C1249DEE8E2C07A0A2` From e6035cc0ac9274b35efc75c904987bee39f50519 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 17 Nov 2022 16:47:19 +0100 Subject: [PATCH 062/280] update readme --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 5cae8f098d..5a70f88cce 100644 --- a/readme.md +++ b/readme.md @@ -37,14 +37,14 @@ Just add the following to your maven configuration or tailor to your own depende com.github.javaparser javaparser-symbol-solver-core - 3.24.7 + 3.24.8 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.24.7' +implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.24.8' ``` Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver. @@ -59,14 +59,14 @@ Using the dependency above will add both JavaParser and JavaSymbolSolver to your com.github.javaparser javaparser-core - 3.24.7 + 3.24.8 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core:3.24.7' +implementation 'com.github.javaparser:javaparser-core:3.24.8' ``` Since version 3.6.17 the AST can be serialized to JSON. @@ -78,14 +78,14 @@ There is a separate module for this: com.github.javaparser javaparser-core-serialization - 3.24.7 + 3.24.8 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core-serialization:3.24.7' +implementation 'com.github.javaparser:javaparser-core-serialization:3.24.8' ``` ## How To Compile Sources From 3926ccabdac3341f365bf867ea2c2a11d1ab224b Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 17 Nov 2022 16:48:45 +0100 Subject: [PATCH 063/280] [maven-release-plugin] prepare release javaparser-parent-3.24.8 --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 2d58827890..96b7730c27 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 672d77659f..653b4244dd 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 4d0c7efe53..931fe2cf74 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index e397e9d65a..72d5ed66c8 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index af0a4f9512..70698e165b 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 5e482d1e8d..e91bf51c84 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index d8e165f052..fbf9590600 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index c4883e168c..bd808a9626 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8-SNAPSHOT + 3.24.8 4.0.0 diff --git a/pom.xml b/pom.xml index 57f8ffef9d..94fef5a40a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.24.8-SNAPSHOT + 3.24.8 javaparser-parent https://github.com/javaparser From 7692dde428113ad9c11fe98cebf8b71f2daef1cc Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 17 Nov 2022 17:00:27 +0100 Subject: [PATCH 064/280] [maven-release-plugin] prepare for next development iteration --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 96b7730c27..46b4dad6b4 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 653b4244dd..cc26f3fe42 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 931fe2cf74..4bd2790dff 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 72d5ed66c8..f647b273c0 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index 70698e165b..ca74bb4c31 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index e91bf51c84..38fc7a39df 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index fbf9590600..65a8e162db 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index bd808a9626..eeb8a7565a 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.8 + 3.24.9-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 94fef5a40a..44c90b0264 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.24.8 + 3.24.9-SNAPSHOT javaparser-parent https://github.com/javaparser From 47406e5c23cba641756d60c6feff1ca1b18e8880 Mon Sep 17 00:00:00 2001 From: hapa Date: Thu, 17 Nov 2022 16:49:44 +0000 Subject: [PATCH 065/280] Remove "executable" bit from code files They serve no purpose but I suspect seem to annoy a security lint. --- .../src/test/java/com/github/javaparser/Issue1017Test.java | 0 .../com/github/javaparser/printer/DefaultPrettyPrinterTest.java | 0 .../com/github/javaparser/printer/PrinterConfigurationTest.java | 0 .../javaparser/printer/lexicalpreservation/Issue1467Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue1634Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue1766Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue1793Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2290Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2374Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2393Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2592Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2610Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2620Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue2806Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue3296Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue3358Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue3387Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue3440Test.java | 0 .../javaparser/printer/lexicalpreservation/Issue3721Test.java | 0 .../printer/lexicalpreservation/PrettyPrinterIssue2340Test.java | 0 .../printer/lexicalpreservation/PrettyPrinterIssue2351Test.java | 0 .../printer/lexicalpreservation/changes/NoChangeTest.java | 0 .../java/com/github/javaparser/printer/DefaultPrettyPrinter.java | 0 .../github/javaparser/printer/DefaultPrettyPrinterVisitor.java | 0 .../src/main/java/com/github/javaparser/printer/Printer.java | 0 .../javaparser/printer/configuration/ConfigurationOption.java | 0 .../printer/configuration/DefaultConfigurationOption.java | 0 .../printer/configuration/DefaultPrinterConfiguration.java | 0 .../com/github/javaparser/printer/configuration/Indentation.java | 0 .../javaparser/printer/configuration/PrinterConfiguration.java | 0 .../javaparser/symbolsolver/javaparsermodel/FailureHandler.java | 0 .../resolution/promotion/BooleanConditionalExprHandler.java | 0 .../symbolsolver/resolution/promotion/ConditionalExprHandler.java | 0 .../resolution/promotion/ConditionalExprResolver.java | 0 .../resolution/promotion/NumericConditionalExprHandler.java | 0 .../resolution/promotion/ReferenceConditionalExprHandler.java | 0 .../java/com/github/javaparser/symbolsolver/utils/FileUtils.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1456Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1479Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1480Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1518Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1599Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1713Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1726Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1757Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1769Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1774Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1817Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1827Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1868Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1945Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue1950Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2062Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2065Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2083Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2132Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2210Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2236Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2259Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2284Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2289Test.java | 0 .../test/java/com/github/javaparser/symbolsolver/Issue2360.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2406Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2477Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2489Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2740Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2764Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2781Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2823Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2878Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2909Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2987Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue2995Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue3024Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue3083Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue3087Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue3159Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue3614Test.java | 0 .../java/com/github/javaparser/symbolsolver/Issue366Test.java | 0 .../javassistmodel/JavassistFieldDeclarationTest.java | 0 .../javaparser/symbolsolver/model/typesystem/LazyTypeTest.java | 0 .../reflectionmodel/ReflectionFieldDeclarationTest.java | 0 .../javaparser/symbolsolver/resolution/ConditionalExprTest.java | 0 .../github/javaparser/symbolsolver/resolution/DescriptorTest.java | 0 .../symbolsolver/resolution/LambdaGenericResolutionTest.java | 0 .../symbolsolver/resolution/PolyExpressionResolutionTest.java | 0 .../symbolsolver/resolution/ReferenceTypeResolutionTest.java | 0 .../javaparser/contexts/BlockStmtContextResolutionTest.java | 0 .../src/test/resources/AnInterface.java.txt | 0 .../src/test/resources/Issue2258.java.txt | 0 .../src/test/resources/issue1456/bar/A.java | 0 .../src/test/resources/issue1456/foo/A.java | 0 .../src/test/resources/issue1479/A.java | 0 .../src/test/resources/issue1479/B.java | 0 .../src/test/resources/issue1480/A.java | 0 .../src/test/resources/issue1480/B.java | 0 .../src/test/resources/issue1518/Test1.java | 0 .../src/test/resources/issue1599/A.java | 0 .../src/test/resources/issue1769/foo/OtherClass.java | 0 .../src/test/resources/issue1817/X.java | 0 .../src/test/resources/issue1868/B.java | 0 .../issue1945/issue1945/implementations/HairTypeWool.java | 0 .../test/resources/issue1945/issue1945/implementations/Sheep.java | 0 .../issue1945/issue1945/implementations/WoolRenderer.java | 0 .../test/resources/issue1945/issue1945/interfaces/HairType.java | 0 .../issue1945/issue1945/interfaces/HairTypeRenderer.java | 0 .../resources/issue1945/issue1945/interfaces/HairyAnimal.java | 0 .../test/resources/issue1945/issue1945/main/MainIssue1945.java | 0 .../src/test/resources/issue2236/A.java | 0 .../src/test/resources/issue2489/ComponentBase.java | 0 .../src/test/resources/issue2489/ObjectContext.java | 0 .../src/test/resources/issue2489/ObjectContextDecorator .java | 0 .../src/test/resources/issue2823/ClassA.java | 0 .../src/test/resources/issue2823/ClassB.java | 0 .../src/test/resources/issue2878/U9.java | 0 .../src/test/resources/issue2909/OuterClass.java | 0 116 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java mode change 100755 => 100644 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java mode change 100755 => 100644 javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java mode change 100755 => 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/utils/FileUtils.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1456Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1480Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1518Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1599Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1713Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1757Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1769Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1774Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1817Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1868Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2062Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2065Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2360.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2406Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2878Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2987Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2995Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3024Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3083Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3087Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3159Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3614Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue366Test.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConditionalExprTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DescriptorTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/PolyExpressionResolutionTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ReferenceTypeResolutionTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/BlockStmtContextResolutionTest.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/AnInterface.java.txt mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/Issue2258.java.txt mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1456/bar/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1456/foo/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1479/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1479/B.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1480/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1480/B.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1518/Test1.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1599/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1769/foo/OtherClass.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1817/X.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1868/B.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/HairTypeWool.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/Sheep.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/WoolRenderer.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairType.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairTypeRenderer.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairyAnimal.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/main/MainIssue1945.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2236/A.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2489/ComponentBase.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContext.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContextDecorator .java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassA.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassB.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2878/U9.java mode change 100755 => 100644 javaparser-symbol-solver-testing/src/test/resources/issue2909/OuterClass.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java old mode 100755 new mode 100644 diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinter.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Printer.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/ConfigurationOption.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultConfigurationOption.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/DefaultPrinterConfiguration.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/Indentation.java old mode 100755 new mode 100644 diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/configuration/PrinterConfiguration.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/FailureHandler.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/utils/FileUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/utils/FileUtils.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1456Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1456Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1479Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1480Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1480Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1518Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1518Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1599Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1599Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1713Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1713Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1757Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1757Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1769Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1769Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1774Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1774Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1817Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1817Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1868Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1868Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1945Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2062Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2062Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2065Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2065Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2360.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2360.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2406Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2406Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2740Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2878Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2878Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2909Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2987Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2987Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2995Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2995Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3024Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3024Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3083Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3083Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3087Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3087Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3159Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3159Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3614Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3614Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue366Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue366Test.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConditionalExprTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConditionalExprTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DescriptorTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DescriptorTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/PolyExpressionResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/PolyExpressionResolutionTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ReferenceTypeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ReferenceTypeResolutionTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/BlockStmtContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/BlockStmtContextResolutionTest.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/AnInterface.java.txt b/javaparser-symbol-solver-testing/src/test/resources/AnInterface.java.txt old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/Issue2258.java.txt b/javaparser-symbol-solver-testing/src/test/resources/Issue2258.java.txt old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1456/bar/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue1456/bar/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1456/foo/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue1456/foo/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1479/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue1479/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1479/B.java b/javaparser-symbol-solver-testing/src/test/resources/issue1479/B.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1480/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue1480/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1480/B.java b/javaparser-symbol-solver-testing/src/test/resources/issue1480/B.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1518/Test1.java b/javaparser-symbol-solver-testing/src/test/resources/issue1518/Test1.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1599/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue1599/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1769/foo/OtherClass.java b/javaparser-symbol-solver-testing/src/test/resources/issue1769/foo/OtherClass.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1817/X.java b/javaparser-symbol-solver-testing/src/test/resources/issue1817/X.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1868/B.java b/javaparser-symbol-solver-testing/src/test/resources/issue1868/B.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/HairTypeWool.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/HairTypeWool.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/Sheep.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/Sheep.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/WoolRenderer.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/implementations/WoolRenderer.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairType.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairType.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairTypeRenderer.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairTypeRenderer.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairyAnimal.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/interfaces/HairyAnimal.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/main/MainIssue1945.java b/javaparser-symbol-solver-testing/src/test/resources/issue1945/issue1945/main/MainIssue1945.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2236/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue2236/A.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2489/ComponentBase.java b/javaparser-symbol-solver-testing/src/test/resources/issue2489/ComponentBase.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContext.java b/javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContext.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContextDecorator .java b/javaparser-symbol-solver-testing/src/test/resources/issue2489/ObjectContextDecorator .java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassA.java b/javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassA.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassB.java b/javaparser-symbol-solver-testing/src/test/resources/issue2823/ClassB.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2878/U9.java b/javaparser-symbol-solver-testing/src/test/resources/issue2878/U9.java old mode 100755 new mode 100644 diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue2909/OuterClass.java b/javaparser-symbol-solver-testing/src/test/resources/issue2909/OuterClass.java old mode 100755 new mode 100644 From cd11a9874073e99bba1fead7ba08e5e8acf53d11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Nov 2022 23:01:07 +0000 Subject: [PATCH 066/280] chore(deps): bump maven-install-plugin from 3.0.1 to 3.1.0 Bumps [maven-install-plugin](https://github.com/apache/maven-install-plugin) from 3.0.1 to 3.1.0. - [Release notes](https://github.com/apache/maven-install-plugin/releases) - [Commits](https://github.com/apache/maven-install-plugin/compare/maven-install-plugin-3.0.1...maven-install-plugin-3.1.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-install-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 44c90b0264..87ae044f91 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ org.apache.maven.plugins maven-install-plugin - 3.0.1 + 3.1.0 org.apache.maven.plugins From d1219c2f1028e3df6a2d173878b94e640abf60bd Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sun, 20 Nov 2022 20:52:00 +0100 Subject: [PATCH 067/280] Fix: Fix the indentation generated by the LexicalPreservingPrinter when inserting a new member in a block. --- .../printer/lexicalpreservation/Issue2620Test.java | 6 +++--- .../javaparser/printer/lexicalpreservation/Difference.java | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java index ae3e57b7cd..86762b4b48 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java @@ -74,9 +74,9 @@ public void doTest(LineSeparator eol) { // FIXME: Indentation is bad here. String expected = "" + " public class Foo { //comment" + eol + - " private String newField;" + eol + - " " + eol + - " private String a;" + eol + + " private String newField;" + eol + + " " + eol + + " private String a;" + eol + " private String b;" + eol + " private String c;" + eol + " private String d;" + eol + diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index c10c8820cd..5fae55002a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -533,7 +533,6 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea diffIndex++; } else if (kept.isNewLine() && originalTextToken.isSpaceOrTab()) { originalIndex++; - diffIndex++; } else if (kept.isWhiteSpaceOrComment()) { diffIndex++; } else if (originalTextToken.isWhiteSpaceOrComment()) { From bf54d8300e0d1dd5917fa22c6e3ecaf7baf6d9fe Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 21 Nov 2022 10:05:29 +0100 Subject: [PATCH 068/280] Fix: #3750 Lexical preserving corrupts source --- .../LexicalPreservingPrinterTest.java | 1 - .../printer/lexicalpreservation/Difference.java | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java index abdde430ab..75e8aabd52 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java @@ -361,7 +361,6 @@ void printASimpleClassRemovingAField() { ClassOrInterfaceDeclaration c = cu.getClassByName("A").get(); c.getMembers().remove(0); assertEquals("class /*a comment*/ A {\t\t" + SYSTEM_EOL + - SYSTEM_EOL + " void foo(int p ) { return 'z' \t; }}", LexicalPreservingPrinter.print(c)); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 5fae55002a..de373e3f87 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -419,6 +419,10 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, diffIndex++; } else if (originalElementIsToken && originalElement.isWhiteSpaceOrComment()) { originalIndex++; + // skip the newline token which may be generated unnecessarily by the concrete syntax pattern + if (removed.isNewLine()) { + diffIndex++; + } } else if (originalElement.isLiteral()) { nodeText.removeElement(originalIndex); diffIndex++; @@ -464,6 +468,11 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo nodeText.removeElement(originalIndex - 1); originalIndex--; } + // Remove remaining newline character if needed + if (nodeText.getTextElement(originalIndex).isNewline()) { + nodeText.removeElement(originalIndex); + originalIndex = originalIndex > 0 ? originalIndex-- : 0; + } } } // Mark RemovedGroup as processed From 515a21b6ae8fcc531f48759d676ae6ec6d3f3267 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 21 Nov 2022 10:10:38 +0100 Subject: [PATCH 069/280] Fix: #3750 Lexical preserving corrupts source - adding junit test --- .../lexicalpreservation/Issue3750Test.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java new file mode 100755 index 0000000000..dbd21a5234 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.utils.LineSeparator; + +public class Issue3750Test extends AbstractLexicalPreservingTest { + + @Test + void test() { + considerCode( + "public class MyClass {\n" + + " String s0;\n" + + " // Comment\n" + + " String s1;\n" + + "}"); + + List fields = cu.findAll(FieldDeclaration.class); + FieldDeclaration field = fields.get(0); + + String expected = + "public class MyClass {\n" + + " // Comment\n" + + " String s1;\n" + + "}"; + + field.remove(); + + assertEquals(expected, LexicalPreservingPrinter.print(cu)); + } +} From ea14d4aabcddca6b85d084d2ee0b28c8e54e1c73 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 21 Nov 2022 19:17:31 +0100 Subject: [PATCH 070/280] Fix: #3746 Incorrect indentation by LexicalPreservingPrinter when removing/adding first statement of a block --- .../lexicalpreservation/Issue3746Test.java | 78 +++++++++++++++++++ .../DifferenceElementCalculator.java | 7 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java new file mode 100755 index 0000000000..b28fc70843 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.utils.LineSeparator; + +public class Issue3746Test extends AbstractLexicalPreservingTest { + + @Test + void test() { + considerCode( + "public class MyClass {\n" + + " String s0;\n" + + " // Comment\n" + + " String s1;\n" + + "}"); + + considerCode("class A {\n" + + " void foo() {\n" + + " int first = 1;\n" + + " int second = 2;\n" + + " }\n" + + "}" + ); + + String expected = + "class A {\n" + + " void foo() {\n" + + " foo();\n" + + " int second = 2;\n" + + " }\n" + + "}"; + BlockStmt block = cu.findAll(BlockStmt.class).get(0); + ExpressionStmt newStmt = new ExpressionStmt(new MethodCallExpr("foo")); + block.addStatement(1,newStmt); + block.getStatement(0).remove(); + assertEquals(expected, LexicalPreservingPrinter.print(cu)); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index 099e5403db..a06369c779 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -52,7 +52,12 @@ public boolean equals(Object other) { // verify that the node content and the position are equal // because we can have nodes with the same content but in different lines // in this case we consider that nodes are not equals - return this.node.equals(cpi.node) && this.node.hasRange() && cpi.node.hasRange() && this.node.getRange().get().contains(cpi.node.getRange().get()); + // If the nodes have no declared position they are considered equal. + return this.node.equals(cpi.node) + && (this.node.hasRange() == false && cpi.node.hasRange() == false + || (this.node.hasRange() && cpi.node.hasRange() && this.node.getRange().get().contains(cpi.node.getRange().get()) + ) + ); } @Override From 5fd2b5e47e16dfe450dd3b11fceb4f897e373d26 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 22 Nov 2022 16:38:18 +0100 Subject: [PATCH 071/280] Fix: #3693 Removing modifiers from method declaration results in loss of white space --- .../MethodDeclarationTransformationsTest.java | 23 ++++- .../lexicalpreservation/Difference.java | 99 ++++++++++++++----- 2 files changed, 97 insertions(+), 25 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/MethodDeclarationTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/MethodDeclarationTransformationsTest.java index 15e1380e83..2251604e28 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/MethodDeclarationTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/MethodDeclarationTransformationsTest.java @@ -239,7 +239,28 @@ void removingModifiersWithExistingAnnotations() { String result = LexicalPreservingPrinter.print(cu.findCompilationUnit().get()); assertEqualsStringIgnoringEol("class X {\n" + " @Test\n" + - "void testCase() {\n" + + " void testCase() {\n" + + " }\n" + + "}\n", result); + } + + @Test + void removingModifiersWithExistingAnnotations_withVariableNumberOfSeparator() { + considerCode( + "class X {" + SYSTEM_EOL + + " @Test" + SYSTEM_EOL + + " public void testCase() {" + SYSTEM_EOL + + " }" + SYSTEM_EOL + + "}" + SYSTEM_EOL + ); + + cu.getType(0).getMethods().get(0).setModifiers(new NodeList<>()); + + String result = LexicalPreservingPrinter.print(cu.findCompilationUnit().get()); + assertEqualsStringIgnoringEol( + "class X {\n" + + " @Test\n" + + " void testCase() {\n" + " }\n" + "}\n", result); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index de373e3f87..13d9bbddcc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -134,57 +134,103 @@ private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) { } /** - * If we are at the beginning of a line, with just spaces or tabs before us we should force the space to be - * the same as the indentation. + * If we are at the beginning of a line, with just spaces or tabs before/after the position of the deleted element + * we should force the space to be the same as the current indentation. + * This method handles the following case if we remove the modifier {@code public} ([ ] is an indent character) + * {@code + * [ ][ ]public[ ][ ][ ]void[ ]m{} + * <-1--> <---2---> + * 1/ current indentation + * 2/ these whitespaces must be removed + * } + * should produce + * {@code + * [ ][ ]void[ ]m{} + * } */ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) { - boolean hasOnlyWsBefore = hasOnlyWsBefore(nodeText, nodeTextIndex); + EnforcingIndentationContext enforcingIndentationContext = defineEnforcingIndentationContext(nodeText, nodeTextIndex); // the next position in the list (by default the current position) int res = nodeTextIndex; - if (hasOnlyWsBefore) { - res = removeExtraCharacters(nodeText, nodeTextIndex); + if (enforcingIndentationContext.extraCharacters > 0) { + int extraCharacters = enforcingIndentationContext.extraCharacters > indentation.size() ? enforcingIndentationContext.extraCharacters - indentation.size() : 0; + res = removeExtraCharacters(nodeText, enforcingIndentationContext.start, extraCharacters); + // The next position must take into account the indentation + res = extraCharacters > 0 ? res + indentation.size() : res; } if (res < 0) { throw new IllegalStateException(); } return res; } + + /* + * This data structure class hold the starting position of the first whitespace char + * and the number of consecutive whitespace (or tab) characters + */ + private class EnforcingIndentationContext { + int start; + int extraCharacters; + public EnforcingIndentationContext(int start) { + this.start=start; + this.extraCharacters=0; + } + } /** + * Remove excess white space after deleting element. * @param nodeText Contains a list of elements to analyze * @param nodeTextIndex Starting position in the input list * @return The current position in the list of the elements */ - private int removeExtraCharacters(NodeText nodeText, int nodeTextIndex) { + private int removeExtraCharacters(NodeText nodeText, int nodeTextIndex, int extraCharacters) { int pos = nodeTextIndex; - for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { + int count = 0; + for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements() && count < extraCharacters; i++) { if (nodeText.getTextElement(i).isNewline()) { break; } - nodeText.removeElement(i); - pos = i; + nodeText.removeElement(pos); + count++; } return pos; } /** - * Tries to determine if there are only spaces between the previous end of line and the index + * Starting at {@code nodeTextIndex} this method tries to determine how many contiguous spaces there are between + * the previous end of line and the next non whitespace (or tab) character * @param nodeText List of elements to analyze * @param nodeTextIndex Starting position in the input list - * @return + * @return EnforcingIndentationContext Data structure that hold the starting position of the first whitespace char and + * The number of consecutive whitespace (or tab) characters */ - private boolean hasOnlyWsBefore(NodeText nodeText, int nodeTextIndex) { - boolean hasOnlyWsBefore = true; - for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { - if (nodeText.getTextElement(i).isNewline()) { - break; - } - if (!nodeText.getTextElement(i).isSpaceOrTab()) { - hasOnlyWsBefore = false; - break; - } - } - return hasOnlyWsBefore; + private EnforcingIndentationContext defineEnforcingIndentationContext(NodeText nodeText, int nodeTextIndex) { + EnforcingIndentationContext ctx = new EnforcingIndentationContext(nodeTextIndex); + // compute space before nodeTextIndex value + if (nodeTextIndex < nodeText.numberOfElements()) { + for (int i = nodeTextIndex; i >= 0 && i < nodeText.numberOfElements(); i--) { + if (nodeText.getTextElement(i).isNewline()) { + break; + } + if (!nodeText.getTextElement(i).isSpaceOrTab()) { + ctx = new EnforcingIndentationContext(nodeTextIndex); + break; + } + ctx.start = i; + ctx.extraCharacters++; + } + // compute space after nodeTextIndex value + if (nodeText.getTextElement(nodeTextIndex).isSpaceOrTab()) { + for (int i = nodeTextIndex + 1; i >= 0 && i < nodeText.numberOfElements(); i++) { + if (!nodeText.getTextElement(i).isSpaceOrTab()) { + break; + } + ctx.extraCharacters++; + } + } + } + + return ctx; } /** @@ -395,7 +441,12 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } else { nodeText.removeElement(originalIndex); - if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1).isAdded())) && !removedGroup.isACompleteLine()) { + // When we don't try to remove a complete line + // and removing the element is not the first action of a replacement (removal followed by addition) + // (in the latter case we keep the indentation) + // then we want to enforce the indentation. + if ((diffIndex + 1 >= diffElements.size() || !(diffElements.get(diffIndex + 1).isAdded())) + && !removedGroup.isACompleteLine()) { originalIndex = considerEnforcingIndentation(nodeText, originalIndex); } // If in front we have one space and before also we had space let's drop one space From 9875571adf9c145a7c70a6373f204e5bfdb721ec Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 23 Nov 2022 19:27:38 +0100 Subject: [PATCH 072/280] Minor refactoring in ordering differences --- .../printer/lexicalpreservation/Difference.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 13d9bbddcc..3af5310a5d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -624,7 +624,7 @@ private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolea */ private int getArrayLevel(DifferenceElement element) { CsmElement csmElem = element.getElement(); - if (csmElem instanceof LexicalDifferenceCalculator.CsmChild && ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild() instanceof ArrayType) { + if (isArrayType(element)) { Node child = ((LexicalDifferenceCalculator.CsmChild) csmElem).getChild(); return ((ArrayType) child).getArrayLevel(); } @@ -945,17 +945,17 @@ private Map getCorrespondanceBetweenNextOrderAndPreviousOrder( List previousOrderElements = elementsFromPreviousOrder.getElements(); WrappingRangeIterator piNext = new WrappingRangeIterator(previousOrderElements.size()); for (int ni = 0; ni < nextOrderElements.size(); ni++) { - boolean found = false; CsmElement ne = nextOrderElements.get(ni); - for (int counter = 0; counter < previousOrderElements.size() && !found; counter++) { + for (int counter = 0; counter < previousOrderElements.size(); counter++) { Integer pi = piNext.next(); CsmElement pe = previousOrderElements.get(pi); if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) && DifferenceElementCalculator.matching(ne, pe)) { - found = true; correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi); + break; } } } + return correspondanceBetweenNextOrderAndPreviousOrder; } From a54ab41a711853b3dc342bcae583141d6da58f49 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 24 Nov 2022 13:27:32 +0100 Subject: [PATCH 073/280] Fix: #3761 Lexical preserving corrupts source when adding a modifier in first position --- .../lexicalpreservation/Issue3761Test.java | 67 ++++++++++ .../lexicalpreservation/Difference.java | 121 +++++++++++++++--- 2 files changed, 171 insertions(+), 17 deletions(-) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java new file mode 100755 index 0000000000..028d2d8238 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.utils.LineSeparator; + +public class Issue3761Test extends AbstractLexicalPreservingTest { + + @Test + public void test() { + considerCode( + "class C { \n" + + " static String S = \"s\";\n" + + "}"); + + FieldDeclaration field = cu.findAll(FieldDeclaration.class).get(0); + + List kws = field.getModifiers().stream().map(Modifier::getKeyword).collect(Collectors.toList()); + kws.add(0, Modifier.Keyword.PROTECTED); + field.setModifiers(kws.toArray(new Modifier.Keyword[] {})); + + String expected = + "class C { \r\n" + + " protected static String S = \"s\";\r\n" + + "}"; + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 3af5310a5d..074acdf24e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -939,24 +939,111 @@ private String tokenDescription(int kind) { return GeneratedJavaParserConstants.tokenImage[kind]; } - private Map getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder) { - Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); - List nextOrderElements = elementsFromNextOrder.getElements(); - List previousOrderElements = elementsFromPreviousOrder.getElements(); - WrappingRangeIterator piNext = new WrappingRangeIterator(previousOrderElements.size()); - for (int ni = 0; ni < nextOrderElements.size(); ni++) { - CsmElement ne = nextOrderElements.get(ni); - for (int counter = 0; counter < previousOrderElements.size(); counter++) { - Integer pi = piNext.next(); - CsmElement pe = previousOrderElements.get(pi); - if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi) && DifferenceElementCalculator.matching(ne, pe)) { - correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi); - break; - } - } - } + /* + * Considering that the lists of elements are ordered, We can find the common + * elements by starting with the list before the modifications and, for each + * element, by going through the list of elements containing the modifications. + * + * We can find the common elements by starting with the list before the + * modifications (L1) and, for each element, by going through the list of elements + * containing the modifications (L2). + * + * If element A in list L1 is not found in list L2, it is a deleted element. + * If element A of list L1 is found in list L2, it is a kept element. In this + * case the search for the next element of the list L1 must start from the + * position of the last element kept {@code syncNextIndex}. + */ + private Map getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, + CsmMix elementsFromNextOrder) { + Map correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>(); + ReadOnlyListIterator previousOrderElementsIterator = new ReadOnlyListIterator( + elementsFromPreviousOrder.getElements()); + int syncNextIndex = 0; + while (previousOrderElementsIterator.hasNext()) { + CsmElement pe = previousOrderElementsIterator.next(); + ReadOnlyListIterator nextOrderElementsIterator = new ReadOnlyListIterator( + elementsFromNextOrder.getElements(), syncNextIndex); + while (nextOrderElementsIterator.hasNext()) { + CsmElement ne = nextOrderElementsIterator.next(); + if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(previousOrderElementsIterator.index()) + && DifferenceElementCalculator.matching(ne, pe)) { + correspondanceBetweenNextOrderAndPreviousOrder.put(nextOrderElementsIterator.index(), + previousOrderElementsIterator.index()); + // set the position to start on the next {@code nextOrderElementsIterator} iteration + syncNextIndex = nextOrderElementsIterator.index(); + break; + } + } + } + return correspondanceBetweenNextOrderAndPreviousOrder; + } + + /* + * A list iterator which does not allow to modify the list + * and which provides a method to know the current positioning + */ + private class ReadOnlyListIterator implements ListIterator { + ListIterator elements; + public ReadOnlyListIterator(List elements) { + this(elements, 0); + } + + public ReadOnlyListIterator(List elements, int index) { + this.elements = elements.listIterator(index); + } + + @Override + public boolean hasNext() { + return elements.hasNext(); + } - return correspondanceBetweenNextOrderAndPreviousOrder; + @Override + public T next() { + return elements.next(); + } + + @Override + public boolean hasPrevious() { + return elements.hasPrevious(); + } + + @Override + public T previous() { + return elements.previous(); + } + + @Override + public int nextIndex() { + return elements.nextIndex(); + } + + @Override + public int previousIndex() { + return elements.previousIndex(); + } + + /* + * Returns the current index in the underlying list + */ + public int index() { + return elements.nextIndex() - 1; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public void set(T e) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(T e) { + throw new UnsupportedOperationException(); + } + } /* From 14eeb65d4a3b4b88668db796643d7b13279577ee Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 24 Nov 2022 13:28:07 +0100 Subject: [PATCH 074/280] Removing useless class WrappingRangeIterator --- .../WrappingRangeIterator.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java deleted file mode 100644 index f9411f971d..0000000000 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/WrappingRangeIterator.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2007-2010 Júlio Vilmar Gesser. - * Copyright (C) 2011, 2013-2021 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser can be used either under the terms of - * a) the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * b) the terms of the Apache License - * - * You should have received a copy of both licenses in LICENCE.LGPL and - * LICENCE.APACHE. Please refer to those files for details. - * - * JavaParser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ -package com.github.javaparser.printer.lexicalpreservation; - -import java.util.Iterator; - -public class WrappingRangeIterator implements Iterator { - - private final int limit; - - private int currentValue = 0; - - public WrappingRangeIterator(int limit) { - this.limit = limit; - } - - @Override - public boolean hasNext() { - return true; - } - - @Override - public Integer next() { - int valueToReturn = currentValue; - ++currentValue; - if (currentValue == limit) { - currentValue = 0; - } - return valueToReturn; - } -} From 245bf0532fe36fdbeb6fe88f4d90cf3a603e3538 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 24 Nov 2022 19:55:13 +0100 Subject: [PATCH 075/280] Fix: #2137 ClassOrInterfaceDeclaration addMember using index --- .../lexicalpreservation/Issue2137Test.java | 65 +++++++++++++++++++ .../lexicalpreservation/Difference.java | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java new file mode 100755 index 0000000000..0c071706a7 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java @@ -0,0 +1,65 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; + +import java.util.StringJoiner; + +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.type.VoidType; +import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.javadoc.description.JavadocDescription; + +public class Issue2137Test extends AbstractLexicalPreservingTest { + + @Test + void test2137() { + considerCode( + "public class Foo {\n" + + " void mymethod1() {}\n" + + " void mymethod2() {}\n" + + "}"); + String expected = + "public class Foo {\n" + + " void mymethod1() {}\n" + + " void mymethod3() {\n"+ + " }\n" + + " \n" + + " void mymethod2() {}\n" + + "}"; + ClassOrInterfaceDeclaration cid = cu.getClassByName("Foo").get(); + MethodDeclaration methodDeclaration = new MethodDeclaration(); + methodDeclaration.setName("mymethod3"); + methodDeclaration.setType(new VoidType()); + cid.getMembers().add(1, methodDeclaration); + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 074acdf24e..4079e1a1f5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -927,7 +927,7 @@ private void applyAddedDiffElement(Added added) { if (addedTextElement.isNewline()) { boolean followedByUnindent = isFollowedByUnindent(diffElements, diffIndex); boolean nextIsRightBrace = nextIsRightBrace(originalIndex); - boolean nextIsNewLine = nodeText.getTextElement(originalIndex).isNewline(); + boolean nextIsNewLine = originalElements.get(originalIndex).isNewline(); if ((!nextIsNewLine && !nextIsRightBrace) || followedByUnindent) { originalIndex = adjustIndentation(indentation, nodeText, originalIndex, followedByUnindent); } From cf3d95dfb30169397039ce06c11524d81333bc5f Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 25 Nov 2022 16:09:04 +0100 Subject: [PATCH 076/280] Fix: #3441 LexicalPreservingPrinter prints wrong output with line comments --- .../lexicalpreservation/Issue3441Test.java | 60 +++++++++++++++++++ .../lexicalpreservation/Difference.java | 55 +++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java new file mode 100755 index 0000000000..d2587880f6 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java @@ -0,0 +1,60 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; + +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.SwitchEntry; +import com.github.javaparser.utils.TestUtils; + +public class Issue3441Test extends AbstractLexicalPreservingTest { + + @Test + void test() { + considerCode( + "public class Foo {\n" + + " void bar() {\n" + + " stmt1(); // comment 1\n" + + " stmt2(); // comment 2\n" + + " }\n" + + "}"); + String expected = + "public class Foo {\n" + + " void bar() {\n" + + " stmt2(); // comment 2\n" + + " }\n" + + "}"; + + BlockStmt block = cu.findFirst(BlockStmt.class).get(); + Statement stmt = block.getStatements().get(0); + + block.remove(stmt); + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 4079e1a1f5..bcf68cf154 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -97,6 +97,55 @@ private List processIndentation(List indentation, } return res; } + + /* + * Returns the position of the next element in the list starting from @{code fromIndex} which is a comment (Ignoring spaces) + * or -1 if it's not a comment. + */ + private int posOfNextComment(int fromIndex, List elements) { + if (!isValidIndex(fromIndex, elements)) + return -1; + ReadOnlyListIterator iterator = new ReadOnlyListIterator(elements, fromIndex); + // search for the next consecutive space characters + while (iterator.hasNext()) { + TextElement element = iterator.next(); + if (element.isSpaceOrTab()) { + continue; + } + if (element.isComment()) { + return iterator.index(); + } + break; + } + return -1; + } + + /* + * Returns true if the next element in the list (starting from @{code fromIndex}) is a comment + */ + private boolean isFollowedByComment(int fromIndex, List elements) { + return posOfNextComment(fromIndex, elements) != -1; + } + + /* + * Removes all elements in the list starting from @{code fromIndex}) ending to @{code toIndex}) + */ + private void removeElements(int fromIndex, int toIndex, List elements) { + if (!(isValidIndex(fromIndex, elements) && isValidIndex(toIndex, elements) && fromIndex <= toIndex)) + return; + ListIterator iterator = elements.listIterator(fromIndex); + // removing elements + int count = fromIndex; + while (iterator.hasNext() && count <= toIndex) { + TextElement element = iterator.next(); + iterator.remove(); + count++; + } + } + + private boolean isValidIndex(int index, List elements) { + return index >= 0 && index <= elements.size(); + } /* * Returns the position of the last new line character or -1 if there is no eol in the specified list of TextElement @@ -461,6 +510,12 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, } } } + // We need to know if, in the original list of elements, the deleted child node is immediately followed by a comment. + // If so, it should also be deleted. + if (isFollowedByComment(originalIndex, originalElements)) { + int indexOfNextComment = posOfNextComment(originalIndex, originalElements); + removeElements(originalIndex, indexOfNextComment, originalElements); + } diffIndex++; } } else if (removed.isToken() && originalElementIsToken && (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // handle EOLs separately as their token kind might not be equal. This is because the 'removed' From db6711d2c930a5c595bf70df1e46b9c8e51229c1 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 25 Nov 2022 22:47:39 +0100 Subject: [PATCH 077/280] Fix: #3472 Line comment removal causes IllegalStateException with LexicalPreservingPrinter --- .../LexicalPreservingPrinter.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index 3670b05aea..097ec82201 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -196,7 +196,7 @@ private int getIndexOfComment(Comment oldValue, NodeText nodeText) { private List findChildTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingChildElements; - matchingChildElements = nodeText.getElements().stream().filter(e -> e.isChild()).map(c -> (ChildTextElement) c).filter(c -> c.isComment()).filter(c -> ((Comment) c.getChild()).getContent().equals(oldValue.getContent())).collect(toList()); + matchingChildElements = selectMatchingChildElements(oldValue, nodeText); if (matchingChildElements.size() > 1) { // Duplicate child nodes found, refine the result matchingChildElements = matchingChildElements.stream().filter(t -> isEqualRange(t.getChild().getRange(), oldValue.getRange())).collect(toList()); @@ -206,6 +206,30 @@ private List findChildTextElementForComment(Comment oldValue, } return matchingChildElements; } + + private List selectMatchingChildElements(Comment oldValue, NodeText nodeText) { + List result = new ArrayList<>(); + List childTextElements = nodeText.getElements().stream().filter(e -> e.isChild()) + .map(c -> (ChildTextElement) c).collect(toList()); + ListIterator iterator = childTextElements.listIterator(); + while(iterator.hasNext()) { + ChildTextElement textElement = iterator.next(); + if (textElement.isComment() && isSameComment(((Comment) textElement.getChild()), oldValue)) { + result.add(textElement); + continue; + } + Node node = textElement.getChild(); + if (node.getComment().isPresent() && isSameComment(node.getComment().get(), oldValue)) { + result.add(textElement); + continue; + } + } + return result; + } + + private boolean isSameComment(Comment childValue, Comment oldValue) { + return childValue.getContent().equals(oldValue.getContent()); + } private List findTokenTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingTokens; @@ -370,7 +394,9 @@ private static Iterator tokensPreceeding(final Node node) { if (node.getParentNode().get() instanceof VariableDeclarator) { return tokensPreceeding(node.getParentNode().get()); } else { - throw new IllegalArgumentException(String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", node, node.getParentNode().get(), parentNodeText)); + // comment node can be removed at this stage. + return new TextElementIteratorsFactory.EmptyIterator(); +// throw new IllegalArgumentException(String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s", node, node.getParentNode().get(), parentNodeText)); } } return new TextElementIteratorsFactory.CascadingIterator<>(TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1), () -> tokensPreceeding(node.getParentNode().get())); From 945249a691bd7a69edb600e32d2abab87bf66f19 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 26 Nov 2022 10:20:29 +0100 Subject: [PATCH 078/280] Fix: #3216 LexicalPreservingPrinter add Wrong indentation when removing comments --- .../LexicalPreservingPrinterTest.java | 58 ++++++++++++++ ...nMemberDeclarationTransformationsTest.java | 2 +- .../LexicalPreservingPrinter.java | 76 +++++++++++++++++-- 3 files changed, 130 insertions(+), 6 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java index 75e8aabd52..29c3c830e3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java @@ -1755,5 +1755,63 @@ void testRemovingInlinedAnnotation_alternate_case() { assertTransformedToString(expectedCode, cu); } + + // issue 3216 LexicalPreservingPrinter add Wrong indentation when removing comments + @Test + void removedIndentationLineCommentsPrinted() { + considerCode("public class Foo {\n" + + " //line \n" + + " void mymethod() {\n" + + " }\n" + + "}"); + String expected = + "public class Foo {\n" + + " void mymethod() {\n" + + " }\n" + + "}"; + cu.getAllContainedComments().get(0).remove(); + System.out.println(LexicalPreservingPrinter.print(cu)); + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + + // issue 3216 LexicalPreservingPrinter add Wrong indentation when removing comments + @Test + void removedIndentationBlockCommentsPrinted() { + considerCode("public class Foo {\n" + + " /*\n" + + " *Block comment coming through\n" + + " */\n" + + " void mymethod() {\n" + + " }\n" + + "}"); + String expected = + "public class Foo {\n" + + " void mymethod() {\n" + + " }\n" + + "}"; + cu.getAllContainedComments().get(0).remove(); + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + + // issue 3216 LexicalPreservingPrinter add Wrong indentation when removing comments + @Test + void removedIndentationJavaDocCommentsPrinted() { + considerCode("public class Foo {\n" + + " /**\n" + + " *JavaDoc comment coming through\n" + + " */\n" + + " void mymethod() {\n" + + " }\n" + + "}"); + String expected = + "public class Foo {\n" + + " void mymethod() {\n" + + " }\n" + + "}"; + cu.getAllContainedComments().get(0).remove(); + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/AnnotationMemberDeclarationTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/AnnotationMemberDeclarationTransformationsTest.java index f00c7465e9..29bc5a184e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/AnnotationMemberDeclarationTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/AnnotationMemberDeclarationTransformationsTest.java @@ -161,7 +161,7 @@ void addingJavadoc() { void removingJavadoc() { AnnotationMemberDeclaration it = consider("/**Cool this annotation!*/ int foo();"); assertTrue(it.getJavadocComment().get().remove()); - assertTransformedToString("@interface AD { int foo(); }", it.getParentNode().get()); + assertTransformedToString("@interface AD { int foo(); }", it.getParentNode().get()); } @Test diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index 097ec82201..3f55f2fc6e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -130,7 +130,7 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert Optional parentNode = observedNode.getParentNode(); NodeText nodeText = parentNode.map(parent -> getOrCreateNodeText(parentNode.get())).// We're at the root node. orElse(getOrCreateNodeText(observedNode)); - if (oldValue == null) { + if (oldValue == null) { // this case corresponds to the addition of a comment int index = parentNode.isPresent() ? // Find the position of the comment node and put in front of it the [...] nodeText.findChild(observedNode) : // 0; @@ -139,18 +139,23 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert LineSeparator lineSeparator = observedNode.getLineEndingStyleOrDefault(LineSeparator.SYSTEM); nodeText.addElement(index, makeCommentToken((Comment) newValue)); nodeText.addToken(index + 1, eolTokenKind(lineSeparator), lineSeparator.asRawString()); - } else if (newValue == null) { + } else if (newValue == null) { // this case corresponds to a deletion of a comment if (oldValue instanceof Comment) { if (((Comment) oldValue).isOrphan()) { nodeText = getOrCreateNodeText(observedNode); } int index = getIndexOfComment((Comment) oldValue, nodeText); nodeText.removeElement(index); - if (nodeText.getElements().get(index).isNewline()) { - nodeText.removeElement(index); + if (isCompleteLine(nodeText.getElements(), index)) { + removeAllExtraCharacters(nodeText.getElements(), index); + } else { + removeAllExtraCharactersStartingFrom(nodeText.getElements().listIterator(index)); } +// if (nodeText.getElements().get(index).isNewline()) { +// nodeText.removeElement(index); +// } } else { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Trying to remove something that is not a comment!"); } } else { List matchingTokens = findTokenTextElementForComment((Comment) oldValue, nodeText); @@ -168,7 +173,68 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } LEXICAL_DIFFERENCE_CALCULATOR.calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue); } + + private boolean isCompleteLine(List elements , int index) { + if (index <= 0 || index >= elements.size()) return false; + boolean isCompleteLine=true; + ListIterator iterator = elements.listIterator(index); + // verify if elements after the index are only spaces or tabs + while(iterator.hasNext()) { + TextElement textElement = iterator.next(); + if (textElement.isNewline()) break; + if (textElement.isSpaceOrTab()) continue; + isCompleteLine=false; + break; + } + // verify if elements before the index are only spaces or tabs + iterator = elements.listIterator(index); + while(iterator.hasPrevious() && isCompleteLine) { + TextElement textElement = iterator.previous(); + if (textElement.isNewline()) break; + if (textElement.isSpaceOrTab()) continue; + isCompleteLine=false; + } + + return isCompleteLine; + } + + private void removeAllExtraCharacters(List elements , int index) { + if (index < 0 || index >= elements.size()) return; + removeAllExtraCharactersStartingFrom(elements.listIterator(index)); + removeAllExtraCharactersBeforePosition(elements.listIterator(index)); + } + + /* + * Removes all spaces,tabs characters before this position + */ + private void removeAllExtraCharactersBeforePosition(ListIterator iterator) { + while(iterator.hasPrevious()) { + TextElement textElement = iterator.previous(); + if (textElement.isSpaceOrTab()) { + iterator.remove(); + continue; + } + break; + } + } + /* + * Removes all spaces,tabs or new line characters starting from this position + */ + private void removeAllExtraCharactersStartingFrom(ListIterator iterator) { + while(iterator.hasNext()) { + TextElement textElement = iterator.next(); + if (textElement.isSpaceOrTab()) { + iterator.remove(); + continue; + } + if (textElement.isNewline()) { + iterator.remove(); + } + break; + } + } + private TokenTextElement makeCommentToken(Comment newComment) { if (newComment.isJavadocComment()) { return new TokenTextElement(JAVADOC_COMMENT, "/**" + newComment.getContent() + "*/"); From 52f65028f89834098a50a37c4b36aa549613f632 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 26 Nov 2022 10:21:15 +0100 Subject: [PATCH 079/280] Minor refactoring --- .../github/javaparser/printer/lexicalpreservation/Added.java | 4 ++-- .../javaparser/printer/lexicalpreservation/RemovedGroup.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java index 8dbc3833c4..c4e712cebb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Added.java @@ -101,13 +101,13 @@ public TextElement toTextElement() { */ @Override public DifferenceElement replaceEolTokens(CsmElement lineSeparator) { - return isNewLineToken() ? new Added(lineSeparator) : this; + return isNewLine() ? new Added(lineSeparator) : this; } /* * Return true if the wrapped {@code CsmElement} is a new line token */ - private boolean isNewLineToken() { + public boolean isNewLine() { return isToken() && ((CsmToken) element).isNewLine(); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java index 2f34b70232..641729e0f4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/RemovedGroup.java @@ -159,7 +159,7 @@ private boolean hasOnlyWhitespace(Removed startElement, Function Date: Sun, 27 Nov 2022 23:56:01 +0100 Subject: [PATCH 080/280] Fix: #3725 JavaParserFacade var type in for-each loop cannot be resolved Before this fix it was not possible to resolve the type of the variable used in a for-each loop when the type of the variable was defined as `var`. This was because the original code only took care of the `var with initializer` case (e.g. `var i = "hello";`). The fix now also covers the usage of a `var` in a for-each loop, e.g. as in `for (var s: names) {...}`. The expression at the right side of the `:` must either be an array or an Iterable. The bug was originally reported in https://github.com/javaparser/javaparser/issues/3725 --- .../javaparsermodel/JavaParserFacade.java | 49 +++++++++++-- .../JavaParserFacadeResolutionTest.java | 68 +++++++++++++++++++ 2 files changed, 112 insertions(+), 5 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 1f3c7dc4fb..3a66124fee 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.ast.stmt.ForEachStmt; import com.github.javaparser.ast.type.*; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; @@ -72,9 +73,9 @@ public class JavaParserFacade { }; private static final Map instances = new WeakHashMap<>(); - + private static final String JAVA_LANG_STRING = String.class.getCanonicalName(); - + /** * Note that the addition of the modifier {@code synchronized} is specific and directly in response to issue #2668. *
This MUST NOT be misinterpreted as a signal that JavaParser is safe to use within a multi-threaded environment. @@ -115,11 +116,11 @@ protected static ResolvedType solveGenericTypes(ResolvedType type, Context conte } // End of static class - + private final TypeSolver typeSolver; private final TypeExtractor typeExtractor; private final SymbolSolver symbolSolver; - + private FailureHandler failureHandler; private JavaParserFacade(TypeSolver typeSolver) { @@ -757,11 +758,49 @@ protected ResolvedType convertVarTypeToUsage(VarType varType, Context context) { throw new IllegalStateException("Trying to resolve a `var` which is not in a variable declaration."); } final VariableDeclarator variableDeclarator = (VariableDeclarator) parent; - return variableDeclarator.getInitializer() + Optional initializer = variableDeclarator.getInitializer(); + if (!initializer.isPresent()) { + // When a `var` type decl has no initializer it may be part of a + // for-each statement (e.g. `for(var i : expr)`). + Optional forEachStmt = forEachStmtWithVariableDeclarator(variableDeclarator); + if (forEachStmt.isPresent()) { + Expression iterable = forEachStmt.get().getIterable(); + ResolvedType iterType = iterable.calculateResolvedType(); + if (iterType instanceof ResolvedArrayType) { + // The type of a variable in a for-each loop with an array + // is the component type of the array. + return ((ResolvedArrayType)iterType).getComponentType(); + } + if (iterType instanceof ResolvedReferenceType) { + // The type of a variable in a for-each loop with an + // Iterable is the same type as returned by the `next()` + // method of its `iterator()` + MethodCallExpr nextCall = new MethodCallExpr( + new MethodCallExpr(iterable, "iterator"), "next"); + MethodUsage methodUsage = solveMethodAsUsage(nextCall); + return methodUsage.returnType(); + } + } + } + return initializer .map(Expression::calculateResolvedType) .orElseThrow(() -> new IllegalStateException("Cannot resolve `var` which has no initializer.")); } + private Optional forEachStmtWithVariableDeclarator( + VariableDeclarator variableDeclarator) { + Optional node = variableDeclarator.getParentNode(); + if (!node.isPresent() || !(node.get() instanceof VariableDeclarationExpr)) { + return Optional.empty(); + } + node = node.get().getParentNode(); + if (!node.isPresent() || !(node.get() instanceof ForEachStmt)) { + return Optional.empty(); + } else { + return Optional.of((ForEachStmt)node.get()); + } + } + public ResolvedType convert(Type type, Node node) { return convert(type, JavaParserFactory.getContext(node, typeSolver)); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 848451351c..72c35e842b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -179,4 +179,72 @@ void classToResolvedTypeViaReflection() { assertTrue(resolvedType.isReferenceType()); assertEquals(clazz.getCanonicalName(), resolvedType.asReferenceType().getQualifiedName()); } + + // See issue 3725 + @Test + void resolveVarTypeInForEachLoopFromArrayExpression() { + String sourceCode = "" + + "import java.util.Arrays;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " for (var s:args) {\n" + + " s.hashCode();\n" + + " }\n" + + " }\n" + + "}"; + + Expression toStringCallScope = scopeOfFirstHashCodeCall(sourceCode); + + // Before fixing the bug the next line failed with + // "java.lang.IllegalStateException: Cannot resolve `var` which has no initializer." + ResolvedType resolvedType = toStringCallScope.calculateResolvedType(); + + assertEquals("java.lang.String", resolvedType.describe()); + } + + // See issue 3725 + @Test + void resolveVarTypeInForEachLoopFromIterableExpression() { + String sourceCode = "" + + "import java.util.Arrays;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " for (var s: Arrays.asList(args)) {\n" + + " s.hashCode();\n" + + " }\n" + + " }\n" + + "}"; + + Expression toStringCallScope = scopeOfFirstHashCodeCall(sourceCode); + + // Before fixing the bug the next line failed with + // "java.lang.IllegalStateException: Cannot resolve `var` which has no initializer." + ResolvedType resolvedType = toStringCallScope.calculateResolvedType(); + + assertEquals("java.lang.String", resolvedType.describe()); + } + + /** + * Private helper method that returns the scope of the first + * {@code hashCode} method call in the given sourceCode. + *

+ * The sourceCode is processed with a Java 15 parser and a + * ReflectionTypeSolver. + */ + private static Expression scopeOfFirstHashCodeCall(String sourceCode) { + // Parse the source code with Java 15 (and ReflectionTypeSolver) + JavaSymbolSolver symbolResolver = + new JavaSymbolSolver(new ReflectionTypeSolver()); + JavaParser parser = new JavaParser(new ParserConfiguration() + .setSymbolResolver(symbolResolver) + .setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_15)); + CompilationUnit cu = parser.parse(sourceCode).getResult().get(); + + MethodCallExpr toStringCall = cu.findAll(MethodCallExpr.class).stream() + .filter(mce -> mce.getNameAsString().equals("hashCode")) + .findFirst().get(); + return toStringCall.getScope().get(); + } } From 7dd9bac2d8e16bea663a51608d36daef77d65090 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 28 Nov 2022 17:09:59 +0100 Subject: [PATCH 081/280] Partial fix of th issue #3223 LexicalPreservingPrinter prints Wrong Import position when there is comment in the ClassOrInterface --- .../printer/lexicalpreservation/Difference.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index bcf68cf154..355a3f5d30 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -588,10 +588,10 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo // note: // increment originalIndex if we want to keep the original element - // increment diffIndex if we don't want to skip the diff element + // increment diffIndex if we want to skip the diff element private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) { - if (originalElement.isComment()) { - originalIndex++; + if (originalElement.isComment()) { + originalIndex++; } else if (kept.isChild() && ((CsmChild) kept.getElement()).getChild() instanceof Comment) { diffIndex++; } else if (kept.isChild() && originalElementIsChild) { @@ -936,7 +936,10 @@ private void applyAddedDiffElement(Added added) { boolean currentIsNewline = nodeText.getTextElement(originalIndex).isNewline(); boolean isFirstElement = originalIndex == 0; boolean previousIsWhiteSpace = originalIndex > 0 && nodeText.getTextElement(originalIndex - 1).isWhiteSpace(); - if (sufficientTokensRemainToSkip && currentIsAComment) { + boolean commentIsBeforeAddedElement = currentIsAComment && addedTextElement.getRange().isPresent() + && nodeText.getTextElement(originalIndex).getRange() + .map(range -> range.isBefore(addedTextElement.getRange().get())).orElse(false); + if (sufficientTokensRemainToSkip && currentIsAComment && commentIsBeforeAddedElement) { // Need to get behind the comment: // FIXME: Why 2? This comment and the next newline? originalIndex += 2; From 5674b074c4b03738b06a6c39c38d3928d96ced6c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 14:58:58 +0100 Subject: [PATCH 082/280] Refactoring convert to usage : Move class SymbolReference to JP core module --- .../javaparser/resolution/model}/SymbolReference.java | 2 +- .../github/javaparser/symbolsolver/JavaSymbolSolver.java | 2 +- .../javaparser/symbolsolver/SourceFileInfoExtractor.java | 2 +- .../javaparser/symbolsolver/core/resolution/Context.java | 2 +- .../core/resolution/SymbolResolutionCapability.java | 2 +- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 6 +++--- .../javaparsermodel/LambdaArgumentTypePlaceholder.java | 2 +- .../symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../javaparsermodel/contexts/AbstractJavaParserContext.java | 2 +- .../contexts/AbstractMethodLikeDeclarationContext.java | 2 +- .../contexts/AnnotationDeclarationContext.java | 2 +- .../contexts/AnonymousClassDeclarationContext.java | 2 +- .../javaparsermodel/contexts/ArrayAccessExprContext.java | 2 +- .../javaparsermodel/contexts/BlockStmtContext.java | 2 +- .../javaparsermodel/contexts/CatchClauseContext.java | 2 +- .../contexts/ClassOrInterfaceDeclarationContext.java | 2 +- .../contexts/ClassOrInterfaceDeclarationExtendsContext.java | 2 +- .../javaparsermodel/contexts/CompilationUnitContext.java | 2 +- .../javaparsermodel/contexts/EnumDeclarationContext.java | 2 +- .../javaparsermodel/contexts/FieldAccessContext.java | 2 +- .../javaparsermodel/contexts/ForEachStatementContext.java | 2 +- .../javaparsermodel/contexts/ForStatementContext.java | 2 +- .../javaparsermodel/contexts/InstanceOfExprContext.java | 2 +- .../contexts/JavaParserTypeDeclarationAdapter.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodCallExprContext.java | 2 +- .../contexts/MethodReferenceExprContext.java | 2 +- .../javaparsermodel/contexts/ObjectCreationContext.java | 2 +- .../javaparsermodel/contexts/StatementContext.java | 2 +- .../javaparsermodel/contexts/SwitchEntryContext.java | 2 +- .../javaparsermodel/contexts/TryWithResourceContext.java | 2 +- .../contexts/VariableDeclarationExprContext.java | 2 +- .../javaparsermodel/declarations/AstResolutionUtils.java | 2 +- .../declarations/JavaParserAnonymousClassDeclaration.java | 2 +- .../declarations/JavaParserClassDeclaration.java | 2 +- .../declarations/JavaParserEnumDeclaration.java | 2 +- .../declarations/JavaParserInterfaceDeclaration.java | 2 +- .../javaparsermodel/declarations/JavaParserTypeAdapter.java | 2 +- .../declarations/JavaParserTypeParameter.java | 2 +- .../declarations/JavaParserTypeVariableDeclaration.java | 2 +- .../JavassistAnnotationMemberDeclaration.java | 2 +- .../javassistmodel/JavassistClassDeclaration.java | 2 +- .../javassistmodel/JavassistEnumDeclaration.java | 2 +- .../javassistmodel/JavassistInterfaceDeclaration.java | 2 +- .../symbolsolver/javassistmodel/JavassistUtils.java | 2 +- .../symbolsolver/logic/MethodResolutionCapability.java | 2 +- .../symbolsolver/model/resolution/TypeSolver.java | 1 + .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 2 +- .../reflectionmodel/ReflectionAnnotationDeclaration.java | 2 +- .../ReflectionAnnotationMemberDeclaration.java | 2 +- .../reflectionmodel/ReflectionClassDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../reflectionmodel/ReflectionMethodResolutionLogic.java | 2 +- .../symbolsolver/resolution/ConstructorResolutionLogic.java | 2 +- .../symbolsolver/resolution/MethodResolutionLogic.java | 2 +- .../javaparser/symbolsolver/resolution/SymbolSolver.java | 2 +- .../symbolsolver/resolution/naming/NameLogic.java | 2 +- .../symbolsolver/resolution/typeinference/TypeHelper.java | 2 +- .../symbolsolver/resolution/typesolvers/AarTypeSolver.java | 2 +- .../resolution/typesolvers/ClassLoaderTypeSolver.java | 2 +- .../resolution/typesolvers/CombinedTypeSolver.java | 2 +- .../symbolsolver/resolution/typesolvers/JarTypeSolver.java | 2 +- .../resolution/typesolvers/JavaParserTypeSolver.java | 2 +- .../resolution/typesolvers/MemoryTypeSolver.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1364Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1814Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue232Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2953Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue300Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue314Test.java | 2 +- .../declarations/JavaParserClassDeclarationTest.java | 2 +- .../declarations/JavaParserEnumDeclarationTest.java | 2 +- .../declarations/JavaParserInterfaceDeclarationTest.java | 2 +- .../symbolsolver/model/resolution/SymbolReferenceTest.java | 1 + .../ReflectionAnnotationDeclarationTest.java | 2 +- .../symbolsolver/resolution/ConstructorsResolutionTest.java | 2 +- .../javaparser/symbolsolver/resolution/ContextTest.java | 2 +- .../symbolsolver/resolution/DefaultPackageTest.java | 2 +- .../symbolsolver/resolution/EnumResolutionTest.java | 2 +- .../symbolsolver/resolution/FieldsResolutionTest.java | 2 +- .../resolution/JavaParserFacadeResolutionTest.java | 2 +- .../symbolsolver/resolution/MethodsResolutionTest.java | 2 +- .../resolution/QualifiedNameResolutionTest.java | 2 +- .../resolution/StatementContextResolutionTest.java | 2 +- .../symbolsolver/resolution/SymbolSolverTest.java | 2 +- .../resolution/SymbolSolverWithJavassistClassTest.java | 2 +- .../resolution/SymbolSolverWithJavassistEnumTest.java | 2 +- .../resolution/SymbolSolverWithJavassistInterfaceTest.java | 2 +- .../resolution/UnknownMethodsResolutionTest.java | 2 +- .../ClassOrInterfaceDeclarationContextResolutionTest.java | 2 +- .../contexts/CompilationUnitContextResolutionTest.java | 2 +- .../contexts/EnumDeclarationContextResolutionTest.java | 2 +- .../javaparser/contexts/MethodContextResolutionTest.java | 2 +- .../resolution/typesolvers/ClassLoaderTypeSolverTest.java | 3 ++- .../resolution/typesolvers/CombinedTypeSolverTest.java | 2 +- .../resolution/typesolvers/JavaParserTypeSolverTest.java | 2 +- 97 files changed, 100 insertions(+), 97 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution => javaparser-core/src/main/java/com/github/javaparser/resolution/model}/SymbolReference.java (98%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/SymbolReference.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/SymbolReference.java index 80c3581fae..9c1db619a2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/SymbolReference.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.resolution; +package com.github.javaparser.resolution.model; import com.github.javaparser.quality.Nullable; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index d93a52cfd3..6c5d609afa 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -30,12 +30,12 @@ import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.*; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java index 03f23c498e..989a4d7a8b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java @@ -34,10 +34,10 @@ import com.github.javaparser.ast.stmt.SwitchEntry; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.io.IOException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index fa9c94e00a..3cb91f9f08 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -28,9 +28,9 @@ import com.github.javaparser.quality.Nullable; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.Value; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java index 622ec24843..87088e68ba 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java @@ -1,7 +1,7 @@ package com.github.javaparser.symbolsolver.core.resolution; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 3a66124fee..018861a4c9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -34,12 +34,12 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; @@ -54,9 +54,9 @@ import java.util.*; import java.util.stream.Collectors; +import static com.github.javaparser.resolution.model.SymbolReference.solved; +import static com.github.javaparser.resolution.model.SymbolReference.unsolved; import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.solved; -import static com.github.javaparser.symbolsolver.model.resolution.SymbolReference.unsolved; /** * Class to be used by final users to solve symbols for JavaParser ASTs. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java index ed8eebea68..097d6117e2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; /** * Placeholder used to represent a lambda argument type while it is being diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 50025e5aa9..f532aa3fcf 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -35,6 +35,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; @@ -43,7 +44,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index a7978d1111..42bb044328 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -29,6 +29,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -36,7 +37,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java index d1cb11b8f7..abe2bb3660 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java @@ -30,12 +30,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java index b92bcbb450..8e7f521e88 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java @@ -26,9 +26,9 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java index c2c53554f1..afa9cb8068 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java @@ -30,13 +30,13 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java index 400b89ed4d..36003e6127 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java @@ -23,7 +23,7 @@ import com.github.javaparser.ast.expr.ArrayAccessExpr; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java index 39ffac21c0..31b7111e6d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java @@ -28,9 +28,9 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java index f909267c0c..4d6b42dcd4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.stmt.CatchClause; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java index b9b1f1be93..fcfbbd3299 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java @@ -30,11 +30,11 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java index 155a058e05..8efd744399 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index e7d3786116..b27f440334 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -32,13 +32,13 @@ import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java index 1d7211c24e..8b08c01c62 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java @@ -27,10 +27,10 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumConstantDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index af2987a6be..5c89036140 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -25,12 +25,12 @@ import com.github.javaparser.ast.expr.FieldAccessExpr; import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java index 8a30658b0b..0099624ded 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.stmt.ForEachStmt; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java index 3d2e6c960c..cefdbc4bf7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java @@ -32,9 +32,9 @@ import com.github.javaparser.ast.stmt.ForStmt; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java index 065d7aed04..862b612fff 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java @@ -3,10 +3,10 @@ import com.github.javaparser.ast.expr.InstanceOfExpr; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 4a34bcf268..78c7e044f1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -33,13 +33,13 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.ConstructorResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 3f82a4adfe..23a2b43811 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -35,13 +35,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 0ab0c8d6d6..e9efd24b92 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -27,10 +27,10 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index aaf5307606..62c4560d13 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -31,12 +31,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java index b78931bca3..f4d9889a47 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java @@ -32,10 +32,10 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index fbc423e20a..8597f9c098 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -30,11 +30,11 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java index 0c43fb4701..f977575ace 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java @@ -27,10 +27,10 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java index 0b34562f94..dd92b1779c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java @@ -30,9 +30,9 @@ import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java index a3a05f399d..501359079e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java @@ -27,10 +27,10 @@ import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java index e8df880e23..056f2bac2f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java @@ -34,8 +34,8 @@ import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.google.common.collect.ImmutableList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java index 45af2b1708..82647a82eb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java @@ -42,6 +42,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -50,7 +51,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ObjectCreationContext; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.google.common.collect.ImmutableList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 9705358eed..5ae63712e4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -44,6 +44,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -52,7 +53,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 1ed4d0d793..8742826ca4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -50,6 +50,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -62,7 +63,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 19fee8194f..4ccefe860e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -45,6 +45,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -54,7 +55,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index f3973028a5..eca4d37a0f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -31,11 +31,11 @@ import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 88440458b2..89704b64c1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -39,12 +39,12 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 985e77e550..959a4d2c87 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -31,12 +31,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index 97b9450440..59003c6b68 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -30,8 +30,8 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtMethod; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index cefb10a4b4..f2ca749e4b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -33,7 +34,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index 109377a5cf..ad4b2b24ed 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -32,7 +33,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index a489b7b3d6..3717851c0e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -33,7 +34,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index eea8e302eb..dadbf0bdfa 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -35,6 +35,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java index 20783e1994..e644dfee0c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.logic; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java index 1fc42425ac..028e8f4f62 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; /** * An element able to find TypeDeclaration from their name. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index acad918f8d..03a1e3490a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -34,6 +34,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; @@ -42,7 +43,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index 72e5612de7..32a12b89e6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -40,6 +40,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -48,7 +49,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index 2df69993cc..a4cb538bd9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -35,9 +35,9 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index cd90acaf9c..96493a5543 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -33,7 +34,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.comparators.MethodComparator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index c16e6a94b7..8e18e5dab9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -33,7 +34,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index e213e290c6..511eee5c87 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -36,7 +37,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index dbdee4f30a..ca71a9fd24 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -25,11 +25,11 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.core.resolution.Context; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java index d49e495b64..149f3aa4b6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java @@ -24,9 +24,9 @@ import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index bfc3b8aa2c..64bbe4f791 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -24,9 +24,9 @@ import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index b2e0d6443f..0ab6fe5353 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -30,13 +30,13 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java index a5decbd1b9..5acb89199e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java @@ -71,9 +71,9 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index dab4a590f6..ca46b36461 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -33,6 +33,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -40,7 +41,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.utils.Pair; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java index ab18891f01..b6da41f042 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.io.File; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java index d6888f2d1e..4429fb8762 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java index c5e42e1656..2b95a0f003 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java @@ -23,9 +23,9 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.NoCache; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java index abdfbbdd80..9d85ac39ed 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java @@ -23,8 +23,8 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javassistmodel.JavassistFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import javassist.ClassPool; import javassist.NotFoundException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java index 083fe73471..8f597b995e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java @@ -25,11 +25,11 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.GuavaCache; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.utils.FileUtils; import com.google.common.cache.CacheBuilder; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java index 94342109b6..f662a9f410 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.HashMap; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java index 6d4329f7a0..d664ad8e24 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java @@ -28,8 +28,8 @@ import com.github.javaparser.ast.expr.SimpleName; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java index 54c835e998..51847bba57 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java @@ -30,8 +30,8 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java index da252ffa25..4f682e8f5a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java @@ -24,11 +24,11 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2953Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2953Test.java index e902c78ba5..ad7ce5a1f0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2953Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2953Test.java @@ -10,13 +10,13 @@ import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.symbolsolver.javassistmodel.JavassistEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java index 855e183e7a..c1b98b0d17 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java @@ -24,10 +24,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.FieldAccessExpr; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java index caeb1bc4a3..7d52d6a2b5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java @@ -24,10 +24,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.*; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java index c9a40abc6b..37e9715880 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java @@ -53,6 +53,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -60,7 +61,6 @@ import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java index 4d65e53fc4..7fcf540c72 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java @@ -59,6 +59,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; @@ -66,7 +67,6 @@ import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapabilityTest; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java index ef1be214ff..ce893cceaa 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java @@ -53,6 +53,7 @@ import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -60,7 +61,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java index 3b7a95a514..33544b88aa 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java @@ -3,6 +3,7 @@ import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java index 69a4952772..0c59bb7470 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java @@ -33,7 +33,7 @@ import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java index 5a75c4b136..e3449ea125 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java @@ -31,12 +31,12 @@ import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 08df65e928..9411ad46ff 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -65,13 +65,13 @@ import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java index fa8021a0fa..6d6c41243b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java @@ -25,11 +25,11 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java index 9b4dc3b3d7..bbdb541437 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java @@ -36,12 +36,12 @@ import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java index b877070fcc..eb55ceec0b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java @@ -32,12 +32,12 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 72c35e842b..89036ba08f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -33,13 +33,13 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedUnionType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java index eb1e75a954..d4a94e4e17 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java @@ -33,13 +33,13 @@ import com.github.javaparser.ast.stmt.*; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java index 9855fe07d5..9ea3ac4255 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java index 289666a605..ca95769dff 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java index cc9476affa..b7993da25c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java index 27631b8430..b2618f5a00 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java index e4b933bf7d..8783467211 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java index d592e49272..f75e0346af 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java index 82b6c99d77..7098b78af3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index f4b599d346..d09f180cd3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -37,13 +37,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java index bb2b2b893a..26508d293e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java @@ -27,11 +27,11 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java index 4db02f4b97..703d8851a1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java index 13010e90d8..3a143f5032 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java @@ -25,10 +25,10 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolverTest.java index 9979243cbd..17d4e34852 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolverTest.java @@ -1,7 +1,8 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; +import com.github.javaparser.resolution.model.SymbolReference; + import org.junit.jupiter.api.Test; import java.util.Map; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java index 28b3a206f8..abdd7a683f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.InMemoryCache; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver.ExceptionHandlers; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolverTest.java index 7564ca910d..4a1eef8b07 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolverTest.java @@ -23,8 +23,8 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration; import com.github.javaparser.utils.CodeGenerationUtils; import org.junit.jupiter.api.Disabled; From 4b8b9db4aa87fa8237418b47034de62d9c8e2d76 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 15:14:25 +0100 Subject: [PATCH 083/280] Refactoring convert to usage : Move class Value to JP core module --- .../java/com/github/javaparser/resolution/model}/Value.java | 2 +- .../github/javaparser/symbolsolver/core/resolution/Context.java | 2 +- .../javaparser/symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../javaparsermodel/contexts/AbstractJavaParserContext.java | 2 +- .../contexts/AbstractMethodLikeDeclarationContext.java | 2 +- .../javaparsermodel/contexts/CatchClauseContext.java | 2 +- .../contexts/ClassOrInterfaceDeclarationContext.java | 2 +- .../javaparsermodel/contexts/FieldAccessContext.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodCallExprContext.java | 2 +- .../symbolsolver/javaparsermodel/contexts/StatementContext.java | 2 +- .../javaparsermodel/contexts/TryWithResourceContext.java | 2 +- .../declarations/JavaParserParameterDeclaration.java | 2 +- .../github/javaparser/symbolsolver/resolution/SymbolSolver.java | 2 +- .../symbolsolver/resolution/GenericsResolutionTest.java | 2 +- .../ClassOrInterfaceDeclarationContextResolutionTest.java | 2 +- .../contexts/CompilationUnitContextResolutionTest.java | 2 +- .../contexts/EnumDeclarationContextResolutionTest.java | 2 +- .../javaparser/contexts/LambdaExprContextResolutionTest.java | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution => javaparser-core/src/main/java/com/github/javaparser/resolution/model}/Value.java (96%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/Value.java similarity index 96% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/Value.java index be1ab2ddb9..a13df115f3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/Value.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.resolution; +package com.github.javaparser.resolution.model; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index 3cb91f9f08..a4644a40df 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -29,9 +29,9 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext; -import com.github.javaparser.symbolsolver.model.resolution.Value; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index f532aa3fcf..219d849b04 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -36,6 +36,7 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; @@ -45,7 +46,6 @@ import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 42bb044328..6cc1fb59bb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -30,6 +30,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java index abe2bb3660..567f17edac 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java @@ -31,13 +31,13 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java index 4d6b42dcd4..dfd04171a0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java @@ -28,10 +28,10 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java index fcfbbd3299..ef0f1fc056 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java @@ -31,12 +31,12 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index 5c89036140..c06d964b66 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -26,13 +26,13 @@ import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import java.util.Collection; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 23a2b43811..d1fd3a8f30 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -36,6 +36,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -43,7 +44,6 @@ import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index e9efd24b92..4bc7d6498c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -28,11 +28,11 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index 8597f9c098..bc1ed382cf 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -31,12 +31,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java index dd92b1779c..ca3f54ac63 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java @@ -31,10 +31,10 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import java.util.Collections; import java.util.LinkedList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java index fceabe0ec9..813fe2b0be 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java @@ -25,13 +25,13 @@ import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 0ab6fe5353..e8ef1a802e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -31,6 +31,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.List; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java index 9812084b89..9482717c6a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java @@ -32,12 +32,12 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index d09f180cd3..15440d24e6 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -38,6 +38,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -45,7 +46,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java index 26508d293e..2bbe2cb257 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java @@ -28,12 +28,12 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java index 703d8851a1..20bc695fba 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java @@ -24,11 +24,11 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java index 441b9ecabb..87d95b3664 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java @@ -28,11 +28,11 @@ import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.model.Value; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.Value; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; From 53349493508cc6e8aecec1f375361fdc1e29f91b Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 15:24:22 +0100 Subject: [PATCH 084/280] Refactoring convert to usage : removing reference to a concrete class in the Context interface --- .../symbolsolver/core/resolution/Context.java | 14 ++++++++++---- .../contexts/AbstractJavaParserContext.java | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index a4644a40df..459e0c3945 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -44,6 +44,12 @@ * @author Federico Tomassetti */ public interface Context { + + /** + * Returns the node wrapped in the context + * + */ + N getWrappedNode(); /** * @return The parent context, if there is one. For example, a method exists within a compilation unit. @@ -273,7 +279,7 @@ default Optional localVariableDeclarationInScope(String name } // First check if the variable is directly declared within this context. - Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode(); + Node wrappedNode = getWrappedNode(); Context parentContext = getParent().get(); Optional localResolutionResults = parentContext .localVariablesExposedToChild(wrappedNode) @@ -296,7 +302,7 @@ default Optional parameterDeclarationInScope(String name) { } // First check if the parameter is directly declared within this context. - Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode(); + Node wrappedNode = getWrappedNode(); Context parentContext = getParent().get(); Optional localResolutionResults = parentContext .parametersExposedToChild(wrappedNode) @@ -342,7 +348,7 @@ default Optional patternExprInScope(String name) { // FIXME: If there are multiple patterns, throw an error? // First check if the pattern is directly declared within this context. - Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode(); + Node wrappedNode = getWrappedNode(); Optional localResolutionResults = parentContext .patternExprsExposedToChild(wrappedNode) .stream() @@ -363,7 +369,7 @@ default Optional fieldDeclarationInScope(String name) } Context parentContext = getParent().get(); // First check if the parameter is directly declared within this context. - Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode(); + Node wrappedNode = getWrappedNode(); Optional localResolutionResults = parentContext .fieldsExposedToChild(wrappedNode) .stream() diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 6cc1fb59bb..c5e484a44b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -275,6 +275,7 @@ protected Collection findTypeDeclarations(Opti ); } + @Override public N getWrappedNode() { return wrappedNode; } From 831ccc1ac5f7104f877fdd89de1ccdb2de2b396d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 15:32:01 +0100 Subject: [PATCH 085/280] Refactoring convert to usage : removing reference to a concrete class in the Context interface (2) --- .../symbolsolver/core/resolution/Context.java | 18 +------------ .../contexts/AbstractJavaParserContext.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java index 459e0c3945..817cdfe627 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java @@ -418,22 +418,6 @@ default SymbolReference solveMethodInParentContext(St * Similar to solveMethod but we return a MethodUsage. * A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables. */ - default Optional solveMethodAsUsage(String name, List argumentsTypes) { - SymbolReference methodSolved = solveMethod(name, argumentsTypes, false); - if (methodSolved.isSolved()) { - ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration(); - if (!(methodDeclaration instanceof TypeVariableResolutionCapability)) { - throw new UnsupportedOperationException(String.format( - "Resolved method declarations must implement %s.", - TypeVariableResolutionCapability.class.getName() - )); - } - - MethodUsage methodUsage = ((TypeVariableResolutionCapability) methodDeclaration).resolveTypeVariables(this, argumentsTypes); - return Optional.of(methodUsage); - } else { - return Optional.empty(); - } - } + Optional solveMethodAsUsage(String name, List argumentsTypes); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index c5e484a44b..26397e732b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -24,7 +24,9 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; +import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -34,6 +36,7 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; +import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; @@ -274,6 +277,28 @@ protected Collection findTypeDeclarations(Opti .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) ); } + + /** + * Similar to solveMethod but we return a MethodUsage. + * A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables. + */ + public Optional solveMethodAsUsage(String name, List argumentsTypes) { + SymbolReference methodSolved = solveMethod(name, argumentsTypes, false); + if (methodSolved.isSolved()) { + ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration(); + if (!(methodDeclaration instanceof TypeVariableResolutionCapability)) { + throw new UnsupportedOperationException(String.format( + "Resolved method declarations must implement %s.", + TypeVariableResolutionCapability.class.getName() + )); + } + + MethodUsage methodUsage = ((TypeVariableResolutionCapability) methodDeclaration).resolveTypeVariables(this, argumentsTypes); + return Optional.of(methodUsage); + } else { + return Optional.empty(); + } + } @Override public N getWrappedNode() { From 4a577eecb34b25827686a665fc9a5c09a66df160 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 20:52:08 +0100 Subject: [PATCH 086/280] Refactoring convert to usage : Move interface TypeSolver to JP core module --- .../java/com/github/javaparser}/resolution/TypeSolver.java | 3 +-- .../github/javaparser/symbolsolver/JavaSymbolSolver.java | 2 +- .../javaparser/symbolsolver/SourceFileInfoExtractor.java | 2 +- .../core/resolution/SymbolResolutionCapability.java | 2 +- .../declarations/common/MethodDeclarationCommonLogic.java | 2 +- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 2 +- .../symbolsolver/javaparsermodel/JavaParserFactory.java | 2 +- .../symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../contexts/AbstractJavaParserContext.java | 2 +- .../contexts/AbstractMethodLikeDeclarationContext.java | 2 +- .../contexts/AnnotationDeclarationContext.java | 2 +- .../contexts/AnonymousClassDeclarationContext.java | 2 +- .../javaparsermodel/contexts/ArrayAccessExprContext.java | 2 +- .../javaparsermodel/contexts/BinaryExprContext.java | 2 +- .../javaparsermodel/contexts/BlockStmtContext.java | 2 +- .../javaparsermodel/contexts/CatchClauseContext.java | 2 +- .../contexts/ClassOrInterfaceDeclarationContext.java | 2 +- .../ClassOrInterfaceDeclarationExtendsContext.java | 2 +- .../javaparsermodel/contexts/CompilationUnitContext.java | 2 +- .../javaparsermodel/contexts/ConstructorContext.java | 2 +- .../javaparsermodel/contexts/EnclosedExprContext.java | 2 +- .../javaparsermodel/contexts/EnumDeclarationContext.java | 2 +- .../javaparsermodel/contexts/FieldAccessContext.java | 2 +- .../javaparsermodel/contexts/ForEachStatementContext.java | 2 +- .../javaparsermodel/contexts/ForStatementContext.java | 2 +- .../javaparsermodel/contexts/IfStatementContext.java | 2 +- .../javaparsermodel/contexts/InstanceOfExprContext.java | 2 +- .../contexts/JavaParserTypeDeclarationAdapter.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodCallExprContext.java | 2 +- .../javaparsermodel/contexts/MethodContext.java | 2 +- .../contexts/MethodReferenceExprContext.java | 2 +- .../javaparsermodel/contexts/ObjectCreationContext.java | 2 +- .../javaparsermodel/contexts/StatementContext.java | 2 +- .../javaparsermodel/contexts/SwitchEntryContext.java | 2 +- .../javaparsermodel/contexts/TryWithResourceContext.java | 2 +- .../javaparsermodel/contexts/UnaryExprContext.java | 2 +- .../contexts/VariableDeclarationExprContext.java | 2 +- .../contexts/VariableDeclaratorContext.java | 2 +- .../javaparsermodel/declarations/AstResolutionUtils.java | 2 +- .../declarations/JavaParserAnnotationDeclaration.java | 2 +- .../JavaParserAnnotationMemberDeclaration.java | 2 +- .../declarations/JavaParserAnonymousClassDeclaration.java | 2 +- .../declarations/JavaParserClassDeclaration.java | 2 +- .../declarations/JavaParserConstructorDeclaration.java | 2 +- .../declarations/JavaParserEnumConstantDeclaration.java | 2 +- .../declarations/JavaParserEnumDeclaration.java | 2 +- .../declarations/JavaParserFieldDeclaration.java | 2 +- .../declarations/JavaParserInterfaceDeclaration.java | 2 +- .../declarations/JavaParserMethodDeclaration.java | 2 +- .../declarations/JavaParserParameterDeclaration.java | 2 +- .../declarations/JavaParserPatternDeclaration.java | 2 +- .../declarations/JavaParserSymbolDeclaration.java | 2 +- .../declarations/JavaParserTypeAdapter.java | 2 +- .../declarations/JavaParserTypeParameter.java | 2 +- .../declarations/JavaParserTypeVariableDeclaration.java | 2 +- .../declarations/JavaParserVariableDeclaration.java | 2 +- .../declarators/AbstractSymbolDeclarator.java | 2 +- .../javaparsermodel/declarators/FieldSymbolDeclarator.java | 2 +- .../javaparsermodel/declarators/NoSymbolDeclarator.java | 2 +- .../declarators/ParameterSymbolDeclarator.java | 2 +- .../declarators/PatternSymbolDeclarator.java | 2 +- .../declarators/VariableSymbolDeclarator.java | 2 +- .../javassistmodel/JavassistAnnotationDeclaration.java | 2 +- .../JavassistAnnotationMemberDeclaration.java | 2 +- .../javassistmodel/JavassistClassDeclaration.java | 2 +- .../javassistmodel/JavassistConstructorDeclaration.java | 3 ++- .../javassistmodel/JavassistEnumConstantDeclaration.java | 2 +- .../javassistmodel/JavassistEnumDeclaration.java | 2 +- .../symbolsolver/javassistmodel/JavassistFactory.java | 2 +- .../javassistmodel/JavassistFieldDeclaration.java | 2 +- .../javassistmodel/JavassistInterfaceDeclaration.java | 2 +- .../javassistmodel/JavassistMethodDeclaration.java | 3 ++- .../JavassistMethodLikeDeclarationAdapter.java | 2 +- .../javassistmodel/JavassistParameterDeclaration.java | 3 ++- .../javassistmodel/JavassistTypeDeclarationAdapter.java | 2 +- .../javassistmodel/JavassistTypeParameter.java | 2 +- .../symbolsolver/javassistmodel/JavassistUtils.java | 2 +- .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 2 +- .../symbolsolver/reflectionmodel/MyObjectProvider.java | 2 +- .../reflectionmodel/ReflectionAnnotationDeclaration.java | 2 +- .../ReflectionAnnotationMemberDeclaration.java | 2 +- .../reflectionmodel/ReflectionClassAdapter.java | 2 +- .../reflectionmodel/ReflectionClassDeclaration.java | 2 +- .../reflectionmodel/ReflectionConstructorDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumConstantDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionFactory.java | 2 +- .../reflectionmodel/ReflectionFieldDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../reflectionmodel/ReflectionMethodDeclaration.java | 2 +- .../reflectionmodel/ReflectionMethodResolutionLogic.java | 2 +- .../reflectionmodel/ReflectionParameterDeclaration.java | 2 +- .../reflectionmodel/ReflectionPatternDeclaration.java | 2 +- .../reflectionmodel/ReflectionTypeParameter.java | 2 +- .../resolution/ConstructorResolutionLogic.java | 2 +- .../symbolsolver/resolution/MethodResolutionLogic.java | 2 +- .../javaparser/symbolsolver/resolution/SymbolSolver.java | 2 +- .../symbolsolver/resolution/naming/NameLogic.java | 2 +- .../symbolsolver/resolution/typeinference/BoundSet.java | 2 +- .../resolution/typeinference/ConstraintFormulaSet.java | 4 ++-- .../resolution/typeinference/ExpressionHelper.java | 2 +- .../symbolsolver/resolution/typeinference/TypeHelper.java | 2 +- .../resolution/typeinference/TypeInference.java | 2 +- .../resolution/typeinference/TypeInferenceCache.java | 2 +- .../constraintformulas/ExpressionCompatibleWithType.java | 2 +- .../constraintformulas/TypeCompatibleWithType.java | 2 +- .../constraintformulas/TypeSubtypeOfType.java | 2 +- .../symbolsolver/resolution/typesolvers/AarTypeSolver.java | 2 +- .../resolution/typesolvers/ClassLoaderTypeSolver.java | 2 +- .../resolution/typesolvers/CombinedTypeSolver.java | 2 +- .../symbolsolver/resolution/typesolvers/JarTypeSolver.java | 3 ++- .../resolution/typesolvers/JavaParserTypeSolver.java | 2 +- .../resolution/typesolvers/MemoryTypeSolver.java | 2 +- .../com/github/javaparser/symbolsolver/Issue113Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue116Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue128Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1364Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue144Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue156Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1668Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1726Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1814Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1827Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue186Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue18Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1946Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue1950Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue200Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2035Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2044Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2083Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2132Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2162Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2236Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2259Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2284Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2289Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue232Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue235Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2397Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue241Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2477Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2481Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2489Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue251Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2595Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2764Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue276Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue2823Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue300Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue3028Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue314Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue343Test.java | 2 +- .../com/github/javaparser/symbolsolver/Issue347Test.java | 2 +- .../symbolsolver/JavaParserAPIIntegrationTest.java | 2 +- .../javaparser/symbolsolver/PullRequest2398Test.java | 2 +- .../symbolsolver/SolveMethodDeclaredInEnumTest.java | 2 +- .../symbolsolver/javaparsermodel/ConvertToUsageTest.java | 2 +- .../javaparsermodel/DifferentiateDotExpressionTest.java | 2 +- .../symbolsolver/javaparsermodel/JavaParserFacadeTest.java | 2 +- .../contexts/ClassOrInterfaceDeclarationContextTest.java | 2 +- .../declarations/JavaParserAnnotationDeclarationTest.java | 2 +- .../declarations/JavaParserClassDeclarationTest.java | 2 +- .../declarations/JavaParserEnumDeclarationTest.java | 2 +- .../declarations/JavaParserInterfaceDeclarationTest.java | 2 +- .../declarations/JavaParserMethodDeclarationTest.java | 2 +- .../declarations/JavaParserSymbolDeclarationTest.java | 2 +- .../declarations/JavaParserTypeParameterTest.java | 2 +- .../symbolsolver/javassistmodel/Issue257Test.java | 2 +- .../javassistmodel/JavassistAnnotationDeclarationTest.java | 2 +- .../JavassistAnnotationMemberDeclarationTest.java | 2 +- .../javassistmodel/JavassistClassDeclarationTest.java | 2 +- .../JavassistConstructorDeclarationTest.java | 2 +- .../JavassistEnumConstantDeclarationTest.java | 2 +- .../javassistmodel/JavassistEnumDeclarationTest.java | 2 +- .../javassistmodel/JavassistFieldDeclarationTest.java | 2 +- .../javassistmodel/JavassistInterfaceDeclarationTest.java | 2 +- .../javassistmodel/JavassistMethodDeclarationTest.java | 2 +- .../javassistmodel/JavassistParameterDeclarationTest.java | 2 +- .../JavassistTypeDeclarationAdapterTest.java | 2 +- .../JavassistTypeParameterDeclarationTest.java | 2 +- .../symbolsolver/logic/FunctionInterfaceLogicTest.java | 2 +- .../symbolsolver/logic/InferenceContextTest.java | 2 +- .../symbolsolver/model/resolution/SymbolReferenceTest.java | 1 + .../symbolsolver/model/typesystem/ArrayTypeTest.java | 2 +- .../symbolsolver/model/typesystem/LazyTypeTest.java | 2 +- .../symbolsolver/model/typesystem/NullTypeTest.java | 2 +- .../symbolsolver/model/typesystem/PrimitiveTypeTest.java | 2 +- .../symbolsolver/model/typesystem/ReferenceTypeTest.java | 2 +- .../model/typesystem/TypeVariableUsageTest.java | 2 +- .../symbolsolver/model/typesystem/VoidTypeTest.java | 2 +- .../symbolsolver/model/typesystem/WildcardUsageTest.java | 2 +- .../ReflectionAnnotationDeclarationTest.java | 2 +- .../reflectionmodel/ReflectionClassDeclarationTest.java | 2 +- .../reflectionmodel/ReflectionEnumDeclarationTest.java | 2 +- .../reflectionmodel/ReflectionFieldDeclarationTest.java | 2 +- .../ReflectionInterfaceDeclarationTest.java | 2 +- .../reflectionmodel/ReflectionMethodDeclarationTest.java | 2 +- .../ReflectionParameterDeclarationTest.java | 2 +- .../symbolsolver/resolution/AbstractResolutionTest.java | 2 +- .../resolution/AnalyseNewJavaParserHelpersTest.java | 2 +- .../resolution/ConstructorsResolutionTest.java | 2 +- .../javaparser/symbolsolver/resolution/ContextTest.java | 2 +- .../symbolsolver/resolution/EnumResolutionTest.java | 2 +- .../symbolsolver/resolution/ExprResolutionTest.java | 2 +- .../symbolsolver/resolution/GenericsResolutionTest.java | 2 +- .../javaparser/symbolsolver/resolution/InstanceOfTest.java | 2 +- .../resolution/JavaParserFacadeResolutionTest.java | 2 +- .../resolution/MethodReferenceResolutionTest.java | 2 +- .../resolution/MethodsResolutionLogicTest.java | 2 +- .../symbolsolver/resolution/MethodsResolutionTest.java | 2 +- .../resolution/StatementContextResolutionTest.java | 2 +- .../symbolsolver/resolution/SymbolSolverTest.java | 2 +- .../resolution/SymbolSolverWithJavassistClassTest.java | 2 +- .../resolution/SymbolSolverWithJavassistEnumTest.java | 2 +- .../resolution/SymbolSolverWithJavassistInterfaceTest.java | 2 +- .../symbolsolver/resolution/VariadicResolutionTest.java | 2 +- .../symbolsolver/resolution/javaparser/VarTypeTest.java | 2 +- .../ClassOrInterfaceDeclarationContextResolutionTest.java | 2 +- .../contexts/CompilationUnitContextResolutionTest.java | 2 +- .../contexts/EnumDeclarationContextResolutionTest.java | 2 +- .../contexts/FieldAccessContextResolutionTest.java | 2 +- .../contexts/LambdaExprContextResolutionTest.java | 2 +- .../javaparser/contexts/MethodContextResolutionTest.java | 2 +- .../JavaParserTypeParameterResolutionTest.java | 2 +- .../resolution/naming/AbstractNameLogicTest.java | 2 +- .../resolution/naming/NameLogicDisambiguationTest.java | 2 +- .../reflectionmodel/SymbolResolutionResolutionTest.java | 2 +- .../resolution/typeinference/bounds/SameAsBoundTest.java | 2 +- .../typeinference/bounds/SubtypeOfBoundTest.java | 2 +- .../constraintformulas/ConstraintFormulaTest.java | 2 +- .../resolution/typesolvers/AbstractTypeSolverTest.java | 7 ++++--- .../resolution/typesolvers/CombinedTypeSolverTest.java | 2 +- 234 files changed, 242 insertions(+), 237 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model => javaparser-core/src/main/java/com/github/javaparser}/resolution/TypeSolver.java (95%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java similarity index 95% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java index 028e8f4f62..aa8c2e4ac4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java @@ -19,9 +19,8 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.resolution; +package com.github.javaparser.resolution; -import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index 6c5d609afa..712079ff96 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -36,7 +37,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.*; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * This implementation of the SymbolResolver wraps the functionality of the library to make them easily usable diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java index 989a4d7a8b..eed469cd3e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java @@ -32,13 +32,13 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.SwitchEntry; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.io.IOException; import java.io.PrintStream; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java index 87088e68ba..f37b8acb41 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/SymbolResolutionCapability.java @@ -1,8 +1,8 @@ package com.github.javaparser.symbolsolver.core.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * Allows for an implementing declaration type to support solving for field (symbol) usage. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java index e0d0d3bf74..c96a784284 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.declarations.common; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -29,7 +30,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 018861a4c9..fce78b2446 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.type.*; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -40,7 +41,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java index 86a0089e73..7a640d5780 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java @@ -30,6 +30,7 @@ import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.*; @@ -43,7 +44,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarators.ParameterSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.PatternSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.VariableSymbolDeclarator; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 219d849b04..2e3a912e0c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -45,7 +46,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 26397e732b..077ac010d4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -41,7 +42,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java index 567f17edac..952b8d88f0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java @@ -27,6 +27,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithParameters; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java index 8e7f521e88..bd92271d17 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnnotationDeclarationContext.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -29,7 +30,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java index afa9cb8068..4346e64363 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java @@ -26,6 +26,7 @@ import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.google.common.base.Preconditions; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java index 36003e6127..7dba23162a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ArrayAccessExprContext.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.expr.ArrayAccessExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** *

diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java index 4f7e1e3398..dd435cb7c5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java @@ -4,9 +4,9 @@ import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java index 31b7111e6d..aa6f503468 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java @@ -27,11 +27,11 @@ import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; import java.util.LinkedList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java index dfd04171a0..5ed11c6e4e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java @@ -25,13 +25,13 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java index ef0f1fc056..d283f1e1b3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -36,7 +37,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java index 8efd744399..78cde58305 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationExtendsContext.java @@ -23,11 +23,11 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index b27f440334..1d2c537427 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; @@ -39,7 +40,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ConstructorContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ConstructorContext.java index 1c67561659..2167e327ac 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ConstructorContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ConstructorContext.java @@ -24,7 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ConstructorDeclaration; import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java index 844e0a5126..baca5ce1a8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java @@ -5,9 +5,9 @@ import com.github.javaparser.ast.expr.EnclosedExpr; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; public class EnclosedExprContext extends AbstractJavaParserContext { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java index 8b08c01c62..e1408d876c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnumDeclarationContext.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.body.EnumConstantDeclaration; import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumConstantDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index c06d964b66..8bc1f206ce 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.FieldAccessExpr; import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import java.util.Collection; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java index 0099624ded..f855c9d359 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java @@ -25,12 +25,12 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ForEachStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java index cefdbc4bf7..ddde217c27 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java @@ -30,12 +30,12 @@ import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.nodeTypes.NodeWithStatements; import com.github.javaparser.ast.stmt.ForStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java index 893fc09ad7..b44c983474 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java @@ -4,9 +4,9 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java index 862b612fff..272fb49434 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java @@ -2,12 +2,12 @@ import com.github.javaparser.ast.expr.InstanceOfExpr; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 78c7e044f1..8646ec55ed 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -40,7 +41,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.ConstructorResolutionLogic; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index d1fd3a8f30..1d55a9be0f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -43,7 +44,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 4bc7d6498c..52ccfbc14b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodContext.java index a23f131af7..2cd67b8095 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodContext.java @@ -24,7 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 62c4560d13..7bf0dc4b6e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java index f4d9889a47..001c2d0eb3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -36,7 +37,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index bc1ed382cf..44809fd6d1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.nodeTypes.NodeWithStatements; import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; @@ -36,7 +37,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java index f977575ace..0cdbb02790 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.SwitchEntry; import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java index ca3f54ac63..8365ceb907 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java @@ -28,13 +28,13 @@ import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; import java.util.LinkedList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java index a6ebe5bb7b..1f0289cc56 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java @@ -1,10 +1,10 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.expr.UnaryExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java index 501359079e..ebb489d421 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java @@ -26,12 +26,12 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java index 8cb9222667..6b57f46ca8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java index 056f2bac2f..8e679954d9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/AstResolutionUtils.java @@ -30,13 +30,13 @@ import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; import com.github.javaparser.ast.nodeTypes.NodeWithMembers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.google.common.collect.ImmutableList; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java index dbecff49a4..79a413b8de 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.ast.body.AnnotationMemberDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -41,7 +42,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java index 67451e1140..7a2f67a9ca 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java @@ -23,12 +23,12 @@ import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java index 82647a82eb..ceed1d3156 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java @@ -36,6 +36,7 @@ import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -51,7 +52,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ObjectCreationContext; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 5ae63712e4..99bac02298 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -36,6 +36,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -53,7 +54,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java index 9be898cca5..44b9379db4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserConstructorDeclaration.java @@ -24,10 +24,10 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java index 25ca5ca751..e9cd2eade8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.ast.body.EnumDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 8742826ca4..6c0c83294d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -38,6 +38,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -63,7 +64,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java index 51c2c3fc1c..e796094c34 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java @@ -30,12 +30,12 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 4ccefe860e..e5cb442073 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -36,6 +36,7 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -55,7 +56,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java index ad1161308b..fb1cc7c510 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -36,7 +37,6 @@ import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.List; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java index 813fe2b0be..032fe518fb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserParameterDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.model.Value; @@ -31,7 +32,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java index 47f6c77a69..30e78aefac 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserPatternDeclaration.java @@ -22,11 +22,11 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java index 7853029eae..6cfd9cff12 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java @@ -28,7 +28,7 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; /** * This should not be used to represent fields of parameters. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index eca4d37a0f..bed1f06188 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -28,6 +28,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -36,7 +37,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 89704b64c1..20b91110c8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -45,7 +46,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 959a4d2c87..57852c5be7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java index 6be6794377..8d9230fac9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java @@ -23,11 +23,11 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java index 99bcb0450e..3015988643 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java @@ -22,7 +22,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarators; import com.github.javaparser.ast.Node; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/FieldSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/FieldSymbolDeclarator.java index 74a72012d0..b62efbd344 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/FieldSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/FieldSymbolDeclarator.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/NoSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/NoSymbolDeclarator.java index 0ce3daa123..601faa5c22 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/NoSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/NoSymbolDeclarator.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarators; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/ParameterSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/ParameterSymbolDeclarator.java index 7ac9adae31..58b73579c0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/ParameterSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/ParameterSymbolDeclarator.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarators; import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/PatternSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/PatternSymbolDeclarator.java index e5b883713c..27c5bc668d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/PatternSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/PatternSymbolDeclarator.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarators; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.LinkedList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/VariableSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/VariableSymbolDeclarator.java index 131538ae37..a008cb09e4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/VariableSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/VariableSymbolDeclarator.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java index 2d766ac354..854ab96fa5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -40,7 +41,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import javassist.CtClass; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index 59003c6b68..72f0765224 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -28,11 +28,11 @@ import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.LongLiteralExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtMethod; import javassist.bytecode.AnnotationDefaultAttribute; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index f2ca749e4b..73e046a3c6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java index d91364cd8c..5bf72cb283 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java @@ -23,9 +23,10 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; + import javassist.CtConstructor; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java index e9db25eb14..13292dd4e1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtField; import javassist.bytecode.AccessFlag; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index ad4b2b24ed..369919d05a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -33,7 +34,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java index 0c4ee68722..2dea433447 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.*; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.*; import javassist.CtClass; import javassist.NotFoundException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java index 4f6b457c24..79e21aa0ec 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java @@ -24,11 +24,11 @@ import java.lang.reflect.Modifier; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import javassist.CtField; import javassist.bytecode.BadBytecode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index 3717851c0e..f60154edf5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java index 400cc85c88..21aac6fd15 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -33,7 +34,7 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; + import javassist.CtMethod; import java.lang.reflect.Modifier; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java index 444aaacb0f..083df39813 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtBehavior; import javassist.bytecode.BadBytecode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java index a92214faef..f28ae1d190 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java @@ -21,9 +21,10 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; + import javassist.CtClass; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java index e29c22f78c..771f00791c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -30,7 +31,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java index 782c377ee6..eaa130a28d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java @@ -26,12 +26,12 @@ import java.util.Objects; import java.util.Optional; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.bytecode.SignatureAttribute; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index dadbf0bdfa..6b4eb5ca24 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -45,7 +46,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index 03a1e3490a..fb3e19551a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -43,7 +44,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java index f79fdf71e7..1a5d47b4e9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.logic.ObjectProvider; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index 32a12b89e6..31c7aea5cc 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -49,7 +50,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Malte Skoruppa diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index a4cb538bd9..e99d1270e5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -33,12 +33,12 @@ import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.LongLiteralExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index 22ebf5f546..c234da56e8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 96493a5543..8be892e5b6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.comparators.MethodComparator; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java index 51e1b98dda..1335be41d4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java @@ -23,12 +23,12 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.lang.reflect.Constructor; import java.util.Arrays; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java index af013d74ce..8db8b9df89 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 8e18e5dab9..28ec71dbce 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java index 3f5efcfe9a..2e9d999eff 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java @@ -30,6 +30,7 @@ import java.util.List; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; @@ -39,7 +40,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java index 5a6ca45b64..f7c4a527da 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java @@ -25,10 +25,10 @@ import java.lang.reflect.Modifier; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 511eee5c87..6dbb5c1268 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java index e37b7901b0..14c41c8dc4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -32,7 +33,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.lang.reflect.Method; import java.lang.reflect.Modifier; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index ca71a9fd24..8d53ba44ef 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -30,7 +31,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.core.resolution.Context; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java index 729d240a60..73b914914f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.Objects; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java index 96caa0af8c..3f3e25e5d3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * WARNING: Implemented fairly blindly. Unsure if required or even appropriate. Use with extreme caution. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java index 74abde2b3d..3e32c1644d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java @@ -30,12 +30,12 @@ import java.util.Optional; import java.util.stream.Collectors; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java index 149f3aa4b6..f6da457ea1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java @@ -22,12 +22,12 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.resolution.MethodAmbiguityException; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.ArrayList; import java.util.HashMap; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index 64bbe4f791..1d2c8f09b6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -23,11 +23,11 @@ import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index e8ef1a802e..2f44ed6a31 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java index 5acb89199e..66ca2c1572 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java @@ -68,13 +68,13 @@ import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * NameLogic contains a set of static methods to implement the abstraction of a "Name" as defined diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java index f6d7f7d983..4d68611382 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java @@ -34,10 +34,10 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.CapturesBound; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.FalseBound; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ConstraintFormulaSet.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ConstraintFormulaSet.java index d568f84a25..013b660129 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ConstraintFormulaSet.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ConstraintFormulaSet.java @@ -21,11 +21,11 @@ package com.github.javaparser.symbolsolver.resolution.typeinference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - import java.util.LinkedList; import java.util.List; +import com.github.javaparser.resolution.TypeSolver; + /** * @author Federico Tomassetti */ diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java index e5801340a0..7c75d0ffde 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index ca46b36461..dbb888a4f9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.SymbolReference; @@ -41,7 +42,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.utils.Pair; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java index d07d21934a..8b80206071 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java @@ -33,12 +33,12 @@ import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.ThrowsBound; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInferenceCache.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInferenceCache.java index 88916d836a..af1136b3fe 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInferenceCache.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInferenceCache.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.resolution.typeinference; import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java index 6285c60a91..2541a0b4d5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java @@ -42,11 +42,11 @@ import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; import com.github.javaparser.symbolsolver.resolution.typeinference.ControlFlowLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java index f2f428c45a..e730c15b9b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.constraintformulas; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java index 96d765769d..b3ba649ead 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java @@ -23,9 +23,9 @@ import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isProperType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java index b6da41f042..db62634406 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AarTypeSolver.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.io.File; import java.io.IOException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java index 4429fb8762..b74a719ae3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/ClassLoaderTypeSolver.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import java.util.Objects; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java index 2b95a0f003..184804ada5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.NoCache; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.*; import java.util.function.Predicate; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java index 9d85ac39ed..c3c0bf758a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JarTypeSolver.java @@ -21,11 +21,12 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javassistmodel.JavassistFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; + import javassist.ClassPool; import javassist.NotFoundException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java index 8f597b995e..444c7b56c1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java @@ -24,13 +24,13 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.GuavaCache; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.utils.FileUtils; import com.google.common.cache.CacheBuilder; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java index f662a9f410..e0137791b5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/MemoryTypeSolver.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import java.util.HashMap; import java.util.Map; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue113Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue113Test.java index 89a9cd2d71..54e90489bd 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue113Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue113Test.java @@ -24,10 +24,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java index c442de12f6..12737c61f9 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java @@ -26,10 +26,10 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java index c28da114c7..ec0e42ebc8 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java index d664ad8e24..c789752905 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1364Test.java @@ -26,11 +26,11 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java index e6822e9755..bd9aa9968f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java index b1392e00fa..00e32e8649 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1668Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1668Test.java index e34cc22488..e917ab72a7 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1668Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1668Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java index 07721058c9..e0947114ca 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1726Test.java @@ -8,7 +8,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; public class Issue1726Test extends AbstractSymbolResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java index 51847bba57..4411d73a7e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1814Test.java @@ -28,11 +28,11 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java index bdc3ebbd97..5d1b654349 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java @@ -8,8 +8,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java index a1846206fe..ac6508ce62 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java index 79f9330d16..eb522a2dbe 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java @@ -25,10 +25,10 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1946Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1946Test.java index 25151fd92a..61f43fa81b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1946Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1946Test.java @@ -28,9 +28,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.FieldAccessExpr; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java index f212131bbc..28e04020b2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1950Test.java @@ -9,8 +9,8 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java index e058547f69..7b8c7be7d6 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2035Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2035Test.java index c66163cb0e..d9cf461f7b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2035Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2035Test.java @@ -27,7 +27,7 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Assertions; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java index aa9a8e03ba..312c422ca0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2044Test.java @@ -40,9 +40,9 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java index 6c71a980b0..2910c88e9c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2083Test.java @@ -8,7 +8,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java index c50dbc6706..28017435b0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.java @@ -8,7 +8,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java index e059ce0451..18005cadbf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2162Test.java @@ -38,8 +38,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java index 7e70b7cf85..0920ccfca7 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2236Test.java @@ -11,7 +11,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java index c7d49a1dbb..5b97a11b03 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2259Test.java @@ -12,7 +12,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java index 8875744476..3f68029625 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2284Test.java @@ -10,7 +10,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; public class Issue2284Test extends AbstractSymbolResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java index 096b553fc0..ec70f350c2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2289Test.java @@ -10,7 +10,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; public class Issue2289Test extends AbstractSymbolResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java index 4f682e8f5a..991dc7ecd9 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java @@ -23,13 +23,13 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java index f802f0d2b3..b941e2d514 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Assertions; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2397Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2397Test.java index 0c423e869e..9b6ad85209 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2397Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2397Test.java @@ -7,8 +7,8 @@ import com.github.javaparser.ast.stmt.AssertStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java index a857d87ec2..21ac475eb9 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java @@ -25,10 +25,10 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java index 02912c3a5d..a6ed68b390 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2477Test.java @@ -8,7 +8,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2481Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2481Test.java index 1045e1f17c..497372ce30 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2481Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2481Test.java @@ -6,7 +6,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.visitor.VoidVisitorAdapter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java index 14fa146cde..7f69621c6b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2489Test.java @@ -11,7 +11,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java index 77628ac7f6..18cd20f4eb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java index 0d3a66c980..d5271b5348 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2595Test.java @@ -14,7 +14,7 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java index 472aa210c0..7c62ce28e4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2764Test.java @@ -11,8 +11,8 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.printer.PrettyPrinter; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java index 67212fe360..d69bb5fc1f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java index 6e7b291911..00ce648d63 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2823Test.java @@ -8,7 +8,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java index c1b98b0d17..9bbe86d915 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java @@ -23,12 +23,12 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java index 424fb36aac..b73b7f3b05 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java @@ -7,9 +7,9 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.symbolsolver.javaparser.Navigator; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java index 7d52d6a2b5..1ff5c2f936 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java @@ -23,12 +23,12 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.*; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java index 8c5759b48b..f9cdc086c0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java @@ -22,10 +22,10 @@ package com.github.javaparser.symbolsolver; import com.github.javaparser.ast.expr.*; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java index 5779dc74ac..365c733739 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java @@ -23,10 +23,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java index 901024cbf9..e5810a61c0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java @@ -26,9 +26,9 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.*; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/PullRequest2398Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/PullRequest2398Test.java index be5d54c848..c077feba10 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/PullRequest2398Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/PullRequest2398Test.java @@ -4,11 +4,11 @@ import java.io.IOException; import java.nio.file.Path; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javassistmodel.JavassistClassDeclaration; import com.github.javaparser.symbolsolver.javassistmodel.JavassistMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/SolveMethodDeclaredInEnumTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/SolveMethodDeclaredInEnumTest.java index d0f888fe68..4bb3434094 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/SolveMethodDeclaredInEnumTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/SolveMethodDeclaredInEnumTest.java @@ -27,8 +27,8 @@ import com.github.javaparser.StringProvider; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/ConvertToUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/ConvertToUsageTest.java index 90094ff8aa..a5cd25463e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/ConvertToUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/ConvertToUsageTest.java @@ -23,8 +23,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java index 0ec4fd5c4a..c170b44d52 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java index 510b40f56e..0306fdc1db 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java index d9073f5dab..2989915e84 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java @@ -25,10 +25,10 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclarationTest.java index da6b70bcd0..9d75fc54f0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclarationTest.java @@ -36,8 +36,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java index 37e9715880..fffbb1dd49 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java @@ -47,6 +47,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -61,7 +62,6 @@ import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java index 7fcf540c72..33693e2cdf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java @@ -50,6 +50,7 @@ import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.AssociableToASTTest; @@ -67,7 +68,6 @@ import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapabilityTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java index ce893cceaa..8888096842 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java @@ -45,6 +45,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.AssociableToASTTest; @@ -61,7 +62,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java index f158c8b390..5ddc5aea01 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclarationTest.java @@ -23,11 +23,11 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclarationTest; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapabilityTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import java.util.Optional; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclarationTest.java index a31861b5c6..1b75960acc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclarationTest.java @@ -3,8 +3,8 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.PatternExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java index 58a0d007df..93742618e0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameterTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; class JavaParserTypeParameterTest extends AbstractTypeDeclarationTest implements ResolvedTypeParameterDeclarationTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/Issue257Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/Issue257Test.java index dbd8fba0bd..c3eef08dba 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/Issue257Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/Issue257Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java index 22155c7b84..e67f33d3dc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclarationTest.java @@ -32,12 +32,12 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java index 7ffe6d3b84..e21f9e2d18 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclarationTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; import javassist.CtClass; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java index 714aebc293..0039866d45 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java @@ -39,6 +39,7 @@ import org.junit.jupiter.api.Test; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -48,7 +49,6 @@ import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclarationTest.java index 421b9ef4cc..fa4c03d882 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclarationTest.java @@ -22,10 +22,10 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclarationTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; import javassist.CtClass; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java index a290057f71..4d215bf711 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclarationTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclarationTest; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; import javassist.CtClass; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclarationTest.java index a1714602f7..973eee7ad1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclarationTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java index e078176b61..743ad43ca5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclarationTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java index 0871861562..e00366cd32 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -28,7 +29,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclarationTest.java index e5cb3e50b7..b1b0fdff90 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclarationTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclarationTest.java index 6f71036571..c6a3b72ca2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclarationTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapterTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapterTest.java index bd35d9f0ed..51aa98a3f3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapterTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapterTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import javassist.ClassPool; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameterDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameterDeclarationTest.java index c691384046..d19d54dddc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameterDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameterDeclarationTest.java @@ -35,9 +35,9 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java index 3ca4e22b9b..8a0ad75a97 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.logic; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index 21cf73c6cb..a7e7fff741 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -21,11 +21,11 @@ package com.github.javaparser.symbolsolver.logic; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java index 33544b88aa..6c139a2c1a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReferenceTest.java @@ -1,5 +1,6 @@ package com.github.javaparser.symbolsolver.model.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java index 15429218a8..0e4f4c4fda 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java index a78349e0c9..7d313487f2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java @@ -26,9 +26,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java index 975f2e7f3f..5327080b58 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java index 1584d05e70..73ebd3c884 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index 08e6cdfcdb..fe3cdaf2b4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -50,6 +50,7 @@ import com.github.javaparser.StringProvider; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -66,7 +67,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java index 1b5f078dd4..6e333b5a60 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java @@ -21,9 +21,9 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java index 73d87b53df..188ad8aabb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java index c644f73eb2..7f84d6f2da 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.model.typesystem; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java index 0c59bb7470..a22ecc06a2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclarationTest.java @@ -31,10 +31,10 @@ import org.junit.jupiter.api.Test; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; @interface OuterAnnotation { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java index 212042f4e0..0a8b81f252 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java @@ -34,6 +34,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -42,7 +43,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.google.common.collect.ImmutableList; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclarationTest.java index 4147c6ad35..970417ce3a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclarationTest.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java index 3e72a7a366..21a37b6def 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclarationTest.java @@ -28,8 +28,8 @@ import org.junit.jupiter.api.Test; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; class ReflectionFieldDeclarationTest extends AbstractSymbolResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java index 9b45585eaf..13096ed200 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -28,7 +29,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.google.common.collect.ImmutableList; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclarationTest.java index 8613dc8c58..5fbfa42609 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclarationTest.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclarationTest.java index 3eab31cbda..0da820d4a3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclarationTest.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java index 3bb8171a58..7b44c0aa2d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java @@ -27,9 +27,9 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnalyseNewJavaParserHelpersTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnalyseNewJavaParserHelpersTest.java index 1ac9d3f424..7dc844742b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnalyseNewJavaParserHelpersTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnalyseNewJavaParserHelpersTest.java @@ -24,10 +24,10 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java index e3449ea125..96a4ff6ddf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java @@ -30,6 +30,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 9411ad46ff..4ad86e04e5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -61,6 +61,7 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -72,7 +73,6 @@ import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java index bbdb541437..8d2507e872 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -42,7 +43,6 @@ import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java index f3e7e29ff6..1f3d59b755 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java index 9482717c6a..97d0349478 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java @@ -32,12 +32,12 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java index 36802c882f..2d525e2d60 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/InstanceOfTest.java @@ -21,12 +21,12 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; public class InstanceOfTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 89036ba08f..8c1d410d2c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.stmt.CatchClause; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; @@ -40,7 +41,6 @@ import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java index 2b11baf035..2b2e281926 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java @@ -35,11 +35,11 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; class MethodReferenceResolutionTest extends AbstractResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java index c5a695fdfd..63913bd54d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java @@ -22,9 +22,9 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java index d4a94e4e17..91f40b1b72 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; @@ -40,7 +41,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.Log; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java index ca95769dff..8805e2bc37 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java @@ -26,11 +26,11 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java index b7993da25c..c0676f1403 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java @@ -21,11 +21,11 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java index b2618f5a00..2246ad0623 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistClassDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java index 8783467211..bb592bfd36 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistEnumDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java index f75e0346af..7c73727236 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java @@ -21,12 +21,12 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.javassistmodel.JavassistInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java index 48978818bc..612788c8a4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java @@ -36,10 +36,10 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java index ffac83ddaa..9c03a5bb0a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java @@ -26,10 +26,10 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.type.VarType; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index 15440d24e6..6da7bb23a0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -34,6 +34,7 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -45,7 +46,6 @@ import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java index 2bbe2cb257..d8d72c0e34 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.ParseException; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -33,7 +34,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java index 20bc695fba..c363e9f844 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java @@ -22,13 +22,13 @@ package com.github.javaparser.symbolsolver.resolution.javaparser.contexts; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java index c98f84de56..b36e402fbf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java index 87d95b3664..d582f2ac81 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java @@ -28,11 +28,11 @@ import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java index 3a143f5032..ab80a8a42e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java @@ -24,12 +24,12 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java index 085857dbf0..38972012ce 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java @@ -25,13 +25,13 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/AbstractNameLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/AbstractNameLogicTest.java index 535f494ab1..c21d429f5a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/AbstractNameLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/AbstractNameLogicTest.java @@ -23,8 +23,8 @@ import com.github.javaparser.*; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import java.util.List; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogicDisambiguationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogicDisambiguationTest.java index 6b5f7ca4f9..4ffc685b6c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogicDisambiguationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogicDisambiguationTest.java @@ -24,9 +24,9 @@ import com.github.javaparser.ParseStart; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java index dea4379fae..ff6edf8df5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java @@ -28,10 +28,10 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java index c087e3c1e6..297fdc5e40 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java @@ -21,8 +21,8 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.bounds; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.Bound; import com.github.javaparser.symbolsolver.resolution.typeinference.InferenceVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java index bd05620929..ef17f57f6f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java @@ -21,11 +21,11 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.bounds; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.*; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java index 22d8f09529..508422b930 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AbstractTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AbstractTypeSolverTest.java index 2b80cfc9b4..b4c57eb457 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AbstractTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/AbstractTypeSolverTest.java @@ -1,7 +1,8 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; + import org.junit.jupiter.api.Test; import java.util.function.Supplier; @@ -53,9 +54,9 @@ void tryingToSetParentIfParentAlreadyDefinedShouldThrowIllegalStateException() { } /** - * When a {@link com.github.javaparser.symbolsolver.model.resolution.TypeSolver} don't have a parent it should return + * When a {@link com.github.javaparser.resolution.TypeSolver} don't have a parent it should return * {@code null}. - * After setting a parent using {@link com.github.javaparser.symbolsolver.model.resolution.TypeSolver#setParent(TypeSolver)} + * After setting a parent using {@link com.github.javaparser.resolution.TypeSolver#setParent(TypeSolver)} * the method {@link TypeSolver#getParent()} should return the value set. */ @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java index abdd7a683f..5600374ae2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolverTest.java @@ -21,11 +21,11 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.InMemoryCache; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver.ExceptionHandlers; import org.junit.jupiter.api.Test; From 16de7d95c93e7c5b5f7b4de3c25186729d42716f Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 29 Nov 2022 21:01:04 +0100 Subject: [PATCH 087/280] Refactoring convert to usage : Move class LambdaArgumentTypePlaceholder to JP core module --- .../resolution/model}/LambdaArgumentTypePlaceholder.java | 3 +-- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 1 + .../symbolsolver/javassistmodel/JavassistClassDeclaration.java | 2 +- .../javassistmodel/JavassistTypeDeclarationAdapter.java | 2 +- .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionClassAdapter.java | 2 +- .../reflectionmodel/ReflectionClassDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../javassistmodel/JavassistClassDeclarationTest.java | 2 +- .../javassistmodel/JavassistInterfaceDeclarationTest.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel => javaparser-core/src/main/java/com/github/javaparser/resolution/model}/LambdaArgumentTypePlaceholder.java (94%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java similarity index 94% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java index 097d6117e2..554e4cb8d7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java @@ -19,10 +19,9 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.javaparsermodel; +package com.github.javaparser.resolution.model; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; -import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index fce78b2446..6ef3210843 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -35,6 +35,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index 73e046a3c6..925574b099 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -27,13 +27,13 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java index 771f00791c..7a4e904214 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java @@ -28,9 +28,9 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index fb3e19551a..8a248e13ee 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -35,13 +35,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index c234da56e8..c29610d4cb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -28,9 +28,9 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 8be892e5b6..0c9be57512 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -26,13 +26,13 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 6dbb5c1268..6d21abfab4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -27,13 +27,13 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java index 0039866d45..2b4d3e71b7 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java @@ -43,9 +43,9 @@ import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java index e00366cd32..b5e69db9e7 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java @@ -24,11 +24,11 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; From a06833e4b52d8b8b02e22c2879cbb38d0d249e0d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 23:00:52 +0000 Subject: [PATCH 088/280] chore(deps): bump maven-dependency-plugin from 3.3.0 to 3.4.0 Bumps [maven-dependency-plugin](https://github.com/apache/maven-dependency-plugin) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/apache/maven-dependency-plugin/releases) - [Commits](https://github.com/apache/maven-dependency-plugin/compare/maven-dependency-plugin-3.3.0...maven-dependency-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-dependency-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 87ae044f91..b17657978c 100644 --- a/pom.xml +++ b/pom.xml @@ -329,7 +329,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.3.0 + 3.4.0 org.codehaus.mojo From 94946d8991a98f59d41cb7bec2d66804be40dab1 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 08:11:55 +0100 Subject: [PATCH 089/280] Refactoring convert to usage : removing reference to JavaParserTypeVariableDeclaration in the class ReferenceTypeImpl --- .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index 8a248e13ee..f8fbcf13ff 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -42,7 +42,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeTransformer; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration; import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; /** @@ -82,11 +81,7 @@ public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, List< @Override public ResolvedTypeParameterDeclaration asTypeParameter() { - if (this.typeDeclaration instanceof JavaParserTypeVariableDeclaration) { - JavaParserTypeVariableDeclaration javaParserTypeVariableDeclaration = (JavaParserTypeVariableDeclaration) this.typeDeclaration; - return javaParserTypeVariableDeclaration.asTypeParameter(); - } - throw new UnsupportedOperationException(this.typeDeclaration.getClass().getCanonicalName()); + return this.typeDeclaration.asTypeParameter(); } /** From 70af9c63007f3fda402a69f0c6e5db6583ab9116 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 08:17:46 +0100 Subject: [PATCH 090/280] Refactoring convert to usage : Move class FunctionalInterfaceLogic to JP core module --- .../javaparser/resolution}/logic/FunctionalInterfaceLogic.java | 2 +- .../javaparser/symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodReferenceExprContext.java | 2 +- .../javaparser/symbolsolver/logic/AbstractTypeDeclaration.java | 1 + .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionClassAdapter.java | 2 +- .../symbolsolver/resolution/typeinference/TypeHelper.java | 2 +- .../constraintformulas/ExpressionCompatibleWithType.java | 2 +- .../symbolsolver/logic/FunctionInterfaceLogicTest.java | 1 + 10 files changed, 10 insertions(+), 8 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/logic/FunctionalInterfaceLogic.java (98%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java index 425146cc03..dc94af19f1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.logic; +package com.github.javaparser.resolution.logic; import java.lang.reflect.Method; import java.lang.reflect.Parameter; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 2e3a912e0c..755f197a6d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -36,6 +36,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedArrayType; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 1d55a9be0f..8f01fd1501 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -36,13 +36,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 7bf0dc4b6e..6d505b865e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -32,11 +32,11 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractTypeDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractTypeDeclaration.java index 255db3c44b..cea0161080 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractTypeDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractTypeDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.utils.Pair; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index f8fbcf13ff..a81fd897e4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -35,6 +35,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -42,7 +43,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeTransformer; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index c29610d4cb..81a1447aaa 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -28,10 +28,10 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index dbb888a4f9..ace32423cd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -34,6 +34,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; @@ -41,7 +42,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.utils.Pair; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java index 2541a0b4d5..c59a4bdd43 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ExpressionCompatibleWithType.java @@ -43,10 +43,10 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; import com.github.javaparser.symbolsolver.resolution.typeinference.ControlFlowLogic; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java index 8a0ad75a97..9fd985f33f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.logic; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; From 9073420016c508b590f3cbfdc0b68bd5f101ec3c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 08:26:43 +0100 Subject: [PATCH 091/280] Refactoring convert to usage : Move class NullType and LaztType to JP core module --- .../javaparser/resolution}/model/typesystem/LazyType.java | 2 +- .../javaparser/resolution}/model/typesystem/NullType.java | 2 +- .../javaparser/symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../declarations/JavaParserClassDeclaration.java | 2 +- .../javaparsermodel/declarations/JavaParserEnumDeclaration.java | 2 +- .../declarations/JavaParserInterfaceDeclaration.java | 2 +- .../symbolsolver/model/typesystem/ReferenceTypeImpl.java | 1 + .../symbolsolver/reflectionmodel/ReflectionClassAdapter.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../typeinference/constraintformulas/TypeSubtypeOfType.java | 2 +- .../javassistmodel/JavassistClassDeclarationTest.java | 2 +- .../javassistmodel/JavassistInterfaceDeclarationTest.java | 2 +- .../javaparser/symbolsolver/model/typesystem/LazyTypeTest.java | 1 + .../javaparser/symbolsolver/model/typesystem/NullTypeTest.java | 1 + .../symbolsolver/model/typesystem/PrimitiveTypeTest.java | 1 + .../symbolsolver/model/typesystem/ReferenceTypeTest.java | 1 + .../javaparser/symbolsolver/model/typesystem/VoidTypeTest.java | 1 + .../ClassOrInterfaceDeclarationContextResolutionTest.java | 2 +- .../contexts/CompilationUnitContextResolutionTest.java | 2 +- 19 files changed, 19 insertions(+), 13 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/model/typesystem/LazyType.java (98%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/model/typesystem/NullType.java (96%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/LazyType.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/LazyType.java index be319f6f9d..82329a243f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/LazyType.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.typesystem; +package com.github.javaparser.resolution.model.typesystem; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.types.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java similarity index 96% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java index dac282ef7e..87536d8115 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.typesystem; +package com.github.javaparser.resolution.model.typesystem; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 755f197a6d..44610241f0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -39,6 +39,7 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; @@ -46,7 +47,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 99bac02298..08d9f3841c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -46,6 +46,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -54,7 +55,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 6c0c83294d..2a5ded7160 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -52,6 +52,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -64,7 +65,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index e5cb442073..71bcaf222e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -47,6 +47,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -56,7 +57,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.LazyType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java index a81fd897e4..4baddae322 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java @@ -38,6 +38,7 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index 81a1447aaa..1b59dc2721 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -30,9 +30,9 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.annotation.Annotation; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 6d21abfab4..52d3efe1da 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -29,6 +29,7 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java index b3ba649ead..d48209f4d2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeSubtypeOfType.java @@ -24,9 +24,9 @@ import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isProperType; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java index 2b4d3e71b7..63290380bc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java @@ -44,12 +44,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclarationTest; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java index b5e69db9e7..e4b02ab898 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java @@ -25,11 +25,11 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java index 7d313487f2..612b6e7dcf 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java index 5327080b58..c56b001fa6 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java index 73ebd3c884..87de478c71 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index fe3cdaf2b4..f7af6ea0c1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -57,6 +57,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration.Bound; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java index 188ad8aabb..60e5bcaa45 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index 6da7bb23a0..fe9d394aa5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -40,13 +40,13 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java index d8d72c0e34..39572a54c3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java @@ -30,11 +30,11 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; From de5c48e2ed0b173bd8240801e43e52d070a44ab3 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 08:32:43 +0100 Subject: [PATCH 092/280] Refactoring convert to usage : Move class ReferenceTypeImpl to JP core module --- .../resolution}/model/typesystem/ReferenceTypeImpl.java | 3 +-- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 2 +- .../javaparser/symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodCallExprContext.java | 2 +- .../javaparsermodel/contexts/MethodReferenceExprContext.java | 2 +- .../javaparsermodel/contexts/SwitchEntryContext.java | 2 +- .../declarations/JavaParserAnnotationDeclaration.java | 2 +- .../declarations/JavaParserAnonymousClassDeclaration.java | 2 +- .../declarations/JavaParserClassDeclaration.java | 2 +- .../declarations/JavaParserEnumConstantDeclaration.java | 2 +- .../declarations/JavaParserEnumDeclaration.java | 2 +- .../declarations/JavaParserInterfaceDeclaration.java | 2 +- .../javaparsermodel/declarations/JavaParserTypeAdapter.java | 2 +- .../javaparsermodel/declarations/JavaParserTypeParameter.java | 2 +- .../declarations/JavaParserTypeVariableDeclaration.java | 2 +- .../javassistmodel/JavassistAnnotationMemberDeclaration.java | 3 ++- .../symbolsolver/javassistmodel/JavassistClassDeclaration.java | 2 +- .../javassistmodel/JavassistEnumConstantDeclaration.java | 3 ++- .../symbolsolver/javassistmodel/JavassistFactory.java | 2 +- .../javassistmodel/JavassistMethodLikeDeclarationAdapter.java | 3 ++- .../javassistmodel/JavassistTypeDeclarationAdapter.java | 3 ++- .../symbolsolver/javassistmodel/JavassistTypeParameter.java | 2 +- .../javaparser/symbolsolver/javassistmodel/JavassistUtils.java | 2 +- .../symbolsolver/reflectionmodel/MyObjectProvider.java | 2 +- .../reflectionmodel/ReflectionAnnotationMemberDeclaration.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionClassAdapter.java | 2 +- .../reflectionmodel/ReflectionClassDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumConstantDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionFactory.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../reflectionmodel/ReflectionMethodResolutionLogic.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionTypeParameter.java | 2 +- .../symbolsolver/resolution/MethodResolutionLogic.java | 2 +- .../javaparser/symbolsolver/resolution/SymbolSolver.java | 2 +- .../symbolsolver/resolution/typeinference/BoundSet.java | 2 +- .../symbolsolver/resolution/typeinference/TypeHelper.java | 2 +- .../symbolsolver/resolution/typeinference/TypeInference.java | 2 +- .../constraintformulas/TypeCompatibleWithType.java | 2 +- .../javaparser/symbolsolver/JavaParserAPIIntegrationTest.java | 2 +- .../declarations/JavaParserClassDeclarationTest.java | 2 +- .../javassistmodel/JavassistInterfaceDeclarationTest.java | 2 +- .../symbolsolver/logic/FunctionInterfaceLogicTest.java | 2 +- .../javaparser/symbolsolver/logic/InferenceContextTest.java | 2 +- .../symbolsolver/model/typesystem/ArrayTypeTest.java | 1 + .../javaparser/symbolsolver/model/typesystem/LazyTypeTest.java | 1 + .../javaparser/symbolsolver/model/typesystem/NullTypeTest.java | 1 + .../symbolsolver/model/typesystem/PrimitiveTypeTest.java | 1 + .../symbolsolver/model/typesystem/ReferenceTypeTest.java | 1 + .../symbolsolver/model/typesystem/TypeVariableUsageTest.java | 1 + .../javaparser/symbolsolver/model/typesystem/VoidTypeTest.java | 1 + .../symbolsolver/model/typesystem/WildcardUsageTest.java | 1 + .../reflectionmodel/ReflectionClassDeclarationTest.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclarationTest.java | 2 +- .../javaparser/symbolsolver/resolution/ExprResolutionTest.java | 2 +- .../symbolsolver/resolution/MethodsResolutionTest.java | 2 +- .../symbolsolver/resolution/javaparser/VarTypeTest.java | 2 +- .../ClassOrInterfaceDeclarationContextResolutionTest.java | 2 +- .../contexts/MethodCallExprContextResolutionTest.java | 2 +- .../resolution/typeinference/bounds/SameAsBoundTest.java | 2 +- .../resolution/typeinference/bounds/SubtypeOfBoundTest.java | 2 +- .../constraintformulas/ConstraintFormulaTest.java | 2 +- 63 files changed, 67 insertions(+), 56 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/model/typesystem/ReferenceTypeImpl.java (98%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java index 4baddae322..0aa1f9d904 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.model.typesystem; +package com.github.javaparser.resolution.model.typesystem; import java.util.Collections; import java.util.HashSet; @@ -38,7 +38,6 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 6ef3210843..e888df1447 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -37,12 +37,12 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 44610241f0..67b1932b45 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -40,6 +40,7 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; @@ -47,7 +48,6 @@ import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 8f01fd1501..065d951d59 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -39,12 +39,12 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 52ccfbc14b..dfe65bba8e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -30,10 +30,10 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 6d505b865e..81611de018 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -34,11 +34,11 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java index 0cdbb02790..f8235dca5b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java @@ -29,10 +29,10 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java index 79a413b8de..6be800d8ac 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java @@ -39,10 +39,10 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java index ceed1d3156..78eea753ed 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java @@ -44,6 +44,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -52,7 +53,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ObjectCreationContext; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 08d9f3841c..27f7bad902 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -47,6 +47,7 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.LazyType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -55,7 +56,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java index e9cd2eade8..5af559804b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 2a5ded7160..3264e5be19 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -53,6 +53,7 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.LazyType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -65,7 +66,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 71bcaf222e..2a86adf3ff 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -48,6 +48,7 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.LazyType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -57,7 +58,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index bed1f06188..2da02af43c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -33,11 +33,11 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 20b91110c8..3b017c8939 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -41,12 +41,12 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 57852c5be7..fc1c3f634c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -33,12 +33,12 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.ArrayList; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index 72f0765224..dbf33f8d5d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -32,8 +32,9 @@ import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; + import javassist.CtMethod; import javassist.bytecode.AnnotationDefaultAttribute; import javassist.bytecode.BadBytecode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index 925574b099..600586da42 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -29,13 +29,13 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java index 13292dd4e1..d1f35e1400 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java @@ -23,8 +23,9 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; + import javassist.CtField; import javassist.bytecode.AccessFlag; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java index 2dea433447..48c5f7cc7e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; -import com.github.javaparser.symbolsolver.model.typesystem.*; import javassist.CtClass; import javassist.NotFoundException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java index 083df39813..a3d82850dd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java @@ -26,8 +26,9 @@ import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; + import javassist.CtBehavior; import javassist.bytecode.BadBytecode; import javassist.bytecode.ExceptionsAttribute; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java index 7a4e904214..e1e78f714b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java @@ -29,9 +29,10 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; + import javassist.CtClass; import javassist.CtField; import javassist.NotFoundException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java index eaa130a28d..d0e74f415e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java @@ -31,8 +31,8 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import javassist.bytecode.SignatureAttribute; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index 6b4eb5ca24..2ed7efaaad 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -37,6 +37,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -46,7 +47,6 @@ import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import javassist.CtBehavior; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java index 1a5d47b4e9..63d757ced0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java @@ -23,9 +23,9 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.logic.ObjectProvider; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index e99d1270e5..e93c16d57f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -37,9 +37,9 @@ import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** * @author Malte Skoruppa diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index 1b59dc2721..6060ff6ab5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -31,9 +31,9 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 0c9be57512..abe93a5598 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -28,6 +28,7 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -35,7 +36,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.comparators.MethodComparator; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java index 8db8b9df89..496753f084 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java @@ -24,8 +24,8 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 28ec71dbce..94559910a2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -35,7 +36,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java index 2e9d999eff..757eb4271d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java @@ -33,6 +33,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -40,7 +41,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 52d3efe1da..1b4b45a09c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -30,6 +30,7 @@ import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; @@ -39,7 +40,6 @@ import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.lang.reflect.Field; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index 8d53ba44ef..57916e0c1a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -27,11 +27,11 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.core.resolution.Context; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import java.lang.reflect.Method; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java index 3e32c1644d..b9235df902 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java @@ -35,8 +35,8 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index 1d2c8f09b6..54298f3378 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -26,9 +26,9 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 2f44ed6a31..8273ddd0de 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -33,13 +33,13 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import java.util.List; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java index 4d68611382..e21cff5282 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java @@ -36,9 +36,9 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.CapturesBound; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.FalseBound; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SameAsBound; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index ace32423cd..90bbebc277 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -36,13 +36,13 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.utils.Pair; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java index 8b80206071..6bae43b746 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeInference.java @@ -37,9 +37,9 @@ import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound; import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.ThrowsBound; import com.github.javaparser.symbolsolver.resolution.typeinference.constraintformulas.ExpressionCompatibleWithType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java index e730c15b9b..dfb2717e03 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/TypeCompatibleWithType.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.constraintformulas; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java index e5810a61c0..0f6dc9b256 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/JavaParserAPIIntegrationTest.java @@ -28,8 +28,8 @@ import com.github.javaparser.ast.body.*; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java index fffbb1dd49..8d43a79f3e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java @@ -55,6 +55,7 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -62,7 +63,6 @@ import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java index e4b02ab898..17998f2b83 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java @@ -26,11 +26,11 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java index 9fd985f33f..100ea7febc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java @@ -23,8 +23,8 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index a7e7fff741..197fbc95cb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java index 0e4f4c4fda..00703a5770 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java index 612b6e7dcf..b9ad7c0ca9 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java @@ -28,6 +28,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.model.typesystem.LazyType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java index c56b001fa6..c8809eb43e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java @@ -24,6 +24,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java index 87de478c71..417ffd3e29 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java @@ -24,6 +24,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index f7af6ea0c1..d711ec32ca 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -58,6 +58,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration.Bound; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java index 6e333b5a60..4d58ff5da4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java index 60e5bcaa45..c26d69fb73 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java @@ -24,6 +24,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java index 7f84d6f2da..d9d6dfef91 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java index 0a8b81f252..f5ab7cf040 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java @@ -40,10 +40,10 @@ import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java index 13096ed200..fb2b2a7236 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java @@ -26,10 +26,10 @@ import com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java index 1f3d59b755..c2043a74b0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java index 91f40b1b72..0e9dac00c1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java @@ -35,13 +35,13 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.Log; import org.junit.jupiter.api.AfterEach; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java index 9c03a5bb0a..607f21f75d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java @@ -27,10 +27,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.type.VarType; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index fe9d394aa5..313aaa6d8a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -41,13 +41,13 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.NullType; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index 10a61a1d4d..aa8e4bc0c5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -46,13 +46,13 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ClassLoaderTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java index 297fdc5e40..b50a852c3c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.bounds; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.Bound; import com.github.javaparser.symbolsolver.resolution.typeinference.InferenceVariable; import com.github.javaparser.symbolsolver.resolution.typeinference.Instantiation; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java index ef17f57f6f..a2555141e6 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.*; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java index 508422b930..db1f263933 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java @@ -25,8 +25,8 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet; import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula; import com.github.javaparser.symbolsolver.resolution.typeinference.InferenceVariable; From 80a4008353616b9fc90a17df5166cda9ad4d4cf6 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 10:09:19 +0100 Subject: [PATCH 093/280] Refactoring convert to usage : Remove useless methods already implemented in interface --- .../resolution/model/LambdaArgumentTypePlaceholder.java | 5 ----- .../javaparser/resolution/model/typesystem/NullType.java | 5 ----- .../javaparser/resolution/types/ResolvedTypeVariable.java | 5 ----- 3 files changed, 15 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java index 554e4cb8d7..cd95ae8dc2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/LambdaArgumentTypePlaceholder.java @@ -44,11 +44,6 @@ public boolean isArray() { return false; } - @Override - public boolean isPrimitive() { - return false; - } - @Override public boolean isReferenceType() { return false; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java index 87536d8115..c30848948f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/NullType.java @@ -41,11 +41,6 @@ public boolean isArray() { return false; } - @Override - public boolean isPrimitive() { - return false; - } - public boolean isNull() { return true; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java index 6808effa47..762130ebba 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -74,11 +74,6 @@ public boolean isArray() { return false; } - @Override - public boolean isPrimitive() { - return false; - } - @Override public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map inferredTypes) { if (tpToBeReplaced.getName().equals(this.typeParameter.getName())) { From a556ce57fcbd6c3a46656031dda221f7cbd11789 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 13:56:57 +0100 Subject: [PATCH 094/280] Refactoring convert to usage : Internal refactoring of the class ResolvedPrimitiveType --- .../types/ResolvedPrimitiveType.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java index bfab10fc3d..66fd7d1add 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -29,27 +29,27 @@ */ public enum ResolvedPrimitiveType implements ResolvedType { - BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()), - SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)), - CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()), - INT("int", Integer.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, CHAR)), - LONG("long", Long.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, INT, CHAR)), - BOOLEAN("boolean", Boolean.class.getCanonicalName(), Collections.emptyList()), - FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), - DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); + BYTE("byte", Byte.class, Collections.emptyList()), + SHORT("short", Short.class, Collections.singletonList(BYTE)), + CHAR("char", Character.class, Collections.emptyList()), + INT("int", Integer.class, Arrays.asList(BYTE, SHORT, CHAR)), + LONG("long", Long.class, Arrays.asList(BYTE, SHORT, INT, CHAR)), + BOOLEAN("boolean", Boolean.class, Collections.emptyList()), + FLOAT("float", Float.class, Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)), + DOUBLE("double", Double.class, Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR)); // / // / Fields // / private String name; - private String boxTypeQName; + private Class boxTypeClass; private List promotionTypes; - ResolvedPrimitiveType(String name, String boxTypeQName, List promotionTypes) { + ResolvedPrimitiveType(String name, Class boxTypeClass, List promotionTypes) { this.name = name; - this.boxTypeQName = boxTypeQName; + this.boxTypeClass = boxTypeClass; this.promotionTypes = promotionTypes; } @@ -109,11 +109,11 @@ public boolean isAssignableBy(ResolvedType other) { if (other.isPrimitive()) { return this == other || promotionTypes.contains(other); } else if (other.isReferenceType()) { - if (other.asReferenceType().getQualifiedName().equals(boxTypeQName)) { + if (other.asReferenceType().getQualifiedName().equals(getBoxTypeQName())) { return true; } for (ResolvedPrimitiveType promotion : promotionTypes) { - if (other.asReferenceType().getQualifiedName().equals(promotion.boxTypeQName)) { + if (other.asReferenceType().getQualifiedName().equals(promotion.getBoxTypeQName())) { return true; } } @@ -124,7 +124,7 @@ public boolean isAssignableBy(ResolvedType other) { } public String getBoxTypeQName() { - return boxTypeQName; + return boxTypeClass.getCanonicalName(); } public boolean isNumeric() { From 4b464255672abdcdbd97b5d27b9b90ec9f902691 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 18:49:28 +0100 Subject: [PATCH 095/280] Refactoring convert to usage : removing adhesions with the symbol solver and improving unit tests on ResolvedPrimitiveType --- .../model/typesystem/ReferenceTypeImpl.java | 10 ++--- .../types/ResolvedPrimitiveType.java | 42 +++++++++++++++++-- .../model/typesystem/PrimitiveTypeTest.java | 12 ++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java index 0aa1f9d904..3de765cebc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java @@ -38,6 +38,7 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; @@ -101,13 +102,12 @@ public boolean isAssignableBy(ResolvedType other) { if (this.isJavaLangObject()) { return true; } + // Check if 'other' can be boxed to match this type if (isCorrespondingBoxingType(other.describe())) return true; - - // Resolve the boxed type and check if it can be assigned via widening reference conversion - SymbolReference type = typeSolver - .tryToSolveType(other.asPrimitive().getBoxTypeQName()); - return type.getCorrespondingDeclaration().canBeAssignedTo(super.typeDeclaration); + + // All numeric types extend Number + return other.isNumericType() && this.isReferenceType() && this.asReferenceType().getQualifiedName().equals(Number.class.getCanonicalName()); } if (other instanceof LambdaArgumentTypePlaceholder) { return FunctionalInterfaceLogic.isFunctionalInterfaceType(this); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java index 66fd7d1add..e588f1b198 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; /** * @author Federico Tomassetti @@ -62,12 +63,40 @@ public static ResolvedType byName(String name) { } throw new IllegalArgumentException("Name " + name); } - + + /* + * Returns true if the specified type is a boxed type of a primitive type. + */ + public static boolean isBoxType(ResolvedType type) { + if (!type.getClass().isInstance(ResolvedReferenceType.class)) { + return false; + } + String qName = type.asReferenceType().getQualifiedName(); + for (ResolvedPrimitiveType ptu : values()) { + if (ptu.getBoxTypeQName().equals(qName)) { + return true; + } + } + return false; + } + + /* + * Returns the primitive type corresponding to the specified boxed type canonical name. + */ + public static Optional byBoxTypeQName(String qName) { + for (ResolvedPrimitiveType ptu : values()) { + if (ptu.getBoxTypeQName().equals(qName)) { + return Optional.of(ptu); + } + } + return Optional.empty(); + } + /* * Returns an array containing all numeric types */ public static ResolvedPrimitiveType[] getNumericPrimitiveTypes() { - return new ResolvedPrimitiveType[] { BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE }; + return new ResolvedPrimitiveType[] { BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR }; } @Override @@ -126,9 +155,16 @@ public boolean isAssignableBy(ResolvedType other) { public String getBoxTypeQName() { return boxTypeClass.getCanonicalName(); } + + /* + * Returns the boxed class of the primitive type. + */ + public Class getBoxTypeClass() { + return boxTypeClass; + } public boolean isNumeric() { - return this != BOOLEAN; + return Arrays.asList(getNumericPrimitiveTypes()).contains(this); } /** diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java index 417ffd3e29..0bce6565aa 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java @@ -334,5 +334,17 @@ void testIsAssignableByAnythingElse() { assertEquals(false, ptu.isAssignableBy(arrayOfListOfA)); } } + + @Test + void testIsNumeric() { + assertFalse(ResolvedPrimitiveType.BOOLEAN.isNumeric()); + assertTrue(ResolvedPrimitiveType.CHAR.isNumeric()); + assertTrue(ResolvedPrimitiveType.BYTE.isNumeric()); + assertTrue(ResolvedPrimitiveType.SHORT.isNumeric()); + assertTrue(ResolvedPrimitiveType.INT.isNumeric()); + assertTrue(ResolvedPrimitiveType.LONG.isNumeric()); + assertTrue(ResolvedPrimitiveType.FLOAT.isNumeric()); + assertTrue(ResolvedPrimitiveType.DOUBLE.isNumeric()); + } } From bbad65b0f04cc7db43bebc80940f07c8b6371d26 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 30 Nov 2022 23:05:19 +0100 Subject: [PATCH 096/280] Refactoring convert to usage : removing the call to typeSolver to get the object declaration and improve unit tests --- .../ResolvedReferenceTypeDeclaration.java | 8 ++-- .../model/typesystem/ReferenceTypeImpl.java | 15 ++++---- .../model/typesystem/ReferenceTypeTest.java | 10 +---- .../ReflectionInterfaceDeclarationTest.java | 38 +++++++++++++++++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java index 5522c1a4f7..163a3aa353 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java @@ -136,7 +136,7 @@ default List getAllAncestors(Function> breadthFirstFunc = (rrtd) -> { - Set ancestors = new HashSet<>(); + List ancestors = new ArrayList<>(); // We want to avoid infinite recursion in case of Object having Object as ancestor if (!rrtd.isJavaLangObject()) { // init direct ancestors @@ -148,11 +148,13 @@ default List getAllAncestors(Function getDirectAncestors() { // Avoid repetitions of Object -- remove them all and, if appropriate, add it back precisely once. - ancestors.removeIf(ResolvedReferenceType::isJavaLangObject); +// ancestors.removeIf(ResolvedReferenceType::isJavaLangObject); // Conditionally re-insert java.lang.Object as an ancestor. if(this.getTypeDeclaration().isPresent()) { ResolvedReferenceTypeDeclaration thisTypeDeclaration = this.getTypeDeclaration().get(); + // The superclass of interfaces is always null if (thisTypeDeclaration.isClass()) { Optional optionalSuperClass = thisTypeDeclaration.asClass().getSuperClass(); boolean superClassIsJavaLangObject = optionalSuperClass.isPresent() && optionalSuperClass.get().isJavaLangObject(); boolean thisIsJavaLangObject = thisTypeDeclaration.asClass().isJavaLangObject(); if (superClassIsJavaLangObject && !thisIsJavaLangObject) { - ancestors.add(create(typeSolver.getSolvedJavaLangObject())); +// ancestors.add(create(typeSolver.getSolvedJavaLangObject())); + ancestors.add(optionalSuperClass.get()); } - } else { - // If this isn't a class (i.e. is enum or interface (or record?)), add java.lang.Object as a supertype - // TODO: Should we also add the implicit java.lang.Enum ancestor in the case of enums? - // TODO: getDirectAncestors() shouldn't be inserting implicit ancesters...? See also issue #2696 - ancestors.add(create(typeSolver.getSolvedJavaLangObject())); } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index d711ec32ca..ebac7c41b3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -742,23 +742,17 @@ void testDirectAncestorsOfInterface() { ResolvedReferenceType iterableOfString = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(Iterable.class, typeSolver), ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver); - assertEquals(1, iterableOfString.getDirectAncestors().size()); - ResolvedReferenceType ancestor = iterableOfString.getDirectAncestors().get(0); - assertEquals("java.lang.Object", ancestor.getQualifiedName()); - assertEquals(true, ancestor.getTypeParametersMap().isEmpty()); + assertEquals(0, iterableOfString.getDirectAncestors().size()); } @Test void testDirectAncestorsOfInterfaceExtendingInterface() { - assertEquals(2, collectionOfString.getDirectAncestors().size()); + assertEquals(1, collectionOfString.getDirectAncestors().size()); ResolvedReferenceType ancestor1 = collectionOfString.getDirectAncestors().get(0); assertEquals("java.lang.Iterable", ancestor1.getQualifiedName()); assertEquals(1, ancestor1.getTypeParametersMap().size()); assertEquals("T", ancestor1.getTypeParametersMap().get(0).a.getName()); assertEquals("java.lang.String", ancestor1.getTypeParametersMap().get(0).b.describe()); - ResolvedReferenceType ancestor2 = collectionOfString.getDirectAncestors().get(1); - assertEquals("java.lang.Object", ancestor2.getQualifiedName()); - assertEquals(true, ancestor2.getTypeParametersMap().isEmpty()); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java index fb2b2a7236..3a7350e3ae 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java @@ -34,6 +34,8 @@ import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Test; +import java.nio.Buffer; +import java.nio.CharBuffer; import java.util.*; import java.util.stream.Collectors; @@ -83,5 +85,41 @@ void testAllAncestors() { assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.lang.Iterable")); } + + @Test + void testAllAncestorsForAnInterfaceWithBreadthFirstFunc() { + TypeSolver typeResolver = new ReflectionTypeSolver(); + ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver); + List ancestors = list.getAllAncestors(ResolvedReferenceTypeDeclaration.breadthFirstFunc); + assertEquals(2, ancestors.size()); + + ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(list.getTypeParameters().get(0)); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), + ImmutableList.of(typeVariable), typeResolver), ancestors.get(0)); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), + ImmutableList.of(typeVariable), typeResolver), ancestors.get(1)); + } + + @Test + void testAllAncestorsForAClassWithBreadthFirstFunc() { + TypeSolver typeResolver = new ReflectionTypeSolver(); + ReflectionClassDeclaration obj = new ReflectionClassDeclaration(CharBuffer.class, typeResolver); + List ancestors = obj.getAllAncestors(ResolvedReferenceTypeDeclaration.breadthFirstFunc); + assertEquals(6, ancestors.size()); + + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Buffer.class, typeResolver), typeResolver), + ancestors.get(0)); + assertEquals( + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Appendable.class, typeResolver), typeResolver), + ancestors.get(2)); + assertEquals( + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(CharSequence.class, typeResolver), typeResolver), + ancestors.get(3)); + assertEquals( + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Readable.class, typeResolver), typeResolver), + ancestors.get(4)); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), + ancestors.get(5)); + } } From 9cc7ceb96fa93b380e6cef41dc199ba5f9ed7048 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 30 Nov 2022 19:48:20 +0000 Subject: [PATCH 097/280] chore(deps): update dependency biz.aqute.bnd:bnd-maven-plugin to v6.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b17657978c..b18d500643 100644 --- a/pom.xml +++ b/pom.xml @@ -299,7 +299,7 @@ biz.aQute.bnd bnd-maven-plugin - 6.3.1 + 6.4.0 org.apache.maven.plugins From 1f1af573a7c5f41d8fd20c7af94412b4d571879d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 1 Dec 2022 17:02:38 +0100 Subject: [PATCH 098/280] Refactoring convert to usage : removing the call to typeSolver to get the object declaration and fix issue on getAllAncestors methods and adapt unit tests --- .../model/typesystem/ReferenceTypeImpl.java | 28 +++++++++---------- .../types/ResolvedReferenceType.java | 11 +++++++- .../resolution/types/ResolvedUnionType.java | 7 ++++- .../ReflectionClassAdapter.java | 26 ++++++++--------- .../ReflectionMethodResolutionLogic.java | 6 ++-- .../JavaParserClassDeclarationTest.java | 20 +++++++++---- .../JavaParserEnumDeclarationTest.java | 12 ++++---- .../JavaParserInterfaceDeclarationTest.java | 8 +++--- .../JavassistClassDeclarationTest.java | 8 +++--- .../model/typesystem/ReferenceTypeTest.java | 3 +- .../ReflectionClassDeclarationTest.java | 5 ++++ .../ReflectionInterfaceDeclarationTest.java | 5 ++-- 12 files changed, 83 insertions(+), 56 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java index f6615f1905..eb944c0c19 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java @@ -21,6 +21,7 @@ package com.github.javaparser.resolution.model.typesystem; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -28,6 +29,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import java.util.stream.Collectors; import com.github.javaparser.resolution.MethodUsage; @@ -149,8 +151,8 @@ public boolean isAssignableBy(ResolvedType other) { return false; } if (other.isUnionType()) { - return other.asUnionType().getCommonAncestor() - .map(ancestor -> isAssignableBy(ancestor)).orElse(false); + Optional common = other.asUnionType().getCommonAncestor(); + return common.map(ancestor -> isAssignableBy(ancestor)).orElse(false); } return false; } @@ -203,23 +205,26 @@ public ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer) return result; } + /* + * Get all ancestors with the default traverser (depth first) + */ + @Override public List getAllAncestors() { + return getAllAncestors(ResolvedReferenceTypeDeclaration.depthFirstFunc); + } + + public List getAllAncestors(Function> traverser) { // We need to go through the inheritance line and propagate the type parameters - List ancestors = typeDeclaration.getAllAncestors(); + List ancestors = typeDeclaration.getAllAncestors(traverser); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); - // Avoid repetitions of Object - ancestors.removeIf(ResolvedReferenceType::isJavaLangObject); - ResolvedReferenceTypeDeclaration objectType = typeSolver.getSolvedJavaLangObject(); - ancestors.add(create(objectType)); - return ancestors; } - + public List getDirectAncestors() { // We need to go through the inheritance line and propagate the type parameters @@ -229,10 +234,6 @@ public List getDirectAncestors() { .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); - - // Avoid repetitions of Object -- remove them all and, if appropriate, add it back precisely once. -// ancestors.removeIf(ResolvedReferenceType::isJavaLangObject); - // Conditionally re-insert java.lang.Object as an ancestor. if(this.getTypeDeclaration().isPresent()) { ResolvedReferenceTypeDeclaration thisTypeDeclaration = this.getTypeDeclaration().get(); @@ -242,7 +243,6 @@ public List getDirectAncestors() { boolean superClassIsJavaLangObject = optionalSuperClass.isPresent() && optionalSuperClass.get().isJavaLangObject(); boolean thisIsJavaLangObject = thisTypeDeclaration.asClass().isJavaLangObject(); if (superClassIsJavaLangObject && !thisIsJavaLangObject) { -// ancestors.add(create(typeSolver.getSolvedJavaLangObject())); ancestors.add(optionalSuperClass.get()); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java index ffc8d61792..bc0d8bd31e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -33,6 +33,7 @@ import com.github.javaparser.utils.Pair; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -200,6 +201,7 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe * Return all ancestors, that means all superclasses and interfaces. * This list should always include Object (unless this is a reference to Object). * The type typeParametersValues should be expressed in terms of this type typeParametersValues. + * The default order of presenting ancestors corresponds to a search in depth. *

* For example, given: *

@@ -210,7 +212,14 @@ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToRe * Foo<Boolean, String>. */ public abstract List getAllAncestors(); - + + /** + * Return all ancestors, that means all superclasses and interfaces. + * This list should always include Object (unless this is a reference to Object). + * The type typeParametersValues should be expressed in terms of this type typeParametersValues. + */ + public abstract List getAllAncestors(Function> traverser); + /** * Return direct ancestors, that means the superclasses and interfaces implemented directly. * This list should include Object if the class has no other superclass or the interface is not extending another interface. diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java index 304c895612..50546f07ba 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java @@ -23,6 +23,8 @@ import java.util.*; import java.util.stream.Collectors; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; + /** * A union type is defined in java as list of types separates by pipes. * @@ -40,7 +42,10 @@ public ResolvedUnionType(List elements) { } public Optional getCommonAncestor() { - Optional> reduce = elements.stream().map(ResolvedType::asReferenceType).map(ResolvedReferenceType::getAllAncestors).reduce((a, b) -> { + Optional> reduce = elements.stream() + .map(ResolvedType::asReferenceType) + .map(rt -> rt. getAllAncestors(ResolvedReferenceTypeDeclaration.breadthFirstFunc)) + .reduce((a, b) -> { ArrayList common = new ArrayList<>(a); common.retainAll(b); return common; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index 6060ff6ab5..d9bc42d103 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -96,22 +96,18 @@ public List getInterfaces() { public List getAncestors() { List ancestors = new LinkedList<>(); - if (getSuperClass().isPresent()) { - ReferenceTypeImpl superClass = getSuperClass().get(); - ancestors.add(superClass); - } else { - // Inject the implicitly added extends java.lang.Object - ReferenceTypeImpl object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - ancestors.add(object); - } + if (typeDeclaration.isClass() && !Object.class.getCanonicalName().equals(clazz.getCanonicalName())) { + if (getSuperClass().isPresent()) { + ReferenceTypeImpl superClass = getSuperClass().get(); + ancestors.add(superClass); + } else { + // Inject the implicitly added extends java.lang.Object + ReferenceTypeImpl object = new ReferenceTypeImpl( + new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + ancestors.add(object); + } + } ancestors.addAll(getInterfaces()); - for (int i = 0; i < ancestors.size(); i++) { - ResolvedReferenceType ancestor = ancestors.get(i); - if (ancestor.hasName() && ancestor.isJavaLangObject()) { - ancestors.remove(i); - i--; - } - } return ancestors; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index 57916e0c1a..d259a8eb66 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -102,7 +102,9 @@ static Optional solveMethodAsUsage(String name, List } - for(ResolvedReferenceType ancestor : scopeType.getAncestors()){ + List ancestors = scopeType.getAncestors(); + + for(ResolvedReferenceType ancestor : ancestors){ if(ancestor.getTypeDeclaration().isPresent()) { ResolvedReferenceTypeDeclaration ancestorTypeDeclaration = ancestor.getTypeDeclaration().get(); SymbolReference ref = MethodResolutionLogic.solveMethodInType(ancestorTypeDeclaration, name, argumentsTypes); @@ -114,7 +116,7 @@ static Optional solveMethodAsUsage(String name, List } } - if (scopeType.getAncestors().isEmpty()) { + if (ancestors.isEmpty()) { Optional optionalObjectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver).getTypeDeclaration(); if (optionalObjectClass.isPresent()) { SymbolReference ref = MethodResolutionLogic.solveMethodInType(optionalObjectClass.get(), name, argumentsTypes); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java index 8d43a79f3e..8b5972e87d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java @@ -377,13 +377,23 @@ void testGetAllAncestorsWithoutTypeParameters() { assertEquals(ImmutableSet.of("java.lang.Cloneable", "com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllAncestors().stream().map(i -> i.getQualifiedName()).collect(Collectors.toSet())); } + @Test + void testGetAllAncestorsWithDepthFirstTraversalOrder() { + ResolvedReferenceTypeDeclaration integer = typeSolver.solveType(Integer.class.getCanonicalName()); + List ancestors = integer.getAllAncestors(); + assertEquals("java.lang.Number", ancestors.get(0).getQualifiedName()); + assertEquals("java.lang.Object", ancestors.get(1).getQualifiedName()); + assertEquals("java.io.Serializable", ancestors.get(2).getQualifiedName()); + assertEquals("java.lang.Comparable", ancestors.get(3).getQualifiedName()); + } + @Test void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); List ancestors = constructorDeclaration.getAllAncestors(); assertEquals(12, ancestors.size()); - + ResolvedReferenceType ancestor; ancestor = ancestors.get(0); @@ -394,15 +404,15 @@ void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName()); ancestor = ancestors.get(2); + assertEquals("java.lang.Object", ancestor.getQualifiedName()); + + ancestor = ancestors.get(3); assertEquals("java.lang.Cloneable", ancestor.getQualifiedName()); - ancestor = ancestors.get(3); + ancestor = ancestors.get(4); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName()); - ancestor = ancestors.get(4); - assertEquals("java.lang.Object", ancestor.getQualifiedName()); - ancestor = ancestors.get(5); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java index 33693e2cdf..c3bccd38c4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java @@ -374,7 +374,7 @@ void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { List ancestors = constructorDeclaration.getAllAncestors(); assertEquals(12, ancestors.size()); - + ResolvedReferenceType ancestor; ancestor = ancestors.get(0); @@ -384,16 +384,16 @@ void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { ancestor = ancestors.get(1); assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName()); - ancestor = ancestors.get(2); + ancestor = constructorDeclaration.getAllAncestors().get(2); + assertEquals("java.lang.Object", ancestor.getQualifiedName()); + + ancestor = ancestors.get(3); assertEquals("java.lang.Cloneable", ancestor.getQualifiedName()); - ancestor = ancestors.get(3); + ancestor = ancestors.get(4); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName()); - ancestor = constructorDeclaration.getAllAncestors().get(4); - assertEquals("java.lang.Object", ancestor.getQualifiedName()); - ancestor = ancestors.get(5); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java index 8888096842..e746acdc32 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclarationTest.java @@ -380,15 +380,15 @@ void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName()); ancestor = ancestors.get(2); + assertEquals("java.lang.Object", ancestor.getQualifiedName()); + + ancestor = ancestors.get(3); assertEquals("java.lang.Cloneable", ancestor.getQualifiedName()); - ancestor = ancestors.get(3); + ancestor = ancestors.get(4); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName()); - ancestor = ancestors.get(4); - assertEquals("java.lang.Object", ancestor.getQualifiedName()); - ancestor = ancestors.get(5); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java index 63290380bc..ca81511956 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclarationTest.java @@ -481,15 +481,15 @@ void testGetAllAncestorsWithTypeParametersWithDepthFirstTraversalOrder() { assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName()); ancestor = ancestors.get(2); + assertEquals("java.lang.Object", ancestor.getQualifiedName()); + + ancestor = ancestors.get(3); assertEquals("java.lang.Cloneable", ancestor.getQualifiedName()); - ancestor = ancestors.get(3); + ancestor = ancestors.get(4); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName()); - ancestor = ancestors.get(4); - assertEquals("java.lang.Object", ancestor.getQualifiedName()); - ancestor = ancestors.get(5); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index ebac7c41b3..bdb1b18803 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -625,10 +625,9 @@ void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForInterface() { Map ancestors = new HashMap<>(); listOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); - assertEquals(3, ancestors.size()); + assertEquals(2, ancestors.size()); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable")); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java index f5ab7cf040..eb27e535e0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java @@ -304,10 +304,15 @@ void testGetAllMethods() { "com.github.javaparser.symbolsolver.reflectionmodel.ReflectionTestObject.getA()" ); + // Returns a list of all declared methods of this type declaration, whether declared or inherited. + // Note that it must not include overloaded methods. + // Since the ReflectionTestObject class implicitly inherits from the Object class, + // the list of methods also contains the methods of the Object class that we filter for more readability. Set actual = testObject.getAllMethods() .stream() .map(MethodUsage::getQualifiedSignature) .filter(s -> !"com.github.javaparser.symbolsolver.reflectionmodel.ReflectionTestObject.$jacocoInit()".equals(s)) // Ignore the methods injected via reflection by jacoco -- see also #1701 and #2637 + .filter(s -> !s.startsWith("java.lang.Object")) .collect(Collectors.toSet()); assertEquals(expected, actual); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java index 3a7350e3ae..cdfe1e37b3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java @@ -30,6 +30,7 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; +import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Test; @@ -78,11 +79,11 @@ void testAllAncestors() { ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver); Map ancestors = new HashMap<>(); list.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); - assertEquals(3, ancestors.size()); + assertEquals(2, ancestors.size()); + // Since List is an interface, Object cannot be an ancestor of List ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(list.getTypeParameters().get(0)); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.lang.Iterable")); } From b8159e1bc267f375b3b408aa4b1eb2590c48d94c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Dec 2022 10:30:39 +0100 Subject: [PATCH 099/280] Fix: registering a mapping between a formal parameter and an actual parameter must take into account that an interface does not extend the class Object --- .../javaparser/symbolsolver/logic/InferenceContext.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java index 9f9034827b..ae66f16e77 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java @@ -80,7 +80,11 @@ private void registerCorrespondance(ResolvedType formalType, ResolvedType actual if (!formalTypeAsReference.getQualifiedName().equals(actualTypeAsReference.getQualifiedName())) { List ancestors = actualTypeAsReference.getAllAncestors(); final String formalParamTypeQName = formalTypeAsReference.getQualifiedName(); - List correspondingFormalType = ancestors.stream().filter((a) -> a.getQualifiedName().equals(formalParamTypeQName)).collect(Collectors.toList()); + // Interfaces do not extend the class Object, + // which means that if the formal parameter is of type Object, all types can match. + List correspondingFormalType = "java.lang.Object".equals(formalParamTypeQName) ? + ancestors.stream().map(ancestor -> ancestor.asReferenceType()).collect(Collectors.toList()) : + ancestors.stream().filter((a) -> a.getQualifiedName().equals(formalParamTypeQName)).collect(Collectors.toList()); if (correspondingFormalType.isEmpty()) { ancestors = formalTypeAsReference.getAllAncestors(); final String actualParamTypeQname = actualTypeAsReference.getQualifiedName(); From 59aa06f7a22abaecd35833c7818382b21dc159ff Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Dec 2022 10:31:49 +0100 Subject: [PATCH 100/280] Refactoring convert to usage : removing the typeSolver reference into ReferenceTypeImpl --- .../model/typesystem/ReferenceTypeImpl.java | 25 +- .../javaparsermodel/JavaParserFacade.java | 12 +- .../javaparsermodel/TypeExtractor.java | 21 +- .../contexts/LambdaExprContext.java | 2 +- .../contexts/MethodCallExprContext.java | 4 +- .../contexts/MethodReferenceExprContext.java | 2 +- .../JavaParserAnnotationDeclaration.java | 2 +- .../JavaParserAnonymousClassDeclaration.java | 4 +- .../JavaParserClassDeclaration.java | 6 +- .../JavaParserEnumConstantDeclaration.java | 2 +- .../JavaParserEnumDeclaration.java | 12 +- .../JavaParserInterfaceDeclaration.java | 6 +- .../declarations/JavaParserTypeAdapter.java | 2 +- .../declarations/JavaParserTypeParameter.java | 4 +- .../JavaParserTypeVariableDeclaration.java | 2 +- .../JavassistAnnotationMemberDeclaration.java | 2 +- .../JavassistClassDeclaration.java | 6 +- .../JavassistEnumConstantDeclaration.java | 3 +- .../javassistmodel/JavassistFactory.java | 9 +- ...JavassistMethodLikeDeclarationAdapter.java | 2 +- .../JavassistTypeDeclarationAdapter.java | 9 +- .../JavassistTypeParameter.java | 2 +- .../javassistmodel/JavassistUtils.java | 5 +- .../reflectionmodel/MyObjectProvider.java | 4 +- ...ReflectionAnnotationMemberDeclaration.java | 2 +- .../ReflectionClassAdapter.java | 10 +- .../ReflectionClassDeclaration.java | 6 +- .../ReflectionEnumConstantDeclaration.java | 2 +- .../ReflectionEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionFactory.java | 2 +- .../ReflectionInterfaceDeclaration.java | 6 +- .../ReflectionMethodResolutionLogic.java | 6 +- .../ReflectionTypeParameter.java | 2 +- .../resolution/MethodResolutionLogic.java | 8 +- .../symbolsolver/resolution/SymbolSolver.java | 2 +- .../resolution/typeinference/BoundSet.java | 2 +- .../resolution/typeinference/TypeHelper.java | 6 +- .../typeinference/TypeInference.java | 2 +- .../TypeCompatibleWithType.java | 4 +- .../JavaParserAPIIntegrationTest.java | 6 +- .../JavaParserClassDeclarationTest.java | 10 +- .../JavassistInterfaceDeclarationTest.java | 6 +- .../logic/FunctionInterfaceLogicTest.java | 8 +- .../logic/InferenceContextTest.java | 6 +- .../model/typesystem/ArrayTypeTest.java | 12 +- .../model/typesystem/LazyTypeTest.java | 6 +- .../model/typesystem/NullTypeTest.java | 6 +- .../model/typesystem/PrimitiveTypeTest.java | 24 +- .../model/typesystem/ReferenceTypeTest.java | 224 +++++++++--------- .../typesystem/TypeVariableUsageTest.java | 2 +- .../model/typesystem/VoidTypeTest.java | 6 +- .../model/typesystem/WildcardUsageTest.java | 8 +- .../ReflectionClassDeclarationTest.java | 18 +- .../ReflectionInterfaceDeclarationTest.java | 18 +- .../resolution/ExprResolutionTest.java | 2 +- .../resolution/javaparser/VarTypeTest.java | 2 +- ...rfaceDeclarationContextResolutionTest.java | 4 +- .../MethodCallExprContextResolutionTest.java | 2 +- .../typeinference/bounds/SameAsBoundTest.java | 2 +- .../bounds/SubtypeOfBoundTest.java | 14 +- .../ConstraintFormulaTest.java | 2 +- 61 files changed, 289 insertions(+), 309 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java index eb944c0c19..1a6f31264b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/model/typesystem/ReferenceTypeImpl.java @@ -21,8 +21,6 @@ package com.github.javaparser.resolution.model.typesystem; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; @@ -34,15 +32,12 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; -import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeTransformer; @@ -52,36 +47,30 @@ /** * @author Federico Tomassetti */ -// TODO Remove references to typeSolver: it is needed to instantiate other instances of ReferenceTypeUsage -// and to get the Object type declaration public class ReferenceTypeImpl extends ResolvedReferenceType { - private TypeSolver typeSolver; - - public static ResolvedReferenceType undeterminedParameters(ResolvedReferenceTypeDeclaration typeDeclaration, TypeSolver typeSolver) { + public static ResolvedReferenceType undeterminedParameters(ResolvedReferenceTypeDeclaration typeDeclaration) { return new ReferenceTypeImpl(typeDeclaration, typeDeclaration.getTypeParameters().stream().map( ResolvedTypeVariable::new - ).collect(Collectors.toList()), typeSolver); + ).collect(Collectors.toList())); } @Override protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParametersCorrected) { - return new ReferenceTypeImpl(typeDeclaration, typeParametersCorrected, typeSolver); + return new ReferenceTypeImpl(typeDeclaration, typeParametersCorrected); } @Override protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration) { - return new ReferenceTypeImpl(typeDeclaration, typeSolver); + return new ReferenceTypeImpl(typeDeclaration); } - public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, TypeSolver typeSolver) { + public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration) { super(typeDeclaration); - this.typeSolver = typeSolver; } - public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, List typeArguments, TypeSolver typeSolver) { + public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, List typeArguments) { super(typeDeclaration, typeArguments); - this.typeSolver = typeSolver; } @Override @@ -177,7 +166,7 @@ public ResolvedType toRawType() { if (this.isRawType()) { return this; } - return new ReferenceTypeImpl(typeDeclaration, Collections.emptyList(), typeSolver); + return new ReferenceTypeImpl(typeDeclaration, Collections.emptyList()); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index e888df1447..d4fc6109d4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -355,7 +355,7 @@ public ResolvedType getType(Node node) { .solveType(nameExpr.getNameAsString()); if (typeDeclaration.isSolved() && typeDeclaration.getCorrespondingDeclaration() instanceof ResolvedReferenceTypeDeclaration) { ResolvedReferenceTypeDeclaration resolvedReferenceTypeDeclaration = (ResolvedReferenceTypeDeclaration) typeDeclaration.getCorrespondingDeclaration(); - return ReferenceTypeImpl.undeterminedParameters(resolvedReferenceTypeDeclaration, typeSolver); + return ReferenceTypeImpl.undeterminedParameters(resolvedReferenceTypeDeclaration); } } throw failureHandler.handle(e); @@ -694,7 +694,7 @@ protected ResolvedType convertClassOrInterfaceTypeToUsage(ClassOrInterfaceType c if (typeDeclaration.isTypeParameter()) { return new ResolvedTypeVariable(typeDeclaration.asTypeParameter()); } else { - return new ReferenceTypeImpl((ResolvedReferenceTypeDeclaration) typeDeclaration, typeParameters, typeSolver); + return new ReferenceTypeImpl((ResolvedReferenceTypeDeclaration) typeDeclaration, typeParameters); } } @@ -852,15 +852,15 @@ public ResolvedReferenceTypeDeclaration getTypeDeclaration(ClassOrInterfaceDecla public ResolvedType getTypeOfThisIn(Node node) { // TODO consider static methods if (node instanceof ClassOrInterfaceDeclaration) { - return new ReferenceTypeImpl(getTypeDeclaration((ClassOrInterfaceDeclaration) node), typeSolver); + return new ReferenceTypeImpl(getTypeDeclaration((ClassOrInterfaceDeclaration) node)); } if (node instanceof EnumDeclaration) { JavaParserEnumDeclaration enumDeclaration = new JavaParserEnumDeclaration((EnumDeclaration) node, typeSolver); - return new ReferenceTypeImpl(enumDeclaration, typeSolver); + return new ReferenceTypeImpl(enumDeclaration); } if (node instanceof ObjectCreationExpr && ((ObjectCreationExpr) node).getAnonymousClassBody().isPresent()) { JavaParserAnonymousClassDeclaration anonymousDeclaration = new JavaParserAnonymousClassDeclaration((ObjectCreationExpr) node, typeSolver); - return new ReferenceTypeImpl(anonymousDeclaration, typeSolver); + return new ReferenceTypeImpl(anonymousDeclaration); } return getTypeOfThisIn(demandParentNode(node)); } @@ -891,7 +891,7 @@ public ResolvedType classToResolvedType(Class clazz) { } else { declaration = new ReflectionClassDeclaration(clazz, typeSolver); } - return new ReferenceTypeImpl(declaration, typeSolver); + return new ReferenceTypeImpl(declaration); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 67b1932b45..bd935219d7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -77,7 +77,7 @@ public TypeExtractor(TypeSolver typeSolver, JavaParserFacade facade) { this.typeSolver = typeSolver; this.facade = facade; //pre-calculate the String reference (optimization) - stringReferenceType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(JAVA_LANG_STRING), typeSolver); + stringReferenceType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(JAVA_LANG_STRING)); } @Override @@ -169,7 +169,7 @@ public ResolvedType visit(ClassExpr node, Boolean solveLambdas) { // This implementation does not regard the actual type argument of the ClassExpr. Type astType = node.getType(); ResolvedType jssType = facade.convertToUsage(astType, node.getType()); - return new ReferenceTypeImpl(new ReflectionClassDeclaration(Class.class, typeSolver), ImmutableList.of(jssType), typeSolver); + return new ReferenceTypeImpl(new ReflectionClassDeclaration(Class.class, typeSolver), ImmutableList.of(jssType)); } /* @@ -221,7 +221,7 @@ private ResolvedType solveDotExpressionType(ResolvedReferenceTypeDeclaration par } else if (parentType.hasField(node.getName().getId())) { return parentType.getField(node.getName().getId()).getType(); } else if (parentType.hasInternalType(node.getName().getId())) { - return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId()), typeSolver); + return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId())); } else { throw new UnsolvedSymbolException(node.getName().getId()); } @@ -266,7 +266,7 @@ public ResolvedType visit(FieldAccessExpr node, Boolean solveLambdas) { // We should solve for the type declaration inside this package. SymbolReference sref = typeSolver.tryToSolveType(node.toString()); if (sref.isSolved()) { - return new ReferenceTypeImpl(sref.getCorrespondingDeclaration(), typeSolver); + return new ReferenceTypeImpl(sref.getCorrespondingDeclaration()); } } if (value.isPresent()) { @@ -355,7 +355,7 @@ public ResolvedType visit(TypeExpr node, Boolean solveLambdas) { .getContext(classOrInterfaceType, typeSolver) .solveType(nameWithScope); if (typeDeclarationSymbolReference.isSolved()) { - return new ReferenceTypeImpl(typeDeclarationSymbolReference.getCorrespondingDeclaration().asReferenceType(), typeSolver); + return new ReferenceTypeImpl(typeDeclarationSymbolReference.getCorrespondingDeclaration().asReferenceType()); } // JLS 15.13 - ExpressionName :: [TypeArguments] Identifier @@ -382,18 +382,17 @@ public ResolvedType visit(ThisExpr node, Boolean solveLambdas) { // first try a buttom/up approach try { return new ReferenceTypeImpl( - facade.getTypeDeclaration(facade.findContainingTypeDeclOrObjectCreationExpr(node, className)), - typeSolver); + facade.getTypeDeclaration(facade.findContainingTypeDeclOrObjectCreationExpr(node, className))); } catch (IllegalStateException e) { // trying another approach from type solver Optional cu = node.findAncestor(CompilationUnit.class); SymbolReference clazz = typeSolver.tryToSolveType(className); if (clazz.isSolved()) { - return new ReferenceTypeImpl(clazz.getCorrespondingDeclaration(), typeSolver); + return new ReferenceTypeImpl(clazz.getCorrespondingDeclaration()); } } } - return new ReferenceTypeImpl(facade.getTypeDeclaration(facade.findContainingTypeDeclOrObjectCreationExpr(node)), typeSolver); + return new ReferenceTypeImpl(facade.getTypeDeclaration(facade.findContainingTypeDeclOrObjectCreationExpr(node))); } @Override @@ -406,7 +405,7 @@ public ResolvedType visit(SuperExpr node, Boolean solveLambdas) { // Cfr JLS $15.12.1 ResolvedTypeDeclaration resolvedTypeName = resolvedTypeNameRef.getCorrespondingDeclaration(); if (resolvedTypeName.isInterface()) { - return new ReferenceTypeImpl(resolvedTypeName.asInterface(), typeSolver); + return new ReferenceTypeImpl(resolvedTypeName.asInterface()); } else if (resolvedTypeName.isClass()) { // TODO: Maybe include a presence check? e.g. in the case of `java.lang.Object` there will be no superclass. return resolvedTypeName.asClass().getSuperClass().orElseThrow(() -> new RuntimeException("super class unexpectedly empty")); @@ -538,7 +537,7 @@ private ResolvedType resolveLambda(LambdaExpr node, ResolvedType result) { // At this point parameterType // if Function // we should replace Stream.T - ResolvedType functionalInterfaceType = ReferenceTypeImpl.undeterminedParameters(functionalMethod.get().getDeclaration().declaringType(), typeSolver); + ResolvedType functionalInterfaceType = ReferenceTypeImpl.undeterminedParameters(functionalMethod.get().getDeclaration().declaringType()); lambdaCtx.addPair(result, functionalInterfaceType); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 065d951d59..0b329f0090 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -91,7 +91,7 @@ public Optional solveSymbolAsValue(String name) { lambdaType.asReferenceType().getTypeDeclaration().ifPresent(typeDeclaration -> { inferenceContext.addPair( lambdaType, - new ReferenceTypeImpl(typeDeclaration, typeSolver) + new ReferenceTypeImpl(typeDeclaration) ); }); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index dfe65bba8e..4d3887d23c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -458,14 +458,14 @@ private Optional solveMethodAsUsage(ResolvedType type, String name, } else if (wildcardUsage.isExtends()) { return solveMethodAsUsage(wildcardUsage.getBoundedType(), name, argumentsTypes, invokationContext); } else { - return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver), name, argumentsTypes, invokationContext); + return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)), name, argumentsTypes, invokationContext); } } else if (type instanceof ResolvedLambdaConstraintType){ ResolvedLambdaConstraintType constraintType = (ResolvedLambdaConstraintType) type; return solveMethodAsUsage(constraintType.getBound(), name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedArrayType) { // An array inherits methods from Object not from it's component type - return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver), name, argumentsTypes, invokationContext); + return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)), name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedUnionType) { Optional commonAncestor = type.asUnionType().getCommonAncestor(); if (commonAncestor.isPresent()) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 81611de018..86f738c08e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -118,7 +118,7 @@ private List inferArgumentTypes() { // Resolve each type variable of the lambda, and use this later to infer the type of each // implicit parameter - inferenceContext.addPair(new ReferenceTypeImpl(functionalMethod.declaringType(), typeSolver), lambdaType); + inferenceContext.addPair(new ReferenceTypeImpl(functionalMethod.declaringType()), lambdaType); // Now resolve the argument type using the inference context ResolvedType argType = inferenceContext.resolve(inferenceContext.addSingle(type)); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java index 6be800d8ac..63b4badf57 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationDeclaration.java @@ -62,7 +62,7 @@ public JavaParserAnnotationDeclaration(AnnotationDeclaration wrappedNode, TypeSo @Override public List getAncestors(boolean acceptIncompleteList) { List ancestors = new ArrayList<>(); - ancestors.add(new ReferenceTypeImpl(typeSolver.solveType("java.lang.annotation.Annotation"), typeSolver)); + ancestors.add(new ReferenceTypeImpl(typeSolver.solveType("java.lang.annotation.Annotation"))); return ancestors; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java index 78eea753ed..2aa36597ce 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java @@ -118,7 +118,7 @@ public Optional solveMethodAsUsage(String name, List @Override protected ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } @Override @@ -127,7 +127,7 @@ public Optional getSuperClass() { if (superRRTD == null) { return Optional.empty(); } - return Optional.of(new ReferenceTypeImpl(superRRTD, typeSolver)); + return Optional.of(new ReferenceTypeImpl(superRRTD)); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index 27f7bad902..c3b1546a16 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -446,7 +446,7 @@ public Optional toAst() { @Override protected ResolvedReferenceType object() { ResolvedReferenceTypeDeclaration solvedJavaLangObject = typeSolver.getSolvedJavaLangObject(); - return new ReferenceTypeImpl(solvedJavaLangObject, typeSolver); + return new ReferenceTypeImpl(solvedJavaLangObject); } @Override @@ -486,7 +486,7 @@ private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterf } if (!classOrInterfaceType.getTypeArguments().isPresent()) { - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType()); } List superClassTypeParameters = classOrInterfaceType.getTypeArguments().get() @@ -494,6 +494,6 @@ private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterf .map(ta -> new LazyType(v -> JavaParserFacade.get(typeSolver).convert(ta, ta))) .collect(Collectors.toList()); - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters, typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java index 5af559804b..a35c3484c5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java @@ -44,7 +44,7 @@ public JavaParserEnumConstantDeclaration(com.github.javaparser.ast.body.EnumCons @Override public ResolvedType getType() { - return new ReferenceTypeImpl(new JavaParserEnumDeclaration((EnumDeclaration) demandParentNode(wrappedNode), typeSolver), typeSolver); + return new ReferenceTypeImpl(new JavaParserEnumDeclaration((EnumDeclaration) demandParentNode(wrappedNode), typeSolver)); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 3264e5be19..92cdb4a610 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -266,7 +266,7 @@ public List getAncestors(boolean acceptIncompleteList) { .getTypeParameters() .get(0); enumClass = enumClass.deriveTypeParameters(new ResolvedTypeParametersMap.Builder() - .setValue(eTypeParameter, new ReferenceTypeImpl(this, typeSolver)) + .setValue(eTypeParameter, new ReferenceTypeImpl(this)) .build()); ancestors.add(enumClass); } else { @@ -300,12 +300,12 @@ private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterf throw new UnsolvedSymbolException(classOrInterfaceType.getName().getId()); } if (!classOrInterfaceType.getTypeArguments().isPresent()) { - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType()); } List superClassTypeParameters = classOrInterfaceType.getTypeArguments().get() .stream().map(ta -> new LazyType(v -> JavaParserFacade.get(typeSolver).convert(ta, ta))) .collect(Collectors.toList()); - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters, typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters); } /** @@ -380,7 +380,7 @@ public ResolvedReferenceTypeDeclaration declaringType() { @Override public ResolvedType getReturnType() { - return new ResolvedArrayType(new ReferenceTypeImpl(enumDeclaration, typeSolver)); + return new ResolvedArrayType(new ReferenceTypeImpl(enumDeclaration)); } @Override @@ -474,7 +474,7 @@ public ResolvedReferenceTypeDeclaration declaringType() { @Override public ResolvedType getReturnType() { - return new ReferenceTypeImpl(enumDeclaration, typeSolver); + return new ReferenceTypeImpl(enumDeclaration); } @Override @@ -493,7 +493,7 @@ public String getName() { @Override public ResolvedType getType() { - return new ReferenceTypeImpl(typeSolver.solveType("java.lang.String"), typeSolver); + return new ReferenceTypeImpl(typeSolver.solveType("java.lang.String")); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 2a86adf3ff..0ef9eeb0c1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -141,7 +141,7 @@ public List getInterfacesExtended() { List interfaces = new ArrayList<>(); for (ClassOrInterfaceType t : wrappedNode.getExtendedTypes()) { interfaces.add(new ReferenceTypeImpl( - solveType(t.getName().getId()).getCorrespondingDeclaration().asInterface(), typeSolver)); + solveType(t.getName().getId()).getCorrespondingDeclaration().asInterface())); } return interfaces; } @@ -408,11 +408,11 @@ private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterf throw new UnsolvedSymbolException(classOrInterfaceType.getName().getId()); } if (!classOrInterfaceType.getTypeArguments().isPresent()) { - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType()); } List superClassTypeParameters = classOrInterfaceType.getTypeArguments().get() .stream().map(ta -> new LazyType(v -> JavaParserFacade.get(typeSolver).convert(ta, ta))) .collect(Collectors.toList()); - return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters, typeSolver); + return new ReferenceTypeImpl(ref.getCorrespondingDeclaration().asReferenceType(), superClassTypeParameters); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index 2da02af43c..66d55cedfd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -74,7 +74,7 @@ public String getQualifiedName() { public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { List ancestorsOfOther = other.getAllAncestors(); - ancestorsOfOther.add(new ReferenceTypeImpl(other, typeSolver)); + ancestorsOfOther.add(new ReferenceTypeImpl(other)); for (ResolvedReferenceType ancestorOfOther : ancestorsOfOther) { if (ancestorOfOther.getQualifiedName().equals(this.getQualifiedName())) { return true; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 3b017c8939..02ea4fb2c9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -96,7 +96,7 @@ public String getName() { @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override @@ -243,6 +243,6 @@ public List getConstructors() { @Override public ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index fc1c3f634c..5e5dc3726c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -61,7 +61,7 @@ public JavaParserTypeVariableDeclaration(TypeParameter wrappedNode, TypeSolver t @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index dbf33f8d5d..e3b5dc31e2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -91,7 +91,7 @@ public ResolvedType getType() { SignatureAttribute.MethodSignature signature = SignatureAttribute.toMethodSignature(descriptor); SymbolReference returnType = typeSolver.tryToSolveType(signature.getReturnType().jvmTypeName()); if (returnType.isSolved()) { - return new ReferenceTypeImpl(returnType.getCorrespondingDeclaration(), typeSolver); + return new ReferenceTypeImpl(returnType.getCorrespondingDeclaration()); } } catch (BadBytecode e) { // We don't expect this to happen, but we handle it anyway. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index 600586da42..dd3660511a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -68,7 +68,7 @@ public JavassistClassDeclaration(CtClass ctClass, TypeSolver typeSolver) { @Override protected ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } @Override @@ -83,7 +83,7 @@ public Set getDeclaredMethods() { @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override @@ -180,7 +180,7 @@ public SymbolReference solveMethod(String name, List< } public ResolvedType getUsage(Node node) { - return new ReferenceTypeImpl(this, typeSolver); + return new ReferenceTypeImpl(this); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java index d1f35e1400..56b3a952bd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java @@ -60,8 +60,7 @@ public String getName() { @Override public ResolvedType getType() { if (type == null) { - type = new ReferenceTypeImpl(new JavassistEnumDeclaration(ctField.getDeclaringClass(), typeSolver), - typeSolver); + type = new ReferenceTypeImpl(new JavassistEnumDeclaration(ctField.getDeclaringClass(), typeSolver)); } return type; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java index 48c5f7cc7e..630b32ad1d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFactory.java @@ -48,14 +48,11 @@ public static ResolvedType typeUsageFor(CtClass ctClazz, TypeSolver typeSolver) } } else { if (ctClazz.isInterface()) { - return new ReferenceTypeImpl(new JavassistInterfaceDeclaration(ctClazz, typeSolver), - typeSolver); + return new ReferenceTypeImpl(new JavassistInterfaceDeclaration(ctClazz, typeSolver)); } else if (ctClazz.isEnum()) { - return new ReferenceTypeImpl(new JavassistEnumDeclaration(ctClazz, typeSolver), - typeSolver); + return new ReferenceTypeImpl(new JavassistEnumDeclaration(ctClazz, typeSolver)); } else { - return new ReferenceTypeImpl(new JavassistClassDeclaration(ctClazz, typeSolver), - typeSolver); + return new ReferenceTypeImpl(new JavassistClassDeclaration(ctClazz, typeSolver)); } } } catch (NotFoundException e) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java index a3d82850dd..f4646cef0c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodLikeDeclarationAdapter.java @@ -112,7 +112,7 @@ public ResolvedType getSpecifiedException(int index) { } ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType(exceptions[index]); - return new ReferenceTypeImpl(typeDeclaration, Collections.emptyList(), typeSolver); + return new ReferenceTypeImpl(typeDeclaration, Collections.emptyList()); } public ResolvedType getReturnType() { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java index e1e78f714b..aa60619c1f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeDeclarationAdapter.java @@ -74,8 +74,7 @@ public Optional getSuperClass() { // Compiled classes have generic types erased, but can be made available for reflection via getGenericSignature(). // If it is absent, then no further work is needed and we can return a reference type without generics. return Optional.of(new ReferenceTypeImpl( - typeSolver.solveType(JavassistUtils.internalNameToCanonicalName(ctClass.getClassFile().getSuperclass())), - typeSolver + typeSolver.solveType(JavassistUtils.internalNameToCanonicalName(ctClass.getClassFile().getSuperclass())) )); } else { // If there is a generic signature present, solve the types and return it. @@ -104,7 +103,7 @@ private List getInterfaces(boolean acceptIncompleteList) for (String interfaceType : ctClass.getClassFile().getInterfaces()) { try { ResolvedReferenceTypeDeclaration declaration = typeSolver.solveType(JavassistUtils.internalNameToCanonicalName(interfaceType)); - interfaces.add(new ReferenceTypeImpl(declaration, typeSolver)); + interfaces.add(new ReferenceTypeImpl(declaration)); } catch (UnsolvedSymbolException e) { if (!acceptIncompleteList) { throw e; @@ -211,11 +210,11 @@ public boolean isAssignableBy(ResolvedType other) { return typeDeclaration.isFunctionalInterface(); } - return other.isAssignableBy(new ReferenceTypeImpl(typeDeclaration, typeSolver)); + return other.isAssignableBy(new ReferenceTypeImpl(typeDeclaration)); } public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java index d0e74f415e..894f65080e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java @@ -131,6 +131,6 @@ public Optional containerType() { @Override public ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index 2ed7efaaad..88d1b7498b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -145,7 +145,7 @@ static ResolvedType signatureTypeToType(SignatureAttribute.Type signatureType, T List typeArguments = classType.getTypeArguments() == null ? Collections.emptyList() : Arrays.stream(classType.getTypeArguments()).map(ta -> typeArgumentToType(ta, typeSolver, typeParametrizable)).collect(Collectors.toList()); ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType( removeTypeArguments(internalNameToCanonicalName(getTypeName(classType)))); - return new ReferenceTypeImpl(typeDeclaration, typeArguments, typeSolver); + return new ReferenceTypeImpl(typeDeclaration, typeArguments); } else if (signatureType instanceof SignatureAttribute.TypeVariable) { SignatureAttribute.TypeVariable typeVariableSignature = (SignatureAttribute.TypeVariable) signatureType; Optional typeParameterDeclarationOpt = typeParametrizable.findTypeParameter(typeVariableSignature.getName()); @@ -208,8 +208,7 @@ private static ResolvedType objectTypeArgumentToType(SignatureAttribute.ObjectTy private static ResolvedType getGenericParameterByName(String typeName, ResolvedTypeParametrizable typeParametrizable, TypeSolver typeSolver) { Optional type = typeParametrizable.findTypeParameter(typeName).map(ResolvedTypeVariable::new); return type.orElseGet(() -> new ReferenceTypeImpl( - typeSolver.solveType(removeTypeArguments(internalNameToCanonicalName(typeName))), - typeSolver)); + typeSolver.solveType(removeTypeArguments(internalNameToCanonicalName(typeName))))); } private static ResolvedType typeArgumentToType(SignatureAttribute.TypeArgument typeArgument, TypeSolver typeSolver, ResolvedTypeParametrizable typeParametrizable) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java index 63d757ced0..53dcfd536d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java @@ -41,7 +41,7 @@ private MyObjectProvider() { @Override public ResolvedReferenceType object() { - return new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, new ReflectionTypeSolver()), new ReflectionTypeSolver()); + return new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, new ReflectionTypeSolver())); } @Override @@ -51,7 +51,7 @@ public ResolvedReferenceType byName(String qualifiedName) { if (!typeDeclaration.getTypeParameters().isEmpty()) { throw new UnsupportedOperationException(); } - return new ReferenceTypeImpl(typeDeclaration, typeSolver); + return new ReferenceTypeImpl(typeDeclaration); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index e93c16d57f..9e809f1c6f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -80,7 +80,7 @@ public ResolvedType getType() { } SymbolReference rrtd = typeSolver.tryToSolveType(returnType.getName()); if (rrtd.isSolved()) { - return new ReferenceTypeImpl(rrtd.getCorrespondingDeclaration(), typeSolver); + return new ReferenceTypeImpl(rrtd.getCorrespondingDeclaration()); } throw new UnsupportedOperationException(String.format("Obtaining the type of the annotation member %s is not supported yet.", annotationMember.getName())); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java index d9bc42d103..0d1659ade2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassAdapter.java @@ -73,9 +73,9 @@ public Optional getSuperClass() { List typeParameters = Arrays.stream(parameterizedType.getActualTypeArguments()) .map((t) -> ReflectionFactory.typeUsageFor(t, typeSolver)) .collect(Collectors.toList()); - return Optional.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver), typeParameters, typeSolver)); + return Optional.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver), typeParameters)); } - return Optional.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver), typeSolver)); + return Optional.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver))); } public List getInterfaces() { @@ -86,9 +86,9 @@ public List getInterfaces() { List typeParameters = Arrays.stream(parameterizedType.getActualTypeArguments()) .map((t) -> ReflectionFactory.typeUsageFor(t, typeSolver)) .collect(Collectors.toList()); - interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class) ((ParameterizedType) superInterface).getRawType(), typeSolver), typeParameters, typeSolver)); + interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class) ((ParameterizedType) superInterface).getRawType(), typeSolver), typeParameters)); } else { - interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class) superInterface, typeSolver), typeSolver)); + interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class) superInterface, typeSolver))); } } return interfaces; @@ -103,7 +103,7 @@ public List getAncestors() { } else { // Inject the implicitly added extends java.lang.Object ReferenceTypeImpl object = new ReferenceTypeImpl( - new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + new ReflectionClassDeclaration(Object.class, typeSolver)); ancestors.add(object); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index abe93a5598..aeaec13263 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -208,7 +208,7 @@ public String toString() { public ResolvedType getUsage(Node node) { - return new ReferenceTypeImpl(this, typeSolver); + return new ReferenceTypeImpl(this); } public Optional solveMethodAsUsage(String name, List argumentsTypes, Context invokationContext, List typeParameterValues) { @@ -318,7 +318,7 @@ public boolean hasField(String name) { @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override @@ -402,6 +402,6 @@ public Optional toAst() { @Override protected ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java index 496753f084..72179c5c46 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java @@ -51,6 +51,6 @@ public String getName() { public ResolvedType getType() { Class enumClass = enumConstant.getDeclaringClass(); ResolvedReferenceTypeDeclaration typeDeclaration = new ReflectionEnumDeclaration(enumClass, typeSolver); - return new ReferenceTypeImpl(typeDeclaration, typeSolver); + return new ReferenceTypeImpl(typeDeclaration); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 94559910a2..117082abe4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -151,7 +151,7 @@ public boolean isAssignableBy(ResolvedType type) { @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java index 757eb4271d..bdc91bb0d2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFactory.java @@ -90,7 +90,7 @@ public static ResolvedType typeUsageFor(java.lang.reflect.Type type, TypeSolver } else if (c.isArray()) { return new ResolvedArrayType(typeUsageFor(c.getComponentType(), typeSolver)); } else { - return new ReferenceTypeImpl(typeDeclarationFor(c, typeSolver), typeSolver); + return new ReferenceTypeImpl(typeDeclarationFor(c, typeSolver)); } } else if (type instanceof GenericArrayType) { GenericArrayType genericArrayType = (GenericArrayType) type; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 1b4b45a09c..b513ffa1f1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -80,7 +80,7 @@ public ReflectionInterfaceDeclaration(Class clazz, TypeSolver typeSolver) { @Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { - return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); + return isAssignableBy(new ReferenceTypeImpl(other)); } @Override @@ -120,7 +120,7 @@ public String toString() { } public ResolvedType getUsage(Node node) { - return new ReferenceTypeImpl(this, typeSolver); + return new ReferenceTypeImpl(this); } @Override @@ -285,7 +285,7 @@ public boolean isInterface() { public List getInterfacesExtended() { List res = new ArrayList<>(); for (Class i : clazz.getInterfaces()) { - res.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(i, typeSolver), typeSolver)); + res.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(i, typeSolver))); } return res; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index d259a8eb66..024657ebe7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -68,7 +68,7 @@ static SymbolReference solveMethod(String name, List< } if (scopeType.getAncestors().isEmpty()){ - ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); objectClass.getTypeDeclaration().ifPresent(objectTypeDeclaration -> { SymbolReference ref = MethodResolutionLogic.solveMethodInType(objectTypeDeclaration, name, parameterTypes, staticOnly); if (ref.isSolved()) { @@ -88,7 +88,7 @@ static Optional solveMethodAsUsage(String name, List // Parameters not specified, so default to Object typeParameterValues = new ArrayList<>(); for (int i = 0; i < scopeType.getTypeParameters().size(); i++) { - typeParameterValues.add(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver)); + typeParameterValues.add(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver))); } } } @@ -117,7 +117,7 @@ static Optional solveMethodAsUsage(String name, List } if (ancestors.isEmpty()) { - Optional optionalObjectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver).getTypeDeclaration(); + Optional optionalObjectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)).getTypeDeclaration(); if (optionalObjectClass.isPresent()) { SymbolReference ref = MethodResolutionLogic.solveMethodInType(optionalObjectClass.get(), name, argumentsTypes); if (ref.isSolved()) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java index b9235df902..b3ad00fc66 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java @@ -137,6 +137,6 @@ public Optional containerType() { @Override public ResolvedReferenceType object() { - return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index 54298f3378..02fb1a2720 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -345,7 +345,7 @@ public static ResolvedType replaceTypeParam(ResolvedType type, ResolvedTypeParam if (bounds.size() == 1) { return bounds.get(0).getType(); } - return new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver); + return new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT)); } return type; } @@ -454,7 +454,7 @@ public static boolean isApplicable(MethodUsage methodUsage, String needleName, L for (ResolvedTypeParameterDeclaration tp : typeParameters) { if (tp.getBounds().isEmpty()) { //expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp.getName(), new ReferenceTypeUsageImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver)); - expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver))); + expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT)))); } else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { @@ -473,13 +473,13 @@ public static boolean isApplicable(MethodUsage methodUsage, String needleName, L ResolvedType expectedTypeWithSubstitutions = expectedTypeWithoutSubstitutions; for (ResolvedTypeParameterDeclaration tp : typeParameters) { if (tp.getBounds().isEmpty()) { - expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver)); + expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT))); } else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, bound.getType()); } else { - expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver)); + expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT))); } } else { throw new UnsupportedOperationException(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 8273ddd0de..53daf1e907 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -118,7 +118,7 @@ public ResolvedType solveTypeUsage(String name, Context context) { return genericType.get(); } ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType(name); - return new ReferenceTypeImpl(typeDeclaration, typeSolver); + return new ReferenceTypeImpl(typeDeclaration); } /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java index e21cff5282..59ec914179 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/BoundSet.java @@ -715,7 +715,7 @@ public Optional performResolution(List vari boolean throwsBound = bounds.stream().anyMatch(b -> b.isThrowsBoundOn(alphaI)); if (Ti == null && throwsBound && properUpperBoundsAreAtMostExceptionThrowableAndObject(alphaI)) { - Ti = new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_RUNTIME_EXCEPTION), typeSolver); + Ti = new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_RUNTIME_EXCEPTION)); } // - Otherwise, where αi has proper upper bounds U1, ..., Uk, Ti = glb(U1, ..., Uk) (§5.1.10). diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index 90bbebc277..00a05456ab 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -172,7 +172,7 @@ public static ResolvedType toBoxedType(ResolvedPrimitiveType primitiveType) { // get the resolved boxed type of the specified primitive type public static ResolvedType toBoxedType(ResolvedPrimitiveType primitiveType, TypeSolver typeSolver ) { SymbolReference typeDeclaration = typeSolver.tryToSolveType(primitiveType.getBoxTypeQName()); - return new ReferenceTypeImpl(typeDeclaration.getCorrespondingDeclaration(), typeSolver); + return new ReferenceTypeImpl(typeDeclaration.getCorrespondingDeclaration()); } public static boolean areCompatibleThroughWideningReferenceConversion(ResolvedType s, ResolvedType t) { @@ -353,7 +353,7 @@ private static ResolvedReferenceType nonWildcardParameterizationOf(ResolvedRefer // Let P1...Pn be the type parameters of I with corresponding bounds B1...Bn. For all i (1 ≤ i ≤ n), // Ti is derived according to the form of Ai: - ResolvedReferenceType object = new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject(), typeSolver); + ResolvedReferenceType object = new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); for (int i=0;i declaredTypes(String... lines) { CompilationUnit tree = treeOf(lines); List results = Lists.newLinkedList(); for (ClassOrInterfaceDeclaration classTree : tree.findAll(ClassOrInterfaceDeclaration.class)) { - results.add(new ReferenceTypeImpl(classTree.resolve(), typeSolver)); + results.add(new ReferenceTypeImpl(classTree.resolve())); } return results; } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java index 17998f2b83..cd5f40bbe2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclarationTest.java @@ -192,12 +192,12 @@ void whenOtherTypeIsProvided() { void whenSameClassButWithDifferentTypeParametersIsProvided() { ReflectionTypeSolver reflectionTypeSolver = new ReflectionTypeSolver(); - ReferenceTypeImpl javaLangObject = new ReferenceTypeImpl(reflectionTypeSolver.getSolvedJavaLangObject(), typeSolver); + ReferenceTypeImpl javaLangObject = new ReferenceTypeImpl(reflectionTypeSolver.getSolvedJavaLangObject()); ResolvedWildcard wildCard = ResolvedWildcard.extendsBound(javaLangObject); JavassistInterfaceDeclaration nodeWithImplements = (JavassistInterfaceDeclaration) typeSolver.solveType(CLASS_TO_SOLVE); - ResolvedType typeA = new ReferenceTypeImpl(nodeWithImplements, Collections.singletonList(wildCard), typeSolver); - ResolvedType typeB = new ReferenceTypeImpl(nodeWithImplements, Collections.singletonList(javaLangObject), typeSolver); + ResolvedType typeA = new ReferenceTypeImpl(nodeWithImplements, Collections.singletonList(wildCard)); + ResolvedType typeB = new ReferenceTypeImpl(nodeWithImplements, Collections.singletonList(javaLangObject)); assertFalse(typeB.isAssignableBy(typeA), "This should not be allowed:" + " NodeWithImplements node = new NodeWithImplements()"); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java index 100ea7febc..8bbd2edf75 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/FunctionInterfaceLogicTest.java @@ -40,17 +40,17 @@ class FunctionInterfaceLogicTest { @Test void testGetFunctionalMethodNegativeCaseOnClass() { TypeSolver typeSolver = new ReflectionTypeSolver(); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); assertEquals(false, FunctionalInterfaceLogic.getFunctionalMethod(string).isPresent()); } @Test void testGetFunctionalMethodPositiveCasesOnInterfaces() { TypeSolver typeSolver = new ReflectionTypeSolver(); - ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Function.class, typeSolver), typeSolver); + ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Function.class, typeSolver)); assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(function).isPresent()); assertEquals("apply", FunctionalInterfaceLogic.getFunctionalMethod(function).get().getName()); - ResolvedType consumer = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Consumer.class, typeSolver), typeSolver); + ResolvedType consumer = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Consumer.class, typeSolver)); assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(consumer).isPresent()); assertEquals("accept", FunctionalInterfaceLogic.getFunctionalMethod(consumer).get().getName()); } @@ -58,7 +58,7 @@ void testGetFunctionalMethodPositiveCasesOnInterfaces() { @Test void testGetFunctionalMethodWith2AbstractMethodsInHierarcy() { TypeSolver typeSolver = new ReflectionTypeSolver(); - ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Foo.class, typeSolver), typeSolver); + ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Foo.class, typeSolver)); assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(function).isPresent()); assertEquals("foo", FunctionalInterfaceLogic.getFunctionalMethod(function).get().getName()); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index 197fbc95cb..4606de1a05 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -56,8 +56,8 @@ class InferenceContextTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); - object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); + object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); listOfString = listOf(string); tpE = mock(ResolvedTypeParameterDeclaration.class); when(tpE.getName()).thenReturn("T"); @@ -66,7 +66,7 @@ void setup() { } private ResolvedReferenceType listOf(ResolvedType elementType) { - return new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(elementType), typeSolver); + return new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(elementType)); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java index 00703a5770..56aacf6c33 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ArrayTypeTest.java @@ -54,17 +54,17 @@ class ArrayTypeTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN); arrayOfStrings = new ResolvedArrayType(STRING); tpA = ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()); arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ResolvedTypeVariable(tpA)), typeSolver)); + ImmutableList.of(new ResolvedTypeVariable(tpA)))); arrayOfListOfStrings = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver)); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver))))); } @Test @@ -144,7 +144,7 @@ void testReplaceParam() { assertEquals(arrayOfListOfStrings, arrayOfListOfStrings.replaceTypeVariables(tpA, OBJECT)); ResolvedArrayType arrayOfListOfObjects = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(OBJECT), typeSolver)); + ImmutableList.of(OBJECT))); assertTrue(arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).isArray()); assertEquals(ImmutableList.of(OBJECT), arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).asArrayType().getComponentType() @@ -154,7 +154,7 @@ void testReplaceParam() { .asReferenceType().getTypeDeclaration().get()); assertEquals(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(OBJECT), typeSolver), + ImmutableList.of(OBJECT)), arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).asArrayType().getComponentType()); assertEquals(arrayOfListOfObjects, arrayOfListOfA.replaceTypeVariables(tpA, OBJECT)); assertEquals(arrayOfListOfStrings, arrayOfListOfA.replaceTypeVariables(tpA, STRING)); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java index b9ad7c0ca9..6109f2d4ae 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/LazyTypeTest.java @@ -53,9 +53,9 @@ class Baz extends Foo {} @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); - bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver), typeSolver); - baz = new ReferenceTypeImpl(new ReflectionClassDeclaration(Baz.class, typeSolver), typeSolver); + foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver)); + bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver)); + baz = new ReferenceTypeImpl(new ReflectionClassDeclaration(Baz.class, typeSolver)); lazyFoo = lazy(foo); lazyBar = lazy(bar); lazyBaz = lazy(baz); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java index c8809eb43e..eed0d9d8bc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/NullTypeTest.java @@ -53,12 +53,12 @@ class NullTypeTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN); arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver)); + ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))))); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java index 0bce6565aa..831c93dc6b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/PrimitiveTypeTest.java @@ -61,21 +61,21 @@ class PrimitiveTypeTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN); arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver)); - - booleanBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Boolean.class, typeSolver), typeSolver); - characterBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Character.class, typeSolver), typeSolver); - byteBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Byte.class, typeSolver), typeSolver); - shortBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Short.class, typeSolver), typeSolver); - integerBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Integer.class, typeSolver), typeSolver); - longBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Long.class, typeSolver), typeSolver); - floatBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Float.class, typeSolver), typeSolver); - doubleBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Double.class, typeSolver), typeSolver); + ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))))); + + booleanBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Boolean.class, typeSolver)); + characterBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Character.class, typeSolver)); + byteBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Byte.class, typeSolver)); + shortBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Short.class, typeSolver)); + integerBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Integer.class, typeSolver)); + longBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Long.class, typeSolver)); + floatBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Float.class, typeSolver)); + doubleBox = new ReferenceTypeImpl(new ReflectionClassDeclaration(Double.class, typeSolver)); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java index bdb1b18803..79c12d11b6 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeTest.java @@ -93,34 +93,34 @@ class ReferenceTypeTest extends AbstractSymbolResolutionTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); listOfA = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver); + ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList())))); listOfStrings = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); linkedListOfString = new ReferenceTypeImpl( new ReflectionClassDeclaration(LinkedList.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); collectionOfString = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(Collection.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); listOfWildcardExtendsString = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(ResolvedWildcard.extendsBound(string)), typeSolver); + ImmutableList.of(ResolvedWildcard.extendsBound(string))); listOfWildcardSuperString = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(ResolvedWildcard.superBound(string)), typeSolver); - ioException = new ReferenceTypeImpl(new ReflectionClassDeclaration(IOException.class, typeSolver), typeSolver); + ImmutableList.of(ResolvedWildcard.superBound(string))); + ioException = new ReferenceTypeImpl(new ReflectionClassDeclaration(IOException.class, typeSolver)); unionWithIOExceptionAsCommonAncestor = new ResolvedUnionType(Arrays.asList( - new ReferenceTypeImpl(new ReflectionClassDeclaration(ProtocolException.class, typeSolver), typeSolver), - new ReferenceTypeImpl(new ReflectionClassDeclaration(FileSystemException.class, typeSolver), typeSolver) + new ReferenceTypeImpl(new ReflectionClassDeclaration(ProtocolException.class, typeSolver)), + new ReferenceTypeImpl(new ReflectionClassDeclaration(FileSystemException.class, typeSolver)) )); unionWithThrowableAsCommonAncestor = new ResolvedUnionType(Arrays.asList( - new ReferenceTypeImpl(new ReflectionClassDeclaration(ClassCastException.class, typeSolver), typeSolver), - new ReferenceTypeImpl(new ReflectionClassDeclaration(AssertionError.class, typeSolver), typeSolver) + new ReferenceTypeImpl(new ReflectionClassDeclaration(ClassCastException.class, typeSolver)), + new ReferenceTypeImpl(new ReflectionClassDeclaration(AssertionError.class, typeSolver)) )); // minimal initialization of JavaParser @@ -133,7 +133,7 @@ void setup() { @Test void testDerivationOfTypeParameters() { ReflectionTypeSolver typeSolver = new ReflectionTypeSolver(); - ReferenceTypeImpl ref1 = new ReferenceTypeImpl(typeSolver.solveType(LinkedList.class.getCanonicalName()), typeSolver); + ReferenceTypeImpl ref1 = new ReferenceTypeImpl(typeSolver.solveType(LinkedList.class.getCanonicalName())); assertEquals(1, ref1.typeParametersValues().size()); assertEquals(true, ref1.typeParametersValues().get(0).isTypeVariable()); assertEquals("E", ref1.typeParametersValues().get(0).asTypeParameter().getName()); @@ -250,15 +250,15 @@ void testIsAssignableBySimple() { @Test void testIsAssignableByBoxedPrimitive() { - ResolvedReferenceType numberType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Number.class, typeSolver), typeSolver); - ResolvedReferenceType intType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Integer.class, typeSolver), typeSolver); - ResolvedReferenceType doubleType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Double.class, typeSolver), typeSolver); - ResolvedReferenceType byteType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Byte.class, typeSolver), typeSolver); - ResolvedReferenceType shortType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Short.class, typeSolver), typeSolver); - ResolvedReferenceType charType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Character.class, typeSolver), typeSolver); - ResolvedReferenceType longType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Long.class, typeSolver), typeSolver); - ResolvedReferenceType booleanType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Boolean.class, typeSolver), typeSolver); - ResolvedReferenceType floatType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Float.class, typeSolver), typeSolver); + ResolvedReferenceType numberType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Number.class, typeSolver)); + ResolvedReferenceType intType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Integer.class, typeSolver)); + ResolvedReferenceType doubleType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Double.class, typeSolver)); + ResolvedReferenceType byteType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Byte.class, typeSolver)); + ResolvedReferenceType shortType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Short.class, typeSolver)); + ResolvedReferenceType charType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Character.class, typeSolver)); + ResolvedReferenceType longType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Long.class, typeSolver)); + ResolvedReferenceType booleanType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Boolean.class, typeSolver)); + ResolvedReferenceType floatType = new ReferenceTypeImpl(new ReflectionClassDeclaration(Float.class, typeSolver)); assertEquals(true, numberType.isAssignableBy(ResolvedPrimitiveType.INT)); assertEquals(true, numberType.isAssignableBy(ResolvedPrimitiveType.DOUBLE)); @@ -284,7 +284,7 @@ class ResolvedReferenceTypeTester extends ReferenceTypeImpl { public ResolvedReferenceTypeTester(ResolvedReferenceTypeDeclaration typeDeclaration, TypeSolver typeSolver) { - super(typeDeclaration, typeSolver); + super(typeDeclaration); } public boolean isCorrespondingBoxingType(String name) { @@ -388,66 +388,66 @@ class MoreBazzing extends Bazzer { @Test void testGetAllAncestorsConsideringGenericsCases() { - ReferenceTypeImpl foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); - ReferenceTypeImpl bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver), typeSolver); + ReferenceTypeImpl foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver)); + ReferenceTypeImpl bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver)); ReferenceTypeImpl left, right; //YES MoreBazzing e1 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver) + ImmutableList.of(foo, bar)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver)) + ImmutableList.of(foo, bar))) ); //YES MoreBazzing e2 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(ResolvedWildcard.extendsBound(foo), bar), typeSolver) + ImmutableList.of(ResolvedWildcard.extendsBound(foo), bar)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver)) + ImmutableList.of(foo, bar))) ); //YES MoreBazzing e3 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, ResolvedWildcard.extendsBound(bar)), typeSolver) + ImmutableList.of(foo, ResolvedWildcard.extendsBound(bar))) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver)) + ImmutableList.of(foo, bar))) ); //YES MoreBazzing e4 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(ResolvedWildcard.extendsBound(foo), ResolvedWildcard.extendsBound(foo)), typeSolver) + ImmutableList.of(ResolvedWildcard.extendsBound(foo), ResolvedWildcard.extendsBound(foo))) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver)) + ImmutableList.of(foo, bar))) ); //YES MoreBazzing e5 = new MoreBazzing(); left = new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(ResolvedWildcard.extendsBound(foo), ResolvedWildcard.extendsBound(foo)), typeSolver); + ImmutableList.of(ResolvedWildcard.extendsBound(foo), ResolvedWildcard.extendsBound(foo))); right = new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(bar, bar), typeSolver); + ImmutableList.of(bar, bar)); assertEquals(true, left.isAssignableBy(right)); //YES Bazzer e6 = new MoreBazzing(); left = new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(object, string, string), typeSolver); + ImmutableList.of(object, string, string)); right = new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(string, object), typeSolver); + ImmutableList.of(string, object)); // To debug the following List ancestors = right.getAllAncestors(); @@ -461,68 +461,68 @@ void testGetAllAncestorsConsideringGenericsCases() { assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(string, string, string), typeSolver) + ImmutableList.of(string, string, string)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(string, string), typeSolver)) + ImmutableList.of(string, string))) ); //YES Bazzer e8 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(bar, string, foo), typeSolver) + ImmutableList.of(bar, string, foo)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(foo, bar), typeSolver)) + ImmutableList.of(foo, bar))) ); //YES Bazzer e9 = new MoreBazzing(); assertEquals(true, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(foo, string, bar), typeSolver) + ImmutableList.of(foo, string, bar)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(bar, foo), typeSolver)) + ImmutableList.of(bar, foo))) ); //NO Bazzer n1 = new MoreBazzing(); assertEquals(false, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(bar, string, foo), typeSolver) + ImmutableList.of(bar, string, foo)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(bar, foo), typeSolver)) + ImmutableList.of(bar, foo))) ); //NO Bazzer n2 = new MoreBazzing(); assertEquals(false, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(bar, string, foo), typeSolver) + ImmutableList.of(bar, string, foo)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(bar, foo), typeSolver)) + ImmutableList.of(bar, foo))) ); //NO Bazzer n3 = new MoreBazzing(); assertEquals(false, new ReferenceTypeImpl( new ReflectionClassDeclaration(Bazzer.class, typeSolver), - ImmutableList.of(foo, object, bar), typeSolver) + ImmutableList.of(foo, object, bar)) .isAssignableBy(new ReferenceTypeImpl( new ReflectionClassDeclaration(MoreBazzing.class, typeSolver), - ImmutableList.of(bar, foo), typeSolver)) + ImmutableList.of(bar, foo))) ); } @Test void charSequenceIsAssignableToObject() { TypeSolver typeSolver = new ReflectionTypeSolver(); - ReferenceTypeImpl charSequence = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(CharSequence.class, typeSolver), typeSolver); - ReferenceTypeImpl object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + ReferenceTypeImpl charSequence = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(CharSequence.class, typeSolver)); + ReferenceTypeImpl object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); assertEquals(false, charSequence.isAssignableBy(object)); assertEquals(true, object.isAssignableBy(charSequence)); } @@ -535,7 +535,7 @@ class Foo { } TypeSolver typeSolver = new ReflectionTypeSolver(); - ReferenceTypeImpl ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); + ReferenceTypeImpl ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver)); assertEquals(true, ref.getFieldType("elements").isPresent()); assertEquals(true, ref.getFieldType("elements").get().isReferenceType()); @@ -545,8 +545,7 @@ class Foo { assertEquals("A", ref.getFieldType("elements").get().asReferenceType().typeParametersValues().get(0).asTypeParameter().getName()); ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), - typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); assertEquals(true, ref.getFieldType("elements").isPresent()); assertEquals(true, ref.getFieldType("elements").get().isReferenceType()); @@ -564,13 +563,12 @@ class Foo { } TypeSolver typeSolver = new ReflectionTypeSolver(); - ReferenceTypeImpl ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); + ReferenceTypeImpl ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver)); assertEquals(false, ref.getFieldType("bar").isPresent()); ref = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), - typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); assertEquals(false, ref.getFieldType("bar").isPresent()); } @@ -584,8 +582,8 @@ void testTypeParamValue() { ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver); ResolvedInterfaceDeclaration collection = new ReflectionInterfaceDeclaration(Collection.class, typeResolver); ResolvedInterfaceDeclaration iterable = new ReflectionInterfaceDeclaration(Iterable.class, typeResolver); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); - ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string), typeResolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); + ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string)); assertEquals(Optional.of(string), arrayListOfString.typeParamValue(arraylist.getTypeParameters().get(0))); assertEquals(Optional.of(string), arrayListOfString.typeParamValue(abstractList.getTypeParameters().get(0))); assertEquals(Optional.of(string), arrayListOfString.typeParamValue(abstractCollection.getTypeParameters().get(0))); @@ -598,99 +596,99 @@ void testTypeParamValue() { void testGetAllAncestorsOnRawType() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver); - ResolvedReferenceType rawArrayList = new ReferenceTypeImpl(arraylist, typeResolver); + ResolvedReferenceType rawArrayList = new ReferenceTypeImpl(arraylist); Map ancestors = new HashMap<>(); rawArrayList.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); assertEquals(9, ancestors.size()); ResolvedTypeVariable tv = new ResolvedTypeVariable(arraylist.getTypeParameters().get(0)); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver), typeResolver), ancestors.get("java.util.RandomAccess")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.util.AbstractCollection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.util.List")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver), typeResolver), ancestors.get("java.lang.Cloneable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.util.AbstractList")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.lang.Iterable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver), typeResolver), ancestors.get("java.io.Serializable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver)), ancestors.get("java.util.RandomAccess")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(tv)), ancestors.get("java.util.AbstractCollection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(tv)), ancestors.get("java.util.List")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver)), ancestors.get("java.lang.Cloneable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(tv)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(tv)), ancestors.get("java.util.AbstractList")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get("java.lang.Object")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(tv)), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver)), ancestors.get("java.io.Serializable")); } @Test void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForInterface() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); - ResolvedReferenceType listOfString = new ReferenceTypeImpl(list, ImmutableList.of(string), typeResolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); + ResolvedReferenceType listOfString = new ReferenceTypeImpl(list, ImmutableList.of(string)); Map ancestors = new HashMap<>(); listOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); assertEquals(2, ancestors.size()); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.lang.Iterable")); } @Test void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractCollection() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedClassDeclaration abstractCollection = new ReflectionClassDeclaration(AbstractCollection.class, typeResolver); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); - ResolvedReferenceType abstractCollectionOfString = new ReferenceTypeImpl(abstractCollection, ImmutableList.of(string), typeResolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); + ResolvedReferenceType abstractCollectionOfString = new ReferenceTypeImpl(abstractCollection, ImmutableList.of(string)); Map ancestors = new HashMap<>(); abstractCollectionOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); assertEquals(3, ancestors.size()); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get("java.lang.Object")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.lang.Iterable")); } @Test void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractList() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedClassDeclaration abstractList = new ReflectionClassDeclaration(AbstractList.class, typeResolver); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); - ResolvedReferenceType abstractListOfString = new ReferenceTypeImpl(abstractList, ImmutableList.of(string), typeResolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); + ResolvedReferenceType abstractListOfString = new ReferenceTypeImpl(abstractList, ImmutableList.of(string)); Map ancestors = new HashMap<>(); abstractListOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); assertEquals(5, ancestors.size()); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractCollection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.List")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.AbstractCollection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.List")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get("java.lang.Object")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.lang.Iterable")); } @Test void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassArrayList() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver); - ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); - ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string), typeResolver); + ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); + ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string)); Map ancestors = new HashMap<>(); arrayListOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a)); assertEquals(9, ancestors.size()); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver), typeResolver), ancestors.get("java.util.RandomAccess")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractCollection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.List")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver), typeResolver), ancestors.get("java.lang.Cloneable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractList")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver), typeResolver), ancestors.get("java.io.Serializable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver)), ancestors.get("java.util.RandomAccess")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.AbstractCollection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.List")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver)), ancestors.get("java.lang.Cloneable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.util.AbstractList")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get("java.lang.Object")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string)), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver)), ancestors.get("java.io.Serializable")); } @Test void testTypeParametersValues() { TypeSolver typeResolver = new ReflectionTypeSolver(); - ResolvedReferenceType stream = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Stream.class, typeResolver), typeResolver); + ResolvedReferenceType stream = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Stream.class, typeResolver)); assertEquals(1, stream.typeParametersValues().size()); assertEquals(new ResolvedTypeVariable(new ReflectionInterfaceDeclaration(Stream.class, typeResolver).getTypeParameters().get(0)), stream.typeParametersValues().get(0)); } @@ -699,7 +697,7 @@ void testTypeParametersValues() { void testReplaceTypeVariables() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedInterfaceDeclaration streamInterface = new ReflectionInterfaceDeclaration(Stream.class, typeResolver); - ResolvedReferenceType stream = new ReferenceTypeImpl(streamInterface, typeResolver); + ResolvedReferenceType stream = new ReferenceTypeImpl(streamInterface); ResolvedMethodDeclaration streamMap = streamInterface.getDeclaredMethods().stream().filter(m -> m.getName().equals("map")).findFirst().get(); ResolvedTypeParameterDeclaration streamMapR = streamMap.findTypeParameter("T").get(); @@ -707,7 +705,7 @@ void testReplaceTypeVariables() { stream = stream.deriveTypeParameters(stream.typeParametersMap().toBuilder().setValue(stream.getTypeDeclaration().get().getTypeParameters().get(0), typeVariable).build()); ResolvedTypeParameterDeclaration tpToReplace = streamInterface.getTypeParameters().get(0); - ResolvedType replaced = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); + ResolvedType replaced = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); ResolvedType streamReplaced = stream.replaceTypeVariables(tpToReplace, replaced); assertEquals("java.util.stream.Stream", streamReplaced.describe()); @@ -717,7 +715,7 @@ void testReplaceTypeVariables() { void testReplaceTypeVariablesWithLambdaInBetween() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedInterfaceDeclaration streamInterface = new ReflectionInterfaceDeclaration(Stream.class, typeResolver); - ResolvedReferenceType stream = new ReferenceTypeImpl(streamInterface, typeResolver); + ResolvedReferenceType stream = new ReferenceTypeImpl(streamInterface); ResolvedMethodDeclaration streamMap = streamInterface.getDeclaredMethods().stream().filter(m -> m.getName().equals("map")).findFirst().get(); ResolvedTypeParameterDeclaration streamMapR = streamMap.findTypeParameter("T").get(); @@ -725,7 +723,7 @@ void testReplaceTypeVariablesWithLambdaInBetween() { stream = stream.deriveTypeParameters(stream.typeParametersMap().toBuilder().setValue(stream.getTypeDeclaration().get().getTypeParameters().get(0), typeVariable).build()); ResolvedTypeParameterDeclaration tpToReplace = streamInterface.getTypeParameters().get(0); - ResolvedType replaced = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver); + ResolvedType replaced = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver)); ResolvedType streamReplaced = stream.replaceTypeVariables(tpToReplace, replaced); assertEquals("java.util.stream.Stream", streamReplaced.describe()); @@ -740,7 +738,7 @@ void testDirectAncestorsOfObject() { void testDirectAncestorsOfInterface() { ResolvedReferenceType iterableOfString = new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(Iterable.class, typeSolver), - ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver); + ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)))); assertEquals(0, iterableOfString.getDirectAncestors().size()); } @@ -756,7 +754,7 @@ void testDirectAncestorsOfInterfaceExtendingInterface() { @Test void testDirectAncestorsOfClassWithoutSuperClassOrInterfaces() { - ResolvedReferenceType buffer = new ReferenceTypeImpl(new ReflectionClassDeclaration(Buffer.class, typeSolver), typeSolver); + ResolvedReferenceType buffer = new ReferenceTypeImpl(new ReflectionClassDeclaration(Buffer.class, typeSolver)); Set ancestors = buffer.getDirectAncestors() .stream() .map(ResolvedReferenceType::describe) @@ -767,7 +765,7 @@ void testDirectAncestorsOfClassWithoutSuperClassOrInterfaces() { @Test void testDirectAncestorsOfObjectClass() { - ResolvedReferenceType object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); + ResolvedReferenceType object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); Set ancestors = object.getDirectAncestors() .stream() .map(ResolvedReferenceType::describe) @@ -778,7 +776,7 @@ void testDirectAncestorsOfObjectClass() { @Test void testDirectAncestorsOfClassWithSuperClass() { - ResolvedReferenceType charbuffer = new ReferenceTypeImpl(new ReflectionClassDeclaration(CharBuffer.class, typeSolver), typeSolver); + ResolvedReferenceType charbuffer = new ReferenceTypeImpl(new ReflectionClassDeclaration(CharBuffer.class, typeSolver)); Set ancestors = charbuffer.getDirectAncestors() .stream() .map(ResolvedReferenceType::describe) @@ -836,8 +834,8 @@ void testDeclaredFields() { ClassOrInterfaceDeclaration classA = cu.getClassByName("A").get(); ClassOrInterfaceDeclaration classB = cu.getClassByName("B").get(); - ResolvedReferenceType rtA = new ReferenceTypeImpl(classA.resolve(), typeSolver); - ResolvedReferenceType rtB = new ReferenceTypeImpl(classB.resolve(), typeSolver); + ResolvedReferenceType rtA = new ReferenceTypeImpl(classA.resolve()); + ResolvedReferenceType rtB = new ReferenceTypeImpl(classB.resolve()); assertEquals(3, rtA.getDeclaredFields().size()); assertTrue(rtA.getDeclaredFields().stream().anyMatch(f -> f.getName().equals("i"))); @@ -862,8 +860,8 @@ void testGetAllFieldsVisibleToInheritors() { ClassOrInterfaceDeclaration classA = cu.getClassByName("A").get(); ClassOrInterfaceDeclaration classB = cu.getClassByName("B").get(); - ResolvedReferenceType rtA = new ReferenceTypeImpl(classA.resolve(), typeSolver); - ResolvedReferenceType rtB = new ReferenceTypeImpl(classB.resolve(), typeSolver); + ResolvedReferenceType rtA = new ReferenceTypeImpl(classA.resolve()); + ResolvedReferenceType rtB = new ReferenceTypeImpl(classB.resolve()); assertEquals(2, rtA.getAllFieldsVisibleToInheritors().size()); assertTrue(rtA.getAllFieldsVisibleToInheritors().stream().anyMatch(f -> f.getName().equals("c"))); @@ -956,7 +954,7 @@ private ResolvedType genericType(String type, ResolvedType... parameterTypes) { // return a generic type with type arguments private ResolvedType genericType(String type, String... parameterTypes) { - return new ReferenceTypeImpl(typeSolver.solveType(type), types(parameterTypes), typeSolver); + return new ReferenceTypeImpl(typeSolver.solveType(type), types(parameterTypes)); } // return a list of types @@ -970,7 +968,7 @@ private ResolvedType type(String type) { } private ResolvedType type(String type, List typeArguments) { - return new ReferenceTypeImpl(typeSolver.solveType(type), typeArguments, typeSolver); + return new ReferenceTypeImpl(typeSolver.solveType(type), typeArguments); } // return a type parameter @@ -1002,7 +1000,7 @@ private List declaredTypes(String... lines) { CompilationUnit tree = treeOf(lines); List results = Lists.newLinkedList(); for (ClassOrInterfaceDeclaration classTree : tree.findAll(ClassOrInterfaceDeclaration.class)) { - results.add(new ReferenceTypeImpl(classTree.resolve(), typeSolver)); + results.add(new ReferenceTypeImpl(classTree.resolve())); } return results; } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java index 4d58ff5da4..b5e1aecb31 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/TypeVariableUsageTest.java @@ -45,7 +45,7 @@ void setup() { tpA = new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList())); typeSolver = new ReflectionTypeSolver(); - tpString = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + tpString = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java index c26d69fb73..e7b0e15064 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/VoidTypeTest.java @@ -54,12 +54,12 @@ class VoidTypeTest { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN); arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl( new ReflectionInterfaceDeclaration(List.class, typeSolver), - ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver)); + ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))))); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java index d9d6dfef91..4fc65ef564 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/model/typesystem/WildcardUsageTest.java @@ -64,10 +64,10 @@ class Bar extends Foo { @BeforeEach void setup() { typeSolver = new ReflectionTypeSolver(); - foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver), typeSolver); - bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver), typeSolver); - object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); - string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + foo = new ReferenceTypeImpl(new ReflectionClassDeclaration(Foo.class, typeSolver)); + bar = new ReferenceTypeImpl(new ReflectionClassDeclaration(Bar.class, typeSolver)); + object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)); + string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); superFoo = ResolvedWildcard.superBound(foo); superBar = ResolvedWildcard.superBound(bar); extendsFoo = ResolvedWildcard.extendsBound(foo); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java index eb27e535e0..bc7f1ede81 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclarationTest.java @@ -346,15 +346,15 @@ void testAllAncestorsWithDepthFirstTraversalOrder() { assertEquals(9, ancestors.size()); ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(arraylist.getTypeParameters().get(0)); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver), typeResolver), ancestors.get("java.util.RandomAccess")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.AbstractCollection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.List")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver), typeResolver), ancestors.get("java.lang.Cloneable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.AbstractList")); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.lang.Iterable")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver), typeResolver), ancestors.get("java.io.Serializable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver)), ancestors.get("java.util.RandomAccess")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.util.AbstractCollection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.util.List")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver)), ancestors.get("java.lang.Cloneable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.util.AbstractList")); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get("java.lang.Object")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver)), ancestors.get("java.io.Serializable")); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java index cdfe1e37b3..8523e771ed 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclarationTest.java @@ -83,8 +83,8 @@ void testAllAncestors() { // Since List is an interface, Object cannot be an ancestor of List ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(list.getTypeParameters().get(0)); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.util.Collection")); - assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable), typeResolver), ancestors.get("java.lang.Iterable")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.util.Collection")); + assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(typeVariable)), ancestors.get("java.lang.Iterable")); } @Test @@ -96,9 +96,9 @@ void testAllAncestorsForAnInterfaceWithBreadthFirstFunc() { ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(list.getTypeParameters().get(0)); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), - ImmutableList.of(typeVariable), typeResolver), ancestors.get(0)); + ImmutableList.of(typeVariable)), ancestors.get(0)); assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), - ImmutableList.of(typeVariable), typeResolver), ancestors.get(1)); + ImmutableList.of(typeVariable)), ancestors.get(1)); } @Test @@ -108,18 +108,18 @@ void testAllAncestorsForAClassWithBreadthFirstFunc() { List ancestors = obj.getAllAncestors(ResolvedReferenceTypeDeclaration.breadthFirstFunc); assertEquals(6, ancestors.size()); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Buffer.class, typeResolver), typeResolver), + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Buffer.class, typeResolver)), ancestors.get(0)); assertEquals( - new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Appendable.class, typeResolver), typeResolver), + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Appendable.class, typeResolver)), ancestors.get(2)); assertEquals( - new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(CharSequence.class, typeResolver), typeResolver), + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(CharSequence.class, typeResolver)), ancestors.get(3)); assertEquals( - new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Readable.class, typeResolver), typeResolver), + new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Readable.class, typeResolver)), ancestors.get(4)); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver)), ancestors.get(5)); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java index c2043a74b0..2961c68c44 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ExprResolutionTest.java @@ -45,7 +45,7 @@ class ExprResolutionTest extends AbstractResolutionTest { @BeforeEach void setup() { ts = new ReflectionTypeSolver(); - stringType = new ReferenceTypeImpl(ts.solveType(String.class.getCanonicalName()), ts); + stringType = new ReferenceTypeImpl(ts.solveType(String.class.getCanonicalName())); } // JLS 5.6.2. Binary Numeric Promotion diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java index 607f21f75d..0071e2d6c3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/VarTypeTest.java @@ -63,7 +63,7 @@ void resolveAReferenceType() { ResolvedType resolvedType = varType.resolve(); - assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver), resolvedType); + assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)), resolvedType); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index 313aaa6d8a..7193f0f581 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -402,7 +402,7 @@ void solveMethodWithMoreSpecializedParameter() { ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); - ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); SymbolReference ref = context.solveMethod("foo4", ImmutableList.of(stringType), false); assertEquals(true, ref.isSolved()); @@ -482,7 +482,7 @@ void solveMethodAsUsageWithMoreSpecializedParameter() { Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, new ReflectionTypeSolver()); - ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); + ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver)); Optional ref = context.solveMethodAsUsage("foo4", ImmutableList.of(stringType)); assertEquals(true, ref.isPresent()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index aa8e4bc0c5..dcb73de9e0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -134,7 +134,7 @@ private void assertCanSolveGenericMethodCallCanInferFromArguments(String callMet ResolvedReferenceTypeDeclaration stringType = typeSolver.solveType("java.lang.String"); List argumentsTypes = new ArrayList<>(); - argumentsTypes.add(new ReferenceTypeImpl(stringType, typeSolver)); + argumentsTypes.add(new ReferenceTypeImpl(stringType)); Optional ref = context.solveMethodAsUsage(callMethodName, argumentsTypes); assertTrue(ref.isPresent()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java index b50a852c3c..213cdb26f7 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SameAsBoundTest.java @@ -37,7 +37,7 @@ class SameAsBoundTest { private TypeSolver typeSolver = new ReflectionTypeSolver(); - private ResolvedType stringType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(String.class.getCanonicalName()), typeSolver); + private ResolvedType stringType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(String.class.getCanonicalName())); @Test void recognizeInstantiation() { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java index a2555141e6..4cc151af1c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/bounds/SubtypeOfBoundTest.java @@ -42,11 +42,11 @@ class SubtypeOfBoundTest { private TypeSolver typeSolver = new ReflectionTypeSolver(); - private ResolvedReferenceType iterableType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Iterable.class.getCanonicalName()), typeSolver); - private ResolvedReferenceType listType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(List.class.getCanonicalName()), typeSolver); - private ResolvedType integerType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Integer.class.getCanonicalName()), typeSolver); - private ResolvedType doubleType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Double.class.getCanonicalName()), typeSolver); - private ResolvedType objectType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Object.class.getCanonicalName()), typeSolver); + private ResolvedReferenceType iterableType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Iterable.class.getCanonicalName())); + private ResolvedReferenceType listType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(List.class.getCanonicalName())); + private ResolvedType integerType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Integer.class.getCanonicalName())); + private ResolvedType doubleType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Double.class.getCanonicalName())); + private ResolvedType objectType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(Object.class.getCanonicalName())); @Test void recognizeProperLowerBound1() { @@ -92,8 +92,8 @@ void recognizeProperUpperBound2() { InferenceVariable alpha = new InferenceVariable("α", typeParameterDeclaration1); InferenceVariable beta = new InferenceVariable("β", typeParameterDeclaration2); - ResolvedType iterableOfWildcard = new ReferenceTypeImpl(iterableType.getTypeDeclaration().get(), Arrays.asList(ResolvedWildcard.UNBOUNDED), typeSolver); - ResolvedType listOfBeta = new ReferenceTypeImpl(listType.getTypeDeclaration().get(), Arrays.asList(beta), typeSolver); + ResolvedType iterableOfWildcard = new ReferenceTypeImpl(iterableType.getTypeDeclaration().get(), Arrays.asList(ResolvedWildcard.UNBOUNDED)); + ResolvedType listOfBeta = new ReferenceTypeImpl(listType.getTypeDeclaration().get(), Arrays.asList(beta)); Bound bound1 = new SubtypeOfBound(alpha, iterableOfWildcard); Bound bound2 = new SubtypeOfBound(beta, objectType); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java index db1f263933..dbce6a0dd5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typeinference/constraintformulas/ConstraintFormulaTest.java @@ -39,7 +39,7 @@ class ConstraintFormulaTest { private TypeSolver typeSolver = new ReflectionTypeSolver(); - private ResolvedType stringType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(String.class.getCanonicalName()), typeSolver); + private ResolvedType stringType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(String.class.getCanonicalName())); /** * From JLS 18.1.2 From b29da5219d3d736a2f2e308acba50daed45dd9b0 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Dec 2022 14:59:17 +0100 Subject: [PATCH 101/280] Refactoring convert to usage : Removing adhesions with type solver to resolve type 'var' in a for-each loop --- .../javaparsermodel/JavaParserFacade.java | 21 +++++--- .../JavaParserFacadeResolutionTest.java | 52 +++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index d4fc6109d4..855a62eb1c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -39,6 +39,7 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; +import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; @@ -76,6 +77,8 @@ public class JavaParserFacade { private static final Map instances = new WeakHashMap<>(); private static final String JAVA_LANG_STRING = String.class.getCanonicalName(); + + private static final String JAVA_LANG_OBJECT = Object.class.getCanonicalName(); /** * Note that the addition of the modifier {@code synchronized} is specific and directly in response to issue #2668. @@ -772,14 +775,18 @@ protected ResolvedType convertVarTypeToUsage(VarType varType, Context context) { // is the component type of the array. return ((ResolvedArrayType)iterType).getComponentType(); } - if (iterType instanceof ResolvedReferenceType) { + if (iterType.isReferenceType()) { // The type of a variable in a for-each loop with an - // Iterable is the same type as returned by the `next()` - // method of its `iterator()` - MethodCallExpr nextCall = new MethodCallExpr( - new MethodCallExpr(iterable, "iterator"), "next"); - MethodUsage methodUsage = solveMethodAsUsage(nextCall); - return methodUsage.returnType(); + // Iterable with parameter type + List parametersType = iterType.asReferenceType().typeParametersMap().getTypes(); + if (parametersType.isEmpty()) { + Optional oObjectDeclaration = context.solveType(JAVA_LANG_OBJECT) + .getDeclaration(); + return oObjectDeclaration + .map(decl -> ReferenceTypeImpl.undeterminedParameters(decl.asReferenceType())) + .orElseThrow(() -> new UnsupportedOperationException()); + } + return parametersType.get(0); } } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 8c1d410d2c..6f45208f17 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -47,8 +47,12 @@ import static com.github.javaparser.StaticJavaParser.parse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.ArrayList; +import java.util.List; + class JavaParserFacadeResolutionTest extends AbstractResolutionTest { @@ -225,6 +229,54 @@ void resolveVarTypeInForEachLoopFromIterableExpression() { assertEquals("java.lang.String", resolvedType.describe()); } + + // See issue 3725 + @Test + void resolveVarTypeInForEachLoopFromIterableExpression2() { + String sourceCode = "" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList<>();" + + " for (var s: list) {\n" + + " s.hashCode();\n" + + " }\n" + + " }\n" + + "}"; + + Expression toStringCallScope = scopeOfFirstHashCodeCall(sourceCode); + + // Before fixing the bug the next line failed with + // "java.lang.IllegalStateException: Cannot resolve `var` which has no initializer." + ResolvedType resolvedType = toStringCallScope.calculateResolvedType(); + + assertEquals("java.lang.String", resolvedType.describe()); + } + + // See issue 3725 + @Test + void resolveVarTypeInForEachLoopFromIterableExpression_withRawType() { + String sourceCode = "" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();" + + " for (var s: list) {\n" + + " s.hashCode();\n" + + " }\n" + + " }\n" + + "}"; + + Expression toStringCallScope = scopeOfFirstHashCodeCall(sourceCode); + + ResolvedType resolvedType = toStringCallScope.calculateResolvedType(); + + assertEquals("java.lang.Object", resolvedType.describe()); + } /** * Private helper method that returns the scope of the first From 86f41353d40bfd3ef0669b863926626b6c4949bf Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Dec 2022 17:35:49 +0100 Subject: [PATCH 102/280] Refactoring convert to usage --- ...er_symbol_solver_testing_src_test_java.txt | 5 +- .../github/javaparser/ast/type/ArrayType.java | 7 + .../ast/type/ClassOrInterfaceType.java | 37 +++++ .../ast/type/ConvertibleToUsage.java | 13 ++ .../javaparser/ast/type/IntersectionType.java | 8 + .../javaparser/ast/type/PrimitiveType.java | 8 + .../com/github/javaparser/ast/type/Type.java | 2 +- .../javaparser/ast/type/TypeParameter.java | 7 + .../github/javaparser/ast/type/UnionType.java | 14 ++ .../javaparser/ast/type/UnknownType.java | 14 ++ .../github/javaparser/ast/type/VarType.java | 69 ++++++++ .../github/javaparser/ast/type/VoidType.java | 7 + .../javaparser/ast/type/WildcardType.java | 24 +++ .../javaparser}/resolution/Context.java | 4 +- .../MethodUsageResolutionCapability.java | 1 + .../TypeVariableResolutionCapability.java | 1 + .../common/MethodDeclarationCommonLogic.java | 2 +- .../javaparsermodel/JavaParserFacade.java | 148 +----------------- .../javaparsermodel/JavaParserFactory.java | 2 +- .../javaparsermodel/TypeExtractor.java | 8 +- .../contexts/AbstractJavaParserContext.java | 2 +- .../contexts/BinaryExprContext.java | 2 +- .../contexts/BlockStmtContext.java | 2 +- .../contexts/ContextHelper.java | 2 +- .../contexts/EnclosedExprContext.java | 2 +- .../contexts/IfStatementContext.java | 2 +- .../contexts/InstanceOfExprContext.java | 2 +- .../JavaParserTypeDeclarationAdapter.java | 2 +- .../contexts/LambdaExprContext.java | 2 +- .../contexts/MethodCallExprContext.java | 2 +- .../contexts/MethodReferenceExprContext.java | 2 +- .../contexts/StatementContext.java | 2 +- .../contexts/UnaryExprContext.java | 2 +- .../VariableDeclarationExprContext.java | 2 +- .../contexts/VariableDeclaratorContext.java | 2 +- ...JavaParserAnnotationMemberDeclaration.java | 2 +- .../JavaParserAnonymousClassDeclaration.java | 2 +- .../JavaParserClassDeclaration.java | 2 +- .../JavaParserEnumDeclaration.java | 2 +- .../JavaParserInterfaceDeclaration.java | 2 +- .../JavaParserMethodDeclaration.java | 2 +- .../declarations/JavaParserTypeParameter.java | 2 +- .../JavaParserTypeVariableDeclaration.java | 2 +- .../JavassistClassDeclaration.java | 2 +- .../JavassistEnumDeclaration.java | 2 +- .../JavassistInterfaceDeclaration.java | 2 +- .../JavassistMethodDeclaration.java | 2 +- .../javassistmodel/JavassistUtils.java | 2 +- .../ReflectionAnnotationDeclaration.java | 2 +- .../ReflectionClassDeclaration.java | 2 +- .../ReflectionEnumDeclaration.java | 2 +- .../ReflectionInterfaceDeclaration.java | 2 +- .../ReflectionMethodDeclaration.java | 2 +- .../ReflectionMethodResolutionLogic.java | 2 +- .../symbolsolver/resolution/SymbolSolver.java | 2 +- .../resolution/naming/NameLogic.java | 2 +- .../javaparser/symbolsolver/Issue232Test.java | 2 +- .../symbolsolver/resolution/ContextTest.java | 2 +- .../MethodsResolutionWithJavassistTest.java | 2 +- ...rfaceDeclarationContextResolutionTest.java | 2 +- .../CompilationUnitContextResolutionTest.java | 2 +- .../EnumDeclarationContextResolutionTest.java | 2 +- .../LambdaExprContextResolutionTest.java | 2 +- .../MethodCallExprContextResolutionTest.java | 2 +- .../contexts/MethodContextResolutionTest.java | 2 +- 65 files changed, 269 insertions(+), 202 deletions(-) create mode 100755 javaparser-core/src/main/java/com/github/javaparser/ast/type/ConvertibleToUsage.java rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core => javaparser-core/src/main/java/com/github/javaparser}/resolution/Context.java (98%) diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt b/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt index 8a9fcbee58..425e902f35 100644 --- a/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt @@ -1 +1,4 @@ -0 problems in 0 files \ No newline at end of file +com/github/javaparser/symbolsolver/Issue232Test.java +(line 25,col 66) Parse error. Found "<<", expected one of ";" "@" "\u001a" "abstract" "class" "default" "enum" "final" "import" "interface" "module" "native" "open" "private" "protected" "public" "record" "static" "strictfp" "synchronized" "transient" "transitive" "volatile" + +1 problems in 1 files \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java index 2a6267e94a..0f6439cb10 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java @@ -33,7 +33,9 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ArrayTypeMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedArrayType; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.utils.Pair; import java.util.ArrayList; @@ -312,4 +314,9 @@ public Type getElementType() { public int getArrayLevel() { return 1 + this.getComponentType().getArrayLevel(); } + + @Override + public ResolvedType convertToUsage(Context context) { + return new ResolvedArrayType(getComponentType().convertToUsage(context)); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java index 5cfbbac5b9..7e7fe5b7c0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -37,14 +37,25 @@ import com.github.javaparser.metamodel.ClassOrInterfaceTypeMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.UnsolvedSymbolException; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.resolution.types.ResolvedTypeVariable; import java.util.Optional; import java.util.function.Consumer; +import java.util.stream.Collectors; import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; +import java.util.Collections; +import java.util.List; + /** * A class or an interface type. *
{@code Object} @@ -320,4 +331,30 @@ public ResolvedType resolve() { public Optional toClassOrInterfaceType() { return Optional.of(this); } + + /** + * Convert a {@link ClassOrInterfaceType} into a {@link ResolvedType}. + * + * @param classOrInterfaceType The class of interface type to be converted. + * @param context The current context. + * + * @return The type resolved. + */ + @Override + public ResolvedType convertToUsage(Context context) { + String name = getNameWithScope(); + SymbolReference ref = context.solveType(name); + if (!ref.isSolved()) { + throw new UnsolvedSymbolException(name); + } + ResolvedTypeDeclaration typeDeclaration = ref.getCorrespondingDeclaration(); + List typeParameters = Collections.emptyList(); + if (getTypeArguments().isPresent()) { + typeParameters = getTypeArguments().get().stream().map((pt) -> pt.convertToUsage(context)).collect(Collectors.toList()); + } + if (typeDeclaration.isTypeParameter()) { + return new ResolvedTypeVariable(typeDeclaration.asTypeParameter()); + } + return new ReferenceTypeImpl((ResolvedReferenceTypeDeclaration) typeDeclaration, typeParameters); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ConvertibleToUsage.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ConvertibleToUsage.java new file mode 100755 index 0000000000..97f4889137 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ConvertibleToUsage.java @@ -0,0 +1,13 @@ +package com.github.javaparser.ast.type; + +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.types.ResolvedType; + +/** + * Convert a {@link Type} into a {@link ResolvedType}. + * + */ +public interface ConvertibleToUsage { + + ResolvedType convertToUsage(Context context); +} 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 index fb0347a990..c17dc2df93 100644 --- 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 @@ -34,7 +34,10 @@ import com.github.javaparser.metamodel.IntersectionTypeMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.NonEmptyProperty; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedIntersectionType; +import com.github.javaparser.resolution.types.ResolvedType; + import java.util.Optional; import java.util.function.Consumer; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -183,4 +186,9 @@ public ResolvedIntersectionType resolve() { public Optional toIntersectionType() { return Optional.of(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + throw new UnsupportedOperationException(getClass().getCanonicalName()); + } } 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 index 270c60b9e0..ee1f0fa709 100644 --- 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 @@ -33,7 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.PrimitiveTypeMetaModel; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; +import com.github.javaparser.resolution.types.ResolvedType; + import java.util.HashMap; import java.util.Optional; import java.util.function.Consumer; @@ -234,4 +237,9 @@ public ResolvedPrimitiveType resolve() { public Optional toPrimitiveType() { return Optional.of(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + return ResolvedPrimitiveType.byName(getType().name()); + } } 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 index 34b0c31e00..ce42d5961d 100644 --- 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 @@ -44,7 +44,7 @@ * * @author Julio Vilmar Gesser */ -public abstract class Type extends Node implements Resolvable { +public abstract class Type extends Node implements Resolvable, ConvertibleToUsage { private NodeList annotations; 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 index c762f2ccee..ab8e9cdc02 100644 --- 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 @@ -35,6 +35,8 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.TypeParameterMetaModel; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import java.util.Optional; import java.util.function.Consumer; @@ -240,4 +242,9 @@ public ResolvedTypeVariable resolve() { public Optional toTypeParameter() { return Optional.of(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + throw new UnsupportedOperationException(getClass().getCanonicalName()); + } } 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 index 08751dd11d..8428a67d3a 100644 --- 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 @@ -34,12 +34,18 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.NonEmptyProperty; import com.github.javaparser.metamodel.UnionTypeMetaModel; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedUnionType; import java.util.Optional; import java.util.function.Consumer; +import java.util.stream.Collectors; + import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; +import java.util.List; + /** *

The union type

* Represents a set of types. A given value of this type has to be assignable to at least one of the element types. @@ -192,4 +198,12 @@ public ResolvedUnionType resolve() { public Optional toUnionType() { return Optional.of(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + List resolvedElements = getElements().stream() + .map(el -> el.convertToUsage(context)) + .collect(Collectors.toList()); + return new ResolvedUnionType(resolvedElements); + } } 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 index f5ec5dacd0..3a5554affd 100644 --- 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 @@ -31,6 +31,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.UnknownTypeMetaModel; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import java.util.Optional; @@ -134,4 +135,17 @@ public Optional toUnknownType() { public boolean isPhantom() { return true; } + + /** + * A {@link UnknownType} cannot be convertible to {@link ResolvedType}. + * + * @param type The type to be converted. + * @param context The current context. + * + * @return The type resolved. + */ + @Override + public ResolvedType convertToUsage(Context context) { + throw new IllegalArgumentException("Inferred lambda parameter type"); + } } 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 index e05f48d7dc..184c59bad1 100644 --- 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 @@ -25,13 +25,26 @@ import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.ForEachStmt; 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.VarTypeMetaModel; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; +import com.github.javaparser.resolution.types.ResolvedArrayType; +import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; + +import java.util.List; import java.util.Optional; import java.util.function.Consumer; @@ -44,6 +57,8 @@ * */ public class VarType extends Type { + + private static final String JAVA_LANG_OBJECT = Object.class.getCanonicalName(); @AllFieldsConstructor public VarType() { @@ -121,4 +136,58 @@ public Optional toVarType() { public void ifVarType(Consumer action) { action.accept(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + Node parent = getParentNode().get(); + if (!(parent instanceof VariableDeclarator)) { + throw new IllegalStateException("Trying to resolve a `var` which is not in a variable declaration."); + } + final VariableDeclarator variableDeclarator = (VariableDeclarator) parent; + Optional initializer = variableDeclarator.getInitializer(); + if (!initializer.isPresent()) { + // When a `var` type decl has no initializer it may be part of a + // for-each statement (e.g. `for(var i : expr)`). + Optional forEachStmt = forEachStmtWithVariableDeclarator(variableDeclarator); + if (forEachStmt.isPresent()) { + Expression iterable = forEachStmt.get().getIterable(); + ResolvedType iterType = iterable.calculateResolvedType(); + if (iterType instanceof ResolvedArrayType) { + // The type of a variable in a for-each loop with an array + // is the component type of the array. + return ((ResolvedArrayType)iterType).getComponentType(); + } + if (iterType.isReferenceType()) { + // The type of a variable in a for-each loop with an + // Iterable with parameter type + List parametersType = iterType.asReferenceType().typeParametersMap().getTypes(); + if (parametersType.isEmpty()) { + Optional oObjectDeclaration = context.solveType(JAVA_LANG_OBJECT) + .getDeclaration(); + return oObjectDeclaration + .map(decl -> ReferenceTypeImpl.undeterminedParameters(decl.asReferenceType())) + .orElseThrow(() -> new UnsupportedOperationException()); + } + return parametersType.get(0); + } + } + } + return initializer + .map(Expression::calculateResolvedType) + .orElseThrow(() -> new IllegalStateException("Cannot resolve `var` which has no initializer.")); + } + + private Optional forEachStmtWithVariableDeclarator( + VariableDeclarator variableDeclarator) { + Optional node = variableDeclarator.getParentNode(); + if (!node.isPresent() || !(node.get() instanceof VariableDeclarationExpr)) { + return Optional.empty(); + } + node = node.get().getParentNode(); + if (!node.isPresent() || !(node.get() instanceof ForEachStmt)) { + return Optional.empty(); + } else { + return Optional.of((ForEachStmt)node.get()); + } + } } 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 index ebf1e5ec59..e90693c8a8 100644 --- 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 @@ -32,6 +32,8 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.VoidTypeMetaModel; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import java.util.Optional; import java.util.function.Consumer; @@ -126,4 +128,9 @@ public ResolvedVoidType resolve() { public Optional toVoidType() { return Optional.of(this); } + + @Override + public ResolvedType convertToUsage(Context context) { + return ResolvedVoidType.INSTANCE; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java index f2bb11fc3e..8a3b4a2703 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java @@ -34,6 +34,8 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.metamodel.WildcardTypeMetaModel; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; import java.util.Optional; import java.util.function.Consumer; @@ -254,4 +256,26 @@ public ResolvedWildcard resolve() { public Optional toWildcardType() { return Optional.of(this); } + + /** + * Convert a {@link WildcardType} into a {@link ResolvedType}. + * + * @param wildcardType The wildcard type to be converted. + * @param context The current context. + * + * @return The type resolved. + */ + @Override + public ResolvedType convertToUsage(Context context) { + if (getExtendedType().isPresent() && !getSuperType().isPresent()) { + return ResolvedWildcard.extendsBound(getExtendedType().get().convertToUsage(context)); // removed (ReferenceTypeImpl) + } + if (!getExtendedType().isPresent() && getSuperType().isPresent()) { + return ResolvedWildcard.superBound(getSuperType().get().convertToUsage(context)); // removed (ReferenceTypeImpl) + } + if (!getExtendedType().isPresent() && !getSuperType().isPresent()) { + return ResolvedWildcard.UNBOUNDED; + } + throw new UnsupportedOperationException(toString()); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Context.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/Context.java index 817cdfe627..6c24701b45 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Context.java @@ -19,19 +19,17 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.core.resolution; +package com.github.javaparser.resolution; 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.PatternExpr; import com.github.javaparser.quality.Nullable; -import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/MethodUsageResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/MethodUsageResolutionCapability.java index c3ce36dbd0..c2b61a2887 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/MethodUsageResolutionCapability.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/MethodUsageResolutionCapability.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.core.resolution; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/TypeVariableResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/TypeVariableResolutionCapability.java index a7dab94506..530cda94a2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/TypeVariableResolutionCapability.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/TypeVariableResolutionCapability.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.core.resolution; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java index c96a784284..279b65d5e8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.declarations.common; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -28,7 +29,6 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 855a62eb1c..6fa570c4c2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -30,6 +30,7 @@ import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.ast.stmt.ForEachStmt; import com.github.javaparser.ast.type.*; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; @@ -40,7 +41,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; @@ -78,8 +78,6 @@ public class JavaParserFacade { private static final String JAVA_LANG_STRING = String.class.getCanonicalName(); - private static final String JAVA_LANG_OBJECT = Object.class.getCanonicalName(); - /** * Note that the addition of the modifier {@code synchronized} is specific and directly in response to issue #2668. *
This MUST NOT be misinterpreted as a signal that JavaParser is safe to use within a multi-threaded environment. @@ -615,10 +613,6 @@ protected Node findContainingTypeDeclOrObjectCreationExpr(Node node, String clas } } - public ResolvedType convertToUsageVariableType(VariableDeclarator var) { - return get(typeSolver).convertToUsage(var.getType(), var); - } - /** * Convert a {@link Type} into the corresponding {@link ResolvedType}. * @@ -631,25 +625,7 @@ protected ResolvedType convertToUsage(Type type, Context context) { if (context == null) { throw new NullPointerException("Context should not be null"); } - if (type.isUnknownType()) { - throw new IllegalArgumentException("Inferred lambda parameter type"); - } else if (type.isClassOrInterfaceType()) { - return convertClassOrInterfaceTypeToUsage(type.asClassOrInterfaceType(), context); - } else if (type.isPrimitiveType()) { - return ResolvedPrimitiveType.byName(type.asPrimitiveType().getType().name()); - } else if (type.isWildcardType()) { - return convertWildcardTypeToUsage(type.asWildcardType(), context); - } else if (type.isVoidType()) { - return ResolvedVoidType.INSTANCE; - } else if (type.isArrayType()) { - return convertArrayTypeToUsage(type.asArrayType(), context); - } else if (type.isUnionType()) { - return convertUnionTypeToUsage(type.asUnionType(), context); - } else if (type.isVarType()) { - return convertVarTypeToUsage(type.asVarType(), context); - } else { - throw new UnsupportedOperationException(type.getClass().getCanonicalName()); - } + return type.convertToUsage(context); } /** @@ -675,126 +651,6 @@ public ResolvedType convertToUsage(Type type) { return convertToUsage(type, type); } - /** - * Convert a {@link ClassOrInterfaceType} into a {@link ResolvedType}. - * - * @param classOrInterfaceType The class of interface type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - protected ResolvedType convertClassOrInterfaceTypeToUsage(ClassOrInterfaceType classOrInterfaceType, Context context) { - String name = classOrInterfaceType.getNameWithScope(); - SymbolReference ref = context.solveType(name); - if (!ref.isSolved()) { - throw new UnsolvedSymbolException(name); - } - ResolvedTypeDeclaration typeDeclaration = ref.getCorrespondingDeclaration(); - List typeParameters = Collections.emptyList(); - if (classOrInterfaceType.getTypeArguments().isPresent()) { - typeParameters = classOrInterfaceType.getTypeArguments().get().stream().map((pt) -> convertToUsage(pt, context)).collect(Collectors.toList()); - } - if (typeDeclaration.isTypeParameter()) { - return new ResolvedTypeVariable(typeDeclaration.asTypeParameter()); - } else { - return new ReferenceTypeImpl((ResolvedReferenceTypeDeclaration) typeDeclaration, typeParameters); - } - } - - /** - * Convert a {@link WildcardType} into a {@link ResolvedType}. - * - * @param wildcardType The wildcard type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - protected ResolvedType convertWildcardTypeToUsage(WildcardType wildcardType, Context context) { - if (wildcardType.getExtendedType().isPresent() && !wildcardType.getSuperType().isPresent()) { - return ResolvedWildcard.extendsBound(convertToUsage(wildcardType.getExtendedType().get(), context)); // removed (ReferenceTypeImpl) - } else if (!wildcardType.getExtendedType().isPresent() && wildcardType.getSuperType().isPresent()) { - return ResolvedWildcard.superBound(convertToUsage(wildcardType.getSuperType().get(), context)); // removed (ReferenceTypeImpl) - } else if (!wildcardType.getExtendedType().isPresent() && !wildcardType.getSuperType().isPresent()) { - return ResolvedWildcard.UNBOUNDED; - } else { - throw new UnsupportedOperationException(wildcardType.toString()); - } - } - - /** - * Convert a {@link ArrayType} into a {@link ResolvedType}. - * - * @param arrayType The array type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - protected ResolvedType convertArrayTypeToUsage(ArrayType arrayType, Context context) { - return new ResolvedArrayType(convertToUsage(arrayType.getComponentType(), context)); - } - - /** - * Convert a {@link UnionType} into a {@link ResolvedType}. - * - * @param unionType The union type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - protected ResolvedType convertUnionTypeToUsage(UnionType unionType, Context context) { - List resolvedElements = unionType.getElements().stream() - .map(el -> convertToUsage(el, context)) - .collect(Collectors.toList()); - return new ResolvedUnionType(resolvedElements); - } - - /** - * Convert a {@link VarType} into a {@link ResolvedType}. - * - * @param varType The var type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - protected ResolvedType convertVarTypeToUsage(VarType varType, Context context) { - Node parent = varType.getParentNode().get(); - if (!(parent instanceof VariableDeclarator)) { - throw new IllegalStateException("Trying to resolve a `var` which is not in a variable declaration."); - } - final VariableDeclarator variableDeclarator = (VariableDeclarator) parent; - Optional initializer = variableDeclarator.getInitializer(); - if (!initializer.isPresent()) { - // When a `var` type decl has no initializer it may be part of a - // for-each statement (e.g. `for(var i : expr)`). - Optional forEachStmt = forEachStmtWithVariableDeclarator(variableDeclarator); - if (forEachStmt.isPresent()) { - Expression iterable = forEachStmt.get().getIterable(); - ResolvedType iterType = iterable.calculateResolvedType(); - if (iterType instanceof ResolvedArrayType) { - // The type of a variable in a for-each loop with an array - // is the component type of the array. - return ((ResolvedArrayType)iterType).getComponentType(); - } - if (iterType.isReferenceType()) { - // The type of a variable in a for-each loop with an - // Iterable with parameter type - List parametersType = iterType.asReferenceType().typeParametersMap().getTypes(); - if (parametersType.isEmpty()) { - Optional oObjectDeclaration = context.solveType(JAVA_LANG_OBJECT) - .getDeclaration(); - return oObjectDeclaration - .map(decl -> ReferenceTypeImpl.undeterminedParameters(decl.asReferenceType())) - .orElseThrow(() -> new UnsupportedOperationException()); - } - return parametersType.get(0); - } - } - } - return initializer - .map(Expression::calculateResolvedType) - .orElseThrow(() -> new IllegalStateException("Cannot resolve `var` which has no initializer.")); - } - private Optional forEachStmtWithVariableDeclarator( VariableDeclarator variableDeclarator) { Optional node = variableDeclarator.getParentNode(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java index 7a640d5780..792f3bde63 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java @@ -31,8 +31,8 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.*; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index bd935219d7..95dafaba9e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.UnknownType; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -45,7 +46,6 @@ import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; @@ -83,9 +83,9 @@ public TypeExtractor(TypeSolver typeSolver, JavaParserFacade facade) { @Override public ResolvedType visit(VariableDeclarator node, Boolean solveLambdas) { if (demandParentNode(node) instanceof FieldDeclaration) { - return facade.convertToUsageVariableType(node); + return facade.convertToUsage(node.getType()); } else if (demandParentNode(node) instanceof VariableDeclarationExpr) { - return facade.convertToUsageVariableType(node); + return facade.convertToUsage(node.getType()); } throw new UnsupportedOperationException(demandParentNode(node).getClass().getCanonicalName()); } @@ -450,7 +450,7 @@ public ResolvedType visit(VariableDeclarationExpr node, Boolean solveLambdas) { if (node.getVariables().size() != 1) { throw new UnsupportedOperationException(); } - return facade.convertToUsageVariableType(node.getVariables().get(0)); + return facade.convertToUsage(node.getVariables().get(0).getType()); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 077ac010d4..ceba19736c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -36,7 +37,6 @@ import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java index dd435cb7c5..2819380af7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BinaryExprContext.java @@ -5,7 +5,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.core.resolution.Context; +import com.github.javaparser.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java index aa6f503468..6745ad450c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/BlockStmtContext.java @@ -28,9 +28,9 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ContextHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ContextHelper.java index 86360c1ca7..64b110ccba 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ContextHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ContextHelper.java @@ -21,10 +21,10 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java index baca5ce1a8..b337e71da7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/EnclosedExprContext.java @@ -6,7 +6,7 @@ import com.github.javaparser.ast.expr.EnclosedExpr; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.core.resolution.Context; +import com.github.javaparser.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java index b44c983474..50efcc4267 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/IfStatementContext.java @@ -5,7 +5,7 @@ import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.stmt.IfStmt; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.core.resolution.Context; +import com.github.javaparser.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java index 272fb49434..89da5134d2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/InstanceOfExprContext.java @@ -3,9 +3,9 @@ import com.github.javaparser.ast.expr.InstanceOfExpr; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 8646ec55ed..29cc8c0071 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -33,11 +33,11 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 0b329f0090..3afe567f44 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -122,7 +122,7 @@ public Optional solveSymbolAsValue(String name) { } } else if (parentNode instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) parentNode; - ResolvedType t = JavaParserFacade.get(typeSolver).convertToUsageVariableType(variableDeclarator); + ResolvedType t = JavaParserFacade.get(typeSolver).convertToUsage(variableDeclarator.getType()); Optional functionalMethod = FunctionalInterfaceLogic.getFunctionalMethod(t); if (functionalMethod.isPresent()) { ResolvedType lambdaType = functionalMethod.get().getParamType(index); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 4d3887d23c..903c242d93 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 86f738c08e..56d5f85436 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -139,7 +139,7 @@ private List inferArgumentTypes() { } } else if (demandParentNode(wrappedNode) instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) demandParentNode(wrappedNode); - ResolvedType t = JavaParserFacade.get(typeSolver).convertToUsageVariableType(variableDeclarator); + ResolvedType t = JavaParserFacade.get(typeSolver).convertToUsage(variableDeclarator.getType()); Optional functionalMethod = FunctionalInterfaceLogic.getFunctionalMethod(t); if (functionalMethod.isPresent()) { List resolvedTypes = new ArrayList<>(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index 44809fd6d1..523f012894 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -29,12 +29,12 @@ import com.github.javaparser.ast.nodeTypes.NodeWithStatements; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java index 1f0289cc56..8a13032cb1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/UnaryExprContext.java @@ -2,8 +2,8 @@ import com.github.javaparser.ast.expr.UnaryExpr; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.ast.expr.PatternExpr; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java index ebb489d421..5bf752c135 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclarationExprContext.java @@ -27,9 +27,9 @@ import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java index 6b57f46ca8..d63f4610b5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/VariableDeclaratorContext.java @@ -26,7 +26,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.core.resolution.Context; +import com.github.javaparser.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java index 7a2f67a9ca..02a911fbf5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java index 2aa36597ce..e34916753a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclaration.java @@ -35,6 +35,7 @@ import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -47,7 +48,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java index c3b1546a16..461834714e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclaration.java @@ -35,6 +35,7 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -50,7 +51,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 92cdb4a610..9292724885 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -37,6 +37,7 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -58,7 +59,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 0ef9eeb0c1..602c4330a3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -35,6 +35,7 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -51,7 +52,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java index fb1cc7c510..0841a5d35b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 02ea4fb2c9..1a5087e62e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -34,6 +34,7 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 5e5dc3726c..3739de0f08 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -36,7 +37,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index dd3660511a..eca5973762 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index 369919d05a..d009ae2574 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -29,7 +30,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index f60154edf5..5343f78f59 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -30,7 +31,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java index 21aac6fd15..a25a89ec78 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index 88d1b7498b..b93e8e6eb2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -29,6 +29,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -45,7 +46,6 @@ import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index 31c7aea5cc..d4bb86f81b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -32,6 +32,7 @@ import java.util.stream.Stream; import com.github.javaparser.ast.body.AnnotationDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index aeaec13263..3861b2318b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 117082abe4..9cf3d3d5d4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; @@ -29,7 +30,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index b513ffa1f1..23ede03be3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; @@ -33,7 +34,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java index 14c41c8dc4..2c2002259c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -30,7 +31,6 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index 024657ebe7..f6bf36a997 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -31,7 +32,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import java.lang.reflect.Method; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 53daf1e907..3cb72af956 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -35,7 +36,6 @@ import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java index 66ca2c1572..37659a03df 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/naming/NameLogic.java @@ -69,11 +69,11 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; /** diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java index 991dc7ecd9..51df878768 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 4ad86e04e5..5fdf4aa1d3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -60,6 +60,7 @@ import com.github.javaparser.ast.stmt.IfStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; @@ -69,7 +70,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java index c9116134b8..9f7d8b867e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java @@ -27,8 +27,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index 7193f0f581..892ee7f861 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java index 39572a54c3..871ee88af4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/CompilationUnitContextResolutionTest.java @@ -24,6 +24,7 @@ import com.github.javaparser.ParseException; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -33,7 +34,6 @@ import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java index c363e9f844..78957ccb8b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java index d582f2ac81..8d3a79148e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java @@ -29,8 +29,8 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.model.Value; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index dcb73de9e0..46fd5c3486 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -42,6 +42,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -50,7 +51,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java index ab80a8a42e..d723ef272c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.core.resolution.Context; import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; From fc8303ac59d329df319f844cbf4eb29b9c801cea Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sat, 3 Dec 2022 22:52:43 +0100 Subject: [PATCH 103/280] Fix: #2517 Modifying some nodes with the lexicalPreservation enabled throws an exception --- .../lexicalpreservation/Issue2517Test.java | 70 +++++++++++++++++++ .../DifferenceElementCalculator.java | 36 ++++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java new file mode 100755 index 0000000000..01b3e03998 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java @@ -0,0 +1,70 @@ +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; + +import java.util.StringJoiner; + +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.javadoc.description.JavadocDescription; + +public class Issue2517Test extends AbstractLexicalPreservingTest { + + @Test + public void test() { + + considerCode("public class A {\n" + + " public A(String a , String b) {\n" + + " }\n" + + " public static A m() {\n" + + " return new A(\"a\",\"b\");\n" + + " }\n" + + "}"); + + String expected = + "public class A {\n" + + " public A(String a , String b) {\n" + + " }\n" + + " public static A m() {\n" + + " return new A(\"b\", \"a\");\n" + + " }\n" + + "}"; + + ObjectCreationExpr cd = cu.findFirst(ObjectCreationExpr.class).get(); + NodeList args = cd.getArguments(); + Expression a1 = args.get(0); + Expression a2 = args.get(1); + NodeList newArgs = new NodeList<>(a2, a1); + cd.setArguments(newArgs); + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index a06369c779..56898f377c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -24,9 +24,11 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; import com.github.javaparser.printer.concretesyntaxmodel.*; +import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CalculatedSyntaxModel; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -171,21 +173,45 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS int originalIndex = 0; int afterIndex = 0; int commonChildrenIndex = 0; + // The algorithm is based on common child elements. + // It first analyzes the elements preceding this child. + // Then it keeps the common element and continues the analysis between the element + // following this child and the common element in the list. while (commonChildrenIndex < commonChildren.size()) { ChildPositionInfo child = commonChildren.get(commonChildrenIndex++); // search the position of the node "child" in the original list of cms element int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); // search the position of the node "child" in the modified list of cms element int posOfNextChildInAfter = childrenInAfter.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); + // Imagine that the common elements has been moved, for example in the case where the parameters of a method are reversed + // In this case the afterIndex will be greater than the position of the child in + // the list + // For example : if {@code new Foo(a, b)} become {@code new Foo(b, a)} + // Nota: in this example there is 3 child elements Foo, 'a' and 'b', others are tokens + // In the orginal list the child element 'a' is at the position 5 and the + // element 'b' is at the position 8 + // After reverting the list of parameters the child element 'a' is at the + // position 8 and the element 'b' is at the position 5 + // When we deal with element 'b', it is in 5th position in the list after the + // modification but the previous position in the list was that of element 'a'. if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) { - elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter))); + // defines the sublist of elements located before the common element + CalculatedSyntaxModel originalSub = originalIndex < posOfNextChildInOriginal ? original.sub(originalIndex, posOfNextChildInOriginal) : new CalculatedSyntaxModel(Collections.EMPTY_LIST); + CalculatedSyntaxModel afterSub = afterIndex < posOfNextChildInAfter ? after.sub(afterIndex, posOfNextChildInAfter) : new CalculatedSyntaxModel(Collections.EMPTY_LIST); + elements.addAll(calculateImpl(originalSub, afterSub)); } - elements.add(new Kept(new CsmChild(child.node))); - originalIndex = posOfNextChildInOriginal + 1; - afterIndex = posOfNextChildInAfter + 1; + if (afterIndex <= posOfNextChildInAfter) { + elements.add(new Kept(new CsmChild(child.node))); + } else { + elements.add(new Removed(new CsmChild(child.node))); + } + originalIndex = originalIndex <= posOfNextChildInOriginal ? posOfNextChildInOriginal + 1 : originalIndex; + afterIndex = afterIndex <= posOfNextChildInAfter ? posOfNextChildInAfter + 1 : afterIndex; } if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) { - elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size()))); + CalculatedSyntaxModel originalSub = originalIndex < original.elements.size() ? original.sub(originalIndex, original.elements.size()) : new CalculatedSyntaxModel(Collections.EMPTY_LIST); + CalculatedSyntaxModel afterSub = afterIndex < after.elements.size() ? after.sub(afterIndex, after.elements.size()) : new CalculatedSyntaxModel(Collections.EMPTY_LIST); + elements.addAll(calculateImpl(originalSub, afterSub)); } return elements; } From 572c1365ac32f06eb520532dedf6b000ea62f71a Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 5 Dec 2022 09:18:45 +0100 Subject: [PATCH 104/280] Fix: #3773 Replacing nodes causes error in lexical preserving printer if some nodes are identical --- .../DifferenceElementCalculator.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java index 56898f377c..b1517b41c7 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java @@ -173,6 +173,8 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS int originalIndex = 0; int afterIndex = 0; int commonChildrenIndex = 0; + int posOfNextChildInOriginal = -1; // undefined + int posOfNextChildInAfter = -1; // undefined // The algorithm is based on common child elements. // It first analyzes the elements preceding this child. // Then it keeps the common element and continues the analysis between the element @@ -180,9 +182,19 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS while (commonChildrenIndex < commonChildren.size()) { ChildPositionInfo child = commonChildren.get(commonChildrenIndex++); // search the position of the node "child" in the original list of cms element - int posOfNextChildInOriginal = childrenInOriginal.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); + final int currentPosOfNextChildInOriginal = posOfNextChildInOriginal; + final int currentPosOfNextChildInAfter = posOfNextChildInAfter; + posOfNextChildInOriginal = childrenInOriginal.stream() + .filter(i -> i.equals(child)) + .map(i -> i.position) + .filter(position -> position > currentPosOfNextChildInOriginal) + .findFirst().orElse(posOfNextChildInOriginal); // search the position of the node "child" in the modified list of cms element - int posOfNextChildInAfter = childrenInAfter.stream().filter(i -> i.equals(child)).map(i -> i.position).findFirst().get(); + posOfNextChildInAfter = childrenInAfter.stream() + .filter(i -> i.equals(child)) + .map(i -> i.position) + .filter(position -> position > currentPosOfNextChildInAfter) + .findFirst().orElse(posOfNextChildInAfter); // Imagine that the common elements has been moved, for example in the case where the parameters of a method are reversed // In this case the afterIndex will be greater than the position of the child in // the list @@ -201,8 +213,11 @@ static List calculate(LexicalDifferenceCalculator.CalculatedS elements.addAll(calculateImpl(originalSub, afterSub)); } if (afterIndex <= posOfNextChildInAfter) { + // we need to keep the current common node elements.add(new Kept(new CsmChild(child.node))); } else { + // In this case the current node was not found in the list after change + // so we need to remove it. elements.add(new Removed(new CsmChild(child.node))); } originalIndex = originalIndex <= posOfNextChildInOriginal ? posOfNextChildInOriginal + 1 : originalIndex; From d8478a14ff769b4fb95f4a49a145ffe47c4ca0da Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 5 Dec 2022 09:39:10 +0100 Subject: [PATCH 105/280] Fix: #3773 Adding a unit test --- .../lexicalpreservation/Issue3773Test.java | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java new file mode 100755 index 0000000000..7983d97c69 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java @@ -0,0 +1,163 @@ + +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2019 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.BinaryExpr.Operator; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.visitor.ModifierVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.printer.lexicalpreservation.AATest.FunctionVisitor; + +class Issue3773Test extends AbstractLexicalPreservingTest { + + @Test + void test3773() { + considerCode( + "class A {\r\n" + + " public String output = \"Contents of \";\r\n" + + " \r\n" + + " public String debug(String output) {\r\n" + + "\r\n" + + " Log.d(\"Debug\", output1); \r\n" + + " Log.d(\"Debug\", output2); \r\n" + + " Log.d(\"Debug\", output3); \r\n" + + " Log.d(\"Debug\", output4); \r\n" + + " \r\n" + + " output = \"1\";\r\n" + + " Log.d(\"Debug\", output1);\r\n" + + " \r\n" + + " output = \"2\";\r\n" + + " Log.d(\"Debug\", output2);\r\n" + + " \r\n" + + " output = \"3\";\r\n" + + " Log.d(\"Debug\", output3);\r\n" + + " \r\n" + + " Log.d(\"Debug\", \"\"); \r\n" + + " Log.d(\"Debug\", \"\"); \r\n" + + " Log.d(\"Debug\", \"3\"); \r\n" + + " Log.d(\"Debug\", \"4\"); \r\n" + + " \r\n" + + " return \"\";\r\n" + + " }\r\n" + + "}"); + String expected = + "class A {\r\n" + + " public String output = \"Contents of \";\r\n" + + " \r\n" + + " public String debug(String output) {\r\n" + + "\r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output1); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output2); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output3); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output4); \r\n" + + " \r\n" + + " output = \"1\";\r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output1);\r\n" + + " \r\n" + + " output = \"2\";\r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output2);\r\n" + + " \r\n" + + " output = \"3\";\r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", output3);\r\n" + + " \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", \"\"); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", \"\"); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", \"3\"); \r\n" + + " if (Log.Level >= 3)\r\n" + + " Log.d(\"Debug\", \"4\"); \r\n" + + " \r\n" + + " return \"\";\r\n" + + " }\r\n" + + "}"; + + // here the logic + FunctionVisitor funVisitor = new FunctionVisitor(); + funVisitor.visit(cu, null); + + + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + + public class FunctionVisitor extends ModifierVisitor { + + @Override + public Visitable visit(ExpressionStmt node, Object arg) { + List mces = node.getChildNodesByType(MethodCallExpr.class); + if (mces.isEmpty()) + return node; + MethodCallExpr mce = mces.get(0); + if (mce.getScope().isPresent() && mce.getName() != null) { + String nodeScope = mce.getScope().get().toString(); + String nodeName = mce.getName().toString(); + if (nodeScope.equals("Log")) { + if (nodeName.equals("d")) { + IfStmt ifStmt = makeIfStmt(node); + return ifStmt; + } + } + } + return node; + } + } + + private IfStmt makeIfStmt(Statement thenStmt) { + Expression left = new FieldAccessExpr(new NameExpr("Log"), "Level"); + Expression right = new IntegerLiteralExpr("3"); + BinaryExpr condition = new BinaryExpr(left, right, Operator.GREATER_EQUALS); + IfStmt ifStmt = new IfStmt(condition, thenStmt, null); + return ifStmt; + } + +} From d5b3d9fe93fe44a465378267d77544106dcff805 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 5 Dec 2022 09:43:19 +0100 Subject: [PATCH 106/280] Fix: #3773 Adding a unit test - fix test case --- .../printer/lexicalpreservation/Issue3773Test.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java index 7983d97c69..41859b1d51 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java @@ -23,18 +23,11 @@ package com.github.javaparser.printer.lexicalpreservation; import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import org.junit.jupiter.api.Test; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.FieldAccessExpr; @@ -42,13 +35,11 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.BinaryExpr.Operator; -import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.IfStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.visitor.ModifierVisitor; import com.github.javaparser.ast.visitor.Visitable; -import com.github.javaparser.printer.lexicalpreservation.AATest.FunctionVisitor; class Issue3773Test extends AbstractLexicalPreservingTest { From e87fef819279f9215483ecf970be0fce37f83072 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 5 Dec 2022 11:33:29 +0100 Subject: [PATCH 107/280] Fix: #3681 LineComment alwaysing trimming content --- .../printer/PrettyPrintVisitorTest.java | 6 ++--- .../issue_samples/Issue412.java.expected.txt | 24 +++++++++---------- .../printer/DefaultPrettyPrinterVisitor.java | 5 +++- .../printer/PrettyPrintVisitor.java | 5 +++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java index 4a6f060b6e..a1af7fb0ed 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java @@ -381,7 +381,7 @@ void singlelineCommentGetsFormatted() { assertEqualsStringIgnoringEol("public class X {\n" + "\n" + - " // line1\n" + + " // line1\n" + " void abc() {\n" + " }\n" + "}\n", cu.toString()); @@ -402,8 +402,8 @@ void blockcommentGetsNoFormatting() { assertEqualsStringIgnoringEol("class A {\n" + "\n" + " public void helloWorld(String greeting, String name) {\n" + - " // sdfsdfsdf\n" + - " // sdfds\n" + + " //sdfsdfsdf\n" + + " //sdfds\n" + " /*\n" + " dgfdgfdgfdgfdgfd\n" + " */\n" + diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/issue_samples/Issue412.java.expected.txt b/javaparser-core-testing/src/test/resources/com/github/javaparser/issue_samples/Issue412.java.expected.txt index a13577a5a8..9bc4779730 100644 --- a/javaparser-core-testing/src/test/resources/com/github/javaparser/issue_samples/Issue412.java.expected.txt +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/issue_samples/Issue412.java.expected.txt @@ -6,30 +6,30 @@ */ package /* a */ /* b */ -// c -// d +//c +//d com.pany/*alma*/ /*körte*/ -// lófasz -// jóska +//lófasz +//jóska .experiment; -// z -// x +//z +//x /*y*/ /*w*/ /*aa*/ /*bb*/ -// cc -// dd +//cc +//dd import com.github.javaparser.JavaParser; public class Main { public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { - // try (FileInputStream fisTargetFile = new FileInputStream(new File(FILENAME))) { - // final String content = IOUtils.toString(fisTargetFile, "UTF-8"); - // System.out.println(content); - // } + // try (FileInputStream fisTargetFile = new FileInputStream(new File(FILENAME))) { + // final String content = IOUtils.toString(fisTargetFile, "UTF-8"); + // System.out.println(content); + // } } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java index 078077d9ed..3e1b36e139 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java @@ -39,6 +39,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition; @@ -50,6 +51,8 @@ * Outputs the AST as formatted Java source code. */ public class DefaultPrettyPrinterVisitor implements VoidVisitor { + + private static Pattern RTRIM = Pattern.compile("\\s+$"); protected final PrinterConfiguration configuration; @@ -1609,7 +1612,7 @@ public void visit(final LineComment n, final Void arg) { if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) { return; } - printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("//").println(normalizeEolInTextBlock(RTRIM.matcher(n.getContent()).replaceAll(""), "")); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index 1c260aad81..441197ac66 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -37,6 +37,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; @@ -55,6 +56,8 @@ */ @Deprecated public class PrettyPrintVisitor implements VoidVisitor { + + private static Pattern RTRIM = Pattern.compile("\\s+$"); protected PrettyPrinterConfiguration configuration; @@ -1614,7 +1617,7 @@ public void visit(final LineComment n, final Void arg) { if (configuration.isIgnoreComments()) { return; } - printer.print("// ").println(normalizeEolInTextBlock(n.getContent(), "").trim()); + printer.print("//").println(normalizeEolInTextBlock(RTRIM.matcher(n.getContent()).replaceAll(""), "")); } @Override From 92a5a6d95d3ec6ddc6075157e4d09ebc0feb8227 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 5 Dec 2022 12:40:16 +0100 Subject: [PATCH 108/280] Fix comment in jbehave unit test --- .../com/github/javaparser/pretty_printing_scenarios.story | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javaparser-core-testing-bdd/src/test/resources/com/github/javaparser/pretty_printing_scenarios.story b/javaparser-core-testing-bdd/src/test/resources/com/github/javaparser/pretty_printing_scenarios.story index b9cb786c47..061344367d 100644 --- a/javaparser-core-testing-bdd/src/test/resources/com/github/javaparser/pretty_printing_scenarios.story +++ b/javaparser-core-testing-bdd/src/test/resources/com/github/javaparser/pretty_printing_scenarios.story @@ -48,8 +48,8 @@ Then it is printed as: class A { public void helloWorld(String greeting, String name) { - // sdfsdfsdf - // sdfds + //sdfsdfsdf + //sdfds /* dgfdgfdgfdgfdgfd */ From 3b6ee2e9f72d824eb11cc3e0afca8bed76b37df6 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 6 Dec 2022 14:05:14 +0100 Subject: [PATCH 109/280] Fix: #3195 Resolved methods in outer classes not inferred correcly --- .../contexts/MethodCallExprContext.java | 32 +++++++++++++++++-- .../MethodCallExprContextResolutionTest.java | 24 ++++++++++++++ .../src/test/resources/MethodCalls.java.txt | 7 ++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 903c242d93..90c6ce4b88 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -21,9 +21,11 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; @@ -358,6 +360,24 @@ private MethodUsage resolveMethodTypeParameters(MethodUsage methodUsage, List because of the assumption +// ResolvedType actualType = new ResolvedArrayType(actualParamTypes.get(actualParamTypes.size() - 1)); + ResolvedType actualType = actualParamTypes.get(actualParamTypes.size() - 1); + if (!expectedType.isAssignableBy(actualType)) { + throw new UnsupportedOperationException( + String.format("Unable to resolve the type typeParametersValues in a MethodUsage. Expected type: %s, Actual type: %s. Method Declaration: %s. MethodUsage: %s", + expectedType, + actualType, + methodUsage.getDeclaration(), + methodUsage)); + } + matchTypeParameters(expectedType, actualType, matchedTypeParameters); + return replaceTypeParameter(methodUsage, matchedTypeParameters); } else { return methodUsage; } @@ -372,12 +392,18 @@ private MethodUsage resolveMethodTypeParameters(MethodUsage methodUsage, List matchedTypeParameters) { + for (ResolvedTypeParameterDeclaration tp : matchedTypeParameters.keySet()) { + methodUsage = methodUsage.replaceTypeParameter(tp, matchedTypeParameters.get(tp)); + } + return methodUsage; + } + private void matchTypeParameters(ResolvedType expectedType, ResolvedType actualType, Map matchedTypeParameters) { if (expectedType.isTypeVariable()) { ResolvedType type = actualType; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index 46fd5c3486..2ffba9837e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -52,6 +52,7 @@ import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ClassLoaderTypeSolver; @@ -192,4 +193,27 @@ public void testResolveChainedCallOnReflectionType() throws Exception { assertEquals(0, errorCount, "Expected zero UnsolvedSymbolException s"); } + + @Test + void solveVariadicStaticGenericMethodCallCanInferFromArguments() { + ParserConfiguration config = new ParserConfiguration() + .setSymbolResolver(new JavaSymbolSolver(createTypeSolver())); + StaticJavaParser.setConfiguration(config); + MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", "variadicStaticGenericMethod"); + + ResolvedType resolvedType = methodCallExpr.calculateResolvedType(); + assertEquals("java.lang.String", resolvedType.describe()); + } + + // Related to issue #3195 + @Test + void solveVariadicStaticGenericMethodCallCanInferFromArguments2() { + ParserConfiguration config = new ParserConfiguration() + .setSymbolResolver(new JavaSymbolSolver(createTypeSolver())); + StaticJavaParser.setConfiguration(config); + MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", "asList"); + + ResolvedType resolvedType = methodCallExpr.calculateResolvedType(); + assertEquals("java.util.List", resolvedType.describe()); + } } diff --git a/javaparser-symbol-solver-testing/src/test/resources/MethodCalls.java.txt b/javaparser-symbol-solver-testing/src/test/resources/MethodCalls.java.txt index 534a144b29..714c54c931 100644 --- a/javaparser-symbol-solver-testing/src/test/resources/MethodCalls.java.txt +++ b/javaparser-symbol-solver-testing/src/test/resources/MethodCalls.java.txt @@ -1,4 +1,5 @@ import java.util.List; +import java.util.Arrays; import java.lang.Class; class MethodCalls { @@ -65,6 +66,8 @@ class MethodCalls { static T staticGenericMethod0() { return null; } static T staticGenericMethod1(T x) { return x; } + + static T variadicStaticGenericMethod(T... x) { return null; } static class GenericClass {} @@ -78,5 +81,9 @@ class MethodCalls { MethodCalls.staticGenericMethod1("Hello"); MethodCalls.variadicWithGenericArg(1, new GenericClass()); + + MethodCalls.variadicStaticGenericMethod("Hello1", "Hello2"); + + Arrays.asList("Hello1", "Hello2"); } } From 9360f0a87c6f932cec846a75e9d1ff2fdbc0aff2 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Thu, 8 Dec 2022 00:25:18 +0000 Subject: [PATCH 110/280] Fixed TypeSolver imports --- .../symbolsolver/resolution/typesolvers/TypeSolverBuilder.java | 2 +- .../resolution/typesolvers/TypeSolverBuilderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java index 35e94e03d8..6b175c87f7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilder.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import org.checkerframework.checker.nullness.qual.NonNull; import java.io.File; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java index 02a955ff85..055a84df0f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/typesolvers/TypeSolverBuilderTest.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.resolution.typesolvers; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; +import com.github.javaparser.resolution.TypeSolver; import org.junit.jupiter.api.Test; import java.io.File; From b7375c946214c0301dd83d9fcd98b3a8ca991296 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 14:48:15 +0100 Subject: [PATCH 111/280] Changing, in test classes, the initialization of the lexical preservation printer --- .../LineSeparatorProcessorTest.java | 10 +- .../github/javaparser/ast/NodeListTest.java | 15 +- .../ast/visitor/ModifierVisitorTest.java | 6 +- .../javaparser/issues/Issue3113Test.java | 3 +- .../AbstractLexicalPreservingTest.java | 6 + .../AnnotationSpaceTest.java | 10 +- .../lexicalpreservation/Issue1467Test.java | 8 +- .../lexicalpreservation/Issue1634Test.java | 5 +- .../lexicalpreservation/Issue1766Test.java | 22 +- .../lexicalpreservation/Issue1793Test.java | 9 +- .../lexicalpreservation/Issue2290Test.java | 10 +- .../lexicalpreservation/Issue2374Test.java | 5 +- .../lexicalpreservation/Issue2393Test.java | 6 +- .../lexicalpreservation/Issue2592Test.java | 13 +- .../lexicalpreservation/Issue2610Test.java | 6 +- .../lexicalpreservation/Issue2620Test.java | 9 +- .../lexicalpreservation/Issue2806Test.java | 9 +- .../lexicalpreservation/Issue3296Test.java | 6 +- .../lexicalpreservation/Issue3387Test.java | 7 +- .../lexicalpreservation/Issue3440Test.java | 1 - .../LexicalPreservingPrinterTest.java | 235 ++++++------------ .../TransformationsTest.java | 20 +- .../javaparser/remove/NodeRemovalTest.java | 26 +- ...er_symbol_solver_testing_src_test_java.txt | 5 +- 24 files changed, 160 insertions(+), 292 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java index f279a1fc17..487321d482 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java @@ -16,10 +16,11 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import com.github.javaparser.utils.LineSeparator; -public class LineSeparatorProcessorTest { +public class LineSeparatorProcessorTest extends AbstractLexicalPreservingTest{ // TODO: Add more tests outside the "happy path" (e.g. mixed EOL, no EOL, etc.) @@ -29,13 +30,13 @@ public class LineSeparatorProcessorTest { public void doTest(LineSeparator lineSeparator) { String eol = lineSeparator.asRawString(); - final String original = "" + + considerCode("" + " public class Foo { //comment" + eol + " private String a;" + eol + " private String b;" + eol + " private String c;" + eol + " private String d;" + eol + - " }"; + " }"); // Note: Expect the platform's EOL character when printing String expected = "" + @@ -49,9 +50,6 @@ public void doTest(LineSeparator lineSeparator) { " }"; - CompilationUnit cu = StaticJavaParser.parse(original); - LexicalPreservingPrinter.setup(cu); - // create a new field declaration VariableDeclarator variable = new VariableDeclarator(new ClassOrInterfaceType("String"), "newField"); FieldDeclaration fd = new FieldDeclaration(new NodeList(Modifier.privateModifier()), variable); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java index 55d8004933..b7842451cc 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java @@ -30,6 +30,7 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.ast.observer.AstObserver; import com.github.javaparser.ast.observer.ObservableProperty; +import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -45,7 +46,7 @@ import static com.github.javaparser.ast.NodeList.nodeList; import static org.junit.jupiter.api.Assertions.*; -class NodeListTest { +class NodeListTest extends AbstractLexicalPreservingTest { @Test void replace() { @@ -283,20 +284,16 @@ void whenSet() { @Test void usageTest() { final String REFERENCE_TO_BE_DELETED = "bad"; - String original = "" + + considerCode("" + "@MyAnnotation(myElements = {\"good\", \"bad\", \"ugly\"})\n" + "public final class MyClass {\n" + - "}"; + "}"); String expected = "" + "@MyAnnotation(myElements = {\"good\", \"ugly\"})\n" + "public final class MyClass {\n" + "}"; - JavaParser javaParser = new JavaParser(); - javaParser.getParserConfiguration().setLexicalPreservationEnabled(true); - - CompilationUnit compilationUnit = javaParser.parse(original).getResult().get(); - List annotations = compilationUnit.findAll(NormalAnnotationExpr.class); + List annotations = cu.findAll(NormalAnnotationExpr.class); annotations.forEach(annotation -> { // testcase, per https://github.com/javaparser/javaparser/issues/2936#issuecomment-731370505 @@ -316,7 +313,7 @@ void usageTest() { } }); - assertEquals(expected, LexicalPreservingPrinter.print(compilationUnit)); + assertEquals(expected, LexicalPreservingPrinter.print(cu)); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java index ee718ceec8..f02c4d52c3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java @@ -37,9 +37,10 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; -class ModifierVisitorTest { +class ModifierVisitorTest extends AbstractLexicalPreservingTest { @Test void makeSureParentListsCanBeModified() { NodeList list = new NodeList<>(); @@ -133,13 +134,12 @@ public Visitable visit(VariableDeclarator x, Void arg) { @Test void issue2124() { ModifierVisitor modifier = new ModifierVisitor<>(); - CompilationUnit cu = StaticJavaParser.parse("\n" + + considerCode("\n" + "public class ModifierVisitorTest {\n" + " private void causesException() {\n" + " String[] listWithExtraCommaAndEqualElements = {\"a\", \"a\",};\n" + " }\n" + "}"); - LexicalPreservingPrinter.setup(cu); cu.accept(modifier, null); //there should be no exception LexicalPreservingPrinter.print(cu); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3113Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3113Test.java index b8ba8a8588..a8a4ecadc7 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3113Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3113Test.java @@ -4,12 +4,13 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class Issue3113Test { +public class Issue3113Test extends AbstractLexicalPreservingTest { @Test public void issue3113() { StaticJavaParser.getConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_12); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java index 87e3e48ec5..9fe8982f86 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java @@ -34,11 +34,13 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.stmt.Statement; public abstract class AbstractLexicalPreservingTest { protected CompilationUnit cu; protected Expression expression; + protected Statement statement; @AfterAll public static void tearDown() { @@ -56,6 +58,10 @@ protected void considerCode(String code) { protected void considerExpression(String code) { expression = LexicalPreservingPrinter.setup(StaticJavaParser.parseExpression(code)); } + + protected void considerStatement(String code) { + statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement(code)); + } protected void considerVariableDeclaration(String code) { expression = LexicalPreservingPrinter.setup(StaticJavaParser.parseVariableDeclarationExpr(code)); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java index 7ffb75c58e..05c03781c1 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java @@ -32,17 +32,13 @@ import com.github.javaparser.ast.expr.MarkerAnnotationExpr; import com.github.javaparser.ast.type.ClassOrInterfaceType; -public class AnnotationSpaceTest { +public class AnnotationSpaceTest extends AbstractLexicalPreservingTest { /** Tests that inserted annotations on types are followed by a space. */ @Test public void test() { - CompilationUnit cu = - StaticJavaParser.parse( - "public class Foo {\n" + + considerCode("public class Foo {\n" + " void myMethod(String param);\n" + - "}" - ); - LexicalPreservingPrinter.setup(cu); + "}"); // Insert the annotation onto the String parameter type. Optional type = cu.findFirst(ClassOrInterfaceType.class); type.get().addAnnotation(new MarkerAnnotationExpr("Nullable")); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java index 8a5b4f89de..3397bd74b4 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java @@ -37,22 +37,20 @@ import com.github.javaparser.ast.stmt.ThrowStmt; import com.github.javaparser.utils.TestUtils; -public class Issue1467Test { +public class Issue1467Test extends AbstractLexicalPreservingTest { @Test public void test() { - String before = + considerCode( "public class Bar {\n" + " public void foo() {\n" + " System.out.print(\"Hello\");\n" + " }\n" + - "}"; + "}"); String expected = "public void f() {\n" + " throw new UnsupportedOperationException(\"Not supported yet.\");\n" + " }" ; - CompilationUnit cu = StaticJavaParser.parse(before); - LexicalPreservingPrinter.setup(cu); // add method declaration MethodDeclaration decl = cu.getChildNodesByType(ClassOrInterfaceDeclaration.class).get(0).addMethod("f", Keyword.PUBLIC); // create body diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java index a5e7b6c26f..8468fc776a 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java @@ -14,7 +14,7 @@ public class Issue1634Test extends AbstractLexicalPreservingTest { @Test public void testWithLexicalPreservationEnabled() { - String actual = "package com.wangym.test;\nclass A{ }"; + considerCode("package com.wangym.test;\nclass A{ }"); String expected = "package com.wangym.test;\n" @@ -22,9 +22,6 @@ public void testWithLexicalPreservationEnabled() { + "\n" + "class A{ }"; - CompilationUnit cu = StaticJavaParser.parse(actual); - LexicalPreservingPrinter.setup(cu); - NodeList imports = cu.getImports(); String str = "lombok.Data"; imports.add(new ImportDeclaration(str, false, false)); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java index 7a2f129ac0..47388b858e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java @@ -33,7 +33,7 @@ public class Issue1766Test extends AbstractLexicalPreservingTest { @Test public void testWithLexicalPreservationEnabled() { - String actual = + considerCode( "public class SimpleTestClass {\n" + " public SimpleTestClass() {\n" + " // nothing\n" + @@ -42,7 +42,7 @@ public void testWithLexicalPreservationEnabled() { " void bubber() {\n" + " // nothing\n" + " }\n" + - "}"; + "}"); String expected = "public class SimpleTestClass {\n" + @@ -55,18 +55,13 @@ public void testWithLexicalPreservationEnabled() { " }\n" + "}"; - final ParserConfiguration parserConfiguration = new ParserConfiguration(); - parserConfiguration.setLexicalPreservationEnabled(true); - StaticJavaParser.setConfiguration(parserConfiguration); - - CompilationUnit cu = StaticJavaParser.parse(actual); - TestUtils.assertEqualsStringIgnoringEol(expected, actual); + TestUtils.assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); } @Test public void testWithLexicalPreservingPrinterSetup() { - String actual = + considerCode( "public class SimpleTestClass {\n" + " public SimpleTestClass() {\n" + " // nothing\n" + @@ -75,7 +70,7 @@ public void testWithLexicalPreservingPrinterSetup() { " void bubber() {\n" + " // nothing\n" + " }\n" + - "}"; + "}"); String expected = "public class SimpleTestClass {\n" + @@ -88,11 +83,6 @@ public void testWithLexicalPreservingPrinterSetup() { " }\n" + "}"; - final ParserConfiguration parserConfiguration = new ParserConfiguration(); - StaticJavaParser.setConfiguration(parserConfiguration); - - CompilationUnit cu = StaticJavaParser.parse(actual); - LexicalPreservingPrinter.setup(cu); - TestUtils.assertEqualsStringIgnoringEol(expected, actual); + TestUtils.assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java index fef95686f4..45178aec0e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java @@ -31,7 +31,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; -class Issue1793Test { +class Issue1793Test extends AbstractLexicalPreservingTest { @AfterEach public void reset() { @@ -40,7 +40,7 @@ public void reset() { @Test void importIsAddedOnTheSameLine() { - String src = + considerCode( "public class Test {\n" + " public void foo(Bar x, Bar y) {\n" + " x.barf(); // expected to be wrapped\n" + @@ -48,10 +48,7 @@ void importIsAddedOnTheSameLine() { " y.barf(); // expected to be wrapped\n" + " y.bark(); // expected to be wrapped\n" + " }\n" + - "}"; - StaticJavaParser.setConfiguration(new ParserConfiguration().setLexicalPreservationEnabled(true)); - CompilationUnit cu = StaticJavaParser.parse(src); - LexicalPreservingPrinter.setup(cu); + "}"); assertEquals(LexicalPreservingPrinter.print(cu), LexicalPreservingPrinter.print(cu.clone())); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java index d310be17b0..d3a4aadaf7 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java @@ -38,20 +38,14 @@ public class Issue2290Test extends AbstractLexicalPreservingTest { @Test public void test() { - ParserConfiguration config = new ParserConfiguration() - .setLexicalPreservationEnabled(true) - .setStoreTokens(true); - StaticJavaParser.setConfiguration(config); - - String s = + considerCode( "public class Clone1 {\n" + " public static void main(String[] args) {\n" + " System.out.println(\"I'm a clone10\");\n" + " System.out.println(\"I'm not a clone!\");\n" + " System.out.println(\"I'm a clone10\");\n" + " }\n" + - "}"; - CompilationUnit cu = StaticJavaParser.parse(s); + "}"); List exprs = cu.findAll(ExpressionStmt.class); ExpressionStmt es = exprs.get(exprs.size()-1); es.getParentNode().get().remove(es); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java index 6309b2448d..2799339c30 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java @@ -32,19 +32,18 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.Statement; -public class Issue2374Test { +public class Issue2374Test extends AbstractLexicalPreservingTest { @Test public void test() { String lineComment = "Example comment"; - CompilationUnit cu = StaticJavaParser.parse( + considerCode( "public class Bar {\n" + " public void foo() {\n" + " System.out.print(\"Hello\");\n" + " }\n" + "}" ); - LexicalPreservingPrinter.setup(cu); // contruct a statement with a comment Statement stmt = StaticJavaParser.parseStatement("System.out.println(\"World!\");"); stmt.setLineComment(lineComment); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java index e781a06d31..2a885baa1f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java @@ -26,16 +26,14 @@ import org.junit.jupiter.api.Test; import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.stmt.IfStmt; public class Issue2393Test extends AbstractLexicalPreservingTest { @Test public void test() { - CompilationUnit compilationUnit = StaticJavaParser.parse("public class Test { public void foo() { int i = 0;\nif(i == 5) { System.out.println(i); } } }"); - LexicalPreservingPrinter.setup(compilationUnit); - IfStmt ifStmt = compilationUnit.findFirst(IfStmt.class).orElseThrow(() -> new IllegalStateException("Expected if")); + considerCode("public class Test { public void foo() { int i = 0;\nif(i == 5) { System.out.println(i); } } }"); + IfStmt ifStmt = cu.findFirst(IfStmt.class).orElseThrow(() -> new IllegalStateException("Expected if")); ifStmt.setCondition(StaticJavaParser.parseExpression("i > 0")); assertEquals("i > 0", ifStmt.getCondition().toString()); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java index 1905d87f82..9da8f03258 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java @@ -13,26 +13,19 @@ import com.github.javaparser.ast.expr.SimpleName; -public class Issue2592Test { +public class Issue2592Test extends AbstractLexicalPreservingTest { @Test public void testLPP() { -// // Either do this before parsing, or manually pass the node to `LexicalPreservingPrinter.setup(node);` -// StaticJavaParser.getConfiguration().setLexicalPreservationEnabled(true); - - String s = "public class A {" + + considerCode("public class A {" + " public void m(final int a_original, int b) {" + " }" + - "} "; - CompilationUnit cu = StaticJavaParser.parse(s); + "} "); Optional md = cu.findFirst(MethodDeclaration.class); //all parameters have parent nodes here assertTrue(md.get().getParameters().stream().allMatch(p -> p.getParentNode().isPresent())); - //this seems to be doing nasty things to parent nodes (after a change happens) - LexicalPreservingPrinter.setup(cu); - //all parameters have parent nodes here assertTrue(md.get().getParameters().stream().allMatch(p -> p.getParentNode().isPresent())); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java index dac532fa3b..faaf88eeae 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java @@ -30,7 +30,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; -public class Issue2610Test { +public class Issue2610Test extends AbstractLexicalPreservingTest { /* * This test case must prevent an UnsupportedOperation Removed throwed by LexicalPreservation when we try to replace an expression @@ -38,7 +38,7 @@ public class Issue2610Test { @Test public void test() { - CompilationUnit cu = StaticJavaParser.parse( + considerCode( "public class Bar {\n" + " public void foo() {\n" + " // comment\n" + @@ -46,11 +46,11 @@ public void test() { " }\n" + "}" ); - LexicalPreservingPrinter.setup(cu); // contruct a statement with a comment Expression expr = StaticJavaParser.parseExpression("System.out.println(\"warning\")"); // Replace the method expression Optional mce = cu.findFirst(MethodCallExpr.class); mce.get().getParentNode().get().replace(mce.get(), expr); + // TODO assert something } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java index 86762b4b48..a509b56290 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java @@ -39,7 +39,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.utils.LineSeparator; -public class Issue2620Test { +public class Issue2620Test extends AbstractLexicalPreservingTest { @Test public void testWithCr() { @@ -62,13 +62,13 @@ public void testWithCrLf() { */ public void doTest(LineSeparator eol) { - final String original = "" + + considerCode("" + " public class Foo { //comment" + eol + " private String a;" + eol + " private String b;" + eol + " private String c;" + eol + " private String d;" + eol + - " }"; + " }"); // Note: Expect the platform's EOL character when printing // FIXME: Indentation is bad here. @@ -83,9 +83,6 @@ public void doTest(LineSeparator eol) { " }"; - CompilationUnit cu = StaticJavaParser.parse(original); - LexicalPreservingPrinter.setup(cu); - // create a new field declaration VariableDeclarator variable = new VariableDeclarator(new ClassOrInterfaceType("String"), "newField"); FieldDeclaration fd = new FieldDeclaration(new NodeList(Modifier.privateModifier()), variable); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java index bf21707e76..05c4414a64 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java @@ -32,24 +32,21 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; -class Issue2806Test { +class Issue2806Test extends AbstractLexicalPreservingTest{ private JavaParser javaParser; @Test void importIsAddedOnTheSameLine() { - String junit4 = "import java.lang.IllegalArgumentException;\n" + + considerCode("import java.lang.IllegalArgumentException;\n" + "\n" + "public class A {\n" + - "}"; + "}"); String junit5 = "import java.lang.IllegalArgumentException;\n" + "import java.nio.file.Paths;\n" + "\n" + "public class A {\n" + "}"; - JavaParser parser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - CompilationUnit cu = parser.parse(junit4).getResult().get(); - LexicalPreservingPrinter.setup(cu); ImportDeclaration importDeclaration = new ImportDeclaration("java.nio.file.Paths", false, false); CompilationUnit compilationUnit = cu.addImport(importDeclaration); String out = LexicalPreservingPrinter.print(compilationUnit); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java index 228ba6ebe4..8113ee9283 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java @@ -38,10 +38,9 @@ public class Issue3296Test extends AbstractLexicalPreservingTest { @Test public void test() { - String code = "public class Test { String[][] allTest; }"; + considerCode("public class Test { String[][] allTest; }"); String expected = "public class Test { @Nullable\n" + "String[][] allTest; }"; - CompilationUnit cu = LexicalPreservingPrinter.setup(StaticJavaParser.parse(code)); Optional clazzOptional = cu.getClassByName("Test"); assertTrue(clazzOptional.isPresent()); ClassOrInterfaceDeclaration clazz = clazzOptional.get(); @@ -58,7 +57,6 @@ public void test() { } } })); - String changed = LexicalPreservingPrinter.print(cu); - assertEqualsStringIgnoringEol(changed, expected); + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); } } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java index 86e8910609..d7dd2fd6fc 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java @@ -37,14 +37,14 @@ public class Issue3387Test extends AbstractLexicalPreservingTest { @Test public void test3387() { - String input = new StringJoiner("\n") + considerCode(new StringJoiner("\n") .add("class A {") .add("") .add("\tpublic void setTheNumber(int number) {") .add("\t\tnumber = number;") .add("\t}") .add("") - .add("}").toString(); + .add("}").toString()); String expected = "class A {\n" + "\n" + @@ -57,9 +57,6 @@ public void test3387() { "\n" + "}"; - CompilationUnit cu = StaticJavaParser.parse(input); - LexicalPreservingPrinter.setup(cu); - MethodDeclaration md = cu.findFirst(MethodDeclaration.class).get(); // create new javadoc comment Javadoc javadoc = new Javadoc(JavadocDescription.parseText("Change Javadoc")); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java index e2b0e09115..ebba294909 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java @@ -33,7 +33,6 @@ public class Issue3440Test extends AbstractLexicalPreservingTest { void test3440() { considerCode("public class Foo { public void bar() { switch(1) {case 1: break; } } }"); String expected = "public class Foo { public void bar() { switch(1) {case 1: } } }"; - LexicalPreservingPrinter.setup(cu); SwitchEntry entry = cu.findFirst(SwitchEntry.class).get(); entry.setStatements(new NodeList<>()); TestUtils.assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java index 29c3c830e3..70be958d36 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java @@ -461,15 +461,13 @@ void printASimpleMethodRemovingAStatementCR() { } private void printASimpleMethodRemovingAStatement(String eol) { - String code = "class A {" + eol + considerCode("class A {" + eol + "\t" + "foo(int a, int b) {" + eol + "\t\t" + "int result = a * b;" + eol + "\t\t" + "return a * b;" + eol + "\t" + "}" + eol - + "}"; + + "}"); - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); ExpressionStmt stmt = cu.findAll(ExpressionStmt.class).get(0); stmt.remove(); @@ -634,16 +632,13 @@ void printLambdaIntersectionTypeReturn() { // See issue #855 @Test void handleOverrideAnnotation() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -901,15 +896,12 @@ void addASecondStatementToExistingMethod() throws IOException { // See issue #866 @Test void moveOverrideAnnotations() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected @Override void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -936,15 +928,12 @@ void moveOverrideAnnotations() { // See issue #866 @Test void moveOrAddOverrideAnnotations() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected @Override void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -974,16 +963,13 @@ void moveOrAddOverrideAnnotations() { // See issue #865 @Test void handleAddingMarkerAnnotation() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -1008,15 +994,12 @@ void handleAddingMarkerAnnotation() { // See issue #865 @Test void handleOverrideMarkerAnnotation() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -1035,15 +1018,12 @@ void handleOverrideMarkerAnnotation() { // See issue #865 @Test void handleOverrideAnnotationAlternative() { - String code = "public class TestPage extends Page {" + SYSTEM_EOL + + considerCode("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + - "}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getTypes() .forEach(type -> type.getMembers() @@ -1061,22 +1041,17 @@ void handleOverrideAnnotationAlternative() { @Test void invokeModifierVisitor() { - String code = "class A {" + SYSTEM_EOL + considerCode("class A {" + SYSTEM_EOL + " Object f() {" + SYSTEM_EOL + " return (Comparator> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL - + "}}"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + + "}}"); cu.accept(new ModifierVisitor<>(), null); } @Test void handleDeprecatedAnnotationFinalClass() { - String code = "public final class A {}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + considerCode("public final class A {}"); cu.getTypes().forEach(type -> type.addAndGetAnnotation(Deprecated.class)); @@ -1087,10 +1062,7 @@ void handleDeprecatedAnnotationFinalClass() { @Test void handleDeprecatedAnnotationAbstractClass() { - String code = "public abstract class A {}"; - - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + considerCode("public abstract class A {}"); cu.getTypes().forEach(type -> type.addAndGetAnnotation(Deprecated.class)); @@ -1100,11 +1072,9 @@ void handleDeprecatedAnnotationAbstractClass() { @Test void issue1244() { - String code = "public class Foo {" + SYSTEM_EOL + SYSTEM_EOL + considerCode("public class Foo {" + SYSTEM_EOL + SYSTEM_EOL + "// Some comment" + SYSTEM_EOL + SYSTEM_EOL // does work with only one \n - + "public void writeExternal() {}" + SYSTEM_EOL + "}"; - CompilationUnit originalCu = parse(code); - CompilationUnit cu = LexicalPreservingPrinter.setup(originalCu); + + "public void writeExternal() {}" + SYSTEM_EOL + "}"); cu.findAll(ClassOrInterfaceDeclaration.class).forEach(c -> { List methods = c.getMethodsByName("writeExternal"); @@ -1128,15 +1098,13 @@ public Visitable visit(MethodCallExpr n, Void arg) { // See issue 1277 @Test void testInvokeModifierVisitor() { - String code = "class A {" + SYSTEM_EOL + + considerCode("class A {" + SYSTEM_EOL + " public String message = \"hello\";" + SYSTEM_EOL + " void bar() {" + SYSTEM_EOL + " System.out.println(\"hello\");" + SYSTEM_EOL + " }" + SYSTEM_EOL + - "}"; + "}"); - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); cu.accept(new AddFooCallModifierVisitor(), null); } @@ -1150,24 +1118,20 @@ public Visitable visit(MethodCallExpr n, Void arg) { @Test void invokeModifierVisitorIssue1297() { - String code = "class A {" + SYSTEM_EOL + + considerCode("class A {" + SYSTEM_EOL + " public void bar() {" + SYSTEM_EOL + " System.out.println(\"hello\");" + SYSTEM_EOL + " System.out.println(\"hello\");" + SYSTEM_EOL + " // comment" + SYSTEM_EOL + " }" + SYSTEM_EOL + - "}"; + "}"); - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); cu.accept(new CallModifierVisitor(), null); } @Test void addedBlockCommentsPrinted() { - String code = "public class Foo { }"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + considerCode("public class Foo { }"); cu.getClassByName("Foo").get() .addMethod("mymethod") @@ -1181,9 +1145,7 @@ void addedBlockCommentsPrinted() { @Test void addedLineCommentsPrinted() { - String code = "public class Foo { }"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + considerCode("public class Foo { }"); cu.getClassByName("Foo").get() .addMethod("mymethod") @@ -1197,13 +1159,11 @@ void addedLineCommentsPrinted() { @Test void removedLineCommentsPrinted() { - String code = "public class Foo {" + SYSTEM_EOL + + considerCode("public class Foo {" + SYSTEM_EOL + "//line" + SYSTEM_EOL + "void mymethod() {" + SYSTEM_EOL + "}" + SYSTEM_EOL + - "}"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getAllContainedComments().get(0).remove(); assertEqualsStringIgnoringEol("public class Foo {" + SYSTEM_EOL + @@ -1215,13 +1175,11 @@ void removedLineCommentsPrinted() { // Checks if comments get removed properly with Unix style line endings @Test void removedLineCommentsPrintedUnix() { - String code = "public class Foo {" + "\n" + + considerCode("public class Foo {" + "\n" + "//line" + "\n" + "void mymethod() {" + "\n" + "}" + "\n" + - "}"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getAllContainedComments().get(0).remove(); assertEquals("public class Foo {" + "\n" + @@ -1232,15 +1190,13 @@ void removedLineCommentsPrintedUnix() { @Test void removedBlockCommentsPrinted() { - String code = "public class Foo {" + SYSTEM_EOL + + considerCode("public class Foo {" + SYSTEM_EOL + "/*" + SYSTEM_EOL + "Block comment coming through" + SYSTEM_EOL + "*/" + SYSTEM_EOL + "void mymethod() {" + SYSTEM_EOL + "}" + SYSTEM_EOL + - "}"; - CompilationUnit cu = parse(code); - LexicalPreservingPrinter.setup(cu); + "}"); cu.getAllContainedComments().get(0).remove(); assertEqualsStringIgnoringEol("public class Foo {" + SYSTEM_EOL + @@ -1252,21 +1208,20 @@ void removedBlockCommentsPrinted() { @Test void testFixIndentOfMovedNode() { try { - CompilationUnit compilationUnit = parse(readExample("FixIndentOfMovedNode")); - LexicalPreservingPrinter.setup(compilationUnit); + considerExample("FixIndentOfMovedNode"); - compilationUnit.getClassByName("ThisIsASampleClass").get() + cu.getClassByName("ThisIsASampleClass").get() .getMethodsByName("longerMethod") .get(0) .setBlockComment("Lorem ipsum dolor sit amet, consetetur sadipscing elitr."); - compilationUnit.getClassByName("Foo").get() + cu.getClassByName("Foo").get() .getFieldByName("myFoo") .get() .setLineComment("sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat"); String expectedCode = readExample("FixIndentOfMovedNodeExpected"); - assertEquals(expectedCode, LexicalPreservingPrinter.print(compilationUnit)); + assertEquals(expectedCode, LexicalPreservingPrinter.print(cu)); } catch (IOException ex) { fail("Could not read test code", ex); } @@ -1274,32 +1229,27 @@ void testFixIndentOfMovedNode() { @Test void issue1321() { - CompilationUnit compilationUnit = parse("class X { X() {} private void testme() {} }"); - LexicalPreservingPrinter.setup(compilationUnit); + considerCode("class X { X() {} private void testme() {} }"); - ClassOrInterfaceDeclaration type = compilationUnit.getClassByName("X").get(); + ClassOrInterfaceDeclaration type = cu.getClassByName("X").get(); type.getConstructors().get(0).setBody(new BlockStmt().addStatement("testme();")); assertEqualsStringIgnoringEol("class X { X() {\n testme();\n} private void testme() {} }", - LexicalPreservingPrinter.print(compilationUnit)); + LexicalPreservingPrinter.print(cu)); } @Test void issue2001() { - CompilationUnit compilationUnit = parse("class X {void blubb(){X.p(\"blaubb04\");}}"); - LexicalPreservingPrinter.setup(compilationUnit); + considerCode("class X {void blubb(){X.p(\"blaubb04\");}}"); - compilationUnit - .findAll(MethodCallExpr.class) - .forEach(Node::removeForced); + cu.findAll(MethodCallExpr.class).forEach(Node::removeForced); - assertEqualsStringIgnoringEol("class X {void blubb(){}}", LexicalPreservingPrinter.print(compilationUnit)); + assertEqualsStringIgnoringEol("class X {void blubb(){}}", LexicalPreservingPrinter.print(cu)); } @Test void testIndentOfCodeBlocks() throws IOException { - CompilationUnit compilationUnit = parse(considerExample("IndentOfInsertedCodeBlocks")); - LexicalPreservingPrinter.setup(compilationUnit); + considerExample("IndentOfInsertedCodeBlocks"); IfStmt ifStmt = new IfStmt(); ifStmt.setCondition(StaticJavaParser.parseExpression("name.equals(\"foo\")")); @@ -1313,15 +1263,14 @@ void testIndentOfCodeBlocks() throws IOException { ifStmt.setThenStmt(blockStmt); ifStmt.setElseStmt(new BlockStmt()); - compilationUnit.findFirst(BlockStmt.class).get().addStatement(ifStmt); + cu.findFirst(BlockStmt.class).get().addStatement(ifStmt); String expected = considerExample("IndentOfInsertedCodeBlocksExpected"); - TestUtils.assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(compilationUnit)); + TestUtils.assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); } @Test void commentAddedAtTopLevel() { - JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - CompilationUnit cu = javaParser.parse("package x;class X{}").getResult().get(); + considerCode("package x;class X{}"); cu.setComment(new LineComment("Bla")); assertEqualsStringIgnoringEol("//Bla\npackage x;class X{}", LexicalPreservingPrinter.print(cu)); @@ -1335,147 +1284,117 @@ void commentAddedAtTopLevel() { @Test public void testReplaceStringLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - final String code = "\"asd\""; + considerExpression("\"asd\""); final String expected = "\"REPLACEMENT\""; - final Expression b = javaParser.parseExpression(code).getResult().orElseThrow(AssertionError::new); - - assertTrue(b.isStringLiteralExpr()); - StringLiteralExpr sle = (StringLiteralExpr) b; + assertTrue(expression.isStringLiteralExpr()); + StringLiteralExpr sle = (StringLiteralExpr) expression; sle.setValue("REPLACEMENT"); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(expression); assertEquals(expected, actual); } @Test public void testReplaceStringLiteralWithinStatement() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "String str = \"aaa\";"; + considerStatement("String str = \"aaa\";"); String expected = "String str = \"REPLACEMENT\";"; - Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(StringLiteralExpr.class).forEach(stringLiteralExpr -> { + statement.findAll(StringLiteralExpr.class).forEach(stringLiteralExpr -> { stringLiteralExpr.setValue("REPLACEMENT"); }); - assertEquals(expected, LexicalPreservingPrinter.print(b)); - assertEquals(expected, b.toString()); + assertEquals(expected, LexicalPreservingPrinter.print(statement)); + assertEquals(expected, statement.toString()); } @Test public void testReplaceClassName() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); + considerCode("class A {}"); - final String code = "class A {}"; - final CompilationUnit b = javaParser.parse(code).getResult().orElseThrow(AssertionError::new); - LexicalPreservingPrinter.setup(b); - - assertEquals(1, b.findAll(ClassOrInterfaceDeclaration.class).size()); - b.findAll(ClassOrInterfaceDeclaration.class).forEach(coid -> coid.setName("B")); + assertEquals(1, cu.findAll(ClassOrInterfaceDeclaration.class).size()); + cu.findAll(ClassOrInterfaceDeclaration.class).forEach(coid -> coid.setName("B")); final String expected = "class B {}"; - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(cu); assertEquals(expected, actual); } @Test public void testReplaceIntLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - final String code = "5"; + considerExpression("5"); final String expected = "10"; - final Expression b = javaParser.parseExpression(code).getResult().orElseThrow(AssertionError::new); - - assertTrue(b.isIntegerLiteralExpr()); - ((IntegerLiteralExpr) b).setValue("10"); + assertTrue(expression.isIntegerLiteralExpr()); + ((IntegerLiteralExpr) expression).setValue("10"); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(expression); assertEquals(expected, actual); } @Test public void testReplaceLongLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "long x = 5L;"; + considerStatement("long x = 5L;"); String expected = "long x = 10L;"; - final Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(LongLiteralExpr.class).forEach(longLiteralExpr -> { + statement.findAll(LongLiteralExpr.class).forEach(longLiteralExpr -> { longLiteralExpr.setValue("10L"); }); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(statement); assertEquals(expected, actual); } @Test public void testReplaceBooleanLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "boolean x = true;"; + considerStatement("boolean x = true;"); String expected = "boolean x = false;"; - final Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(BooleanLiteralExpr.class).forEach(booleanLiteralExpr -> { + statement.findAll(BooleanLiteralExpr.class).forEach(booleanLiteralExpr -> { booleanLiteralExpr.setValue(false); }); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(statement); assertEquals(expected, actual); } @Test public void testReplaceDoubleLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "double x = 5.0D;"; + considerStatement("double x = 5.0D;"); String expected = "double x = 10.0D;"; - final Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(DoubleLiteralExpr.class).forEach(doubleLiteralExpr -> { + statement.findAll(DoubleLiteralExpr.class).forEach(doubleLiteralExpr -> { doubleLiteralExpr.setValue("10.0D"); }); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(statement); assertEquals(expected, actual); } @Test public void testReplaceCharLiteral() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "char x = 'a';"; + considerStatement("char x = 'a';"); String expected = "char x = 'b';"; - final Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(CharLiteralExpr.class).forEach(charLiteralExpr -> { + statement.findAll(CharLiteralExpr.class).forEach(charLiteralExpr -> { charLiteralExpr.setValue("b"); }); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(statement); assertEquals(expected, actual); } @Test public void testReplaceCharLiteralUnicode() { - final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLexicalPreservationEnabled(true)); - - String code = "char x = 'a';"; + considerStatement("char x = 'a';"); String expected = "char x = '\\u0000';"; - final Statement b = javaParser.parseStatement(code).getResult().orElseThrow(AssertionError::new); - b.findAll(CharLiteralExpr.class).forEach(charLiteralExpr -> { + statement.findAll(CharLiteralExpr.class).forEach(charLiteralExpr -> { charLiteralExpr.setValue("\\u0000"); }); - final String actual = LexicalPreservingPrinter.print(b); + final String actual = LexicalPreservingPrinter.print(statement); assertEquals(expected, actual); } diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java index 39f47a5b93..0d513acc9e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java @@ -174,10 +174,10 @@ void exampleParam5() throws IOException { @Test void issue2099AddingStatementAfterTraillingComment1() { - Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement( + considerStatement( " if(value != null) {" + SYSTEM_EOL + " value.value();" + SYSTEM_EOL + - " }")); + " }"); BlockStmt blockStmt = LexicalPreservingPrinter.setup(StaticJavaParser.parseBlock("{" + SYSTEM_EOL + " value1();" + SYSTEM_EOL + @@ -198,10 +198,10 @@ void issue2099AddingStatementAfterTraillingComment1() { @Test void issue2099AddingStatementAfterTraillingComment2() { - Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement( + considerStatement( " if(value != null) {" + SYSTEM_EOL + " value.value();" + SYSTEM_EOL + - " }")); + " }"); BlockStmt blockStmt = LexicalPreservingPrinter.setup(StaticJavaParser.parseBlock("{" + SYSTEM_EOL + " value1();" + SYSTEM_EOL + @@ -223,10 +223,10 @@ void issue2099AddingStatementAfterTraillingComment2() { @Test void addingStatement1() { - Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement( + considerStatement( " if(value != null) {" + SYSTEM_EOL + " value.value();" + SYSTEM_EOL + - " }")); + " }"); CompilationUnit compilationUnit = LexicalPreservingPrinter.setup(StaticJavaParser.parse("public class Test {" + SYSTEM_EOL + " public void method() {" + SYSTEM_EOL + @@ -253,10 +253,10 @@ void addingStatement1() { @Test void addingStatement2() { - Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement( + considerStatement( " if(value != null) {" + SYSTEM_EOL + " value.value();" + SYSTEM_EOL + - " }")); + " }"); CompilationUnit compilationUnit = LexicalPreservingPrinter.setup(StaticJavaParser.parse("public class Test {" + SYSTEM_EOL + " public void method() {" + SYSTEM_EOL + @@ -283,10 +283,10 @@ void addingStatement2() { @Test void addingStatement3() { - Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement( + considerStatement( " if(value != null) {" + SYSTEM_EOL + " value.value();" + SYSTEM_EOL + - " }")); + " }"); CompilationUnit compilationUnit = LexicalPreservingPrinter.setup(StaticJavaParser.parse("public class Test {" + SYSTEM_EOL + " public void method() {" + SYSTEM_EOL + diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java index 375dd8b814..ee647039f2 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java @@ -28,8 +28,8 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; -import com.github.javaparser.utils.TestParser; import org.junit.jupiter.api.Test; @@ -38,21 +38,22 @@ import java.util.List; -class NodeRemovalTest { - private final CompilationUnit cu = new CompilationUnit(); +class NodeRemovalTest extends AbstractLexicalPreservingTest{ + + private final CompilationUnit compilationUnit = new CompilationUnit(); @Test void testRemoveClassFromCompilationUnit() { - ClassOrInterfaceDeclaration testClass = cu.addClass("test"); - assertEquals(1, cu.getTypes().size()); + ClassOrInterfaceDeclaration testClass = compilationUnit.addClass("test"); + assertEquals(1, compilationUnit.getTypes().size()); boolean remove = testClass.remove(); assertTrue(remove); - assertEquals(0, cu.getTypes().size()); + assertEquals(0, compilationUnit.getTypes().size()); } @Test void testRemoveFieldFromClass() { - ClassOrInterfaceDeclaration testClass = cu.addClass("test"); + ClassOrInterfaceDeclaration testClass = compilationUnit.addClass("test"); FieldDeclaration addField = testClass.addField(String.class, "test"); assertEquals(1, testClass.getMembers().size()); @@ -63,7 +64,7 @@ void testRemoveFieldFromClass() { @Test void testRemoveStatementFromMethodBody() { - ClassOrInterfaceDeclaration testClass = cu.addClass("testC"); + ClassOrInterfaceDeclaration testClass = compilationUnit.addClass("testC"); MethodDeclaration addMethod = testClass.addMethod("testM"); BlockStmt methodBody = addMethod.createBody(); @@ -76,12 +77,11 @@ void testRemoveStatementFromMethodBody() { @Test void testRemoveStatementFromMethodBodyWithLexicalPreservingPrinter() { - String sample = "{\r\n" + " log.error(\"context\", e);\r\n" + + considerStatement("{\r\n" + " log.error(\"context\", e);\r\n" + " log.error(\"context\", e);\r\n" + - " throw new ApplicationException(e);\r\n" + "}\r\n"; - BlockStmt bstmt = TestParser.parseStatement(sample).asBlockStmt(); - BlockStmt stmt = LexicalPreservingPrinter.setup(bstmt); - List children = stmt.getChildNodes(); + " throw new ApplicationException(e);\r\n" + "}\r\n"); + BlockStmt bstmt = statement.asBlockStmt(); + List children = bstmt.getChildNodes(); remove(children.get(0)); assertTrue(children.size() == 2); remove(children.get(0)); diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt b/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt index 425e902f35..8a9fcbee58 100644 --- a/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results_javaparser_symbol_solver_testing_src_test_java.txt @@ -1,4 +1 @@ -com/github/javaparser/symbolsolver/Issue232Test.java -(line 25,col 66) Parse error. Found "<<", expected one of ";" "@" "\u001a" "abstract" "class" "default" "enum" "final" "import" "interface" "module" "native" "open" "private" "protected" "public" "record" "static" "strictfp" "synchronized" "transient" "transitive" "volatile" - -1 problems in 1 files \ No newline at end of file +0 problems in 0 files \ No newline at end of file From 96005a5a0f4748035ef83a4cb09428ff44ecf146 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 15:24:47 +0100 Subject: [PATCH 112/280] Refactoring: Removing useless method convertToUsage in JavaParserFacade --- .../javaparser/symbolsolver/JavaSymbolSolver.java | 2 +- .../javaparsermodel/JavaParserFacade.java | 14 +------------- .../javaparsermodel/TypeExtractor.java | 7 +++---- .../declarations/JavaParserTypeParameter.java | 2 +- .../TypeInClassWithAnnotationAncestorTest.java | 2 +- 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index 712079ff96..319c3da527 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -278,7 +278,7 @@ public T resolveDeclaration(Node node, Class resultClass) { @Override public T toResolvedType(Type javaparserType, Class resultClass) { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).convertToUsage(javaparserType, javaparserType); + ResolvedType resolvedType = JavaParserFacade.get(typeSolver).convertToUsage(javaparserType); if (resultClass.isInstance(resolvedType)) { return resultClass.cast(resolvedType); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 6fa570c4c2..84dfdc4ab7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -628,18 +628,6 @@ protected ResolvedType convertToUsage(Type type, Context context) { return type.convertToUsage(context); } - /** - * Convert a {@link Type} into the corresponding {@link ResolvedType}. - * - * @param type The type to be converted. - * @param context The current context. - * - * @return The type resolved. - */ - public ResolvedType convertToUsage(Type type, Node context) { - return convertToUsage(type, JavaParserFactory.getContext(context, typeSolver)); - } - /** * Convert a {@link Type} into the corresponding {@link ResolvedType}. * @@ -648,7 +636,7 @@ public ResolvedType convertToUsage(Type type, Node context) { * @return The type resolved. */ public ResolvedType convertToUsage(Type type) { - return convertToUsage(type, type); + return convertToUsage(type, JavaParserFactory.getContext(type, typeSolver)); } private Optional forEachStmtWithVariableDeclarator( diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 95dafaba9e..dd6ade8def 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -95,7 +95,7 @@ public ResolvedType visit(Parameter node, Boolean solveLambdas) { if (node.getType() instanceof UnknownType) { throw new IllegalStateException("Parameter has unknown type: " + node); } - return facade.convertToUsage(node.getType(), node); + return facade.convertToUsage(node.getType()); } @@ -167,8 +167,7 @@ public ResolvedType visit(CastExpr node, Boolean solveLambdas) { @Override public ResolvedType visit(ClassExpr node, Boolean solveLambdas) { // This implementation does not regard the actual type argument of the ClassExpr. - Type astType = node.getType(); - ResolvedType jssType = facade.convertToUsage(astType, node.getType()); + ResolvedType jssType = facade.convertToUsage(node.getType()); return new ReferenceTypeImpl(new ReflectionClassDeclaration(Class.class, typeSolver), ImmutableList.of(jssType)); } @@ -369,7 +368,7 @@ public ResolvedType visit(TypeExpr node, Boolean solveLambdas) { @Override public ResolvedType visit(ObjectCreationExpr node, Boolean solveLambdas) { - return facade.convertToUsage(node.getType(), node); + return facade.convertToUsage(node.getType()); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 1a5087e62e..09fb5dc681 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -156,7 +156,7 @@ public List getBounds() { } private Bound toBound(ClassOrInterfaceType classOrInterfaceType, TypeSolver typeSolver) { - ResolvedType type = JavaParserFacade.get(typeSolver).convertToUsage(classOrInterfaceType, classOrInterfaceType); + ResolvedType type = JavaParserFacade.get(typeSolver).convertToUsage(classOrInterfaceType); return Bound.extendsBound(type); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java index 10356e0df2..13d6c59e72 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java @@ -40,7 +40,7 @@ void resolveStringReturnType() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassWithAnnotationAncestor"); MethodDeclaration method = Navigator.demandMethod(clazz, "testMethod"); ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()) - .convertToUsage(method.getType(), method.getType()); + .convertToUsage(method.getType()); assertFalse(type.isTypeVariable()); assertEquals("java.lang.String", type.describe()); } From 8e616cd8366d351950c4cfa4cc9bebf6687a8133 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 17:11:32 +0100 Subject: [PATCH 113/280] Refactoring context: defining a Solver interface from SymbolSolver class --- .../github/javaparser/resolution/Solver.java | 53 +++++++++++++++++++ .../javaparsermodel/JavaParserFacade.java | 5 +- .../javaparsermodel/TypeExtractor.java | 3 +- .../symbolsolver/resolution/SymbolSolver.java | 39 +++++++++----- .../symbolsolver/resolution/ContextTest.java | 23 ++++---- .../resolution/FieldsResolutionTest.java | 3 +- .../resolution/GenericsResolutionTest.java | 11 ++-- .../resolution/SymbolSolverTest.java | 3 +- .../SymbolSolverWithJavassistClassTest.java | 3 +- .../SymbolSolverWithJavassistEnumTest.java | 3 +- ...ymbolSolverWithJavassistInterfaceTest.java | 3 +- 11 files changed, 112 insertions(+), 37 deletions(-) create mode 100755 javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java new file mode 100755 index 0000000000..f36add5614 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java @@ -0,0 +1,53 @@ +package com.github.javaparser.resolution; + +import java.util.List; +import java.util.Optional; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.types.ResolvedType; + +public interface Solver { + + SymbolReference solveSymbol(String name, Context context); + + SymbolReference solveSymbol(String name, Node node); + + Optional solveSymbolAsValue(String name, Context context); + + Optional solveSymbolAsValue(String name, Node node); + + SymbolReference solveType(String name, Context context); + + SymbolReference solveType(String name, Node node); + + MethodUsage solveMethod(String methodName, List argumentsTypes, Context context); + + MethodUsage solveMethod(String methodName, List argumentsTypes, Node node); + + ResolvedTypeDeclaration solveType(Type type); + + ResolvedType solveTypeUsage(String name, Context context); + + /** + * Solve any possible visible symbols including: fields, internal types, type variables, the type itself or its + * containers. + *

+ * It should contain its own private fields but not inherited private fields. + */ + SymbolReference solveSymbolInType(ResolvedTypeDeclaration typeDeclaration, + String name); + + /** + * Try to solve a symbol just in the declaration, it does not delegate to the container. + * + * @deprecated Similarly to solveType this should eventually disappear as the symbol resolution logic should be more general + * and do not be specific to JavaParser classes like in this case. + */ + SymbolReference solveTypeInType(ResolvedTypeDeclaration typeDeclaration, String name); + +} \ No newline at end of file diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 84dfdc4ab7..da91b513ef 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -33,6 +33,7 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -121,7 +122,7 @@ protected static ResolvedType solveGenericTypes(ResolvedType type, Context conte private final TypeSolver typeSolver; private final TypeExtractor typeExtractor; - private final SymbolSolver symbolSolver; + private final Solver symbolSolver; private FailureHandler failureHandler; @@ -136,7 +137,7 @@ public TypeSolver getTypeSolver() { return typeSolver; } - public SymbolSolver getSymbolSolver() { + public Solver getSymbolSolver() { return symbolSolver; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index dd6ade8def..cd645194c6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -34,6 +34,7 @@ import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -643,7 +644,7 @@ public ResolvedType visit(FieldDeclaration node, Boolean solveLambdas) { throw new IllegalArgumentException("Cannot resolve the type of a field with multiple variable declarations. Pick one"); } - protected SymbolSolver createSolver() { + protected Solver createSolver() { return new SymbolSolver(typeSolver); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index 3cb72af956..aca78f88ba 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -26,6 +26,7 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -47,7 +48,7 @@ /** * @author Federico Tomassetti */ -public class SymbolSolver { +public class SymbolSolver implements Solver { private final TypeSolver typeSolver; @@ -59,32 +60,39 @@ public SymbolSolver(TypeSolver typeSolver) { this.typeSolver = typeSolver; } - public SymbolReference solveSymbol(String name, Context context) { + @Override + public SymbolReference solveSymbol(String name, Context context) { return context.solveSymbol(name); } - public SymbolReference solveSymbol(String name, Node node) { + @Override + public SymbolReference solveSymbol(String name, Node node) { return solveSymbol(name, JavaParserFactory.getContext(node, typeSolver)); } - public Optional solveSymbolAsValue(String name, Context context) { + @Override + public Optional solveSymbolAsValue(String name, Context context) { return context.solveSymbolAsValue(name); } - public Optional solveSymbolAsValue(String name, Node node) { + @Override + public Optional solveSymbolAsValue(String name, Node node) { Context context = JavaParserFactory.getContext(node, typeSolver); return solveSymbolAsValue(name, context); } - public SymbolReference solveType(String name, Context context) { + @Override + public SymbolReference solveType(String name, Context context) { return context.solveType(name); } - public SymbolReference solveType(String name, Node node) { + @Override + public SymbolReference solveType(String name, Node node) { return solveType(name, JavaParserFactory.getContext(node, typeSolver)); } - public MethodUsage solveMethod(String methodName, List argumentsTypes, Context context) { + @Override + public MethodUsage solveMethod(String methodName, List argumentsTypes, Context context) { SymbolReference decl = context.solveMethod(methodName, argumentsTypes, false); if (!decl.isSolved()) { throw new UnsolvedSymbolException(context.toString(), methodName); @@ -92,11 +100,13 @@ public MethodUsage solveMethod(String methodName, List argumentsTy return new MethodUsage(decl.getCorrespondingDeclaration()); } - public MethodUsage solveMethod(String methodName, List argumentsTypes, Node node) { + @Override + public MethodUsage solveMethod(String methodName, List argumentsTypes, Node node) { return solveMethod(methodName, argumentsTypes, JavaParserFactory.getContext(node, typeSolver)); } - public ResolvedTypeDeclaration solveType(Type type) { + @Override + public ResolvedTypeDeclaration solveType(Type type) { if (type instanceof ClassOrInterfaceType) { // FIXME should call typesolver here! @@ -112,7 +122,8 @@ public ResolvedTypeDeclaration solveType(Type type) { } } - public ResolvedType solveTypeUsage(String name, Context context) { + @Override + public ResolvedType solveTypeUsage(String name, Context context) { Optional genericType = context.solveGenericType(name); if (genericType.isPresent()) { return genericType.get(); @@ -127,7 +138,8 @@ public ResolvedType solveTypeUsage(String name, Context context) { *

* It should contain its own private fields but not inherited private fields. */ - public SymbolReference solveSymbolInType(ResolvedTypeDeclaration typeDeclaration, String name) { + @Override + public SymbolReference solveSymbolInType(ResolvedTypeDeclaration typeDeclaration, String name) { if (typeDeclaration instanceof SymbolResolutionCapability) { return ((SymbolResolutionCapability) typeDeclaration).solveSymbol(name, typeSolver); } @@ -140,7 +152,8 @@ public SymbolReference solveSymbolInType(Res * @deprecated Similarly to solveType this should eventually disappear as the symbol resolution logic should be more general * and do not be specific to JavaParser classes like in this case. */ - @Deprecated + @Override + @Deprecated public SymbolReference solveTypeInType(ResolvedTypeDeclaration typeDeclaration, String name) { if (typeDeclaration instanceof JavaParserClassDeclaration) { return ((JavaParserClassDeclaration) typeDeclaration).solveType(name); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 5fdf4aa1d3..40587819c1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -62,6 +62,7 @@ import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; @@ -98,7 +99,7 @@ void resolveDeclaredFieldReference() { ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0); AssignExpr assignExpr = (AssignExpr) stmt.getExpression(); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget()); assertTrue(symbolReference.isSolved()); @@ -114,7 +115,7 @@ void resolveInheritedFieldReference() { ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0); AssignExpr assignExpr = (AssignExpr) stmt.getExpression(); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget()); assertTrue(symbolReference.isSolved()); @@ -129,7 +130,7 @@ void resolveParameterReference() { MethodDeclaration method1 = Navigator.demandMethod(referencesToField, "aMethod"); NameExpr foo = Navigator.findNameExpression(method1, "foo").get(); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference symbolReference = symbolSolver.solveSymbol("foo", foo); assertTrue(symbolReference.isSolved()); @@ -152,7 +153,7 @@ void resolveReferenceToImportedType() { when(typeSolver.getRoot()).thenReturn(typeSolver); when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); when(typeSolver.tryToSolveType("com.github.javaparser.ast.CompilationUnit")).thenReturn(SymbolReference.solved(compilationUnitDecl)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference ref = symbolSolver.solveType("CompilationUnit", param); @@ -177,7 +178,7 @@ void resolveReferenceUsingQualifiedName() { when(typeSolver.getRoot()).thenReturn(typeSolver); when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); when(typeSolver.tryToSolveType("com.github.javaparser.ast.CompilationUnit")).thenReturn(SymbolReference.solved(compilationUnitDecl)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference ref = symbolSolver.solveType("com.github.javaparser.ast.CompilationUnit", param); @@ -201,7 +202,7 @@ void resolveReferenceToClassesInTheSamePackage() { when(typeSolver.getRoot()).thenReturn(typeSolver); when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); when(typeSolver.tryToSolveType("my.packagez.CompilationUnit")).thenReturn(SymbolReference.solved(compilationUnitDecl)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference ref = symbolSolver.solveType("CompilationUnit", param); @@ -226,7 +227,7 @@ void resolveReferenceToClassInJavaLang() { when(typeSolver.getRoot()).thenReturn(typeSolver); when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver)); when(typeSolver.tryToSolveType("java.lang.String")).thenReturn(SymbolReference.solved(stringDecl)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference ref = symbolSolver.solveType("String", param); @@ -244,7 +245,7 @@ void resolveReferenceToMethod() throws IOException { Path pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar"); TypeSolver typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver(true)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); MethodUsage ref = symbolSolver.solveMethod("getTypes", Collections.emptyList(), callToGetTypes); @@ -263,7 +264,7 @@ void resolveCascadeOfReferencesToMethod() throws IOException { Path pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar"); TypeSolver typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver(true)); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); MethodUsage ref = symbolSolver.solveMethod("stream", Collections.emptyList(), callToStream); assertEquals("stream", ref.getName()); @@ -279,7 +280,7 @@ void resolveReferenceToMethodCalledOnArrayAccess() { Path src = adaptPath("src/test/resources"); TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src, new LeanParserConfiguration())); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); MethodUsage ref = symbolSolver.solveMethod("trim", Collections.emptyList(), callToTrim); assertEquals("trim", ref.getName()); @@ -336,7 +337,7 @@ void resolveReferenceToLambdaParamSimplified() { MethodCallExpr call = Navigator.findMethodCall(method, "isEmpty").get(); TypeSolver typeSolver = new ReflectionTypeSolver(); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); MethodUsage ref = symbolSolver.solveMethod("isEmpty", Collections.emptyList(), call); assertEquals("isEmpty", ref.getName()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java index eb55ceec0b..c9c3c83bd5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; @@ -80,7 +81,7 @@ void accessClassFieldThroughThisWithCompetingSymbolInParentContext() { Path src = adaptPath("src/test/resources"); CombinedTypeSolver typeSolver = new CombinedTypeSolver(new JavaParserTypeSolver(src, new LeanParserConfiguration()), new ReflectionTypeSolver()); - SymbolSolver symbolSolver = new SymbolSolver(typeSolver); + Solver symbolSolver = new SymbolSolver(typeSolver); SymbolReference ref = symbolSolver.solveSymbol(fieldAccessExpr.getName().getId(), fieldAccessExpr); assertTrue(ref.isSolved()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java index 97d0349478..91a037f3a4 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -57,7 +58,7 @@ void resolveFieldWithGenericTypeToString() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics"); VariableDeclarator fieldS = Navigator.demandField(clazz, "s"); - SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); Optional symbolReference = symbolSolver.solveSymbolAsValue("s", fieldS); assertEquals(true, symbolReference.isPresent()); @@ -74,7 +75,7 @@ void resolveFieldWithGenericTypeToDeclaredClass() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics"); VariableDeclarator fieldS = Navigator.demandField(clazz, "g"); - SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); Optional symbolReference = symbolSolver.solveSymbolAsValue("g", fieldS); assertEquals(true, symbolReference.isPresent()); @@ -91,7 +92,7 @@ void resolveFieldWithGenericTypeToInteger() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics"); VariableDeclarator fieldS = Navigator.demandField(clazz, "i"); - SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); Optional symbolReference = symbolSolver.solveSymbolAsValue("i", fieldS); assertEquals(true, symbolReference.isPresent()); @@ -108,7 +109,7 @@ void resolveFieldOfVariableType() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection"); VariableDeclarator field = Navigator.demandField(clazz, "a"); - SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); Optional symbolReference = symbolSolver.solveSymbolAsValue("a", field); assertEquals(true, symbolReference.isPresent()); @@ -125,7 +126,7 @@ void resolveFieldOfGenericReferringToVariableType() { ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection"); VariableDeclarator field = Navigator.demandField(clazz, "as"); - SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); Optional symbolReference = symbolSolver.solveSymbolAsValue("as", field); assertEquals(true, symbolReference.isPresent()); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java index c0676f1403..dfbed29392 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; @@ -44,7 +45,7 @@ class SymbolSolverTest extends AbstractSymbolResolutionTest { private TypeSolver typeSolverNewCode; - private SymbolSolver symbolSolver; + private Solver symbolSolver; @BeforeEach void setup() { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java index 2246ad0623..9981617e5e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistClassTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -40,7 +41,7 @@ class SymbolSolverWithJavassistClassTest extends AbstractSymbolResolutionTest { private TypeSolver typeSolver; - private SymbolSolver symbolSolver; + private Solver symbolSolver; private JavassistClassDeclaration classDeclarationConcreteClass; private JavassistClassDeclaration classDeclarationSubClassOwnJar; private JavassistClassDeclaration classDeclarationInterfaceUserOwnJar; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java index bb592bfd36..133e22f2d8 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistEnumTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -40,7 +41,7 @@ class SymbolSolverWithJavassistEnumTest extends AbstractSymbolResolutionTest { private TypeSolver typeSolver; - private SymbolSolver symbolSolver; + private Solver symbolSolver; private JavassistEnumDeclaration enumDeclarationConcrete; private JavassistEnumDeclaration enumDeclarationInterfaceUserOwnJar; private JavassistEnumDeclaration enumDeclarationInterfaceUserIncludedJar; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java index 7c73727236..0af14e1ead 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/SymbolSolverWithJavassistInterfaceTest.java @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.resolution; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -40,7 +41,7 @@ class SymbolSolverWithJavassistInterfaceTest extends AbstractSymbolResolutionTest { private TypeSolver typeSolver; - private SymbolSolver symbolSolver; + private Solver symbolSolver; private JavassistInterfaceDeclaration interfaceDeclarationStandalone; private JavassistInterfaceDeclaration interfaceDeclarationSubInterfaceOwnJar; private JavassistInterfaceDeclaration interfaceDeclarationSubInterfaceIncludedJar; From c9292ac57f6bba2fe81b3769f088991e6c9a518c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 18:08:04 +0100 Subject: [PATCH 114/280] Moving Navigator to JP core module --- .../javaparser/resolution}/Navigator.java | 2 +- .../context/AbstractJavaParserContext.java | 307 ++++++++++++++++++ .../symbolsolver/SourceFileInfoExtractor.java | 2 +- .../javaparsermodel/JavaParserFacade.java | 2 +- .../javaparsermodel/JavaParserFactory.java | 2 +- .../javaparsermodel/TypeExtractor.java | 2 +- .../contexts/AbstractJavaParserContext.java | 2 +- .../contexts/FieldAccessContext.java | 4 +- .../contexts/ForEachStatementContext.java | 4 +- .../contexts/ForStatementContext.java | 4 +- .../contexts/LambdaExprContext.java | 4 +- .../contexts/MethodReferenceExprContext.java | 4 +- .../contexts/ObjectCreationContext.java | 2 +- .../contexts/SwitchEntryContext.java | 4 +- .../contexts/TryWithResourceContext.java | 4 +- .../JavaParserEnumConstantDeclaration.java | 4 +- .../JavaParserFieldDeclaration.java | 2 +- .../JavaParserMethodDeclaration.java | 4 +- .../JavaParserSymbolDeclaration.java | 2 +- .../declarations/JavaParserTypeParameter.java | 2 +- .../JavaParserVariableDeclaration.java | 4 +- .../typesolvers/JavaParserTypeSolver.java | 2 +- .../symbolsolver/FindingAllFieldsTest.java | 2 +- .../javaparser/symbolsolver/Issue116Test.java | 2 +- .../javaparser/symbolsolver/Issue128Test.java | 2 +- .../javaparser/symbolsolver/Issue144Test.java | 2 +- .../javaparser/symbolsolver/Issue156Test.java | 2 +- .../symbolsolver/Issue1827Test.java | 2 +- .../javaparser/symbolsolver/Issue185Test.java | 2 +- .../javaparser/symbolsolver/Issue186Test.java | 2 +- .../javaparser/symbolsolver/Issue18Test.java | 2 +- .../javaparser/symbolsolver/Issue200Test.java | 2 +- .../symbolsolver/Issue2210Test.java | 2 +- .../javaparser/symbolsolver/Issue232Test.java | 2 +- .../javaparser/symbolsolver/Issue235Test.java | 2 +- .../javaparser/symbolsolver/Issue241Test.java | 2 +- .../javaparser/symbolsolver/Issue251Test.java | 2 +- .../javaparser/symbolsolver/Issue276Test.java | 2 +- .../javaparser/symbolsolver/Issue300Test.java | 2 +- .../symbolsolver/Issue3028Test.java | 2 +- .../javaparser/symbolsolver/Issue314Test.java | 2 +- .../symbolsolver/Issue3272Test.java | 2 +- .../javaparser/symbolsolver/Issue347Test.java | 2 +- .../javaparser/symbolsolver/Issue84Test.java | 2 +- .../DifferentiateDotExpressionTest.java | 2 +- ...lassOrInterfaceDeclarationContextTest.java | 2 +- ...vaParserAnonymousClassDeclarationTest.java | 2 +- .../JavaParserClassDeclarationTest.java | 2 +- ...JavaParserTypeVariableDeclarationTest.java | 2 +- .../resolution/AnnotationsResolutionTest.java | 2 +- .../CompilationUnitContextResolutionTest.java | 2 +- .../ConstructorsResolutionTest.java | 2 +- .../symbolsolver/resolution/ContextTest.java | 2 +- .../resolution/EnumResolutionTest.java | 2 +- .../FieldAccessExprResolutionTest.java | 2 +- .../resolution/FieldsResolutionTest.java | 2 +- .../resolution/GenericsResolutionTest.java | 2 +- ...plementedOrExtendedTypeResolutionTest.java | 2 +- .../JavaParserFacadeResolutionTest.java | 2 +- .../LambdaGenericResolutionTest.java | 2 +- .../resolution/LambdaResolutionTest.java | 2 +- .../resolution/MethodLikeSignaturesTest.java | 2 +- .../MethodReferenceResolutionTest.java | 2 +- .../resolution/MethodsResolutionTest.java | 2 +- .../MethodsResolutionWithJavassistTest.java | 2 +- .../resolution/NotQuiteCyclicParentTest.java | 2 +- .../QualifiedNameResolutionTest.java | 2 +- .../StatementContextResolutionTest.java | 2 +- ...TypeInClassWithAnnotationAncestorTest.java | 2 +- .../TypeResolutionWithSameNameTest.java | 2 +- .../UnknownMethodsResolutionTest.java | 2 +- .../resolution/VariableResolutionTest.java | 2 +- .../resolution/VariadicResolutionTest.java | 2 +- ...rfaceDeclarationContextResolutionTest.java | 2 +- .../EnumDeclarationContextResolutionTest.java | 2 +- .../FieldAccessContextResolutionTest.java | 2 +- .../LambdaExprContextResolutionTest.java | 2 +- .../MethodCallExprContextResolutionTest.java | 2 +- .../contexts/MethodContextResolutionTest.java | 2 +- ...JavaParserTypeParameterResolutionTest.java | 2 +- .../SymbolResolutionResolutionTest.java | 2 +- 81 files changed, 397 insertions(+), 90 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser => javaparser-core/src/main/java/com/github/javaparser/resolution}/Navigator.java (99%) create mode 100644 javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Navigator.java similarity index 99% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/Navigator.java index b0a46db2b2..4bd7c686e4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Navigator.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.javaparser; +package com.github.javaparser.resolution; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java new file mode 100644 index 0000000000..ceba19736c --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2015-2016 Federico Tomassetti + * Copyright (C) 2017-2020 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +package com.github.javaparser.symbolsolver.javaparsermodel.contexts; + +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.*; +import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; +import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.UnsolvedSymbolException; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.types.ResolvedReferenceType; +import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; +import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; +import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; +import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; +import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; +import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; + +import java.util.*; + +import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static java.util.Collections.singletonList; + +/** + * @author Federico Tomassetti + */ +public abstract class AbstractJavaParserContext implements Context { + + protected N wrappedNode; + protected TypeSolver typeSolver; + + /// + /// Static methods + /// + + protected static boolean isQualifiedName(String name) { + return name.contains("."); + } + + public static SymbolReference solveWith(SymbolDeclarator symbolDeclarator, String name) { + for (ResolvedValueDeclaration decl : symbolDeclarator.getSymbolDeclarations()) { + if (decl.getName().equals(name)) { + return SymbolReference.solved(decl); + } + } + return SymbolReference.unsolved(); + } + + /// + /// Constructors + /// + + public AbstractJavaParserContext(N wrappedNode, TypeSolver typeSolver) { + if (wrappedNode == null) { + throw new NullPointerException(); + } + this.wrappedNode = wrappedNode; + this.typeSolver = typeSolver; + } + + /// + /// Public methods + /// + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AbstractJavaParserContext that = (AbstractJavaParserContext) o; + + return wrappedNode != null ? wrappedNode.equals(that.wrappedNode) : that.wrappedNode == null; + } + + @Override + public int hashCode() { + return wrappedNode == null ? 0 : wrappedNode.hashCode(); + } + + @Override + public final Optional getParent() { + Node parentNode = wrappedNode.getParentNode().orElse(null); + + // TODO/FiXME: Document why the method call expression is treated differently. + if (parentNode instanceof MethodCallExpr) { + MethodCallExpr parentCall = (MethodCallExpr) parentNode; + // TODO: Can this be replaced with: boolean found = parentCall.getArguments().contains(wrappedNode); + boolean found = false; + for (Expression expression : parentCall.getArguments()) { + if (expression == wrappedNode) { + found = true; + break; + } + } + if (found) { + Node notMethod = parentNode; + while (notMethod instanceof MethodCallExpr) { + notMethod = demandParentNode(notMethod); + } + return Optional.of(JavaParserFactory.getContext(notMethod, typeSolver)); + } + } + Node notMethodNode = parentNode; + // to avoid an infinite loop if parent scope is the same as wrapped node + while (notMethodNode instanceof MethodCallExpr || notMethodNode instanceof FieldAccessExpr + || (notMethodNode != null && notMethodNode.hasScope() && getScope(notMethodNode).equals(wrappedNode)) ) { + notMethodNode = notMethodNode.getParentNode().orElse(null); + } + if (notMethodNode == null) { + return Optional.empty(); + } + Context parentContext = JavaParserFactory.getContext(notMethodNode, typeSolver); + return Optional.of(parentContext); + } + + // before to call this method verify the node has a scope + protected Node getScope(Node node) { + return (Node) ((NodeWithOptionalScope)node).getScope().get(); + } + + + @Override + public SymbolReference solveSymbolInParentContext(String name) { + Optional optionalParentContext = getParent(); + if (!optionalParentContext.isPresent()) { + return SymbolReference.unsolved(); + } + + // First check if there are any pattern expressions available to this node. + Context parentContext = optionalParentContext.get(); + if(parentContext instanceof BinaryExprContext || parentContext instanceof IfStatementContext) { + List patternExprs = parentContext.patternExprsExposedToChild(this.getWrappedNode()); + + Optional localResolutionResults = patternExprs + .stream() + .filter(vd -> vd.getNameAsString().equals(name)) + .findFirst(); + + if (localResolutionResults.isPresent()) { + if(patternExprs.size() == 1) { + JavaParserPatternDeclaration decl = JavaParserSymbolDeclaration.patternVar(localResolutionResults.get(), typeSolver); + return SymbolReference.solved(decl); + } else if(patternExprs.size() > 1) { + throw new IllegalStateException("Unexpectedly more than one reference in scope"); + } + } + } + + // Delegate solving to the parent context. + return parentContext.solveSymbol(name); + } + + /// + /// Protected methods + /// + + protected Optional solveWithAsValue(SymbolDeclarator symbolDeclarator, String name) { + return symbolDeclarator.getSymbolDeclarations().stream() + .filter(d -> d.getName().equals(name)) + .map(Value::from) + .findFirst(); + } + + protected Collection findTypeDeclarations(Optional optScope) { + if (optScope.isPresent()) { + Expression scope = optScope.get(); + + // consider static methods + if (scope instanceof NameExpr) { + NameExpr scopeAsName = scope.asNameExpr(); + SymbolReference symbolReference = this.solveType(scopeAsName.getName().getId()); + if (symbolReference.isSolved() && symbolReference.getCorrespondingDeclaration().isType()) { + return singletonList(symbolReference.getCorrespondingDeclaration().asReferenceType()); + } + } + + ResolvedType typeOfScope; + try { + typeOfScope = JavaParserFacade.get(typeSolver).getType(scope); + } catch (Exception e) { + // If the scope corresponds to a type we should treat it differently + if (scope instanceof FieldAccessExpr) { + FieldAccessExpr scopeName = (FieldAccessExpr) scope; + if (this.solveType(scopeName.toString()).isSolved()) { + return Collections.emptyList(); + } + } + throw new UnsolvedSymbolException(scope.toString(), wrappedNode.toString(), e); + } + if (typeOfScope.isWildcard()) { + if (typeOfScope.asWildcard().isExtends() || typeOfScope.asWildcard().isSuper()) { + // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... + return singletonList( + typeOfScope.asWildcard() + .getBoundedType() + .asReferenceType() + .getTypeDeclaration() + .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) + ); + } else { + return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); + } + } else if (typeOfScope.isArray()) { + // method call on array are Object methods + return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); + } else if (typeOfScope.isTypeVariable()) { + Collection result = new ArrayList<>(); + for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { + // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... + result.add( + bound.getType() + .asReferenceType() + .getTypeDeclaration() + .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) + ); + } + return result; + } else if (typeOfScope.isConstraint()) { + // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... + return singletonList( + typeOfScope.asConstraintType() + .getBound() + .asReferenceType() + .getTypeDeclaration() + .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) + ); + } else if (typeOfScope.isUnionType()) { + return typeOfScope.asUnionType().getCommonAncestor() + .flatMap(ResolvedReferenceType::getTypeDeclaration) + .map(Collections::singletonList) + .orElseThrow(() -> new UnsolvedSymbolException("No common ancestor available for UnionType" + typeOfScope.describe())); + } + + // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... + return singletonList( + typeOfScope.asReferenceType() + .getTypeDeclaration() + .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) + ); + } + + ResolvedType typeOfScope = JavaParserFacade.get(typeSolver).getTypeOfThisIn(wrappedNode); + + // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... + return singletonList( + typeOfScope.asReferenceType() + .getTypeDeclaration() + .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) + ); + } + + /** + * Similar to solveMethod but we return a MethodUsage. + * A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables. + */ + public Optional solveMethodAsUsage(String name, List argumentsTypes) { + SymbolReference methodSolved = solveMethod(name, argumentsTypes, false); + if (methodSolved.isSolved()) { + ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration(); + if (!(methodDeclaration instanceof TypeVariableResolutionCapability)) { + throw new UnsupportedOperationException(String.format( + "Resolved method declarations must implement %s.", + TypeVariableResolutionCapability.class.getName() + )); + } + + MethodUsage methodUsage = ((TypeVariableResolutionCapability) methodDeclaration).resolveTypeVariables(this, argumentsTypes); + return Optional.of(methodUsage); + } else { + return Optional.empty(); + } + } + + @Override + public N getWrappedNode() { + return wrappedNode; + } +} diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java index eed469cd3e..d4dbed4765 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/SourceFileInfoExtractor.java @@ -51,7 +51,7 @@ import java.util.List; import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import static java.util.Comparator.comparing; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index da91b513ef..a842b31ef0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -57,9 +57,9 @@ import java.util.*; import java.util.stream.Collectors; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import static com.github.javaparser.resolution.model.SymbolReference.solved; import static com.github.javaparser.resolution.model.SymbolReference.unsolved; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; /** * Class to be used by final users to solve symbols for JavaParser ASTs. diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java index 792f3bde63..d7bbae8a0a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index cd645194c6..5266afdc06 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -62,7 +62,7 @@ import java.util.List; import java.util.Optional; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import static com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solveGenericTypes; public class TypeExtractor extends DefaultVisitorAdapter { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index ceba19736c..e85f284ed3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -47,7 +47,7 @@ import java.util.*; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import static java.util.Collections.singletonList; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java index 8bc1f206ce..977477d473 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/FieldAccessContext.java @@ -35,12 +35,12 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.Collection; import java.util.List; import java.util.Optional; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - /** * @author Federico Tomassetti */ diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java index f855c9d359..881d22bf47 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForEachStatementContext.java @@ -32,11 +32,11 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.Collections; import java.util.List; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - public class ForEachStatementContext extends AbstractJavaParserContext { public ForEachStatementContext(ForEachStmt wrappedNode, TypeSolver typeSolver) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java index ddde217c27..6996f6825b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ForStatementContext.java @@ -37,11 +37,11 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.LinkedList; import java.util.List; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - public class ForStatementContext extends AbstractJavaParserContext { public ForStatementContext(ForStmt wrappedNode, TypeSolver typeSolver) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 3afe567f44..384d3b7616 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -48,14 +48,14 @@ import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - /** * @author Federico Tomassetti */ diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 56d5f85436..e9e8fc2e67 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -42,9 +42,9 @@ import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; -import java.util.*; +import static com.github.javaparser.resolution.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import java.util.*; public class MethodReferenceExprContext extends AbstractJavaParserContext { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java index 001c2d0eb3..df88d68984 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ObjectCreationContext.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java index f8235dca5b..2b2e362180 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java @@ -35,9 +35,9 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; -import java.util.List; +import static com.github.javaparser.resolution.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import java.util.List; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java index 8365ceb907..d9974d6ad9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/TryWithResourceContext.java @@ -36,14 +36,14 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - public class TryWithResourceContext extends AbstractJavaParserContext { public TryWithResourceContext(TryStmt wrappedNode, TypeSolver typeSolver) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java index a35c3484c5..f02b4b7876 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumConstantDeclaration.java @@ -21,14 +21,14 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - /** * @author Federico Tomassetti */ diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java index e796094c34..4b8f3fcddb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserFieldDeclaration.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java index 0841a5d35b..30da374231 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java @@ -38,12 +38,12 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - /** * @author Federico Tomassetti */ diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java index 6cfd9cff12..bb762dbab5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.Parameter; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java index 09fb5dc681..4524720818 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeParameter.java @@ -21,7 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import static com.github.javaparser.resolution.Navigator.demandParentNode; import java.util.ArrayList; import java.util.Collections; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java index 8d9230fac9..a83f8b07f8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserVariableDeclaration.java @@ -29,9 +29,9 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import java.util.Optional; +import static com.github.javaparser.resolution.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; +import java.util.Optional; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java index 444c7b56c1..90fb861eb9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/JavaParserTypeSolver.java @@ -24,12 +24,12 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; import com.github.javaparser.symbolsolver.cache.GuavaCache; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.utils.FileUtils; import com.google.common.cache.CacheBuilder; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/FindingAllFieldsTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/FindingAllFieldsTest.java index 808333dca9..9816c85260 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/FindingAllFieldsTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/FindingAllFieldsTest.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java index 12737c61f9..c750c3aca2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue116Test.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java index ec0e42ebc8..5f9cfd5a99 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue128Test.java @@ -25,8 +25,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java index bd9aa9968f..0053ed739e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue144Test.java @@ -26,8 +26,8 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java index 00e32e8649..3b60bf0ee3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue156Test.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java index 5d1b654349..5eac63bd04 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue1827Test.java @@ -8,8 +8,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue185Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue185Test.java index f78ea4cfdf..ee29eb7fec 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue185Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue185Test.java @@ -23,7 +23,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java index ac6508ce62..65d0226600 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue186Test.java @@ -26,8 +26,8 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java index eb522a2dbe..23e4369135 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue18Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java index 7b8c7be7d6..5ddd73d05e 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue200Test.java @@ -25,8 +25,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java index e2f75f4fb6..658cc13500 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2210Test.java @@ -9,8 +9,8 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java index 51df878768..ef2c71c85b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue232Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java index b941e2d514..dd4f82b708 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue235Test.java @@ -26,8 +26,8 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java index 21ac475eb9..01018907c3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue241Test.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java index 18cd20f4eb..4099776e83 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue251Test.java @@ -26,8 +26,8 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java index d69bb5fc1f..24853821d2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue276Test.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java index 9bbe86d915..023da62640 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue300Test.java @@ -23,11 +23,11 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java index b73b7f3b05..6a777b3064 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3028Test.java @@ -7,9 +7,9 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java index 1ff5c2f936..087d9b01f0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue314Test.java @@ -23,11 +23,11 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.*; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3272Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3272Test.java index 06af0a37f8..a473885fa8 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3272Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3272Test.java @@ -4,8 +4,8 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.LambdaExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java index 365c733739..cc82f9a91d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue347Test.java @@ -23,9 +23,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.FieldDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue84Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue84Test.java index 0fe3626ce8..243afe9a48 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue84Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue84Test.java @@ -23,8 +23,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java index c170b44d52..e5d4c04171 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/DifferentiateDotExpressionTest.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java index 2989915e84..76cbc601e5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/ClassOrInterfaceDeclarationContextTest.java @@ -25,10 +25,10 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclarationTest.java index 1ed0f8ffae..66fda42aeb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserAnonymousClassDeclarationTest.java @@ -29,7 +29,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java index dd76f49f35..034d101c2a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserClassDeclarationTest.java @@ -47,6 +47,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -61,7 +62,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java index 5681e28a4c..41518d369d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclarationTest.java @@ -25,10 +25,10 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.AssociableToASTTest; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclarationTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnnotationsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnnotationsResolutionTest.java index c02b8e400e..63762faf67 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnnotationsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AnnotationsResolutionTest.java @@ -46,13 +46,13 @@ import com.github.javaparser.ast.expr.NormalAnnotationExpr; import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; import com.github.javaparser.symbolsolver.javassistmodel.JavassistAnnotationDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/CompilationUnitContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/CompilationUnitContextResolutionTest.java index 763976ab82..0b6efe6b75 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/CompilationUnitContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/CompilationUnitContextResolutionTest.java @@ -23,10 +23,10 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java index 96a4ff6ddf..68b7754195 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConstructorsResolutionTest.java @@ -30,12 +30,12 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java index 40587819c1..ba41193ad0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ContextTest.java @@ -62,6 +62,7 @@ import com.github.javaparser.ast.stmt.TryStmt; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; @@ -71,7 +72,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java index 8d2507e872..915385553a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/EnumResolutionTest.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -40,7 +41,6 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldAccessExprResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldAccessExprResolutionTest.java index af3f3d8d9c..a21d143481 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldAccessExprResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldAccessExprResolutionTest.java @@ -33,8 +33,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; /** diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java index c9c3c83bd5..d61860e627 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/FieldsResolutionTest.java @@ -31,12 +31,12 @@ import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java index 91a037f3a4..e4e6225257 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/GenericsResolutionTest.java @@ -32,12 +32,12 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ImplementedOrExtendedTypeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ImplementedOrExtendedTypeResolutionTest.java index 217c305ad3..d8b81f0d76 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ImplementedOrExtendedTypeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ImplementedOrExtendedTypeResolutionTest.java @@ -22,10 +22,10 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import java.io.IOException; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 6f45208f17..8b31849760 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.stmt.CatchClause; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -39,7 +40,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedUnionType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java index 8e46bba956..99049990ce 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaGenericResolutionTest.java @@ -29,10 +29,10 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Assertions; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaResolutionTest.java index 8f1fd89a8d..3585745d79 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/LambdaResolutionTest.java @@ -27,8 +27,8 @@ import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodLikeSignaturesTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodLikeSignaturesTest.java index d113d577b7..2f01029061 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodLikeSignaturesTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodLikeSignaturesTest.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java index 2b2e281926..83dc98f5d0 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodReferenceResolutionTest.java @@ -35,11 +35,11 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; class MethodReferenceResolutionTest extends AbstractResolutionTest { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java index 0e9dac00c1..1e6a331e8d 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionTest.java @@ -32,13 +32,13 @@ import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java index 9f7d8b867e..100a27d8b5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionWithJavassistTest.java @@ -29,7 +29,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/NotQuiteCyclicParentTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/NotQuiteCyclicParentTest.java index 992514eddf..c914573aeb 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/NotQuiteCyclicParentTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/NotQuiteCyclicParentTest.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java index 9ea3ac4255..a58ff9ecd5 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/QualifiedNameResolutionTest.java @@ -24,9 +24,9 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java index 8805e2bc37..e9ca0d5f11 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/StatementContextResolutionTest.java @@ -26,10 +26,10 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java index 13d6c59e72..f8e103684a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeInClassWithAnnotationAncestorTest.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeResolutionWithSameNameTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeResolutionWithSameNameTest.java index 701fd7783e..b5eeee7b7b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeResolutionWithSameNameTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/TypeResolutionWithSameNameTest.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java index 7098b78af3..c2dfe56783 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/UnknownMethodsResolutionTest.java @@ -25,10 +25,10 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariableResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariableResolutionTest.java index d7fa31a444..81a4ed1db2 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariableResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariableResolutionTest.java @@ -5,7 +5,7 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.symbolsolver.javaparser.Navigator; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java index 612788c8a4..231e210226 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/VariadicResolutionTest.java @@ -36,9 +36,9 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java index 892ee7f861..e759386572 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/ClassOrInterfaceDeclarationContextResolutionTest.java @@ -35,6 +35,7 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -45,7 +46,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java index 78957ccb8b..97188d3ab1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/EnumDeclarationContextResolutionTest.java @@ -24,10 +24,10 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java index b36e402fbf..efe4de489b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/FieldAccessContextResolutionTest.java @@ -25,8 +25,8 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java index 8d3a79148e..67de7989dc 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/LambdaExprContextResolutionTest.java @@ -30,8 +30,8 @@ import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.model.Value; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java index 2ffba9837e..12852b9faa 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodCallExprContextResolutionTest.java @@ -44,6 +44,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -51,7 +52,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java index d723ef272c..26d14e73e1 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/contexts/MethodContextResolutionTest.java @@ -26,9 +26,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java index 38972012ce..aa905659aa 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/javaparser/declarations/JavaParserTypeParameterResolutionTest.java @@ -25,11 +25,11 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java index ff6edf8df5..3139ea0ac3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/reflectionmodel/SymbolResolutionResolutionTest.java @@ -28,9 +28,9 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.resolution.Navigator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; From b748e032a4a7054b7b63987f7098f284382a6594 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 18:33:54 +0100 Subject: [PATCH 115/280] Removing usage of JavaParserFacade to get Object declaration --- .../javaparsermodel/contexts/AbstractJavaParserContext.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index e85f284ed3..5abf471deb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -42,7 +42,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.*; @@ -227,11 +226,11 @@ protected Collection findTypeDeclarations(Opti .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) ); } else { - return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); + return singletonList(typeSolver.getSolvedJavaLangObject()); } } else if (typeOfScope.isArray()) { // method call on array are Object methods - return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); + return singletonList(typeSolver.getSolvedJavaLangObject()); } else if (typeOfScope.isTypeVariable()) { Collection result = new ArrayList<>(); for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { From 3a97c93355b20a973aede307df5f454aa81d046d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Dec 2022 22:26:55 +0100 Subject: [PATCH 116/280] Fix: issue on type solver setup --- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index a842b31ef0..dc379cd0f0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -129,7 +129,7 @@ protected static ResolvedType solveGenericTypes(ResolvedType type, Context conte private JavaParserFacade(TypeSolver typeSolver) { this.typeSolver = typeSolver.getRoot(); this.symbolSolver = new SymbolSolver(typeSolver); - this.typeExtractor = new TypeExtractor(typeSolver, this); + this.typeExtractor = new TypeExtractor(this.typeSolver, this); this.failureHandler = new FailureHandler(); } From 2eda7d2f97b72ccd89d30e4772e95be4228c7cda Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 09:03:08 +0100 Subject: [PATCH 117/280] Fix: Update ResolvedReferenceType.equals(..) to consider LazyType --- .../resolution/types/ResolvedReferenceType.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java index bc0d8bd31e..bf73d4dce4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java @@ -27,6 +27,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration.Bound; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParameterValueProvider; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; @@ -87,15 +88,27 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) + if (o == null || (!isLazyType(o) && getClass() != o.getClass()) + || (isLazyType(o) && !this.equals(asResolvedReferenceType(o)))) return false; - ResolvedReferenceType that = (ResolvedReferenceType) o; + ResolvedReferenceType that = asResolvedReferenceType(o); if (!typeDeclaration.equals(that.typeDeclaration)) return false; if (!typeParametersMap.equals(that.typeParametersMap)) return false; return true; } + + private boolean isLazyType(Object type) { + return type !=null && type instanceof LazyType; + } + + private ResolvedReferenceType asResolvedReferenceType(Object o) { + if (isLazyType(o)) { + return ((LazyType) o).asReferenceType(); + } + return ResolvedReferenceType.class.cast(o); + } @Override public int hashCode() { From 3b40ac21150124d27b789edcf26e215a740fe950 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 09:14:09 +0100 Subject: [PATCH 118/280] Fix: Consider a LazyType to resolve the String type reference in the TypeExtractor class so as not to have to systematically declare a ReflectionTypeSolver, adapt unit tests accordingly and classes that do not support LazyType --- .../symbolsolver/javaparsermodel/TypeExtractor.java | 8 +++++--- .../javaparsermodel/contexts/MethodCallExprContext.java | 3 +++ .../symbolsolver/resolution/typeinference/TypeHelper.java | 4 ++++ .../com/github/javaparser/symbolsolver/Issue343Test.java | 5 +++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 5266afdc06..7a5632d76d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -41,6 +41,7 @@ import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; @@ -68,7 +69,7 @@ public class TypeExtractor extends DefaultVisitorAdapter { private static final String JAVA_LANG_STRING = String.class.getCanonicalName(); - private final ReferenceTypeImpl stringReferenceType; + private final ResolvedType stringReferenceType; private TypeSolver typeSolver; private JavaParserFacade facade; @@ -77,8 +78,9 @@ public class TypeExtractor extends DefaultVisitorAdapter { public TypeExtractor(TypeSolver typeSolver, JavaParserFacade facade) { this.typeSolver = typeSolver; this.facade = facade; - //pre-calculate the String reference (optimization) - stringReferenceType = new ReferenceTypeImpl(new ReflectionTypeSolver().solveType(JAVA_LANG_STRING)); + // pre-calculate the String reference (optimization) + // consider a LazyType to avoid having to systematically declare a ReflectionTypeSolver + stringReferenceType = new LazyType(v -> new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_STRING))); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 90c6ce4b88..892360a01a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -33,6 +33,7 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -475,6 +476,8 @@ private Optional solveMethodAsUsage(ResolvedTypeVariable tp, String private Optional solveMethodAsUsage(ResolvedType type, String name, List argumentsTypes, Context invokationContext) { if (type instanceof ResolvedReferenceType) { return solveMethodAsUsage((ResolvedReferenceType) type, name, argumentsTypes, invokationContext); + } else if (type instanceof LazyType) { + return solveMethodAsUsage(type.asReferenceType(), name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedTypeVariable) { return solveMethodAsUsage((ResolvedTypeVariable) type, name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedWildcard) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java index 00a05456ab..cdd8fa5868 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/TypeHelper.java @@ -36,6 +36,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedIntersectionType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; @@ -67,6 +68,9 @@ public static boolean isProperType(ResolvedType type) { ResolvedReferenceType referenceType = (ResolvedReferenceType) type; return referenceType.typeParametersValues().stream().allMatch(it -> isProperType(it)); } + if (type instanceof LazyType) { + return type.asReferenceType().typeParametersValues().stream().allMatch(it -> isProperType(it)); + } if (type instanceof ResolvedWildcard) { ResolvedWildcard wildcard = (ResolvedWildcard)type; if (wildcard.isBounded()) { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java index f9cdc086c0..15b084827c 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java @@ -34,6 +34,7 @@ import static com.github.javaparser.StaticJavaParser.parseExpression; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Note this issue number refers to the archived `javasymbolsolver` repository, @@ -58,7 +59,7 @@ void setup() { @Test void resolveStringLiteralOutsideAST() { - assertEquals(javaParserFacade.classToResolvedType(String.class), getExpressionType(typeResolver, new StringLiteralExpr(""))); + assertTrue(javaParserFacade.classToResolvedType(String.class).equals(getExpressionType(typeResolver, new StringLiteralExpr("")))); } @Test @@ -79,7 +80,7 @@ void toResolveFloatWeNeedTheAST() { @Test void resolveMethodCallOnStringLiteralOutsideAST() { - assertEquals(javaParserFacade.classToResolvedType(int.class), getExpressionType(typeResolver, new MethodCallExpr(new StringLiteralExpr("hello"), "length"))); + assertTrue(javaParserFacade.classToResolvedType(int.class).equals(getExpressionType(typeResolver, new MethodCallExpr(new StringLiteralExpr("hello"), "length")))); } @Test From b178869522a6535969cda76f258918355a3ce4aa Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 10:43:53 +0100 Subject: [PATCH 119/280] Move SymbolDeclarator interface to JP core module --- .../com/github/javaparser}/resolution/SymbolDeclarator.java | 2 +- .../symbolsolver/javaparsermodel/JavaParserFactory.java | 2 +- .../javaparsermodel/contexts/AbstractJavaParserContext.java | 2 +- .../contexts/AbstractMethodLikeDeclarationContext.java | 2 +- .../javaparsermodel/contexts/CatchClauseContext.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../symbolsolver/javaparsermodel/contexts/StatementContext.java | 2 +- .../javaparsermodel/contexts/SwitchEntryContext.java | 2 +- .../javaparsermodel/declarators/AbstractSymbolDeclarator.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/SymbolDeclarator.java (94%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolDeclarator.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolDeclarator.java similarity index 94% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolDeclarator.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolDeclarator.java index 9a696adb45..984298859a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolDeclarator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolDeclarator.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.resolution; +package com.github.javaparser.resolution; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java index d7bbae8a0a..65e229d9c4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.*; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; @@ -44,7 +45,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarators.ParameterSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.PatternSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.VariableSymbolDeclarator; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 5abf471deb..31a48e4db7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -26,6 +26,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; @@ -42,7 +43,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java index 952b8d88f0..9859c5f0ca 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.java @@ -27,6 +27,7 @@ import com.github.javaparser.ast.nodeTypes.NodeWithParameters; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.List; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java index 5ed11c6e4e..c918fb1642 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CatchClauseContext.java @@ -25,6 +25,7 @@ import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.stmt.CatchClause; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; @@ -32,7 +33,6 @@ import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 384d3b7616..92b5734a6d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -32,6 +32,7 @@ import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -46,7 +47,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import static com.github.javaparser.resolution.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java index 523f012894..7765670a3f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/StatementContext.java @@ -30,6 +30,7 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; @@ -37,7 +38,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import java.util.Collections; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java index 2b2e362180..e48ec17b79 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/SwitchEntryContext.java @@ -24,6 +24,7 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.SwitchEntry; import com.github.javaparser.ast.stmt.SwitchStmt; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -33,7 +34,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; import static com.github.javaparser.resolution.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java index 3015988643..95601dc163 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarators/AbstractSymbolDeclarator.java @@ -22,8 +22,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarators; import com.github.javaparser.ast.Node; +import com.github.javaparser.resolution.SymbolDeclarator; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; /** * @author Federico Tomassetti From 8d34941dd94f24a53f61b96439ac1771549cd1f8 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 12:07:17 +0100 Subject: [PATCH 120/280] Removing dependency between TypeExtractor and JavaParserFacade --- .../resolution/types/ResolvedType.java | 8 ++++++++ .../resolution/types/ResolvedTypeVariable.java | 9 +++++++++ .../resolution/types/ResolvedWildcard.java | 17 +++++++++++++++++ .../javaparsermodel/JavaParserFacade.java | 18 ------------------ .../javaparsermodel/TypeExtractor.java | 6 ++---- .../contexts/AbstractJavaParserContext.java | 1 + 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java index 8c982e3107..cf5a02fe13 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java @@ -20,6 +20,7 @@ */ package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import java.util.Arrays; @@ -230,4 +231,11 @@ default boolean isNumericType() { default ResolvedType erasure() { return this; } + + /* + * Returns the resolved type for a type variable or the bounded resolved type or the type itself. + */ + default ResolvedType solveGenericTypes(Context context) { + return this; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java index 762130ebba..e65291288b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java @@ -20,6 +20,7 @@ */ package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import java.util.List; @@ -135,4 +136,12 @@ public ResolvedType erasure() { } return typeParameter.object(); } + + /* + * Returns the resolved type for a type variable. + */ + @Override + public ResolvedType solveGenericTypes(Context context) { + return context.solveGenericType(describe()).orElse(this); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java index cb887ad7aa..49cb3f578a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java @@ -20,6 +20,7 @@ */ package com.github.javaparser.resolution.types; +import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import java.util.List; @@ -177,4 +178,20 @@ public enum BoundType { SUPER, EXTENDS } + + /* + * Returns the bounded resolved type. + */ + @Override + public ResolvedType solveGenericTypes(Context context) { + if (isExtends() || isSuper()) { + ResolvedType boundResolved = getBoundedType().solveGenericTypes(context); + if (isExtends()) { + return ResolvedWildcard.extendsBound(boundResolved); + } else { + return ResolvedWildcard.superBound(boundResolved); + } + } + return this; + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index dc379cd0f0..11f10717f1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -100,24 +100,6 @@ public static void clearInstances() { instances.clear(); } - protected static ResolvedType solveGenericTypes(ResolvedType type, Context context) { - if (type.isTypeVariable()) { - return context.solveGenericType(type.describe()).orElse(type); - } - if (type.isWildcard()) { - if (type.asWildcard().isExtends() || type.asWildcard().isSuper()) { - ResolvedWildcard wildcardUsage = type.asWildcard(); - ResolvedType boundResolved = solveGenericTypes(wildcardUsage.getBoundedType(), context); - if (wildcardUsage.isExtends()) { - return ResolvedWildcard.extendsBound(boundResolved); - } else { - return ResolvedWildcard.superBound(boundResolved); - } - } - } - return type; - } - // End of static class private final TypeSolver typeSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 7a5632d76d..bc904c9107 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -55,7 +55,6 @@ import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprHandler; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprResolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.Log; import com.github.javaparser.utils.Pair; import com.google.common.collect.ImmutableList; @@ -64,7 +63,6 @@ import java.util.Optional; import static com.github.javaparser.resolution.Navigator.demandParentNode; -import static com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solveGenericTypes; public class TypeExtractor extends DefaultVisitorAdapter { @@ -524,7 +522,7 @@ public ResolvedType visit(LambdaExpr node, Boolean solveLambdas) { private ResolvedType resolveLambda(LambdaExpr node, ResolvedType result) { // We need to replace the type variables Context ctx = JavaParserFactory.getContext(node, typeSolver); - result = solveGenericTypes(result, ctx); + result = result.solveGenericTypes(ctx); //We should find out which is the functional method (e.g., apply) and replace the params of the //solveLambdas with it, to derive so the values. We should also consider the value returned by the @@ -601,7 +599,7 @@ public ResolvedType visit(MethodReferenceExpr node, Boolean solveLambdas) { ResolvedType result = usage.getParamType(pos); // We need to replace the type variables Context ctx = JavaParserFactory.getContext(node, typeSolver); - result = solveGenericTypes(result, ctx); + result = result.solveGenericTypes(ctx); //We should find out which is the functional method (e.g., apply) and replace the params of the //solveLambdas with it, to derive so the values. We should also consider the value returned by the diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java index 31a48e4db7..1443ef6797 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java @@ -46,6 +46,7 @@ import java.util.*; +import com.github.javaparser.resolution.Context; import static com.github.javaparser.resolution.Navigator.demandParentNode; import static java.util.Collections.singletonList; From c4e8194397e83ef913f90b8a47256c1c33df2219 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 12:08:33 +0100 Subject: [PATCH 121/280] Reverting the move of the class AbstractJavaParserContext to JP core module --- .../context/AbstractJavaParserContext.java | 307 ------------------ 1 file changed, 307 deletions(-) delete mode 100644 javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java deleted file mode 100644 index ceba19736c..0000000000 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/context/AbstractJavaParserContext.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2015-2016 Federico Tomassetti - * Copyright (C) 2017-2020 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser can be used either under the terms of - * a) the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * b) the terms of the Apache License - * - * You should have received a copy of both licenses in LICENCE.LGPL and - * LICENCE.APACHE. Please refer to those files for details. - * - * JavaParser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ - -package com.github.javaparser.symbolsolver.javaparsermodel.contexts; - -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope; -import com.github.javaparser.resolution.Context; -import com.github.javaparser.resolution.MethodUsage; -import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; -import com.github.javaparser.resolution.model.SymbolReference; -import com.github.javaparser.resolution.model.Value; -import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserPatternDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; - -import java.util.*; - -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; -import static java.util.Collections.singletonList; - -/** - * @author Federico Tomassetti - */ -public abstract class AbstractJavaParserContext implements Context { - - protected N wrappedNode; - protected TypeSolver typeSolver; - - /// - /// Static methods - /// - - protected static boolean isQualifiedName(String name) { - return name.contains("."); - } - - public static SymbolReference solveWith(SymbolDeclarator symbolDeclarator, String name) { - for (ResolvedValueDeclaration decl : symbolDeclarator.getSymbolDeclarations()) { - if (decl.getName().equals(name)) { - return SymbolReference.solved(decl); - } - } - return SymbolReference.unsolved(); - } - - /// - /// Constructors - /// - - public AbstractJavaParserContext(N wrappedNode, TypeSolver typeSolver) { - if (wrappedNode == null) { - throw new NullPointerException(); - } - this.wrappedNode = wrappedNode; - this.typeSolver = typeSolver; - } - - /// - /// Public methods - /// - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - AbstractJavaParserContext that = (AbstractJavaParserContext) o; - - return wrappedNode != null ? wrappedNode.equals(that.wrappedNode) : that.wrappedNode == null; - } - - @Override - public int hashCode() { - return wrappedNode == null ? 0 : wrappedNode.hashCode(); - } - - @Override - public final Optional getParent() { - Node parentNode = wrappedNode.getParentNode().orElse(null); - - // TODO/FiXME: Document why the method call expression is treated differently. - if (parentNode instanceof MethodCallExpr) { - MethodCallExpr parentCall = (MethodCallExpr) parentNode; - // TODO: Can this be replaced with: boolean found = parentCall.getArguments().contains(wrappedNode); - boolean found = false; - for (Expression expression : parentCall.getArguments()) { - if (expression == wrappedNode) { - found = true; - break; - } - } - if (found) { - Node notMethod = parentNode; - while (notMethod instanceof MethodCallExpr) { - notMethod = demandParentNode(notMethod); - } - return Optional.of(JavaParserFactory.getContext(notMethod, typeSolver)); - } - } - Node notMethodNode = parentNode; - // to avoid an infinite loop if parent scope is the same as wrapped node - while (notMethodNode instanceof MethodCallExpr || notMethodNode instanceof FieldAccessExpr - || (notMethodNode != null && notMethodNode.hasScope() && getScope(notMethodNode).equals(wrappedNode)) ) { - notMethodNode = notMethodNode.getParentNode().orElse(null); - } - if (notMethodNode == null) { - return Optional.empty(); - } - Context parentContext = JavaParserFactory.getContext(notMethodNode, typeSolver); - return Optional.of(parentContext); - } - - // before to call this method verify the node has a scope - protected Node getScope(Node node) { - return (Node) ((NodeWithOptionalScope)node).getScope().get(); - } - - - @Override - public SymbolReference solveSymbolInParentContext(String name) { - Optional optionalParentContext = getParent(); - if (!optionalParentContext.isPresent()) { - return SymbolReference.unsolved(); - } - - // First check if there are any pattern expressions available to this node. - Context parentContext = optionalParentContext.get(); - if(parentContext instanceof BinaryExprContext || parentContext instanceof IfStatementContext) { - List patternExprs = parentContext.patternExprsExposedToChild(this.getWrappedNode()); - - Optional localResolutionResults = patternExprs - .stream() - .filter(vd -> vd.getNameAsString().equals(name)) - .findFirst(); - - if (localResolutionResults.isPresent()) { - if(patternExprs.size() == 1) { - JavaParserPatternDeclaration decl = JavaParserSymbolDeclaration.patternVar(localResolutionResults.get(), typeSolver); - return SymbolReference.solved(decl); - } else if(patternExprs.size() > 1) { - throw new IllegalStateException("Unexpectedly more than one reference in scope"); - } - } - } - - // Delegate solving to the parent context. - return parentContext.solveSymbol(name); - } - - /// - /// Protected methods - /// - - protected Optional solveWithAsValue(SymbolDeclarator symbolDeclarator, String name) { - return symbolDeclarator.getSymbolDeclarations().stream() - .filter(d -> d.getName().equals(name)) - .map(Value::from) - .findFirst(); - } - - protected Collection findTypeDeclarations(Optional optScope) { - if (optScope.isPresent()) { - Expression scope = optScope.get(); - - // consider static methods - if (scope instanceof NameExpr) { - NameExpr scopeAsName = scope.asNameExpr(); - SymbolReference symbolReference = this.solveType(scopeAsName.getName().getId()); - if (symbolReference.isSolved() && symbolReference.getCorrespondingDeclaration().isType()) { - return singletonList(symbolReference.getCorrespondingDeclaration().asReferenceType()); - } - } - - ResolvedType typeOfScope; - try { - typeOfScope = JavaParserFacade.get(typeSolver).getType(scope); - } catch (Exception e) { - // If the scope corresponds to a type we should treat it differently - if (scope instanceof FieldAccessExpr) { - FieldAccessExpr scopeName = (FieldAccessExpr) scope; - if (this.solveType(scopeName.toString()).isSolved()) { - return Collections.emptyList(); - } - } - throw new UnsolvedSymbolException(scope.toString(), wrappedNode.toString(), e); - } - if (typeOfScope.isWildcard()) { - if (typeOfScope.asWildcard().isExtends() || typeOfScope.asWildcard().isSuper()) { - // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... - return singletonList( - typeOfScope.asWildcard() - .getBoundedType() - .asReferenceType() - .getTypeDeclaration() - .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) - ); - } else { - return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); - } - } else if (typeOfScope.isArray()) { - // method call on array are Object methods - return singletonList(new ReflectionClassDeclaration(Object.class, typeSolver).asReferenceType()); - } else if (typeOfScope.isTypeVariable()) { - Collection result = new ArrayList<>(); - for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { - // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... - result.add( - bound.getType() - .asReferenceType() - .getTypeDeclaration() - .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) - ); - } - return result; - } else if (typeOfScope.isConstraint()) { - // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... - return singletonList( - typeOfScope.asConstraintType() - .getBound() - .asReferenceType() - .getTypeDeclaration() - .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) - ); - } else if (typeOfScope.isUnionType()) { - return typeOfScope.asUnionType().getCommonAncestor() - .flatMap(ResolvedReferenceType::getTypeDeclaration) - .map(Collections::singletonList) - .orElseThrow(() -> new UnsolvedSymbolException("No common ancestor available for UnionType" + typeOfScope.describe())); - } - - // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... - return singletonList( - typeOfScope.asReferenceType() - .getTypeDeclaration() - .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) - ); - } - - ResolvedType typeOfScope = JavaParserFacade.get(typeSolver).getTypeOfThisIn(wrappedNode); - - // TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how... - return singletonList( - typeOfScope.asReferenceType() - .getTypeDeclaration() - .orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty.")) - ); - } - - /** - * Similar to solveMethod but we return a MethodUsage. - * A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables. - */ - public Optional solveMethodAsUsage(String name, List argumentsTypes) { - SymbolReference methodSolved = solveMethod(name, argumentsTypes, false); - if (methodSolved.isSolved()) { - ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration(); - if (!(methodDeclaration instanceof TypeVariableResolutionCapability)) { - throw new UnsupportedOperationException(String.format( - "Resolved method declarations must implement %s.", - TypeVariableResolutionCapability.class.getName() - )); - } - - MethodUsage methodUsage = ((TypeVariableResolutionCapability) methodDeclaration).resolveTypeVariables(this, argumentsTypes); - return Optional.of(methodUsage); - } else { - return Optional.empty(); - } - } - - @Override - public N getWrappedNode() { - return wrappedNode; - } -} From bfc9d6842fe0ce7eb3a0a30547e4be645189959c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 13:17:35 +0100 Subject: [PATCH 122/280] Removing dependency between TypeExtractor and ReflectionClassDeclaration --- .../javaparser/symbolsolver/javaparsermodel/TypeExtractor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index bc904c9107..12285f33fd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -51,7 +51,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprHandler; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprResolver; @@ -169,7 +168,7 @@ public ResolvedType visit(CastExpr node, Boolean solveLambdas) { public ResolvedType visit(ClassExpr node, Boolean solveLambdas) { // This implementation does not regard the actual type argument of the ClassExpr. ResolvedType jssType = facade.convertToUsage(node.getType()); - return new ReferenceTypeImpl(new ReflectionClassDeclaration(Class.class, typeSolver), ImmutableList.of(jssType)); + return new ReferenceTypeImpl(typeSolver.solveType(Class.class.getCanonicalName()), ImmutableList.of(jssType)); } /* From d682aa22ca7b16ca6e0a9545237ece44f3ddd69e Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 13:56:59 +0100 Subject: [PATCH 123/280] Remove unnecessary use of MyObjectProvider class which can be overridden by using TypeSolver --- .../common/MethodDeclarationCommonLogic.java | 3 +- .../javaparsermodel/TypeExtractor.java | 8 +-- .../contexts/LambdaExprContext.java | 4 +- .../contexts/MethodCallExprContext.java | 7 ++- .../contexts/MethodReferenceExprContext.java | 3 +- .../symbolsolver/logic/InferenceContext.java | 17 ++++-- .../logic/InferenceVariableType.java | 10 +++- .../reflectionmodel/MyObjectProvider.java | 57 ------------------- .../ReflectionAnnotationDeclaration.java | 2 +- .../ReflectionEnumDeclaration.java | 2 +- .../ReflectionInterfaceDeclaration.java | 2 +- .../logic/InferenceContextTest.java | 11 ++-- 12 files changed, 38 insertions(+), 88 deletions(-) delete mode 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java index 279b65d5e8..00d8fc030e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java @@ -30,7 +30,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import java.util.ArrayList; import java.util.List; @@ -60,7 +59,7 @@ public MethodUsage resolveTypeVariables(Context context, List para // We now look at the type parameter for the method which we can derive from the parameter types // and then we replace them in the return type // Map determinedTypeParameters = new HashMap<>(); - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); for (int i = 0; i < methodDeclaration.getNumberOfParams(); i++) { ResolvedParameterDeclaration formalParamDecl = methodDeclaration.getParam(i); ResolvedType formalParamType = formalParamDecl.getType(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 12285f33fd..47e1bbea6c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -30,7 +30,6 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.UnknownType; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; @@ -50,7 +49,6 @@ import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprHandler; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprResolver; @@ -530,8 +528,8 @@ private ResolvedType resolveLambda(LambdaExpr node, ResolvedType result) { if (functionalMethod.isPresent()) { LambdaExpr lambdaExpr = node; - InferenceContext lambdaCtx = new InferenceContext(MyObjectProvider.INSTANCE); - InferenceContext funcInterfaceCtx = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext lambdaCtx = new InferenceContext(typeSolver); + InferenceContext funcInterfaceCtx = new InferenceContext(typeSolver); // At this point parameterType // if Function @@ -623,7 +621,7 @@ public ResolvedType visit(MethodReferenceExpr node, Boolean solveLambdas) { ResolvedType actualType = facade.toMethodUsage(node, functionalMethod.getParamTypes()).returnType(); ResolvedType formalType = functionalMethod.returnType(); - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); inferenceContext.addPair(formalType, actualType); result = inferenceContext.resolve(inferenceContext.addSingle(result)); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index 92b5734a6d..a7c2a224a8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -22,7 +22,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; @@ -46,7 +45,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import static com.github.javaparser.resolution.Navigator.demandParentNode; @@ -84,7 +82,7 @@ public Optional solveSymbolAsValue(String name) { Optional functionalMethodOpt = FunctionalInterfaceLogic.getFunctionalMethod(lambdaType); if (functionalMethodOpt.isPresent()){ MethodUsage functionalMethod = functionalMethodOpt.get(); - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); // Resolve each type variable of the lambda, and use this later to infer the type of each // implicit parameter diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 892360a01a..106cc76a51 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -37,7 +37,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.utils.Pair; @@ -410,14 +409,16 @@ private void matchTypeParameters(ResolvedType expectedType, ResolvedType actualT ResolvedType type = actualType; // in case of primitive type, the expected type must be compared with the boxed type of the actual type if (type.isPrimitive()) { - type = MyObjectProvider.INSTANCE.byName(type.asPrimitive().getBoxTypeQName()); + ResolvedReferenceTypeDeclaration resolvedTypedeclaration = typeSolver.solveType(type.asPrimitive().getBoxTypeQName()); + type = new ReferenceTypeImpl(resolvedTypedeclaration); } /* * "a value of the null type (the null reference is the only such value) may be assigned to any reference type, resulting in a null reference of that type" * https://docs.oracle.com/javase/specs/jls/se15/html/jls-5.html#jls-5.2 */ if (type.isNull()) { - type = MyObjectProvider.INSTANCE.object(); + ResolvedReferenceTypeDeclaration resolvedTypedeclaration = typeSolver.getSolvedJavaLangObject(); + type = new ReferenceTypeImpl(resolvedTypedeclaration); } if (!type.isTypeVariable() && !type.isReferenceType()) { throw new UnsupportedOperationException(type.getClass().getCanonicalName()); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index e9e8fc2e67..44ed67c03d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -39,7 +39,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.InferenceContext; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import static com.github.javaparser.resolution.Navigator.demandParentNode; @@ -114,7 +113,7 @@ private List inferArgumentTypes() { List resolvedTypes = new ArrayList<>(); for (ResolvedType type : functionalMethod.getParamTypes()) { - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); // Resolve each type variable of the lambda, and use this later to infer the type of each // implicit parameter diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java index ae66f16e77..b0f0f27cf2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java @@ -27,7 +27,10 @@ import java.util.Map; import java.util.stream.Collectors; +import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -40,17 +43,17 @@ public class InferenceContext { private int nextInferenceVariableId = 0; - private ObjectProvider objectProvider; + private TypeSolver typeSolver; private List inferenceVariableTypes = new ArrayList<>(); private Map inferenceVariableTypeMap = new HashMap<>(); - public InferenceContext(ObjectProvider objectProvider) { - this.objectProvider = objectProvider; + public InferenceContext(TypeSolver typeSolver) { + this.typeSolver = typeSolver; } private InferenceVariableType inferenceVariableTypeForTp(ResolvedTypeParameterDeclaration tp) { if (!inferenceVariableTypeMap.containsKey(tp.getName())) { - InferenceVariableType inferenceVariableType = new InferenceVariableType(nextInferenceVariableId++, objectProvider); + InferenceVariableType inferenceVariableType = new InferenceVariableType(nextInferenceVariableId++, typeSolver); inferenceVariableTypes.add(inferenceVariableType); inferenceVariableType.setCorrespondingTp(tp); inferenceVariableTypeMap.put(tp.getName(), inferenceVariableType); @@ -162,12 +165,14 @@ private void registerCorrespondance(ResolvedType formalType, ResolvedType actual if (formalType.isPrimitive()) { // nothing to do } else { - registerCorrespondance(formalType, objectProvider.byName(actualType.asPrimitive().getBoxTypeQName())); + ResolvedReferenceTypeDeclaration resolvedTypedeclaration = typeSolver.solveType(actualType.asPrimitive().getBoxTypeQName()); + registerCorrespondance(formalType, new ReferenceTypeImpl(resolvedTypedeclaration)); } } else if (actualType.isReferenceType()) { if (formalType.isPrimitive()) { if (formalType.asPrimitive().getBoxTypeQName().equals(actualType.describe())) { - registerCorrespondance(objectProvider.byName(formalType.asPrimitive().getBoxTypeQName()), actualType); + ResolvedReferenceTypeDeclaration resolvedTypedeclaration = typeSolver.solveType(formalType.asPrimitive().getBoxTypeQName()); + registerCorrespondance(new ReferenceTypeImpl(resolvedTypedeclaration), actualType); } else { // nothing to do } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java index e85fa228fb..5ec8df92f5 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java @@ -21,7 +21,9 @@ package com.github.javaparser.symbolsolver.logic; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; @@ -53,6 +55,7 @@ public void setCorrespondingTp(ResolvedTypeParameterDeclaration correspondingTp) private Set equivalentTypes = new HashSet<>(); private ObjectProvider objectProvider; + private TypeSolver typeSolver; public void registerEquivalentType(ResolvedType type) { this.equivalentTypes.add(type); @@ -80,6 +83,11 @@ public InferenceVariableType(int id, ObjectProvider objectProvider) { this.id = id; this.objectProvider = objectProvider; } + + public InferenceVariableType(int id, TypeSolver typeSolver) { + this.id = id; + this.typeSolver = typeSolver; + } public static InferenceVariableType fromWildcard(ResolvedWildcard wildcard, int id, ObjectProvider objectProvider) { InferenceVariableType inferenceVariableType = new InferenceVariableType(id, objectProvider); @@ -120,7 +128,7 @@ public ResolvedType equivalentType() { Set concreteEquivalent = concreteEquivalentTypesAlsoIndirectly(new HashSet<>(), this); if (concreteEquivalent.isEmpty()) { if (correspondingTp == null) { - return objectProvider.object(); + return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } else { return new ResolvedTypeVariable(correspondingTp); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java deleted file mode 100644 index 53dcfd536d..0000000000 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2015-2016 Federico Tomassetti - * Copyright (C) 2017-2020 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser can be used either under the terms of - * a) the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * b) the terms of the Apache License - * - * You should have received a copy of both licenses in LICENCE.LGPL and - * LICENCE.APACHE. Please refer to those files for details. - * - * JavaParser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ - -package com.github.javaparser.symbolsolver.reflectionmodel; - -import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; -import com.github.javaparser.resolution.types.ResolvedReferenceType; -import com.github.javaparser.symbolsolver.logic.ObjectProvider; -import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; - -/** - * @author Federico Tomassetti - */ -public class MyObjectProvider implements ObjectProvider { - - public static final MyObjectProvider INSTANCE = new MyObjectProvider(); - - private MyObjectProvider() { - // prevent instantiation - } - - @Override - public ResolvedReferenceType object() { - return new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, new ReflectionTypeSolver())); - } - - @Override - public ResolvedReferenceType byName(String qualifiedName) { - TypeSolver typeSolver = new ReflectionTypeSolver(); - ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType(qualifiedName); - if (!typeDeclaration.getTypeParameters().isEmpty()) { - throw new UnsupportedOperationException(); - } - return new ReferenceTypeImpl(typeDeclaration); - } - -} diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index d4bb86f81b..f3ee67d930 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -218,7 +218,7 @@ public Optional solveMethodAsUsage(final String name, typeParameterValues, this, clazz); if (res.isPresent()) { // We have to replace method type typeParametersValues here - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); MethodUsage methodUsage = res.get(); int i = 0; List parameters = new LinkedList<>(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 9cf3d3d5d4..aa03c4f95d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -181,7 +181,7 @@ public Optional solveMethodAsUsage(String name, List typeParameterValues, this, clazz); if (res.isPresent()) { // We have to replace method type typeParametersValues here - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); MethodUsage methodUsage = res.get(); int i = 0; List parameters = new LinkedList<>(); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 23ede03be3..85d6f436f0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -150,7 +150,7 @@ public Optional solveMethodAsUsage(String name, List typeParameterValues, this, clazz); if (res.isPresent()) { // We have to replace method type typeParametersValues here - InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE); + InferenceContext inferenceContext = new InferenceContext(typeSolver); MethodUsage methodUsage = res.get(); int i = 0; List parameters = new LinkedList<>(); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index 4606de1a05..1265f3f638 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -27,7 +27,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.reflectionmodel.MyObjectProvider; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; @@ -71,20 +70,20 @@ private ResolvedReferenceType listOf(ResolvedType elementType) { @Test void noVariablesArePlacedWhenNotNeeded() { - ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(object, string); + ResolvedType result = new InferenceContext(typeSolver).addPair(object, string); assertEquals(object, result); } @Test void placingASingleVariableTopLevel() { - ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(new ResolvedTypeVariable(tpE), listOfString); - assertEquals(new InferenceVariableType(0, MyObjectProvider.INSTANCE), result); + ResolvedType result = new InferenceContext(typeSolver).addPair(new ResolvedTypeVariable(tpE), listOfString); + assertEquals(new InferenceVariableType(0, typeSolver), result); } @Test void placingASingleVariableInside() { - ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(listOfE, listOfString); - assertEquals(listOf(new InferenceVariableType(0, MyObjectProvider.INSTANCE)), result); + ResolvedType result = new InferenceContext(typeSolver).addPair(listOfE, listOfString); + assertEquals(listOf(new InferenceVariableType(0, typeSolver)), result); } } From b5401b4ccad6d89397d1cf12c1bd0e1a2209c9a0 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 14:02:15 +0100 Subject: [PATCH 124/280] Remove unnecessary use of MyObjectProvider class which can be overridden by using TypeSolver (2) --- .../logic/InferenceVariableType.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java index 5ec8df92f5..39fde2d2da 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java @@ -54,7 +54,6 @@ public void setCorrespondingTp(ResolvedTypeParameterDeclaration correspondingTp) } private Set equivalentTypes = new HashSet<>(); - private ObjectProvider objectProvider; private TypeSolver typeSolver; public void registerEquivalentType(ResolvedType type) { @@ -79,28 +78,11 @@ public int hashCode() { private Set superTypes = new HashSet<>(); - public InferenceVariableType(int id, ObjectProvider objectProvider) { - this.id = id; - this.objectProvider = objectProvider; - } - public InferenceVariableType(int id, TypeSolver typeSolver) { this.id = id; this.typeSolver = typeSolver; } - public static InferenceVariableType fromWildcard(ResolvedWildcard wildcard, int id, ObjectProvider objectProvider) { - InferenceVariableType inferenceVariableType = new InferenceVariableType(id, objectProvider); - if (wildcard.isExtends()) { - inferenceVariableType.superTypes.add(wildcard.getBoundedType()); - } - if (wildcard.isSuper()) { - // I am not sure about this one... - inferenceVariableType.superTypes.add(wildcard.getBoundedType()); - } - return inferenceVariableType; - } - @Override public String describe() { return "InferenceVariable_" + id; From cd93bbc5794ee262f1f2a105fd1267dc036faadb Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 14:37:01 +0100 Subject: [PATCH 125/280] Migrate InferenceContext and its attachments to JP core module --- .../github/javaparser/resolution}/logic/InferenceContext.java | 4 +++- .../declarations/common/MethodDeclarationCommonLogic.java | 2 +- .../symbolsolver/javaparsermodel/TypeExtractor.java | 2 +- .../javaparsermodel/contexts/LambdaExprContext.java | 2 +- .../javaparsermodel/contexts/MethodReferenceExprContext.java | 2 +- .../reflectionmodel/ReflectionAnnotationDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../javaparser/symbolsolver/logic/InferenceContextTest.java | 1 + 9 files changed, 11 insertions(+), 8 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/logic/InferenceContext.java (98%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java similarity index 98% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java index b0f0f27cf2..99893c270e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.logic; +package com.github.javaparser.resolution.logic; import java.util.ArrayList; import java.util.HashMap; @@ -36,6 +36,8 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; +import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; +import com.github.javaparser.symbolsolver.logic.InferenceVariableType; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java index 00d8fc030e..504614db57 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/declarations/common/MethodDeclarationCommonLogic.java @@ -27,9 +27,9 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import java.util.ArrayList; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index 47e1bbea6c..fe29df2e5a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -38,6 +38,7 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.LazyType; @@ -48,7 +49,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprHandler; import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprResolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java index a7c2a224a8..be25ca9f23 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java @@ -37,6 +37,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -44,7 +45,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import static com.github.javaparser.resolution.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 44ed67c03d..76e8adedeb 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -33,12 +33,12 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import static com.github.javaparser.resolution.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index f3ee67d930..277d63f51a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -42,13 +42,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index aa03c4f95d..107d7bdcd9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 85d6f436f0..149b27e0ca 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -28,6 +28,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.NullType; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; -import com.github.javaparser.symbolsolver.logic.InferenceContext; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index 1265f3f638..5534fa7795 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; From babef8504d7e1d9a3e42ce0145691c2eb277111f Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 14:41:18 +0100 Subject: [PATCH 126/280] Migrate InferenceContext and its attachments to JP core module (2) --- .../resolution}/logic/ConfilictingGenericTypesException.java | 2 +- .../github/javaparser/resolution/logic/InferenceContext.java | 2 -- .../javaparser/resolution}/logic/InferenceVariableType.java | 2 +- .../reflectionmodel/ReflectionAnnotationDeclaration.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../javaparser/symbolsolver/logic/InferenceContextTest.java | 1 + 7 files changed, 6 insertions(+), 7 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/logic/ConfilictingGenericTypesException.java (95%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/logic/InferenceVariableType.java (99%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/ConfilictingGenericTypesException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConfilictingGenericTypesException.java similarity index 95% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/ConfilictingGenericTypesException.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConfilictingGenericTypesException.java index e159585b51..f62023c310 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/ConfilictingGenericTypesException.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConfilictingGenericTypesException.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.logic; +package com.github.javaparser.resolution.logic; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java index 99893c270e..0f6f78777e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceContext.java @@ -36,8 +36,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; -import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; -import com.github.javaparser.symbolsolver.logic.InferenceVariableType; /** * @author Federico Tomassetti diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceVariableType.java similarity index 99% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceVariableType.java index 39fde2d2da..acc03f522d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/InferenceVariableType.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.logic; +package com.github.javaparser.resolution.logic; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index 277d63f51a..15d83a378e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -42,13 +42,13 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 107d7bdcd9..5d7e3f2932 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -26,6 +26,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -34,7 +35,6 @@ import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 149b27e0ca..9332b7404f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -28,6 +28,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; @@ -38,7 +39,6 @@ import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException; import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java index 5534fa7795..90ec846791 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/InferenceContextTest.java @@ -24,6 +24,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.InferenceContext; +import com.github.javaparser.resolution.logic.InferenceVariableType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; From 3daaa9d9f7c58640b8162d8fafb893b7d808be3f Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 14:49:37 +0100 Subject: [PATCH 127/280] Migrate promotion package to JP core module --- .../resolution/promotion/BooleanConditionalExprHandler.java | 2 +- .../resolution/promotion/ConditionalExprHandler.java | 2 +- .../resolution/promotion/ConditionalExprResolver.java | 2 +- .../resolution/promotion/NumericConditionalExprHandler.java | 2 +- .../resolution/promotion/ReferenceConditionalExprHandler.java | 2 +- .../symbolsolver/javaparsermodel/TypeExtractor.java | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/promotion/BooleanConditionalExprHandler.java (93%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/promotion/ConditionalExprHandler.java (68%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/promotion/ConditionalExprResolver.java (96%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/promotion/NumericConditionalExprHandler.java (99%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser}/resolution/promotion/ReferenceConditionalExprHandler.java (92%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/BooleanConditionalExprHandler.java similarity index 93% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/BooleanConditionalExprHandler.java index 0e7d367b08..793185b8d6 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/BooleanConditionalExprHandler.java @@ -1,4 +1,4 @@ -package com.github.javaparser.symbolsolver.resolution.promotion; +package com.github.javaparser.resolution.promotion; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprHandler.java similarity index 68% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprHandler.java index 275c010a96..c95ffd6a4b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprHandler.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprHandler.java @@ -1,4 +1,4 @@ -package com.github.javaparser.symbolsolver.resolution.promotion; +package com.github.javaparser.resolution.promotion; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprResolver.java similarity index 96% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprResolver.java index 4f55bb304d..a5880f66dd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ConditionalExprResolver.java @@ -1,4 +1,4 @@ -package com.github.javaparser.symbolsolver.resolution.promotion; +package com.github.javaparser.resolution.promotion; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/NumericConditionalExprHandler.java similarity index 99% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/NumericConditionalExprHandler.java index 71b0a79376..86b4cdbe38 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/NumericConditionalExprHandler.java @@ -1,4 +1,4 @@ -package com.github.javaparser.symbolsolver.resolution.promotion; +package com.github.javaparser.resolution.promotion; import java.util.Arrays; import java.util.HashMap; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ReferenceConditionalExprHandler.java similarity index 92% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ReferenceConditionalExprHandler.java index 6be79364fb..bdf2de996c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/promotion/ReferenceConditionalExprHandler.java @@ -1,4 +1,4 @@ -package com.github.javaparser.symbolsolver.resolution.promotion; +package com.github.javaparser.resolution.promotion; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index fe29df2e5a..c146fcef0a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -44,14 +44,14 @@ import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.NullType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; +import com.github.javaparser.resolution.promotion.ConditionalExprHandler; +import com.github.javaparser.resolution.promotion.ConditionalExprResolver; import com.github.javaparser.resolution.types.ResolvedArrayType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; -import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprHandler; -import com.github.javaparser.symbolsolver.resolution.promotion.ConditionalExprResolver; import com.github.javaparser.utils.Log; import com.github.javaparser.utils.Pair; import com.google.common.collect.ImmutableList; From fa213729c4da1fe0a4e06fbb5360c92a3b7c1267 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 9 Dec 2022 14:59:16 +0100 Subject: [PATCH 128/280] Remove dependency between TypeExtractor and JavaParserSymbolDeclaration. The goal of removing dependencies with the javaparser-symbol-solver-core module is to allow the TypeExtractor class to be migrated to the JP core module with the ultimate goal of letting nodes create their own context. --- .../javaparsermodel/TypeExtractor.java | 17 ++++++++++++++--- .../JavaParserSymbolDeclaration.java | 11 ----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java index c146fcef0a..40bc6ab479 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; @@ -50,7 +51,6 @@ import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.utils.Log; import com.github.javaparser.utils.Pair; @@ -455,7 +455,7 @@ public ResolvedType visit(VariableDeclarationExpr node, Boolean solveLambdas) { public ResolvedType visit(LambdaExpr node, Boolean solveLambdas) { if (demandParentNode(node) instanceof MethodCallExpr) { MethodCallExpr callExpr = (MethodCallExpr) demandParentNode(node); - int pos = JavaParserSymbolDeclaration.getParamPos(node); + int pos = getParamPos(node); SymbolReference refMethod = facade.solve(callExpr); if (!refMethod.isSolved()) { throw new UnsolvedSymbolException(demandParentNode(node).toString(), callExpr.getName().getId()); @@ -585,7 +585,7 @@ private ResolvedType resolveLambda(LambdaExpr node, ResolvedType result) { public ResolvedType visit(MethodReferenceExpr node, Boolean solveLambdas) { if (demandParentNode(node) instanceof MethodCallExpr) { MethodCallExpr callExpr = (MethodCallExpr) demandParentNode(node); - int pos = JavaParserSymbolDeclaration.getParamPos(node); + int pos = getParamPos(node); SymbolReference refMethod = facade.solve(callExpr, false); if (!refMethod.isSolved()) { throw new UnsolvedSymbolException(demandParentNode(node).toString(), callExpr.getName().getId()); @@ -640,6 +640,17 @@ public ResolvedType visit(FieldDeclaration node, Boolean solveLambdas) { } throw new IllegalArgumentException("Cannot resolve the type of a field with multiple variable declarations. Pick one"); } + + private static int getParamPos(Node node) { + if (demandParentNode(node) instanceof MethodCallExpr) { + MethodCallExpr call = (MethodCallExpr) demandParentNode(node); + for (int i = 0; i < call.getArguments().size(); i++) { + if (call.getArguments().get(i) == node) return i; + } + throw new IllegalStateException(); + } + throw new IllegalArgumentException(); + } protected Solver createSolver() { return new SymbolSolver(typeSolver); diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java index bb762dbab5..fbd1e7fbd9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java @@ -67,17 +67,6 @@ public static int getParamPos(Parameter parameter) { return pos; } - public static int getParamPos(Node node) { - if (demandParentNode(node) instanceof MethodCallExpr) { - MethodCallExpr call = (MethodCallExpr) demandParentNode(node); - for (int i = 0; i < call.getArguments().size(); i++) { - if (call.getArguments().get(i) == node) return i; - } - throw new IllegalStateException(); - } - throw new IllegalArgumentException(); - } - private JavaParserSymbolDeclaration() { // This private constructor is used to hide the public one } From 5682646f46fcb14f19c3436be8eab4b85020d64f Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 00:28:32 +0000 Subject: [PATCH 129/280] Added checkstyle to the project --- .github/workflows/maven_tests.yml | 17 ++++++++++++ dev-files/JavaParser-CheckStyle.xml | 42 +++++++++++++++++++++++++++++ pom.xml | 15 +++++++++++ 3 files changed, 74 insertions(+) create mode 100644 dev-files/JavaParser-CheckStyle.xml diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 11a7a7e766..6ee8926d79 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -102,3 +102,20 @@ jobs: verbose: false # optional (default = false): flags: javaparser-symbol-solver,AlsoSlowTests,${{ matrix.os }},jdk-${{ matrix.jdk }} env_vars: OS,JDK + + # Run checkstyle validations for pipeline + checkstyle_check: + name: Validate checkstyle + runs-on: ubuntu-latest + steps: + - name: Checkout latest code + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'zulu' + - name: Build with Maven + run: ./mvnw -B checkstyle:check diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml new file mode 100644 index 0000000000..db6dbba73a --- /dev/null +++ b/dev-files/JavaParser-CheckStyle.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index b18d500643..94ef86396a 100644 --- a/pom.xml +++ b/pom.xml @@ -339,6 +339,21 @@ false + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.2 + + dev-files/JavaParser-CheckStyle.xml + + + + com.puppycrawl.tools + checkstyle + 8.45.1 + + + From b70d379fa6fb610316121f07a89bb442ab9e4fda Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 00:38:01 +0000 Subject: [PATCH 130/280] Renamed step --- .github/workflows/maven_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 6ee8926d79..5e4bc5c639 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -117,5 +117,5 @@ jobs: with: java-version: '11' distribution: 'zulu' - - name: Build with Maven + - name: Validate Project Checkstyle run: ./mvnw -B checkstyle:check From 560eb6be34f1a5e2d6aa6b6654bad9efedf60f66 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 00:41:51 +0000 Subject: [PATCH 131/280] Replaced severity from warning to error --- dev-files/JavaParser-CheckStyle.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml index db6dbba73a..6319ace727 100644 --- a/dev-files/JavaParser-CheckStyle.xml +++ b/dev-files/JavaParser-CheckStyle.xml @@ -5,8 +5,6 @@ - - From 7dc64622da3f92d1d08f53eb0fdcfc84b34a36cc Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 23:46:52 +0000 Subject: [PATCH 132/280] Log warning to console --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 94ef86396a..90fd3b83af 100644 --- a/pom.xml +++ b/pom.xml @@ -345,6 +345,7 @@ 3.1.2 dev-files/JavaParser-CheckStyle.xml + true From 3ce0c508347a97cd75a815bff338cc877f11eca8 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 23:47:50 +0000 Subject: [PATCH 133/280] Replaced LineLength severity from error to warning --- dev-files/JavaParser-CheckStyle.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml index 6319ace727..72af6f322f 100644 --- a/dev-files/JavaParser-CheckStyle.xml +++ b/dev-files/JavaParser-CheckStyle.xml @@ -10,6 +10,7 @@ + From a7f1ec4e75c1dc850f156f6484b5fc8f411e1ad5 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sat, 10 Dec 2022 23:53:57 +0000 Subject: [PATCH 134/280] Added warnings for batch execution --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 90fd3b83af..e8e754ce14 100644 --- a/pom.xml +++ b/pom.xml @@ -346,6 +346,7 @@ dev-files/JavaParser-CheckStyle.xml true + true From f988c227c64481dfeed46e860a0b939ebd7bce01 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 11 Dec 2022 13:06:45 +0000 Subject: [PATCH 135/280] Updated Checkstyle severity to warnings --- dev-files/JavaParser-CheckStyle.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml index 72af6f322f..16a5ecd7dd 100644 --- a/dev-files/JavaParser-CheckStyle.xml +++ b/dev-files/JavaParser-CheckStyle.xml @@ -16,13 +16,16 @@ - + + + + @@ -35,6 +38,7 @@ + From 0c9e53b1006f40136a79e2b04e163e56e69f99d2 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 11 Dec 2022 13:49:21 +0000 Subject: [PATCH 136/280] fixup! Simplified classes that depend on AssociableToAST --- .../JavaParserEnumDeclaration.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index b80f924a28..da3af08af9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -21,15 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.BodyDeclaration; @@ -40,7 +31,6 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.AssociableToAST; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; @@ -67,6 +57,15 @@ import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + /** * @author Federico Tomassetti */ @@ -441,7 +440,7 @@ public ResolvedType getSpecifiedException(int index) { @Override public Optional toAst() { - return Optional.empty(); + return Optional.of(enumDeclaration.getWrappedNode()); } } @@ -502,7 +501,7 @@ public boolean isVariadic() { @Override public Optional toAst() { - return Optional.empty(); + return Optional.of(enumDeclaration.getWrappedNode()); } }; @@ -562,7 +561,7 @@ public ResolvedType getSpecifiedException(int index) { @Override public Optional toAst() { - return Optional.empty(); + return Optional.of(enumDeclaration.getWrappedNode()); } } From bbcf0cdcebb3ba1981d8a516ebb663ea31b6a222 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 11 Dec 2022 14:31:09 +0000 Subject: [PATCH 137/280] fixup! Updated tests to expect the correct behavior --- .../declarations/JavaParserEnumDeclarationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java index a86a0c5bf1..38e9359638 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclarationTest.java @@ -36,6 +36,7 @@ import java.util.Set; import java.util.stream.Collectors; +import com.github.javaparser.ast.Node; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -959,7 +960,7 @@ void testHasDirectlyAnnotationPositive() { } @Override - public Optional getWrappedDeclaration(AssociableToAST associableToAST) { + public Optional getWrappedDeclaration(AssociableToAST associableToAST) { return Optional.of( safeCast(associableToAST, JavaParserEnumDeclaration.class).getWrappedNode() ); From 6bf5d8ade220835b3eacaf24b66241ed07f956dd Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Sun, 11 Dec 2022 15:18:08 +0000 Subject: [PATCH 138/280] Code cleanup --- .../declarations/AssociableToAST.java | 4 ++- .../ResolvedMethodDeclaration.java | 3 +-- .../ResolvedTypeParameterDeclaration.java | 4 --- .../symbolsolver/JavaSymbolSolver.java | 7 ----- .../DefaultConstructorDeclaration.java | 4 --- .../JavaParserEnumDeclaration.java | 6 ++--- .../JavaParserSymbolDeclaration.java | 4 +-- .../JavassistAnnotationDeclaration.java | 5 ---- .../JavassistAnnotationMemberDeclaration.java | 9 +------ .../JavassistClassDeclaration.java | 4 --- .../JavassistConstructorDeclaration.java | 4 --- .../JavassistEnumConstantDeclaration.java | 9 +------ .../JavassistEnumDeclaration.java | 15 +---------- .../JavassistFieldDeclaration.java | 14 +++------- .../JavassistInterfaceDeclaration.java | 4 --- .../JavassistMethodDeclaration.java | 6 ----- .../JavassistParameterDeclaration.java | 10 +------ .../JavassistTypeParameter.java | 19 +++++--------- .../ReflectionAnnotationDeclaration.java | 5 ---- ...ReflectionAnnotationMemberDeclaration.java | 26 +++++++++---------- .../ReflectionClassDeclaration.java | 5 ---- .../ReflectionConstructorDeclaration.java | 6 ----- .../ReflectionEnumConstantDeclaration.java | 7 ----- .../ReflectionEnumDeclaration.java | 21 ++------------- .../ReflectionFieldDeclaration.java | 15 +++-------- .../ReflectionInterfaceDeclaration.java | 4 --- .../ReflectionMethodDeclaration.java | 4 --- .../ReflectionParameterDeclaration.java | 7 ----- .../ReflectionPatternDeclaration.java | 7 ----- .../ReflectionTypeParameter.java | 24 +++++++---------- .../resolution/DefaultPackageTest.java | 12 ++++----- 31 files changed, 56 insertions(+), 218 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java index 9f9ce95b23..8ed7018f36 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/AssociableToAST.java @@ -50,7 +50,9 @@ public interface AssociableToAST { * In these cases getWrappedNode is particularly nice because it returns the right type of AST node, * not just a Node. */ - Optional toAst(); + default Optional toAst() { + return Optional.empty(); + } /** * If the declaration is associated to an AST node and the type matches the expected {@link Class} return it, diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java index 7bb1270edb..bd9f56d556 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java @@ -27,8 +27,7 @@ * * @author Federico Tomassetti */ -public interface -ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration { +public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration { /** * The type of the value returned by the current method. This method can also be invoked diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java index e285cbe88d..f0c599a571 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java @@ -101,10 +101,6 @@ public ResolvedReferenceType object() { throw new UnsupportedOperationException(); } - @Override - public Optional toAst() { - return Optional.empty(); - } }; } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index 51462fc15e..319c3da527 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -38,8 +38,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.*; -import java.util.Optional; - /** * This implementation of the SymbolResolver wraps the functionality of the library to make them easily usable * from JavaParser nodes. @@ -70,11 +68,6 @@ public String getName() { public ResolvedType getType() { return ResolvedPrimitiveType.INT; } - - @Override - public Optional toAst() { - return Optional.empty(); - } } private TypeSolver typeSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java index c646fa964f..6900d6c342 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/DefaultConstructorDeclaration.java @@ -87,8 +87,4 @@ public ResolvedType getSpecifiedException(int index) { throw new UnsupportedOperationException("The default constructor does not throw exceptions"); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index da3af08af9..e12f69fd19 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -440,7 +440,7 @@ public ResolvedType getSpecifiedException(int index) { @Override public Optional toAst() { - return Optional.of(enumDeclaration.getWrappedNode()); + return enumDeclaration.toAst(); } } @@ -501,7 +501,7 @@ public boolean isVariadic() { @Override public Optional toAst() { - return Optional.of(enumDeclaration.getWrappedNode()); + return enumDeclaration.toAst(); } }; @@ -561,7 +561,7 @@ public ResolvedType getSpecifiedException(int index) { @Override public Optional toAst() { - return Optional.of(enumDeclaration.getWrappedNode()); + return enumDeclaration.toAst(); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java index 2a364ebd7b..6cfd9cff12 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserSymbolDeclaration.java @@ -21,6 +21,8 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.body.VariableDeclarator; @@ -28,8 +30,6 @@ import com.github.javaparser.ast.expr.PatternExpr; import com.github.javaparser.resolution.TypeSolver; -import static com.github.javaparser.symbolsolver.javaparser.Navigator.demandParentNode; - /** * This should not be used to represent fields of parameters. * diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java index 2fc293e2f2..2159e4c1d7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationDeclaration.java @@ -160,11 +160,6 @@ public List getAnnotationMembers() { .collect(Collectors.toList()); } - @Override - public Optional toAst() { - return Optional.empty(); - } - @Override public boolean isInheritable() { try { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java index dd72416551..e3b5dc31e2 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistAnnotationMemberDeclaration.java @@ -21,7 +21,6 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.BooleanLiteralExpr; import com.github.javaparser.ast.expr.CharLiteralExpr; import com.github.javaparser.ast.expr.DoubleLiteralExpr; @@ -35,6 +34,7 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; + import javassist.CtMethod; import javassist.bytecode.AnnotationDefaultAttribute; import javassist.bytecode.BadBytecode; @@ -49,7 +49,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.function.Function; /** @@ -105,10 +104,4 @@ public ResolvedType getType() { public String getName() { return annotationMember.getName(); } - - @Override - public Optional toAst() { - return Optional.empty(); - } - } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java index eca5973762..387e749447 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistClassDeclaration.java @@ -317,8 +317,4 @@ public boolean hasInternalType(String name) { return this.internalTypes().stream().anyMatch(f -> f.getName().endsWith(name)); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java index f5663b74ec..35157bfe47 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistConstructorDeclaration.java @@ -111,8 +111,4 @@ public ResolvedType getSpecifiedException(int index) { return methodLikeAdaper.getSpecifiedException(index); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java index 88bda6346a..56b3a952bd 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java @@ -21,16 +21,14 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; + import javassist.CtField; import javassist.bytecode.AccessFlag; -import java.util.Optional; - /** * @author Federico Tomassetti */ @@ -75,9 +73,4 @@ public String toString() { '}'; } - @Override - public Optional toAst() { - return Optional.empty(); - } - } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index c5091d698c..d009ae2574 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -22,19 +22,11 @@ package com.github.javaparser.symbolsolver.javassistmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -246,9 +238,4 @@ public String toString() { ", typeSolver=" + typeSolver + '}'; } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java index 17f749399c..79e21aa0ec 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistFieldDeclaration.java @@ -21,20 +21,19 @@ package com.github.javaparser.symbolsolver.javassistmodel; +import java.lang.reflect.Modifier; + import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.types.ResolvedType; + import javassist.CtField; import javassist.bytecode.BadBytecode; import javassist.bytecode.SignatureAttribute; -import java.lang.reflect.Modifier; -import java.util.Optional; - /** * @author Federico Tomassetti */ @@ -65,7 +64,7 @@ public ResolvedType getType() { public boolean isStatic() { return Modifier.isStatic(ctField.getModifiers()); } - + @Override public boolean isVolatile() { return Modifier.isVolatile(ctField.getModifiers()); @@ -100,9 +99,4 @@ public AccessSpecifier accessSpecifier() { public ResolvedTypeDeclaration declaringType() { return JavassistFactory.toTypeDeclaration(ctField.getDeclaringClass(), typeSolver); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index e2a1b6aed4..babe80cc84 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -237,8 +237,4 @@ public List getConstructors() { return Collections.emptyList(); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java index dd350bc0ed..5b8296a700 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclaration.java @@ -37,7 +37,6 @@ import java.lang.reflect.Modifier; import java.util.List; -import java.util.Optional; /** * @author Federico Tomassetti @@ -144,9 +143,4 @@ public ResolvedType getSpecifiedException(int index) { return methodLikeAdaper.getSpecifiedException(index); } - @Override - public Optional toAst() { - return Optional.empty(); - } - } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java index 805f234559..f28ae1d190 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistParameterDeclaration.java @@ -21,19 +21,16 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import javassist.CtClass; -import java.util.Optional; +import javassist.CtClass; /** * @author Federico Tomassetti */ public class JavassistParameterDeclaration implements ResolvedParameterDeclaration { - private ResolvedType type; private TypeSolver typeSolver; private boolean variadic; @@ -93,9 +90,4 @@ public boolean isType() { public ResolvedType getType() { return type; } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java index c25368107e..894f65080e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistTypeParameter.java @@ -21,7 +21,11 @@ package com.github.javaparser.symbolsolver.javassistmodel; -import com.github.javaparser.ast.Node; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -29,12 +33,8 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; -import javassist.bytecode.SignatureAttribute; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import javassist.bytecode.SignatureAttribute; /** * @author Federico Tomassetti @@ -128,14 +128,9 @@ public Optional containerType() { } return Optional.empty(); } - + @Override public ResolvedReferenceType object() { return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index f9ab33230e..a4de81c346 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -204,11 +204,6 @@ public List getAnnotationMembers() { .collect(Collectors.toList()); } - @Override - public Optional toAst() { - return Optional.empty(); - } - @Override public Optional solveMethodAsUsage(final String name, final List parameterTypes, diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java index 19d0b7aa53..9e809f1c6f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationMemberDeclaration.java @@ -21,8 +21,18 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.*; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.DoubleLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.LongLiteralExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -31,12 +41,6 @@ import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; - /** * @author Malte Skoruppa */ @@ -85,10 +89,4 @@ public ResolvedType getType() { public String getName() { return annotationMember.getName(); } - - @Override - public Optional toAst() { - return Optional.empty(); - } - } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 3861b2318b..6a623d86ef 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -391,11 +391,6 @@ public Set internalTypes() { .collect(Collectors.toSet()); } - @Override - public Optional toAst() { - return Optional.empty(); - } - /// /// Protected methods /// diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java index ef466b950b..954ce12a17 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionConstructorDeclaration.java @@ -22,7 +22,6 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; @@ -33,7 +32,6 @@ import java.lang.reflect.Constructor; import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; /** @@ -101,8 +99,4 @@ public ResolvedType getSpecifiedException(int index) { return ReflectionFactory.typeUsageFor(this.constructor.getExceptionTypes()[index], typeSolver); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java index a132cba34f..72179c5c46 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java @@ -21,7 +21,6 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -29,7 +28,6 @@ import com.github.javaparser.resolution.types.ResolvedType; import java.lang.reflect.Field; -import java.util.Optional; public class ReflectionEnumConstantDeclaration implements ResolvedEnumConstantDeclaration { @@ -55,9 +53,4 @@ public ResolvedType getType() { ResolvedReferenceTypeDeclaration typeDeclaration = new ReflectionEnumDeclaration(enumClass, typeSolver); return new ReferenceTypeImpl(typeDeclaration); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index c380922cba..9cf3d3d5d4 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -22,18 +22,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -46,11 +38,7 @@ import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -247,9 +235,4 @@ public Set internalTypes() { public List getConstructors() { return reflectionClassAdapter.getConstructors(); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java index ea2ab54db1..f7c4a527da 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionFieldDeclaration.java @@ -21,17 +21,15 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Optional; - /** * @author Federico Tomassetti */ @@ -72,7 +70,7 @@ public String getName() { public boolean isStatic() { return Modifier.isStatic(field.getModifiers()); } - + @Override public boolean isVolatile() { return Modifier.isVolatile(field.getModifiers()); @@ -106,9 +104,4 @@ public boolean isType() { public AccessSpecifier accessSpecifier() { return ReflectionFactory.modifiersToAccessLevel(field.getModifiers()); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 4310ddc586..2bd18ca8f7 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -338,8 +338,4 @@ public List getConstructors() { return Collections.emptyList(); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java index 834f637ee8..44ee3a0588 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodDeclaration.java @@ -158,8 +158,4 @@ public ResolvedType getSpecifiedException(int index) { return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java index 99b1ee8876..73b914914f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionParameterDeclaration.java @@ -21,13 +21,11 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import java.util.Objects; -import java.util.Optional; /** * @author Federico Tomassetti @@ -119,9 +117,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(type, genericType, typeSolver, variadic, name); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java index 5e9f0ec04f..3f3e25e5d3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionPatternDeclaration.java @@ -21,13 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedPatternDeclaration; import com.github.javaparser.resolution.types.ResolvedType; -import java.util.Optional; - /** * WARNING: Implemented fairly blindly. Unsure if required or even appropriate. Use with extreme caution. * @@ -85,8 +82,4 @@ public ResolvedType getType() { return ReflectionFactory.typeUsageFor(type, typeSolver); } - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java index 6c1d1e8ae3..b3ad00fc66 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionTypeParameter.java @@ -21,15 +21,6 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -import com.github.javaparser.ast.Node; -import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; -import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; -import com.github.javaparser.resolution.types.ResolvedReferenceType; - import java.lang.reflect.Constructor; import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Method; @@ -39,6 +30,14 @@ import java.util.Optional; import java.util.stream.Collectors; +import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; +import com.github.javaparser.resolution.types.ResolvedReferenceType; + /** * @author Federico Tomassetti */ @@ -135,14 +134,9 @@ public Optional containerType() { } return Optional.empty(); } - + @Override public ResolvedReferenceType object() { return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java index 10d8e04be2..6d6c41243b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/DefaultPackageTest.java @@ -22,7 +22,6 @@ package com.github.javaparser.symbolsolver.resolution; import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -34,7 +33,11 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver; import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Set; import static com.github.javaparser.StaticJavaParser.parse; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -147,11 +150,6 @@ public Optional containerType() { public SymbolReference solveMethod(String name, List argumentsTypes, boolean staticOnly) { throw new UnsupportedOperationException(); } - - @Override - public Optional toAst() { - return Optional.empty(); - } } @Test From ad9b7c7e8a85b8f2c46d5286e574cd5ceb59da85 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sun, 11 Dec 2022 16:36:25 +0100 Subject: [PATCH 139/280] Migrate MethodResolutionCapability to JP core module --- .../resolution}/logic/MethodResolutionCapability.java | 2 +- .../javaparsermodel/declarations/JavaParserEnumDeclaration.java | 2 +- .../declarations/JavaParserInterfaceDeclaration.java | 2 +- .../symbolsolver/javassistmodel/JavassistEnumDeclaration.java | 2 +- .../javassistmodel/JavassistInterfaceDeclaration.java | 2 +- .../javaparser/symbolsolver/logic/AbstractClassDeclaration.java | 1 + .../reflectionmodel/ReflectionAnnotationDeclaration.java | 2 +- .../symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionInterfaceDeclaration.java | 2 +- .../symbolsolver/resolution/MethodResolutionLogic.java | 2 +- .../symbolsolver/logic/MethodResolutionCapabilityTest.java | 2 ++ 11 files changed, 12 insertions(+), 9 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver => javaparser-core/src/main/java/com/github/javaparser/resolution}/logic/MethodResolutionCapability.java (96%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionCapability.java similarity index 96% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionCapability.java index e644dfee0c..f6e3d984ea 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionCapability.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.logic; +package com.github.javaparser.resolution.logic; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.model.SymbolReference; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java index 9292724885..2ab42d38a0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserEnumDeclaration.java @@ -52,6 +52,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -65,7 +66,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java index 602c4330a3..19e66b8ff0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserInterfaceDeclaration.java @@ -47,6 +47,7 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.LazyType; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -57,7 +58,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java index d009ae2574..c68fda80c1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumDeclaration.java @@ -27,13 +27,13 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java index 5343f78f59..de25bb89a1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistInterfaceDeclaration.java @@ -28,13 +28,13 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import javassist.CtClass; import javassist.CtField; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractClassDeclaration.java index e13a88a3d1..580290cb35 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/AbstractClassDeclaration.java @@ -22,6 +22,7 @@ package com.github.javaparser.symbolsolver.logic; import com.github.javaparser.resolution.declarations.ResolvedClassDeclaration; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.types.ResolvedReferenceType; import java.util.ArrayList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java index 15d83a378e..b4038eed1e 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionAnnotationDeclaration.java @@ -44,12 +44,12 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; /** * @author Malte Skoruppa diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java index 5d7e3f2932..cc0fd9fdaf 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumDeclaration.java @@ -28,6 +28,7 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; @@ -35,7 +36,6 @@ import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java index 9332b7404f..bb28b3bb38 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionInterfaceDeclaration.java @@ -30,6 +30,7 @@ import com.github.javaparser.resolution.declarations.*; import com.github.javaparser.resolution.logic.ConfilictingGenericTypesException; import com.github.javaparser.resolution.logic.InferenceContext; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.NullType; @@ -39,7 +40,6 @@ import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.lang.reflect.Field; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java index 02fb1a2720..7192145b96 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java @@ -25,10 +25,10 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; -import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapabilityTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapabilityTest.java index 8c2992774e..89271b0e87 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapabilityTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapabilityTest.java @@ -21,6 +21,8 @@ package com.github.javaparser.symbolsolver.logic; +import com.github.javaparser.resolution.logic.MethodResolutionCapability; + public interface MethodResolutionCapabilityTest { MethodResolutionCapability createValue(); From ebc91860013ebb5b920d7a66900f1c64ce987aa7 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sun, 11 Dec 2022 16:43:11 +0100 Subject: [PATCH 140/280] Migrate ConstructorResolutionLogic and MethodResolutionLogic to JP core module --- .../resolution/logic}/ConstructorResolutionLogic.java | 2 +- .../javaparser/resolution/logic}/MethodResolutionLogic.java | 3 +-- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 4 ++-- .../contexts/AnonymousClassDeclarationContext.java | 2 +- .../javaparsermodel/contexts/CompilationUnitContext.java | 2 +- .../contexts/JavaParserTypeDeclarationAdapter.java | 4 ++-- .../javaparsermodel/contexts/MethodCallExprContext.java | 2 +- .../javaparsermodel/contexts/MethodReferenceExprContext.java | 2 +- .../symbolsolver/javassistmodel/JavassistUtils.java | 2 +- .../reflectionmodel/ReflectionClassDeclaration.java | 2 +- .../reflectionmodel/ReflectionMethodResolutionLogic.java | 2 +- .../symbolsolver/resolution/MethodsResolutionLogicTest.java | 1 + 12 files changed, 14 insertions(+), 14 deletions(-) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution => javaparser-core/src/main/java/com/github/javaparser/resolution/logic}/ConstructorResolutionLogic.java (99%) rename {javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution => javaparser-core/src/main/java/com/github/javaparser/resolution/logic}/MethodResolutionLogic.java (99%) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConstructorResolutionLogic.java similarity index 99% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConstructorResolutionLogic.java index f6da457ea1..f61359125d 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/ConstructorResolutionLogic.java @@ -19,7 +19,7 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.resolution; +package com.github.javaparser.resolution.logic; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.TypeSolver; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java similarity index 99% rename from javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java rename to javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java index 7192145b96..033455d4f0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java @@ -19,13 +19,12 @@ * GNU Lesser General Public License for more details. */ -package com.github.javaparser.symbolsolver.resolution; +package com.github.javaparser.resolution.logic; import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; -import com.github.javaparser.resolution.logic.MethodResolutionCapability; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 11f10717f1..9c245c0a2b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -37,6 +37,8 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.ConstructorResolutionLogic; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -49,8 +51,6 @@ import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; -import com.github.javaparser.symbolsolver.resolution.ConstructorResolutionLogic; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.utils.Log; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java index 4346e64363..4d2f4b2b0a 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AnonymousClassDeclarationContext.java @@ -31,6 +31,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -39,7 +40,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.google.common.base.Preconditions; import java.util.List; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index 1d2c537427..81089d32e0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -40,7 +41,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import java.util.LinkedList; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index 29cc8c0071..a05f0dee6f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -35,6 +35,8 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.ConstructorResolutionLogic; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; @@ -42,8 +44,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.ConstructorResolutionLogic; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import java.util.List; import java.util.Optional; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index 106cc76a51..e7ce3d9995 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -31,6 +31,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.LazyType; @@ -38,7 +39,6 @@ import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import com.github.javaparser.utils.Pair; import java.util.*; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java index 76e8adedeb..46768d90fa 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodReferenceExprContext.java @@ -34,12 +34,12 @@ import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.logic.FunctionalInterfaceLogic; import com.github.javaparser.resolution.logic.InferenceContext; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedLambdaConstraintType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import static com.github.javaparser.resolution.Navigator.demandParentNode; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java index b93e8e6eb2..dfa911152c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javassistmodel/JavassistUtils.java @@ -37,6 +37,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; @@ -47,7 +48,6 @@ import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.resolution.types.ResolvedWildcard; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import javassist.CtBehavior; import javassist.CtClass; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java index 3861b2318b..f7198acaa3 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionClassDeclaration.java @@ -27,6 +27,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.*; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.LambdaArgumentTypePlaceholder; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; @@ -37,7 +38,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.contexts.ContextHelper; import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.comparators.MethodComparator; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import java.lang.reflect.Field; import java.lang.reflect.Method; diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java index f6bf36a997..09d933e333 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/ReflectionMethodResolutionLogic.java @@ -27,12 +27,12 @@ import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; import java.lang.reflect.Method; import java.lang.reflect.Modifier; diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java index 63913bd54d..39855264e3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/MethodsResolutionLogicTest.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; +import com.github.javaparser.resolution.logic.MethodResolutionLogic; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory; From dda1f59227f415edc005d01b087c763afe451f43 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Sun, 11 Dec 2022 16:51:16 +0100 Subject: [PATCH 141/280] remove the dependency between JavaParserTypeDeclarationAdapter and ReflexionClassDeclaration (symbol solver module) --- .../contexts/JavaParserTypeDeclarationAdapter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java index a05f0dee6f..9085a685b1 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/JavaParserTypeDeclarationAdapter.java @@ -43,7 +43,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import java.util.List; import java.util.Optional; @@ -258,7 +257,7 @@ public SymbolReference solveMethod(String name, List< // if is interface and candidate method list is empty, we should check the Object Methods if (candidateMethods.isEmpty() && typeDeclaration.isInterface()) { - SymbolReference res = MethodResolutionLogic.solveMethodInType(new ReflectionClassDeclaration(Object.class, typeSolver), name, argumentsTypes, false); + SymbolReference res = MethodResolutionLogic.solveMethodInType(typeSolver.getSolvedJavaLangObject(), name, argumentsTypes, false); if (res.isSolved()) { candidateMethods.add(res.getCorrespondingDeclaration()); } From cbf8642717a810e8d49064f60ad055e8f9fb48b5 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 09:27:22 +0100 Subject: [PATCH 142/280] Migration of the JavaParserFacade.classToResolvedType() method to the SymbolSolver class because not only is it more logical for this functionality to be implemented in SymbolSolver, but also this modification makes it possible to remove class dependencies with the JavaParserFacade class which is specific to the SymbolSolver module. --- .../github/javaparser/resolution/Solver.java | 9 ++++++ .../javaparser/resolution/TypeSolver.java | 2 ++ .../javaparsermodel/JavaParserFacade.java | 21 ++++--------- .../contexts/MethodCallExprContext.java | 11 +++---- .../JavaParserTypeVariableDeclaration.java | 4 +-- .../symbolsolver/resolution/SymbolSolver.java | 30 +++++++++++++++++++ .../javaparser/symbolsolver/Issue343Test.java | 12 ++++---- .../javaparsermodel/JavaParserFacadeTest.java | 14 +++++---- .../JavaParserFacadeResolutionTest.java | 7 +++-- 9 files changed, 71 insertions(+), 39 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java index f36add5614..52eb87288e 100755 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Solver.java @@ -49,5 +49,14 @@ SymbolReference solveSymbolInType(ResolvedTy * and do not be specific to JavaParser classes like in this case. */ SymbolReference solveTypeInType(ResolvedTypeDeclaration typeDeclaration, String name); + + /** + * Convert a {@link Class} into the corresponding {@link ResolvedType}. + * + * @param clazz The class to be converted. + * + * @return The class resolved. + */ + ResolvedType classToResolvedType(Class clazz); } \ No newline at end of file diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java index aa8c2e4ac4..3a81aa2b92 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/TypeSolver.java @@ -23,6 +23,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.types.ResolvedType; /** * An element able to find TypeDeclaration from their name. @@ -83,4 +84,5 @@ default ResolvedReferenceTypeDeclaration getSolvedJavaLangObject() throws Unsolv default boolean hasType(String name) { return tryToSolveType(name).isSolved(); } + } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 9c245c0a2b..cf5603342c 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -52,6 +52,7 @@ import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.Log; import java.util.*; @@ -709,23 +710,13 @@ public ResolvedReferenceTypeDeclaration getTypeDeclaration(TypeDeclaration ty * @param clazz The class to be converted. * * @return The class resolved. + * + * @deprecated instead consider SymbolSolver.classToResolvedType(Class clazz) */ + @Deprecated public ResolvedType classToResolvedType(Class clazz) { - if (clazz.isPrimitive()) { - return ResolvedPrimitiveType.byName(clazz.getName()); - } - - ResolvedReferenceTypeDeclaration declaration; - if (clazz.isAnnotation()) { - declaration = new ReflectionAnnotationDeclaration(clazz, typeSolver); - } else if (clazz.isEnum()) { - declaration = new ReflectionEnumDeclaration(clazz, typeSolver); - } else if (clazz.isInterface()) { - declaration = new ReflectionInterfaceDeclaration(clazz, typeSolver); - } else { - declaration = new ReflectionClassDeclaration(clazz, typeSolver); - } - return new ReferenceTypeImpl(declaration); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + return symbolSolver.classToResolvedType(clazz); } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java index e7ce3d9995..2be39529a0 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/MethodCallExprContext.java @@ -21,11 +21,9 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; @@ -38,7 +36,6 @@ import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import com.github.javaparser.utils.Pair; import java.util.*; @@ -460,8 +457,8 @@ private Optional solveMethodAsUsage(ResolvedTypeVariable tp, String // and make everything generate like instead of // https://github.com/javaparser/javaparser/issues/2044 bounds = Collections.singletonList( - ResolvedTypeParameterDeclaration.Bound.extendsBound( - JavaParserFacade.get(typeSolver).classToResolvedType(Object.class))); + ResolvedTypeParameterDeclaration.Bound.extendsBound(new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()))); + ; } for (ResolvedTypeParameterDeclaration.Bound bound : bounds) { @@ -488,14 +485,14 @@ private Optional solveMethodAsUsage(ResolvedType type, String name, } else if (wildcardUsage.isExtends()) { return solveMethodAsUsage(wildcardUsage.getBoundedType(), name, argumentsTypes, invokationContext); } else { - return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)), name, argumentsTypes, invokationContext); + return solveMethodAsUsage(new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()), name, argumentsTypes, invokationContext); } } else if (type instanceof ResolvedLambdaConstraintType){ ResolvedLambdaConstraintType constraintType = (ResolvedLambdaConstraintType) type; return solveMethodAsUsage(constraintType.getBound(), name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedArrayType) { // An array inherits methods from Object not from it's component type - return solveMethodAsUsage(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver)), name, argumentsTypes, invokationContext); + return solveMethodAsUsage(new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()), name, argumentsTypes, invokationContext); } else if (type instanceof ResolvedUnionType) { Optional commonAncestor = type.asUnionType().getCommonAncestor(); if (commonAncestor.isPresent()) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java index 3739de0f08..75dbe7f1c8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeVariableDeclaration.java @@ -133,9 +133,7 @@ public List getAncestors(boolean acceptIncompleteList) { // Every type variable declared as a type parameter has a bound. // If no bound is declared for a type variable, Object is assumed. // https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.4 - return Collections.singletonList( - JavaParserFacade.get(typeSolver).classToResolvedType(Object.class).asReferenceType() - ); + return Collections.singletonList(new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject())); } else { List ancestors = new ArrayList<>(); for (ClassOrInterfaceType type : wrappedNode.getTypeBound()) { diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java index aca78f88ba..5278325e94 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/SymbolSolver.java @@ -36,11 +36,16 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.Value; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; +import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; +import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import java.util.List; import java.util.Optional; @@ -163,4 +168,29 @@ public SymbolReference solveTypeInType(ResolvedTypeDecl } return SymbolReference.unsolved(); } + + /** + * Convert a {@link Class} into the corresponding {@link ResolvedType}. + * + * @param clazz The class to be converted. + * + * @return The class resolved. + */ + public ResolvedType classToResolvedType(Class clazz) { + if (clazz.isPrimitive()) { + return ResolvedPrimitiveType.byName(clazz.getName()); + } + + ResolvedReferenceTypeDeclaration declaration; + if (clazz.isAnnotation()) { + declaration = new ReflectionAnnotationDeclaration(clazz, typeSolver); + } else if (clazz.isEnum()) { + declaration = new ReflectionEnumDeclaration(clazz, typeSolver); + } else if (clazz.isInterface()) { + declaration = new ReflectionInterfaceDeclaration(clazz, typeSolver); + } else { + declaration = new ReflectionClassDeclaration(clazz, typeSolver); + } + return new ReferenceTypeImpl(declaration); + } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java index 15b084827c..29055ff25b 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue343Test.java @@ -22,11 +22,13 @@ package com.github.javaparser.symbolsolver; import com.github.javaparser.ast.expr.*; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; +import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,7 +47,7 @@ class Issue343Test extends AbstractResolutionTest { private TypeSolver typeResolver; - private JavaParserFacade javaParserFacade; + private Solver symbolSolver; private ResolvedType getExpressionType(TypeSolver typeSolver, Expression expression) { return JavaParserFacade.get(typeSolver).getType(expression); @@ -54,17 +56,17 @@ private ResolvedType getExpressionType(TypeSolver typeSolver, Expression express @BeforeEach void setup() { typeResolver = new ReflectionTypeSolver(); - javaParserFacade = JavaParserFacade.get(typeResolver); + symbolSolver = new SymbolSolver(typeResolver); } @Test void resolveStringLiteralOutsideAST() { - assertTrue(javaParserFacade.classToResolvedType(String.class).equals(getExpressionType(typeResolver, new StringLiteralExpr("")))); + assertTrue(symbolSolver.classToResolvedType(String.class).equals(getExpressionType(typeResolver, new StringLiteralExpr("")))); } @Test void resolveIntegerLiteralOutsideAST() { - assertEquals(javaParserFacade.classToResolvedType(int.class), getExpressionType(typeResolver, new IntegerLiteralExpr(2))); + assertEquals(symbolSolver.classToResolvedType(int.class), getExpressionType(typeResolver, new IntegerLiteralExpr(2))); } @Test @@ -80,7 +82,7 @@ void toResolveFloatWeNeedTheAST() { @Test void resolveMethodCallOnStringLiteralOutsideAST() { - assertTrue(javaParserFacade.classToResolvedType(int.class).equals(getExpressionType(typeResolver, new MethodCallExpr(new StringLiteralExpr("hello"), "length")))); + assertTrue(symbolSolver.classToResolvedType(int.class).equals(getExpressionType(typeResolver, new MethodCallExpr(new StringLiteralExpr("hello"), "length")))); } @Test diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java index 0306fdc1db..b73590d786 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacadeTest.java @@ -21,8 +21,10 @@ package com.github.javaparser.symbolsolver.javaparsermodel; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import org.junit.jupiter.api.Test; @@ -30,35 +32,35 @@ class JavaParserFacadeTest { - private final TypeSolver typeSolver = new ReflectionTypeSolver(); + private final Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); @Test void classToResolvedType_givenPrimitiveShouldBeAReflectionPrimitiveDeclaration() { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).classToResolvedType(int.class); + ResolvedType resolvedType = symbolSolver.classToResolvedType(int.class); assertEquals(int.class.getCanonicalName(), resolvedType.describe()); } @Test void classToResolvedType_givenClassShouldBeAReflectionClassDeclaration() { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).classToResolvedType(String.class); + ResolvedType resolvedType = symbolSolver.classToResolvedType(String.class); assertEquals(String.class.getCanonicalName(), resolvedType.describe()); } @Test void classToResolvedType_givenClassShouldBeAReflectionInterfaceDeclaration() { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).classToResolvedType(String.class); + ResolvedType resolvedType = symbolSolver.classToResolvedType(String.class); assertEquals(String.class.getCanonicalName(), resolvedType.describe()); } @Test void classToResolvedType_givenEnumShouldBeAReflectionEnumDeclaration() { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).classToResolvedType(TestEnum.class); + ResolvedType resolvedType = symbolSolver.classToResolvedType(TestEnum.class); assertEquals(TestEnum.class.getCanonicalName(), resolvedType.describe()); } @Test void classToResolvedType_givenAnnotationShouldBeAReflectionAnnotationDeclaration() { - ResolvedType resolvedType = JavaParserFacade.get(typeSolver).classToResolvedType(Override.class); + ResolvedType resolvedType = symbolSolver.classToResolvedType(Override.class); assertEquals(Override.class.getCanonicalName(), resolvedType.describe()); } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java index 8b31849760..318a1af36a 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/JavaParserFacadeResolutionTest.java @@ -32,10 +32,12 @@ import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.Navigator; +import com.github.javaparser.resolution.Solver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.SymbolReference; +import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedUnionType; @@ -175,9 +177,8 @@ void solveMultiCatchType() { @Test void classToResolvedTypeViaReflection() { Class clazz = this.getClass(); - ReflectionTypeSolver reflectionTypeSolver = new ReflectionTypeSolver(); - JavaParserFacade facade = JavaParserFacade.get(reflectionTypeSolver); - ResolvedType resolvedType = facade.classToResolvedType(clazz); + Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); + ResolvedType resolvedType = symbolSolver.classToResolvedType(clazz); assertNotNull(resolvedType); assertTrue(resolvedType.isReferenceType()); From ec206dc4493bfba0dc7c5f435fa9281cfcc8492d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 11:41:45 +0100 Subject: [PATCH 143/280] Update changelog --- changelog.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index e908e4d7ca..9f64c55656 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ -Next Release (Version 3.24.9) +Next Release (Version 3.24.10) ------------------ -[issues resolved](https://github.com/javaparser/javaparser/milestone/193?closed=1) +[issues resolved](https://github.com/javaparser/javaparser/milestone/194?closed=1) ### Added ### Changed @@ -9,6 +9,55 @@ Next Release (Version 3.24.9) ### Fixed ### Security + +Next Release (Version 3.24.9) +------------------ +[issues resolved](https://github.com/javaparser/javaparser/milestone/193?closed=1) + +### Highlights + +* Remove "executable" bit from code files (PR [#3755](https://github.com/javaparser/javaparser/pull/3755) by [@icmdaf](https://github.com/icmdaf)) + +### Added + +* Created TypeSolverBuilder (PR [#3421](https://github.com/javaparser/javaparser/pull/3421) by [@4everTheOne](https://github.com/4everTheOne)) + +### Changed + +* Changing, in test classes, the initialization of the lexical preserva… (PR [#3779](https://github.com/javaparser/javaparser/pull/3779) by [@jlerbsc](https://github.com/jlerbsc)) +* chore(deps): bump maven-dependency-plugin from 3.3.0 to 3.4.0 (PR [#3770](https://github.com/javaparser/javaparser/pull/3770) by [@dependabot[bot]](https://github.com/apps/dependabot)) +* chore(deps): bump maven-install-plugin from 3.0.1 to 3.1.0 (PR [#3756](https://github.com/javaparser/javaparser/pull/3756) by [@dependabot[bot]](https://github.com/apps/dependabot)) + +### Fixed + +* Fix: #3195 Resolved methods in outer classes not inferred correcly (PR [#3778](https://github.com/javaparser/javaparser/pull/3778) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3681 LineComment alwaysing trimming content (PR [#3777](https://github.com/javaparser/javaparser/pull/3777) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3773 Replacing nodes causes error in lexical preserving printer… (PR [#3776](https://github.com/javaparser/javaparser/pull/3776) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #2517 Modifying some nodes with the lexicalPreservation enabled … (PR [#3775](https://github.com/javaparser/javaparser/pull/3775) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3725 JavaParserFacade var type in for-each loop cannot be resolved (PR [#3768](https://github.com/javaparser/javaparser/pull/3768) by [@abego](https://github.com/abego)) +* Fix: #3216 LexicalPreservingPrinter add Wrong indentation when removing comments (PR [#3766](https://github.com/javaparser/javaparser/pull/3766) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3472 Line comment removal causes IllegalStateException with LexicalPreservingPrinter (PR [#3765](https://github.com/javaparser/javaparser/pull/3765) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3441 LexicalPreservingPrinter prints wrong output with line com… (PR [#3764](https://github.com/javaparser/javaparser/pull/3764) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #2137 ClassOrInterfaceDeclaration addMember using index (PR [#3763](https://github.com/javaparser/javaparser/pull/3763) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3761 Lexical preserving corrupts source when adding a modifier in first position (PR [#3762](https://github.com/javaparser/javaparser/pull/3762) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3693 Removing modifiers from method declaration results in loss… (PR [#3760](https://github.com/javaparser/javaparser/pull/3760) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: #3750 Lexical preserving corrupts source (PR [#3759](https://github.com/javaparser/javaparser/pull/3759) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: Fix the indentation generated by the LexicalPreservingPrinter wh… (PR [#3758](https://github.com/javaparser/javaparser/pull/3758) by [@jlerbsc](https://github.com/jlerbsc)) + +### Security + +* Remove "executable" bit from code files (PR [#3755](https://github.com/javaparser/javaparser/pull/3755) by [@icmdaf](https://github.com/icmdaf)) + +### :heart: Contributors + +Thank You to all contributors who worked on this release! + +* [@abego](https://github.com/abego) +* [@jlerbsc](https://github.com/jlerbsc) +* [@icmdaf](https://github.com/icmdaf) +* [@4everTheOne](https://github.com/4everTheOne) + + Version 3.24.8 -------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/192?closed=1) From eb8d88cfb5264de96c252a491f6444c3c956d33c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 11:43:31 +0100 Subject: [PATCH 144/280] update readme --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 5a70f88cce..8140767d66 100644 --- a/readme.md +++ b/readme.md @@ -37,14 +37,14 @@ Just add the following to your maven configuration or tailor to your own depende com.github.javaparser javaparser-symbol-solver-core - 3.24.8 + 3.24.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.24.8' +implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.24.9' ``` Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver. @@ -59,14 +59,14 @@ Using the dependency above will add both JavaParser and JavaSymbolSolver to your com.github.javaparser javaparser-core - 3.24.8 + 3.24.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core:3.24.8' +implementation 'com.github.javaparser:javaparser-core:3.24.9' ``` Since version 3.6.17 the AST can be serialized to JSON. @@ -78,14 +78,14 @@ There is a separate module for this: com.github.javaparser javaparser-core-serialization - 3.24.8 + 3.24.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core-serialization:3.24.8' +implementation 'com.github.javaparser:javaparser-core-serialization:3.24.9' ``` ## How To Compile Sources From c34e87abf0f96d5bf6fe061a24c5eed7b1dbfc77 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 11:45:15 +0100 Subject: [PATCH 145/280] [maven-release-plugin] prepare release javaparser-parent-3.24.9 --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 46b4dad6b4..ee898ee56b 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index cc26f3fe42..c67ab74940 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 4bd2790dff..6139ea316d 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index f647b273c0..5eaa281079 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index ca74bb4c31..856adc67dd 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 38fc7a39df..1e092e468e 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 65a8e162db..42d135f57f 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index eeb8a7565a..1b4f4483b6 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9-SNAPSHOT + 3.24.9 4.0.0 diff --git a/pom.xml b/pom.xml index b18d500643..b4d349ae61 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.24.9-SNAPSHOT + 3.24.9 javaparser-parent https://github.com/javaparser From 186631b0f953d5ce4976468a962ba585d8cc638e Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 12:17:48 +0100 Subject: [PATCH 146/280] [maven-release-plugin] prepare for next development iteration --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index ee898ee56b..c3ae9e0902 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index c67ab74940..d49aebaccd 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 6139ea316d..9d1caec42f 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 5eaa281079..32a512c1c3 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index 856adc67dd..5bd0763bd7 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 1e092e468e..6219edda3d 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 42d135f57f..dbee5e8e38 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index 1b4f4483b6..8c80cd0f4c 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.24.9 + 3.24.10-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index b4d349ae61..edfdafe52d 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.24.9 + 3.24.10-SNAPSHOT javaparser-parent https://github.com/javaparser From 596990a49dd4a1dffeccd1cb9f4f180cae281590 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 13:54:47 +0100 Subject: [PATCH 147/280] Update bnd file --- javaparser-core/bnd.bnd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/javaparser-core/bnd.bnd b/javaparser-core/bnd.bnd index 9e678f6b78..f33a3fda30 100644 --- a/javaparser-core/bnd.bnd +++ b/javaparser-core/bnd.bnd @@ -32,6 +32,10 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core com.github.javaparser.quality, \ com.github.javaparser.resolution, \ com.github.javaparser.resolution.declarations, \ + com.github.javaparser.resolution.logic, \ + com.github.javaparser.resolution.model, \ + com.github.javaparser.resolution.model.typesystem, \ + com.github.javaparser.resolution.promotion, \ com.github.javaparser.resolution.types, \ com.github.javaparser.resolution.types.parametrization, \ com.github.javaparser.utils From 0acce6b216b9d4d79fcfaa37a7f0250b38a44a34 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 12 Dec 2022 14:00:46 +0100 Subject: [PATCH 148/280] Update bnd file --- javaparser-core/bnd.bnd | 1 + 1 file changed, 1 insertion(+) diff --git a/javaparser-core/bnd.bnd b/javaparser-core/bnd.bnd index f33a3fda30..b4d6f4e35a 100644 --- a/javaparser-core/bnd.bnd +++ b/javaparser-core/bnd.bnd @@ -40,6 +40,7 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core com.github.javaparser.resolution.types.parametrization, \ com.github.javaparser.utils + # Don't use the project's version for the packages # We prefer not setting a version as we don't follow OSGi version semantics -nodefaultversion: true From 6f2d866a39ca48bc931e7f261a39bfc12d77f8d1 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 13 Dec 2022 13:25:31 +0100 Subject: [PATCH 149/280] Add utility methods in AbstractSymbolResolutionTest and setup a ParserConfiguration with a default symbol resolver --- .../symbolsolver/AbstractSymbolResolutionTest.java | 13 ++++++++++++- .../resolution/AbstractResolutionTest.java | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/AbstractSymbolResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/AbstractSymbolResolutionTest.java index d6205d86f3..df05d5c5b3 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/AbstractSymbolResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/AbstractSymbolResolutionTest.java @@ -30,7 +30,10 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.CodeGenerationUtils; public abstract class AbstractSymbolResolutionTest { @@ -39,7 +42,7 @@ public abstract class AbstractSymbolResolutionTest { public void reset() { // reset configuration to not potentially disturb others tests. // So we have to set specific configuration between each test. - StaticJavaParser.setConfiguration(new ParserConfiguration()); + StaticJavaParser.setConfiguration(new ParserConfiguration().setSymbolResolver(symbolResolver(defaultTypeSolver()))); } @AfterAll @@ -144,4 +147,12 @@ protected static Path adaptPath(Path path) { protected static Path adaptPath(String path) { return adaptPath(Paths.get(path)); } + + protected SymbolResolver symbolResolver(TypeSolver typeSolver) { + return new JavaSymbolSolver(typeSolver); + } + + protected TypeSolver defaultTypeSolver() { + return new ReflectionTypeSolver(); + } } diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java index 7b44c0aa2d..5e53b2a569 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java @@ -27,6 +27,7 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; @@ -70,6 +71,7 @@ private CompilationUnit parseSample(String sampleName, String extension, TypeSol } protected JavaParser createParserWithResolver(TypeSolver typeSolver) { - return new JavaParser(new ParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver))); + return new JavaParser(new ParserConfiguration().setSymbolResolver(symbolResolver(typeSolver))); } + } From b45760323abcbd890e51f358b5d02c10ce2120d4 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 13 Dec 2022 19:01:53 +0100 Subject: [PATCH 150/280] Add InMemoryCache in CombinedTypeSolver as a default cache --- .../resolution/typesolvers/CombinedTypeSolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java index 184804ada5..f9e33344e9 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typesolvers/CombinedTypeSolver.java @@ -26,7 +26,7 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.symbolsolver.cache.Cache; -import com.github.javaparser.symbolsolver.cache.NoCache; +import com.github.javaparser.symbolsolver.cache.InMemoryCache; import java.util.*; import java.util.function.Predicate; @@ -72,7 +72,7 @@ public CombinedTypeSolver(Iterable elements) { /** @see #exceptionHandler */ public CombinedTypeSolver(Predicate exceptionHandler, Iterable elements) { - this(exceptionHandler, elements, NoCache.create()); + this(exceptionHandler, elements, InMemoryCache.create()); } /** From 77ccb32a143d7592e648570b6bd2f720d22d08d2 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 13 Dec 2022 21:04:55 +0100 Subject: [PATCH 151/280] Fix: JavaParserFacade must be found from the root typeSolver --- .../symbolsolver/javaparsermodel/JavaParserFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index cf5603342c..9fddbe7b53 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -91,7 +91,7 @@ public class JavaParserFacade { * @see https://github.com/javaparser/javaparser/issues/2671 */ public static synchronized JavaParserFacade get(TypeSolver typeSolver) { - return instances.computeIfAbsent(typeSolver, JavaParserFacade::new); + return instances.computeIfAbsent(typeSolver.getRoot(), JavaParserFacade::new); } /** From a2cda3ff9368c4b0d00fea7cff18d4ce39171c56 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 14 Dec 2022 08:57:20 +0100 Subject: [PATCH 152/280] Move JavaParserFactory.toTypeDeclaration method to SymbolResolver to break dependencies with the symbol solver module --- .../java/com/github/javaparser/ast/Node.java | 2 +- .../javaparser/resolution/SymbolResolver.java | 12 +++++-- .../symbolsolver/JavaSymbolSolver.java | 36 ++++++++++++++++--- .../javaparsermodel/JavaParserFacade.java | 13 ++++--- .../javaparsermodel/JavaParserFactory.java | 28 --------------- .../JavaParserMethodDeclaration.java | 11 +++++- .../declarations/JavaParserTypeAdapter.java | 3 +- .../resolution/AbstractResolutionTest.java | 1 + 8 files changed, 60 insertions(+), 46 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java index 2cbc4dcb8a..fa95992d8c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -782,7 +782,7 @@ public LineSeparator getLineEndingStyle() { return LineSeparator.SYSTEM; } - protected SymbolResolver getSymbolResolver() { + public SymbolResolver getSymbolResolver() { return findCompilationUnit().map(cu -> { if (cu.containsData(SYMBOL_RESOLVER_KEY)) { return cu.getData(SYMBOL_RESOLVER_KEY); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java index f6fde474a3..47404af977 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java @@ -23,13 +23,13 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; public interface SymbolResolver { /** - * For a reference it would find the corresponding - * declaration. + * For a reference it would find the corresponding declaration. */ T resolveDeclaration(Node node, Class resultClass); @@ -38,5 +38,13 @@ public interface SymbolResolver { */ T toResolvedType(Type javaparserType, Class resultClass); + /** + * For an expression it would find the corresponding resolved type. + */ ResolvedType calculateType(Expression expression); + + /** + * For a node it would find the corresponding reference type declaration. + */ + ResolvedReferenceTypeDeclaration toTypeDeclaration(Node node); } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java index 319c3da527..fbef055d7f 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/JavaSymbolSolver.java @@ -21,12 +21,16 @@ package com.github.javaparser.symbolsolver; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.quality.NotNull; import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; @@ -35,7 +39,6 @@ import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.*; /** @@ -72,7 +75,7 @@ public ResolvedType getType() { private TypeSolver typeSolver; - public JavaSymbolSolver(TypeSolver typeSolver) { + public JavaSymbolSolver(@NotNull TypeSolver typeSolver) { this.typeSolver = typeSolver; } @@ -90,13 +93,13 @@ public T resolveDeclaration(Node node, Class resultClass) { return resultClass.cast(new JavaParserMethodDeclaration((MethodDeclaration) node, typeSolver)); } if (node instanceof ClassOrInterfaceDeclaration) { - ResolvedReferenceTypeDeclaration resolved = JavaParserFactory.toTypeDeclaration(node, typeSolver); + ResolvedReferenceTypeDeclaration resolved = toTypeDeclaration(node); if (resultClass.isInstance(resolved)) { return resultClass.cast(resolved); } } if (node instanceof EnumDeclaration) { - ResolvedReferenceTypeDeclaration resolved = JavaParserFactory.toTypeDeclaration(node, typeSolver); + ResolvedReferenceTypeDeclaration resolved = toTypeDeclaration(node); if (resultClass.isInstance(resolved)) { return resultClass.cast(resolved); } @@ -122,7 +125,7 @@ public T resolveDeclaration(Node node, Class resultClass) { } } if (node instanceof AnnotationDeclaration) { - ResolvedReferenceTypeDeclaration resolved = JavaParserFactory.toTypeDeclaration(node, typeSolver); + ResolvedReferenceTypeDeclaration resolved = toTypeDeclaration(node); if (resultClass.isInstance(resolved)) { return resultClass.cast(resolved); } @@ -290,4 +293,27 @@ public T toResolvedType(Type javaparserType, Class resultClass) { public ResolvedType calculateType(Expression expression) { return JavaParserFacade.get(typeSolver).getType(expression); } + + @Override + public ResolvedReferenceTypeDeclaration toTypeDeclaration(Node node) { + if (node instanceof ClassOrInterfaceDeclaration) { + if (((ClassOrInterfaceDeclaration) node).isInterface()) { + return new JavaParserInterfaceDeclaration((ClassOrInterfaceDeclaration) node, typeSolver); + } + return new JavaParserClassDeclaration((ClassOrInterfaceDeclaration) node, typeSolver); + } + if (node instanceof TypeParameter) { + return new JavaParserTypeParameter((TypeParameter) node, typeSolver); + } + if (node instanceof EnumDeclaration) { + return new JavaParserEnumDeclaration((EnumDeclaration) node, typeSolver); + } + if (node instanceof AnnotationDeclaration) { + return new JavaParserAnnotationDeclaration((AnnotationDeclaration) node, typeSolver); + } + if (node instanceof EnumConstantDeclaration) { + return new JavaParserEnumDeclaration((EnumDeclaration) demandParentNode((EnumConstantDeclaration) node), typeSolver); + } + throw new IllegalArgumentException("Cannot get a reference type declaration from " + node.getClass().getCanonicalName()); + } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java index 9fddbe7b53..6b66c6b643 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFacade.java @@ -34,6 +34,7 @@ import com.github.javaparser.resolution.MethodAmbiguityException; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.Solver; +import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.*; @@ -43,14 +44,10 @@ import com.github.javaparser.resolution.model.SymbolReference; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.*; -import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap; +import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.FieldAccessContext; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionEnumDeclaration; -import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.utils.Log; @@ -106,6 +103,7 @@ public static void clearInstances() { private final TypeSolver typeSolver; private final TypeExtractor typeExtractor; private final Solver symbolSolver; + private final SymbolResolver symbolResolver; private FailureHandler failureHandler; @@ -114,6 +112,7 @@ private JavaParserFacade(TypeSolver typeSolver) { this.symbolSolver = new SymbolSolver(typeSolver); this.typeExtractor = new TypeExtractor(this.typeSolver, this); this.failureHandler = new FailureHandler(); + this.symbolResolver = new JavaSymbolSolver(this.typeSolver); } public TypeSolver getTypeSolver() { @@ -678,7 +677,7 @@ public ResolvedReferenceTypeDeclaration getTypeDeclaration(Node node) { } public ResolvedReferenceTypeDeclaration getTypeDeclaration(ClassOrInterfaceDeclaration classOrInterfaceDeclaration) { - return JavaParserFactory.toTypeDeclaration(classOrInterfaceDeclaration, typeSolver); + return symbolResolver.toTypeDeclaration(classOrInterfaceDeclaration); } /** @@ -701,7 +700,7 @@ public ResolvedType getTypeOfThisIn(Node node) { } public ResolvedReferenceTypeDeclaration getTypeDeclaration(TypeDeclaration typeDeclaration) { - return JavaParserFactory.toTypeDeclaration(typeDeclaration, typeSolver); + return symbolResolver.toTypeDeclaration(typeDeclaration); } /** diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java index 65e229d9c4..e789ca9c5b 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/JavaParserFactory.java @@ -29,17 +29,10 @@ import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.TypeParameter; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.SymbolDeclarator; -import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.contexts.*; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.FieldSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.NoSymbolDeclarator; import com.github.javaparser.symbolsolver.javaparsermodel.declarators.ParameterSymbolDeclarator; @@ -169,25 +162,4 @@ public static SymbolDeclarator getSymbolDeclarator(Node node, TypeSolver typeSol return new NoSymbolDeclarator<>(node, typeSolver); } - public static ResolvedReferenceTypeDeclaration toTypeDeclaration(Node node, TypeSolver typeSolver) { - if (node instanceof ClassOrInterfaceDeclaration) { - if (((ClassOrInterfaceDeclaration) node).isInterface()) { - return new JavaParserInterfaceDeclaration((ClassOrInterfaceDeclaration) node, typeSolver); - } - return new JavaParserClassDeclaration((ClassOrInterfaceDeclaration) node, typeSolver); - } - if (node instanceof TypeParameter) { - return new JavaParserTypeParameter((TypeParameter) node, typeSolver); - } - if (node instanceof EnumDeclaration) { - return new JavaParserEnumDeclaration((EnumDeclaration) node, typeSolver); - } - if (node instanceof AnnotationDeclaration) { - return new JavaParserAnnotationDeclaration((AnnotationDeclaration) node, typeSolver); - } - if (node instanceof EnumConstantDeclaration) { - return new JavaParserEnumDeclaration((EnumDeclaration) demandParentNode((EnumConstantDeclaration) node), typeSolver); - } - throw new IllegalArgumentException(node.getClass().getCanonicalName()); - } } diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java index 1b9714fff2..c2f06e6787 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserMethodDeclaration.java @@ -26,12 +26,14 @@ import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.MethodUsage; +import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedType; +import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability; import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; @@ -70,7 +72,14 @@ public ResolvedReferenceTypeDeclaration declaringType() { ObjectCreationExpr parentNode = (ObjectCreationExpr) demandParentNode(wrappedNode); return new JavaParserAnonymousClassDeclaration(parentNode, typeSolver); } - return JavaParserFactory.toTypeDeclaration(demandParentNode(wrappedNode), typeSolver); + // TODO Fix: to use getSymbolResolver() we have to fix many unit tests + // that throw IllegalStateException("Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration" + // return wrappedNode.getSymbolResolver().toTypeDeclaration(wrappedNode); + return symbolResolver(typeSolver).toTypeDeclaration(demandParentNode(wrappedNode)); + } + + private SymbolResolver symbolResolver(TypeSolver typeSolver) { + return new JavaSymbolSolver(typeSolver); } @Override diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java index 66d55cedfd..176b22e4d8 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/declarations/JavaParserTypeAdapter.java @@ -37,7 +37,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; import java.util.*; @@ -156,7 +155,7 @@ public SymbolReference solveType(String name) { public Optional containerType() { return wrappedNode .getParentNode() - .map(node -> JavaParserFactory.toTypeDeclaration(node, typeSolver)); + .map(node -> node.getSymbolResolver().toTypeDeclaration(node)); } public List getFieldsForDeclaredVariables() { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java index 5e53b2a569..8a5f99d86f 100644 --- a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/AbstractResolutionTest.java @@ -31,6 +31,7 @@ import com.github.javaparser.resolution.TypeSolver; import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; import com.github.javaparser.symbolsolver.JavaSymbolSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; /** * @author Federico Tomassetti From 8076ddc89c8569eefcc512ca31e1c5546e962548 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 14 Dec 2022 09:05:56 +0100 Subject: [PATCH 153/280] Fix: In JavaParserJsonDeserializerTest, new SymbolResolver instance must declare the new method toTypeDeclaration --- .../serialization/JavaParserJsonDeserializerTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java b/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java index 029d70203f..16e5b8a8de 100644 --- a/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java +++ b/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java @@ -31,6 +31,7 @@ import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.JavadocBlockTag; import com.github.javaparser.resolution.SymbolResolver; +import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.utils.LineSeparator; import org.junit.jupiter.api.AfterAll; @@ -196,6 +197,11 @@ public T toResolvedType(Type javaparserType, Class resultClass) { public ResolvedType calculateType(Expression expression) { return null; } + + @Override + public ResolvedReferenceTypeDeclaration toTypeDeclaration(Node node) { + return null; + } }; StaticJavaParser.getConfiguration().setSymbolResolver(stubResolver); CompilationUnit cu = parse("public class X{} class Z{}"); From 41cf8cdacfdc8dcf2e317731344758772cdccd3b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 11:49:10 +0000 Subject: [PATCH 154/280] chore(deps): update dependency org.apache.maven.plugins:maven-checkstyle-plugin to v3.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8187b580e8..9ceff67e38 100644 --- a/pom.xml +++ b/pom.xml @@ -342,7 +342,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.2 + 3.2.0 dev-files/JavaParser-CheckStyle.xml true From 5fd2a78f88bc1dd43063a3dd21db4d7376c5e579 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 23:01:03 +0000 Subject: [PATCH 155/280] chore(deps): bump versions-maven-plugin from 2.13.0 to 2.14.1 Bumps [versions-maven-plugin](https://github.com/mojohaus/versions) from 2.13.0 to 2.14.1. - [Release notes](https://github.com/mojohaus/versions/releases) - [Changelog](https://github.com/mojohaus/versions/blob/master/ReleaseNotes.md) - [Commits](https://github.com/mojohaus/versions/compare/2.13.0...2.14.1) --- updated-dependencies: - dependency-name: org.codehaus.mojo:versions-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9ceff67e38..969afa6e69 100644 --- a/pom.xml +++ b/pom.xml @@ -334,7 +334,7 @@ org.codehaus.mojo versions-maven-plugin - 2.13.0 + 2.14.1 false From 78a5c502a639156d97ff2ea0c0544c8d6c4de681 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:06:14 +0000 Subject: [PATCH 156/280] chore(deps): bump actions/checkout from 3.1.0 to 3.2.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.1.0...v3.2.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/create_github_release.yml | 2 +- .github/workflows/maven_tests.yml | 4 ++-- .github/workflows/prepare_release_changelog.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create_github_release.yml b/.github/workflows/create_github_release.yml index 293d631a92..a22e195b8b 100644 --- a/.github/workflows/create_github_release.yml +++ b/.github/workflows/create_github_release.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 - name: Create Release id: create_release diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 5e4bc5c639..3c6ca23f0c 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -45,7 +45,7 @@ jobs: steps: ## Checkout the current version of the code from the repo. - name: Checkout latest code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 with: fetch-depth: "0" @@ -109,7 +109,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout latest code - uses: actions/checkout@v3 + uses: actions/checkout@v3.2.0 with: fetch-depth: "0" - name: Set up JDK 11 diff --git a/.github/workflows/prepare_release_changelog.yml b/.github/workflows/prepare_release_changelog.yml index 595c5fb421..cbba19655d 100644 --- a/.github/workflows/prepare_release_changelog.yml +++ b/.github/workflows/prepare_release_changelog.yml @@ -15,7 +15,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 # Setup Java 11 environment for the next steps - name: Setup Java From 9dfc42577a75a02ed46e495a9e4360bf017addb0 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:06:23 +0000 Subject: [PATCH 157/280] Removed warning for star imports --- dev-files/JavaParser-CheckStyle.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml index 16a5ecd7dd..935cc2ae54 100644 --- a/dev-files/JavaParser-CheckStyle.xml +++ b/dev-files/JavaParser-CheckStyle.xml @@ -28,11 +28,6 @@ - - - - - Date: Fri, 16 Dec 2022 20:06:52 +0000 Subject: [PATCH 158/280] Fixed Imports order, so they don't have to be sorted by name inside groups --- dev-files/JavaParser-CheckStyle.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dev-files/JavaParser-CheckStyle.xml b/dev-files/JavaParser-CheckStyle.xml index 935cc2ae54..b4c990e23d 100644 --- a/dev-files/JavaParser-CheckStyle.xml +++ b/dev-files/JavaParser-CheckStyle.xml @@ -31,8 +31,11 @@ - + value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/> + + + + From 8e860580308d7e621a90a0abdd8c351a16d7feac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:23:30 +0000 Subject: [PATCH 159/280] chore(deps): bump checkstyle from 8.45.1 to 10.5.0 Bumps [checkstyle](https://github.com/checkstyle/checkstyle) from 8.45.1 to 10.5.0. - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](https://github.com/checkstyle/checkstyle/compare/checkstyle-8.45.1...checkstyle-10.5.0) --- updated-dependencies: - dependency-name: com.puppycrawl.tools:checkstyle dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 969afa6e69..39bd9ac2eb 100644 --- a/pom.xml +++ b/pom.xml @@ -352,7 +352,7 @@ com.puppycrawl.tools checkstyle - 8.45.1 + 10.5.0 From 1e34628ceb0fef5499fd22bb59b21d1cfd5bd100 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:29:10 +0000 Subject: [PATCH 160/280] Organized Imports for JavaParser-Core-Generators --- .../main/java/com/github/javaparser/generator/Generator.java | 2 +- .../github/javaparser/generator/core/other/BndGenerator.java | 4 +++- .../generator/core/visitor/CloneVisitorGenerator.java | 4 ++-- .../generator/core/visitor/EqualsVisitorGenerator.java | 2 +- .../core/visitor/GenericVisitorAdapterGenerator.java | 2 +- .../generator/core/visitor/GenericVisitorGenerator.java | 2 +- .../generator/core/visitor/HashCodeVisitorGenerator.java | 4 ++-- .../core/visitor/NoCommentEqualsVisitorGenerator.java | 4 ++-- .../core/visitor/NoCommentHashCodeVisitorGenerator.java | 4 ++-- .../generator/core/visitor/VoidVisitorAdapterGenerator.java | 2 +- 10 files changed, 16 insertions(+), 14 deletions(-) diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/Generator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/Generator.java index 7ced7bc8cb..7c99e7d716 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/Generator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/Generator.java @@ -21,6 +21,7 @@ package com.github.javaparser.generator; +import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.CallableDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -28,7 +29,6 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; -import com.github.javaparser.ast.Generated; import com.github.javaparser.utils.SourceRoot; import java.util.List; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/BndGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/BndGenerator.java index 2c5236378b..c132ab2af6 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/BndGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/BndGenerator.java @@ -25,7 +25,9 @@ import com.github.javaparser.utils.Log; import com.github.javaparser.utils.SourceRoot; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/CloneVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/CloneVisitorGenerator.java index b741a6e2f3..5ebb24e561 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/CloneVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/CloneVisitorGenerator.java @@ -25,11 +25,11 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.generator.VisitorGenerator; +import com.github.javaparser.metamodel.BaseNodeMetaModel; import com.github.javaparser.metamodel.CompilationUnitMetaModel; +import com.github.javaparser.metamodel.PropertyMetaModel; import com.github.javaparser.utils.SeparatedItemStringBuilder; import com.github.javaparser.utils.SourceRoot; -import com.github.javaparser.metamodel.BaseNodeMetaModel; -import com.github.javaparser.metamodel.PropertyMetaModel; import static com.github.javaparser.utils.CodeGenerationUtils.f; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/EqualsVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/EqualsVisitorGenerator.java index 2bc648f3ba..a96891cf04 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/EqualsVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/EqualsVisitorGenerator.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.generator.VisitorGenerator; -import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.metamodel.BaseNodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import com.github.javaparser.utils.SourceRoot; import static com.github.javaparser.utils.CodeGenerationUtils.f; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorAdapterGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorAdapterGenerator.java index 61453337ce..ecf58389cb 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorAdapterGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorAdapterGenerator.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.generator.VisitorGenerator; -import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.metamodel.BaseNodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import com.github.javaparser.utils.SourceRoot; import static com.github.javaparser.utils.CodeGenerationUtils.f; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorGenerator.java index c43a41521d..9db8b6fada 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/GenericVisitorGenerator.java @@ -24,8 +24,8 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.generator.VisitorGenerator; -import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.metamodel.BaseNodeMetaModel; +import com.github.javaparser.utils.SourceRoot; /** * Generates JavaParser's GenericVisitor. diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/HashCodeVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/HashCodeVisitorGenerator.java index 4122f01974..c927d24c49 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/HashCodeVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/HashCodeVisitorGenerator.java @@ -25,10 +25,10 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.generator.VisitorGenerator; -import com.github.javaparser.utils.SeparatedItemStringBuilder; -import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.metamodel.BaseNodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import com.github.javaparser.utils.SeparatedItemStringBuilder; +import com.github.javaparser.utils.SourceRoot; import java.util.List; diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentEqualsVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentEqualsVisitorGenerator.java index c1147a36e4..fae45c88c0 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentEqualsVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentEqualsVisitorGenerator.java @@ -21,8 +21,6 @@ package com.github.javaparser.generator.core.visitor; -import static com.github.javaparser.utils.CodeGenerationUtils.f; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; @@ -32,6 +30,8 @@ import com.github.javaparser.metamodel.PropertyMetaModel; import com.github.javaparser.utils.SourceRoot; +import static com.github.javaparser.utils.CodeGenerationUtils.f; + public class NoCommentEqualsVisitorGenerator extends VisitorGenerator { public NoCommentEqualsVisitorGenerator(SourceRoot sourceRoot) { diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentHashCodeVisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentHashCodeVisitorGenerator.java index 4554840460..2b46f444c6 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentHashCodeVisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/NoCommentHashCodeVisitorGenerator.java @@ -21,8 +21,6 @@ package com.github.javaparser.generator.core.visitor; -import java.util.List; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; @@ -33,6 +31,8 @@ import com.github.javaparser.utils.SeparatedItemStringBuilder; import com.github.javaparser.utils.SourceRoot; +import java.util.List; + import static com.github.javaparser.StaticJavaParser.parseStatement; public class NoCommentHashCodeVisitorGenerator extends VisitorGenerator { diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/VoidVisitorAdapterGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/VoidVisitorAdapterGenerator.java index 714f71dc8a..eb2b8978bc 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/VoidVisitorAdapterGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/visitor/VoidVisitorAdapterGenerator.java @@ -25,9 +25,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.generator.VisitorGenerator; -import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.metamodel.BaseNodeMetaModel; import com.github.javaparser.metamodel.PropertyMetaModel; +import com.github.javaparser.utils.SourceRoot; import static com.github.javaparser.utils.CodeGenerationUtils.f; From cde2ecb03c3732b6164995f716a8ef1592ed4758 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:29:44 +0000 Subject: [PATCH 161/280] Organized Imports for JavaParser-Core-Metamodel-Generator --- .../generator/AbstractGenerator.java | 6 +----- .../metamodel/MetaModelGenerator.java | 20 +++++++++---------- .../metamodel/NodeMetaModelGenerator.java | 12 ++--------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/AbstractGenerator.java b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/AbstractGenerator.java index 74992d1e9a..69b9e441e7 100644 --- a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/AbstractGenerator.java +++ b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/AbstractGenerator.java @@ -28,11 +28,7 @@ import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.CallableDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.expr.AnnotationExpr; diff --git a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java index 196acefc38..5e6394f707 100644 --- a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java +++ b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java @@ -21,23 +21,14 @@ package com.github.javaparser.generator.metamodel; -import static com.github.javaparser.utils.Utils.decapitalize; - -import java.lang.reflect.Field; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.CompactConstructorDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.generator.AbstractGenerator; import com.github.javaparser.printer.DefaultPrettyPrinter; @@ -48,6 +39,15 @@ import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.utils.SourceRoot; +import java.lang.reflect.Field; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import static com.github.javaparser.utils.Utils.decapitalize; + public class MetaModelGenerator extends AbstractGenerator { static final String BASE_NODE_META_MODEL = "BaseNodeMetaModel"; diff --git a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/NodeMetaModelGenerator.java b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/NodeMetaModelGenerator.java index 9b23d9c74a..555efe7e37 100644 --- a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/NodeMetaModelGenerator.java +++ b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/NodeMetaModelGenerator.java @@ -24,11 +24,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.generator.AbstractGenerator; import com.github.javaparser.metamodel.DerivedProperty; @@ -37,11 +33,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; +import java.util.*; import static com.github.javaparser.StaticJavaParser.*; import static com.github.javaparser.ast.Modifier.Keyword.*; From db3320fe1356b3d7a8bd5d30072f16b49cc79647 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:30:09 +0000 Subject: [PATCH 162/280] Organized Imports for JavaParser-Core-Serialization --- .../serialization/JavaParserJsonDeserializer.java | 9 +++++++-- .../serialization/JavaParserJsonDeserializerTest.java | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/javaparser-core-serialization/src/main/java/com/github/javaparser/serialization/JavaParserJsonDeserializer.java b/javaparser-core-serialization/src/main/java/com/github/javaparser/serialization/JavaParserJsonDeserializer.java index 242bc3b66d..6a8ffe5b12 100644 --- a/javaparser-core-serialization/src/main/java/com/github/javaparser/serialization/JavaParserJsonDeserializer.java +++ b/javaparser-core-serialization/src/main/java/com/github/javaparser/serialization/JavaParserJsonDeserializer.java @@ -29,8 +29,13 @@ import com.github.javaparser.metamodel.PropertyMetaModel; import com.github.javaparser.utils.Log; -import javax.json.*; -import java.util.*; +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonValue; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import static com.github.javaparser.ast.NodeList.toNodeList; import static com.github.javaparser.metamodel.JavaParserMetaModel.getNodeMetaModel; diff --git a/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java b/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java index 16e5b8a8de..24d4b9e13a 100644 --- a/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java +++ b/javaparser-core-serialization/src/test/java/com/github/javaparser/serialization/JavaParserJsonDeserializerTest.java @@ -20,7 +20,10 @@ */ package com.github.javaparser.serialization; -import com.github.javaparser.*; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.Range; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.TokenRange; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; From dc23afee0257ae73af15ba5ed243a46b596162a0 Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:31:01 +0000 Subject: [PATCH 163/280] Organized Imports for JavaParser-Core-Testing-BDD --- .../com/github/javaparser/steps/CommentParsingSteps.java | 8 +++----- .../javaparser/steps/ExistenceOfParentNodeVerifier.java | 7 +++++-- .../com/github/javaparser/steps/ManipulationSteps.java | 2 +- .../java/com/github/javaparser/steps/ParsingSteps.java | 2 +- .../java/com/github/javaparser/steps/SharedSteps.java | 2 +- .../github/javaparser/visitors/PositionTestVisitor.java | 5 ++++- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/CommentParsingSteps.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/CommentParsingSteps.java index 97ae99b4d4..6f09d93467 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/CommentParsingSteps.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/CommentParsingSteps.java @@ -33,7 +33,6 @@ import com.github.javaparser.printer.PrettyPrinter; import com.github.javaparser.printer.Printer; import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration; - import org.jbehave.core.annotations.Alias; import org.jbehave.core.annotations.Given; import org.jbehave.core.annotations.Then; @@ -41,20 +40,19 @@ import org.jbehave.core.model.ExamplesTable; import org.jbehave.core.steps.Parameters; -import java.io.IOException; import java.nio.charset.Charset; import java.util.Iterator; import java.util.Set; import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.Providers.*; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.Range.range; import static com.github.javaparser.steps.SharedSteps.getMemberByTypeAndPosition; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.fail; public class CommentParsingSteps { diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ExistenceOfParentNodeVerifier.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ExistenceOfParentNodeVerifier.java index 5aa603699a..ef4624ab26 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ExistenceOfParentNodeVerifier.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ExistenceOfParentNodeVerifier.java @@ -22,7 +22,10 @@ package com.github.javaparser.steps; import com.github.javaparser.HasParentNode; -import com.github.javaparser.ast.*; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.JavadocComment; @@ -32,9 +35,9 @@ import com.github.javaparser.ast.type.*; import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is; -import static org.hamcrest.MatcherAssert.assertThat; /** * The ExistenceOfParentNodeVerifier verifies that each node of the compilation unit has a parent set. diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ManipulationSteps.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ManipulationSteps.java index 8933a5421c..aa0c58b75c 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ManipulationSteps.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ManipulationSteps.java @@ -50,8 +50,8 @@ import static com.github.javaparser.ast.type.PrimitiveType.intType; import static com.github.javaparser.steps.SharedSteps.getMethodByPositionAndClassPosition; import static org.hamcrest.CoreMatchers.is; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ManipulationSteps { diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ParsingSteps.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ParsingSteps.java index 080e3fb458..25c71530ff 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ParsingSteps.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/ParsingSteps.java @@ -44,10 +44,10 @@ import static com.github.javaparser.steps.SharedSteps.getMemberByTypeAndPosition; import static com.github.javaparser.steps.SharedSteps.getMethodByPositionAndClassPosition; import static java.lang.String.format; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.jupiter.api.Assertions.*; -import static org.hamcrest.MatcherAssert.assertThat; public class ParsingSteps { diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/SharedSteps.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/SharedSteps.java index ad941f7320..741c65a9d5 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/SharedSteps.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/steps/SharedSteps.java @@ -37,11 +37,11 @@ import java.util.Map; import static com.github.javaparser.StaticJavaParser.parse; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace; -import static org.hamcrest.MatcherAssert.assertThat; public class SharedSteps { diff --git a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/visitors/PositionTestVisitor.java b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/visitors/PositionTestVisitor.java index 43f84290ea..2b28dc05ec 100644 --- a/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/visitors/PositionTestVisitor.java +++ b/javaparser-core-testing-bdd/src/test/java/com/github/javaparser/visitors/PositionTestVisitor.java @@ -22,7 +22,10 @@ package com.github.javaparser.visitors; import com.github.javaparser.Position; -import com.github.javaparser.ast.*; +import com.github.javaparser.ast.ArrayCreationLevel; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.BlockComment; import com.github.javaparser.ast.comments.JavadocComment; From 7652a88547cccbd089ac83d3790ee99e8c4079dc Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:20:25 +0000 Subject: [PATCH 164/280] Moved License to the correct location in class --- .../lexicalpreservation/Issue2137Test.java | 15 ++++----------- .../lexicalpreservation/Issue2517Test.java | 16 ++++------------ .../lexicalpreservation/Issue3296Test.java | 17 +++++++---------- .../lexicalpreservation/Issue3358Test.java | 9 ++++----- .../lexicalpreservation/Issue3387Test.java | 15 ++++++--------- .../lexicalpreservation/Issue3441Test.java | 12 ++++-------- .../lexicalpreservation/Issue3721Test.java | 9 ++++----- 7 files changed, 33 insertions(+), 60 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java index 0c071706a7..b3c48d2d8c 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2137Test.java @@ -1,9 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - -import java.util.StringJoiner; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -25,15 +19,14 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.javadoc.Javadoc; -import com.github.javaparser.javadoc.description.JavadocDescription; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue2137Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java index 01b3e03998..2cb76c4e42 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2517Test.java @@ -1,9 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - -import java.util.StringJoiner; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -25,16 +19,14 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.javadoc.Javadoc; -import com.github.javaparser.javadoc.description.JavadocDescription; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue2517Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java index 8113ee9283..5d9798404d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3296Test.java @@ -1,10 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -26,13 +19,17 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue3296Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java index ce654eb5a3..7d540ad5f6 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3358Test.java @@ -1,7 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static org.junit.jupiter.api.Assertions.assertTrue; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -23,10 +19,13 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Modifier.Keyword; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue3358Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java index d7dd2fd6fc..7ba2e8e82c 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3387Test.java @@ -1,9 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - -import java.util.StringJoiner; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -25,13 +19,16 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.description.JavadocDescription; +import org.junit.jupiter.api.Test; + +import java.util.StringJoiner; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue3387Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java index d2587880f6..d416364d72 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3441Test.java @@ -1,7 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -23,13 +19,13 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.SwitchEntry; -import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue3441Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java index e7cfd48421..5258d6adcd 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3721Test.java @@ -1,7 +1,3 @@ -package com.github.javaparser.printer.lexicalpreservation; - -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - /* * Copyright (C) 2007-2010 Júlio Vilmar Gesser. * Copyright (C) 2011, 2013-2019 The JavaParser Team. @@ -23,9 +19,12 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; +package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.body.VariableDeclarator; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue3721Test extends AbstractLexicalPreservingTest { From 434b9e3b4efa4d12de4760337afd1c733de0160f Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:25:38 +0000 Subject: [PATCH 165/280] Organized Imports for JavaParser-Core-Testing --- .../javaparser/CommentsInserterTest.java | 16 +++--- .../github/javaparser/ExpectedTokensTest.java | 1 - .../com/github/javaparser/Issue1017Test.java | 3 +- .../com/github/javaparser/Issue3064Test.java | 7 ++- .../com/github/javaparser/JavaTokenTest.java | 18 ++----- .../LineSeparatorProcessorTest.java | 14 ++--- .../javaparser/ParserConfigurationTest.java | 3 +- .../javaparser/PositionMappingTest.java | 10 ++-- .../java/com/github/javaparser/RangeTest.java | 6 +-- .../com/github/javaparser/TokenRangeTest.java | 2 +- .../UnicodeEscapeProcessingProviderTest.java | 4 +- .../github/javaparser/ast/DataKeyTest.java | 1 - .../github/javaparser/ast/FindNodeTest.java | 13 +++-- .../github/javaparser/ast/NodeListTest.java | 15 +----- .../javaparser/ast/NodePositionTest.java | 5 +- .../com/github/javaparser/ast/NodeTest.java | 1 - .../github/javaparser/ast/WalkFindTest.java | 21 ++++---- .../ast/body/FieldDeclarationTest.java | 13 +++-- .../ast/body/MethodDeclarationTest.java | 9 ++-- .../ast/body/RecordDeclarationTest.java | 5 +- .../ast/body/TypeDeclarationTest.java | 1 - .../javaparser/ast/comments/CommentTest.java | 15 +++--- .../ast/expr/MethodReferenceExprTest.java | 1 - .../ast/expr/StringLiteralExprTest.java | 2 +- .../javaparser/ast/expr/SuperExprTest.java | 2 +- .../javaparser/ast/expr/SwitchExprTest.java | 2 - .../ast/nodeTypes/NodeWithBodyTest.java | 5 +- .../ast/nodeTypes/NodeWithJavadocTest.java | 3 +- .../ast/nodeTypes/NodeWithModifiersTest.java | 5 +- .../nodeTypes/NodeWithOptionalScopeTest.java | 9 ++-- .../javaparser/ast/stmt/SwitchStmtTest.java | 2 +- .../javaparser/ast/stmt/YieldStmtTest.java | 7 +-- .../javaparser/ast/type/ArrayTypeTest.java | 18 +++---- .../github/javaparser/ast/type/TypeTest.java | 3 +- .../ast/validator/Java14ValidatorTest.java | 2 - .../ast/validator/Java1_0ValidatorTest.java | 8 --- .../ast/validator/Java1_1ValidatorTest.java | 6 +-- .../ast/validator/Java1_2ValidatorTest.java | 2 +- .../ast/validator/Java1_3ValidatorTest.java | 2 +- .../ast/validator/Java1_4ValidatorTest.java | 2 +- .../ast/validator/Java6ValidatorTest.java | 2 +- .../ast/validator/Java7ValidatorTest.java | 9 ++-- .../ast/validator/Java8ValidatorTest.java | 2 +- .../ast/validator/Java9ValidatorTest.java | 2 +- .../ast/visitor/CloneVisitorTest.java | 1 - .../ast/visitor/ModifierVisitorTest.java | 17 +++--- .../ast/visitor/TreeVisitorTest.java | 15 +++--- .../ast/visitor/VoidVisitorTest.java | 13 +++-- .../builders/CompilationUnitBuildersTest.java | 26 ++++----- .../javaparser/issues/Issue2627Test.java | 17 +++--- .../javaparser/issues/Issue3255Test.java | 9 ++-- .../javadoc/JavadocExtractorTest.java | 1 - .../javaparser/manual/BulkParseTest.java | 3 +- .../ConcreteSyntaxModelAcceptanceTest.java | 13 +++-- .../printer/DefaultPrettyPrinterTest.java | 29 ++++------ .../printer/PrettyPrintVisitorTest.java | 24 ++++----- .../javaparser/printer/PrettyPrinterTest.java | 43 ++++++--------- .../printer/PrinterConfigurationTest.java | 14 ++--- .../AbstractLexicalPreservingTest.java | 15 +++--- .../AnnotationSpaceTest.java | 11 ++-- .../lexicalpreservation/Issue1467Test.java | 5 +- .../lexicalpreservation/Issue1634Test.java | 9 ++-- .../lexicalpreservation/Issue1766Test.java | 6 +-- .../lexicalpreservation/Issue1793Test.java | 8 ++- .../lexicalpreservation/Issue2290Test.java | 12 ++--- .../lexicalpreservation/Issue2374Test.java | 12 ++--- .../lexicalpreservation/Issue2393Test.java | 7 ++- .../lexicalpreservation/Issue2592Test.java | 13 ++--- .../lexicalpreservation/Issue2610Test.java | 8 ++- .../lexicalpreservation/Issue2620Test.java | 17 +++--- .../lexicalpreservation/Issue2806Test.java | 10 ++-- .../lexicalpreservation/Issue3440Test.java | 3 +- .../lexicalpreservation/Issue3746Test.java | 21 ++------ .../lexicalpreservation/Issue3750Test.java | 18 ++----- .../lexicalpreservation/Issue3761Test.java | 19 ++----- .../lexicalpreservation/Issue3773Test.java | 18 +++---- .../LexicalDifferenceCalculatorTest.java | 30 +++++------ .../LexicalPreservingPrinterTest.java | 53 ++++++------------- .../PrettyPrinterIssue2340Test.java | 11 ++-- .../PrettyPrinterIssue2351Test.java | 7 ++- .../TransformationsTest.java | 16 +++--- .../changes/NoChangeTest.java | 13 ++--- ...tructorDeclarationTransformationsTest.java | 2 - .../FieldDeclarationTransformationsTest.java | 13 +++-- ...ializerDeclarationTransformationsTest.java | 2 - .../ast/body/OperatorTransformationsTest.java | 5 +- .../body/StatementTransformationsTest.java | 5 +- .../javaparser/remove/NodeRemovalTest.java | 6 +-- .../utils/CodeGenerationUtilsTest.java | 3 +- .../com/github/javaparser/utils/LogTest.java | 2 +- .../utils/ParserCollectionStrategyTest.java | 17 +++--- .../javaparser/utils/SourceRootTest.java | 21 ++++---- .../javaparser/utils/SourceZipTest.java | 5 +- .../github/javaparser/utils/TestParser.java | 2 +- .../github/javaparser/utils/TestUtils.java | 14 +---- .../github/javaparser/utils/UtilsTest.java | 10 ++-- .../javaparser/utils/VisitorListTest.java | 15 +++--- .../javaparser/utils/VisitorMapTest.java | 4 +- .../javaparser/utils/VisitorSetTest.java | 19 +++---- .../version/Java10PostProcessorTest.java | 17 +++--- 100 files changed, 365 insertions(+), 643 deletions(-) diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/CommentsInserterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/CommentsInserterTest.java index 096d5f7a41..d1ebd48518 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/CommentsInserterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/CommentsInserterTest.java @@ -21,20 +21,18 @@ package com.github.javaparser; -import static com.github.javaparser.utils.TestUtils.assertEqualToTextResource; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.comments.CommentsCollection; +import com.github.javaparser.utils.TestParser; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + import static com.github.javaparser.utils.TestUtils.assertEqualToTextResourceNoEol; import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; import static com.github.javaparser.utils.Utils.SYSTEM_EOL; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.comments.CommentsCollection; -import com.github.javaparser.utils.TestParser; - class CommentsInserterTest { private String makeFilename(String sampleName) { return "com/github/javaparser/issue_samples/" + sampleName + ".java.txt"; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ExpectedTokensTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ExpectedTokensTest.java index 4bde2899eb..598823d34d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ExpectedTokensTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ExpectedTokensTest.java @@ -26,7 +26,6 @@ import com.github.javaparser.utils.ExtractingVisitors; import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.List; import static com.github.javaparser.utils.TestUtils.getNodeStartingAtPosition; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java index a6fb348eeb..293163167e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue1017Test.java @@ -1,10 +1,9 @@ package com.github.javaparser; +import com.github.javaparser.ast.CompilationUnit; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import com.github.javaparser.ast.CompilationUnit; - public class Issue1017Test { @Test() diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java index f84b42b640..a3cb113729 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/Issue3064Test.java @@ -1,12 +1,11 @@ package com.github.javaparser; -import static org.junit.jupiter.api.Assertions.assertEquals; +import com.github.javaparser.ast.CompilationUnit; +import org.junit.jupiter.api.Test; import java.io.StringReader; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.CompilationUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3064Test { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java index 889b00ce79..df9bd8a265 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/JavaTokenTest.java @@ -22,26 +22,18 @@ package com.github.javaparser; +import com.github.javaparser.ast.expr.Expression; +import org.junit.jupiter.api.Test; + import java.lang.reflect.Field; import java.util.Iterator; + import static com.github.javaparser.GeneratedJavaParserConstants.*; -import static com.github.javaparser.JavaToken.Category.COMMENT; -import static com.github.javaparser.JavaToken.Category.LITERAL; -import static com.github.javaparser.JavaToken.Category.OPERATOR; -import static com.github.javaparser.JavaToken.Category.WHITESPACE_NO_EOL; +import static com.github.javaparser.JavaToken.Category.*; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.Range.range; -import static com.github.javaparser.StaticJavaParser.parse; import static org.junit.jupiter.api.Assertions.*; -import java.lang.reflect.Field; -import java.util.Iterator; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.CompilationUnit; - class JavaTokenTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java index 487321d482..2d9eb72a95 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/LineSeparatorProcessorTest.java @@ -1,14 +1,5 @@ package com.github.javaparser; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; @@ -19,6 +10,11 @@ import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; import com.github.javaparser.utils.LineSeparator; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; public class LineSeparatorProcessorTest extends AbstractLexicalPreservingTest{ diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ParserConfigurationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ParserConfigurationTest.java index 70a45d44bc..b63e69c925 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ParserConfigurationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ParserConfigurationTest.java @@ -27,9 +27,8 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.RAW; import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionMappingTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionMappingTest.java index 7d0a13018f..6cbe74c9e5 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/PositionMappingTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/PositionMappingTest.java @@ -20,17 +20,17 @@ */ package com.github.javaparser; -import static com.github.javaparser.UnicodeEscapeProcessingProviderTest.*; -import static org.junit.jupiter.api.Assertions.*; +import com.github.javaparser.UnicodeEscapeProcessingProvider.PositionMapping; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.UnicodeEscapeProcessingProvider.PositionMapping; +import static com.github.javaparser.UnicodeEscapeProcessingProviderTest.process; +import static com.github.javaparser.UnicodeEscapeProcessingProviderTest.provider; +import static org.junit.jupiter.api.Assertions.*; /** * Test case for {@link PositionMapping}. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/RangeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/RangeTest.java index 69ebc05332..b98c9fc97b 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/RangeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/RangeTest.java @@ -21,12 +21,10 @@ package com.github.javaparser; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + class RangeTest { private final Position pos1 = new Position(10, 11); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/TokenRangeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/TokenRangeTest.java index 03f46e2734..2967a1aa77 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/TokenRangeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/TokenRangeTest.java @@ -28,7 +28,7 @@ import java.util.Optional; import static com.github.javaparser.StaticJavaParser.parse; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class TokenRangeTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/UnicodeEscapeProcessingProviderTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/UnicodeEscapeProcessingProviderTest.java index 7c6974a176..d2c44ec1ed 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/UnicodeEscapeProcessingProviderTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/UnicodeEscapeProcessingProviderTest.java @@ -20,11 +20,11 @@ */ package com.github.javaparser; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.io.IOException; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test case for {@link UnicodeEscapeProcessingProvider}. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/DataKeyTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/DataKeyTest.java index db3ac57555..c7d8dd6fa3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/DataKeyTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/DataKeyTest.java @@ -21,7 +21,6 @@ package com.github.javaparser.ast; -import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.expr.SimpleName; import org.junit.jupiter.api.Test; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/FindNodeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/FindNodeTest.java index 1143dd3b4e..c60a533406 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/FindNodeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/FindNodeTest.java @@ -21,16 +21,15 @@ package com.github.javaparser.ast; -import static com.github.javaparser.StaticJavaParser.parse; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.function.Predicate; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.TryStmt; +import org.junit.jupiter.api.Test; + +import java.util.function.Predicate; + +import static com.github.javaparser.StaticJavaParser.parse; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Some tests for finding descendant and ancestor nodes. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java index b7842451cc..f66cb33f3b 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeListTest.java @@ -21,13 +21,7 @@ package com.github.javaparser.ast; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.MemberValuePair; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NormalAnnotationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.observer.AstObserver; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; @@ -36,12 +30,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Optional; +import java.util.*; import static com.github.javaparser.ast.NodeList.nodeList; import static org.junit.jupiter.api.Assertions.*; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodePositionTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodePositionTest.java index 08a0e9e0f4..f795b1ade9 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodePositionTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodePositionTest.java @@ -21,7 +21,10 @@ package com.github.javaparser.ast; -import com.github.javaparser.*; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParseStart; +import com.github.javaparser.Providers; import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeTest.java index da7e410981..e61282d7c1 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/NodeTest.java @@ -35,7 +35,6 @@ import static com.github.javaparser.StaticJavaParser.parse; import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; class NodeTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/WalkFindTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/WalkFindTest.java index 21d1125ea1..b0ef0c856d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/WalkFindTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/WalkFindTest.java @@ -1,22 +1,21 @@ package com.github.javaparser.ast; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.SimpleName; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class WalkFindTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/FieldDeclarationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/FieldDeclarationTest.java index 0b6a1ecc7a..442423b8ce 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/FieldDeclarationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/FieldDeclarationTest.java @@ -21,17 +21,16 @@ package com.github.javaparser.ast.body; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.NodeList; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class FieldDeclarationTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/MethodDeclarationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/MethodDeclarationTest.java index 581f8e44ad..c1cb51c790 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/MethodDeclarationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/MethodDeclarationTest.java @@ -21,14 +21,11 @@ package com.github.javaparser.ast.body; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.junit.jupiter.api.Test; +import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; +import static org.junit.jupiter.api.Assertions.*; + class MethodDeclarationTest { @Test void annotationsAllowedAfterGenericsAndBeforeReturnType() { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/RecordDeclarationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/RecordDeclarationTest.java index f1aa113ad7..a9017579b3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/RecordDeclarationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/RecordDeclarationTest.java @@ -16,10 +16,7 @@ import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class RecordDeclarationTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/TypeDeclarationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/TypeDeclarationTest.java index 0b95dc8028..52f525bd98 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/TypeDeclarationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/body/TypeDeclarationTest.java @@ -21,7 +21,6 @@ package com.github.javaparser.ast.body; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import org.junit.jupiter.api.Test; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/comments/CommentTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/comments/CommentTest.java index c95b551556..292b3fc4c3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/comments/CommentTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/comments/CommentTest.java @@ -21,15 +21,6 @@ package com.github.javaparser.ast.comments; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -43,6 +34,12 @@ import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.*; class CommentTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/MethodReferenceExprTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/MethodReferenceExprTest.java index fc939fe808..aab7042521 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/MethodReferenceExprTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/MethodReferenceExprTest.java @@ -25,7 +25,6 @@ import static com.github.javaparser.utils.TestUtils.assertExpressionValid; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; class MethodReferenceExprTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/StringLiteralExprTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/StringLiteralExprTest.java index bafd1cad40..23e8aaf16a 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/StringLiteralExprTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/StringLiteralExprTest.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.StaticJavaParser.parseExpression; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class StringLiteralExprTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SuperExprTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SuperExprTest.java index 9ddfd0ddbb..ff04978f35 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SuperExprTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SuperExprTest.java @@ -25,8 +25,8 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.StaticJavaParser.parseExpression; -import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class SuperExprTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SwitchExprTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SwitchExprTest.java index f0471da17d..fd38dc0a69 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SwitchExprTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/expr/SwitchExprTest.java @@ -24,8 +24,6 @@ import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.SwitchEntry; -import com.github.javaparser.ast.stmt.SwitchStmt; - import org.junit.jupiter.api.Test; import static com.github.javaparser.ast.stmt.SwitchEntry.Type.*; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithBodyTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithBodyTest.java index 1dc039bb82..67f6ceced0 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithBodyTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithBodyTest.java @@ -22,12 +22,11 @@ package com.github.javaparser.ast.nodeTypes; import com.github.javaparser.ast.stmt.ForStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.utils.TestParser; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class NodeWithBodyTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadocTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadocTest.java index cfedb3ac26..774c0c9024 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadocTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadocTest.java @@ -28,7 +28,8 @@ import com.github.javaparser.ast.comments.LineComment; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class NodeWithJavadocTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiersTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiersTest.java index 32d64edc64..ce82bbf633 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiersTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiersTest.java @@ -32,10 +32,7 @@ import java.util.LinkedList; import java.util.List; -import static com.github.javaparser.ast.Modifier.Keyword.PRIVATE; -import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; -import static com.github.javaparser.ast.Modifier.Keyword.STATIC; -import static com.github.javaparser.ast.Modifier.Keyword.SYNCHRONIZED; +import static com.github.javaparser.ast.Modifier.Keyword.*; import static com.github.javaparser.ast.Modifier.createModifierList; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScopeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScopeTest.java index afbdd44cbe..323ce87cc3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScopeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScopeTest.java @@ -21,14 +21,13 @@ package com.github.javaparser.ast.nodeTypes; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class NodeWithOptionalScopeTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/SwitchStmtTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/SwitchStmtTest.java index 5c0e241444..49f06ae340 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/SwitchStmtTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/SwitchStmtTest.java @@ -27,7 +27,7 @@ import static com.github.javaparser.StaticJavaParser.parseStatement; import static com.github.javaparser.ast.stmt.SwitchEntry.Type.EXPRESSION; import static com.github.javaparser.ast.stmt.SwitchEntry.Type.STATEMENT_GROUP; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class SwitchStmtTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/YieldStmtTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/YieldStmtTest.java index 6122c6ff10..7307edb994 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/YieldStmtTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/stmt/YieldStmtTest.java @@ -22,12 +22,7 @@ package com.github.javaparser.ast.stmt; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; - +import com.github.javaparser.ast.expr.*; import org.junit.jupiter.api.Test; import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_12; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java index 619b822391..3cbed2411e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java @@ -21,18 +21,6 @@ package com.github.javaparser.ast.type; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.StaticJavaParser.parseName; -import static com.github.javaparser.StaticJavaParser.parseParameter; -import static com.github.javaparser.StaticJavaParser.parseStatement; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; @@ -41,6 +29,12 @@ import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.printer.ConcreteSyntaxModel; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.StaticJavaParser.*; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; class ArrayTypeTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java index 2e8a1abd94..6f7f155a7a 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java @@ -30,12 +30,11 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.ParseStart.VARIABLE_DECLARATION_EXPR; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.RAW; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.StaticJavaParser.parseType; import static com.github.javaparser.StaticJavaParser.parseVariableDeclarationExpr; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertThrows; class TypeTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java14ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java14ValidatorTest.java index dde56a87bc..e412b2b04f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java14ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java14ValidatorTest.java @@ -26,10 +26,8 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.utils.TestUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.opentest4j.AssertionFailedError; import static com.github.javaparser.ParseStart.COMPILATION_UNIT; import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_14; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_0ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_0ValidatorTest.java index 4ba1bb6c60..e3e98f2256 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_0ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_0ValidatorTest.java @@ -24,24 +24,16 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.Problem; import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.expr.ArrayCreationExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.validator.language_level_validations.Java1_0Validator; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - import static com.github.javaparser.ParseStart.*; import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_1_0; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertNoProblems; import static com.github.javaparser.utils.TestUtils.assertProblems; -import static org.junit.jupiter.api.Assertions.assertEquals; class Java1_0ValidatorTest { public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLanguageLevel(JAVA_1_0)); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_1ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_1ValidatorTest.java index 0fa74e0a47..5956f31238 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_1ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_1ValidatorTest.java @@ -29,10 +29,8 @@ import com.github.javaparser.ast.stmt.Statement; import org.junit.jupiter.api.Test; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.ParseStart.EXPRESSION; -import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParseStart.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_1_1; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertNoProblems; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_2ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_2ValidatorTest.java index f994e47d43..8003a437f7 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_2ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_2ValidatorTest.java @@ -30,7 +30,7 @@ import static com.github.javaparser.ParseStart.COMPILATION_UNIT; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_1_2; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_3ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_3ValidatorTest.java index 39cd6f802e..fe223d110d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_3ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_3ValidatorTest.java @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_1_3; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java index a52f4eebf4..e4971334c5 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.ParseStart.*; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_1_4; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertNoProblems; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java6ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java6ValidatorTest.java index 514c1f8879..2c2b3426bb 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java6ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java6ValidatorTest.java @@ -30,7 +30,7 @@ import static com.github.javaparser.ParseStart.EXPRESSION; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_6; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java7ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java7ValidatorTest.java index 32a75ea1d1..70f53dbeac 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java7ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java7ValidatorTest.java @@ -33,12 +33,11 @@ import com.github.javaparser.ast.validator.language_level_validations.Java7Validator; import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.List; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.ParseStart.EXPRESSION; -import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParseStart.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_7; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.TestUtils.assertNoProblems; import static com.github.javaparser.utils.TestUtils.assertProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java8ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java8ValidatorTest.java index aaa931ca1b..b326b75c51 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java8ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java8ValidatorTest.java @@ -30,7 +30,7 @@ import static com.github.javaparser.ParseStart.COMPILATION_UNIT; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_8; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.ast.validator.Java1_1ValidatorTest.allModifiers; import static com.github.javaparser.utils.TestUtils.assertNoProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java9ValidatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java9ValidatorTest.java index 07e6bfcfa8..77ecc7a455 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java9ValidatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/validator/Java9ValidatorTest.java @@ -30,7 +30,7 @@ import static com.github.javaparser.ParseStart.COMPILATION_UNIT; import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; import static com.github.javaparser.Providers.provider; import static com.github.javaparser.ast.validator.Java1_1ValidatorTest.allModifiers; import static com.github.javaparser.utils.TestUtils.assertNoProblems; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/CloneVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/CloneVisitorTest.java index bf20141de1..14835b7c94 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/CloneVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/CloneVisitorTest.java @@ -24,7 +24,6 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.expr.Name; import com.github.javaparser.ast.type.Type; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java index f02c4d52c3..61b22db40d 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/ModifierVisitorTest.java @@ -21,16 +21,6 @@ package com.github.javaparser.ast.visitor; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.BodyDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; @@ -39,6 +29,13 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; class ModifierVisitorTest extends AbstractLexicalPreservingTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java index ed5845bfcc..7017f32434 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/TreeVisitorTest.java @@ -21,20 +21,19 @@ package com.github.javaparser.ast.visitor; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.ArrayInitializerExpr; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.SimpleName; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; class TreeVisitorTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/VoidVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/VoidVisitorTest.java index f3b8f44f85..9601a21707 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/VoidVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/ast/visitor/VoidVisitorTest.java @@ -21,16 +21,15 @@ package com.github.javaparser.ast.visitor; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; public class VoidVisitorTest { @Test() diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/builders/CompilationUnitBuildersTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/builders/CompilationUnitBuildersTest.java index 4ae051b817..f38fcc8d54 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/builders/CompilationUnitBuildersTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/builders/CompilationUnitBuildersTest.java @@ -21,27 +21,23 @@ package com.github.javaparser.builders; -import static com.github.javaparser.StaticJavaParser.parseImport; -import static com.github.javaparser.ast.Modifier.Keyword.PRIVATE; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.lang.annotation.ElementType; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.PackageDeclaration; 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.expr.Name; +import org.junit.jupiter.api.Test; + +import java.lang.annotation.ElementType; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +import static com.github.javaparser.StaticJavaParser.parseImport; +import static com.github.javaparser.ast.Modifier.Keyword.PRIVATE; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.*; class CompilationUnitBuildersTest { private final CompilationUnit cu = new CompilationUnit(); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java index 4f154964f3..27780c0764 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue2627Test.java @@ -1,19 +1,18 @@ package com.github.javaparser.issues; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.stream.Stream; - -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - import com.github.javaparser.Range; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.IOException; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue2627Test { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java index 9ca37cb389..643006880c 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue3255Test.java @@ -1,14 +1,13 @@ package com.github.javaparser.issues; -import static com.github.javaparser.utils.TestParser.parseStatement; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.utils.LineSeparator; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.utils.TestParser.parseStatement; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3255Test { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/javadoc/JavadocExtractorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/javadoc/JavadocExtractorTest.java index b29fe6fea2..f4a2db6baa 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/javadoc/JavadocExtractorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/javadoc/JavadocExtractorTest.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.nio.charset.StandardCharsets; import static com.github.javaparser.StaticJavaParser.parse; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java index d11582c04f..921116f723 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java @@ -23,7 +23,6 @@ import com.github.javaparser.ParserConfiguration; import com.github.javaparser.Problem; -import com.github.javaparser.utils.CodeGenerationUtils; import com.github.javaparser.utils.Log; import com.github.javaparser.utils.SourceRoot; import com.github.javaparser.utils.SourceZip; @@ -42,8 +41,8 @@ import java.util.TreeMap; import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; -import static com.github.javaparser.utils.CodeGenerationUtils.*; import static com.github.javaparser.utils.CodeGenerationUtils.f; +import static com.github.javaparser.utils.CodeGenerationUtils.mavenModuleRoot; import static com.github.javaparser.utils.SourceRoot.Callback.Result.DONT_SAVE; import static com.github.javaparser.utils.TestUtils.download; import static com.github.javaparser.utils.TestUtils.temporaryDirectory; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java index 263f576890..dec8e699d8 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java @@ -21,17 +21,16 @@ package com.github.javaparser.printer; -import static com.github.javaparser.StaticJavaParser.parse; - -import java.io.IOException; -import java.nio.file.Path; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.utils.CodeGenerationUtils; import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Path; + +import static com.github.javaparser.StaticJavaParser.parse; class ConcreteSyntaxModelAcceptanceTest { private final Path rootDir = CodeGenerationUtils.mavenModuleRoot(ConcreteSyntaxModelAcceptanceTest.class).resolve("src/test/test_sourcecode"); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java index 0612c13ecd..e5346a468e 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/DefaultPrettyPrinterTest.java @@ -21,24 +21,7 @@ package com.github.javaparser.printer; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static com.github.javaparser.StaticJavaParser.parseStatement; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; @@ -52,6 +35,16 @@ import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.StaticJavaParser.*; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class DefaultPrettyPrinterTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java index a1af7fb0ed..428ee7de55 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrintVisitorTest.java @@ -21,22 +21,7 @@ package com.github.javaparser.printer; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.utils.TestParser.parseBodyDeclaration; -import static com.github.javaparser.utils.TestParser.parseCompilationUnit; -import static com.github.javaparser.utils.TestParser.parseExpression; -import static com.github.javaparser.utils.TestParser.parseStatement; -import static com.github.javaparser.utils.TestParser.parseVariableDeclarationExpr; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Optional; - import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.utils.TestParser; -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; @@ -52,6 +37,15 @@ import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; import com.github.javaparser.printer.configuration.PrinterConfiguration; +import com.github.javaparser.utils.TestParser; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static com.github.javaparser.StaticJavaParser.parse; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.assertEquals; class PrettyPrintVisitorTest extends TestParser { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java index 863eb9b043..d0e4cd431a 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrettyPrinterTest.java @@ -21,29 +21,7 @@ package com.github.javaparser.printer; -import static com.github.javaparser.ParseStart.COMPILATION_UNIT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; -import static com.github.javaparser.Providers.provider; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration; -import static com.github.javaparser.StaticJavaParser.parseStatement; -import static com.github.javaparser.printer.configuration.Indentation.IndentType.TABS; -import static com.github.javaparser.printer.configuration.Indentation.IndentType.TABS_WITH_SPACE_ALIGN; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; -import java.util.function.Function; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.FieldDeclaration; @@ -52,13 +30,22 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.visitor.VoidVisitor; -import com.github.javaparser.printer.configuration.ConfigurationOption; -import com.github.javaparser.printer.configuration.DefaultConfigurationOption; -import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; +import com.github.javaparser.printer.configuration.*; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; -import com.github.javaparser.printer.configuration.Indentation; import com.github.javaparser.printer.configuration.Indentation.IndentType; -import com.github.javaparser.printer.configuration.PrinterConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Optional; +import java.util.function.Function; + +import static com.github.javaparser.ParseStart.COMPILATION_UNIT; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; +import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.StaticJavaParser.*; +import static com.github.javaparser.printer.configuration.Indentation.IndentType.TABS; +import static com.github.javaparser.printer.configuration.Indentation.IndentType.TABS_WITH_SPACE_ALIGN; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.*; class PrettyPrinterTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java index 15985e5751..cbbf277a8b 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/PrinterConfigurationTest.java @@ -1,20 +1,16 @@ package com.github.javaparser.printer; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.printer.configuration.ConfigurationOption; import com.github.javaparser.printer.configuration.DefaultConfigurationOption; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.utils.Utils; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; class PrinterConfigurationTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java index 9fe8982f86..64305601d2 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java @@ -21,20 +21,19 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsString; -import static com.github.javaparser.utils.TestUtils.readResource; - -import java.io.IOException; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; - import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.stmt.Statement; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; + +import java.io.IOException; + +import static com.github.javaparser.utils.TestUtils.assertEqualsString; +import static com.github.javaparser.utils.TestUtils.readResource; public abstract class AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java index 05c03781c1..56888963f1 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AnnotationSpaceTest.java @@ -21,16 +21,13 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import org.junit.jupiter.api.Test; import java.util.Optional; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.expr.MarkerAnnotationExpr; -import com.github.javaparser.ast.type.ClassOrInterfaceType; +import static org.junit.jupiter.api.Assertions.assertTrue; public class AnnotationSpaceTest extends AbstractLexicalPreservingTest { /** Tests that inserted annotations on types are followed by a space. */ diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java index 3397bd74b4..464f36d74b 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java @@ -21,10 +21,6 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -36,6 +32,7 @@ import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.ThrowStmt; import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; public class Issue1467Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java index 8468fc776a..bab9e61482 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1634Test.java @@ -1,13 +1,10 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.NodeList; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue1634Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java index 47388b858e..e70c195a50 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1766Test.java @@ -21,12 +21,8 @@ package com.github.javaparser.printer.lexicalpreservation; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; public class Issue1766Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java index 45178aec0e..d3f6fa80c0 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1793Test.java @@ -22,14 +22,12 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertEquals; - +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.StaticJavaParser; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; class Issue1793Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java index d3a4aadaf7..d4840c29c5 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2290Test.java @@ -21,17 +21,13 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import org.junit.jupiter.api.Test; import java.util.List; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.stmt.ExpressionStmt; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue2290Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java index 2799339c30..469d9301ce 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2374Test.java @@ -21,16 +21,14 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.Statement; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue2374Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java index 2a885baa1f..11c438d670 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2393Test.java @@ -21,12 +21,11 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.stmt.IfStmt; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue2393Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java index 9da8f03258..ac85ce3d23 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2592Test.java @@ -1,16 +1,13 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.SimpleName; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class Issue2592Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java index faaf88eeae..e0c8a88a72 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2610Test.java @@ -21,14 +21,12 @@ package com.github.javaparser.printer.lexicalpreservation; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; +import org.junit.jupiter.api.Test; + +import java.util.Optional; public class Issue2610Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java index a509b56290..cf699d3e9c 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2620Test.java @@ -21,16 +21,6 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -38,6 +28,13 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.utils.LineSeparator; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class Issue2620Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java index 05c4414a64..1a2013861a 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue2806Test.java @@ -22,15 +22,13 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.JavaParser; -import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; class Issue2806Test extends AbstractLexicalPreservingTest{ diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java index ebba294909..1b49f93ec3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3440Test.java @@ -21,11 +21,10 @@ * GNU Lesser General Public License for more details. */ -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.stmt.SwitchEntry; import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; public class Issue3440Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java index b28fc70843..58cb245786 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3746Test.java @@ -21,27 +21,12 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import java.util.List; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.utils.LineSeparator; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3746Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java index dbd21a5234..c2692207ac 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3750Test.java @@ -21,24 +21,12 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import com.github.javaparser.ast.body.FieldDeclaration; +import org.junit.jupiter.api.Test; import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.utils.LineSeparator; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3750Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java index 028d2d8238..1044618721 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3761Test.java @@ -21,25 +21,14 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.body.FieldDeclaration; +import org.junit.jupiter.api.Test; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.utils.LineSeparator; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; public class Issue3761Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java index 41859b1d51..4480bcfe58 100755 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3773Test.java @@ -22,24 +22,18 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; - -import java.util.List; - -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.expr.BinaryExpr.Operator; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.IfStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.visitor.ModifierVisitor; import com.github.javaparser.ast.visitor.Visitable; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; class Issue3773Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java index f19d266fc8..af4c523b08 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java @@ -21,18 +21,6 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.TokenTypes.eolTokenKind; -import static com.github.javaparser.TokenTypes.spaceTokenKind; -import static com.github.javaparser.ast.Modifier.createModifierList; -import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.List; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; @@ -43,12 +31,7 @@ import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.ThisExpr; +import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ExpressionStmt; @@ -57,6 +40,17 @@ import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static com.github.javaparser.TokenTypes.eolTokenKind; +import static com.github.javaparser.TokenTypes.spaceTokenKind; +import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; +import static com.github.javaparser.ast.Modifier.createModifierList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java index 70be958d36..ebcb9b3356 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java @@ -21,55 +21,34 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.StaticJavaParser.parse; -import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; -import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; -import static com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter.NODE_TEXT_DATA; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.JavaParser; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.ArrayCreationLevel; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.AnnotationDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.*; +import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.LineComment; import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.CatchClause; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.IfStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.stmt.TryStmt; +import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.Type; import com.github.javaparser.ast.type.UnionType; import com.github.javaparser.ast.type.VoidType; import com.github.javaparser.ast.visitor.ModifierVisitor; import com.github.javaparser.ast.visitor.Visitable; import com.github.javaparser.utils.TestUtils; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; +import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; +import static com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter.NODE_TEXT_DATA; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; +import static org.junit.jupiter.api.Assertions.*; class LexicalPreservingPrinterTest extends AbstractLexicalPreservingTest { private NodeText getTextForNode(Node node) { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java index 1ccd681269..df39f2f113 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2340Test.java @@ -21,16 +21,11 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Modifier.Keyword; -import com.github.javaparser.ast.body.EnumDeclaration; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; class PrettyPrinterIssue2340Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java index 0a67dd70e1..6b61e4c167 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/PrettyPrinterIssue2351Test.java @@ -21,13 +21,12 @@ package com.github.javaparser.printer.lexicalpreservation; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.github.javaparser.ast.body.EnumDeclaration; +import org.junit.jupiter.api.Test; import java.util.Optional; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.body.EnumDeclaration; +import static org.junit.jupiter.api.Assertions.assertTrue; // manage java.lang.UnsupportedOperationException: Csm token token(}) NodeText TOKEN ";" <102> (line 1,col 39)-(line 1,col 39) class PrettyPrinterIssue2351Test extends AbstractLexicalPreservingTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java index 0d513acc9e..e416e41698 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/TransformationsTest.java @@ -21,14 +21,6 @@ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.ast.Modifier.Keyword.STATIC; -import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -40,9 +32,15 @@ import com.github.javaparser.ast.expr.NullLiteralExpr; import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.ast.type.PrimitiveType; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.github.javaparser.ast.Modifier.Keyword.STATIC; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; /** * These tests are more "high level" than the ones in LexicalPreservingPrinterTest. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java index 9bf98cc4d3..bcfcbb52ff 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChangeTest.java @@ -1,16 +1,11 @@ package com.github.javaparser.printer.lexicalpreservation.changes; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.observer.ObservableProperty; import com.github.javaparser.ast.type.ClassOrInterfaceType; +import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; class NoChangeTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/ConstructorDeclarationTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/ConstructorDeclarationTransformationsTest.java index 5d87867ea2..3127b25811 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/ConstructorDeclarationTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/ConstructorDeclarationTransformationsTest.java @@ -30,8 +30,6 @@ import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import org.junit.jupiter.api.Test; -import java.io.IOException; - import static com.github.javaparser.ast.Modifier.Keyword.PROTECTED; import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; import static com.github.javaparser.ast.Modifier.createModifierList; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/FieldDeclarationTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/FieldDeclarationTransformationsTest.java index 962818053e..6f2dd639e1 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/FieldDeclarationTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/FieldDeclarationTransformationsTest.java @@ -21,16 +21,15 @@ package com.github.javaparser.printer.lexicalpreservation.transformations.ast.body; -import static com.github.javaparser.ast.Modifier.createModifierList; -import static com.github.javaparser.ast.Modifier.Keyword.PROTECTED; -import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; -import static com.github.javaparser.utils.Utils.SYSTEM_EOL; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; +import org.junit.jupiter.api.Test; + +import static com.github.javaparser.ast.Modifier.Keyword.PROTECTED; +import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; +import static com.github.javaparser.ast.Modifier.createModifierList; +import static com.github.javaparser.utils.Utils.SYSTEM_EOL; /** * Transforming FieldDeclaration and verifying the LexicalPreservation works as expected. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/InitializerDeclarationTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/InitializerDeclarationTransformationsTest.java index aba7349cb0..f8d33db01f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/InitializerDeclarationTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/InitializerDeclarationTransformationsTest.java @@ -25,8 +25,6 @@ import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import org.junit.jupiter.api.Test; -import java.io.IOException; - /** * Transforming InitializerDeclaration and verifying the LexicalPreservation works as expected. */ diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/OperatorTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/OperatorTransformationsTest.java index 5355b4bb51..d0c5b23eaa 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/OperatorTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/OperatorTransformationsTest.java @@ -21,13 +21,10 @@ package com.github.javaparser.printer.lexicalpreservation.transformations.ast.body; -import java.io.IOException; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.expr.IntegerLiteralExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; +import org.junit.jupiter.api.Test; /** * Transforming BinaryExpr and verifying the LexicalPreservation works as expected. diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/StatementTransformationsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/StatementTransformationsTest.java index b3d6f54efc..a48cd2124f 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/StatementTransformationsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/transformations/ast/body/StatementTransformationsTest.java @@ -21,15 +21,12 @@ package com.github.javaparser.printer.lexicalpreservation.transformations.ast.body; -import java.io.IOException; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; +import org.junit.jupiter.api.Test; import static com.github.javaparser.StaticJavaParser.parseStatement; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java index ee647039f2..8b5b7376e1 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/remove/NodeRemovalTest.java @@ -29,15 +29,13 @@ import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; -import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; - import org.junit.jupiter.api.Test; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; - class NodeRemovalTest extends AbstractLexicalPreservingTest{ private final CompilationUnit compilationUnit = new CompilationUnit(); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java index 30ebadd24f..98256ddeb0 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/CodeGenerationUtilsTest.java @@ -24,7 +24,8 @@ import org.junit.jupiter.api.Test; import static com.github.javaparser.utils.CodeGenerationUtils.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class CodeGenerationUtilsTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/LogTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/LogTest.java index b233d5f344..1798af3518 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/LogTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/LogTest.java @@ -27,7 +27,7 @@ import java.util.function.Supplier; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class LogTest { private static class TestAdapter implements Log.Adapter { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java index e02650e4e5..4c159aa4e7 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/ParserCollectionStrategyTest.java @@ -21,20 +21,19 @@ package com.github.javaparser.utils; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; -import static com.github.javaparser.utils.CodeGenerationUtils.mavenModuleRoot; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Path; import java.util.List; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; +import static com.github.javaparser.utils.CodeGenerationUtils.mavenModuleRoot; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; class ParserCollectionStrategyTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java index d0b88194ef..34397866c3 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java @@ -21,9 +21,14 @@ package com.github.javaparser.utils; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.github.javaparser.ParseProblemException; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import java.io.IOException; import java.nio.file.Files; @@ -31,15 +36,7 @@ import java.nio.file.Paths; import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.ast.CompilationUnit; +import static org.junit.jupiter.api.Assertions.*; class SourceRootTest { private final Path root = CodeGenerationUtils.mavenModuleRoot(SourceRootTest.class).resolve("src/test/resources/com/github/javaparser/utils/"); diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceZipTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceZipTest.java index 8f1b9c74e5..7d6aeac817 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceZipTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/SourceZipTest.java @@ -26,15 +26,12 @@ import org.junit.jupiter.api.Test; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; class SourceZipTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestParser.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestParser.java index 903dffc022..e7f7f647e7 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestParser.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestParser.java @@ -33,7 +33,7 @@ import java.util.HashMap; import java.util.Map; -import static com.github.javaparser.ParserConfiguration.*; +import static com.github.javaparser.ParserConfiguration.LanguageLevel; import static com.github.javaparser.ParserConfiguration.LanguageLevel.BLEEDING_EDGE; import static org.junit.jupiter.api.Assertions.fail; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestUtils.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestUtils.java index 00dfa9d96a..117a7542a6 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestUtils.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestUtils.java @@ -21,12 +21,7 @@ package com.github.javaparser.utils; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseResult; -import com.github.javaparser.ParseStart; -import com.github.javaparser.ParserConfiguration; -import com.github.javaparser.Position; -import com.github.javaparser.Problem; +import com.github.javaparser.*; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; @@ -34,12 +29,7 @@ import okhttp3.Request; import okhttp3.Response; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/UtilsTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/UtilsTest.java index 65cbe91a41..52157e0821 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/UtilsTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/UtilsTest.java @@ -21,6 +21,8 @@ package com.github.javaparser.utils; +import org.junit.jupiter.api.Test; + import java.io.IOException; import java.io.Reader; import java.util.ArrayList; @@ -28,13 +30,9 @@ import java.util.HashSet; import java.util.Optional; -import org.junit.jupiter.api.Test; - +import static com.github.javaparser.utils.Utils.assertNotNull; import static com.github.javaparser.utils.Utils.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class UtilsTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorListTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorListTest.java index 2a5d43a7aa..bd7d5958fe 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorListTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorListTest.java @@ -21,19 +21,18 @@ package com.github.javaparser.utils; -import static com.github.javaparser.StaticJavaParser.parse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor; +import com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.junit.jupiter.api.Test; - -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor; -import com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor; +import static com.github.javaparser.StaticJavaParser.parse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class VisitorListTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorMapTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorMapTest.java index 1e55f03258..47088c17c9 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorMapTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorMapTest.java @@ -30,9 +30,7 @@ import java.util.Map; import static com.github.javaparser.StaticJavaParser.parse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class VisitorMapTest { @Test diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorSetTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorSetTest.java index 32913d5bff..cb7a373b84 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorSetTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/utils/VisitorSetTest.java @@ -21,21 +21,16 @@ package com.github.javaparser.utils; -import static com.github.javaparser.StaticJavaParser.parse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor; import com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor; +import org.junit.jupiter.api.Test; + +import java.util.*; + +import static com.github.javaparser.StaticJavaParser.parse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class VisitorSetTest { diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java index 10b104308e..510bb84c87 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java @@ -21,20 +21,19 @@ package com.github.javaparser.version; -import static com.github.javaparser.ParseStart.STATEMENT; -import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_10; -import static com.github.javaparser.Providers.provider; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.junit.jupiter.api.Test; - import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.VarType; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static com.github.javaparser.ParseStart.STATEMENT; +import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_10; +import static com.github.javaparser.Providers.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; class Java10PostProcessorTest { public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLanguageLevel(JAVA_10)); From 26a0821b19bcff948142f74892b391b54fb08e6e Mon Sep 17 00:00:00 2001 From: 4everTheOne Date: Fri, 16 Dec 2022 20:27:32 +0000 Subject: [PATCH 166/280] Organized Imports for JavaParser-Core --- .../javaparser/ast/ArrayCreationLevel.java | 2 ++ .../javaparser/ast/CompilationUnit.java | 2 ++ .../javaparser/ast/ImportDeclaration.java | 1 + .../com/github/javaparser/ast/Modifier.java | 2 ++ .../java/com/github/javaparser/ast/Node.java | 2 ++ .../javaparser/ast/PackageDeclaration.java | 1 + .../ast/body/AnnotationDeclaration.java | 6 +++- .../ast/body/AnnotationMemberDeclaration.java | 2 ++ .../javaparser/ast/body/BodyDeclaration.java | 10 +++--- .../ast/body/CallableDeclaration.java | 35 ++++++------------- .../ast/body/ClassOrInterfaceDeclaration.java | 2 ++ .../body/CompactConstructorDeclaration.java | 17 +++------ .../ast/body/ConstructorDeclaration.java | 2 ++ .../ast/body/EnumConstantDeclaration.java | 2 ++ .../javaparser/ast/body/EnumDeclaration.java | 2 ++ .../javaparser/ast/body/FieldDeclaration.java | 2 ++ .../ast/body/InitializerDeclaration.java | 2 ++ .../ast/body/MethodDeclaration.java | 2 ++ .../github/javaparser/ast/body/Parameter.java | 1 + .../ast/body/ReceiverParameter.java | 1 + .../ast/body/RecordDeclaration.java | 9 ++--- .../javaparser/ast/body/TypeDeclaration.java | 2 ++ .../ast/body/VariableDeclarator.java | 2 ++ .../javaparser/ast/comments/Comment.java | 2 ++ .../ast/comments/JavadocComment.java | 3 +- .../javaparser/ast/comments/LineComment.java | 2 +- .../javaparser/ast/expr/AnnotationExpr.java | 2 ++ .../javaparser/ast/expr/ArrayAccessExpr.java | 2 ++ .../ast/expr/ArrayInitializerExpr.java | 2 ++ .../javaparser/ast/expr/AssignExpr.java | 2 ++ .../javaparser/ast/expr/BinaryExpr.java | 2 ++ .../ast/expr/BooleanLiteralExpr.java | 2 +- .../github/javaparser/ast/expr/CastExpr.java | 2 ++ .../javaparser/ast/expr/CharLiteralExpr.java | 2 +- .../github/javaparser/ast/expr/ClassExpr.java | 2 ++ .../javaparser/ast/expr/ConditionalExpr.java | 2 ++ .../ast/expr/DoubleLiteralExpr.java | 2 +- .../javaparser/ast/expr/EnclosedExpr.java | 2 ++ .../javaparser/ast/expr/Expression.java | 2 ++ .../javaparser/ast/expr/FieldAccessExpr.java | 2 ++ .../javaparser/ast/expr/InstanceOfExpr.java | 2 ++ .../ast/expr/IntegerLiteralExpr.java | 3 +- .../javaparser/ast/expr/LambdaExpr.java | 2 ++ .../javaparser/ast/expr/LiteralExpr.java | 2 +- .../ast/expr/LiteralStringValueExpr.java | 3 +- .../javaparser/ast/expr/LongLiteralExpr.java | 3 +- .../ast/expr/MarkerAnnotationExpr.java | 3 +- .../javaparser/ast/expr/MemberValuePair.java | 1 + .../javaparser/ast/expr/MethodCallExpr.java | 2 ++ .../ast/expr/MethodReferenceExpr.java | 2 ++ .../com/github/javaparser/ast/expr/Name.java | 2 ++ .../github/javaparser/ast/expr/NameExpr.java | 2 ++ .../ast/expr/NormalAnnotationExpr.java | 2 ++ .../javaparser/ast/expr/NullLiteralExpr.java | 2 +- .../ast/expr/ObjectCreationExpr.java | 2 ++ .../javaparser/ast/expr/PatternExpr.java | 8 ++--- .../javaparser/ast/expr/SimpleName.java | 1 + .../ast/expr/SingleMemberAnnotationExpr.java | 2 ++ .../ast/expr/StringLiteralExpr.java | 3 +- .../github/javaparser/ast/expr/SuperExpr.java | 1 + .../javaparser/ast/expr/SwitchExpr.java | 2 ++ .../ast/expr/TextBlockLiteralExpr.java | 3 +- .../github/javaparser/ast/expr/ThisExpr.java | 1 + .../github/javaparser/ast/expr/TypeExpr.java | 2 ++ .../github/javaparser/ast/expr/UnaryExpr.java | 2 ++ .../ast/expr/VariableDeclarationExpr.java | 2 ++ .../ast/modules/ModuleDeclaration.java | 1 + .../ast/modules/ModuleDirective.java | 10 +++--- .../ast/modules/ModuleExportsDirective.java | 2 ++ .../ast/modules/ModuleOpensDirective.java | 2 ++ .../ast/modules/ModuleProvidesDirective.java | 2 ++ .../ast/modules/ModuleRequiresDirective.java | 2 ++ .../ast/modules/ModuleUsesDirective.java | 2 ++ .../ast/observer/ObservableProperty.java | 5 +-- .../javaparser/ast/stmt/AssertStmt.java | 2 ++ .../github/javaparser/ast/stmt/BlockStmt.java | 2 ++ .../github/javaparser/ast/stmt/BreakStmt.java | 1 + .../javaparser/ast/stmt/CatchClause.java | 1 + .../javaparser/ast/stmt/ContinueStmt.java | 1 + .../github/javaparser/ast/stmt/DoStmt.java | 2 ++ .../github/javaparser/ast/stmt/EmptyStmt.java | 2 +- .../ExplicitConstructorInvocationStmt.java | 2 ++ .../javaparser/ast/stmt/ExpressionStmt.java | 2 ++ .../javaparser/ast/stmt/ForEachStmt.java | 2 ++ .../github/javaparser/ast/stmt/ForStmt.java | 2 ++ .../github/javaparser/ast/stmt/IfStmt.java | 2 ++ .../javaparser/ast/stmt/LabeledStmt.java | 2 ++ .../ast/stmt/LocalClassDeclarationStmt.java | 2 ++ .../ast/stmt/LocalRecordDeclarationStmt.java | 2 ++ .../javaparser/ast/stmt/ReturnStmt.java | 1 + .../github/javaparser/ast/stmt/Statement.java | 8 +++-- .../javaparser/ast/stmt/SwitchEntry.java | 1 + .../javaparser/ast/stmt/SwitchStmt.java | 2 ++ .../javaparser/ast/stmt/SynchronizedStmt.java | 2 ++ .../github/javaparser/ast/stmt/ThrowStmt.java | 2 ++ .../github/javaparser/ast/stmt/TryStmt.java | 2 ++ .../javaparser/ast/stmt/UnparsableStmt.java | 3 +- .../github/javaparser/ast/stmt/WhileStmt.java | 2 ++ .../github/javaparser/ast/stmt/YieldStmt.java | 2 ++ .../ast/type/ClassOrInterfaceType.java | 5 ++- .../javaparser/ast/type/IntersectionType.java | 1 + .../javaparser/ast/type/PrimitiveType.java | 2 +- .../javaparser/ast/type/ReferenceType.java | 2 +- .../javaparser/ast/type/TypeParameter.java | 2 ++ .../github/javaparser/ast/type/UnionType.java | 4 +-- .../javaparser/ast/type/UnknownType.java | 2 +- .../github/javaparser/ast/type/VarType.java | 3 -- .../github/javaparser/ast/type/VoidType.java | 2 +- .../javaparser/ast/type/WildcardType.java | 1 + .../postprocessors/Java10PostProcessor.java | 8 ++--- .../javaparser/ast/visitor/CloneVisitor.java | 6 +++- .../javaparser/ast/visitor/EqualsVisitor.java | 1 + .../visitor/GenericListVisitorAdapter.java | 1 + .../ast/visitor/ModifierVisitor.java | 2 ++ .../ast/visitor/NoCommentEqualsVisitor.java | 1 + .../AnnotationDeclarationMetaModel.java | 5 +-- .../metamodel/AnnotationExprMetaModel.java | 5 +-- .../AnnotationMemberDeclarationMetaModel.java | 5 +-- .../metamodel/ArrayAccessExprMetaModel.java | 5 +-- .../metamodel/ArrayCreationExprMetaModel.java | 5 +-- .../ArrayCreationLevelMetaModel.java | 3 +- .../ArrayInitializerExprMetaModel.java | 5 +-- .../metamodel/ArrayTypeMetaModel.java | 5 +-- .../metamodel/AssertStmtMetaModel.java | 5 +-- .../metamodel/AssignExprMetaModel.java | 5 +-- .../metamodel/BinaryExprMetaModel.java | 5 +-- .../metamodel/BlockCommentMetaModel.java | 5 +-- .../metamodel/BlockStmtMetaModel.java | 5 +-- .../metamodel/BodyDeclarationMetaModel.java | 5 +-- .../BooleanLiteralExprMetaModel.java | 5 +-- .../metamodel/BreakStmtMetaModel.java | 5 +-- .../CallableDeclarationMetaModel.java | 5 +-- .../metamodel/CastExprMetaModel.java | 5 +-- .../metamodel/CatchClauseMetaModel.java | 5 +-- .../metamodel/CharLiteralExprMetaModel.java | 5 +-- .../metamodel/ClassExprMetaModel.java | 5 +-- .../ClassOrInterfaceDeclarationMetaModel.java | 5 +-- .../ClassOrInterfaceTypeMetaModel.java | 5 +-- .../metamodel/CommentMetaModel.java | 5 +-- ...ompactConstructorDeclarationMetaModel.java | 5 +-- .../metamodel/CompilationUnitMetaModel.java | 3 +- .../metamodel/ConditionalExprMetaModel.java | 5 +-- .../ConstructorDeclarationMetaModel.java | 5 +-- .../metamodel/ContinueStmtMetaModel.java | 5 +-- .../javaparser/metamodel/DoStmtMetaModel.java | 5 +-- .../metamodel/DoubleLiteralExprMetaModel.java | 5 +-- .../metamodel/EmptyStmtMetaModel.java | 5 +-- .../metamodel/EnclosedExprMetaModel.java | 5 +-- .../EnumConstantDeclarationMetaModel.java | 5 +-- .../metamodel/EnumDeclarationMetaModel.java | 5 +-- ...citConstructorInvocationStmtMetaModel.java | 5 +-- .../metamodel/ExpressionMetaModel.java | 5 +-- .../metamodel/ExpressionStmtMetaModel.java | 5 +-- .../metamodel/FieldAccessExprMetaModel.java | 5 +-- .../metamodel/FieldDeclarationMetaModel.java | 5 +-- .../metamodel/ForEachStmtMetaModel.java | 5 +-- .../metamodel/ForStmtMetaModel.java | 5 +-- .../javaparser/metamodel/IfStmtMetaModel.java | 5 +-- .../metamodel/ImportDeclarationMetaModel.java | 5 +-- .../InitializerDeclarationMetaModel.java | 5 +-- .../metamodel/InstanceOfExprMetaModel.java | 5 +-- .../IntegerLiteralExprMetaModel.java | 5 +-- .../metamodel/IntersectionTypeMetaModel.java | 5 +-- .../metamodel/JavaParserMetaModel.java | 3 +- .../metamodel/JavadocCommentMetaModel.java | 5 +-- .../metamodel/LabeledStmtMetaModel.java | 5 +-- .../metamodel/LambdaExprMetaModel.java | 5 +-- .../metamodel/LineCommentMetaModel.java | 5 +-- .../metamodel/LiteralExprMetaModel.java | 5 +-- .../LiteralStringValueExprMetaModel.java | 5 +-- .../LocalClassDeclarationStmtMetaModel.java | 5 +-- .../LocalRecordDeclarationStmtMetaModel.java | 5 +-- .../metamodel/LongLiteralExprMetaModel.java | 5 +-- .../MarkerAnnotationExprMetaModel.java | 5 +-- .../metamodel/MemberValuePairMetaModel.java | 5 +-- .../metamodel/MethodCallExprMetaModel.java | 5 +-- .../metamodel/MethodDeclarationMetaModel.java | 5 +-- .../MethodReferenceExprMetaModel.java | 5 +-- .../metamodel/ModifierMetaModel.java | 5 +-- .../metamodel/ModuleDeclarationMetaModel.java | 5 +-- .../metamodel/ModuleDirectiveMetaModel.java | 5 +-- .../ModuleExportsDirectiveMetaModel.java | 5 +-- .../ModuleOpensDirectiveMetaModel.java | 5 +-- .../ModuleProvidesDirectiveMetaModel.java | 5 +-- .../ModuleRequiresDirectiveMetaModel.java | 5 +-- .../ModuleUsesDirectiveMetaModel.java | 5 +-- .../metamodel/NameExprMetaModel.java | 5 +-- .../javaparser/metamodel/NameMetaModel.java | 5 +-- .../javaparser/metamodel/NodeMetaModel.java | 5 +-- .../NormalAnnotationExprMetaModel.java | 5 +-- .../metamodel/NullLiteralExprMetaModel.java | 5 +-- .../ObjectCreationExprMetaModel.java | 5 +-- .../PackageDeclarationMetaModel.java | 5 +-- .../metamodel/ParameterMetaModel.java | 5 +-- .../metamodel/PatternExprMetaModel.java | 5 +-- .../metamodel/PrimitiveTypeMetaModel.java | 5 +-- .../metamodel/ReceiverParameterMetaModel.java | 5 +-- .../metamodel/RecordDeclarationMetaModel.java | 5 +-- .../metamodel/ReferenceTypeMetaModel.java | 5 +-- .../metamodel/ReturnStmtMetaModel.java | 5 +-- .../metamodel/SimpleNameMetaModel.java | 5 +-- .../SingleMemberAnnotationExprMetaModel.java | 5 +-- .../metamodel/StatementMetaModel.java | 5 +-- .../metamodel/StringLiteralExprMetaModel.java | 5 +-- .../metamodel/SuperExprMetaModel.java | 5 +-- .../metamodel/SwitchEntryMetaModel.java | 5 +-- .../metamodel/SwitchExprMetaModel.java | 5 +-- .../metamodel/SwitchStmtMetaModel.java | 5 +-- .../metamodel/SynchronizedStmtMetaModel.java | 5 +-- .../TextBlockLiteralExprMetaModel.java | 5 +-- .../metamodel/ThisExprMetaModel.java | 5 +-- .../metamodel/ThrowStmtMetaModel.java | 5 +-- .../metamodel/TryStmtMetaModel.java | 5 +-- .../metamodel/TypeDeclarationMetaModel.java | 5 +-- .../metamodel/TypeExprMetaModel.java | 5 +-- .../javaparser/metamodel/TypeMetaModel.java | 5 +-- .../metamodel/TypeParameterMetaModel.java | 5 +-- .../metamodel/UnaryExprMetaModel.java | 5 +-- .../metamodel/UnionTypeMetaModel.java | 5 +-- .../metamodel/UnknownTypeMetaModel.java | 5 +-- .../metamodel/UnparsableStmtMetaModel.java | 5 +-- .../metamodel/VarTypeMetaModel.java | 5 +-- .../VariableDeclarationExprMetaModel.java | 5 +-- .../VariableDeclaratorMetaModel.java | 5 +-- .../metamodel/VoidTypeMetaModel.java | 5 +-- .../metamodel/WhileStmtMetaModel.java | 5 +-- .../metamodel/WildcardTypeMetaModel.java | 5 +-- .../metamodel/YieldStmtMetaModel.java | 5 +-- .../github/javaparser/resolution/Solver.java | 6 ++-- .../javaparser/resolution/TypeSolver.java | 1 - .../ResolvedTypeParameterDeclaration.java | 1 - .../logic/FunctionalInterfaceLogic.java | 8 ++--- .../resolution/logic/InferenceContext.java | 16 ++++----- .../resolution/model/typesystem/LazyType.java | 2 +- .../model/typesystem/ReferenceTypeImpl.java | 14 +++----- .../NumericConditionalExprHandler.java | 6 ++-- .../resolution/types/ResolvedUnionType.java | 4 +-- 237 files changed, 591 insertions(+), 351 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java index df87ae0b3c..379a9a1896 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java @@ -32,7 +32,9 @@ import com.github.javaparser.metamodel.ArrayCreationLevelMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java index baa6433679..e2e83a276d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java @@ -43,6 +43,7 @@ import com.github.javaparser.utils.ClassUtils; import com.github.javaparser.utils.CodeGenerationUtils; import com.github.javaparser.utils.Utils; + import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; @@ -53,6 +54,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; + import static com.github.javaparser.JavaToken.Kind.EOF; import static com.github.javaparser.Providers.UTF8; import static com.github.javaparser.Providers.provider; 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 index cee035bed7..093cfa79b8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java @@ -29,6 +29,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ImportDeclarationMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import static com.github.javaparser.StaticJavaParser.parseName; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index a52613e6d7..d45a81344b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java @@ -27,7 +27,9 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModifierMetaModel; + import java.util.Arrays; + import static com.github.javaparser.ast.NodeList.toNodeList; import static com.github.javaparser.utils.Utils.assertNotNull; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java index fa95992d8c..dd379f9216 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -46,12 +46,14 @@ import com.github.javaparser.printer.configuration.PrinterConfiguration; import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.utils.LineSeparator; + 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.emptySet; 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 index e0441a9a22..066e0dda07 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java @@ -31,6 +31,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.PackageDeclarationMetaModel; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 0858379197..0dd5dc2f43 100644 --- 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 @@ -21,7 +21,10 @@ package com.github.javaparser.ast.body; import com.github.javaparser.TokenRange; -import com.github.javaparser.ast.*; +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Generated; +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.modifiers.NodeWithAbstractModifier; @@ -33,6 +36,7 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; + import java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java index e1ffc8cec7..a750b34ea0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java @@ -41,8 +41,10 @@ import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 8238ed5756..5a72c244b6 100644 --- 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 @@ -20,21 +20,23 @@ */ package com.github.javaparser.ast.body; +import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Generated; 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 com.github.javaparser.TokenRange; -import com.github.javaparser.ast.Generated; + +import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.CodeGenerationUtils.f; -import java.util.Optional; +import static com.github.javaparser.utils.Utils.assertNotNull; /** * Any declaration that can appear between the { and } of a class, interface, enum, or record. 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 index 3a026257c8..0e1cb21781 100644 --- 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 @@ -20,33 +20,12 @@ */ package com.github.javaparser.ast.body; -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.List; -import java.util.Optional; -import java.util.function.Consumer; import com.github.javaparser.TokenRange; -import com.github.javaparser.ast.AllFieldsConstructor; -import com.github.javaparser.ast.Generated; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; +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.NodeWithAnnotations; -import com.github.javaparser.ast.nodeTypes.NodeWithDeclaration; -import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; -import com.github.javaparser.ast.nodeTypes.NodeWithParameters; -import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; -import com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; -import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; -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.nodeTypes.modifiers.NodeWithStrictfpModifier; +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; @@ -57,6 +36,14 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + /** * Represents a declaration which is callable eg. a method or a constructor. */ 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 index e1e44c4c53..6b0e461589 100644 --- 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 @@ -40,8 +40,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java index d23dac8b73..6971524e91 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java @@ -21,19 +21,10 @@ package com.github.javaparser.ast.body; import com.github.javaparser.TokenRange; -import com.github.javaparser.ast.AccessSpecifier; -import com.github.javaparser.ast.AllFieldsConstructor; -import com.github.javaparser.ast.Generated; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; +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.NodeWithBlockStmt; -import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; -import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; -import com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions; -import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; +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; @@ -42,12 +33,14 @@ 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.CompactConstructorDeclarationMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 971defa0f1..dfdc2ed8cf 100644 --- 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 @@ -37,8 +37,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index f8668e8454..f358402cd1 100644 --- 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 @@ -39,8 +39,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index f909850fbf..c69b550584 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNonEmpty; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index a2463315c6..cda45be5b9 100644 --- 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 @@ -44,8 +44,10 @@ import com.github.javaparser.metamodel.NonEmptyProperty; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.ast.NodeList.nodeList; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index 090f3ca8a0..3e2928ec17 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.InitializerDeclarationMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java index b10b57192f..31d9350eb2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -40,8 +40,10 @@ import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java index 8d257d67dc..86a49233dd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java @@ -38,6 +38,7 @@ import com.github.javaparser.metamodel.ParameterMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 9a45cfe06d..303b3f7612 100644 --- 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 @@ -38,6 +38,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ReceiverParameterMetaModel; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/RecordDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/RecordDeclaration.java index 2e010c5459..3a7952aa4a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/RecordDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/RecordDeclaration.java @@ -21,12 +21,7 @@ package com.github.javaparser.ast.body; import com.github.javaparser.TokenRange; -import com.github.javaparser.ast.AllFieldsConstructor; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.Generated; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; +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.NodeWithImplements; @@ -45,9 +40,11 @@ import com.github.javaparser.metamodel.RecordDeclarationMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; + import java.util.List; import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.Collections.unmodifiableList; import static java.util.stream.Collectors.toList; 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 index 3a2b344f62..1f1b29a6f6 100644 --- 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 @@ -35,9 +35,11 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.TypeDeclarationMetaModel; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; + import java.util.List; import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.toList; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java index ef450931b7..e4a7ee13f0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java @@ -43,9 +43,11 @@ import com.github.javaparser.metamodel.VariableDeclaratorMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; + 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; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java index 0f447bd4b6..633f3d88fe 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java @@ -29,8 +29,10 @@ import com.github.javaparser.metamodel.CommentMetaModel; import com.github.javaparser.metamodel.InternalProperty; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.CodeGenerationUtils.f; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index 49b19730ee..dd1ac32b8b 100644 --- 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 @@ -23,15 +23,16 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.javadoc.Javadoc; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JavadocCommentMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.StaticJavaParser.parseJavadoc; /** 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 index a0282b61fa..5097ba0682 100644 --- 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 @@ -23,12 +23,12 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.LineCommentMetaModel; + import java.util.Optional; import java.util.function.Consumer; 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 index a109552094..5c897c1e4c 100644 --- 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 @@ -32,8 +32,10 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 16dcaf69af..0c5527f99f 100644 --- 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 @@ -30,8 +30,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ArrayAccessExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index b5e2d3176f..51914849a5 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ArrayInitializerExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 5d0bee8379..27461db413 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.metamodel.AssignExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.printer.Stringable; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 7e4a696da0..3f33c82e55 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.metamodel.BinaryExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.printer.Stringable; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 2162eb5252..3a1f2e3c8c 100644 --- 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 @@ -23,13 +23,13 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -import com.github.javaparser.ast.Node; 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.BooleanLiteralExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; 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 index 1e9e4a9169..2300115aeb 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.CastExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 5f5d58de57..dbb144897a 100644 --- 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 @@ -23,7 +23,6 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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; @@ -31,6 +30,7 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.utils.StringEscapeUtils; import com.github.javaparser.utils.Utils; + import java.util.Optional; import java.util.function.Consumer; 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 index fd9e949843..0998c95060 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ClassExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 8edf2d0076..f0251fac13 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ConditionalExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 9cabd49f8f..a0bf7239dc 100644 --- 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 @@ -23,12 +23,12 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java index f3b9b32843..748fdc1701 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java @@ -30,8 +30,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.EnclosedExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 7b719d4db8..5cafea6e96 100644 --- 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 @@ -30,8 +30,10 @@ import com.github.javaparser.metamodel.ExpressionMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.resolution.types.ResolvedType; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.CodeGenerationUtils.f; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java index d62bcc3d90..ed32157da9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java @@ -40,8 +40,10 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index d03acb5f46..8480b786f3 100644 --- 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 @@ -35,8 +35,10 @@ import com.github.javaparser.metamodel.InstanceOfExprMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 917aff6197..546f4b6a6a 100644 --- 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 @@ -23,15 +23,16 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Objects; import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.hasUnaryMinusAsParent; /** 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 index e74faeb874..d2a305fb7b 100644 --- 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 @@ -38,8 +38,10 @@ import com.github.javaparser.metamodel.DerivedProperty; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.LambdaExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index b02ba5946c..5d0223c1ae 100644 --- 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 @@ -23,10 +23,10 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Optional; import java.util.function.Consumer; 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 index 9141617349..47287315f2 100644 --- 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 @@ -23,13 +23,14 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index a295686502..9d8309b109 100644 --- 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 @@ -23,16 +23,17 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.math.BigInteger; import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.hasUnaryMinusAsParent; /** 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 index 1d166beb15..e384b5d942 100644 --- 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 @@ -23,14 +23,15 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.MarkerAnnotationExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.StaticJavaParser.parseName; /** 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 index 2b9596a787..f0d03c03f0 100644 --- 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 @@ -31,6 +31,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.MemberValuePairMetaModel; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java index c7c7ce2d12..d1bebfa758 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java @@ -42,8 +42,10 @@ import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.types.ResolvedType; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java index d949f6d14f..12e60d6a99 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java @@ -38,8 +38,10 @@ import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNonEmpty; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index a5a3975b63..87b557f8e3 100644 --- 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 @@ -33,7 +33,9 @@ import com.github.javaparser.metamodel.NameMetaModel; import com.github.javaparser.metamodel.NonEmptyProperty; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; + import static com.github.javaparser.utils.Utils.assertNonEmpty; /** 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 index 599e26b6d9..12ecb4d0f1 100644 --- 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 @@ -35,8 +35,10 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 606672bcae..2160b81b65 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.NormalAnnotationExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 1d655f8086..b685ec7bf0 100644 --- 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 @@ -23,12 +23,12 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.NullLiteralExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java index e07deff59a..357b054ecf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java @@ -43,8 +43,10 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/PatternExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/PatternExpr.java index e8ae76ebf4..4439b85c91 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/PatternExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/PatternExpr.java @@ -21,11 +21,7 @@ package com.github.javaparser.ast.expr; import com.github.javaparser.TokenRange; -import com.github.javaparser.ast.AllFieldsConstructor; -import com.github.javaparser.ast.Generated; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.*; import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.javaparser.ast.nodeTypes.NodeWithType; import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier; @@ -37,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.PatternExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 615561f079..9c6df0bc19 100644 --- 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 @@ -32,6 +32,7 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.NonEmptyProperty; import com.github.javaparser.metamodel.SimpleNameMetaModel; + import static com.github.javaparser.utils.Utils.assertNonEmpty; /** 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 index b38abfa2f1..594e89a5f6 100644 --- 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 @@ -30,8 +30,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.SingleMemberAnnotationExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index b36633a811..609558b21b 100644 --- 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 @@ -23,15 +23,16 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.Utils; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.StringEscapeUtils.escapeJava; import static com.github.javaparser.utils.StringEscapeUtils.unescapeJava; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java index 36a59f0ce2..3d98a0e242 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java @@ -31,6 +31,7 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.metamodel.SuperExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SwitchExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SwitchExpr.java index 77770c19f9..75d63a760c 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SwitchExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SwitchExpr.java @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.SwitchExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TextBlockLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TextBlockLiteralExpr.java index c908b091e9..e091aeb1b2 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TextBlockLiteralExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TextBlockLiteralExpr.java @@ -23,17 +23,18 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.TextBlockLiteralExprMetaModel; import com.github.javaparser.utils.Pair; + import java.util.Arrays; import java.util.Optional; import java.util.function.Consumer; import java.util.stream.Stream; + import static com.github.javaparser.utils.StringEscapeUtils.unescapeJavaTextBlock; import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; 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 index 1eb01f8c63..790f50a5ae 100644 --- 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 @@ -33,6 +33,7 @@ import com.github.javaparser.metamodel.ThisExprMetaModel; import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; + import java.util.Optional; import java.util.function.Consumer; 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 index 1fa23370b0..8eee8056d6 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.TypeExprMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index e7abdff180..6f960deb92 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.UnaryExprMetaModel; import com.github.javaparser.printer.Stringable; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index b4ecc472a6..34f00ef6eb 100644 --- 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 @@ -34,10 +34,12 @@ 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.Optional; import java.util.function.Consumer; import java.util.stream.Collectors; + import static com.github.javaparser.ast.NodeList.nodeList; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index be84709adb..be68bb7a39 100644 --- 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 @@ -35,6 +35,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleDeclarationMetaModel; + import static com.github.javaparser.StaticJavaParser.parseModuleDirective; import static com.github.javaparser.utils.Utils.assertNotNull; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDirective.java index de7ae15bab..7eb43670f1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDirective.java @@ -20,16 +20,18 @@ */ package com.github.javaparser.ast.modules; +import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.visitor.CloneVisitor; -import com.github.javaparser.TokenRange; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.metamodel.ModuleDirectiveMetaModel; + +import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.CodeGenerationUtils.f; -import java.util.Optional; -import com.github.javaparser.metamodel.ModuleDirectiveMetaModel; -import com.github.javaparser.metamodel.JavaParserMetaModel; /** * A module directive. diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsDirective.java index 820ae98922..4c585f1034 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsDirective.java @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleExportsDirectiveMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.StaticJavaParser.parseName; import static com.github.javaparser.utils.Utils.assertNotNull; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensDirective.java index 46ab9b8aac..88a8d60b67 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensDirective.java @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleOpensDirectiveMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesDirective.java index c8fde9da6d..4fbbdfc2fa 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesDirective.java @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleProvidesDirectiveMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresDirective.java index c4d52b2941..f6c9b50b99 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresDirective.java @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleRequiresDirectiveMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.ast.Modifier.Keyword.TRANSITIVE; import static com.github.javaparser.utils.Utils.assertNotNull; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesDirective.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesDirective.java index 4589983cb6..ddf4cbc00a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesDirective.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesDirective.java @@ -32,8 +32,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ModuleUsesDirectiveMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index fe683cefcb..7fcd2569bb 100644 --- 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 @@ -20,14 +20,15 @@ */ package com.github.javaparser.ast.observer; +import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.Generated; import com.github.javaparser.utils.Utils; + import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; import java.util.Collection; import java.util.Optional; -import java.util.Arrays; /** * Properties considered by the AstObserver diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java index 9b754e3920..9c571e62e0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java @@ -33,8 +33,10 @@ import com.github.javaparser.metamodel.AssertStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 519887ad5d..57b89223ec 100644 --- 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 @@ -32,8 +32,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.BlockStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java index 9e84ed9030..0c22c478f1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java @@ -32,6 +32,7 @@ import com.github.javaparser.metamodel.BreakStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; 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 index a9bebb6d16..1481041977 100644 --- 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 @@ -33,6 +33,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.CatchClauseMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java index cc0e291c13..6075c82562 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java @@ -33,6 +33,7 @@ import com.github.javaparser.metamodel.ContinueStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; 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 index fefa193ef6..fd0b5f2ab3 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.DoStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 7eb9d6dc2d..2610137aab 100644 --- 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 @@ -23,12 +23,12 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java index 41b6cb88d5..bca9be90ee 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java @@ -39,8 +39,10 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 1af49980a6..36095b4c5c 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ExpressionStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index baf6d82d89..a003c92b79 100644 --- 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 @@ -36,8 +36,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ForEachStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java index 1e34d1f536..6b8e535681 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java @@ -35,8 +35,10 @@ import com.github.javaparser.metamodel.ForStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java index 7cb5560851..29a585a0e3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java @@ -35,8 +35,10 @@ import com.github.javaparser.metamodel.IfStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 34ac88c86d..7831c4319e 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.LabeledStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 679d751c65..c65bbbc8d6 100644 --- 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 @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.LocalClassDeclarationStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalRecordDeclarationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalRecordDeclarationStmt.java index 2e13a13d78..4a518e196e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalRecordDeclarationStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalRecordDeclarationStmt.java @@ -31,8 +31,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.LocalRecordDeclarationStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java index 49965f7e28..f4a8fdce8a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java @@ -33,6 +33,7 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.metamodel.ReturnStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; 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 index 8c6694e832..fb088ba509 100644 --- 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 @@ -20,16 +20,18 @@ */ package com.github.javaparser.ast.stmt; +import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Generated; 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 com.github.javaparser.TokenRange; -import com.github.javaparser.ast.Generated; + +import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.CodeGenerationUtils.f; -import java.util.Optional; /** * A base class for all statements. diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntry.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntry.java index 695d6fa4ac..905c7fc31f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntry.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntry.java @@ -33,6 +33,7 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.SwitchEntryMetaModel; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 25e05b423f..a4e99e17ec 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.SwitchStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 5603562d2b..06b4bc5fb6 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.SynchronizedStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 75d381e6ef..848548f512 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.ThrowStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index 4f5c411c12..cdcbe575d1 100644 --- 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 @@ -33,8 +33,10 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.metamodel.TryStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** 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 index b9186d7a48..c773d5a7d2 100644 --- 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 @@ -23,14 +23,15 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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.UnparsableStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; /** 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 index 7ad22535b8..fc7fa584b7 100644 --- 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 @@ -34,8 +34,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.WhileStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/YieldStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/YieldStmt.java index 2dc0ffd1c0..27cbd2131b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/YieldStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/YieldStmt.java @@ -33,8 +33,10 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.YieldStmtMetaModel; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java index 7e7fe5b7c0..60e6c5b7b1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java @@ -46,6 +46,8 @@ import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; +import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -53,9 +55,6 @@ import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; -import java.util.Collections; -import java.util.List; - /** * A class or an interface type. *
{@code Object} 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 index c17dc2df93..c45e8d8f58 100644 --- 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 @@ -40,6 +40,7 @@ import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; 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 index ee1f0fa709..4c7a5f5d0d 100644 --- 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 @@ -23,7 +23,6 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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; @@ -40,6 +39,7 @@ import java.util.HashMap; import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; import static com.github.javaparser.utils.Utils.assertNotNull; 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 index c88df5e9c9..42c9e3476e 100644 --- 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 @@ -23,12 +23,12 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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 java.util.Optional; import java.util.function.Consumer; 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 index ab8e9cdc02..74144ce957 100644 --- 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 @@ -38,8 +38,10 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedTypeVariable; + import java.util.Optional; import java.util.function.Consumer; + import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; 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 index 8428a67d3a..2b1e9c5085 100644 --- 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 @@ -37,6 +37,8 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedUnionType; + +import java.util.List; import java.util.Optional; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -44,8 +46,6 @@ import static com.github.javaparser.utils.Utils.assertNotNull; import static java.util.stream.Collectors.joining; -import java.util.List; - /** *

The union type

* Represents a set of types. A given value of this type has to be assignable to at least one of the element types. 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 index 3a5554affd..4df1f1d4e3 100644 --- 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 @@ -23,7 +23,6 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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; @@ -34,6 +33,7 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; + import java.util.Optional; import java.util.function.Consumer; 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 index 184c59bad1..108e0ae7d9 100644 --- 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 @@ -28,7 +28,6 @@ import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.ForEachStmt; import com.github.javaparser.ast.visitor.CloneVisitor; @@ -37,11 +36,9 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.VarTypeMetaModel; import com.github.javaparser.resolution.Context; -import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedArrayType; -import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import java.util.List; 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 index e90693c8a8..b6e0f3f434 100644 --- 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 @@ -23,7 +23,6 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; -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; @@ -35,6 +34,7 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedVoidType; + import java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java index 8a3b4a2703..c0de411e84 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java @@ -37,6 +37,7 @@ import com.github.javaparser.resolution.Context; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedWildcard; + import java.util.Optional; import java.util.function.Consumer; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java index d851c43b3c..6afd0eccc0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java @@ -20,10 +20,6 @@ */ package com.github.javaparser.ast.validator.postprocessors; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.Processor; @@ -32,6 +28,10 @@ import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.VarType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * Processes the generic AST into a Java 10 AST and validates it. */ diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java index 0629d1224f..52ccb1e889 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -22,11 +22,15 @@ import com.github.javaparser.ast.*; import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.comments.*; +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 java.util.Optional; /** diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java index 434f68afcb..a8332b6a10 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java @@ -29,6 +29,7 @@ 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; 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 index f801fca9ce..8f00736df7 100644 --- 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 @@ -29,6 +29,7 @@ import com.github.javaparser.ast.modules.*; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.*; + import java.util.ArrayList; import java.util.List; import java.util.Objects; 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 index f0a1149e1f..b654ffbbb2 100644 --- 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 @@ -31,9 +31,11 @@ import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.*; import com.github.javaparser.utils.Pair; + import java.util.ArrayList; import java.util.List; import java.util.Optional; + import static com.github.javaparser.utils.Utils.removeElementByObjectIdentity; import static com.github.javaparser.utils.Utils.replaceElementByObjectIdentity; 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 index 401cfd3d72..fd0b484656 100644 --- 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 @@ -29,6 +29,7 @@ import com.github.javaparser.ast.modules.*; import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.*; + import java.util.Optional; public class NoCommentEqualsVisitor implements GenericVisitor { diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java index 36b66d725b..95529bf700 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java @@ -20,9 +20,10 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; -import com.github.javaparser.ast.body.AnnotationDeclaration; import com.github.javaparser.ast.Generated; +import com.github.javaparser.ast.body.AnnotationDeclaration; + +import java.util.Optional; /** * This file, class, and its contents are completely generated based on: diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java index 35c2e1c60c..30b7e89076 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java @@ -20,10 +20,11 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; -import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.AnnotationExpr; + +import java.util.Optional; /** * This file, class, and its contents are completely generated based on: diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java index 52da4f5430..68b47c9e80 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java @@ -20,9 +20,10 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.Generated; +import com.github.javaparser.ast.body.AnnotationMemberDeclaration; + +import java.util.Optional; /** * This file, class, and its contents are completely generated based on: diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java index 1395569596..b3bf0b2bf1 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java @@ -20,9 +20,10 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; -import com.github.javaparser.ast.expr.ArrayAccessExpr; import com.github.javaparser.ast.Generated; +import com.github.javaparser.ast.expr.ArrayAccessExpr; + +import java.util.Optional; /** * This file, class, and its contents are completely generated based on: diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java index 92342ae7d0..399f5e3881 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java @@ -20,9 +20,10 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; -import com.github.javaparser.ast.expr.ArrayCreationExpr; import com.github.javaparser.ast.Generated; +import com.github.javaparser.ast.expr.ArrayCreationExpr; + +import java.util.Optional; /** * This file, class, and its contents are completely generated based on: diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java index 1edc0905cd..e47b4ab236 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java @@ -20,10 +20,11 @@ */ package com.github.javaparser.metamodel; -import java.util.Optional; import com.github.javaparser.ast.ArrayCreationLevel; import com.github.javaparser.ast.Generated; +import java.util.Optional; + /** * This file, class, and its contents are completely generated based on: *