package natlab.toolkits.analysis.core;

import java.util.Set;

import natlab.toolkits.analysis.HashSetFlowSet;
import analysis.AbstractDepthFirstAnalysis;
import ast.ASTNode;
import ast.AssignStmt;
import ast.CellIndexExpr;
import ast.DotExpr;
import ast.Function;
import ast.GlobalStmt;
import ast.Name;
import ast.ParameterizedExpr;

/**
 * @author Jesse Doherty
 */
public class NameCollector extends AbstractDepthFirstAnalysis<HashSetFlowSet<Name>>
{
    protected HashSetFlowSet<Name> fullSet;
    protected boolean inLHS = false;

    public NameCollector(ASTNode<?> tree)
    {
        super(tree);
        fullSet = new HashSetFlowSet<Name>();
    }

    public HashSetFlowSet<Name> newInitialFlow()
    {
        return new HashSetFlowSet<Name>();
    }

    public Set<Name> getAllNames()
    {
        return fullSet.getSet();
    }
    public Set<Name> getNames( AssignStmt node )
    {
        HashSetFlowSet<Name> set = flowSets.get(node);
        if( set == null )
            return null;
        else
            return set.getSet();
    }

    public void caseName( Name node )
    {
        if( inLHS )
            currentSet.add(node);
    }

    public void caseAssignStmt( AssignStmt node )
    {
        inLHS = true;
        currentSet = newInitialFlow();
        analyze( node.getLHS() );
        flowSets.put(node,currentSet);
        fullSet.addAll( currentSet );
        inLHS = false;
    }

    public void caseParameterizedExpr( ParameterizedExpr node )
    {
        analyze(node.getTarget());
    }

    public void caseCellIndexExpr(CellIndexExpr node) {
      analyze(node.getTarget());
    }

    public void caseDotExpr(DotExpr node) {
      analyze(node.getTarget());
    }
    
    public void caseFunction(Function f) {
      for (Name name : f.getInputParams()) {
        currentSet.add(name);
      }
      fullSet.addAll(currentSet);
      analyze(f.getStmts());
      analyze(f.getNestedFunctions());
    }
    
    public void caseGlobalStmt(GlobalStmt node) {
      for (Name name : node.getNames()) {
        currentSet.add(name);
      }
      fullSet.addAll(currentSet);
    }
}

@@ -60,56 +60,8 @@
 t;%0A%0A
-import natlab.toolkits.analysis.HashSetFlowSet;%0A
 impo
@@ -281,16 +281,56 @@
 dExpr;%0A%0A
+import com.google.common.collect.Sets;%0A%0A
 /**%0A * @
@@ -416,27 +416,16 @@
 nalysis%3C
-HashSetFlow
 Set%3CName
@@ -443,27 +443,16 @@
 otected 
-HashSetFlow
 Set%3CName
@@ -594,62 +594,55 @@
  new
- HashSetFlowSet%3CName%3E();%0A    %7D%0A%0A    public HashSetFlow
+InitialFlow();%0A    %7D%0A%0A    @Override%0A    public 
 Set%3C
@@ -689,32 +689,23 @@
 urn 
+Sets.
 new
- 
 HashSet
-FlowSet%3CName%3E
 ();%0A
@@ -774,25 +774,16 @@
  fullSet
-.getSet()
 ;%0A    %7D%0A
@@ -847,160 +847,55 @@
     
-  HashSetFlowSet%3CName%3E set = flowSets.get(node);%0A        if( set == null )%0A            return null;%0A        else%0A            return set.getSet();%0A    %7D%0A
+return flowSets.get(node);%0A    %7D%0A%0A    @Override
 %0A   
@@ -988,32 +988,46 @@
 d(node);%0A    %7D%0A%0A
+    @Override%0A
     public void 
@@ -1260,32 +1260,46 @@
 = false;%0A    %7D%0A%0A
+    @Override%0A
     public void 
@@ -1386,32 +1386,46 @@
 rget());%0A    %7D%0A%0A
+    @Override%0A
     public void 
@@ -1496,32 +1496,46 @@
 rget());%0A    %7D%0A%0A
+    @Override%0A
     public void 
@@ -1598,32 +1598,46 @@
 ());%0A    %7D%0A    %0A
+    @Override%0A
     public void 
@@ -1855,24 +1855,38 @@
 %0A    %7D%0A    %0A
+    @Override%0A
     public v

Use Set instead of HashSetFlowSet in NameCollector