/** * Create the JVM signature descriptor for a constructor. This consists of the * descriptors for the constructor parameters surrounded with parentheses, followed by * the descriptor for the return type, which is always "V". Note the * descriptors here are JVM descriptors, unlike the other descriptor forms the * compiler is using which do not include the trailing semicolon. * @param ctor the constructor * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Constructor<?> ctor) { Class<?>[] params = ctor.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")V"); return sb.toString(); }
/** * Create the JVM signature descriptor for a method. This consists of the descriptors * for the method parameters surrounded with parentheses, followed by the * descriptor for the return type. Note the descriptors here are JVM descriptors, * unlike the other descriptor forms the compiler is using which do not include the * trailing semicolon. * @param method the method * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Method method) { Class<?>[] params = method.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")"); sb.append(toJvmDescriptor(method.getReturnType())); return sb.toString(); }
/** * Create the JVM signature descriptor for a method. This consists of the descriptors * for the method parameters surrounded with parentheses, followed by the * descriptor for the return type. Note the descriptors here are JVM descriptors, * unlike the other descriptor forms the compiler is using which do not include the * trailing semicolon. * @param method the method * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Method method) { Class<?>[] params = method.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")"); sb.append(toJvmDescriptor(method.getReturnType())); return sb.toString(); }
/** * Create the JVM signature descriptor for a constructor. This consists of the * descriptors for the constructor parameters surrounded with parentheses, followed by * the descriptor for the return type, which is always "V". Note the * descriptors here are JVM descriptors, unlike the other descriptor forms the * compiler is using which do not include the trailing semicolon. * @param ctor the constructor * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Constructor<?> ctor) { Class<?>[] params = ctor.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")V"); return sb.toString(); }
@Override public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) { boolean isStatic = Modifier.isStatic(this.member.getModifiers()); String descriptor = cf.lastDescriptor(); String classDesc = this.member.getDeclaringClass().getName().replace('.', '/'); if (!isStatic) { if (descriptor == null) { cf.loadTarget(mv); } if (descriptor == null || !classDesc.equals(descriptor.substring(1))) { mv.visitTypeInsn(CHECKCAST, classDesc); } } else { if (descriptor != null) { // A static field/method call will not consume what is on the stack, // it needs to be popped off. mv.visitInsn(POP); } } if (this.member instanceof Method) { mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(), CodeFlow.createSignatureDescriptor((Method) this.member), false); } else { mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(), CodeFlow.toJvmDescriptor(((Field) this.member).getType())); } } }
@Override public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) { boolean isStatic = Modifier.isStatic(this.member.getModifiers()); String descriptor = cf.lastDescriptor(); String classDesc = this.member.getDeclaringClass().getName().replace('.', '/'); if (!isStatic) { if (descriptor == null) { cf.loadTarget(mv); } if (descriptor == null || !classDesc.equals(descriptor.substring(1))) { mv.visitTypeInsn(CHECKCAST, classDesc); } } else { if (descriptor != null) { // A static field/method call will not consume what is on the stack, // it needs to be popped off. mv.visitInsn(POP); } } if (this.member instanceof Method) { mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(), CodeFlow.createSignatureDescriptor((Method) this.member), false); } else { mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(), CodeFlow.toJvmDescriptor(((Field) this.member).getType())); } } }
CodeFlow.toJvmDescriptor(((Field) member).getType()));
CodeFlow.toJvmDescriptor(((Field) member).getType()));
/** * Create the JVM signature descriptor for a method. This consists of the descriptors * for the method parameters surrounded with parentheses, followed by the * descriptor for the return type. Note the descriptors here are JVM descriptors, * unlike the other descriptor forms the compiler is using which do not include the * trailing semicolon. * @param method the method * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Method method) { Class<?>[] params = method.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")"); sb.append(toJvmDescriptor(method.getReturnType())); return sb.toString(); }
/** * Create the JVM signature descriptor for a constructor. This consists of the * descriptors for the constructor parameters surrounded with parentheses, followed by * the descriptor for the return type, which is always "V". Note the * descriptors here are JVM descriptors, unlike the other descriptor forms the * compiler is using which do not include the trailing semicolon. * @param ctor the constructor * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V") */ public static String createSignatureDescriptor(Constructor<?> ctor) { Class<?>[] params = ctor.getParameterTypes(); StringBuilder sb = new StringBuilder(); sb.append("("); for (Class<?> param : params) { sb.append(toJvmDescriptor(param)); } sb.append(")V"); return sb.toString(); }
@Override public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) { boolean isStatic = Modifier.isStatic(this.member.getModifiers()); String descriptor = cf.lastDescriptor(); String classDesc = this.member.getDeclaringClass().getName().replace('.', '/'); if (!isStatic) { if (descriptor == null) { cf.loadTarget(mv); } if (descriptor == null || !classDesc.equals(descriptor.substring(1))) { mv.visitTypeInsn(CHECKCAST, classDesc); } } else { if (descriptor != null) { // A static field/method call will not consume what is on the stack, // it needs to be popped off. mv.visitInsn(POP); } } if (this.member instanceof Method) { mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(), CodeFlow.createSignatureDescriptor((Method) this.member), false); } else { mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(), CodeFlow.toJvmDescriptor(((Field) this.member).getType())); } } }
CodeFlow.toJvmDescriptor(((Field) member).getType()));