package aspectEditor.aspectEditorUtils;
import java.util.jar.JarFile;
import java.util.*;
import java.io.*;
import edu.neu.ccs.demeter.aplib.*;
import edu.neu.ccs.demeter.*;
class NameMap extends SymbolicNameMap {
  protected NameBinding_Commalist bindings;
  public NameBinding_Commalist get_bindings() { return bindings; }
  public void set_bindings(NameBinding_Commalist new_bindings) { bindings = new_bindings; }
  public NameMap() { super(); }
  public NameMap(NameBinding_Commalist bindings) {
    super();
    set_bindings(bindings);
  }
  public static NameMap parse(java.io.Reader in) throws ParseException { return new Parser(in)._NameMap(); }
  public static NameMap parse(java.io.InputStream in) throws ParseException { return new Parser(in)._NameMap(); }
  public static NameMap parse(String s) {
    try { return parse(new java.io.StringReader(s)); }
    catch (ParseException e) {
      throw new RuntimeException(e.toString());
    }
  }
  public ClassGlobSpec get(String l) {
    return (ClassGlobSpec) get_dict().get(l);
  }
 HashMap dict; 
  HashMap get_dict() {
    if (dict == null) dict = buildDict();
    return dict;
  }
  HashMap buildDict() {
    __V_NameMap_buildDict v0 = new __V_NameMap_buildDict();
    v0.start();
    __trav_buildDict(v0);
    v0.finish();
    return v0.get_return_val();
  }
  void addElement(NameBinding obj) {
    get_dict().put(obj.get_sgName().toString(), obj.get_cgNames());
    if (bindings == null) bindings = new NameBinding_Commalist();
    bindings.addElement(obj);
  }
  static NameMapI compose(NameMapI map1, SymbolicNameMapI map2) {
    final NameMapI N1 = map1;
    final SymbolicNameMapI N2 = map2;
    return new NameMapI() {
	public Collection get(String l, ClassGraphI CG)
	  throws NoSuchClassGraphNodeException
	{
	  ClassGlobSpec N2ret = N2.get(l);
	  if (N2ret == null) return N1.get(l, CG);
	  Collection strings = N2ret.getStrings();
	  if (strings == null) return null;
	  Collection ret = new HashSet();
	  Iterator i = strings.iterator();
	  while (i.hasNext()) {
	    Collection N1ret = N1.get((String) i.next(), CG);
	    if (N1ret == null) return null;
	    ret.addAll(N1ret);
	  }
	  return ret;
	}
	public boolean match(String l, Object cgv)
	{ return N1.match(l, cgv) || N2.match(l, cgv); }
	public boolean match(String l, String cgl)
	{ return N1.match(l, cgl) || N2.match(l, cgl); }
	public String toString()
	{ return N1 + " o " + N2; }
      };	    
  }
  static SymbolicNameMapI compose(SymbolicNameMapI map1, SymbolicNameMapI map2) {
    final SymbolicNameMapI N1 = map1;
    final SymbolicNameMapI N2 = map2;
    return new SymbolicNameMap() {
	public ClassGlobSpec get(String l) {
	  ClassGlobSpec N2ret = N2.get(l);
	  if (N2ret == null) return N1.get(l);
	  Collection strings = N2ret.map(N1);
	  if (strings == null)
	    return OneClassGlob.parse("*");
	  Iterator i = strings.iterator();
	  String s = (String) i.next();
	  if (!i.hasNext()) return OneClassGlob.parse(s);
	  while (i.hasNext()) s += ", " + i.next();
	  return ClassGlobSet.parse("{" + s + "}");
	}
	public String toString()
	{ return N1 + " o " + N2; }
      };	    
  }
  public String toString() {
    return "{ " + (bindings == null? "" : bindings.toString()) + " }";
  }
  void universal_trv0_bef(UniversalVisitor _v_) {
    super.universal_trv0_bef(_v_);
    ((UniversalVisitor) _v_).before(this);
  }

  void universal_trv0_aft(UniversalVisitor _v_) {
    ((UniversalVisitor) _v_).after(this);
    super.universal_trv0_aft(_v_);
  }

  void universal_trv0(UniversalVisitor _v_) {
    universal_trv0_bef(_v_);
    if (bindings != null) {
      ((UniversalVisitor) _v_).before_bindings(this, bindings);
      bindings.universal_trv0(_v_);
      ((UniversalVisitor) _v_).after_bindings(this, bindings);
    }
    super.universal_trv0(_v_);
    universal_trv0_aft(_v_);
  }

  void __trav_toGraph_PathDirective_trv_bef(__V_PathDirective_toGraph __v0) {
    super.__trav_toGraph_PathDirective_trv_bef(__v0);
    ((__V_PathDirective_toGraph) __v0).before(this);
  }

  void __trav_toGraph_PathDirective_trv_aft(__V_PathDirective_toGraph __v0) {
    super.__trav_toGraph_PathDirective_trv_aft(__v0);
  }

  void __trav_toGraph_PathDirective_trv(__V_PathDirective_toGraph __v0) {
    __trav_toGraph_PathDirective_trv_bef(__v0);
    __trav_toGraph_PathDirective_trv_aft(__v0);
  }

  public void __trav_buildDict(__V_NameMap_buildDict __v0) {
    __trav_buildDict_NameMap_trv(__v0);
  }

  void __trav_buildDict_NameMap_trv_bef(__V_NameMap_buildDict __v0) {
    super.__trav_buildDict_NameMap_trv_bef(__v0);
  }

  void __trav_buildDict_NameMap_trv_aft(__V_NameMap_buildDict __v0) {
    super.__trav_buildDict_NameMap_trv_aft(__v0);
  }

  void __trav_buildDict_NameMap_trv(__V_NameMap_buildDict __v0) {
    __trav_buildDict_NameMap_trv_bef(__v0);
    if (bindings != null) {
      bindings.__trav_buildDict_NameMap_trv(__v0);
    }
    __trav_buildDict_NameMap_trv_aft(__v0);
  }

}
