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 CobolGrammargrammar
-
Constructor Summary
Constructors Constructor Description CobolAstVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Destroy the visitor.List<AstNodeType>getAstNodeTypesToVisit()This method can't be overridden.CharsetgetCharset()protected CicsGrammargetCicsGrammar()CobolFilegetCobolFile()protected CobolGrammargetCobolGrammar()CommentsgetComments()protected DB2GrammargetSqlGrammar()CobolSymbolTablegetSymbolTable()voidinit()Initialize the visitor.voidleaveFile(AstNode astNode)Called once a computation unit tree has been fully visited.voidleaveNode(AstNode astNode)Called once an AST node has been fully visited.voidsetCharset(Charset charset)voidsetCobolFile(CobolFile cobolFile)voidsetComments(Comments comments)Do not usevoidsetGrammar(CobolGrammar grammar)Do not usevoidsetSymbolTable(CobolSymbolTable symbolTable)Do not usevoidsubscribeTo(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.voidvisitFile(AstNode astNode)Called before starting visiting a computation unit tree.voidvisitNode(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:
getAstNodeTypesToVisitin 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:
visitFilein interfaceAstVisitor- Parameters:
astNode- the root of the tree, ornullif no tree
-
visitNode
public void visitNode(AstNode astNode)
Called to process an AST node whose type has been registered to be visited.- Specified by:
visitNodein 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:
leaveFilein interfaceAstVisitor- Parameters:
astNode- the root of the tree, ornullif no tree
-
leaveNode
public void leaveNode(AstNode astNode)
Called once an AST node has been fully visited.- Specified by:
leaveNodein 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()
-
-