Class ClassAndPropertiesSettersJavadocScraper
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
-
- com.puppycrawl.tools.checkstyle.site.ClassAndPropertiesSettersJavadocScraper
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public class ClassAndPropertiesSettersJavadocScraper extends AbstractJavadocCheck
Class for scraping class javadoc and all property setter javadocs from the given checkstyle module.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private static Map<String,DetailNode>
JAVADOC_FOR_MODULE_OR_PROPERTY
Map of scraped javadocs - name of property, javadoc detail node.private static String
moduleName
Name of the module being scraped.-
Fields inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
MSG_JAVADOC_MISSED_HTML_CLOSE, MSG_JAVADOC_PARSE_RULE_ERROR, MSG_JAVADOC_WRONG_SINGLETON_TAG, MSG_KEY_UNCLOSED_HTML_TAG
-
-
Constructor Summary
Constructors Constructor Description ClassAndPropertiesSettersJavadocScraper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.static Map<String,DetailNode>
getJavadocsForModuleOrProperty()
Get the module or property javadocs map.private static DetailAST
getParentAst(DetailAST ast, int type)
Get the parent node of the given type.private static String
getPropertyName(String setterName)
Get the property name from the setter method name.static void
initialize(String newModuleName)
Initialize the scraper.private static boolean
isMethodOfScrapedModule(DetailAST methodDef)
Checks if the given method is a method of the module being scraped.private static boolean
isSetterMethod(DetailAST ast)
Returns whether an AST represents a setter method.void
visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.-
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginJavadocTree, beginTree, destroy, finishJavadocTree, finishTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredJavadocTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitToken
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, 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
-
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
JAVADOC_FOR_MODULE_OR_PROPERTY
private static final Map<String,DetailNode> JAVADOC_FOR_MODULE_OR_PROPERTY
Map of scraped javadocs - name of property, javadoc detail node. The class javadoc is stored too, with the key being the module name.
-
moduleName
private static String moduleName
Name of the module being scraped.
-
-
Constructor Detail
-
ClassAndPropertiesSettersJavadocScraper
public ClassAndPropertiesSettersJavadocScraper()
-
-
Method Detail
-
initialize
public static void initialize(String newModuleName)
Initialize the scraper. Clears static context and sets the module name.- Parameters:
newModuleName
- the module name.
-
getJavadocsForModuleOrProperty
public static Map<String,DetailNode> getJavadocsForModuleOrProperty()
Get the module or property javadocs map.- Returns:
- the javadocs.
-
getDefaultJavadocTokens
public int[] getDefaultJavadocTokens()
Description copied from class:AbstractJavadocCheck
Returns the default javadoc token types a check is interested in.- Specified by:
getDefaultJavadocTokens
in classAbstractJavadocCheck
- Returns:
- the default javadoc token types
- See Also:
JavadocTokenTypes
-
visitJavadocToken
public void visitJavadocToken(DetailNode ast)
Description copied from class:AbstractJavadocCheck
Called to process a Javadoc token.- Specified by:
visitJavadocToken
in classAbstractJavadocCheck
- Parameters:
ast
- the token to process
-
isMethodOfScrapedModule
private static boolean isMethodOfScrapedModule(DetailAST methodDef)
Checks if the given method is a method of the module being scraped. Traverses parent nodes until it finds the class definition and checks if the class name is the same as the module name. We want to avoid scraping javadocs from inner classes.- Parameters:
methodDef
- the method definition.- Returns:
- true if the method is a method of the given module, false otherwise.
-
getParentAst
private static DetailAST getParentAst(DetailAST ast, int type)
Get the parent node of the given type. Traverses up the tree until it finds the given type.- Parameters:
ast
- the node to start traversing from.type
- the type of the parent node to find.- Returns:
- the parent node of the given type, or null if not found.
-
getPropertyName
private static String getPropertyName(String setterName)
Get the property name from the setter method name. For example, getPropertyName("setFoo") returns "foo". This method removes the "set" prefix and decapitalizes the first letter of the property name.- Parameters:
setterName
- the setter method name.- Returns:
- the property name.
-
isSetterMethod
private static boolean isSetterMethod(DetailAST ast)
Returns whether an AST represents a setter method.- Parameters:
ast
- the AST to check with- Returns:
- whether the AST represents a setter method
-
-