com.sonar.c.api.ast
Class CAstVisitor

java.lang.Object
  extended by com.sonar.c.api.ast.CAstVisitor
All Implemented Interfaces:
AstVisitor
Direct Known Subclasses:
CAstCheck

public abstract class CAstVisitor
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
protected  CGrammar grammar
           
 
Constructor Summary
CAstVisitor()
           
 
Method Summary
 void addSourceCode(SourceCode child)
          Do not use
 void destroy()
          Destroy the visitor.
 List<AstNodeType> getAstNodeTypesToVisit()
          This method can't be overridden.
protected  CGrammar getCGrammar()
           
 Comments getComments()
           
 File getFile()
           
 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 onError(Throwable exception)
           
 SourceCode peekSourceCode()
          Do not use
 void popSourceCode()
          Do not use
 void setComments(Comments comments)
          Do not use
 void setFile(File file)
           
 void setGrammar(CGrammar grammar)
          Do not use
 void setSourceCodeStack(Stack<SourceCode> sourceCodeStack)
          Do not use
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grammar

protected CGrammar grammar
Constructor Detail

CAstVisitor

public CAstVisitor()
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 interface AstVisitor
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.


setSourceCodeStack

public final void setSourceCodeStack(Stack<SourceCode> sourceCodeStack)
Do not use


setGrammar

public final void setGrammar(CGrammar grammar)
Do not use


setComments

public final void setComments(Comments comments)
Do not use


getComments

public final Comments getComments()

addSourceCode

public final void addSourceCode(SourceCode child)
Do not use


popSourceCode

public final void popSourceCode()
Do not use


peekSourceCode

public final SourceCode peekSourceCode()
Do not use


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(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 interface AstVisitor
Parameters:
astNode - the root of the 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 interface AstVisitor
Parameters:
astNode - the AST node to process

leaveFile

public void leaveFile(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 interface AstVisitor
Parameters:
astNode - the root of the tree

onError

public void onError(Throwable exception)

leaveNode

public void leaveNode(AstNode astNode)
Called once an AST node has been fully visited.

Specified by:
leaveNode in interface AstVisitor
Parameters:
astNode - the AST node which has been visited

destroy

public void destroy()
Destroy the visitor. It is being retired from service.


setFile

public final void setFile(File file)

getFile

public final File getFile()

getCGrammar

protected final CGrammar getCGrammar()


Copyright © 2010. All Rights Reserved.