Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1197] fix AvoidAccessToStaticMembersViaThis rule #1229

Merged
merged 3 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml
Expand Up @@ -153,9 +153,10 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//Name[@Image = //FieldDeclaration[@Static='true']/@VariableName]
//Name[@Image = //FieldDeclaration[@Static=true()]/VariableDeclarator/VariableDeclaratorId/@Name]
]]></value>
</property>
</properties>
Expand All @@ -175,13 +176,14 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//PrimaryExpression[
(./PrimaryPrefix[@ThisModifier='true']) and
(./PrimaryPrefix[@ThisModifier=true()]) and
(./PrimarySuffix[
@Image=//FieldDeclaration[@Static='true']/@VariableName
or @Image=//MethodDeclaration[@Static='true']/@MethodName
@Image=./ancestor::ClassOrInterfaceBody[1]/ClassOrInterfaceBodyDeclaration/FieldDeclaration[@Static=true()]/VariableDeclarator/VariableDeclaratorId/@Name
or @Image=./ancestor::ClassOrInterfaceBody[1]/ClassOrInterfaceBodyDeclaration/MethodDeclaration[@Static=true()]/@Name
])
]
]]></value>
Expand Down
Expand Up @@ -12,6 +12,21 @@ public int another() {
}

public int addToNum(final int another) {
return another + StaticAccessToStaticFields.number();
return another + StaticAccessToStaticFields.number() + this.another();
}

class InternalClass {
final int num;

InternalClass(final int par) {
this.num = par;
}
static int another() {
return 1;
}

public int add(final int a) {
return a + this.num;
}
}
}