Class MissingOverrideCheck
- All Implemented Interfaces:
Configurable,Contextualizable
@Override annotation is present
when the @inheritDoc javadoc tag is present.
Rationale: The @Override annotation helps compiler tools ensure that an override is actually occurring. It is quite easy to accidentally overload a method or hide a static method and using the @Override annotation points out these problems.
This check will log a violation if using the @inheritDoc tag on a method that is not valid (ex: private, or static method).
There is a slight difference between the @Override annotation in Java 5 versus Java 6 and above. In Java 5, any method overridden from an interface cannot be annotated with @Override. In Java 6 this behavior is allowed.
As a result of the aforementioned difference between Java 5 and Java 6, a
property called javaFiveCompatibility is available. This
property will only check classes, interfaces, etc. that do not contain the
extends or implements keyword or are not anonymous classes. This means it
only checks methods overridden from java.lang.Object.
Java 5 Compatibility mode severely limits this check. It is recommended to
only use it on Java 5 source.
-
Property
javaFiveCompatibility- Enable java 5 compatibility mode. Type isboolean. Default value isfalse.
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
-
annotation.missing.override -
tag.not.valid.on
- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanEnable java 5 compatibility mode.private static final PatternCompiled regexp to match Javadoc tags with no argument and {}.static final StringA key is pointing to the warning message text in "messages.properties" file.static final StringA key is pointing to the warning message text in "messages.properties" file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanChecks to see if the ast contains a inheritDoc tag.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.booleanWhether comment nodes are required or not.voidsetJavaFiveCompatibility(boolean compatibility) Setter to enable java 5 compatibility mode.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_KEY_TAG_NOT_VALID_ON
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MSG_KEY_ANNOTATION_MISSING_OVERRIDE
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MATCH_INHERIT_DOC
Compiled regexp to match Javadoc tags with no argument and {}. -
javaFiveCompatibility
Enable java 5 compatibility mode.
-
-
Constructor Details
-
MissingOverrideCheck
public MissingOverrideCheck()
-
-
Method Details
-
setJavaFiveCompatibility
Setter to enable java 5 compatibility mode.- Parameters:
compatibility- compatibility or not- Since:
- 5.0
-
getDefaultTokens
Description 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 classAbstractCheck- Returns:
- the default tokens
- See Also:
-
getAcceptableTokens
Description 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 classAbstractCheck- Returns:
- the token set this check is designed for.
- See Also:
-
isCommentNodesRequired
Description copied from class:AbstractCheckWhether comment nodes are required or not.- Overrides:
isCommentNodesRequiredin classAbstractCheck- Returns:
- false as a default value.
-
getRequiredTokens
Description copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
getRequiredTokensin classAbstractCheck- Returns:
- the token set this must be registered for.
- See Also:
-
visitToken
Description copied from class:AbstractCheckCalled to process a token.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
containsInheritDocTag
Checks to see if the ast contains a inheritDoc tag.- Parameters:
ast- method AST node- Returns:
- true if contains the tag
-