Package com.puppycrawl.tools.checkstyle
Class TreeWalker
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
com.puppycrawl.tools.checkstyle.TreeWalker
- All Implemented Interfaces:
- Configurable,- Contextualizable,- ExternalResourceHolder,- FileSetCheck
Responsible for walking an abstract syntax tree and notifying interested
 checks at each node.
- 
Nested Class SummaryNested ClassesNested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate ContextContext of child components.private final Set<AbstractCheck>Registered comment checks.private final Set<TreeWalkerFilter>The ast filters.private SeverityLevelSpecify severity Level to log Java parsing exceptions when they are skipped.private ModuleFactoryA factory for creating submodules (i.e. the Checks)private final Set<AbstractCheck>Registered ordinary checks, that don't use comment nodes.static final StringMessage to use when an exception occurs and should be printed as a violation.private booleanControl whether to skip files with Java parsing exceptions.private final Map<Integer,Set<AbstractCheck>> Maps from token name to comment checks.private final Map<Integer,Set<AbstractCheck>> Maps from token name to ordinary checks.The sorted set of violations.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprivate static SortedSet<AbstractCheck>Creates a newSortedSetwith a deterministic order based on the Check's name before the default ordering.voiddestroy()Cleans up the object.voidProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.Returns a set of external configuration resource locations which are used by the module.getFilteredViolations(String fileName, FileContents fileContents, DetailAST rootAST) Returns filtered set ofViolation.private Collection<AbstractCheck>getListOfChecks(DetailAST ast, TreeWalker.AstState astState) Method returns list of checks.private voidnotifyBegin(DetailAST rootAST, FileContents contents, TreeWalker.AstState astState) Notify checks that we are about to begin walking a tree.private voidnotifyEnd(DetailAST rootAST, TreeWalker.AstState astState) Notify checks that we have finished walking a tree.private voidnotifyLeave(DetailAST ast, TreeWalker.AstState astState) Notify checks that leaving a node.private voidnotifyVisit(DetailAST ast, TreeWalker.AstState astState) Notify checks that visiting a node.protected voidprocessFiltered(File file, FileText fileText) Called to process a file that matches the specified file extensions.private voidprocessIter(DetailAST root, TreeWalker.AstState astState) Processes a node calling interested checks at each node.private voidregisterCheck(int tokenId, AbstractCheck check) Register a check for a specified token id.private voidregisterCheck(AbstractCheck check) Register a check for a given configuration.voidsetJavaParseExceptionSeverity(SeverityLevel javaParseExceptionSeverity) Setter to specify the severity level to log Java parsing exceptions when they are skipped.voidsetModuleFactory(ModuleFactory moduleFactory) Sets the module factory for creating child modules (Checks).voidsetSkipFileOnJavaParseException(boolean skipFileOnJavaParseException) Setter to control whether to skip files with Java parsing exceptions.voidsetupChild(Configuration childConf) Called by configure() for every child of this component's Configuration.private voidwalk(DetailAST ast, FileContents contents, TreeWalker.AstState astState) Initiates the walk of an AST.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheckaddViolations, beginProcessing, finishProcessing, fireErrors, getFileContents, getFileExtensions, getMessageDispatcher, getTabWidth, getViolations, init, log, log, process, setFileContents, setFileExtensions, setMessageDispatcher, setTabWidthMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReportergetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfigurationMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.ConfigurableconfigureMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizablecontextualize
- 
Field Details- 
PARSE_EXCEPTION_MSGMessage to use when an exception occurs and should be printed as a violation.- See Also:
 
- 
tokenToOrdinaryChecksMaps from token name to ordinary checks.
- 
tokenToCommentChecksMaps from token name to comment checks.
- 
ordinaryChecksRegistered ordinary checks, that don't use comment nodes.
- 
commentChecksRegistered comment checks.
- 
filtersThe ast filters.
- 
violationsThe sorted set of violations.
- 
childContextContext of child components.
- 
moduleFactoryA factory for creating submodules (i.e. the Checks)
- 
skipFileOnJavaParseExceptionControl whether to skip files with Java parsing exceptions.
- 
javaParseExceptionSeveritySpecify severity Level to log Java parsing exceptions when they are skipped.
 
