Just in case, try to load the generated class first.

We might have generated it from a previous run.
This commit is contained in:
Kristian S. Stangeland 2012-09-27 06:04:29 +02:00
parent 42303ae0fc
commit 2012698275
1 changed files with 12 additions and 2 deletions

View File

@ -42,7 +42,7 @@ import net.sf.cglib.asm.*;
// case 6: return (TField) (Object) target.g;
// case 7: return (TField) (Object) target.h;
// default:
// throw new IllegalArgumentException("Invalid index " + fieldIndex);
// throw new FieldAccessException("Invalid index " + fieldIndex);
// }
// }
//
@ -61,7 +61,7 @@ import net.sf.cglib.asm.*;
// case 6: target.g = (Byte) value; break;
// case 7: target.h = (Integer) value; break;
// default:
// throw new IllegalArgumentException("Invalid index " + index);
// throw new FieldAccessException("Invalid index " + index);
// }
//
// // Chaining
@ -181,6 +181,16 @@ public final class StructureCompiler {
String targetSignature = Type.getDescriptor(targetType);
String targetName = targetType.getName().replace('.', '/');
try {
// This class might have been generated before. Try to load it.
Class<?> before = loader.loadClass(PACKAGE_NAME.replace('/', '.') + "." + className);
if (before != null)
return before;
} catch (ClassNotFoundException e) {
// That's ok.
}
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, PACKAGE_NAME + "/" + className,
"<TField:Ljava/lang/Object;>L" + COMPILED_CLASS + "<TTField;>;",
COMPILED_CLASS, null);