t3 = new Stopwatch().start();
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
ClassVisitor remappingAdapter = new RemappingClassAdapter(cw, remapper);
MergeAdapter mergingAdapter = new MergeAdapter(oldTemplateSlashName, materializedSlashName, remappingAdapter,
impl);
ClassReader tReader = new ClassReader(templateClass);
tReader.accept(mergingAdapter, ClassReader.EXPAND_FRAMES);
byte[] outputClass = cw.toByteArray();
// Files.write(outputClass, new File(String.format("/tmp/%d-output.class", fileNum)));
outputClass = cw.toByteArray();
// Load the class
classLoader.injectByteCode(materializedClassName, outputClass);
}
t3.stop();
Stopwatch t4 = new Stopwatch().start();
int i = 0;
for (String s : remapper.getSubclasses()) {
logger.debug("Setting up sub class {}", s);
// for each sub class, remap them into the new class.
String subclassPath = FileUtils.separator + s + ".class";
final byte[] bytecode = getClassByteCodeFromPath(subclassPath);
RemapClasses localRemapper = new RemapClasses(oldTemplateSlashName, materializedSlashName);
Preconditions.checkArgument(localRemapper.getSubclasses().isEmpty(), "Class transformations are only supported for classes that have a single level of inner classes.");
ClassWriter subcw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
ClassVisitor remap = new RemappingClassAdapter(subcw, localRemapper);
ClassReader reader = new ClassReader(bytecode);
reader.accept(remap, ClassReader.EXPAND_FRAMES);
byte[] newByteCode = subcw.toByteArray();
classLoader.injectByteCode(s.replace(oldTemplateSlashName, materializedSlashName).replace(FileUtils.separatorChar, '.'), newByteCode);
// Files.write(subcw.toByteArray(), new File(String.format("/tmp/%d-sub-%d.class", fileNum, i)));