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
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
FieldsModifier and TypeFieldDescriptionprivate static ObjectThe instance of the module.private static StringName of the module being scraped.The properties of the module.private final Map<String, DetailNode> Map of property names to their setter javadoc nodes.Fields inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
MSG_JAVADOC_PARSE_RULE_ERROR, MSG_KEY_UNCLOSED_HTML_TAG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate PropertyDetailscreatePropertyDetails(String propertyName) Creates a PropertyDetails object for the given property.voidfinishTree(DetailAST rootAST) Called after finished processing a tree.int[]Returns the default javadoc token types a check is interested in.private static DetailASTgetParentAst(DetailAST ast, int type) Get the parent node of the given type.private static StringgetPropertyName(String setterName) Get the property name from the setter method name.private static voidhandleClassComment(DetailNode ast, DetailAST blockCommentAst) Processes class Javadoc.private voidhandleFieldComment(DetailNode ast, DetailAST blockCommentAst) Processes field Javadoc.private voidhandleMethodComment(DetailNode ast, DetailAST blockCommentAst) Processes method Javadoc.static voidinitialize(String newModuleName, Object instance, Set<String> propertiesSet) Initialize the scraper.private static booleanisKnownProperty(String fieldName) Checks if the field name is a known property that should be documented.private static booleanisMethodOfScrapedModule(DetailAST methodDef) Checks if the given method is a method of the module being scraped.private static booleanisSetterMethod(DetailAST ast) Returns whether an AST represents a setter method.voidCalled to process a Javadoc token.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginJavadocTree, beginTree, destroy, finishJavadocTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredJavadocTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitTokenMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, 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
-
moduleName
Name of the module being scraped. -
moduleInstance
The instance of the module. -
properties
The properties of the module. -
setterNodes
Map of property names to their setter javadoc nodes.
-
-
Constructor Details
-
ClassAndPropertiesSettersJavadocScraper
-
-
Method Details
-
initialize
Initialize the scraper. Clears static context and sets the module name.- Parameters:
newModuleName- the module name.instance- the module instance.propertiesSet- the set of properties to document.
-
getDefaultJavadocTokens
Description copied from class:AbstractJavadocCheckReturns the default javadoc token types a check is interested in.- Specified by:
getDefaultJavadocTokensin classAbstractJavadocCheck- Returns:
- the default javadoc token types
- See Also:
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
ast- the token to process
-
handleMethodComment
Processes method Javadoc. If the method is a setter for a property of the module being scraped, the Javadoc node is stored.- Parameters:
ast- the Javadoc node.blockCommentAst- the block comment AST.
-
handleFieldComment
Processes field Javadoc. If the field is a known property of the module being scraped, the Javadoc node is stored.- Parameters:
ast- the Javadoc node.blockCommentAst- the block comment AST.
-
isKnownProperty
Checks if the field name is a known property that should be documented.- Parameters:
fieldName- the name of the field.- Returns:
- true if it is a known property, false otherwise.
-
handleClassComment
Processes class Javadoc. Extracts module metadata such as 'since' version, description, and notes.- Parameters:
ast- the Javadoc node.blockCommentAst- the block comment AST.
-
finishTree
Description copied from class:AbstractCheckCalled after finished processing a tree. Ideal place to report on information collected whilst processing a tree.- Overrides:
finishTreein classAbstractCheck- Parameters:
rootAST- the root of the tree
-
isMethodOfScrapedModule
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
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
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
Returns whether an AST represents a setter method.- Parameters:
ast- the AST to check with- Returns:
- whether the AST represents a setter method
-
createPropertyDetails
private PropertyDetails createPropertyDetails(String propertyName) throws org.apache.maven.doxia.macro.MacroExecutionException Creates a PropertyDetails object for the given property.- Parameters:
propertyName- the name of the property.- Returns:
- the PropertyDetails object.
- Throws:
org.apache.maven.doxia.macro.MacroExecutionException- if an error occurs
-