use of org.mvel2.asm.ClassWriter in project drools by kiegroup.
the class ClassFieldAccessorFactory method dumpWriter.
private static byte[] dumpWriter(final Class<?> originalClass, final String className, final Method getterMethod, final Class<?> fieldType) throws Exception {
final Class<?> superClass = getWriterSuperClassFor(fieldType);
final ClassWriter cw = buildClassHeader(superClass, className);
build3ArgConstructor(superClass, className, cw);
buildSetMethod(originalClass, className, superClass, getterMethod, fieldType, cw);
cw.visitEnd();
return cw.toByteArray();
}
use of org.mvel2.asm.ClassWriter in project drools by kiegroup.
the class ClassFieldAccessorFactory method dumpReader.
private static byte[] dumpReader(final Class<?> originalClass, final String className, final Method getterMethod, final Class<?> fieldType) throws Exception {
final Class<?> superClass = getReaderSuperClassFor(fieldType);
final ClassWriter cw = buildClassHeader(superClass, className);
build3ArgConstructor(superClass, className, cw);
buildGetMethod(originalClass, className, superClass, getterMethod, cw);
cw.visitEnd();
return cw.toByteArray();
}
use of org.mvel2.asm.ClassWriter in project drools by kiegroup.
the class ClassFieldAccessorFactory method buildGetMethod.
/**
* Creates the proxy reader method for the given method
*/
protected static void buildGetMethod(final Class<?> originalClass, final String className, final Class<?> superClass, final Method getterMethod, final ClassWriter cw) {
final Class<?> fieldType = getterMethod.getReturnType();
Method overridingMethod;
try {
overridingMethod = superClass.getMethod(getOverridingGetMethodName(fieldType), InternalWorkingMemory.class, Object.class);
} catch (final Exception e) {
throw new RuntimeException("This is a bug. Please report back to JBoss Rules team.", e);
}
final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, overridingMethod.getName(), Type.getMethodDescriptor(overridingMethod), null, null);
mv.visitCode();
final Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(Opcodes.ALOAD, 2);
mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(originalClass));
if (originalClass.isInterface()) {
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(originalClass), getterMethod.getName(), Type.getMethodDescriptor(getterMethod));
} else {
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(originalClass), getterMethod.getName(), Type.getMethodDescriptor(getterMethod));
}
mv.visitInsn(Type.getType(fieldType).getOpcode(Opcodes.IRETURN));
final Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
mv.visitLocalVariable("workingMemory", Type.getDescriptor(InternalWorkingMemory.class), null, l0, l1, 1);
mv.visitLocalVariable("object", Type.getDescriptor(Object.class), null, l0, l1, 2);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.mvel2.asm.ClassWriter in project drools by kiegroup.
the class ClassFieldAccessorFactory method dumpReader.
private static byte[] dumpReader(final Class<?> originalClass, final String className, final Method getterMethod, final Class<?> fieldType) throws Exception {
final Class<?> superClass = getReaderSuperClassFor(fieldType);
final ClassWriter cw = buildClassHeader(superClass, className);
build3ArgConstructor(superClass, className, cw);
buildGetMethod(originalClass, className, superClass, getterMethod, cw);
cw.visitEnd();
return cw.toByteArray();
}
use of org.mvel2.asm.ClassWriter in project drools by kiegroup.
the class ClassFieldAccessorFactory method buildClassHeader.
/**
* Builds the class header
*/
protected static ClassWriter buildClassHeader(Class<?> superClass, String className) {
ClassWriter cw = createClassWriter(superClass.getClassLoader(), Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className, null, Type.getInternalName(superClass), null);
cw.visitSource(null, null);
return cw;
}
Aggregations