public DirectedGraph<Node, Edge> convert() { DirectedGraph<Node, Edge> graph = new SimpleDirectedGraph<Node, Edge>(Edge.factory); // Add vertices for (Type t : hierarchy) graph.addVertex(Node.get(t)); // Add edges for (Type t : hierarchy) { for (Type i : hierarchy.getInterfaces(t)) { graph.addVertex(Node.get(i)); graph.addEdge(Node.get(t), Node.get(i)); } Type sc = hierarchy.getSuperclass(t); if (sc == null) { assert t.equals(OBJECT) : t; continue; } graph.addVertex(Node.get(sc)); graph.addEdge(Node.get(t), Node.get(sc)); } // Check for cycles if (new CycleDetector<Node, Edge>(graph).detectCycles()) throw new CyclicHierarchyException(graph.toString()); return graph; }
public String toString() { if (type != null) { return type + "(" + id + ")"; } if (this == ClassHierarchy.v().TOP) { return "TOP" + "(" + id + ")"; } if (this == ClassHierarchy.v().R0_1) { return "R0_1" + "(" + id + ")"; } if (this == ClassHierarchy.v().R0_127) { return "R0_127" + "(" + id + ")"; } if (this == ClassHierarchy.v().R0_32767) { return "R0_32767" + "(" + id + ")"; } return "ERROR!!!!"; }
/** * Parse the command line. Inserts residency, update, and swizzle checks into the bytecode of the * methods of the specified classes. */ public static void main(final String[] args) { final ClassFileLoader loader = new ClassFileLoader(); List classes = new ArrayList(); // Names of classes from command line boolean gotdir = false; // Did user specify an output dir? for (int i = 0; i < args.length; i++) { if (args[i].equals("-v") || args[i].equals("-verbose")) { Main.VERBOSE++; } else if (args[i].equals("-help")) { Main.usage(); } else if (args[i].equals("-classpath")) { if (++i >= args.length) { Main.usage(); } final String classpath = args[i]; loader.setClassPath(classpath); } else if (args[i].equals("-skip")) { if (++i >= args.length) { Main.usage(); } final String pkg = args[i].replace('.', '/'); Main.SKIP.add(pkg); } else if (args[i].equals("-only")) { if (++i >= args.length) { Main.usage(); } final String pkg = args[i].replace('.', '/'); Main.ONLY.add(pkg); } else if (args[i].equals("-closure")) { Main.CLOSURE = true; } else if (args[i].equals("-relax-loading")) { ClassHierarchy.RELAX = true; } else if (args[i].equals("-f")) { Main.FORCE = true; } else if (args[i].equals("-norc")) { Main.RC = false; } else if (args[i].equals("-rc")) { Main.RC = true; } else if (args[i].equals("-nouc")) { Main.UC = false; } else if (args[i].equals("-uc")) { Main.UC = true; } else if (args[i].equals("-nosc")) { Main.SC = false; } else if (args[i].equals("-sc")) { Main.SC = true; } else if (args[i].startsWith("-")) { Main.usage(); } else if (i == args.length - 1) { // Last argument is the name of the outpu directory final File f = new File(args[i]); if (f.exists() && !f.isDirectory()) { System.err.println("No such directory: " + f.getPath()); System.exit(2); } loader.setOutputDir(f); gotdir = true; } else { classes.add(args[i]); } } if (!gotdir) { Main.usage(); } if (classes.size() == 0) { Main.usage(); } if (Main.VERBOSE > 3) { ClassFileLoader.DEBUG = true; ClassEditor.DEBUG = true; } boolean errors = false; final Iterator iter = classes.iterator(); // Load each class specified on the command line while (iter.hasNext()) { final String name = (String) iter.next(); try { loader.loadClass(name); } catch (final ClassNotFoundException ex) { System.err.println("Couldn't find class: " + ex.getMessage()); errors = true; } } if (errors) { System.exit(1); } final BloatContext context = new CachingBloatContext(loader, classes, Main.CLOSURE); if (!Main.CLOSURE) { final Iterator e = classes.iterator(); while (e.hasNext()) { final String name = (String) e.next(); try { final ClassInfo info = loader.loadClass(name); Main.decorateClass(context, info); } catch (final ClassNotFoundException ex) { System.err.println("Couldn't find class: " + ex.getMessage()); System.exit(1); } } } else { classes = null; final ClassHierarchy hier = context.getHierarchy(); final Iterator e = hier.classes().iterator(); while (e.hasNext()) { final Type t = (Type) e.next(); if (t.isObject()) { try { final ClassInfo info = loader.loadClass(t.className()); Main.decorateClass(context, info); } catch (final ClassNotFoundException ex) { System.err.println("Couldn't find class: " + ex.getMessage()); System.exit(1); } } } } }
public TypeNode lca_2(TypeNode typeNode) { return ClassHierarchy.v().lca_2(id, typeNode.id); }
public boolean hasAncestor_2(TypeNode typeNode) { if (typeNode == this) return true; return ClassHierarchy.v().hasAncestor_2(id, typeNode.id); }
public TypeNode gcd_1(TypeNode typeNode) { return ClassHierarchy.v().gcd_1(id, typeNode.id); }