final String outputDirectory,
final Log logger)
throws SCRDescriptorException {
// now do byte code manipulation
final String fileName = outputDirectory + File.separatorChar + className.replace('.', File.separatorChar) + ".class";
final ClassNode cn = new ClassNode();
try {
final ClassReader reader = new ClassReader(new FileInputStream(fileName));
reader.accept(cn, 0);
// For target Java7 and above use: ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES
final int mask = (cn.version > 50 ? ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES : 0);
final ClassWriter writer = new ClassWriter(mask) {
@Override
protected String getCommonSuperClass(final String type1, final String type2) {
Class<?> c, d;
try {
c = classLoader.loadClass(type1.replace('/', '.'));
d = classLoader.loadClass(type2.replace('/', '.'));
} catch (final Exception e) {
throw new RuntimeException(e.toString(), e);
}
if (c.isAssignableFrom(d)) {
return type1;
}
if (d.isAssignableFrom(c)) {
return type2;
}
if (c.isInterface() || d.isInterface()) {
return "java/lang/Object";
}
do {
c = c.getSuperclass();
} while (!c.isAssignableFrom(d));
return c.getName().replace('.', '/');
}
};
cn.accept(writer);
if ( createBind ) {
logger.debug("Adding bind " + className + " " + fieldName);
createMethod(writer, className, referenceName, fieldName, typeName, true);
}