resources.report.rules.pmd.UselessQualifiedThis.html Maven / Gradle / Ivy
UselessQualifiedThis
UselessQualifiedThis
Look for qualified this usages in the same class.
//PrimaryExpression
[PrimaryPrefix/Name[@Image]]
[PrimarySuffix[@Arguments='false']]
[not(PrimarySuffix/MemberSelector)]
[ancestor::ClassOrInterfaceBodyDeclaration[1][@AnonymousInnerClass='false']]
/PrimaryPrefix/Name[@Image = ancestor::ClassOrInterfaceDeclaration[1]/@Image]
Example(s):
public class Foo {
final Foo otherFoo = Foo.this; // use "this" directly
public void doSomething() {
final Foo anotherFoo = Foo.this; // use "this" directly
}
private ActionListener returnListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doSomethingWithQualifiedThis(Foo.this); // This is fine
}
};
}
private class Foo3 {
final Foo myFoo = Foo.this; // This is fine
}
private class Foo2 {
final Foo2 myFoo2 = Foo2.this; // Use "this" direclty
}
}