Class HiddenFieldCheck
- All Implemented Interfaces:
- Configurable,- Contextualizable
Notes: It is possible to configure the check to ignore all property setter methods.
A method is recognized as a setter if it is in the following form
 ${returnType} set${Name}(${anyType} ${name}) { ... }
 where ${anyType} is any primitive type, class or interface name; ${name} is name of the variable that is being set and ${Name} its capitalized form that appears in the method name. By default, it is expected that setter returns void, i.e. ${returnType} is 'void'. For example
 void setTime(long time) { ... }
 Any other return types will not let method match a setter pattern. However, by setting setterCanReturnItsClass property to true definition of a setter is expanded, so that setter return type can also be a class in which setter is declared. For example
 class PageBuilder {
   PageBuilder setName(String name) { ... }
 }
 Such methods are known as chain-setters and a common when Builder-pattern is used. Property setterCanReturnItsClass has effect only if ignoreSetter is set to true.
- Since:
- 3.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprivate static final classHolds the names of static and instance fields of a type.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate HiddenFieldCheck.FieldFrameStack of sets of field names, one for each class of a set of nested classes.private booleanControl whether to ignore parameters of abstract methods.private booleanControl whether to ignore constructor parameters.private PatternDefine the RegExp for names of variables and parameters to ignore.private booleanAllow to ignore the parameter of a property setter method.static final StringA key is pointing to the warning message text in "messages.properties" file.private booleanAllow to expand the definition of a setter method to include methods that return the class' instance.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidCalled before the starting to process a tree.private static Stringcapitalize(String name) Capitalizes a given property name the way we expect to see it in a setter name.int[]The configurable token set.int[]Returns the default token a check is interested in.int[]The tokens that this check must be registered for.private booleanDecides whether to ignore an AST node that is the parameter of a constructor.private booleanisIgnoredParam(DetailAST ast, String name) Checks whether method or constructor parameter is ignored.private booleanDecides whether to ignore an AST node that is the parameter of an abstract method.private booleanisIgnoredSetterParam(DetailAST ast, String name) Decides whether to ignore an AST node that is the parameter of a setter method, where the property setter method for field 'xyz' has name 'setXyz', one parameter named 'xyz', and return type void (default behavior) or return type is name of the class in which such method is declared (allowed only ifsetSetterCanReturnItsClass(boolean)is called with value true).private booleanisInstanceField(DetailAST ast, String name) Check for instance field.private static booleanisInStatic(DetailAST ast) Determines whether an AST node is in a static method or static initializer.private booleanisMatchingRegexp(String name) Check name by regExp.private booleanisSetterMethod(DetailAST aMethodAST, String aName) Determine if a specific method identified by methodAST and a single variable name aName is a setter.voidleaveToken(DetailAST ast) Called after all the child nodes have been process.private voidprocessLambda(DetailAST ast) Process a lambda token.private voidprocessVariable(DetailAST ast) Process a variable token.voidsetIgnoreAbstractMethods(boolean ignoreAbstractMethods) Setter to control whether to ignore parameters of abstract methods.voidsetIgnoreConstructorParameter(boolean ignoreConstructorParameter) Setter to control whether to ignore constructor parameters.voidsetIgnoreFormat(Pattern pattern) Setter to define the RegExp for names of variables and parameters to ignore.voidsetIgnoreSetter(boolean ignoreSetter) Setter to allow to ignore the parameter of a property setter method.voidsetSetterCanReturnItsClass(boolean aSetterCanReturnItsClass) Setter to allow to expand the definition of a setter method to include methods that return the class' instance.private voidvisitOtherTokens(DetailAST ast, int type) Called to process tokens other thanTokenTypes.VARIABLE_DEFandTokenTypes.PARAMETER_DEF.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheckclearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporterfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfiguration, setupChild
- 
Field Details- 
MSG_KEYA key is pointing to the warning message text in "messages.properties" file.- See Also:
 
- 
frameStack of sets of field names, one for each class of a set of nested classes.
- 
ignoreFormatDefine the RegExp for names of variables and parameters to ignore.
- 
ignoreSetterAllow to ignore the parameter of a property setter method.
- 
setterCanReturnItsClassAllow to expand the definition of a setter method to include methods that return the class' instance.
- 
ignoreConstructorParameterControl whether to ignore constructor parameters.
- 
ignoreAbstractMethodsControl whether to ignore parameters of abstract methods.
 
- 
- 
Constructor Details- 
HiddenFieldCheckpublic HiddenFieldCheck()
 
- 
- 
Method Details- 
getDefaultTokensDescription copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
- getDefaultTokensin class- AbstractCheck
- Returns:
- the default tokens
- See Also:
 
- 
getAcceptableTokensDescription copied from class:AbstractCheckThe configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Specified by:
- getAcceptableTokensin class- AbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
 
