com.puppycrawl.tools.checkstyle.checks.design

Class VisibilityModifierCheck

Implemented Interfaces:
Configurable, Contextualizable

public class VisibilityModifierCheck
extends 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.

Author:
lkuehne

Constructor Summary

VisibilityModifierCheck()
Create an instance.

Method Summary

int[]
getDefaultTokens()
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(String aPattern)
Set the pattern for public members to ignore.
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

VisibilityModifierCheck

public VisibilityModifierCheck()
Create an instance.

Method Details

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

See Also:
Check


isPackageAllowed

public boolean isPackageAllowed()

Returns:
whether package visible members are allowed


isProtectedAllowed

public boolean isProtectedAllowed()

Returns:
whether protected members are allowed


setPackageAllowed

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

Parameters:
aPackageAllowed - whether package visible members are allowed


setProtectedAllowed

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

Parameters:
aProtectedAllowed - whether protected members are allowed


setPublicMemberPattern

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

Parameters:
aPattern - pattern for public members to ignore.


visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check

See Also:
Check