/** * Adds residency/update/swizzle checks to all of the methods in a given class. * * @param context Information about all the classes we're dealing with * @param info Information about the class we're decorating */ private static void decorateClass(final EditorContext context, final ClassInfo info) { final ClassFile classFile = (ClassFile) info; // Check to see if the class file is up-to-date if (!Main.FORCE) { final File source = classFile.file(); final File target = classFile.outputFile(); if ((source != null) && (target != null) && source.exists() && target.exists() && (source.lastModified() < target.lastModified())) { if (Main.VERBOSE > 1) { System.out.println(classFile.name() + " is up to date"); } return; } } if (Main.VERBOSE > 2) { classFile.print(System.out); } final ClassEditor c = context.editClass(info); boolean skip = false; final String name = c.type().className(); final String qual = c.type().qualifier() + "/*"; // Edit only classes explicitly mentioned. if (Main.ONLY.size() > 0) { skip = true; // Only edit classes we explicitly don't name. for (int i = 0; i < Main.ONLY.size(); i++) { final String pkg = (String) Main.ONLY.get(i); if (name.equals(pkg) || qual.equals(pkg)) { skip = false; break; } } } // Don't edit classes we explicitly skip. if (!skip) { for (int i = 0; i < Main.SKIP.size(); i++) { final String pkg = (String) Main.SKIP.get(i); if (name.equals(pkg) || qual.equals(pkg)) { skip = true; break; } } } if (skip) { if (Main.VERBOSE > 0) { System.out.println("Skipping " + c.type().className()); } context.release(info); return; } if (Main.VERBOSE > 0) { System.out.println("Decorating class " + c.type().className()); } if (Main.VERBOSE > 2) { ((ClassFile) info).print(System.out); } final MethodInfo[] methods = c.methods(); // Add residency checks (via transform()) to each method in the class for (int j = 0; j < methods.length; j++) { MethodEditor m; try { m = context.editMethod(methods[j]); } catch (final ClassFormatException ex) { System.err.println(ex.getMessage()); continue; } Main.transform(m); context.commit(methods[j]); } context.commit(info); }