- 
getRequiredTokensDescription copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
- getRequiredTokensin class- AbstractCheck
- Returns:
- the token set this must be registered for.
- See Also:
 
- 
beginTreeDescription copied from class:AbstractCheckCalled before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Overrides:
- beginTreein class- AbstractCheck
- Parameters:
- rootAST- the root of the tree
 
- 
visitTokenDescription copied from class:AbstractCheckCalled to process a token.- Overrides:
- visitTokenin class- AbstractCheck
- Parameters:
- ast- the token to process
 
- 
processLambdaProcess a lambda token. Checks whether a lambda parameter shadows a field. Note, that when parameter of lambda expression is untyped, ANTLR parses the parameter as an identifier.- Parameters:
- ast- the lambda token.
 
- 
visitOtherTokensCalled to process tokens other thanTokenTypes.VARIABLE_DEFandTokenTypes.PARAMETER_DEF.- Parameters:
- ast- token to process
- type- type of the token
 
- 
leaveTokenDescription copied from class:AbstractCheckCalled after all the child nodes have been process.- Overrides:
- leaveTokenin class- AbstractCheck
- Parameters:
- ast- the token leaving
 
- 
processVariableProcess a variable token. Check whether a local variable or parameter shadows a field. Store a field for later comparison with local variables and parameters.- Parameters:
- ast- the variable token.
 
- 
isIgnoredParamChecks whether method or constructor parameter is ignored.- Parameters:
- ast- the parameter token.
- name- the parameter name.
- Returns:
- true if parameter is ignored.
 
- 
isInstanceFieldCheck for instance field.- Parameters:
- ast- token
- name- identifier of token
- Returns:
- true if instance field
 
- 
isMatchingRegexpCheck name by regExp.- Parameters:
- name- string value to check
- Returns:
- true is regexp is matching
 
- 
isInStaticDetermines whether an AST node is in a static method or static initializer.- Parameters:
- ast- the node to check.
- Returns:
- true if ast is in a static method or a static block;
 
- 
isIgnoredSetterParamDecides whether to ignore an AST node that is the parameter of a setter method, where the property setter method for field 'xyz' has name 'setXyz', one parameter named 'xyz', and return type void (default behavior) or return type is name of the class in which such method is declared (allowed only ifsetSetterCanReturnItsClass(boolean)is called with value true).- Parameters:
- ast- the AST to check.
- name- the name of ast.
- Returns:
- true if ast should be ignored because check property ignoreSetter is true and ast is the parameter of a setter method.
 
- 
isSetterMethodDetermine if a specific method identified by methodAST and a single variable name aName is a setter. This recognition partially depends on mSetterCanReturnItsClass property.- Parameters:
- aMethodAST- AST corresponding to a method call
- aName- name of single parameter of this method.
- Returns:
- true of false indicating of method is a setter or not.
 
- 
capitalizeCapitalizes a given property name the way we expect to see it in a setter name.- Parameters:
- name- a property name
- Returns:
- capitalized property name
 
- 
isIgnoredConstructorParamDecides whether to ignore an AST node that is the parameter of a constructor.- Parameters:
- ast- the AST to check.
- Returns:
- true if ast should be ignored because check property ignoreConstructorParameter is true and ast is a constructor parameter.
 
- 
isIgnoredParamOfAbstractMethodDecides whether to ignore an AST node that is the parameter of an abstract method.- Parameters:
- ast- the AST to check.
- Returns:
- true if ast should be ignored because check property ignoreAbstractMethods is true and ast is a parameter of abstract methods.
 
- 
setIgnoreFormatSetter to define the RegExp for names of variables and parameters to ignore.- Parameters:
- pattern- a pattern.
- Since:
- 3.2
 
- 
setIgnoreSetterSetter to allow to ignore the parameter of a property setter method.- Parameters:
- ignoreSetter- decide whether to ignore the parameter of a property setter method.
- Since:
- 3.2
 
- 
setSetterCanReturnItsClassSetter to allow to expand the definition of a setter method to include methods that return the class' instance.- Parameters:
- aSetterCanReturnItsClass- if true then setter can return either void or class in which it is declared. If false then in order to be recognized as setter method (otherwise already recognized as a setter) must return void. Later is the default behavior.
- Since:
- 6.3
 
- 
setIgnoreConstructorParameterSetter to control whether to ignore constructor parameters.- Parameters:
- ignoreConstructorParameter- decide whether to ignore constructor parameters.
- Since:
- 3.2
 
- 
setIgnoreAbstractMethodsSetter to control whether to ignore parameters of abstract methods.- Parameters:
- ignoreAbstractMethods- decide whether to ignore parameters of abstract methods.
- Since:
- 4.0
 
 
-