Class RequiredParameterForAnnotationCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.github.sevntu.checkstyle.checks.annotation.RequiredParameterForAnnotationCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable
,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class RequiredParameterForAnnotationCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Check that annotation is used with all required parameters.
Parameters:
annotationName - The name of the target annotation where enforcement of parameter should happen.
requiredParameters - Set of parameter names that are required on the target annotation. Names can be specified on any order in target annotation.Example 1.
Configuration:<module name="RequiredParameterForAnnotation"> <property name="annotationName" value="TheAnnotation"/> <property name="requiredParameters" value="ThePropertyName1"/> </module>
Result:
@TheAnnotation() //Violation. ThePropertyName1 missing. someMethod() {} @TheAnnotation(ThePropertyName2=2) //Violation. ThePropertyName1 missing. class SomeClass {} @TheAnnotation(ThePropertyName1=1) //Correct. class SomeClass {} @TheAnnotation(ThePropertyName2=2, ThePropertyName3=3, ThePropertyName1=1) //Correct. class SomeClass {}
Example 2.
Configuration:<module name="RequiredParameterForAnnotation"> <property name="annotationName" value="TheAnnotation"/> <property name="requiredParameters" value="ThePropertyName1,ThePropertyName2, ThePropertyName3"/> </module>
Result:
@TheAnnotation() //Violation. ThePropertyName 1, 2, 3 missing. someMethod() {} @TheAnnotation(ThePropertyName2=2) //Violation. ThePropertyName 1 and 3 missing. class SomeClass {} @TheAnnotation(ThePropertyName3=3, ThePropertyName2=2, ThePropertyName1=1) //Correct. class SomeClass {}
- Since:
- 1.13.0
- Author:
- Andrew Uljanenko
-
-
Constructor Summary
Constructors Constructor Description RequiredParameterForAnnotationCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getAcceptableTokens()
int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
setAnnotationName(String annotationName)
The annotation name we are interested in.void
setRequiredParameters(String... requiredPropertiesParameter)
The required list of parameters we have to use.void
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST annotationNode)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
-
-
-
Field Detail
-
MSG_KEY
public static final String MSG_KEY
Key for error message.- See Also:
- Constant Field Values
-
-
Method Detail
-
setAnnotationName
public void setAnnotationName(String annotationName)
The annotation name we are interested in.- Parameters:
annotationName
- set annotation name
-
setRequiredParameters
public void setRequiredParameters(String... requiredPropertiesParameter)
The required list of parameters we have to use.- Parameters:
requiredPropertiesParameter
- set required list of parameters
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST annotationNode)
- Overrides:
visitToken
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
-