private String getCastType(final Class<?> returnType) { if (returnType.isPrimitive()) { return getWrapperType(returnType); } return Type.getInternalName(returnType); }
/** * Gets the string to use for CHECKCAST instruction, returning the correct value for any type, including primitives and arrays * * @param returnType The type to cast to with CHECKCAST * @return CHECKCAST parameter */ protected String getCastType(Class<?> returnType) { if (returnType.isPrimitive()) { return getWrapperType(returnType); } else { return Type.getInternalName(returnType); } }
final String classFileName = proxyClassName.replace('.', '/'); final String[] interfaceNames = { Type.getInternalName(Serializable.class) }; final String superClassName = Type.getInternalName(classToProxy);
for (int i = 0; i < exceptionTypes.length; i++) exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName(); boolean isItf = delegatedMethod.getDeclaringClass().isInterface(); mv.visitMethodInsn( isItf ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, isItf);
for (int i = 0; i < exceptionTypes.length; i++) exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName(); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Provider.class), "get", "()Ljava/lang/Object;", true); mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(classToProxy)); boolean interfaceMethod = Modifier.isInterface(delegatedMethod.getDeclaringClass().getModifiers()); mv.visitMethodInsn(interfaceMethod ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, interfaceMethod);
String classFileName = classToProxy.getName().replace('.', '/'); String[] interfaceNames = {Type.getInternalName(getMarkerInterface())}; String superClassName = classFileName; interfaceNames = new String[]{Type.getInternalName(classToProxy), interfaceNames[0]}; superClassName = Type.getInternalName(Object.class);
for (int i = 0; i < exceptionTypes.length; i++) exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName(); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, false);
if (classToProxy.isInterface()) parentClassFileName = Type.getInternalName(Object.class); superDefaultCt = Object.class.getConstructor(null); for (int i = 0; i < exceptionTypes.length; i++) exceptions[i] = Type.getInternalName(exceptionTypes[i]);
String[] exceptions = null; if (classToProxy.isInterface()) { parentClassFileName = Type.getInternalName(Object.class); superDefaultCt = Object.class.getConstructor(); } else { exceptions = exceptionTypes.length == 0 ? null : new String[exceptionTypes.length]; for (int i = 0; i < exceptionTypes.length; i++) { exceptions[i] = Type.getInternalName(exceptionTypes[i]);
@Override protected void createSerialisation(ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName) { String[] exceptionTypeNames = {Type.getType(ObjectStreamException.class).getInternalName()}; MethodVisitor mv = cw.visitMethod(Modifier.PUBLIC, "writeReplace", "()Ljava/lang/Object;", null, exceptionTypeNames); // fill method body mv.visitCode(); // load the contextual instance Provider mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class)); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Provider.class), "get", "()Ljava/lang/Object;", true); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(NormalScopeProxyFactory.class), "delegateProtectedMethod", "(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
if (classToProxy.isInterface()) parentClassFileName = Type.getInternalName(Object.class); superDefaultCt = Object.class.getConstructor(null);
@Override protected void createSerialisation(ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName) { String[] exceptionTypeNames = {Type.getType(ObjectStreamException.class).getInternalName()}; MethodVisitor mv = cw.visitMethod(Modifier.PUBLIC, "writeReplace", "()Ljava/lang/Object;", null, exceptionTypeNames); // fill method body mv.visitCode(); // load the contextual instance Provider mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class)); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
private void createSerialisation(final ClassWriter cw, final String pluginId, final String key) { final MethodVisitor mv = cw .visitMethod(Modifier.PUBLIC, "writeReplace", "()Ljava/lang/Object;", null, new String[] { Type.getType(ObjectStreamException.class).getInternalName() }); mv.visitCode(); mv.visitTypeInsn(NEW, "org/talend/sdk/component/runtime/serialization/SerializableService"); mv.visitInsn(DUP); mv.visitLdcInsn(pluginId); mv.visitLdcInsn(key); mv .visitMethodInsn(INVOKESPECIAL, "org/talend/sdk/component/runtime/serialization/SerializableService", "<init>", "(Ljava/lang/String;Ljava/lang/String;)V", false); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
parentClassFileName = Type.getInternalName(Object.class); superDefaultCt = Object.class.getConstructor(null); descriptor = Type.getConstructorDescriptor(superDefaultCt);
.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(InterceptorHandler.class), "invoke", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;", true);
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(InterceptorHandler.class), "invoke", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;", true);