// This file is copyrighted and is part of nzdis-oql package. // See the file LICENSE for copyright information and the terms and conditions for copying, distributing and modifications of nzdis-oql package. // @copyright@ package nzdis.lang.oql; /**/ import nzdis.lang.oql.analysis.DepthFirstAdapter; import nzdis.lang.oql.node.*; import java.util.Hashtable; import java.util.Vector; /** * Projection names extractor. Traverses the AST and collects all the * references to names declared in projection nodes. * works fine with identifiers and structs. Need to be extended for * different projections. Do not cope yet with star (*) projections. * *@author Mariusz Nowostawski *@version @version@ $Revision: 1.1 $ */ class ProjectionNamesWalker extends DepthFirstAdapter { /** * Projection names index by appropriate nodes. */ private Hashtable list = new Hashtable(); private Vector names = new Vector(); private Node root = null; /** Returns the variable hash. */ public Hashtable getList(){ return this.list; } /** Returns variable names only. */ public Vector getNames(){ return this.names; } public void inAIdentifierExpr(AIdentifierExpr node){ if(this.root == null) this.root = node; } public void outAIdentifierExpr(AIdentifierExpr node){ if(root == node) { String name = node.getIdentifier().getText().trim(); this.list.put(node, name); this.names.addElement(name); } } public void inANewStructExpr(ANewStructExpr node){ if(this.root == null) this.root = node; } public void outANewStructExpr(ANewStructExpr node){ if(root == node) node.apply(new FieldWalker()); } /** Field walker for projections. */ class FieldWalker extends DepthFirstAdapter { public void outAField(AField node){ String name = node.getIdentifier().getText().trim(); list.put(node.getExpr(), name); names.addElement(name); } }// FieldWalker }// ProjectionNamesWalker