@Override protected void createInstanceVariables(ClassWriter cw, Class<?> classToProxy, String classFileName) { // variable #1, the Provider<?> for the Contextual Instance cw.visitField(Opcodes.ACC_PRIVATE, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class), null, null).visitEnd(); // variable #2, the Method[] for all protected methods cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, FIELD_PROTECTED_METHODS, Type.getDescriptor(Method[].class), null, null).visitEnd(); }
@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(); }
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); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", descriptor, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, parentClassFileName, "<init>", descriptor, false); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTFIELD, proxyClassFileName, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTFIELD, proxyClassFileName, FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class)); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(-1, -1); mv.visitEnd();
throws ProxyGenerationException ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); 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); cw.visit(findJavaVersion(classToProxy), Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames); cw.visitSource(classFileName + ".java", null); cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, FIELD_BEAN_PASSIVATION_ID, Type.getDescriptor(String.class), null, null).visitEnd(); return cw.toByteArray();
public String getType() { // if this method starts to be used internally move this to constructors and just return type final Type t = Type.getType(type); if (t.getClassName() == null) { return t.getDescriptor(); } return t.getClassName(); }
protected void readClassDef(InputStream in, String path) throws IOException { ClassReader classReader = new ClassReader(in); classReader.accept(new InfoBuildingVisitor(path), ASM_FLAGS); }
public AnnotationInfo(Annotation annotation) { this(Type.getType(annotation.annotationType()).getDescriptor()); }
private void pushIntOntoStack(final MethodVisitor mv, final int i) { if (i == 0) { mv.visitInsn(ICONST_0); } else if (i == 1) { mv.visitInsn(ICONST_1); } else if (i == 2) { mv.visitInsn(ICONST_2); } else if (i == 3) { mv.visitInsn(ICONST_3); } else if (i == 4) { mv.visitInsn(ICONST_4); } else if (i == 5) { mv.visitInsn(ICONST_5); } else if (i > 5 && i <= 255) { mv.visitIntInsn(BIPUSH, i); } else { mv.visitIntInsn(SIPUSH, i); } }
public MethodInfo(ClassInfo info, Method method) { super(method); this.declaringClass = info; this.name = method.getName(); this.descriptor = Type.getMethodDescriptor(method); this.method = method; }
public MethodInfo(ClassInfo info, Constructor constructor) { super(constructor); this.declaringClass = info; this.name = "<init>"; this.descriptor = Type.getConstructorDescriptor(constructor); }
protected void generateReturn(MethodVisitor mv, Method delegatedMethod) { Class<?> returnType = delegatedMethod.getReturnType(); mv.visitInsn(getReturnInsn(returnType)); }
private String getCastType(final Class<?> returnType) { if (returnType.isPrimitive()) { return getWrapperType(returnType); } return Type.getInternalName(returnType); }
if (classToProxy.isInterface()) parentClassFileName = Type.getInternalName(Object.class); superDefaultCt = Object.class.getConstructor(null); String descriptor = Type.getConstructorDescriptor(superDefaultCt); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", descriptor, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, parentClassFileName, "<init>", descriptor, false); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTFIELD, proxyClassFileName, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class)); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(-1, -1); mv.visitEnd();
@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(); }
public AnnotationInfo(String name) { final Type type = Type.getType(name); name = type.getClassName(); if (name == null) { name = type.getDescriptor(); // name was already a class name } this.name = name; }
protected void readClassDef(InputStream in) throws IOException { try { ClassReader classReader = new ClassReader(in); classReader.accept(new InfoBuildingVisitor(), ASM_FLAGS); } finally { in.close(); } }
@Override protected void createInstanceVariables(ClassWriter cw, Class<?> classToProxy, String classFileName) { // variable #1, the delegation point cw.visitField(Opcodes.ACC_PRIVATE, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy), null, null).visitEnd(); // variable #2, the invocation handler cw.visitField(Opcodes.ACC_PRIVATE, FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class), null, null).visitEnd(); // variable #3, the Method[] of all intercepted methods. cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, FIELD_INTERCEPTED_METHODS, Type.getDescriptor(Method[].class), null, null).visitEnd(); }
public FieldInfo(ClassInfo info, Field field) { super(field); this.declaringClass = info; this.name = field.getName(); this.type = Type.getType(field.getType()).getDescriptor(); this.field = field; }
mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ICONST_2); mv.visitInsn(Opcodes.ICONST_3); mv.visitInsn(Opcodes.ICONST_4); mv.visitInsn(Opcodes.ICONST_5); mv.visitIntInsn(Opcodes.BIPUSH, i); mv.visitIntInsn(Opcodes.SIPUSH, i);