Class TreeWalker

    • Field Detail

      • tokenToOrdinaryChecks

        private final java.util.Map<java.lang.Integer,​java.util.Set<AbstractCheck>> tokenToOrdinaryChecks
        Maps from token name to ordinary checks.
      • tokenToCommentChecks

        private final java.util.Map<java.lang.Integer,​java.util.Set<AbstractCheck>> tokenToCommentChecks
        Maps from token name to comment checks.
      • ordinaryChecks

        private final java.util.Set<AbstractCheck> ordinaryChecks
        Registered ordinary checks, that don't use comment nodes.
      • commentChecks

        private final java.util.Set<AbstractCheck> commentChecks
        Registered comment checks.
      • filters

        private final java.util.Set<TreeWalkerFilter> filters
        The ast filters.
      • violations

        private final java.util.SortedSet<Violation> violations
        The sorted set of violations.
      • childContext

        private Context childContext
        Context of child components.
      • moduleFactory

        private ModuleFactory moduleFactory
        A factory for creating submodules (i.e. the Checks)
    • Constructor Detail

      • TreeWalker

        public TreeWalker()
        Creates a new TreeWalker instance.
    • Method Detail

      • setModuleFactory

        public void setModuleFactory​(ModuleFactory moduleFactory)
        Sets the module factory for creating child modules (Checks).
        Parameters:
        moduleFactory - the factory
      • finishLocalSetup

        public void finishLocalSetup()
        Description copied from class: AutomaticBean
        Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.

        The default implementation does nothing.

        Overrides:
        finishLocalSetup in class AbstractViolationReporter
      • getFilteredViolations

        private java.util.SortedSet<Violation> getFilteredViolations​(java.lang.String fileName,
                                                                     FileContents fileContents,
                                                                     DetailAST rootAST)
        Returns filtered set of Violation.
        Parameters:
        fileName - path to the file
        fileContents - the contents of the file
        rootAST - root AST element DetailAST of the file
        Returns:
        filtered set of violations
      • registerCheck

        private void registerCheck​(int tokenId,
                                   AbstractCheck check)
                            throws CheckstyleException
        Register a check for a specified token id.
        Parameters:
        tokenId - the id of the token
        check - the check to register
        Throws:
        CheckstyleException - if Check is misconfigured
      • walk

        private void walk​(DetailAST ast,
                          FileContents contents,
                          TreeWalker.AstState astState)
        Initiates the walk of an AST.
        Parameters:
        ast - the root AST
        contents - the contents of the file the AST was generated from.
        astState - state of AST.
      • notifyBegin

        private void notifyBegin​(DetailAST rootAST,
                                 FileContents contents,
                                 TreeWalker.AstState astState)
        Notify checks that we are about to begin walking a tree.
        Parameters:
        rootAST - the root of the tree.
        contents - the contents of the file the AST was generated from.
        astState - state of AST.
      • notifyEnd

        private void notifyEnd​(DetailAST rootAST,
                               TreeWalker.AstState astState)
        Notify checks that we have finished walking a tree.
        Parameters:
        rootAST - the root of the tree.
        astState - state of AST.
      • notifyVisit

        private void notifyVisit​(DetailAST ast,
                                 TreeWalker.AstState astState)
        Notify checks that visiting a node.
        Parameters:
        ast - the node to notify for.
        astState - state of AST.
      • notifyLeave

        private void notifyLeave​(DetailAST ast,
                                 TreeWalker.AstState astState)
        Notify checks that leaving a node.
        Parameters:
        ast - the node to notify for
        astState - state of AST.
      • getListOfChecks

        private java.util.Collection<AbstractCheck> getListOfChecks​(DetailAST ast,
                                                                    TreeWalker.AstState astState)
        Method returns list of checks.
        Parameters:
        ast - the node to notify for
        astState - state of AST.
        Returns:
        list of visitors
      • getExternalResourceLocations

        public java.util.Set<java.lang.String> getExternalResourceLocations()
        Description copied from interface: ExternalResourceHolder
        Returns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will be NullPointerException in Checker. Such behaviour will signal that your module (check or filter) is designed incorrectly. It make sense to return an empty set from 'getExternalResourceLocations()' only for composite modules like TreeWalker.
        Specified by:
        getExternalResourceLocations in interface ExternalResourceHolder
        Returns:
        a set of external configuration resource locations which are used by the module.
      • processIter

        private void processIter​(DetailAST root,
                                 TreeWalker.AstState astState)
        Processes a node calling interested checks at each node. Uses iterative algorithm.
        Parameters:
        root - the root of tree for process
        astState - state of AST.
      • createNewCheckSortedSet

        private static java.util.SortedSet<AbstractCheck> createNewCheckSortedSet()
        Creates a new SortedSet with a deterministic order based on the Check's name before the default ordering.
        Returns:
        The new SortedSet.