/** * @return an array of ASM internal names of the type */ public static String[] getClassInternalNames(ClassNode[] names) { int size = names.length; String[] answer = new String[size]; for (int i = 0; i < size; i++) { answer[i] = getClassInternalName(names[i]); } return answer; }
private String[] buildExceptions(ClassNode[] exceptions) { if (exceptions == null) return null; String[] ret = new String[exceptions.length]; for (int i = 0; i < exceptions.length; i++) { ret[i] = BytecodeHelper.getClassInternalName(exceptions[i]); } return ret; }
/** * @return an array of ASM internal names of the type */ public static String[] getClassInternalNames(ClassNode[] names) { int size = names.length; String[] answer = new String[size]; for (int i = 0; i < size; i++) { answer[i] = getClassInternalName(names[i]); } return answer; }
private String[] buildExceptions(ClassNode[] exceptions) { if (exceptions == null) return null; String[] ret = new String[exceptions.length]; for (int i = 0; i < exceptions.length; i++) { ret[i] = BytecodeHelper.getClassInternalName(exceptions[i]); } return ret; }
/** * @return an array of ASM internal names of the type */ public static String[] getClassInternalNames(ClassNode[] names) { int size = names.length; String[] answer = new String[size]; for (int i = 0; i < size; i++) { answer[i] = getClassInternalName(names[i]); } return answer; }
private String getClassName() { String className; if (!classNode.isInterface() || interfaceClassLoadingClass == null) { className = internalClassName; } else { className = BytecodeHelper.getClassInternalName(interfaceClassLoadingClass); } return className; }
public static String getClassInternalName(ClassNode t) { if (t.isPrimaryClassNode()) { return getClassInternalName(t.getName()); } return getClassInternalName(t.getTypeClass()); }
/** * Generates the bytecode to autobox the current value on the stack */ public void box(Class type) { if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) { String returnString = "(" + getTypeDescription(type) + ")Ljava/lang/Object;"; mv.visitMethodInsn(INVOKESTATIC, getClassInternalName(DefaultTypeTransformation.class.getName()), "box", returnString); } }
/** * Generates the bytecode to autobox the current value on the stack */ public void box(Class type) { if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) { String returnString = "(" + getTypeDescription(type) + ")Ljava/lang/Object;"; mv.visitMethodInsn(INVOKESTATIC, getClassInternalName(DefaultTypeTransformation.class.getName()), "box", returnString); } }
public static String getClassInternalName(ClassNode t) { if (t.isPrimaryClassNode()) { return getClassInternalName(t.getName()); } return getClassInternalName(t.getTypeClass()); }
public void doCast(Class type) { if (type != Object.class) { if (type.isPrimitive() && type != Void.TYPE) { unbox(type); } else { mv.visitTypeInsn( CHECKCAST, type.isArray() ? getTypeDescription(type) : getClassInternalName(type.getName())); } } }
/** * Generates the bytecode to autobox the current value on the stack */ public void box(Class type) { if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) { String returnString = "(" + getTypeDescription(type) + ")Ljava/lang/Object;"; mv.visitMethodInsn(INVOKESTATIC, getClassInternalName(DefaultTypeTransformation.class.getName()), "box", returnString); } }
public void quickUnboxIfNecessary(ClassNode type) { if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) { // todo care when BigDecimal or BigIneteger on stack ClassNode wrapper = ClassHelper.getWrapper(type); String internName = getClassInternalName(wrapper); if (type == ClassHelper.boolean_TYPE) { mv.visitTypeInsn(CHECKCAST, internName); mv.visitMethodInsn(INVOKEVIRTUAL, internName, type.getName() + "Value", "()" + getTypeDescription(type)); } else { // numbers mv.visitTypeInsn(CHECKCAST, "java/lang/Number"); mv.visitMethodInsn(INVOKEVIRTUAL, /*internName*/"java/lang/Number", type.getName() + "Value", "()" + getTypeDescription(type)); } } }
public void doCast(ClassNode type) { if (type == ClassHelper.OBJECT_TYPE) return; if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) { unbox(type); } else { mv.visitTypeInsn( CHECKCAST, type.isArray() ? getTypeDescription(type) : getClassInternalName(type)); } }
public void visit(MethodVisitor mv) { if (field.isStatic()) { mv.visitFieldInsn(GETSTATIC, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } else { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } final BytecodeHelper helper = new BytecodeHelper(mv); helper.doReturn(field.getType()); } });
private void addGeneratedClosureConstructorCall(ConstructorCallExpression call) { mv.visitVarInsn(ALOAD, 0); ClassNode callNode = classNode.getSuperClass(); TupleExpression arguments = (TupleExpression) call.getArguments(); if (arguments.getExpressions().size()!=2) throw new GroovyBugError("expected 2 arguments for closure constructor super call, but got"+arguments.getExpressions().size()); arguments.getExpression(0).visit(this); arguments.getExpression(1).visit(this); Parameter p = new Parameter(ClassHelper.OBJECT_TYPE,"_p"); String descriptor = helper.getMethodDescriptor(ClassHelper.VOID_TYPE, new Parameter[]{p,p}); mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(callNode), "<init>", descriptor); }
private void addGeneratedClosureConstructorCall(ConstructorCallExpression call) { mv.visitVarInsn(ALOAD, 0); ClassNode callNode = classNode.getSuperClass(); TupleExpression arguments = (TupleExpression) call.getArguments(); if (arguments.getExpressions().size()!=2) throw new GroovyBugError("expected 2 arguments for closure constructor super call, but got"+arguments.getExpressions().size()); arguments.getExpression(0).visit(this); arguments.getExpression(1).visit(this); Parameter p = new Parameter(ClassHelper.OBJECT_TYPE,"_p"); String descriptor = helper.getMethodDescriptor(ClassHelper.VOID_TYPE, new Parameter[]{p,p}); mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(callNode), "<init>", descriptor); }
public void doCast(ClassNode type) { if (type == ClassHelper.OBJECT_TYPE) return; if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) { unbox(type); } else { mv.visitTypeInsn( CHECKCAST, type.isArray() ? getTypeDescription(type) : getClassInternalName(type)); } }
private void addGeneratedClosureConstructorCall(ConstructorCallExpression call) { mv.visitVarInsn(ALOAD, 0); ClassNode callNode = classNode.getSuperClass(); TupleExpression arguments = (TupleExpression) call.getArguments(); if (arguments.getExpressions().size()!=2) throw new GroovyBugError("expected 2 arguments for closure constructor super call, but got"+arguments.getExpressions().size()); arguments.getExpression(0).visit(this); arguments.getExpression(1).visit(this); Parameter p = new Parameter(ClassHelper.OBJECT_TYPE,"_p"); String descriptor = helper.getMethodDescriptor(ClassHelper.VOID_TYPE, new Parameter[]{p,p}); mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(callNode), "<init>", descriptor); }
public void quickUnboxIfNecessary(ClassNode type) { if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) { // todo care when BigDecimal or BigIneteger on stack ClassNode wrapper = ClassHelper.getWrapper(type); String internName = getClassInternalName(wrapper); if (type == ClassHelper.boolean_TYPE) { mv.visitTypeInsn(CHECKCAST, internName); mv.visitMethodInsn(INVOKEVIRTUAL, internName, type.getName() + "Value", "()" + getTypeDescription(type)); } else { // numbers mv.visitTypeInsn(CHECKCAST, "java/lang/Number"); mv.visitMethodInsn(INVOKEVIRTUAL, /*internName*/"java/lang/Number", type.getName() + "Value", "()" + getTypeDescription(type)); } } }