Skip to content

Commit 4cf643c

Browse files
committed
[#1197] fix static via this rule
1 parent 2d2dfef commit 4cf643c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
182182
//PrimaryExpression[
183183
(./PrimaryPrefix[@ThisModifier=true()]) and
184184
(./PrimarySuffix[
185-
@Image=//FieldDeclaration[@Static=true()]/VariableDeclarator/VariableDeclaratorId/@Name
186-
or @Image=//MethodDeclaration[@Static=true()]/@MethodName
185+
@Image=./ancestor::ClassOrInterfaceBody[1]/ClassOrInterfaceBodyDeclaration/FieldDeclaration[@Static=true()]/VariableDeclarator/VariableDeclaratorId/@Name
186+
or @Image=./ancestor::ClassOrInterfaceBody[1]/ClassOrInterfaceBodyDeclaration/MethodDeclaration[@Static=true()]/@MethodName
187187
])
188188
]
189189
]]></value>

qulice-pmd/src/test/resources/com/qulice/pmd/StaticAccessToStaticFields.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ public int another() {
1212
}
1313

1414
public int addToNum(final int another) {
15-
return another + StaticAccessToStaticFields.number();
15+
return another + StaticAccessToStaticFields.number() + this.another();
16+
}
17+
18+
class InternalClass {
19+
final int num;
20+
21+
InternalClass(final int par) {
22+
this.num = par;
23+
}
24+
static int another() {
25+
return 1;
26+
}
27+
28+
public int add(final int a) {
29+
return a + this.num;
30+
}
1631
}
1732
}

0 commit comments

Comments
 (0)