Package com.sonarsource.cobol.api.ast
Class CobolAstVisitor
- java.lang.Object
-
- com.sonarsource.cobol.api.ast.CobolAstVisitor
-
- All Implemented Interfaces:
AstVisitor
- Direct Known Subclasses:
CobolCheck
public abstract class CobolAstVisitor extends Object implements AstVisitor
Base class to visit an AST (Abstract Syntactic Tree) generated by a parser. Methods are visited in the following sequential order : init(), visitFile(), visitNode(), leaveNode(), leaveFile() and destroy()
-
-
Field Summary
Fields Modifier and Type Field Description protected CobolGrammar
grammar
-
Constructor Summary
Constructors Constructor Description CobolAstVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Destroy the visitor.List<AstNodeType>
getAstNodeTypesToVisit()
This method can't be overridden.Charset
getCharset()
protected CicsGrammar
getCicsGrammar()
CobolFile
getCobolFile()
protected CobolGrammar
getCobolGrammar()
Comments
getComments()
protected DB2Grammar
getSqlGrammar()
CobolSymbolTable
getSymbolTable()
void
init()
Initialize the visitor.void
leaveFile(AstNode astNode)
Called once a computation unit tree has been fully visited.void
leaveNode(AstNode astNode)
Called once an AST node has been fully visited.void
setCharset(Charset charset)
void
setCobolFile(CobolFile cobolFile)
void
setComments(Comments comments)
Do not usevoid
setGrammar(CobolGrammar grammar)
Do not usevoid
setSymbolTable(CobolSymbolTable symbolTable)
Do not usevoid
subscribeTo(AstNodeType... astNodeTypes)
This method must called into the init() method when a Cobol AST visitor wants to subscribe to a set of AST node type.void
visitFile(AstNode astNode)
Called before starting visiting a computation unit tree.void
visitNode(AstNode astNode)
Called to process an AST node whose type has been registered to be visited.
-
-
-
Field Detail
-
grammar
protected CobolGrammar grammar
-
-
Method Detail
-
getAstNodeTypesToVisit
public final List<AstNodeType> getAstNodeTypesToVisit()
This method can't be overridden. The method subscribeTo(AstNodeType... astNodeTypes) must be used to while overriding the public void init() method.- Specified by:
getAstNodeTypesToVisit
in interfaceAstVisitor
- Returns:
- the AST node types this must be registered for.
-
subscribeTo
public final void subscribeTo(AstNodeType... astNodeTypes)
This method must called into the init() method when a Cobol AST visitor wants to subscribe to a set of AST node type.
-
setGrammar
public final void setGrammar(CobolGrammar grammar)
Do not use
-
setComments
public final void setComments(Comments comments)
Do not use
-
setSymbolTable
public final void setSymbolTable(CobolSymbolTable symbolTable)
Do not use
-
getSymbolTable
public final CobolSymbolTable getSymbolTable()
-
getComments
public final Comments getComments()
-
init
public void init()
Initialize the visitor. This is the time to verify that the visitor has everything required to perform it job. This method is called once.
-
visitFile
public void visitFile(@Nullable AstNode astNode)
Called before starting visiting a computation unit tree. Ideal place to initialize information that is to be collected while processing the tree.- Specified by:
visitFile
in interfaceAstVisitor
- Parameters:
astNode
- the root of the tree, ornull
if no tree
-
visitNode
public void visitNode(AstNode astNode)
Called to process an AST node whose type has been registered to be visited.- Specified by:
visitNode
in interfaceAstVisitor
- Parameters:
astNode
- the AST node to process
-
leaveFile
public void leaveFile(@Nullable AstNode astNode)
Called once a computation unit tree has been fully visited. Ideal place to report on information collected while processing a tree.- Specified by:
leaveFile
in interfaceAstVisitor
- Parameters:
astNode
- the root of the tree, ornull
if no tree
-
leaveNode
public void leaveNode(AstNode astNode)
Called once an AST node has been fully visited.- Specified by:
leaveNode
in interfaceAstVisitor
- Parameters:
astNode
- the AST node which has been visited
-
destroy
public void destroy()
Destroy the visitor. It is being retired from service.
-
getCharset
public Charset getCharset()
-
setCharset
public void setCharset(Charset charset)
-
getCobolFile
public CobolFile getCobolFile()
-
setCobolFile
public void setCobolFile(CobolFile cobolFile)
-
getCobolGrammar
protected final CobolGrammar getCobolGrammar()
-
getSqlGrammar
protected final DB2Grammar getSqlGrammar()
-
getCicsGrammar
protected final CicsGrammar getCicsGrammar()
-
-