From 28c5cd71146e68518e9f48fb91462659d1b6ae7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sun, 28 Apr 2024 12:18:36 -0300 Subject: [PATCH] Remove `@Names` attribute from ASTReferenceExpression --- .../lang/apex/ast/ASTReferenceExpression.java | 3 +++ .../pmd/lang/apex/ast/InnerClassLocations.txt | 8 +++--- .../lang/apex/ast/SafeNavigationOperator.txt | 26 +++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java index dbf9e887ec..22378be985 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.apex.ast; import java.util.List; import java.util.stream.Collectors; +import net.sourceforge.pmd.lang.rule.xpath.NoAttribute; + import com.google.summit.ast.Identifier; public final class ASTReferenceExpression extends AbstractApexNode.Many { @@ -38,6 +40,7 @@ public final class ASTReferenceExpression extends AbstractApexNode.Many getNames() { return nodes.stream().map(Identifier::getString).collect(Collectors.toList()); } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/InnerClassLocations.txt b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/InnerClassLocations.txt index 095e8b8803..4f71b48450 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/InnerClassLocations.txt +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/InnerClassLocations.txt @@ -8,11 +8,11 @@ | +- BlockStatement[@CurlyBrace = true, @DefiningType = "InnerClassLocations.bar1", @RealLoc = true] | +- ExpressionStatement[@DefiningType = "InnerClassLocations.bar1", @RealLoc = true] | | +- MethodCallExpression[@DefiningType = "InnerClassLocations.bar1", @FullMethodName = "System.out.println", @InputParametersSize = 1, @MethodName = "println", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar1", @Image = "System", @Names = ("System", "out"), @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + | | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar1", @Image = "System", @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] | | +- LiteralExpression[@Boolean = false, @Decimal = false, @DefiningType = "InnerClassLocations.bar1", @Double = false, @Image = "foo", @Integer = false, @LiteralType = LiteralType.STRING, @Long = false, @Name = null, @Null = false, @RealLoc = true, @String = true] | +- ExpressionStatement[@DefiningType = "InnerClassLocations.bar1", @RealLoc = true] | +- MethodCallExpression[@DefiningType = "InnerClassLocations.bar1", @FullMethodName = "System.out.println", @InputParametersSize = 1, @MethodName = "println", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar1", @Image = "System", @Names = ("System", "out"), @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar1", @Image = "System", @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] | +- LiteralExpression[@Boolean = false, @Decimal = false, @DefiningType = "InnerClassLocations.bar1", @Double = false, @Image = "foo", @Integer = false, @LiteralType = LiteralType.STRING, @Long = false, @Name = null, @Null = false, @RealLoc = true, @String = true] +- UserClass[@DefiningType = "InnerClassLocations.bar2", @Image = "bar2", @InterfaceNames = (), @RealLoc = true, @SimpleName = "bar2", @SuperClassName = ""] +- ModifierNode[@Abstract = false, @DefiningType = "InnerClassLocations.bar2", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 1, @Override = false, @Private = false, @Protected = false, @Public = true, @RealLoc = true, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false] @@ -21,9 +21,9 @@ +- BlockStatement[@CurlyBrace = true, @DefiningType = "InnerClassLocations.bar2", @RealLoc = true] +- ExpressionStatement[@DefiningType = "InnerClassLocations.bar2", @RealLoc = true] | +- MethodCallExpression[@DefiningType = "InnerClassLocations.bar2", @FullMethodName = "System.out.println", @InputParametersSize = 1, @MethodName = "println", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar2", @Image = "System", @Names = ("System", "out"), @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + | +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar2", @Image = "System", @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] | +- LiteralExpression[@Boolean = false, @Decimal = false, @DefiningType = "InnerClassLocations.bar2", @Double = false, @Image = "foo", @Integer = false, @LiteralType = LiteralType.STRING, @Long = false, @Name = null, @Null = false, @RealLoc = true, @String = true] +- ExpressionStatement[@DefiningType = "InnerClassLocations.bar2", @RealLoc = true] +- MethodCallExpression[@DefiningType = "InnerClassLocations.bar2", @FullMethodName = "System.out.println", @InputParametersSize = 1, @MethodName = "println", @RealLoc = true] - +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar2", @Image = "System", @Names = ("System", "out"), @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + +- ReferenceExpression[@DefiningType = "InnerClassLocations.bar2", @Image = "System", @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] +- LiteralExpression[@Boolean = false, @Decimal = false, @DefiningType = "InnerClassLocations.bar2", @Double = false, @Image = "foo", @Integer = false, @LiteralType = LiteralType.STRING, @Long = false, @Name = null, @Null = false, @RealLoc = true, @String = true] diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/SafeNavigationOperator.txt b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/SafeNavigationOperator.txt index 226b07f37a..d044128082 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/SafeNavigationOperator.txt +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/SafeNavigationOperator.txt @@ -9,7 +9,7 @@ | +- ModifierNode[@Abstract = false, @DefiningType = "Foo", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 0, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = false, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false] | +- FieldDeclaration[@DefiningType = "Foo", @Image = "x", @Name = "x", @RealLoc = true] | +- VariableExpression[@DefiningType = "Foo", @Image = "anIntegerField", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "anObject", @RealLoc = true] | | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] | +- VariableExpression[@DefiningType = "Foo", @Image = "x", @RealLoc = true] @@ -18,9 +18,9 @@ | +- ModifierNode[@Abstract = false, @DefiningType = "Foo", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 0, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = false, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false] | +- FieldDeclaration[@DefiningType = "Foo", @Image = "profileUrl", @Name = "profileUrl", @RealLoc = true] | +- MethodCallExpression[@DefiningType = "Foo", @FullMethodName = "toExternalForm", @InputParametersSize = 0, @MethodName = "toExternalForm", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] | | +- MethodCallExpression[@DefiningType = "Foo", @FullMethodName = "user.getProfileUrl", @InputParametersSize = 0, @MethodName = "getProfileUrl", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "user", @Names = ("user"), @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "user", @RealLoc = true, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] | +- VariableExpression[@DefiningType = "Foo", @Image = "profileUrl", @RealLoc = true] | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] +- Method[@Arity = 1, @CanonicalName = "bar1", @Constructor = false, @DefiningType = "Foo", @Image = "bar1", @RealLoc = true, @ReturnType = "void", @StaticInitializer = false] @@ -30,15 +30,15 @@ | +- BlockStatement[@CurlyBrace = true, @DefiningType = "Foo", @RealLoc = true] | +- ExpressionStatement[@DefiningType = "Foo", @RealLoc = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "b", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "a", @RealLoc = true] | | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] | +- ExpressionStatement[@DefiningType = "Foo", @RealLoc = true] | +- MethodCallExpression[@DefiningType = "Foo", @FullMethodName = "c1", @InputParametersSize = 0, @MethodName = "c1", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] + | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] | +- CastExpression[@DefiningType = "Foo", @RealLoc = true] | +- VariableExpression[@DefiningType = "Foo", @Image = "b1", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] | +- VariableExpression[@DefiningType = "Foo", @Image = "a1", @RealLoc = true] | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] +- Method[@Arity = 2, @CanonicalName = "bar2", @Constructor = false, @DefiningType = "Foo", @Image = "bar2", @RealLoc = true, @ReturnType = "void", @StaticInitializer = false] @@ -50,9 +50,9 @@ | +- BlockStatement[@CurlyBrace = true, @DefiningType = "Foo", @RealLoc = true] | +- ExpressionStatement[@DefiningType = "Foo", @RealLoc = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "aField", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = false] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = false] | | +- MethodCallExpression[@DefiningType = "Foo", @FullMethodName = "aMethod", @InputParametersSize = 0, @MethodName = "aMethod", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = true] | | +- ArrayLoadExpression[@DefiningType = "Foo", @RealLoc = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "a", @RealLoc = true] | | | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] @@ -60,9 +60,9 @@ | | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] | +- ExpressionStatement[@DefiningType = "Foo", @RealLoc = true] | +- VariableExpression[@DefiningType = "Foo", @Image = "aField", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] | +- MethodCallExpression[@DefiningType = "Foo", @FullMethodName = "aMethod", @InputParametersSize = 0, @MethodName = "aMethod", @RealLoc = true] - | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] + | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.METHOD, @SObjectType = false, @SafeNav = false] | +- ArrayLoadExpression[@DefiningType = "Foo", @RealLoc = true] | +- VariableExpression[@DefiningType = "Foo", @Image = "a", @RealLoc = true] | | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] @@ -77,14 +77,14 @@ | +- ModifierNode[@Abstract = false, @DefiningType = "Foo", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 0, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = false, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false] | +- VariableDeclaration[@DefiningType = "Foo", @Image = "s", @RealLoc = true, @Type = "String"] | +- VariableExpression[@DefiningType = "Foo", @Image = "BillingCity", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] | | +- VariableExpression[@DefiningType = "Foo", @Image = "Account", @RealLoc = true] - | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "contact", @Names = ("contact"), @RealLoc = true, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = false] + | | +- ReferenceExpression[@DefiningType = "Foo", @Image = "contact", @RealLoc = true, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = false] | +- VariableExpression[@DefiningType = "Foo", @Image = "s", @RealLoc = true] | +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false] +- ReturnStatement[@DefiningType = "Foo", @RealLoc = true] +- VariableExpression[@DefiningType = "Foo", @Image = "Name", @RealLoc = true] - +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @Names = (), @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] + +- ReferenceExpression[@DefiningType = "Foo", @Image = "", @RealLoc = false, @ReferenceType = ReferenceType.LOAD, @SObjectType = false, @SafeNav = true] +- SoqlExpression[@CanonicalQuery = "SELECT Name FROM Account WHERE Id = :tmpVar1", @DefiningType = "Foo", @Query = "SELECT Name FROM Account WHERE Id = :accId", @RealLoc = true] +- BindExpressions[@DefiningType = "Foo", @RealLoc = true] +- VariableExpression[@DefiningType = "Foo", @Image = "accId", @RealLoc = true]