Class ClassAndPropertiesSettersJavadocScraper

All Implemented Interfaces:
Configurable, Contextualizable

Class for scraping class javadoc and all property setter javadocs from the given checkstyle module.
  • Field Details

  • Constructor Details

  • Method Details

    • initialize

      public static void initialize(String newModuleName, Object instance, Set<String> propertiesSet)
      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

      public int[] getDefaultJavadocTokens()
      Description copied from class: AbstractJavadocCheck
      Returns the default javadoc token types a check is interested in.
      Specified by:
      getDefaultJavadocTokens in class AbstractJavadocCheck
      Returns:
      the default javadoc token types
      See Also:
    • visitJavadocToken

      public void visitJavadocToken(DetailNode ast)
      Description copied from class: AbstractJavadocCheck
      Called to process a Javadoc token.
      Specified by:
      visitJavadocToken in class AbstractJavadocCheck
      Parameters:
      ast - the token to process
    • handleMethodComment

      private void handleMethodComment(DetailNode ast, DetailAST blockCommentAst)
      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

      private void handleFieldComment(DetailNode ast, DetailAST blockCommentAst)
      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

      private static boolean isKnownProperty(String fieldName)
      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

      private static void handleClassComment(DetailNode ast, DetailAST blockCommentAst)
      Processes class Javadoc. Extracts module metadata such as 'since' version, description, and notes.
      Parameters:
      ast - the Javadoc node.
      blockCommentAst - the block comment AST.
    • finishTree

      public void finishTree(DetailAST rootAST)
      Description copied from class: AbstractCheck
      Called after finished processing a tree. Ideal place to report on information collected whilst processing a tree.
      Overrides:
      finishTree in class AbstractCheck
      Parameters:
      rootAST - the root of the tree
    • 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
    • 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