コード例 #1
0
 /** Creates the 'invoke' method. */
 protected void createInvokeMethod() {
   String invokeDesc = buildInvokeMethodSignature();
   MethodVisitor cv =
       m_cw.visitMethod(
           ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
           INVOKE_METHOD_NAME,
           invokeDesc,
           null,
           new String[] {THROWABLE_CLASS_NAME});
   AsmHelper.loadArgumentTypes(cv, Type.getArgumentTypes(invokeDesc), true);
   cv.visitMethodInsn(
       INVOKESTATIC, m_redefinedModel.getJoinPointClassName(), INVOKE_METHOD_NAME, invokeDesc);
   AsmHelper.addReturnStatement(cv, Type.getReturnType(invokeDesc));
   cv.visitMaxs(0, 0);
 }
コード例 #2
0
 /**
  * TODO refactor - many member fields holds data that is in either the adviceDef (which is in the
  * class) or the aspectDef (which is accessible from the adviceDef)
  *
  * <p>Creates a new advice info.
  *
  * @param aspectQualifiedName
  * @param aspectClassName
  * @param aspectDeploymentModel
  * @param methodName
  * @param methodSignature
  * @param methodParameterTypes
  * @param type the advice type
  * @param specialArgumentType the special arg type
  * @param adviceName full qualified advice method name (aspectFQN/advice(call sig))
  * @param targetWithRuntimeCheck true if a runtime check is needed based on target instance
  * @param expressionInfo
  * @param expressionContext
  * @param adviceDef
  */
 public AdviceInfo(
     final String aspectQualifiedName,
     final String aspectClassName,
     final int aspectDeploymentModel,
     final String methodName,
     final String methodSignature,
     final Type[] methodParameterTypes,
     final AdviceType type,
     final String specialArgumentType,
     final String adviceName,
     final boolean targetWithRuntimeCheck,
     final ExpressionInfo expressionInfo,
     final ExpressionContext expressionContext,
     final AdviceDefinition adviceDef) {
   m_aspectQualifiedName = aspectQualifiedName;
   m_aspectClassName = aspectClassName;
   m_aspectDeploymentModel = aspectDeploymentModel;
   m_methodName = methodName;
   m_methodSignature = methodSignature;
   m_methodParameterTypes = methodParameterTypes;
   m_type = type;
   if (specialArgumentType != null) {
     m_specialArgumentTypeDesc = AsmHelper.convertReflectDescToTypeDesc(specialArgumentType);
     m_specialArgumentTypeName = specialArgumentType.replace('.', '/');
   }
   m_name = adviceName;
   m_targetWithRuntimeCheck = targetWithRuntimeCheck;
   m_expressionInfo = expressionInfo;
   m_expressionContext = expressionContext;
   m_adviceDef = adviceDef;
 }
コード例 #3
0
  /**
   * Adds the mixin methods to the target class.
   *
   * @param fieldInfo
   * @param mixinDef
   */
  private void addMixinMethods(final MixinFieldInfo fieldInfo, final MixinDefinition mixinDef) {
    for (Iterator it3 = mixinDef.getMethodsToIntroduce().iterator(); it3.hasNext(); ) {
      MethodInfo methodInfo = (MethodInfo) it3.next();
      final String methodName = methodInfo.getName();
      final String methodSignature = methodInfo.getSignature();

      if (m_addedMethods.contains(
          AlreadyAddedMethodVisitor.getMethodKey(methodName, methodSignature))) {
        continue;
      }

      MethodVisitor mv =
          cv.visitMethod(ACC_PUBLIC + ACC_SYNTHETIC, methodName, methodSignature, null, null);
      if (fieldInfo.isStatic) {
        mv.visitFieldInsn(
            GETSTATIC,
            m_declaringTypeName,
            fieldInfo.fieldName,
            fieldInfo.mixinClassInfo.getSignature());
      } else {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(
            GETFIELD,
            m_declaringTypeName,
            fieldInfo.fieldName,
            fieldInfo.mixinClassInfo.getSignature());
      }
      AsmHelper.loadArgumentTypes(mv, Type.getArgumentTypes(methodSignature), false);
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          fieldInfo.mixinClassInfo.getName().replace('.', '/'),
          methodName,
          methodSignature);
      AsmHelper.addReturnStatement(mv, Type.getReturnType(methodSignature));
      mv.visitMaxs(0, 0);
    }
  }
コード例 #4
0
  /**
   * Handles the arguments to the after advice.
   *
   * @param cv
   * @param adviceMethodInfo
   * @param joinPointInstanceIndex
   */
  public void createAfterAdviceArgumentHandling(
      final MethodVisitor cv,
      final AdviceMethodInfo adviceMethodInfo,
      final int joinPointInstanceIndex) {
    final String joinPointClassName = adviceMethodInfo.getJoinPointClassName();
    final int joinPointIndex = joinPointInstanceIndex;
    final String specArgDesc = adviceMethodInfo.getSpecialArgumentTypeDesc();
    if (specArgDesc == null) {
      cv.visitInsn(ACONST_NULL);
    } else {
      cv.visitVarInsn(ALOAD, adviceMethodInfo.getSpecialArgumentIndex());
      AsmHelper.wrapPrimitiveType(cv, Type.getType(specArgDesc));
    }
    cv.visitFieldInsn(
        GETSTATIC, joinPointClassName, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE);
    cv.visitMethodInsn(
        INVOKEVIRTUAL,
        METHOD_SIGNATURE_IMPL_CLASS_NAME,
        GET_METHOD_METHOD_NAME,
        GET_METHOD_METHOD_SIGNATURE);

    if (Type.getArgumentTypes(adviceMethodInfo.getCalleeMemberDesc()).length == 0) {
      cv.visitInsn(ACONST_NULL);
    } else {
      cv.visitVarInsn(ALOAD, joinPointIndex);
      cv.visitMethodInsn(
          INVOKEVIRTUAL, joinPointClassName, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE);
      cv.visitTypeInsn(CHECKCAST, METHOD_RTTI_IMPL_CLASS_NAME);
      cv.visitMethodInsn(
          INVOKEVIRTUAL,
          METHOD_RTTI_IMPL_CLASS_NAME,
          GET_PARAMETER_VALUES_METHOD_NAME,
          GET_ARGUMENTS_METHOD_SIGNATURE);
    }

    cv.visitVarInsn(ALOAD, joinPointIndex);
    cv.visitFieldInsn(
        GETFIELD,
        joinPointClassName,
        CALLEE_INSTANCE_FIELD_NAME,
        adviceMethodInfo.getCalleeClassSignature());
  }