Menu

#1244 FieldDeclarationsShouldBeAtStartOfClass and anonymous classes

PMD-5.1.3
closed
None
PMD
3-Major
Feature-Request
2014-11-04
2014-08-15
No

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.

Related

Discussion: FieldDeclarationsShouldBeAtStartOfClass - Configurable?

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-08-15
    • assigned_to: Andreas Dangel
    • Type: Bug --> Feature-Request
     
  • Andreas Dangel

    Andreas Dangel - 2014-08-18

    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
  • Andreas Dangel

    Andreas Dangel - 2014-08-18
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.