import edu.neu.ccs.demeterf.*; import edu.neu.ccs.demeter.Ident; // to compute the supertype of a class look // underlying traversal visits entire class graph // inefficient because no traversal control is used // combine methods send the supertype up the class graph public class SuperType extends ID{ String look; SuperType(String s){ look = s; } // passing down the containing object Object update(Object o, Object prev){ return o; } // use apply for leafs String apply(TypeName i){ return (""+i).equals(look)?""+i:""; } // s for subtypes, c for enclosing ClassDef // structural assumption: enclosing class of Abstract is ClassDef // if subtraversal found a match, pass up name of class definition String combine(Abstract a, String s, ClassDef c){ return (s.equals(""))?s:c.name.toString(); } // n for name, d for decl, only interested in decl String combine(ClassDef c, Object n, String d){ return d; } String combine(ConsList c, String f, String r){ return r.equals("")?f:r; } // used for Concrete: does not contribute to superclass computation String combine(Object c){ return ""; } }