/** Prepares return value. */
 public static void prepareReturnValue(
     MethodVisitor mv, MethodSignatureVisitor msign, int varOffset) {
   varOffset += msign.getAllArgumentsSize();
   switch (msign.getReturnOpcodeType()) {
     case 'V':
       mv.visitInsn(ACONST_NULL);
       break;
     case 'B':
       AsmUtil.valueOfByte(mv);
       break;
     case 'C':
       AsmUtil.valueOfCharacter(mv);
       break;
     case 'S':
       AsmUtil.valueOfShort(mv);
       break;
     case 'I':
       AsmUtil.valueOfInteger(mv);
       break;
     case 'Z':
       AsmUtil.valueOfBoolean(mv);
       break;
     case 'J':
       AsmUtil.valueOfLong(mv);
       break;
     case 'F':
       AsmUtil.valueOfFloat(mv);
       break;
     case 'D':
       AsmUtil.valueOfDouble(mv);
       break;
   }
 }
 /** Stores one argument. Index is 1-based. No conversion occurs. */
 public static void storeMethodArgument(
     MethodVisitor mv, MethodSignatureVisitor msign, int index) {
   int offset = msign.getArgumentOffset(index);
   int type = msign.getArgumentOpcodeType(index);
   switch (type) {
     case 'V':
       break;
     case 'B':
     case 'C':
     case 'S':
     case 'I':
     case 'Z':
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'J':
       mv.visitVarInsn(LSTORE, offset);
       break;
     case 'F':
       mv.visitVarInsn(FSTORE, offset);
       break;
     case 'D':
       mv.visitVarInsn(DSTORE, offset);
       break;
     default:
       mv.visitVarInsn(ASTORE, offset);
   }
 }
 /** Validates argument index. */
 public static void checkArgumentIndex(
     MethodSignatureVisitor msign, int argIndex, Class<? extends ProxyAdvice> advice) {
   if ((argIndex < 1) || (argIndex > msign.getArgumentsCount())) {
     throw new ProxettaException(
         "Invalid argument index: '" + argIndex + "' used in advice: " + advice.getName());
   }
 }
 public static void loadMethodArgumentAsObject(
     MethodVisitor mv, MethodSignatureVisitor msign, int index) {
   int offset = msign.getArgumentOffset(index);
   int type = msign.getArgumentOpcodeType(index);
   switch (type) {
     case 'V':
       break;
     case 'B':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfByte(mv);
       break;
     case 'C':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfCharacter(mv);
       break;
     case 'S':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfShort(mv);
       break;
     case 'I':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfInteger(mv);
       break;
     case 'Z':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfBoolean(mv);
       break;
     case 'J':
       mv.visitVarInsn(LLOAD, offset);
       AsmUtil.valueOfLong(mv);
       break;
     case 'F':
       mv.visitVarInsn(FLOAD, offset);
       AsmUtil.valueOfFloat(mv);
       break;
     case 'D':
       mv.visitVarInsn(DLOAD, offset);
       AsmUtil.valueOfDouble(mv);
       break;
     default:
       mv.visitVarInsn(ALOAD, offset);
   }
 }
  public static void castToReturnType(MethodVisitor mv, MethodSignatureVisitor msign) {
    final String returnType;

    char returnOpcodeType = msign.getReturnOpcodeType();

    switch (returnOpcodeType) {
      case 'I':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_INTEGER;
        break;
      case 'J':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_LONG;
        break;
      case 'S':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_SHORT;
        break;
      case 'B':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_BYTE;
        break;
      case 'Z':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_BOOLEAN;
        break;
      case 'F':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_FLOAT;
        break;
      case 'D':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_DOUBLE;
        break;
      case 'C':
        returnType = AsmUtil.SIGNATURE_JAVA_LANG_CHARACTER;
        break;
      case '[':
        returnType = msign.getReturnTypeName();
        break;
      default:
        returnType = msign.getReturnType().replace('.', '/');
        break;
    }

    mv.visitTypeInsn(CHECKCAST, returnType);
  }
 public static void loadMethodReturnClass(MethodVisitor mv, MethodSignatureVisitor msign) {
   loadClass(mv, msign.getReturnOpcodeType(), msign.getReturnTypeName());
 }
 public static void loadMethodArgumentClass(
     MethodVisitor mv, MethodSignatureVisitor msign, int index) {
   loadClass(mv, msign.getArgumentOpcodeType(index), msign.getArgumentTypeName(index));
 }
  /** Visits return opcodes. */
  public static void visitReturn(MethodVisitor mv, MethodSignatureVisitor msign, boolean isLast) {
    switch (msign.getReturnOpcodeType()) {
      case 'V':
        if (isLast == true) {
          mv.visitInsn(POP);
        }
        mv.visitInsn(RETURN);
        break;

      case 'B':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.byteValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'C':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.charValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'S':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.shortValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'I':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.intValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'Z':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.booleanValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'J':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(LCONST_0);
          mv.visitInsn(LRETURN);
          mv.visitLabel(label);

          AsmUtil.longValue(mv);
        }
        mv.visitInsn(LRETURN);
        break;

      case 'F':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(FCONST_0);
          mv.visitInsn(FRETURN);
          mv.visitLabel(label);

          AsmUtil.floatValue(mv);
        }
        mv.visitInsn(FRETURN);
        break;

      case 'D':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(DCONST_0);
          mv.visitInsn(DRETURN);
          mv.visitLabel(label);

          AsmUtil.doubleValue(mv);
        }
        mv.visitInsn(DRETURN);
        break;

      default:
        mv.visitInsn(ARETURN);
        break;
    }
  }
 public static void storeMethodArgumentFromObject(
     MethodVisitor mv, MethodSignatureVisitor msign, int index) {
   int type = msign.getArgumentOpcodeType(index);
   int offset = msign.getArgumentOffset(index);
   storeValue(mv, offset, type);
 }
Exemple #10
0
 /** Loads all method arguments before INVOKEVIRTUAL call. */
 public static void loadVirtualMethodArguments(MethodVisitor mv, MethodSignatureVisitor msign) {
   for (int i = 1; i <= msign.getArgumentsCount(); i++) {
     loadMethodArgument(mv, msign, i);
   }
 }
Exemple #11
0
 /** Loads all method arguments before INVOKESPECIAL call. */
 public static void loadSpecialMethodArguments(MethodVisitor mv, MethodSignatureVisitor msign) {
   mv.visitVarInsn(ALOAD, 0);
   for (int i = 1; i <= msign.getArgumentsCount(); i++) {
     loadMethodArgument(mv, msign, i);
   }
 }