com.metamatrix.query.sql.visitor
Class VariableCollectorVisitor

java.lang.Object
  extended by com.metamatrix.query.sql.LanguageVisitor
      extended by com.metamatrix.query.sql.visitor.VariableCollectorVisitor

public class VariableCollectorVisitor
extends LanguageVisitor

This visitor class will traverse a language object tree and collect all variable symbol references it finds. It uses a collection to collect the elements in so different collections will give you different collection properties - for instance, using a Set will remove duplicates.

The easiest way to use this visitor is to call the static methods which create the visitor (and possibly the collection), run the visitor, and return the collection. The public visit() methods should NOT be called directly.


Constructor Summary
VariableCollectorVisitor(java.util.Collection variables)
          Construct a new visitor with the specified collection, which should be non-null.
 
Method Summary
 java.util.Collection getVariables()
          Get the variables collected by the visitor.
static java.util.Collection getVariables(LanguageObject obj, boolean removeDuplicates)
          Helper to quickly get the variables from obj in a collection.
static void getVariables(LanguageObject obj, java.util.Collection variables)
          Helper to quickly get the variables from obj in the variables collection
 void visit(ElementSymbol obj)
          Visit a language object and collect symbols.
 
Methods inherited from class com.metamatrix.query.sql.LanguageVisitor
setAbort, shouldAbort, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableCollectorVisitor

public VariableCollectorVisitor(java.util.Collection variables)
Construct a new visitor with the specified collection, which should be non-null.

Parameters:
variables - Collection to use for variables
Throws:
java.lang.IllegalArgumentException - If elements is null
Method Detail

getVariables

public java.util.Collection getVariables()
Get the variables collected by the visitor. This should best be called after the visitor has been run on the language object tree.

Returns:
Collection of ElementSymbol

visit

public void visit(ElementSymbol obj)
Visit a language object and collect symbols. This method should NOT be called directly.

Overrides:
visit in class LanguageVisitor
Parameters:
obj - Language object

getVariables

public static final void getVariables(LanguageObject obj,
                                      java.util.Collection variables)
Helper to quickly get the variables from obj in the variables collection

Parameters:
obj - Language object
variables - Collection to collect variables in

getVariables

public static final java.util.Collection getVariables(LanguageObject obj,
                                                      boolean removeDuplicates)
Helper to quickly get the variables from obj in a collection. The removeDuplicates flag affects whether duplicate variables will be filtered out.

Parameters:
obj - Language object
removeDuplicates - True to remove duplicates
Returns:
Collection of ElementSymbol


Copyright © 2009. All Rights Reserved.