Package jodd.proxetta

Examples of jodd.proxetta.InvokeReplacer


      throw new ProxettaException("Super call detected in class " + methodInfo.getClassname() + " method: " + methodInfo.getSignature() +
        "\nProxetta can't handle super calls due to VM limitations.");
    }


    InvokeReplacer ir = null;

    // find first matching aspect
    for (InvokeAspect aspect : aspects) {
      ir = aspect.pointcut(invokeInfo);
      if (ir != null) {
        break;
      }
    }

    if (ir == null || ir.isNone()) {

      if (ProxettaAsmUtil.isCreateArgumentsArrayMethod(name, desc)) {
        ProxyTargetReplacement.createArgumentsArray(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isCreateArgumentsClassArrayMethod(name, desc)) {
        ProxyTargetReplacement.createArgumentsClassArray(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isArgumentsCountMethod(name, desc)) {
        ProxyTargetReplacement.argumentsCount(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodNameMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodName(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodDescriptionMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodDescription(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodSignatureMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodSignature(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isReturnTypeMethod(name, desc)) {
        ProxyTargetReplacement.returnType(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetClassMethod(name, desc)) {
        ProxyTargetReplacement.targetClass(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (isArgumentTypeMethod(name, desc)) {
        int argIndex = this.getArgumentIndex();
        ProxyTargetReplacement.argumentType(mv, methodInfo, argIndex);
        wd.proxyApplied = true;
        return;
      }

      if (isArgumentMethod(name, desc)) {
        int argIndex = this.getArgumentIndex();
        ProxyTargetReplacement.argument(mv, methodInfo, argIndex);
        wd.proxyApplied = true;
        return;
      }

      if (isInfoMethod(name, desc)) {
        ProxyTargetReplacement.info(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      super.visitMethodInsn(opcode, owner, name, desc);
      return;
    }

    wd.proxyApplied = true;

    String exOwner = owner;
    owner = ir.getOwner();
    name = ir.getMethodName();

    switch (opcode) {
      case INVOKEINTERFACE:
        desc = prependArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
        break;
      case INVOKEVIRTUAL:
        desc = prependArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
        break;
      case INVOKESTATIC:
        break;
      default:
        throw new ProxettaException("Unsupported opcode: " + opcode);
    }

    // additional arguments
    if (ir.isPassOwnerName()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(exOwner);
    }
    if (ir.isPassMethodName()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(methodInfo.getMethodName());
    }
    if (ir.isPassMethodSignature()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(methodInfo.getSignature());
    }
    if (ir.isPassTargetClass()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_CLASS);
      super.mv.visitLdcInsn(Type.getType('L' + wd.superReference + ';'));
    }
    if (ir.isPassThis()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
      super.mv.visitVarInsn(ALOAD, 0);
    }

    super.visitMethodInsn(INVOKESTATIC, owner, name, desc);
View Full Code Here


  @Override
  public void visitTypeInsn(int opcode, String type) {
    if (opcode == NEW) {
      InvokeInfo invokeInfo = new InvokeInfo(type, INIT, StringPool.EMPTY);
      for (InvokeAspect aspect : aspects) {
        InvokeReplacer ir = aspect.pointcut(invokeInfo);
        if (ir != null && !ir.isNone()) {
          newInvokeReplacer = ir;

          // new pointcut found, skip the new instruction and the following dup.
          // and then go to the invokespecial
          return;
View Full Code Here

      throw new ProxettaException("Super call detected in class " + methodInfo.getClassname() + " method: " + methodInfo.getSignature() +
        "\nProxetta can't handle super calls due to VM limitations.");
    }


    InvokeReplacer ir = null;

    // find first matching aspect
    for (InvokeAspect aspect : aspects) {
      ir = aspect.pointcut(invokeInfo);
      if (ir != null) {
        break;
      }
    }

    if (ir == null || ir.isNone()) {

      if (ProxettaAsmUtil.isCreateArgumentsArrayMethod(name, desc)) {
        ProxyTargetReplacement.createArgumentsArray(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isCreateArgumentsClassArrayMethod(name, desc)) {
        ProxyTargetReplacement.createArgumentsClassArray(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isArgumentsCountMethod(name, desc)) {
        ProxyTargetReplacement.argumentsCount(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodNameMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodName(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodDescriptionMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodDescription(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetMethodSignatureMethod(name, desc)) {
        ProxyTargetReplacement.targetMethodSignature(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isReturnTypeMethod(name, desc)) {
        ProxyTargetReplacement.returnType(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (ProxettaAsmUtil.isTargetClassMethod(name, desc)) {
        ProxyTargetReplacement.targetClass(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (isArgumentTypeMethod(name, desc)) {
        int argIndex = this.getArgumentIndex();
        ProxyTargetReplacement.argumentType(mv, methodInfo, argIndex);
        wd.proxyApplied = true;
        return;
      }

      if (isArgumentMethod(name, desc)) {
        int argIndex = this.getArgumentIndex();
        ProxyTargetReplacement.argument(mv, methodInfo, argIndex);
        wd.proxyApplied = true;
        return;
      }

      if (isInfoMethod(name, desc)) {
        ProxyTargetReplacement.info(mv, methodInfo);
        wd.proxyApplied = true;
        return;
      }

      if (isTargetMethodAnnotationMethod(name, desc)) {
        String[] args = getLastTwoStringArguments();

        // pop current two args
        mv.visitInsn(POP);
        mv.visitInsn(POP);

        ProxyTargetReplacement.targetMethodAnnotation(mv, methodInfo, args);
        wd.proxyApplied = true;
        return;
      }

      if (isTargetClassAnnotationMethod(name, desc)) {
        String[] args = getLastTwoStringArguments();

        // pop current two args
        mv.visitInsn(POP);
        mv.visitInsn(POP);

        ProxyTargetReplacement.targetClassAnnotation(mv, methodInfo.getClassInfo(), args);
        wd.proxyApplied = true;
        return;
      }


      super.visitMethodInsn(opcode, owner, name, desc);
      return;
    }

    wd.proxyApplied = true;

    String exOwner = owner;
    owner = ir.getOwner();
    name = ir.getMethodName();

    switch (opcode) {
      case INVOKEINTERFACE:
        desc = prependArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
        break;
      case INVOKEVIRTUAL:
        desc = prependArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
        break;
      case INVOKESTATIC:
        break;
      default:
        throw new ProxettaException("Unsupported opcode: " + opcode);
    }

    // additional arguments
    if (ir.isPassOwnerName()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(exOwner);
    }
    if (ir.isPassMethodName()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(methodInfo.getMethodName());
    }
    if (ir.isPassMethodSignature()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_STRING);
      super.visitLdcInsn(methodInfo.getSignature());
    }
    if (ir.isPassTargetClass()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_CLASS);
      super.mv.visitLdcInsn(Type.getType('L' + wd.superReference + ';'));
    }
    if (ir.isPassThis()) {
      desc = appendArgument(desc, AsmUtil.L_SIGNATURE_JAVA_LANG_OBJECT);
      super.mv.visitVarInsn(ALOAD, 0);
    }

    super.visitMethodInsn(INVOKESTATIC, owner, name, desc);
View Full Code Here

  @Override
  public void visitTypeInsn(int opcode, String type) {
    if (opcode == NEW) {
      InvokeInfo invokeInfo = new InvokeInfo(type, INIT, StringPool.EMPTY);
      for (InvokeAspect aspect : aspects) {
        InvokeReplacer ir = aspect.pointcut(invokeInfo);
        if (ir != null && !ir.isNone()) {
          newInvokeReplacer = ir;

          // new pointcut found, skip the new instruction and the following dup.
          // and then go to the invokespecial
          return;
View Full Code Here

TOP

Related Classes of jodd.proxetta.InvokeReplacer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.