diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index da5e3ff13b..1a3ab6dc48 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -22,6 +22,7 @@ This is a {{ site.pmd.release_type }} release. * java * [#4912](https://github.com/pmd/pmd/issues/4912): \[java] Unable to parse some Java9+ resource references * [#4973](https://github.com/pmd/pmd/pull/4973): \[java] Stop parsing Java for CPD + * [#4988](https://github.com/pmd/pmd/pull/4988): \[java] Fix impl of ASTVariableId::isResourceDeclaration / VariableId/@ResourceDeclaration * java-bestpractices * [#4278](https://github.com/pmd/pmd/issues/4278): \[java] UnusedPrivateMethod FP with Junit 5 @MethodSource and default factory method name * [#4852](https://github.com/pmd/pmd/issues/4852): \[java] ReplaceVectorWithList false-positive (neither Vector nor List usage) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java index e21de7a2b5..88f97fecfe 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java @@ -232,7 +232,8 @@ public final class ASTVariableId extends AbstractTypedSymbolDeclarator { - variableId("a") + variableId("a") { + it::isResourceDeclaration shouldBe true + } int(2) } } @@ -57,7 +59,9 @@ class ASTTryStatementTest : ParserTestSpec({ } classType("Foo") fromChild { - variableId("a") + variableId("a") { + it::isResourceDeclaration shouldBe true + } int(2) } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt index 1d588cc7f3..cfe179b90a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt @@ -408,7 +408,7 @@ | | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{}"] | | | +- ClassType[@FullyQualified = false, @SimpleName = "BufferedReader"] | | | +- VariableDeclarator[@Initializer = true, @Name = "br"] - | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "br", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] + | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "br", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = true, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | | | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] | | | +- ClassType[@FullyQualified = false, @SimpleName = "BufferedReader"] | | | +- ArgumentList[@Empty = false, @Size = 1] @@ -464,7 +464,7 @@ | | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{}"] | | | +- ClassType[@FullyQualified = true, @SimpleName = "ZipFile"] | | | +- VariableDeclarator[@Initializer = true, @Name = "zf"] - | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "zf", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] + | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "zf", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = true, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | | | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] | | | +- ClassType[@FullyQualified = true, @SimpleName = "ZipFile"] | | | +- ArgumentList[@Empty = false, @Size = 1] @@ -474,7 +474,7 @@ | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{}"] | | +- ClassType[@FullyQualified = true, @SimpleName = "BufferedWriter"] | | +- VariableDeclarator[@Initializer = true, @Name = "writer"] - | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "writer", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] + | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "writer", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = true, @Static = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | | +- MethodCall[@CompileTimeConstant = false, @Image = "newBufferedWriter", @MethodName = "newBufferedWriter", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = true, @SimpleName = "Files"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21p/Jep443_UnnamedPatternsAndVariables.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21p/Jep443_UnnamedPatternsAndVariables.txt index 93734fdee0..43649b068b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21p/Jep443_UnnamedPatternsAndVariables.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21p/Jep443_UnnamedPatternsAndVariables.txt @@ -523,7 +523,7 @@ | | +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = true, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{}"] | | +- VariableDeclarator[@Initializer = true, @Name = "_"] - | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "_", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] + | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "_", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = true, @Static = false, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] | | +- MethodCall[@CompileTimeConstant = false, @Image = "acquire", @MethodName = "acquire", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @SimpleName = "ScopedContext"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt index c9f4bbc107..087e015c7d 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt @@ -523,7 +523,7 @@ | | +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = true, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{}"] | | +- VariableDeclarator[@Initializer = true, @Name = "_"] - | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "_", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] + | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "_", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = true, @Static = false, @TypeInferred = true, @Visibility = Visibility.V_LOCAL] | | +- MethodCall[@CompileTimeConstant = false, @Image = "acquire", @MethodName = "acquire", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @SimpleName = "ScopedContext"]