See https://sourceforge.net/p/pmd/discussion/188194/thread/ccd89d18/
public class MyClass {
private final String name;
public MyClass() {
this.name = "whatever";
}
public void onCreate() {
someView.setListener(onSomeViewClick);
}
private final OnClickListener onSomeViewClick = new OnClickListener() {
@Override
public void onClick(View v) {
// something
}
};
}
In the above example PMD - FieldDeclarationsShouldBeAtStartOfClass will say that onSomeViewClick needs to be declared at the top of the class above the constructor etc.
However for readability purposes it is much better place below where the variable is used and treated like a method block.
This will be implemented with the next PMD release (5.1.3).
There will be a new rule property ignoreAnonymousClassDeclarations for FieldDeclarationsShouldBeAtStartOfClass, which is by default "true" and means, that such anonymous classes will be ignored by default.
Last edit: Andreas Dangel 2014-08-18