From 1fa349b9ab39005a4627d397551566547362a951 Mon Sep 17 00:00:00 2001 From: Palash Sharma Date: Mon, 1 Jan 2024 12:16:02 +0700 Subject: [PATCH 01/65] Changed SwitchStmt to SwitchNode to avoid ClassCastException when resolving MethodCallExpr for code that has enhanced switch statements --- .../javaparsermodel/contexts/SwitchEntryContext.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 44036fcb44..ad0593cf1a 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 @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; +import com.github.javaparser.ast.nodeTypes.SwitchNode; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.SwitchEntry; import com.github.javaparser.ast.stmt.SwitchStmt; @@ -50,8 +51,8 @@ public SwitchEntryContext(SwitchEntry wrappedNode, TypeSolver typeSolver) { @Override public SymbolReference solveSymbol(String name) { - SwitchStmt switchStmt = (SwitchStmt) demandParentNode(wrappedNode); - ResolvedType type = JavaParserFacade.get(typeSolver).getType(switchStmt.getSelector()); + SwitchNode switchNode = (SwitchNode) demandParentNode(wrappedNode); + ResolvedType type = JavaParserFacade.get(typeSolver).getType(switchNode.getSelector()); if (type.isReferenceType() && type.asReferenceType().getTypeDeclaration().isPresent()) { ResolvedReferenceTypeDeclaration typeDeclaration = type.asReferenceType().getTypeDeclaration().get(); if (typeDeclaration.isEnum()) { @@ -75,7 +76,7 @@ public SymbolReference solveSymbol(String na } // look for declaration in this and previous switch entry statements - for (SwitchEntry seStmt : switchStmt.getEntries()) { + for (SwitchEntry seStmt : switchNode.getEntries()) { for (Statement stmt : seStmt.getStatements()) { SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(stmt, typeSolver); SymbolReference symbolReference = solveWith(symbolDeclarator, name); From 2bb9b3a98cb2a8402860f44fd212969397dfc8f4 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 1 Jan 2024 16:00:23 +0100 Subject: [PATCH 02/65] [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 6a392e54b9..265c1ddd1e 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 6b3efad0b4..9868f842a8 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.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 7e3c14ebf9..f266d77118 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index f39c087c7a..8200456c45 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.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index 7b6c01ef38..c9084c9de0 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 794a57d763..94d02532e9 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index d2543dda7d..3d608b07da 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.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index c2defc5fe3..1d89cb7b74 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.25.8 + 3.25.9-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 1be138555c..38c9dcd731 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.25.8 + 3.25.9-SNAPSHOT javaparser-parent https://github.com/javaparser From 7fce381a96dfb309ead9f10f4224d56cfa9729ec Mon Sep 17 00:00:00 2001 From: Palash Sharma Date: Mon, 1 Jan 2024 22:44:13 +0700 Subject: [PATCH 03/65] Removed unused import from SwitchEntryContext.java --- .../javaparsermodel/contexts/SwitchEntryContext.java | 1 - 1 file changed, 1 deletion(-) 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 ad0593cf1a..937b316c94 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,7 +24,6 @@ import com.github.javaparser.ast.nodeTypes.SwitchNode; 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; From 1e0b768c9bcd011034e9e90a84ff9f50ac1bd67a Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 1 Jan 2024 17:37:23 +0100 Subject: [PATCH 04/65] fix: Adds unit test for issue 4284 --- .../symbolsolver/Issue4284Test.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4284Test.java diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4284Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4284Test.java new file mode 100755 index 0000000000..e68599360f --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4284Test.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2024 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the 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 org.junit.jupiter.api.Test; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.JavaParserAdapter; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; + +public class Issue4284Test extends AbstractResolutionTest { + + @Test + void test() { + + String code = + "public class SampleCode {\n" + + " public static void main(String... args) {\n" + + " char ch = args[0].charAt(0);\n" + + " int result = switch (ch) {\n" + + " default -> System.out.println(ch);\n" + + " };\n" + + " }\n" + + "}"; + + ParserConfiguration parserConfiguration = new ParserConfiguration() + .setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17) + .setSymbolResolver(symbolResolver(defaultTypeSolver())); + + CompilationUnit cu = JavaParserAdapter.of(new JavaParser(parserConfiguration)).parse(code); + + cu.findAll(MethodCallExpr.class).forEach(MethodCallExpr::resolve); + + } + +} From bd95adcf97a361831b1bac715ddb7400a31b3ae3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 3 Jan 2024 01:02:04 +0000 Subject: [PATCH 05/65] chore(deps): update dependency org.assertj:assertj-core to v3.25.1 --- javaparser-core-testing/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index c9084c9de0..b8348cb6a4 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -125,7 +125,7 @@ org.assertj assertj-core - 3.25.0 + 3.25.1 test From d854f21249418f5c3e13a0459e23a322e4a75008 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:06:24 +0000 Subject: [PATCH 06/65] chore(deps): update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.2.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 38c9dcd731..de012a9a62 100644 --- a/pom.xml +++ b/pom.xml @@ -288,7 +288,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.3 + 3.2.5 org.codehaus.mojo From 4603287b0f5174ca76f2d3674cf5d292ec815228 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 10 Jan 2024 15:40:42 +0100 Subject: [PATCH 07/65] Fix: issue 3939 SymbolResolver.calculateType(Expression) may fails on first try, then succeed on later tries --- .../java/com/github/javaparser/ast/Node.java | 16 ++++++ .../javaparsermodel/JavaParserFacade.java | 50 ++++++++----------- .../javaparsermodel/JavaParserFacadeTest.java | 36 +++++++++++-- 3 files changed, 69 insertions(+), 33 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 4527fa017d..cf33376af8 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 @@ -522,6 +522,22 @@ public M getData(final DataKey key) { return value; } + /** + * Gets data for this node using the given key or returns an {@code Optional.empty()}. + * + * @param The type of the data. + * @param key The key for the data + * @return The data. + * @see DataKey + */ + @SuppressWarnings("unchecked") + public Optional findData(final DataKey key) { + if (containsData(key)) { + return Optional.of(getData(key)); + } + return Optional.empty(); + } + /** * This method was added to support the clone method. * 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 fdc8b6273f..6f07ea6077 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 @@ -343,53 +343,45 @@ public ResolvedType getType(Node node) { } } + /* + * Returns the resolved Type of the {@code Node}. If the node is a method call + * expression and and the flag activates lambda expression resolution, the type + * of the arguments to the expression are looked up beforehand so that the type + * resolution is as relevant as possible. + */ public ResolvedType getType(Node node, boolean solveLambdas) { if (solveLambdas) { if (!node.containsData(TYPE_WITH_LAMBDAS_RESOLVED)) { - ResolvedType res = getTypeConcrete(node, solveLambdas); - - node.setData(TYPE_WITH_LAMBDAS_RESOLVED, res); - boolean secondPassNecessary = false; - if (node instanceof MethodCallExpr) { + if (node instanceof MethodCallExpr) { MethodCallExpr methodCallExpr = (MethodCallExpr) node; for (Node arg : methodCallExpr.getArguments()) { if (!arg.containsData(TYPE_WITH_LAMBDAS_RESOLVED)) { getType(arg, true); - secondPassNecessary = true; } } } - if (secondPassNecessary) { - node.removeData(TYPE_WITH_LAMBDAS_RESOLVED); - ResolvedType type = getType(node, true); - node.setData(TYPE_WITH_LAMBDAS_RESOLVED, type); - - } + ResolvedType res = getTypeConcrete(node, solveLambdas); + node.setData(TYPE_WITH_LAMBDAS_RESOLVED, res); Log.trace("getType on %s -> %s", () -> node, () -> res); } return node.getData(TYPE_WITH_LAMBDAS_RESOLVED); } - Optional res = find(TYPE_WITH_LAMBDAS_RESOLVED, node); + + // Try to return a value from the cache of resolved types using lambda expressions + Optional res = node.findData(TYPE_WITH_LAMBDAS_RESOLVED); if (res.isPresent()) { return res.get(); - } - res = find(TYPE_WITHOUT_LAMBDAS_RESOLVED, node); - if (!res.isPresent()) { - ResolvedType resType = getTypeConcrete(node, solveLambdas); - node.setData(TYPE_WITHOUT_LAMBDAS_RESOLVED, resType); - Optional finalRes = res; - Log.trace("getType on %s (no solveLambdas) -> %s", () -> node, () -> finalRes); - return resType; - } - return res.get(); - } - - private Optional find(DataKey dataKey, Node node) { - if (node.containsData(dataKey)) { - return Optional.of(node.getData(dataKey)); } - return Optional.empty(); + + // else try to return a value from the cache of resolved types without lambda expressions + // Or resolves the node type without resolving the lambda expressions + return node.findData(TYPE_WITHOUT_LAMBDAS_RESOLVED).orElseGet(() -> { + ResolvedType resType = getTypeConcrete(node, solveLambdas); + node.setData(TYPE_WITHOUT_LAMBDAS_RESOLVED, resType); + Log.trace("getType on %s (no solveLambdas) -> %s", () -> node, () -> res); + return resType; + }); } protected MethodUsage toMethodUsage(MethodReferenceExpr methodReferenceExpr, List paramTypes) { 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 31a3d416c2..210e9528f3 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,15 +21,22 @@ package com.github.javaparser.symbolsolver.javaparsermodel; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.JavaParserAdapter; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.Solver; +import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; +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.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - -class JavaParserFacadeTest { +class JavaParserFacadeTest extends AbstractResolutionTest { private final Solver symbolSolver = new SymbolSolver(new ReflectionTypeSolver()); @@ -70,4 +77,25 @@ private enum TestEnum { A, B; } + // issue 3939 + @Test + public void checksThatTheBehaviourIsConsistentInTheEventOfAnUnsolvedSymbol() { + String code = + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Foo {\n" + + "\n" + + " void m(List> classNames) {\n" + + " classNames.stream().map(c -> c.asSubclass(IMutator.class));\n" + + " }\n" + + "}"; + CompilationUnit cu = JavaParserAdapter.of(createParserWithResolver(defaultTypeSolver())).parse(code); + MethodCallExpr expr = cu.findFirst(MethodCallExpr.class).get(); + // First pass, there must be an UnsolvedSymbolException because the type of the method parameter cannot be resolved + assertThrows(UnsolvedSymbolException.class, () -> expr.getSymbolResolver().calculateType(expr)); + // Second pass, we always want an exception to ensure consistent behaviour + assertThrows(UnsolvedSymbolException.class, () -> expr.getSymbolResolver().calculateType(expr)); + } + } From 642ba3e360816a5fca3eee960a13f0fd007e1a5c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 11 Jan 2024 11:06:54 +0100 Subject: [PATCH 08/65] refac: Removes useless ExpressionHelper utility class and replaces some explicit casts by using the javaparser API --- .../javaparser/ast/expr/LambdaExpr.java | 23 ++++-- .../typeinference/ExpressionHelper.java | 49 ------------- .../resolution/typeinference/TypeHelper.java | 2 +- .../ExpressionCompatibleWithType.java | 72 +++++++++++-------- 4 files changed, 58 insertions(+), 88 deletions(-) delete mode 100644 javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java 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 9858bd11a0..b3e634cc1a 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 @@ -20,6 +20,11 @@ */ package com.github.javaparser.ast.expr; +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,11 +44,6 @@ 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; - /** *

A lambda expression

*

Java 1-7

@@ -117,12 +117,14 @@ public LambdaExpr(TokenRange tokenRange, NodeList parameters, Stateme customInitialization(); } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getParameters() { return parameters; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public LambdaExpr setParameters(final NodeList parameters) { assertNotNull(parameters); if (parameters == this.parameters) { @@ -274,4 +276,11 @@ public Optional toLambdaExpr() { public boolean isPolyExpression() { return true; } + + /* + * Returns true if no type parameter has been defined + */ + public boolean isExplicitlyTyped() { + return getParameters().stream().allMatch(p -> !(p.getType().isUnknownType())); + } } 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 deleted file mode 100644 index 011fc80577..0000000000 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ExpressionHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2015-2016 Federico Tomassetti - * Copyright (C) 2017-2024 The JavaParser Team. - * - * This file is part of JavaParser. - * - * JavaParser can be used either under the terms of - * a) the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * b) the terms of the Apache License - * - * You should have received a copy of both licenses in LICENCE.LGPL and - * LICENCE.APACHE. Please refer to those files for details. - * - * JavaParser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the 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.typeinference; - -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; - -import java.util.List; - -/** - * @author Federico Tomassetti - */ -public class ExpressionHelper { - - public static boolean isExplicitlyTyped(LambdaExpr lambdaExpr) { - return lambdaExpr.getParameters().stream().allMatch(p -> !(p.getType().isUnknownType())); - } - - public static List getResultExpressions(BlockStmt blockStmt) { - throw new UnsupportedOperationException(); - } - - public static boolean isCompatibleInAssignmentContext(Expression expression, ResolvedType type, TypeSolver typeSolver) { - return type.isAssignableBy(JavaParserFacade.get(typeSolver).getType(expression, false)); - } -} 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 30efaf20b3..eb3fa7801e 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 @@ -223,7 +223,7 @@ public static Pair groundTargetTypeOfLambda(LambdaExpr la // - If T is a wildcard-parameterized functional interface type and the lambda expression is explicitly typed, // then the ground target type is inferred as described in §18.5.3. - if (ExpressionHelper.isExplicitlyTyped(lambdaExpr)) { + if (lambdaExpr.isExplicitlyTyped()) { used18_5_3 = true; throw new UnsupportedOperationException(); } 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 9e24b281aa..e31b1ef2ab 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 @@ -21,9 +21,20 @@ package com.github.javaparser.symbolsolver.resolution.typeinference.constraintformulas; -import com.github.javaparser.ast.expr.*; +import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isCompatibleInALooseInvocationContext; +import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isProperType; +import static java.util.stream.Collectors.toList; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import com.github.javaparser.ast.expr.ConditionalExpr; +import com.github.javaparser.ast.expr.EnclosedExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.resolution.TypeSolver; @@ -34,15 +45,6 @@ import com.github.javaparser.symbolsolver.resolution.typeinference.*; import com.github.javaparser.utils.Pair; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isCompatibleInALooseInvocationContext; -import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isProperType; -import static java.util.stream.Collectors.toList; - /** * An expression is compatible in a loose invocation context with type T * @@ -86,8 +88,8 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // - If the expression is a parenthesized expression of the form ( Expression' ), the constraint reduces // to ‹Expression' → T›. - if (expression instanceof EnclosedExpr) { - EnclosedExpr enclosedExpr = (EnclosedExpr)expression; + if (expression.isEnclosedExpr()) { + EnclosedExpr enclosedExpr = expression.asEnclosedExpr(); return ReductionResult.oneConstraint(new ExpressionCompatibleWithType(typeSolver, enclosedExpr.getInner(), T)); } @@ -99,20 +101,20 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // This bound set may contain new inference variables, as well as dependencies between these new // variables and the inference variables in T. - if (expression instanceof ObjectCreationExpr) { + if (expression.isObjectCreationExpr()) { BoundSet B3 = new TypeInference(typeSolver).invocationTypeInferenceBoundsSetB3(); return ReductionResult.bounds(B3); } - if (expression instanceof MethodCallExpr) { + if (expression.isMethodCallExpr()) { throw new UnsupportedOperationException(); } // - If the expression is a conditional expression of the form e1 ? e2 : e3, the constraint reduces to two // constraint formulas, ‹e2 → T› and ‹e3 → T›. - if (expression instanceof ConditionalExpr) { - ConditionalExpr conditionalExpr = (ConditionalExpr)expression; + if (expression.isConditionalExpr()) { + ConditionalExpr conditionalExpr = expression.asConditionalExpr(); return ReductionResult.withConstraints( new ExpressionCompatibleWithType(typeSolver, conditionalExpr.getThenExpr(), T), new ExpressionCompatibleWithType(typeSolver, conditionalExpr.getElseExpr(), T)); @@ -123,8 +125,8 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // A constraint formula of the form ‹LambdaExpression → T›, where T mentions at least one inference variable, is reduced as follows: - if (expression instanceof LambdaExpr) { - LambdaExpr lambdaExpr = (LambdaExpr)expression; + if (expression.isLambdaExpr()) { + LambdaExpr lambdaExpr = expression.asLambdaExpr(); // - If T is not a functional interface type (§9.8), the constraint reduces to false. @@ -150,7 +152,7 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // // Federico: THIS SHOULD NOT HAPPEN, IN CASE WE WILL THROW AN EXCEPTION // - // - Otherwise, the congruence of LambdaExpression with the target function type is asserted as + // - Otherwise,) the congruence of LambdaExpression with the target function type is asserted as // follows: // // - If the number of lambda parameters differs from the number of parameter types of the function @@ -176,7 +178,7 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // - If the function type's result is not void and the lambda body is a block that is not // value-compatible, the constraint reduces to false. - if (!targetFunctionType.getReturnType().isVoid() && lambdaExpr.getBody() instanceof BlockStmt + if (!targetFunctionType.getReturnType().isVoid() && lambdaExpr.getBody().isBlockStmt() && !isValueCompatibleBlock(lambdaExpr.getBody())) { return ReductionResult.falseResult(); } @@ -204,16 +206,16 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // - If R is a proper type, and if the lambda body or some result expression in the lambda body // is not compatible in an assignment context with R, then false. - if (lambdaExpr.getBody() instanceof BlockStmt) { - List resultExpressions = ExpressionHelper.getResultExpressions((BlockStmt)lambdaExpr.getBody()); + if (lambdaExpr.getBody().isBlockStmt()) { + List resultExpressions = getResultExpressions(lambdaExpr.getBody().asBlockStmt()); for (Expression e : resultExpressions) { - if (!ExpressionHelper.isCompatibleInAssignmentContext(e, R, typeSolver)) { + if (!isCompatibleInAssignmentContext(e, R, typeSolver)) { return ReductionResult.falseResult(); } } } else { - Expression e = ((ExpressionStmt)lambdaExpr.getBody()).getExpression(); - if (!ExpressionHelper.isCompatibleInAssignmentContext(e, R, typeSolver)) { + Expression e = lambdaExpr.getBody().asExpressionStmt().getExpression(); + if (!isCompatibleInAssignmentContext(e, R, typeSolver)) { return ReductionResult.falseResult(); } } @@ -222,8 +224,8 @@ public ReductionResult reduce(BoundSet currentBoundSet) { // the constraint ‹Expression → R›; or where the lambda body is a block with result // expressions e1, ..., em, for all i (1 ≤ i ≤ m), ‹ei → R›. - if (lambdaExpr.getBody() instanceof BlockStmt) { - getAllReturnExpressions((BlockStmt)lambdaExpr.getBody()).forEach(e -> constraints.add(new ExpressionCompatibleWithType(typeSolver, e, R))); + if (lambdaExpr.getBody().isBlockStmt()) { + getAllReturnExpressions(lambdaExpr.getBody().asBlockStmt()).forEach(e -> constraints.add(new ExpressionCompatibleWithType(typeSolver, e, R))); } else { // FEDERICO: Added - Start for (int i=0;i getResultExpressions(BlockStmt blockStmt) { + throw new UnsupportedOperationException(); + } + + private boolean isCompatibleInAssignmentContext(Expression expression, ResolvedType type, TypeSolver typeSolver) { + return type.isAssignableBy(JavaParserFacade.get(typeSolver).getType(expression, false)); + } + private List getAllReturnExpressions(BlockStmt blockStmt) { return blockStmt.findAll(ReturnStmt.class).stream() .filter(r -> r.getExpression().isPresent()) @@ -290,7 +300,7 @@ private boolean isValueCompatibleBlock(Statement statement) { // A block lambda body is value-compatible if it cannot complete normally (§14.21) and every return statement // in the block has the form return Expression;. - if (statement instanceof BlockStmt) { + if (statement.isBlockStmt()) { if (!ControlFlowLogic.getInstance().canCompleteNormally(statement)) { return true; } From 9a6b2be23db1e804fc739c8d994a67c111438251 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:26:56 +0000 Subject: [PATCH 09/65] chore(deps): update actions/cache action to v4 --- .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 abbc205a02..97119e994f 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -63,7 +63,7 @@ jobs: ## Use a cache to reduce the build/test times (avoids having to download dependencies on EVERY run). ### https://help.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-maven#caching-dependencies - name: Cache Maven packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} From dfd8dfb8e8df6f88d869098fcf8884b7f2a8b85d Mon Sep 17 00:00:00 2001 From: magicwerk Date: Fri, 19 Jan 2024 00:21:15 +0100 Subject: [PATCH 10/65] optimize HasParentNode.findAncestor --- .../main/java/com/github/javaparser/HasParentNode.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 50d59680a5..60353e16bb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -92,13 +92,14 @@ default Optional findAncestor(Predicate predicate, Class... types) 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(); - if (oType.isPresent()) { - return Optional.of(oType.get().cast(parent)); + for (Class type : types) { + if (type.isAssignableFrom(parent.getClass()) && predicate.test(type.cast(parent))) { + return Optional.of(type.cast(parent)); + } } return parent.findAncestor(predicate, types); } - + /** * Determines whether this {@code HasParentNode} node is a descendant of the given node. A node is not a * descendant of itself. From 91eb0fc0615463e4162311c8ea47743d6adbf1d3 Mon Sep 17 00:00:00 2001 From: magicwerk Date: Fri, 19 Jan 2024 00:24:23 +0100 Subject: [PATCH 11/65] fix formatting --- .../src/main/java/com/github/javaparser/HasParentNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 60353e16bb..6be68e7b92 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -99,7 +99,7 @@ default Optional findAncestor(Predicate predicate, Class... types) } return parent.findAncestor(predicate, types); } - + /** * Determines whether this {@code HasParentNode} node is a descendant of the given node. A node is not a * descendant of itself. From 0d14859260a2ad9a910a417ded91677a72fe6409 Mon Sep 17 00:00:00 2001 From: yushouqiu Date: Mon, 22 Jan 2024 14:54:30 +0800 Subject: [PATCH 12/65] Fix: issue #3878 resolve MethodReference in ObjectCreationExpr --- .../contexts/MethodReferenceExprContext.java | 88 ++++++++++++------- .../symbolsolver/Issue3878Test.java | 58 ++++++++++++ 2 files changed, 114 insertions(+), 32 deletions(-) create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3878Test.java 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 45f8786070..f5c88d894d 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 @@ -30,9 +30,12 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.MethodReferenceExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithArguments; 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.ResolvedConstructorDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; @@ -108,38 +111,25 @@ private List inferArgumentTypes() { rmd.getLastParam().getType().asArrayType().getComponentType(): methodUsage.getParamType(pos); - // Get the functional method in order for us to resolve it's type arguments properly - Optional functionalMethodOpt = FunctionalInterfaceLogic.getFunctionalMethod(lambdaType); - if (functionalMethodOpt.isPresent()) { - MethodUsage functionalMethod = functionalMethodOpt.get(); - - List resolvedTypes = new ArrayList<>(); - - for (ResolvedType type : functionalMethod.getParamTypes()) { - InferenceContext inferenceContext = new InferenceContext(typeSolver); - - // 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()), lambdaType); - - // Now resolve the argument type using the inference context - ResolvedType argType = inferenceContext.resolve(inferenceContext.addSingle(type)); - - ResolvedLambdaConstraintType conType; - if (argType.isWildcard()){ - conType = ResolvedLambdaConstraintType.bound(argType.asWildcard().getBoundedType()); - } else { - conType = ResolvedLambdaConstraintType.bound(argType); - } - - resolvedTypes.add(conType); - } + return resolveLambdaTypes(lambdaType); + } - return resolvedTypes; - } - throw new UnsupportedOperationException(); + if (demandParentNode(wrappedNode) instanceof ObjectCreationExpr) { + ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) demandParentNode(wrappedNode); + ResolvedConstructorDeclaration rcd = JavaParserFacade.get(typeSolver).solve(objectCreationExpr) + .getCorrespondingDeclaration(); + int pos = pos(objectCreationExpr, wrappedNode); + // Since variable parameters are represented by an array, in case we deal with + // the variadic parameter we have to take into account the base type of the + // array. + ResolvedType lambdaType = (rcd.hasVariadicParameter() && pos >= rcd.getNumberOfParams() - 1) ? + rcd.getLastParam().getType().asArrayType().getComponentType(): + rcd.getParam(pos).getType(); + + return resolveLambdaTypes(lambdaType); } - if (demandParentNode(wrappedNode) instanceof VariableDeclarator) { + + if (demandParentNode(wrappedNode) instanceof VariableDeclarator) { VariableDeclarator variableDeclarator = (VariableDeclarator) demandParentNode(wrappedNode); ResolvedType t = JavaParserFacade.get(typeSolver).convertToUsage(variableDeclarator.getType()); Optional functionalMethod = FunctionalInterfaceLogic.getFunctionalMethod(t); @@ -165,7 +155,8 @@ private List inferArgumentTypes() { } throw new UnsupportedOperationException(); } - if (demandParentNode(wrappedNode) instanceof ReturnStmt) { + + if (demandParentNode(wrappedNode) instanceof ReturnStmt) { ReturnStmt returnStmt = (ReturnStmt) demandParentNode(wrappedNode); Optional optDeclaration = returnStmt.findAncestor(MethodDeclaration.class); if (optDeclaration.isPresent()) { @@ -198,7 +189,40 @@ private List inferArgumentTypes() { throw new UnsupportedOperationException(); } - private int pos(MethodCallExpr callExpr, Expression param) { + private List resolveLambdaTypes(ResolvedType lambdaType) { + // Get the functional method in order for us to resolve it's type arguments properly + Optional functionalMethodOpt = FunctionalInterfaceLogic.getFunctionalMethod(lambdaType); + if (functionalMethodOpt.isPresent()) { + MethodUsage functionalMethod = functionalMethodOpt.get(); + + List resolvedTypes = new ArrayList<>(); + + for (ResolvedType type : functionalMethod.getParamTypes()) { + InferenceContext inferenceContext = new InferenceContext(typeSolver); + + // 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()), lambdaType); + + // Now resolve the argument type using the inference context + ResolvedType argType = inferenceContext.resolve(inferenceContext.addSingle(type)); + + ResolvedLambdaConstraintType conType; + if (argType.isWildcard()){ + conType = ResolvedLambdaConstraintType.bound(argType.asWildcard().getBoundedType()); + } else { + conType = ResolvedLambdaConstraintType.bound(argType); + } + + resolvedTypes.add(conType); + } + + return resolvedTypes; + } + throw new UnsupportedOperationException(); + } + + private int pos(NodeWithArguments callExpr, Expression param) { int i = 0; for (Expression p : callExpr.getArguments()) { if (p == param) { diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3878Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3878Test.java new file mode 100644 index 0000000000..6a5e269bd9 --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue3878Test.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013-2024 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the 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.expr.MethodReferenceExpr; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue3878Test { + + @BeforeEach + void setup() { + JavaSymbolSolver symbolSolver = new JavaSymbolSolver(new ReflectionTypeSolver()); + StaticJavaParser.getParserConfiguration().setSymbolResolver(symbolSolver); + } + + @Test + void resolve_method_reference_in_ObjectCreationExpr() { + String code = "package test;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "class A {\n" + + "A(Consumer f) {}\n" + + "void bar(int i) {}\n" + + "void foo() { new A(this::bar); }\n" + + "}"; + CompilationUnit cu = StaticJavaParser.parse(code); + MethodReferenceExpr expr = cu.findFirst(MethodReferenceExpr.class).get(); + + ResolvedMethodDeclaration decl = expr.resolve(); + + assertEquals("test.A.bar(int)", decl.getQualifiedSignature()); + } +} From d87467c77c13ebfa9fc504e3ee9ef1b99cd4a1fa Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:16:07 +0000 Subject: [PATCH 13/65] chore(deps): update dependency org.assertj:assertj-core to v3.25.2 --- javaparser-core-testing/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index b8348cb6a4..df22b03e22 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -125,7 +125,7 @@ org.assertj assertj-core - 3.25.1 + 3.25.2 test From a686d562e848d9862becc9c5ac953f3836500892 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 19:25:45 +0000 Subject: [PATCH 14/65] chore(deps): update codecov/codecov-action action to v3.1.5 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 97119e994f..34d3cbbb30 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v3.1.4 + uses: codecov/codecov-action@v3.1.5 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v3.1.4 + uses: codecov/codecov-action@v3.1.5 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From 33166d6aedf8d476407a743af97c80caf02a60e8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:28:51 +0000 Subject: [PATCH 15/65] chore(deps): update dependency com.puppycrawl.tools:checkstyle to v10.13.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de012a9a62..e31cb908b3 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.puppycrawl.tools checkstyle - 10.12.7 + 10.13.0
From fe4c091df0ad8e8b1baa8745468446a2b25b34f9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 19:43:40 +0000 Subject: [PATCH 16/65] chore(deps): update codecov/codecov-action action to v3.1.6 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 34d3cbbb30..ef3a27d8b9 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v3.1.5 + uses: codecov/codecov-action@v3.1.6 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v3.1.5 + uses: codecov/codecov-action@v3.1.6 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From a53b9108af9e69f41bd1741b66c523f8e83cb4c0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:24:34 +0000 Subject: [PATCH 17/65] chore(deps): update codecov/codecov-action action to v4 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index ef3a27d8b9..d2d3b5ac53 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v3.1.6 + uses: codecov/codecov-action@v4.0.0 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v3.1.6 + uses: codecov/codecov-action@v4.0.0 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From 3706834c73a888ba0286718485a5a9e7775bd8f2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:51:28 +0000 Subject: [PATCH 18/65] chore(deps): update codecov/codecov-action action to v4.0.1 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index d2d3b5ac53..c889d10137 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v4.0.0 + uses: codecov/codecov-action@v4.0.1 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v4.0.0 + uses: codecov/codecov-action@v4.0.1 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From af4ea97ba4bbcaa3c497bd067bbdeb801e261454 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Feb 2024 16:55:36 +0100 Subject: [PATCH 19/65] Fix checkstyle issue --- .../src/main/java/com/github/javaparser/HasParentNode.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 6be68e7b92..8b5b07450a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java +++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java @@ -20,13 +20,12 @@ */ 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. */ From 9c78318ee4258c0eb32af8bb51f4da026fd52dbc Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Feb 2024 17:26:02 +0100 Subject: [PATCH 20/65] Minor refactoring to use the existing getArgumentPosition method --- .../javaparsermodel/contexts/MethodReferenceExprContext.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f5c88d894d..6bbe39ae7b 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 @@ -102,7 +102,7 @@ private List inferArgumentTypes() { if (demandParentNode(wrappedNode) instanceof MethodCallExpr) { MethodCallExpr methodCallExpr = (MethodCallExpr) demandParentNode(wrappedNode); MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(methodCallExpr); - int pos = pos(methodCallExpr, wrappedNode); + int pos = methodCallExpr.getArgumentPosition(wrappedNode); ResolvedMethodDeclaration rmd = methodUsage.getDeclaration(); // Since variable parameters are represented by an array, in case we deal with // the variadic parameter we have to take into account the base type of the @@ -118,7 +118,7 @@ private List inferArgumentTypes() { ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) demandParentNode(wrappedNode); ResolvedConstructorDeclaration rcd = JavaParserFacade.get(typeSolver).solve(objectCreationExpr) .getCorrespondingDeclaration(); - int pos = pos(objectCreationExpr, wrappedNode); + int pos = objectCreationExpr.getArgumentPosition(wrappedNode); // Since variable parameters are represented by an array, in case we deal with // the variadic parameter we have to take into account the base type of the // array. From c241695934baf2eb932f143b7acd9008caccf72c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 2 Feb 2024 17:28:44 +0100 Subject: [PATCH 21/65] Removal of an unnecessary private method that searches for the position of an argument --- .../contexts/MethodReferenceExprContext.java | 13 ------------- 1 file changed, 13 deletions(-) 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 6bbe39ae7b..1e278f11b3 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 @@ -27,11 +27,9 @@ import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.MethodReferenceExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.nodeTypes.NodeWithArguments; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.TypeSolver; @@ -222,15 +220,4 @@ private List resolveLambdaTypes(ResolvedType lambdaType) { throw new UnsupportedOperationException(); } - private int pos(NodeWithArguments callExpr, Expression param) { - int i = 0; - for (Expression p : callExpr.getArguments()) { - if (p == param) { - return i; - } - i++; - } - throw new IllegalArgumentException(); - } - } From 81ad20313641e6be0aa54125614c366f215e85e7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:23:40 +0000 Subject: [PATCH 22/65] chore(deps): update junit5 monorepo to v5.10.2 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e31cb908b3..a52a88187a 100644 --- a/pom.xml +++ b/pom.xml @@ -366,19 +366,19 @@ org.junit.jupiter junit-jupiter-engine - 5.10.1 + 5.10.2 test org.junit.jupiter junit-jupiter-params - 5.10.1 + 5.10.2 test org.junit.vintage junit-vintage-engine - 5.10.1 + 5.10.2 test From a75a2bc3cfbb4c65e44e5320a3b4d44e08d91e63 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 01:14:53 +0000 Subject: [PATCH 23/65] chore(deps): update dependency org.assertj:assertj-core to v3.25.3 --- javaparser-core-testing/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index df22b03e22..ef97bd20c2 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -125,7 +125,7 @@ org.assertj assertj-core - 3.25.2 + 3.25.3 test From 6a26527b8a0745c53be0523f009a01aa0540cfb3 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 6 Feb 2024 13:55:01 +0100 Subject: [PATCH 24/65] fix: issue 4311 IllegalStateException when removing all comments with LexicalPreservingPrinter --- .../LexicalPreservingPrinterTest.java | 23 +++++++- .../LexicalPreservingPrinter.java | 58 +++++++++++-------- 2 files changed, 57 insertions(+), 24 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 97793c87dc..f8dd5e308e 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 @@ -26,7 +26,10 @@ 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.*; +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.fail; import java.io.IOException; import java.util.Arrays; @@ -1702,6 +1705,24 @@ void removedIndentationLineCommentsPrinted() { assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); } + // issue 4311 IllegalStateException when removing all comments with LexicalPreservingPrinter + @Test + void removedLineCommentsWithSameContent() { + considerCode("public class Foo {\n" + + " //line 1 \n" + + " //line 1 \n" + + " void mymethod() {\n" + + " }\n" + + "}"); + String expected = + "public class Foo {\n" + + " void mymethod() {\n" + + " }\n" + + "}"; + cu.getAllContainedComments().stream().forEach(c -> c.remove()); + assertEqualsStringIgnoringEol(expected, LexicalPreservingPrinter.print(cu)); + } + // issue 3216 LexicalPreservingPrinter add Wrong indentation when removing comments @Test void removedIndentationBlockCommentsPrinted() { 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 00414440bf..8089a71422 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 @@ -175,9 +175,6 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert } else { removeAllExtraCharactersStartingFrom(nodeText.getElements().listIterator(index)); } -// if (nodeText.getElements().get(index).isNewline()) { -// nodeText.removeElement(index); -// } } else { throw new UnsupportedOperationException("Trying to remove something that is not a comment!"); } @@ -285,12 +282,21 @@ private int getIndexOfComment(Comment oldValue, NodeText nodeText) { return nodeText.findElement(matchingChild.and(matchingChild.matchByRange())); } + /* + * Comment + */ private List findChildTextElementForComment(Comment oldValue, NodeText nodeText) { List matchingChildElements; 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()); + matchingChildElements = matchingChildElements.stream() + .filter(t -> t.getChild().hasRange() && oldValue.hasRange()) + .filter(t -> t.getChild().getRange().get().equals(oldValue.getRange().get()) + || (t.getChild().getComment().isPresent() + && t.getChild().getComment().get().hasRange() + && t.getChild().getComment().get().getRange().get().equals(oldValue.getRange().get()))) + .collect(toList()); } if (matchingChildElements.size() != 1) { throw new IllegalStateException("The matching child text element for the comment to be removed could not be found."); @@ -324,25 +330,31 @@ private boolean isSameComment(Comment childValue, Comment oldValue) { 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.getHeader() + oldValue.getContent() + oldValue.getFooter())).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.getHeader() + oldValue.getContent() + oldValue.getFooter())).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.getHeader() + 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()); - } - return matchingTokens; - } - - private boolean isEqualRange(Optional range1, Optional range2) { - if (range1.isPresent() && range2.isPresent()) { - return range1.get().equals(range2.get()); - } - return false; + if (oldValue instanceof JavadocComment) { + matchingTokens = nodeText.getElements().stream() + .filter(e -> e.isToken(JAVADOC_COMMENT)) + .map(e -> (TokenTextElement) e) + .filter(t -> t.getText().equals(oldValue.asString())) + .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.asString())) + .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.asString()).trim())) + .collect(toList()); + } + // To check that a comment matches in the list of tokens, the range must be always checked, + // as comments with the same content may exist on different lines. + return matchingTokens.stream() + .filter(t -> t.getToken().hasRange() && oldValue.hasRange()) + .filter(t -> t.getToken().getRange().get().equals(oldValue.getRange().get())) + .collect(toList()); } /** From 0ea703de0ca1092a678dab4e424f56fec99a0cd3 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 6 Feb 2024 14:29:01 +0100 Subject: [PATCH 25/65] fix: Consider the case where the position is not defined. In this case, if the content is identical, you can assume that you have found the token corresponding to the comment. --- .../lexicalpreservation/LexicalPreservingPrinter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 8089a71422..8e3f8fc844 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 @@ -349,11 +349,12 @@ private List findTokenTextElementForComment(Comment oldValue, .filter(t -> t.getText().trim().equals((oldValue.asString()).trim())) .collect(toList()); } - // To check that a comment matches in the list of tokens, the range must be always checked, + // To check that a comment matches in the list of tokens, if exists the range must be always checked, // as comments with the same content may exist on different lines. return matchingTokens.stream() - .filter(t -> t.getToken().hasRange() && oldValue.hasRange()) - .filter(t -> t.getToken().getRange().get().equals(oldValue.getRange().get())) + .filter(t -> (!t.getToken().hasRange() && !oldValue.hasRange()) + || (t.getToken().hasRange() && oldValue.hasRange() + && t.getToken().getRange().get().equals(oldValue.getRange().get()))) .collect(toList()); } From 0846c654b713a25a21952c2dd973abea9ae18b7e Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 7 Feb 2024 18:18:18 +0100 Subject: [PATCH 26/65] Fix: issue #3946 Symbol solver is unable to resolve inherited inner classes --- .../JavaParserTypeDeclarationAdapter.java | 16 ++---- .../JavaParserTypeDeclarationAdapterTest.java | 54 +++++++++++++++---- 2 files changed, 49 insertions(+), 21 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 7c4aed0f69..29f7498b40 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 @@ -96,7 +96,9 @@ public SymbolReference solveType(String name, List symbolRef = context.getParent() .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) .solveType(name, typeArguments); @@ -140,17 +142,7 @@ public SymbolReference solveType(String name, List returnTypes = compilationUnit.findAll(MethodDeclaration.class) + .stream() + .map(md -> md.resolve()) + .map(rmd -> rmd.getReturnType().describe()) + .collect(Collectors.toList()); + + returnTypes.forEach(type -> assertEquals("Activity.Timestamps", type)); + } } From 91e513479963865eb25ea5fd5224fae4aca57038 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Feb 2024 11:53:18 +0100 Subject: [PATCH 27/65] fix: issue 1638 Further improve correction of whitespace during difference application --- .../lexicalpreservation/Difference.java | 57 ++++++++++++++++++- .../changes/ListRemovalChange.java | 26 ++++++++- 2 files changed, 79 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 51cb93dba7..464754fbe3 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 @@ -20,7 +20,9 @@ */ package com.github.javaparser.printer.lexicalpreservation; -import static com.github.javaparser.GeneratedJavaParserConstants.*; +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 java.util.function.Predicate; @@ -334,6 +336,26 @@ private EnforcingIndentationContext defineEnforcingIndentationContext(NodeText n return ctx; } + /* + * An element is considered inlined if, before the line break, there are nodes in the list of elements + */ + private boolean isInlined(NodeText nodeText, int startIndex) { + boolean inlined = false; + if (startIndex < nodeText.numberOfElements() && startIndex >= 0) { + // at this stage startIndex points to the first element before the deleted one + for (int i = startIndex; i < nodeText.numberOfElements(); i++) { + if (nodeText.getTextElement(i).isNewline()) { + break; + } + if (nodeText.getTextElement(i).isChild()) { + inlined = true; + break; + } + } + } + return inlined; + } + /* * Returns true if the indexed element is a space or a tab */ @@ -464,6 +486,26 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, originalIndex++; } } else { + // If we delete the first element, it is possible that there is an indentation to be deleted which is stored in the parent node. + NodeText parentNodeText = new NodeText(); + List indentationTokens = new ArrayList<>(); + if (originalIndex == 0 && removed.getChild().getParentNode().isPresent()) { + Node startingNodeForFindingIndentation = removed.getChild(); + Node parentNode = removed.getChild().getParentNode().get(); + parentNodeText = LexicalPreservingPrinter.getOrCreateNodeText(parentNode); + // If we are trying to delete the first element of a node and that node is also the first element of the parent node, we need to look for the grandfather node which logically contains the indentation characters. + // This is the case, for example, when trying to delete an annotation positioned on a method declaration. + // The token corresponding to the annotation is the first element of the annotation node + // and it is also the first element of the parent node (MethodDeclaration), + // so the previous indentation is defined in the parent node of the method declaration. + if (!parentNodeText.getElements().isEmpty() + && parentNode.getParentNode().isPresent() + && parentNodeText.getTextElement(0).equals(nodeText.getTextElement(originalIndex))) { + startingNodeForFindingIndentation = parentNode; + parentNodeText = LexicalPreservingPrinter.getOrCreateNodeText(parentNode.getParentNode().get()); + } + indentationTokens = LexicalPreservingPrinter.findIndentation(startingNodeForFindingIndentation); + } nodeText.removeElement(originalIndex); // 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) @@ -494,6 +536,19 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, if (isRemovingIndentationActivable(removedGroup)) { // Since the element has been deleted we try to start the analysis from the previous element originalIndex = considerRemovingIndentation(nodeText, originalIndex); + // If we delete the first element, it is possible that there is an indentation + // to be deleted which is stored in the parent node. + // We don't want to remove indentation when the node to remove is not the only + // node in the line (if there are other nodes before the next character + // indicating the end of line). + // This is for example the case when we want to delete an annotation declared on + // the same line as a method declaration. + if (originalIndex == 0 && !indentationTokens.isEmpty() && !isInlined(nodeText, originalIndex)) { + for (TextElement indentationToken : indentationTokens) { + parentNodeText.removeElement( + parentNodeText.findElement(indentationToken.and(indentationToken.matchByRange()))); + } + } } diffIndex++; } 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 8a0f4e98fe..7757c22934 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 @@ -22,6 +22,7 @@ import java.util.Optional; +import com.github.javaparser.Range; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.observer.ObservableProperty; @@ -56,14 +57,33 @@ public Object getValue(ObservableProperty property, Node node) { NodeList newNodeList = new NodeList<>(); // 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); + // Here we want to obtain a sub-list that does not contain an element. + // It is important not to implement this by first adding all the elements in the + // list and then deleting the element to be removed, as this involves event + // propagation mechanisms, particularly for lexical preservation, + // which deletes the relationship between a node and its parent node. + // This relationship is necessary to reinforce indentation, for example when + // deleting a node, as indentation can be carried by the parent node. + currentNodeList.stream().filter(n -> !isSameNode(currentNodeList.get(index),n)) + .forEach(selectedNode -> newNodeList.add(selectedNode)); return newNodeList; } return new NoChange().getValue(property, node); } + private boolean isSameNode(Node n1, Node n2) { + return n1.equals(n2) && isSameRange(n1, n2); + } + + private boolean isSameRange(Node n1, Node n2) { + return (!n1.hasRange() && !n2.hasRange()) + || (n1.hasRange() && n2.hasRange() && isSameRange(n1.getRange().get(), n2.getRange().get())); + } + + private boolean isSameRange(Range r1, Range r2) { + return r1.equals(r2); + } + @Override public ObservableProperty getProperty() { return observableProperty; From 9147ce2f365e9a2ae0f83322e85a3ea83265d5fe Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Feb 2024 11:53:48 +0100 Subject: [PATCH 28/65] Minor refactoring to improve readability --- .../javaparser/remove/NodeRemovalTest.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 30ba14929e..bf0ff600a8 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 @@ -21,6 +21,13 @@ package com.github.javaparser.remove; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.junit.jupiter.api.Test; + import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -29,15 +36,9 @@ import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest; -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; class NodeRemovalTest extends AbstractLexicalPreservingTest{ - + private final CompilationUnit compilationUnit = new CompilationUnit(); @Test @@ -75,9 +76,12 @@ void testRemoveStatementFromMethodBody() { @Test void testRemoveStatementFromMethodBodyWithLexicalPreservingPrinter() { - considerStatement("{\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"); + " throw new ApplicationException(e);\r\n" + + "}\r\n"); BlockStmt bstmt = statement.asBlockStmt(); List children = bstmt.getChildNodes(); remove(children.get(0)); From df56883dd7df911e0578e0def6ae7a8c5a95f17d Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Feb 2024 12:11:03 +0100 Subject: [PATCH 29/65] Adds unit test --- .../javaparser/remove/NodeRemovalTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 bf0ff600a8..4d80274170 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 @@ -21,6 +21,7 @@ package com.github.javaparser.remove; +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -36,6 +37,7 @@ 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; class NodeRemovalTest extends AbstractLexicalPreservingTest{ @@ -91,6 +93,27 @@ void testRemoveStatementFromMethodBodyWithLexicalPreservingPrinter() { assertTrue(children.stream().allMatch(n -> n.getParentNode() != null)); } + @Test + // issue 1638 + public void removingAnnotationsFormattedWithAdditionalSpaces() { + considerCode( + "class X {\n" + + " @Override\n" + + " public void testCase() {\n" + + " }\n" + + "}" + ); + + cu.getType(0).getMethods().get(0).getAnnotationByName("Override").get().remove(); + + String result = LexicalPreservingPrinter.print(cu.findCompilationUnit().get()); + assertEqualsStringIgnoringEol( + "class X {\n" + + " public void testCase() {\n" + + " }\n" + + "}", result); + } + // remove the node and parent's node until response is true boolean remove(Node node) { boolean result = node.remove(); From 3636a055d1f4f8d13aa2de251084c2e13e14da90 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Feb 2024 19:42:17 +0100 Subject: [PATCH 30/65] fix: issue 2043 getAccessSpecifier should return public for interface methods --- .../ast/body/MethodDeclarationTest.java | 34 ++++++++++++++++--- .../ast/body/MethodDeclaration.java | 34 +++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) 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 797d439e11..accd501508 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,10 +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.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.*; +import com.github.javaparser.ast.CompilationUnit; class MethodDeclarationTest { @Test @@ -102,7 +108,7 @@ void signatureToString() { MethodDeclaration method1 = parseBodyDeclaration("int x(int z, String q);").asMethodDeclaration(); assertEquals("x(int, String)", method1.getSignature().toString()); } - + @Test void isVariableArityMethod() { MethodDeclaration method1 = parseBodyDeclaration("int x(int... z);").asMethodDeclaration(); @@ -110,7 +116,7 @@ void isVariableArityMethod() { MethodDeclaration method2 = parseBodyDeclaration("int x(int i, int... z);").asMethodDeclaration(); assertTrue(method2.isVariableArityMethod()); } - + @Test void isFixedArityMethod() { MethodDeclaration method1 = parseBodyDeclaration("int x(int z);").asMethodDeclaration(); @@ -118,4 +124,24 @@ void isFixedArityMethod() { MethodDeclaration method2 = parseBodyDeclaration("int x();").asMethodDeclaration(); assertTrue(method2.isFixedArityMethod()); } + + @Test + void isInterfaceImplictlyPublic() { + CompilationUnit cu = parse("interface Foo { void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isPublic()); + cu = parse("interface Foo { abstract void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isPublic()); + cu = parse("interface Foo { protected void m(); }"); + assertFalse(cu.findFirst(MethodDeclaration.class).get().isPublic()); + } + + @Test + void isInterfaceImplictlyAbstract() { + CompilationUnit cu = parse("interface Foo { void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + cu = parse("interface Foo { abstract void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + cu = parse("interface Foo { protected void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + } } 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 97d09e8522..89ed01764c 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 @@ -20,6 +20,7 @@ */ package com.github.javaparser.ast.body; +import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; import static com.github.javaparser.utils.Utils.assertNotNull; import java.util.Optional; @@ -27,6 +28,7 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.*; +import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.SimpleName; import com.github.javaparser.ast.nodeTypes.*; @@ -251,6 +253,38 @@ public String toDescriptor() { return sb.toString(); } + /* + * Interface methods are implicitly public + */ + @Override + public boolean isPublic() { + return hasModifier(PUBLIC) || isImplicitlyPublic(); + } + + private boolean isImplicitlyPublic() { + return getAccessSpecifier() == AccessSpecifier.NONE + && hasParentNode() + && getParentNode().get() instanceof ClassOrInterfaceDeclaration + && ((ClassOrInterfaceDeclaration)getParentNode().get()).isInterface(); + } + + /* + * Every interface is implicitly abstract. + * https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.1.1 + */ + @Override + public boolean isAbstract() { + return hasModifier(Keyword.ABSTRACT) || isImplicitlyAbstract(); + } + + private boolean isImplicitlyAbstract() { + return hasParentNode() + && getParentNode().get() instanceof ClassOrInterfaceDeclaration + && ((ClassOrInterfaceDeclaration)getParentNode().get()).isInterface(); + } + + + public boolean isNative() { return hasModifier(Modifier.Keyword.NATIVE); } From 199cfe836a2a0d2de9987848f61d310bb112ca04 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 8 Feb 2024 21:26:35 +0100 Subject: [PATCH 31/65] Only one of abstract, default, or static modifier is permitted, so if a method is declared as static or by default, it cannot be implicitly abstract --- .../javaparser/ast/body/MethodDeclarationTest.java | 2 ++ .../github/javaparser/ast/body/MethodDeclaration.java | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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 accd501508..65ecd4214d 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 @@ -143,5 +143,7 @@ void isInterfaceImplictlyAbstract() { assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); cu = parse("interface Foo { protected void m(); }"); assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + cu = parse("interface Foo { static void m(); }"); + assertFalse(cu.findFirst(MethodDeclaration.class).get().isAbstract()); } } 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 89ed01764c..3a646f7986 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 @@ -23,6 +23,7 @@ import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC; import static com.github.javaparser.utils.Utils.assertNotNull; +import java.util.Arrays; import java.util.Optional; import java.util.function.Consumer; @@ -269,13 +270,16 @@ && getParentNode().get() instanceof ClassOrInterfaceDeclaration } /* - * Every interface is implicitly abstract. + * Every interface is implicitly abstract but + * only one of abstract, default, or static modifier is permitted * https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.1.1 */ @Override public boolean isAbstract() { - return hasModifier(Keyword.ABSTRACT) || isImplicitlyAbstract(); - } + return hasModifier(Keyword.ABSTRACT) || (isImplicitlyAbstract() && Arrays + .asList(Keyword.STATIC, Keyword.DEFAULT).stream() + .noneMatch(modifier -> hasModifier(modifier))); + } private boolean isImplicitlyAbstract() { return hasParentNode() From 91b7cf988f38754f8b85401a832d1a313caabdbb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:47:42 +0000 Subject: [PATCH 32/65] fix(deps): update byte-buddy.version to v1.14.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a52a88187a..d8f2b6facd 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ UTF-8 1.8 - 1.14.11 + 1.14.12 -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/${byte-buddy.version}/byte-buddy-agent-${byte-buddy.version}.jar 2024-01-01T00:00:00Z From 600a82f95e99b5a134d72c6fb3c3a60442b4f113 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:04:27 +0000 Subject: [PATCH 33/65] Switch order of literals to prevent NullPointerException --- .../com/github/javaparser/generator/VisitorGenerator.java | 2 +- .../javaparser/generator/core/other/TokenKindGenerator.java | 2 +- .../generator/core/visitor/CloneVisitorGenerator.java | 2 +- .../ast/validator/RecordAsTypeIdentifierNotAllowed.java | 4 ++-- .../chunks/UnderscoreKeywordValidator.java | 2 +- .../ast/validator/postprocessors/Java10PostProcessor.java | 2 +- .../javaparser/printer/lexicalpreservation/Difference.java | 2 +- .../declarations/ResolvedReferenceTypeDeclaration.java | 4 ++-- .../com/github/javaparser/utils/CollectionStrategy.java | 2 +- .../github/javaparser/utils/ParserCollectionStrategy.java | 2 +- .../github/javaparser/symbolsolver/JavaSymbolSolver.java | 2 +- .../javaparsermodel/contexts/FieldAccessContext.java | 2 +- .../declarations/JavaParserEnumDeclaration.java | 6 +++--- .../javassistmodel/JavassistEnumDeclaration.java | 2 +- .../reflectionmodel/ReflectionEnumDeclaration.java | 2 +- 15 files changed, 19 insertions(+), 19 deletions(-) diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/VisitorGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/VisitorGenerator.java index 4c7efe59f9..450550390e 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/VisitorGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/VisitorGenerator.java @@ -79,7 +79,7 @@ protected void after() throws Exception { private void generateVisitMethodForNode(BaseNodeMetaModel node, ClassOrInterfaceDeclaration visitorClass, CompilationUnit compilationUnit) { final Optional existingVisitMethod = visitorClass.getMethods().stream() - .filter(m -> m.getNameAsString().equals("visit")) + .filter(m -> "visit".equals(m.getNameAsString())) .filter(m -> m.getParameter(0).getType().toString().equals(node.getTypeName())) .findFirst(); diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/TokenKindGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/TokenKindGenerator.java index cf997f5c54..3989e33478 100644 --- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/TokenKindGenerator.java +++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/other/TokenKindGenerator.java @@ -53,7 +53,7 @@ public void generate() { final CompilationUnit javaTokenCu = sourceRoot.parse("com.github.javaparser", "JavaToken.java"); final ClassOrInterfaceDeclaration javaToken = javaTokenCu.getClassByName("JavaToken").orElseThrow(() -> new AssertionError("Can't find class in java file.")); - final EnumDeclaration kindEnum = javaToken.findFirst(EnumDeclaration.class, e -> e.getNameAsString().equals("Kind")).orElseThrow(() -> new AssertionError("Can't find class in java file.")); + final EnumDeclaration kindEnum = javaToken.findFirst(EnumDeclaration.class, e -> "Kind".equals(e.getNameAsString())).orElseThrow(() -> new AssertionError("Can't find class in java file.")); kindEnum.getEntries().clear(); annotateGenerated(kindEnum); 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 24688552d8..e3036bafad 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 @@ -64,7 +64,7 @@ protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder(f("%s r = new %s(", node.getTypeNameGenerified(), node.getTypeNameGenerified()), ",", ");"); builder.append("n.getTokenRange().orElse(null)"); for (PropertyMetaModel field : node.getConstructorParameters()) { - if (field.getName().equals("comment")) { + if ("comment".equals(field.getName())) { continue; } if (field.getNodeReference().isPresent()) { 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 5a7f0b5272..4fe7bd7736 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 @@ -39,7 +39,7 @@ public RecordAsTypeIdentifierNotAllowed() { @Override public void visit(Name n, ProblemReporter arg) { - if (n.getIdentifier().equals("record") && !validUsage(n)) { + if ("record".equals(n.getIdentifier()) && !validUsage(n)) { arg.report(n, error); } super.visit(n, arg); @@ -47,7 +47,7 @@ public void visit(Name n, ProblemReporter arg) { @Override public void visit(SimpleName n, ProblemReporter arg) { - if (n.getIdentifier().equals("record") && !validUsage(n)) { + if ("record".equals(n.getIdentifier()) && !validUsage(n)) { arg.report(n, error); } super.visit(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 873eba395f..6613ef83aa 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 @@ -41,7 +41,7 @@ public void visit(SimpleName n, ProblemReporter arg) { } private static void validateIdentifier(Node n, String id, ProblemReporter arg) { - if (id.equals("_")) { + if ("_".equals(id)) { arg.report(n, "'_' is a reserved keyword."); } } 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 575e04dfa8..ca9c632e50 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 @@ -51,7 +51,7 @@ public void postProcess(ParseResult result, ParserConfiguration result.getResult().ifPresent(node -> { node.findAll(ClassOrInterfaceType.class) .forEach(n -> { - if (n.getNameAsString().equals("var") + if ("var".equals(n.getNameAsString()) && !matchForbiddenContext(n)) { n.replace(new VarType(n.getTokenRange().orElse(null))); } 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 464754fbe3..ffd31f07e4 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 @@ -786,7 +786,7 @@ private int getIndexToNextTokenElement(TokenTextElement element, DifferenceEleme if (part.equals(token.asString())) { // get 'dot' token token = token.getNextToken().get(); - if (!token.asString().equals(".")) + if (!".".equals(token.asString())) break; // get the next part token = token.getNextToken().get(); 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 1afabcfcd6..a17be414be 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 @@ -360,7 +360,7 @@ default Optional findTypeParameter(String name */ default boolean isJavaLangObject() { return this.isClass() && !isAnonymousClass() && // Consider anonymous classes - hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT); + hasName() && JAVA_LANG_OBJECT.equals(getQualifiedName()); } /** @@ -368,6 +368,6 @@ default boolean isJavaLangObject() { * @see ResolvedReferenceType#isJavaLangEnum() */ default boolean isJavaLangEnum() { - return this.isEnum() && getQualifiedName().equals(JAVA_LANG_ENUM); + return this.isEnum() && JAVA_LANG_ENUM.equals(getQualifiedName()); } } 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 3ffd1d5cbf..0c549f2ce9 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 @@ -50,7 +50,7 @@ default Optional getRoot(Path file) { if (parseResult.getResult().isPresent()) { final Optional storage = parseResult.getResult().flatMap(CompilationUnit::getStorage); if (storage.isPresent()) { - if (storage.get().getFileName().equals("module-info.java")) { + if ("module-info.java".equals(storage.get().getFileName())) { // module-info.java is useless for finding the source root, since it can be placed in any directory. return Optional.empty(); } 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 979fbe29f3..c95a4bbded 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 @@ -66,7 +66,7 @@ public ProjectRoot collect(Path path) { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - if (file.getFileName().toString().equals("module-info.java")) { + if ("module-info.java".equals(file.getFileName().toString())) { // module-info.java is useless for finding the source root, since it can be placed within any directory. return CONTINUE; } 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 aac04d0065..26e90d8e26 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 @@ -215,7 +215,7 @@ public T resolveDeclaration(Node node, Class resultClass) { return resultClass.cast(result.getCorrespondingDeclaration()); } } else { - if (((FieldAccessExpr) node).getName().getId().equals("length")) { + if ("length".equals(((FieldAccessExpr) node).getName().getId())) { ResolvedType scopeType = ((FieldAccessExpr) node).getScope().calculateResolvedType(); if (scopeType.isArray()) { if (resultClass.isInstance(ArrayLengthValueDeclaration.INSTANCE)) { 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 7fcdba898d..1060e7f60c 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 @@ -83,7 +83,7 @@ public Optional solveSymbolAsValue(String name) { Expression scope = wrappedNode.getScope(); if (wrappedNode.getName().toString().equals(name)) { ResolvedType typeOfScope = JavaParserFacade.get(typeSolver).getType(scope); - if (typeOfScope.isArray() && name.equals(ARRAY_LENGTH_FIELD_NAME)) { + if (typeOfScope.isArray() && ARRAY_LENGTH_FIELD_NAME.equals(name)) { return Optional.of(new Value(ResolvedPrimitiveType.INT, ARRAY_LENGTH_FIELD_NAME)); } if (typeOfScope.isReferenceType()) { 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 94b510506e..dc5318df75 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 @@ -122,7 +122,7 @@ public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(this.getQualifiedName())) { return true; } - if (otherName.equals(JAVA_LANG_ENUM)) { + if (JAVA_LANG_ENUM.equals(otherName)) { return true; } // Enum implements Comparable and Serializable @@ -204,10 +204,10 @@ public Optional solveMethodAsUsage(String name, List @Override public SymbolReference solveMethod(String name, List argumentsTypes, boolean staticOnly) { - if (name.equals("values") && argumentsTypes.isEmpty()) { + if ("values".equals(name) && argumentsTypes.isEmpty()) { return SymbolReference.solved(new JavaParserEnumDeclaration.ValuesMethod(this, typeSolver)); } - if (name.equals("valueOf") && argumentsTypes.size() == 1) { + if ("valueOf".equals(name) && argumentsTypes.size() == 1) { ResolvedType argument = argumentsTypes.get(0); if (argument.isReferenceType() && "java.lang.String".equals(argument.asReferenceType().getQualifiedName())) { return SymbolReference.solved(new JavaParserEnumDeclaration.ValueOfMethod(this, typeSolver)); 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 3299872b71..ae21ba5a0d 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 @@ -127,7 +127,7 @@ public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(this.getQualifiedName())) { return true; } - if (otherName.equals(JAVA_LANG_ENUM)) { + if (JAVA_LANG_ENUM.equals(otherName)) { return true; } // Enum implements Comparable and Serializable 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 abb9e82662..6436c76c11 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 canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(this.getQualifiedName())) { return true; } - if (otherName.equals(JAVA_LANG_ENUM)) { + if (JAVA_LANG_ENUM.equals(otherName)) { return true; } // Enum implements Comparable and Serializable From 9d42774e4627d62f9cbb2fb33aa8fbee1fde7b56 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:29:30 +0000 Subject: [PATCH 34/65] chore(deps): bump org.codehaus.mojo:exec-maven-plugin Bumps [org.codehaus.mojo:exec-maven-plugin](https://github.com/mojohaus/exec-maven-plugin) from 3.1.1 to 3.2.0. - [Release notes](https://github.com/mojohaus/exec-maven-plugin/releases) - [Commits](https://github.com/mojohaus/exec-maven-plugin/compare/3.1.1...3.2.0) --- updated-dependencies: - dependency-name: org.codehaus.mojo:exec-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 d8f2b6facd..2e91845a1d 100644 --- a/pom.xml +++ b/pom.xml @@ -293,7 +293,7 @@ org.codehaus.mojo exec-maven-plugin - 3.1.1 + 3.2.0 org.apache.maven.plugins From 0946cca68a641fa122192f1761fe4a61a8c4f7ff Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:29:44 +0000 Subject: [PATCH 35/65] chore(deps): update dependency org.codehaus.mojo:exec-maven-plugin to v3.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d8f2b6facd..2e91845a1d 100644 --- a/pom.xml +++ b/pom.xml @@ -293,7 +293,7 @@ org.codehaus.mojo exec-maven-plugin - 3.1.1 + 3.2.0 org.apache.maven.plugins From 6846f0e87c5b2dfc9ba0cfa1bcd83069ae6690c4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:36:19 +0000 Subject: [PATCH 36/65] chore(deps): update codecov/codecov-action action to v4.0.2 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index c889d10137..8bd30fbb33 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v4.0.2 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v4.0.2 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From f8d7444a972e717e95935fc463040edde61b18fb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:03:02 +0000 Subject: [PATCH 37/65] chore(deps): update codecov/codecov-action action to v4.1.0 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 8bd30fbb33..053589eb8a 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v4.0.2 + uses: codecov/codecov-action@v4.1.0 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v4.0.2 + uses: codecov/codecov-action@v4.1.0 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From d7efb09776806d83ef3925bbe3f0a8548dcb5cdf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:03:04 +0000 Subject: [PATCH 38/65] chore(deps): update dependency com.puppycrawl.tools:checkstyle to v10.14.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2e91845a1d..397024df98 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.puppycrawl.tools checkstyle - 10.13.0 + 10.14.0 From 2a97f3c2adb58b64bc30461f6a6621a3f0210a95 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 29 Feb 2024 16:34:25 +0100 Subject: [PATCH 39/65] fix: Replace this if-then-else statement by a single return statement (sonar rule) --- .../JavaParserEnumDeclaration.java | 9 ++---- .../JavaParserInterfaceDeclaration.java | 4 +-- .../declarations/JavaParserTypeParameter.java | 14 ++++----- .../JavassistEnumDeclaration.java | 5 +--- .../JavassistTypeParameter.java | 22 +++++++------- .../ReflectionClassDeclaration.java | 25 ++++++++-------- .../ReflectionEnumDeclaration.java | 5 +--- .../ReflectionInterfaceDeclaration.java | 27 +++++++---------- .../ReflectionTypeParameter.java | 29 +++++++++---------- .../resolution/naming/NameLogic.java | 26 ++++------------- 10 files changed, 62 insertions(+), 104 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 dc5318df75..054eed272c 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 @@ -132,10 +132,7 @@ public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(JAVA_IO_SERIALIZABLE)) { return true; } - if (other.isJavaLangObject()) { - return true; - } - return false; + return other.isJavaLangObject(); } @Override @@ -185,9 +182,7 @@ public boolean equals(Object o) { JavaParserEnumDeclaration that = (JavaParserEnumDeclaration) o; - if (!wrappedNode.equals(that.wrappedNode)) return false; - - return true; + return wrappedNode.equals(that.wrappedNode); } @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 925f496026..f812501d03 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 @@ -93,9 +93,7 @@ public boolean equals(Object o) { JavaParserInterfaceDeclaration that = (JavaParserInterfaceDeclaration) o; - if (!wrappedNode.equals(that.wrappedNode)) return false; - - return true; + return wrappedNode.equals(that.wrappedNode); } @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 4a5cdad06f..02acbd055f 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,6 +21,11 @@ package com.github.javaparser.symbolsolver.javaparsermodel.declarations; +import static com.github.javaparser.resolution.Navigator.demandParentNode; + +import java.util.*; +import java.util.stream.Collectors; + import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; @@ -34,11 +39,6 @@ import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import java.util.*; -import java.util.stream.Collectors; - -import static com.github.javaparser.resolution.Navigator.demandParentNode; - /** * @author Federico Tomassetti @@ -69,9 +69,7 @@ public boolean equals(Object o) { JavaParserTypeParameter that = (JavaParserTypeParameter) o; - if (wrappedNode != null ? !wrappedNode.equals(that.wrappedNode) : that.wrappedNode != null) return false; - - return true; + return wrappedNode != null && wrappedNode.equals(that.wrappedNode); } @Override 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 ae21ba5a0d..ea871b1a53 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 @@ -137,10 +137,7 @@ public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(JAVA_IO_SERIALIZABLE)) { return true; } - if (other.isJavaLangObject()) { - return true; - } - return false; + return other.isJavaLangObject(); } @Override 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 b66ede7786..02f325ba15 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,6 +21,11 @@ package com.github.javaparser.symbolsolver.javassistmodel; +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; @@ -28,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 @@ -60,14 +61,11 @@ public boolean equals(Object o) { if (!getQualifiedName().equals(that.getQualifiedName())) { return false; } - if (declaredOnType() != that.declaredOnType()) { - return false; - } - if (declaredOnMethod() != that.declaredOnMethod()) { - return false; + if (declaredOnType() == that.declaredOnType()) { + return true; } // TODO check bounds - return true; + return declaredOnMethod() == that.declaredOnMethod(); } @Override @@ -128,7 +126,7 @@ public Optional containerType() { } return Optional.empty(); } - + @Override public ResolvedReferenceType object() { return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); 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 cd082ff15e..c5bf4bdddd 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 @@ -21,6 +21,13 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; + import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.Context; @@ -39,13 +46,6 @@ import com.github.javaparser.symbolsolver.logic.AbstractClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.comparators.MethodComparator; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - /** * @author Federico Tomassetti */ @@ -108,9 +108,7 @@ public boolean equals(Object o) { ReflectionClassDeclaration that = (ReflectionClassDeclaration) o; - if (!clazz.getCanonicalName().equals(that.clazz.getCanonicalName())) return false; - - return true; + return clazz.getCanonicalName().equals(that.clazz.getCanonicalName()); } @Override @@ -190,8 +188,8 @@ public SymbolReference solveMethod(String name, List< } // When empty there is no sense in trying to find the most applicable. - // This is useful for debugging. Performance is not affected as - // MethodResolutionLogic.findMostApplicable method returns very early + // This is useful for debugging. Performance is not affected as + // MethodResolutionLogic.findMostApplicable method returns very early // when candidateSolvedMethods is empty. if (candidateSolvedMethods.isEmpty()) { return SymbolReference.unsolved(); @@ -211,7 +209,8 @@ public ResolvedType getUsage(Node node) { return new ReferenceTypeImpl(this); } - public Optional solveMethodAsUsage(String name, List argumentsTypes, Context invokationContext, List typeParameterValues) { + @Override + public Optional solveMethodAsUsage(String name, List argumentsTypes, Context invokationContext, List typeParameterValues) { List methodUsages = new ArrayList<>(); List allMethods = Arrays.stream(clazz.getDeclaredMethods()) 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 6436c76c11..98aca00233 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 @@ -161,10 +161,7 @@ public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (otherName.equals(JAVA_IO_SERIALIZABLE)) { return true; } - if (other.isJavaLangObject()) { - return true; - } - return false; + return other.isJavaLangObject(); } @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 7611ff0171..40904709b9 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 @@ -21,6 +21,10 @@ package com.github.javaparser.symbolsolver.reflectionmodel; +import java.lang.reflect.Field; +import java.util.*; +import java.util.stream.Collectors; + import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.ast.Node; import com.github.javaparser.resolution.Context; @@ -40,10 +44,6 @@ import com.github.javaparser.symbolsolver.core.resolution.SymbolResolutionCapability; import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; -import java.lang.reflect.Field; -import java.util.*; -import java.util.stream.Collectors; - /** * @author Federico Tomassetti */ @@ -131,11 +131,7 @@ public boolean equals(Object o) { if (!clazz.getCanonicalName().equals(that.clazz.getCanonicalName())) return false; - if (!getTypeParameters().equals(that.getTypeParameters())) { - return false; - } - - return true; + return getTypeParameters().equals(that.getTypeParameters()); } @Override @@ -143,7 +139,8 @@ public int hashCode() { return clazz.hashCode(); } - public Optional solveMethodAsUsage(String name, List parameterTypes, + @Override + public Optional solveMethodAsUsage(String name, List parameterTypes, Context invokationContext, List typeParameterValues) { Optional res = ReflectionMethodResolutionLogic.solveMethodAsUsage(name, parameterTypes, typeSolver, invokationContext, typeParameterValues, this, clazz); @@ -193,12 +190,8 @@ && new ReflectionInterfaceDeclaration(clazz.getSuperclass(), typeSolver).canBeAs } } - if (other.isJavaLangObject()) { - // Everything can be assigned to {@code java.lang.Object} - return true; - } - - return false; + // Everything can be assigned to {@code java.lang.Object} + return other.isJavaLangObject(); } @Override @@ -288,7 +281,7 @@ public List getInterfacesExtended() { } return res; } - + @Override public Optional containerType() { return reflectionClassAdapter.containerType(); 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 d8314804a5..016a02a2af 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,14 +21,6 @@ package com.github.javaparser.symbolsolver.reflectionmodel; -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; @@ -38,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 */ @@ -70,14 +70,11 @@ public boolean equals(Object o) { if (!getQualifiedName().equals(that.getQualifiedName())) { return false; } - if (declaredOnType() != that.declaredOnType()) { - return false; - } - if (declaredOnMethod() != that.declaredOnMethod()) { - return false; + if (declaredOnType() == that.declaredOnType()) { + return true; } // TODO check bounds - return true; + return declaredOnMethod() == that.declaredOnMethod(); } @Override @@ -107,7 +104,7 @@ public String getContainerId() { } return ((ResolvedMethodLikeDeclaration) container).getQualifiedSignature(); } - + @Override public ResolvedTypeParametrizable getContainer() { return this.container; @@ -132,7 +129,7 @@ public Optional containerType() { } return Optional.empty(); } - + @Override public ResolvedReferenceType object() { return new ReferenceTypeImpl(typeSolver.getSolvedJavaLangObject()); 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 50cec2fdc3..0e3b430e18 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 @@ -592,12 +592,8 @@ private static boolean isSyntacticallyAPackageOrTypeName(Node name) { // 2. In a type-import-on-demand declaration (§7.5.2) - if (whenParentIs(ImportDeclaration.class, name, (p, c) -> - !p.isStatic() && p.isAsterisk() && p.getName() == name)) { - return true; - } - - return false; + return whenParentIs(ImportDeclaration.class, name, (p, c) -> + !p.isStatic() && p.isAsterisk() && p.getName() == name); } private static boolean isSyntacticallyAMethodName(Node name) { @@ -605,11 +601,7 @@ private static boolean isSyntacticallyAMethodName(Node name) { // // 1. Before the "(" in a method invocation expression (§15.12) - if (whenParentIs(MethodCallExpr.class, name, (p, c) -> p.getName() == c)) { - return true; - } - - return false; + return whenParentIs(MethodCallExpr.class, name, (p, c) -> p.getName() == c); } private static boolean isSyntacticallyAModuleName(Node name) { @@ -626,11 +618,8 @@ private static boolean isSyntacticallyAModuleName(Node name) { if (whenParentIs(ModuleExportsDirective.class, name, (p, c) -> p.getModuleNames().contains(name))) { return true; } - if (whenParentIs(ModuleOpensDirective.class, name, (p, c) -> p.getModuleNames().contains(name))) { - return true; - } - return false; + return whenParentIs(ModuleOpensDirective.class, name, (p, c) -> p.getModuleNames().contains(name)); } private static boolean isSyntacticallyAPackageName(Node name) { @@ -644,12 +633,9 @@ private static boolean isSyntacticallyAPackageName(Node name) { return true; } // 2. To the left of the "." in a qualified PackageName - if (whenParentIs(Name.class, name, (p, c) -> p.getQualifier().isPresent() + return whenParentIs(Name.class, name, (p, c) -> p.getQualifier().isPresent() && p.getQualifier().get() == name - && isSyntacticallyAPackageName(p))) { - return true; - } - return false; + && isSyntacticallyAPackageName(p)); } private static boolean isSyntacticallyATypeName(Node name) { From f97a2d8a29d1758117a0f467caf870602b9ecc11 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 29 Feb 2024 20:39:04 +0100 Subject: [PATCH 40/65] fix: Dead stores should be removed (sonar rule) --- .../github/javaparser/utils/UtilsTest.java | 13 +++++++--- .../javaparser/ast/visitor/CloneVisitor.java | 10 ++------ .../logic/MethodResolutionLogic.java | 2 -- .../com/github/javaparser/utils/Utils.java | 25 +++++++++++-------- 4 files changed, 25 insertions(+), 25 deletions(-) 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 8f92ec2c37..250750661f 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,7 +21,11 @@ package com.github.javaparser.utils; -import org.junit.jupiter.api.Test; +import static com.github.javaparser.utils.Utils.*; +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.io.IOException; import java.io.Reader; @@ -30,9 +34,7 @@ import java.util.HashSet; import java.util.Optional; -import static com.github.javaparser.utils.Utils.assertNotNull; -import static com.github.javaparser.utils.Utils.*; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; class UtilsTest { @@ -182,8 +184,11 @@ void testValueIsNullOrEmptyStringOrOptional() { Optional.empty())); assertFalse(valueIsNullOrEmptyStringOrOptional("foo")); + assertFalse(valueIsNullOrEmptyStringOrOptional("")); assertFalse(valueIsNullOrEmptyStringOrOptional( Optional.ofNullable("foo"))); + assertFalse(valueIsNullOrEmptyStringOrOptional( + Optional.ofNullable(""))); } @Test 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 3d9469d58f..27a3ed6e12 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 @@ -20,6 +20,8 @@ */ package com.github.javaparser.ast.visitor; +import java.util.Optional; + import com.github.javaparser.ast.*; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.BlockComment; @@ -31,8 +33,6 @@ import com.github.javaparser.ast.stmt.*; import com.github.javaparser.ast.type.*; -import java.util.Optional; - /** * A visitor that clones (copies) a node and all its children. */ @@ -258,7 +258,6 @@ public Visitable visit(final Parameter n, final Object arg) { @Override public Visitable visit(final InitializerDeclaration n, final Object arg) { BlockStmt body = cloneNode(n.getBody(), arg); - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body); r.setComment(comment); @@ -329,7 +328,6 @@ public Visitable visit(final ArrayCreationLevel n, final Object arg) { @Override public Visitable visit(final IntersectionType n, final Object arg) { NodeList elements = cloneList(n.getElements(), arg); - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements); r.setComment(comment); @@ -341,7 +339,6 @@ public Visitable visit(final IntersectionType n, final Object arg) { @Override public Visitable visit(final UnionType n, final Object arg) { NodeList elements = cloneList(n.getElements(), arg); - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); UnionType r = new UnionType(n.getTokenRange().orElse(null), elements); r.setComment(comment); @@ -352,7 +349,6 @@ public Visitable visit(final UnionType n, final Object arg) { @Override public Visitable visit(final VoidType n, final Object arg) { - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); VoidType r = new VoidType(n.getTokenRange().orElse(null)); r.setComment(comment); @@ -376,7 +372,6 @@ public Visitable visit(final WildcardType n, final Object arg) { @Override public Visitable visit(final UnknownType n, final Object arg) { - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); UnknownType r = new UnknownType(n.getTokenRange().orElse(null)); r.setComment(comment); @@ -1189,7 +1184,6 @@ public Visitable visit(final ReceiverParameter n, final Object arg) { @Override public Visitable visit(final VarType n, final Object arg) { - NodeList annotations = cloneList(n.getAnnotations(), arg); Comment comment = cloneNode(n.getComment(), arg); VarType r = new VarType(n.getTokenRange().orElse(null)); r.setComment(comment); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java index 6922ef1bb4..b13a83371d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java @@ -130,7 +130,6 @@ private static boolean isApplicable(ResolvedMethodDeclaration methodDeclaration, // The index of the final argument passed (on the method usage). int countOfNeedleArgumentsPassedAfterGrouping = needleArgumentTypes.size(); - int lastNeedleArgumentIndexAfterGrouping = getLastParameterIndex(countOfNeedleArgumentsPassed); // If variadic parameters are possible then they will have been "grouped" into a single argument. // At this point, therefore, the number of arguments must be equal -- if they're not, then there is no match. @@ -428,7 +427,6 @@ public static boolean isApplicable(MethodUsage methodUsage, String needleName, L // The index of the final argument passed (on the method usage). int needleParameterCount = needleParameterTypes.size(); - int lastNeedleParameterIndex = getLastParameterIndex(needleParameterCount); // TODO: Does the method usage have a declaration at this point..? boolean methodIsDeclaredWithVariadicParameter = methodUsage.getDeclaration().hasVariadicParameter(); 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 6773c89a90..386c40fb7a 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 @@ -20,15 +20,15 @@ */ package com.github.javaparser.utils; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.expr.UnaryExpr; +import static java.util.Arrays.asList; import java.io.IOException; import java.io.Reader; import java.util.*; import java.util.function.Function; -import static java.util.Arrays.asList; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.UnaryExpr; /** * Any kind of utility. @@ -220,17 +220,20 @@ public static boolean valueIsNullOrEmpty(Object value) { } public static boolean valueIsNullOrEmptyStringOrOptional(Object value) { + // is null? if (value == null) { return true; } - if (value instanceof Optional) { - if (((Optional) value).isPresent()) { - value = ((Optional) value).get(); - } else { - return true; - } - } - return false; +// // is not Optional? +// if (!(value instanceof Optional)) { +// return false; +// } +// // is an empty Optional? +// if (!((Optional) value).isPresent()) { +// return true; +// } +// return false; + return value instanceof Optional ? !((Optional) value).isPresent() : false; } /** From 501ce00cc4a978e71375f8047fcc40ed62f121a4 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 4 Mar 2024 17:35:06 +0100 Subject: [PATCH 41/65] Update changelog --- changelog.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 82df6170f9..8bb167f264 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,8 @@ -Next Release (Version 3.25.9-snapshot) + +Next Release (Version 3.25.10-snapshot) -------------------------------------- -[issues resolved](https://github.com/javaparser/javaparser/milestone/205?closed=1) +[issues resolved](https://github.com/javaparser/javaparser/milestone/206?closed=1) ### Added ### Changed @@ -10,6 +11,51 @@ Next Release (Version 3.25.9-snapshot) ### Fixed ### Security +Version 3.25.9 +-------------- +[issues resolved](https://github.com/javaparser/javaparser/milestone/205?closed=1) + +### Added + +* Fix: issue #3878 resolve MethodReference in ObjectCreationExpr (PR [#4296](https://github.com/javaparser/javaparser/pull/4296) by [@fishautumn](https://github.com/fishautumn)) + +### Changed + +* Switch order of literals to prevent NullPointerException (PR [#4322](https://github.com/javaparser/javaparser/pull/4322) by [@citizenjosh](https://github.com/citizenjosh)) +* Minor refactoring to use the existing getArgumentPosition method (PR [#4306](https://github.com/javaparser/javaparser/pull/4306) by [@jlerbsc](https://github.com/jlerbsc)) +* Optimize find ancestor (PR [#4294](https://github.com/javaparser/javaparser/pull/4294) by [@magicwerk](https://github.com/magicwerk)) +* refac: Removes useless ExpressionHelper utility class and replaces some explicit casts by using the javaparser API (PR [#4291](https://github.com/javaparser/javaparser/pull/4291) by [@jlerbsc](https://github.com/jlerbsc)) + +### Fixed + +* fix: Dead stores should be removed (sonar rule) (PR [#4329](https://github.com/javaparser/javaparser/pull/4329) by [@jlerbsc](https://github.com/jlerbsc)) +* fix: Replace this if-then-else statement by a single return statement (sonar rule) (PR [#4328](https://github.com/javaparser/javaparser/pull/4328) by [@jlerbsc](https://github.com/jlerbsc)) +* fix: issue 2043 getAccessSpecifier should return public for interface methods (PR [#4317](https://github.com/javaparser/javaparser/pull/4317) by [@jlerbsc](https://github.com/jlerbsc)) +* Further improve correction of whitespace during difference application (PR [#4316](https://github.com/javaparser/javaparser/pull/4316) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: issue #3946 Symbol solver is unable to resolve inherited inner classes (PR [#4314](https://github.com/javaparser/javaparser/pull/4314) by [@jlerbsc](https://github.com/jlerbsc)) +* fix: issue 4311 IllegalStateException when removing all comments with LexicalPreservingPrinter (PR [#4313](https://github.com/javaparser/javaparser/pull/4313) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: issue 3939 SymbolResolver.calculateType(Expression) may fails on first try, then succeed on later tries (PR [#4290](https://github.com/javaparser/javaparser/pull/4290) by [@jlerbsc](https://github.com/jlerbsc)) +* Adds unit test for issue 4284 "ClassCastException when resolving MethodCallExpr inside an enhanced switch statement" (PR [#4285](https://github.com/javaparser/javaparser/pull/4285) by [@jlerbsc](https://github.com/jlerbsc)) +* Change `SwitchStmt` to `SwitchNode` in `SwitchEntryContext` to avoid `ClassCastException` (PR [#4283](https://github.com/javaparser/javaparser/pull/4283) by [@PalashSharma20](https://github.com/PalashSharma20)) + +### Developer Changes + +* chore(deps): bump org.codehaus.mojo:exec-maven-plugin from 3.1.1 to 3.2.0 (PR [#4323](https://github.com/javaparser/javaparser/pull/4323) by [@dependabot[bot]](https://github.com/apps/dependabot)) +* chore(deps): update junit5 monorepo to v5.10.2 (PR [#4307](https://github.com/javaparser/javaparser/pull/4307) by [@renovate[bot]](https://github.com/apps/renovate)) +* chore(deps): update codecov/codecov-action action to v4 (PR [#4304](https://github.com/javaparser/javaparser/pull/4304) by [@renovate[bot]](https://github.com/apps/renovate)) +* chore(deps): update actions/cache action to v4 (PR [#4293](https://github.com/javaparser/javaparser/pull/4293) by [@renovate[bot]](https://github.com/apps/renovate)) + +### :heart: Contributors + +Thank You to all contributors who worked on this release! + +* [@citizenjosh](https://github.com/citizenjosh) +* [@magicwerk](https://github.com/magicwerk) +* [@PalashSharma20](https://github.com/PalashSharma20) +* [@jlerbsc](https://github.com/jlerbsc) +* [@fishautumn](https://github.com/fishautumn) + + Version 3.25.8 -------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/204?closed=1) From d20108bf17e598a5986b208a942c886bbed73e50 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 4 Mar 2024 17:36:17 +0100 Subject: [PATCH 42/65] update readme --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 21ba563475..6e6dbc3b0d 100644 --- a/readme.md +++ b/readme.md @@ -46,14 +46,14 @@ Just add the following to your maven configuration or tailor to your own depende com.github.javaparser javaparser-symbol-solver-core - 3.25.8 + 3.25.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.8' +implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.9' ``` Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver. @@ -68,14 +68,14 @@ Using the dependency above will add both JavaParser and JavaSymbolSolver to your com.github.javaparser javaparser-core - 3.25.8 + 3.25.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core:3.25.8' +implementation 'com.github.javaparser:javaparser-core:3.25.9' ``` Since version 3.6.17 the AST can be serialized to JSON. @@ -87,14 +87,14 @@ There is a separate module for this: com.github.javaparser javaparser-core-serialization - 3.25.8 + 3.25.9 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core-serialization:3.25.8' +implementation 'com.github.javaparser:javaparser-core-serialization:3.25.9' ``` ## How To Compile Sources From 6254c7538f14efe09176fc17e7e3dd7de3dfbb15 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 4 Mar 2024 17:38:11 +0100 Subject: [PATCH 43/65] [maven-release-plugin] prepare release javaparser-parent-3.25.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 | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 265c1ddd1e..4f3837abe2 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 9868f842a8..2e2dce7c88 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.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index f266d77118..db52bf70fd 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 8200456c45..19cc35fe7d 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.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index ef97bd20c2..e68b9d3252 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 94d02532e9..06d49dbdde 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 3d608b07da..2afad3604e 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.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index 1d89cb7b74..8c37ccea3f 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.25.9-SNAPSHOT + 3.25.9 4.0.0 diff --git a/pom.xml b/pom.xml index 397024df98..490be7a36a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.25.9-SNAPSHOT + 3.25.9 javaparser-parent https://github.com/javaparser @@ -149,7 +149,7 @@ 1.8 1.14.12 -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/${byte-buddy.version}/byte-buddy-agent-${byte-buddy.version}.jar - 2024-01-01T00:00:00Z + 2024-03-04T00:00:00Z From 430763bfd133a0ad6ff6924656dedf478cc9063b Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Mon, 4 Mar 2024 17:50:12 +0100 Subject: [PATCH 44/65] [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 4f3837abe2..259dd78e50 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 2e2dce7c88..93f9d6ba34 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.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index db52bf70fd..653863dab0 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 19cc35fe7d..f60a9f5f93 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.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index e68b9d3252..10b55d9ab6 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 06d49dbdde..581876d54a 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 2afad3604e..9eee6b0307 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.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index 8c37ccea3f..ed80a2d9cb 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.25.9 + 3.25.10-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 490be7a36a..341b402dec 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.25.9 + 3.25.10-SNAPSHOT javaparser-parent https://github.com/javaparser From 289b2d4c5d5480083dde05ce9ce8206d7bc30ce3 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Wed, 6 Mar 2024 08:46:18 +0100 Subject: [PATCH 45/65] fix: issue 4331 Cannot be 'abstract' and also 'private'. for a private method in an interface --- .../ast/body/MethodDeclarationTest.java | 23 +++++++++++---- .../ast/body/MethodDeclaration.java | 28 +++++++++---------- 2 files changed, 32 insertions(+), 19 deletions(-) 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 65ecd4214d..0dc9118e3d 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 @@ -125,25 +125,38 @@ void isFixedArityMethod() { assertTrue(method2.isFixedArityMethod()); } + /* + * A method in the body of an interface may be declared public or private + * (§6.6). If no access modifier is given, the method is implicitly public. + * https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.4 + */ @Test - void isInterfaceImplictlyPublic() { + void isMethodInterfaceImplictlyPublic() { CompilationUnit cu = parse("interface Foo { void m(); }"); assertTrue(cu.findFirst(MethodDeclaration.class).get().isPublic()); + cu = parse("interface Foo { public void m(); }"); + assertTrue(cu.findFirst(MethodDeclaration.class).get().isPublic()); cu = parse("interface Foo { abstract void m(); }"); assertTrue(cu.findFirst(MethodDeclaration.class).get().isPublic()); - cu = parse("interface Foo { protected void m(); }"); + cu = parse("interface Foo { private void m(); }"); assertFalse(cu.findFirst(MethodDeclaration.class).get().isPublic()); } + /* + * An interface method lacking a private, default, or static modifier is implicitly abstract. + * https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.4 + */ @Test - void isInterfaceImplictlyAbstract() { + void isMethodInterfaceImplictlyAbstract() { CompilationUnit cu = parse("interface Foo { void m(); }"); assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); cu = parse("interface Foo { abstract void m(); }"); assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); - cu = parse("interface Foo { protected void m(); }"); - assertTrue(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + cu = parse("interface Foo { private void m(); }"); + assertFalse(cu.findFirst(MethodDeclaration.class).get().isAbstract()); cu = parse("interface Foo { static void m(); }"); assertFalse(cu.findFirst(MethodDeclaration.class).get().isAbstract()); + cu = parse("interface Foo { default void m(){} }"); + assertFalse(cu.findFirst(MethodDeclaration.class).get().isAbstract()); } } 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 3a646f7986..f888fb0601 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 @@ -254,9 +254,11 @@ public String toDescriptor() { return sb.toString(); } - /* - * Interface methods are implicitly public - */ + /* + * A method in the body of an interface may be declared public or private + * (§6.6). If no access modifier is given, the method is implicitly public. + * https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.4 + */ @Override public boolean isPublic() { return hasModifier(PUBLIC) || isImplicitlyPublic(); @@ -270,22 +272,20 @@ && getParentNode().get() instanceof ClassOrInterfaceDeclaration } /* - * Every interface is implicitly abstract but - * only one of abstract, default, or static modifier is permitted - * https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.1.1 + * An interface method lacking a private, default, or static modifier is implicitly abstract. + * https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.4 */ @Override public boolean isAbstract() { - return hasModifier(Keyword.ABSTRACT) || (isImplicitlyAbstract() && Arrays - .asList(Keyword.STATIC, Keyword.DEFAULT).stream() - .noneMatch(modifier -> hasModifier(modifier))); + return super.isAbstract() || isImplicitlyAbstract(); } - private boolean isImplicitlyAbstract() { - return hasParentNode() - && getParentNode().get() instanceof ClassOrInterfaceDeclaration - && ((ClassOrInterfaceDeclaration)getParentNode().get()).isInterface(); - } + private boolean isImplicitlyAbstract() { + return hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration + && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface() + && Arrays.asList(Keyword.STATIC, Keyword.DEFAULT, Keyword.PRIVATE).stream() + .noneMatch(modifier -> hasModifier(modifier)); + } From ede8cc20ae664a2ab08ee77031beb8f8b3adf1d7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:24:10 +0000 Subject: [PATCH 46/65] chore(deps): update dependency org.apache.maven.plugins:maven-gpg-plugin to v3.2.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 341b402dec..8a7bb4abaa 100644 --- a/pom.xml +++ b/pom.xml @@ -212,7 +212,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.0 org.apache.maven.plugins @@ -494,7 +494,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.0 sign-artifacts From fc941778d60c47bcc22f09ade367c65d4a37d184 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:05:37 +0000 Subject: [PATCH 47/65] chore(deps): update dependency com.puppycrawl.tools:checkstyle to v10.14.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8a7bb4abaa..7bb37b79b0 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.puppycrawl.tools checkstyle - 10.14.0 + 10.14.1 From 549e63d9a08977f61fb83b6641432312c75d81a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:16:21 +0000 Subject: [PATCH 48/65] chore(deps): bump actions/checkout from 4.1.1 to 4.1.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2. - [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/v4.1.1...v4.1.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... 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 80ed0e35cf..4996c0dafe 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@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Create Release id: create_release diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 053589eb8a..b71b4dd9e0 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -44,7 +44,7 @@ jobs: steps: ## Checkout the current version of the code from the repo. - name: Checkout latest code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 with: fetch-depth: "0" @@ -108,7 +108,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout latest code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 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 8416ead59a..00dda94ee4 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@v4.1.1 + uses: actions/checkout@v4.1.2 # Setup Java 11 environment for the next steps - name: Setup Java From 20bfa02b79eeda7c2bd7198eaa368f787533a88c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:43:47 +0000 Subject: [PATCH 49/65] fix(deps): update dependency com.google.guava:guava to v33.1.0-jre --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7bb37b79b0..f6f7c76bf7 100644 --- a/pom.xml +++ b/pom.xml @@ -355,7 +355,7 @@ com.google.guava guava - 33.0.0-jre + 33.1.0-jre org.hamcrest From 0378f9098cb3011171e1e56d2ff79eb10d1848af Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 17 Mar 2024 00:54:17 +0000 Subject: [PATCH 50/65] chore(deps): update dependency com.puppycrawl.tools:checkstyle to v10.14.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6f7c76bf7..bd9186b631 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.puppycrawl.tools checkstyle - 10.14.1 + 10.14.2 From f9e9def0b4aaf5191ec4269c358eb0aa79551920 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:46:49 +0000 Subject: [PATCH 51/65] chore(deps): update dependency org.apache.maven.plugins:maven-gpg-plugin to v3.2.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bd9186b631..1a792e7a30 100644 --- a/pom.xml +++ b/pom.xml @@ -212,7 +212,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.0 + 3.2.1 org.apache.maven.plugins @@ -494,7 +494,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.0 + 3.2.1 sign-artifacts From f0ca78544fb5e15eeb68b549342aeedc7f514158 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:34:35 +0000 Subject: [PATCH 52/65] chore(deps): update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.13.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1a792e7a30..3bf3afcf7d 100644 --- a/pom.xml +++ b/pom.xml @@ -207,7 +207,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 org.apache.maven.plugins From b3c51ccbd030fbaac1c76ea69e2947c26a80c5a1 Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:18:40 +0100 Subject: [PATCH 53/65] Refactor ResolvedReferenceType#equals Fixes comparing against lazy types --- .../types/ResolvedReferenceType.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 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 0f297e26c5..d09d20c413 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 @@ -20,10 +20,6 @@ */ package com.github.javaparser.resolution.types; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -37,6 +33,10 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; import com.github.javaparser.utils.Pair; +import java.util.*; +import java.util.function.Function; +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. @@ -88,10 +88,20 @@ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, L public boolean equals(Object o) { if (this == o) return true; - if (o == null || (!isLazyType(o) && getClass() != o.getClass()) - || (isLazyType(o) && !this.equals(asResolvedReferenceType(o)))) + if (o == null) return false; - ResolvedReferenceType that = asResolvedReferenceType(o); + + if (o instanceof LazyType) { + final LazyType lazyType = (LazyType) o; + if (!lazyType.isReferenceType()) + return false; + return this.equals(lazyType.asReferenceType()); + } + + if (getClass() != o.getClass()) + return false; + + ResolvedReferenceType that = (ResolvedReferenceType) o; if (!typeDeclaration.equals(that.typeDeclaration)) return false; if (!typeParametersMap.equals(that.typeParametersMap)) @@ -99,17 +109,6 @@ public boolean equals(Object o) { 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() { int result = typeDeclaration.hashCode(); From 8bb7fd936bc058442e26f7083e8b9df0ae17bd96 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:28:26 +0000 Subject: [PATCH 54/65] chore(deps): update dependency org.apache.maven.plugins:maven-gpg-plugin to v3.2.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3bf3afcf7d..ad1f318da5 100644 --- a/pom.xml +++ b/pom.xml @@ -212,7 +212,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.1 + 3.2.2 org.apache.maven.plugins @@ -494,7 +494,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.1 + 3.2.2 sign-artifacts From e27e01b56d7398821c94ecb05d6caa0a928ad7ce Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:19:14 +0000 Subject: [PATCH 55/65] chore(deps): update codecov/codecov-action action to v4.1.1 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index b71b4dd9e0..9f19431c4c 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v4.1.0 + uses: codecov/codecov-action@v4.1.1 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v4.1.0 + uses: codecov/codecov-action@v4.1.1 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From 0cb12aa354e188a3d677e7ec65c458b4a968ea9e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:18:49 +0000 Subject: [PATCH 56/65] fix(deps): update byte-buddy.version to v1.14.13 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ad1f318da5..0769052508 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ UTF-8 1.8 - 1.14.12 + 1.14.13 -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/${byte-buddy.version}/byte-buddy-agent-${byte-buddy.version}.jar 2024-03-04T00:00:00Z From dabaf7a79df90b4e6691ff5bbd5951d6039e9317 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 04:58:50 +0000 Subject: [PATCH 57/65] chore(deps): update dependency com.puppycrawl.tools:checkstyle to v10.15.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0769052508..3ac2afe80f 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.puppycrawl.tools checkstyle - 10.14.2 + 10.15.0 From 37f42462dec876276ca3c7da672906825da77fd0 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 2 Apr 2024 16:13:04 +0200 Subject: [PATCH 58/65] Fix issue 4345 Strange error when trying to find erasure of generic type where one of two type parameters is an array --- .../types/ResolvedReferenceType.java | 21 ++------ .../model/typesystem/ReferenceTypeTest.java | 51 ++++++++++++++----- 2 files changed, 43 insertions(+), 29 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 d09d20c413..e8ffea9aef 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 @@ -20,6 +20,10 @@ */ package com.github.javaparser.resolution.types; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + import com.github.javaparser.ast.AccessSpecifier; import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; @@ -33,10 +37,6 @@ import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized; import com.github.javaparser.utils.Pair; -import java.util.*; -import java.util.function.Function; -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. @@ -575,18 +575,7 @@ public ResolvedType erasure() { } private List erasureOfParamaters(ResolvedTypeParametersMap typeParametersMap) { - List erasedParameters = new ArrayList(); - if (!typeParametersMap.isEmpty()) { - // add erased type except java.lang.object - List parameters = typeParametersMap.getTypes().stream() - .filter(type -> !type.isReferenceType()) - .map(type -> type.erasure()) - .filter(erasedType -> !(isJavaObject(erasedType))) - .filter(erasedType -> erasedType != null) - .collect(Collectors.toList()); - erasedParameters.addAll(parameters); - } - return erasedParameters; + return new ArrayList(); } private boolean isJavaObject(ResolvedType rt) { 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 3015521613..3041483ed0 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 @@ -21,10 +21,15 @@ package com.github.javaparser.symbolsolver.model.typesystem; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.jupiter.api.Assertions.*; +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.io.IOException; import java.io.Serializable; @@ -39,7 +44,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.github.javaparser.*; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseStart; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.resolution.TypeSolver; @@ -876,10 +884,28 @@ void erasure_rawtype() { assertEquals(expected, erasedType.describe()); } + @Test + // The erasure of a parameterized type with bound. + void erasure_type_variable() { + List types = declaredTypes( + "class A {}"); + ResolvedType rt = types.get(0); + String expected = "A"; + assertEquals(expected, rt.erasure().describe()); + } + + @Test + // The erasure of a parameterized type + void erasure_parametrizedType() { + ResolvedType parametrizedType = genericType(Map.class.getCanonicalName(), Integer.class.getCanonicalName(), Integer.class.getCanonicalName()); + String expected = "java.util.Map"; + assertEquals(expected, parametrizedType.erasure().describe()); + } + @Test // The erasure of an array type T[] is |T|[]. void erasure_arraytype() { - // create a type : List + // create a type : List [] ResolvedType genericList = array(genericType(List.class.getCanonicalName(), String.class.getCanonicalName())); String expected = "java.util.List[]"; assertEquals(expected, genericList.erasure().describe()); @@ -888,21 +914,20 @@ void erasure_arraytype() { @Test // The erasure of an array type T[] is |T|[]. void erasure_arraytype_with_bound() { - // create a type : List + // create a type : List [] ResolvedTypeVariable typeArguments = parametrizedType("T", Serializable.class.getCanonicalName()); ResolvedType genericList = array(genericType(List.class.getCanonicalName(), typeArguments)); - String expected = "java.util.List[]"; + String expected = "java.util.List[]"; assertEquals(expected, genericList.erasure().describe()); } @Test - // The erasure of a type variable (§4.4) is the erasure of its leftmost bound. - void erasure_type_variable() { - List types = declaredTypes( - "class A {}"); - ResolvedType rt = types.get(0); - String expected = "A"; - assertEquals(expected, rt.erasure().describe()); + // The erasure of T extends Serializable is the erasure of its leftmost bound. + void erasure_bounded_type_parameter() { + // create a type : T extends Serializable + ResolvedTypeVariable typeArguments = parametrizedType("T", Serializable.class.getCanonicalName()); + String expected = "java.io.Serializable"; + assertEquals(expected, typeArguments.erasure().describe()); } @Test From eed85f00848efa26404ef6e05c398dfeaa37b361 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Tue, 2 Apr 2024 16:22:46 +0200 Subject: [PATCH 59/65] Resolve compilation error on StringProvider --- .../symbolsolver/model/typesystem/ReferenceTypeTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 3041483ed0..4f784df539 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 @@ -45,7 +45,6 @@ import org.junit.jupiter.api.Test; import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseStart; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; @@ -819,7 +818,7 @@ void testDeclaredFields() { parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver)); CompilationUnit cu = new JavaParser(parserConfiguration) - .parse(ParseStart.COMPILATION_UNIT, new StringProvider(code)).getResult().get(); + .parse(code).getResult().get(); ClassOrInterfaceDeclaration classA = cu.getClassByName("A").get(); ClassOrInterfaceDeclaration classB = cu.getClassByName("B").get(); @@ -845,7 +844,7 @@ void testGetAllFieldsVisibleToInheritors() { parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver)); CompilationUnit cu = new JavaParser(parserConfiguration) - .parse(ParseStart.COMPILATION_UNIT, new StringProvider(code)).getResult().get(); + .parse(code).getResult().get(); ClassOrInterfaceDeclaration classA = cu.getClassByName("A").get(); ClassOrInterfaceDeclaration classB = cu.getClassByName("B").get(); From cab0b39d99602d405bd4fc024c3358468e0c0676 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:14:58 +0000 Subject: [PATCH 60/65] chore(deps): update dependency org.jacoco:jacoco-maven-plugin to v0.8.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3ac2afe80f..2493c055ad 100644 --- a/pom.xml +++ b/pom.xml @@ -260,7 +260,7 @@ org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.12 org.apache.maven.plugins From afc5c751e20fdbfdd94565b2e830ea0a4c88b98d Mon Sep 17 00:00:00 2001 From: Kosma Dunikowski Date: Sun, 31 Mar 2024 21:49:46 +0200 Subject: [PATCH 61/65] fix: issue 4358 prevent infinite cycles with static imports --- .../JavaParserTypeDeclarationAdapter.java | 3 +- .../symbolsolver/Issue4358Test.java | 38 +++++++++++++++++++ .../src/test/resources/issue4358/foo/A.java | 9 +++++ .../src/test/resources/issue4358/foo/B.java | 6 +++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4358Test.java create mode 100644 javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/A.java create mode 100644 javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/B.java 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 29f7498b40..3709b446e1 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 @@ -265,7 +265,8 @@ public SymbolReference solveMethod(String name, List< // If we haven't located any candidates that are declared on this type or its ancestors, consider the parent context. // This is relevant e.g. with nested classes. // Note that we want to avoid infinite recursion when a class is using its own method - see issue #75 - if (candidateMethods.isEmpty()) { + // We also want to avoid infinite recursion when handling static imports - see issue #4358 + if (candidateMethods.isEmpty() && !staticOnly) { SymbolReference parentSolution = context.getParent() .orElseThrow(() -> new RuntimeException("Parent context unexpectedly empty.")) .solveMethod(name, argumentsTypes, staticOnly); diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4358Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4358Test.java new file mode 100644 index 0000000000..c902f8a1ca --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4358Test.java @@ -0,0 +1,38 @@ +package com.github.javaparser.symbolsolver; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; +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 java.io.IOException; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; + +public class Issue4358Test extends AbstractSymbolResolutionTest { + @Test + public void testIssue4358() throws IOException { + Path issueResourcesPath = adaptPath("src/test/resources/issue4358"); + ReflectionTypeSolver rts = new ReflectionTypeSolver(); + JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath); + CombinedTypeSolver cts = new CombinedTypeSolver(); + cts.add(rts); + cts.add(jpts); + ParserConfiguration pc = new ParserConfiguration() + .setSymbolResolver(new JavaSymbolSolver(cts)); + StaticJavaParser.setConfiguration(pc); + CompilationUnit cu = StaticJavaParser.parse(issueResourcesPath.resolve("foo/A.java")); + + // There's only one method call in this compilation unit + ResolvedMethodDeclaration actual = cu.findAll(MethodCallExpr.class).stream() + .map(MethodCallExpr::resolve) + .findAny().get(); + + assertEquals("foo.B.d()", actual.getQualifiedSignature()); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/A.java b/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/A.java new file mode 100644 index 0000000000..dfeaf5ceff --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/A.java @@ -0,0 +1,9 @@ +package foo; + +import static foo.B.d; + +class A { + void c() { + d(); + } +} diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/B.java b/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/B.java new file mode 100644 index 0000000000..dbafa5726a --- /dev/null +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/B.java @@ -0,0 +1,6 @@ +package foo; + +class B extends A { + static void d() { + } +} From 6298cc2701a12361922cc59fde295bc534c02f51 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:12:26 +0000 Subject: [PATCH 62/65] chore(deps): update codecov/codecov-action action to v4.2.0 --- .github/workflows/maven_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 9f19431c4c..7d2497c8a0 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -83,7 +83,7 @@ jobs: - name: CodeCov - JavaParser Core - uses: codecov/codecov-action@v4.1.1 + uses: codecov/codecov-action@v4.2.0 timeout-minutes: 10 with: files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml @@ -93,7 +93,7 @@ jobs: env_vars: OS,JDK - name: CodeCov - JavaParser Symbol Solver - uses: codecov/codecov-action@v4.1.1 + uses: codecov/codecov-action@v4.2.0 timeout-minutes: 10 with: file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml From 0edfe126396a87a602122fd9545c9318e708aa11 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 4 Apr 2024 10:33:27 +0200 Subject: [PATCH 63/65] Update changelog --- changelog.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 8bb167f264..951ede2a62 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,7 @@ - -Next Release (Version 3.25.10-snapshot) +Next Release (Version 3.25.11-snapshot) -------------------------------------- -[issues resolved](https://github.com/javaparser/javaparser/milestone/206?closed=1) +[issues resolved](https://github.com/javaparser/javaparser/milestone/207?closed=1) ### Added ### Changed @@ -11,6 +10,32 @@ Next Release (Version 3.25.10-snapshot) ### Fixed ### Security + +Version 3.25.10 +--------------- +[issues resolved](https://github.com/javaparser/javaparser/milestone/206?closed=1) + +### Fixed + +* Fix issue 4345 Strange error when trying to find erasure of generic t… (PR [#4362](https://github.com/javaparser/javaparser/pull/4362) by [@jlerbsc](https://github.com/jlerbsc)) +* fix: issue 4358 prevent infinite cycles with static imports (PR [#4359](https://github.com/javaparser/javaparser/pull/4359) by [@kdunee](https://github.com/kdunee)) +* Refactor `ResolvedReferenceType#equals` (PR [#4351](https://github.com/javaparser/javaparser/pull/4351) by [@freya022](https://github.com/freya022)) +* fix: issue 4331 Cannot be 'abstract' and also 'private'. for a private method in an interface (PR [#4332](https://github.com/javaparser/javaparser/pull/4332) by [@jlerbsc](https://github.com/jlerbsc)) + +### Developer Changes + +* chore(deps): bump actions/checkout from 4.1.1 to 4.1.2 (PR [#4341](https://github.com/javaparser/javaparser/pull/4341) by [@dependabot[bot]](https://github.com/apps/dependabot)) + +### :heart: Contributors + +Thank You to all contributors who worked on this release! + +* [@kdunee](https://github.com/kdunee) +* [@freya022](https://github.com/freya022) +* [@jlerbsc](https://github.com/jlerbsc) + + + Version 3.25.9 -------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/205?closed=1) From d12205565470ac78240ec7ebf26cf8cbcbdc514a Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 4 Apr 2024 10:34:31 +0200 Subject: [PATCH 64/65] update readme --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 6e6dbc3b0d..87494d52f2 100644 --- a/readme.md +++ b/readme.md @@ -46,14 +46,14 @@ Just add the following to your maven configuration or tailor to your own depende com.github.javaparser javaparser-symbol-solver-core - 3.25.9 + 3.25.10 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.9' +implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.10' ``` Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver. @@ -68,14 +68,14 @@ Using the dependency above will add both JavaParser and JavaSymbolSolver to your com.github.javaparser javaparser-core - 3.25.9 + 3.25.10 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core:3.25.9' +implementation 'com.github.javaparser:javaparser-core:3.25.10' ``` Since version 3.6.17 the AST can be serialized to JSON. @@ -87,14 +87,14 @@ There is a separate module for this: com.github.javaparser javaparser-core-serialization - 3.25.9 + 3.25.10 ``` **Gradle**: ``` -implementation 'com.github.javaparser:javaparser-core-serialization:3.25.9' +implementation 'com.github.javaparser:javaparser-core-serialization:3.25.10' ``` ## How To Compile Sources From 3492371f90e3e66ef0aff0b1108880cdddc7aba2 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 4 Apr 2024 10:36:08 +0200 Subject: [PATCH 65/65] [maven-release-plugin] prepare release javaparser-parent-3.25.10 --- 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 | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 259dd78e50..6b42363da6 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index 93f9d6ba34..9d61e52039 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.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 653863dab0..6f64d24037 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index f60a9f5f93..7cae9d46af 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.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index 10b55d9ab6..c3fb0c8125 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 581876d54a..bb23581398 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 9eee6b0307..1907229187 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.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index ed80a2d9cb..68ab97755e 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.25.10-SNAPSHOT + 3.25.10 4.0.0 diff --git a/pom.xml b/pom.xml index 2493c055ad..61ab6e8b19 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.25.10-SNAPSHOT + 3.25.10 javaparser-parent https://github.com/javaparser @@ -149,7 +149,7 @@ 1.8 1.14.13 -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/${byte-buddy.version}/byte-buddy-agent-${byte-buddy.version}.jar - 2024-03-04T00:00:00Z + 2024-04-04T00:00:00Z