Menu

FieldDeclarationsShouldBeAtStartOfClass - Configurable?

Developers
blundell
2014-07-04
2014-08-19
  • blundell

    blundell - 2014-07-04
    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.

    Is there any configurable fields for FieldDeclarationsShouldBeAtStartOfClass to allow the above to be valid? Or do I have a case to put this forward as a feature?

     
  • blundell

    blundell - 2014-08-12

    Any feedback?

     
  • Andreas Dangel

    Andreas Dangel - 2014-08-12

    I can see your point. We could add a flag to ignore field declarations, that instantiate an anonymous class, like in your example. Would this work?
    Other options, that come into mind are: suppressing (e.g. via @SuppressWarnings).

     
  • Andreas Dangel

    Andreas Dangel - 2014-08-19

    I've implemented it as feature [#1244].

     

    Related

    Issues: #1244


Log in to post a comment.

MongoDB Logo MongoDB