Class ForbidAnnotationElementValueCheck
- 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.ForbidAnnotationElementValueCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class ForbidAnnotationElementValueCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheckForbids specific element value for specific annotation. You can configure this check using following options:
- Annotation name
- Annotation element name
- Forbidden annotation element value pattern
Here is XML configs and according code samples needed to forbid.
To configure the check to forbid junit Test annotations with the element name "expected":
Config
<module name="ForbidAnnotationElementValue"> </module>
Code
@Test(expected = Exception.class)
To configure the check to forbid single-element annotation element value, like 'SuppressWarnings', elementName option should be specified as "value".
Config
<module name="ForbidAnnotationElementValue"> <property name="annotationName" value="SuppressWarnings"/> <property name="elementName" value="value"/> <property name="forbiddenElementValueRegexp" value="unchecked"/> </module>
Code
@SuppressWarnings("unchecked")To forbid any array-valued element, forbiddenElementValueRegexp option should be: "\{.*\}".
Config
<module name="ForbidAnnotationElementValue"> <property name="annotationName" value="SuppressWarnings"/> <property name="elementName" value="value"/> <property name="forbiddenElementValueRegexp" value="\{.*\}"/> </module>Code
@SuppressWarnings({"unused", "unchecked"})- Since:
- 1.22.0
- Author:
- Sergey Drozd , Richard Veach
-
-
Constructor Summary
Constructors Constructor Description ForbidAnnotationElementValueCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]getAcceptableTokens()int[]getDefaultTokens()int[]getRequiredTokens()voidsetAnnotationName(String annotationName)Sets Annotation Name Check property.voidsetElementName(String elementName)Sets Annotation Element Check property.voidsetForbiddenElementValueRegexp(String forbiddenElementValueRegexp)Sets Forbidden Element Value Pattern Check property.voidvisitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)-
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
Message key.- See Also:
- Constant Field Values
-
-
Method Detail
-
setAnnotationName
public void setAnnotationName(String annotationName)
Sets Annotation Name Check property.- Parameters:
annotationName- The annotation name.
-
setElementName
public void setElementName(String elementName)
Sets Annotation Element Check property.- Parameters:
elementName- The annotation element name.
-
setForbiddenElementValueRegexp
public void setForbiddenElementValueRegexp(String forbiddenElementValueRegexp)
Sets Forbidden Element Value Pattern Check property.- Parameters:
forbiddenElementValueRegexp- The forbidden element value pattern to set.
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
visitTokenin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
-