Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.puppycrawl.tools.checkstyle.checks.design
Class VisibilityModifierCheck  view VisibilityModifierCheck download VisibilityModifierCheck.java

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended bycom.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended bycom.puppycrawl.tools.checkstyle.api.Check
              extended bycom.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck
All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

public class VisibilityModifierCheck
extends com.puppycrawl.tools.checkstyle.api.Check

Checks visibility of class members. Only static final members may be public, other class members must be private unless allowProtected/Package is set.

Public members are not flagged if the name matches the public member regular expression (contains "^serialVersionUID$" by default).

Rationale: Enforce encapsulation.


Field Summary
private  boolean mPackageAllowed
          whether package visible members are allowed
private  boolean mProtectedAllowed
          whether protected members are allowed
private  java.lang.String mPublicMemberPattern
          pattern for public members that should be ignored.
private  org.apache.regexp.RE mPublicMemberRE
          regexp for public members that should be ignored
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
 
Constructor Summary
VisibilityModifierCheck()
          Create an instance.
 
Method Summary
 int[] getDefaultTokens()
          Returns the default token a check is interested in.
private  java.util.Set getModifiers(com.puppycrawl.tools.checkstyle.api.DetailAST aVariableDefAST)
          Returns the set of modifier Strings for a VARIABLE_DEF AST.
private  org.apache.regexp.RE getPublicMemberRegexp()
           
private  com.puppycrawl.tools.checkstyle.api.DetailAST getVarNameAST(com.puppycrawl.tools.checkstyle.api.DetailAST aVariableDefAST)
          Returns the variable name in a VARIABLE_DEF AST.
private  java.lang.String getVisibilityScope(java.util.Set aModifiers)
          Returns the visibility scope specified with a set of modifiers.
private  boolean inInterfaceBlock(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
          Returns whether an AST is in an interface block.
 boolean isPackageAllowed()
           
 boolean isProtectedAllowed()
           
 void setPackageAllowed(boolean aPackageAllowed)
          Set whether package visible members are allowed.
 void setProtectedAllowed(boolean aProtectedAllowed)
          Set whether protected members are allowed.
 void setPublicMemberPattern(java.lang.String aPattern)
          Set the pattern for public members to ignore.
 void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
          Called to process a token.
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, setSeverity
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mProtectedAllowed

private boolean mProtectedAllowed
whether protected members are allowed


mPackageAllowed

private boolean mPackageAllowed
whether package visible members are allowed


mPublicMemberPattern

private java.lang.String mPublicMemberPattern
pattern for public members that should be ignored. Note: Earlier versions of checkstyle used ^f[A-Z][a-zA-Z0-9]*$ as the default 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.


mPublicMemberRE

private org.apache.regexp.RE mPublicMemberRE
regexp for public members that should be ignored

Constructor Detail

VisibilityModifierCheck

public VisibilityModifierCheck()
Create an instance.

Method Detail

isProtectedAllowed

public boolean isProtectedAllowed()

setProtectedAllowed

public void setProtectedAllowed(boolean aProtectedAllowed)
Set whether protected members are allowed.


isPackageAllowed

public boolean isPackageAllowed()

setPackageAllowed

public void setPackageAllowed(boolean aPackageAllowed)
Set whether package visible members are allowed.


setPublicMemberPattern

public void setPublicMemberPattern(java.lang.String aPattern)
Set the pattern for public members to ignore.


getPublicMemberRegexp

private org.apache.regexp.RE getPublicMemberRegexp()

getDefaultTokens

public int[] getDefaultTokens()
Description copied from class: com.puppycrawl.tools.checkstyle.api.Check
Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.


visitToken

public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Description copied from class: com.puppycrawl.tools.checkstyle.api.Check
Called to process a token.


getVarNameAST

private com.puppycrawl.tools.checkstyle.api.DetailAST getVarNameAST(com.puppycrawl.tools.checkstyle.api.DetailAST aVariableDefAST)
Returns the variable name in a VARIABLE_DEF AST.


inInterfaceBlock

private boolean inInterfaceBlock(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Returns whether an AST is in an interface block.


getModifiers

private java.util.Set getModifiers(com.puppycrawl.tools.checkstyle.api.DetailAST aVariableDefAST)
Returns the set of modifier Strings for a VARIABLE_DEF AST.


getVisibilityScope

private java.lang.String getVisibilityScope(java.util.Set aModifiers)
Returns the visibility scope specified with a set of modifiers.