This is a better framework for parse tree analysis and we should migrate to this gradually. I had to cook this up for Suresh who is doing lineage extraction from the parse tree for databee.
The following are the basic framework elements:
It has three interfaces:
1. ParseTreeProcessor (with a default implementation of DefaultParseTreeProcessor that does a pre order traversal)
2. ParseTreeEventDispatcher (with a default implementation of DefaultParseTreeEventDispatcher) which dispatches events to a ParseTreeEventProcessor
3. ParseTreeEventProcessor (with a default implementation of DefaultParseTreeEventProcessor).
The ParseTreeEvent class defines the different kind of parse tree events. These are basically things like saw a select clause, source table, subquery, limit etc... and we can keep adding to these.
The dispatcher code registers for the interested events the event processor that needs to be called. The default dispatcher calls these processors for the event in the order that they were registered.
The process function in the tree processor calls the dispatcher for these events and the default one does that in a pre order way.
I think a framework like this will help us modularize SemanticAnalyzer in a much better way.