Package jodd.proxetta

Examples of jodd.proxetta.ProxettaException


       * Prevents advice to have inner classes.
       */
      @Override
      public void visitInnerClass(String name, String outerName, String innerName, int access) {
        if (outerName.equals(adviceReference)) {
          throw new ProxettaException("Proxetta doesn't allow inner classes in/for advice: " + advice.getName());
        }
        super.visitInnerClass(name, outerName, innerName, access);
      }

      /**
       * Clones advices fields to destination.
       */
      @Override
      public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
        wd.dest.visitField(access, adviceFieldName(name, aspectIndex), desc, signature, value);     // [A5]
        return super.visitField(access, name, desc, signature, value);
      }

      /**
       * Copies advices methods to destination.
       */
      @Override
      public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        if (name.equals(CLINIT) == true) {              // [A6]
          if (desc.equals(DESC_VOID) == false) {
            throw new ProxettaException("Invalid static initialization block description for advice: " + advice.getName());
          }
          name = clinitMethodName + methodDivider + aspectIndex;
          access |= AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL;
          wd.addAdviceClinitMethod(name);
          return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

            @Override
            public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
            }

            @Override
            public void visitLineNumber(int line, Label start) {
            }

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc) {
              if (opcode == INVOKESTATIC) {
                if (owner.equals(adviceReference)) {
                  owner = wd.thisReference;
                  name = adviceMethodName(name, aspectIndex);
                }
              }
              super.visitMethodInsn(opcode, owner, name, desc);
            }

            @Override
            public void visitFieldInsn(int opcode, String owner, String name, String desc) { // [F6]
              if (owner.equals(adviceReference)) {
                owner = wd.thisReference;              // [F5]
                name = adviceFieldName(name, aspectIndex);
              }
              super.visitFieldInsn(opcode, owner, name, desc);
            }
          };
        } else

        if (name.equals(INIT) == true) { // [A7]
          if (desc.equals(DESC_VOID) == false) {
            throw new ProxettaException("Advices can have only default constructors. Invalid advice: " + advice.getName());
          }

          name = initMethodName + methodDivider + aspectIndex;
          access = ProxettaAsmUtil.makePrivateFinalAccess(access);
          wd.addAdviceInitMethod(name);
View Full Code Here


      return null;
    }

    int access = msign.getAccessFlags();
    if ((access & ACC_ABSTRACT) != 0) {
      throw new ProxettaException("Unable to process abstract method: " + msign);
    }

    wd.proxyApplied = true;
    return new ProxettaMethodBuilder(msign, wd, aspectList);
  }
View Full Code Here

      }
    }

    // detection of super calls
    if ((opcode == INVOKESPECIAL) && (owner.equals(wd.nextSupername) && (name.equals(INIT) == false))) {
      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);
View Full Code Here

   * Returns argument index from the history.
   * <b>Must</b> POP value from the stack after the execution.
   */
  protected int getArgumentIndex() {
    if (isPrevious == false) {
      throw new ProxettaException("Unexpected previous instruction type used for setting argument index");
    }
    int argIndex;
    switch (opcode) {
      case ICONST_0: argIndex = 0; break;
      case ICONST_1: argIndex = 1; break;
      case ICONST_2: argIndex = 2; break;
      case ICONST_3: argIndex = 3; break;
      case ICONST_4: argIndex = 4; break;
      case ICONST_5: argIndex = 5; break;
      case BIPUSH:
      case SIPUSH:
        argIndex = operand; break;
      default:
        throw new ProxettaException("Unexpected previous instruction used for setting argument index");
    }
    return argIndex;
  }
View Full Code Here

TOP

Related Classes of jodd.proxetta.ProxettaException

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.