- 
- 
Constructor Details- 
TreeWalkerpublic TreeWalker()Creates a newTreeWalkerinstance.
 
- 
- 
Method Details- 
setModuleFactorySets the module factory for creating child modules (Checks).- Parameters:
- moduleFactory- the factory
 
- 
setSkipFileOnJavaParseExceptionSetter to control whether to skip files with Java parsing exceptions.- Parameters:
- skipFileOnJavaParseException- whether to skip files with Java parsing errors.
- Since:
- 10.18.0
 
- 
setJavaParseExceptionSeveritySetter to specify the severity level to log Java parsing exceptions when they are skipped.- Parameters:
- javaParseExceptionSeverity- severity level to log parsing exceptions when they are skipped.
- Since:
- 10.18.0
 
- 
finishLocalSetupDescription copied from class:AbstractAutomaticBeanProvides 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:
- finishLocalSetupin class- AbstractViolationReporter
 
- 
setupChildCalled by configure() for every child of this component's Configuration.The default implementation throws Creates child module.CheckstyleExceptionifchildConfisnullbecause it doesn't support children. It must be overridden to validate and support children that are wanted.- Overrides:
- setupChildin class- AbstractAutomaticBean
- Parameters:
- childConf- a child of this component's Configuration
- Throws:
- CheckstyleException- if there is a configuration error.
- See Also:
 
- 
processFilteredCalled to process a file that matches the specified file extensions. Processes the file.- Specified by:
- processFilteredin class- AbstractFileSetCheck
- Parameters:
- file- the file to be processed
- fileText- the contents of the file.
- Throws:
- CheckstyleException- if error condition within Checkstyle occurs.
 
- 
getFilteredViolationsprivate SortedSet<Violation> getFilteredViolations(String fileName, FileContents fileContents, DetailAST rootAST) Returns filtered set ofViolation.- Parameters:
- fileName- path to the file
- fileContents- the contents of the file
- rootAST- root AST element- DetailASTof the file
- Returns:
- filtered set of violations
 
- 
registerCheckRegister a check for a given configuration.- Parameters:
- check- the check to register
- Throws:
- CheckstyleException- if an error occurs
 
- 
registerCheckRegister 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
 
- 
walkInitiates 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.
 
- 
notifyBeginNotify 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.
 
- 
notifyEndNotify checks that we have finished walking a tree.- Parameters:
- rootAST- the root of the tree.
- astState- state of AST.
 
- 
notifyVisitNotify checks that visiting a node.- Parameters:
- ast- the node to notify for.
- astState- state of AST.
 
- 
notifyLeaveNotify checks that leaving a node.- Parameters:
- ast- the node to notify for
- astState- state of AST.
 
- 
getListOfChecksMethod returns list of checks.- Parameters:
- ast- the node to notify for
- astState- state of AST.
- Returns:
- list of visitors
 
- 
destroyDescription copied from interface:FileSetCheckCleans up the object.- Specified by:
- destroyin interface- FileSetCheck
- Overrides:
- destroyin class- AbstractFileSetCheck
 
- 
getExternalResourceLocationsDescription copied from interface:ExternalResourceHolderReturns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will beNullPointerExceptioninChecker. Such behaviour will signal that your module (check or filter) is designed incorrectly. It makes sense to return an empty set from 'getExternalResourceLocations()' only for composite modules likeTreeWalker.- Specified by:
- getExternalResourceLocationsin interface- ExternalResourceHolder
- Returns:
- a set of external configuration resource locations which are used by the module.
 
- 
processIterProcesses a node calling interested checks at each node. Uses iterative algorithm.- Parameters:
- root- the root of tree for process
- astState- state of AST.
 
- 
createNewCheckSortedSetCreates a newSortedSetwith a deterministic order based on the Check's name before the default ordering.- Returns:
- The new SortedSet.
 
 
-