Modifier Checks

Checkstyle Logo

ModifierOrder

Description

Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. static
  6. final
  7. transient
  8. volatile
  9. synchronized
  10. native
  11. strictfp

Example

To configure the check:

<module name="ModifierOrder"/>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

RedundantModifier

Checks that method declarations in interfaces include neither the public modifier nor the abstract modifier (see the Java Language specification, section 9.4).

Also checks that variable declarations in interfaces include none of the following modifiers: public, static, final (variables in interface definitions are constants and have these modifiers implicitly, see the Java Language specification, section 9.3).

Properties

name description type default value
tokens tokens to check subset of tokens METHOD_DEF, VARIABLE_DEF METHOD_DEF, VARIABLE_DEF

Example

To configure the check:

<module name="RedundantModifier"/>
      

To configure the check to check only methods and not variables:

<module name="RedundantModifier">
  <property name="tokens" value="METHOD_DEF"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

VisibilityModifier

Checks visibility of class members. Only static final members may be public; other class members must be private unless property protectedAllowed or packageAllowed is set.

Public members are not flagged if the name matches the public member regular expression (contains "^serialVersionUID$" by default). Note: Checkstyle 2 used to include "^f[A-Z][a-zA-Z0-9]*$" in the default pattern to allow CMP for EJB 1.1 with the default settings. With EJB 2.0 it is not longer necessary to have public access for persistent fields, hence the default has been changed.

Rationale: Enforce encapsulation.

Properties

name description type default value
packageAllowed whether package visible members are allowed boolean false
protectedAllowed whether protected members are allowed boolean false
publicMemberPattern pattern for public members that should be ignored regular expression ^serialVersionUID$

Examples

To configure the check:

<module name="VisibilityModifier"/>
      

To configure the check so that it allows package visible members:

<module name="VisibilityModifier">
    <property name="packageAllowed" value="true"/>
</module>
      

To configure the check so that it allows no public members:

<module name="VisibilityModifier">
    <property name="publicMemberPattern" value="^$"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker


Copyright © 2002 Oliver Burn. All rights Reserved.