Package org.aspectj.apache.bcel.classfile.annotation

Examples of org.aspectj.apache.bcel.classfile.annotation.NameValuePair


      return false;
    }

    Method annotatedMethod = struct.method;
    World world = struct.enclosingType.getWorld();
    NameValuePair declareMixinPatternNameValuePair = getAnnotationElement(declareMixinAnnotation, VALUE);

    // declareMixinPattern could be of the form "Bar*" or "A || B" or "Foo+"
    String declareMixinPattern = declareMixinPatternNameValuePair.getValue().stringifyValue();
    TypePattern targetTypePattern = parseTypePattern(declareMixinPattern, struct);

    // Return value of the annotated method is the interface or class that the mixin delegate should have
    ResolvedType methodReturnType = UnresolvedType.forSignature(annotatedMethod.getReturnType().getSignature()).resolve(world);

    if (methodReturnType.isPrimitiveType()) {
      reportError(getMethodForMessage(struct) + ":  factory methods for a mixin cannot return void or a primitive type",
          struct);
      return false;
    }

    if (annotatedMethod.getArgumentTypes().length > 1) {
      reportError(getMethodForMessage(struct) + ": factory methods for a mixin can take a maximum of one parameter", struct);
      return false;
    }

    // The set of interfaces to be mixed in is either:
    // supplied as a list in the 'Class[] interfaces' value in the annotation value
    // supplied as just the interface return value of the annotated method
    // supplied as just the class return value of the annotated method
    NameValuePair interfaceListSpecified = getAnnotationElement(declareMixinAnnotation, "interfaces");

    List<TypePattern> newParents = new ArrayList<TypePattern>(1);
    List<ResolvedType> newInterfaceTypes = new ArrayList<ResolvedType>(1);
    if (interfaceListSpecified != null) {
      ArrayElementValue arrayOfInterfaceTypes = (ArrayElementValue) interfaceListSpecified.getValue();
      int numberOfTypes = arrayOfInterfaceTypes.getElementValuesArraySize();
      ElementValue[] theTypes = arrayOfInterfaceTypes.getElementValuesArray();
      for (int i = 0; i < numberOfTypes; i++) {
        ClassElementValue interfaceType = (ClassElementValue) theTypes[i];
        // Check: needs to be resolvable
View Full Code Here


   */
  private static boolean handleBeforeAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct,
      ResolvedPointcutDefinition preResolvedPointcut) {
    AnnotationGen before = getAnnotation(runtimeAnnotations, AjcMemberMaker.BEFORE_ANNOTATION);
    if (before != null) {
      NameValuePair beforeAdvice = getAnnotationElement(before, VALUE);
      if (beforeAdvice != null) {
        // this/target/args binding
        String argumentNames = getArgNamesValue(before);
        if (argumentNames != null) {
          struct.unparsedArgumentNames = argumentNames;
        }
        FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
        try {
          bindings = extractBindings(struct);
        } catch (UnreadableDebugInfoException unreadableDebugInfoException) {
          return false;
        }
        IScope binding = new BindingScope(struct.enclosingType, struct.context, bindings);

        // joinpoint, staticJoinpoint binding
        int extraArgument = extractExtraArgument(struct.method);

        Pointcut pc = null;
        if (preResolvedPointcut != null) {
          pc = preResolvedPointcut.getPointcut();
          // pc.resolve(binding);
        } else {
          pc = parsePointcut(beforeAdvice.getValue().stringifyValue(), struct, false);
          if (pc == null) {
            return false;// parse error
          }
          pc = pc.resolve(binding);
        }
View Full Code Here

   */
  private static boolean handleAfterAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct,
      ResolvedPointcutDefinition preResolvedPointcut) {
    AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTER_ANNOTATION);
    if (after != null) {
      NameValuePair afterAdvice = getAnnotationElement(after, VALUE);
      if (afterAdvice != null) {
        // this/target/args binding
        FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
        String argumentNames = getArgNamesValue(after);
        if (argumentNames != null) {
          struct.unparsedArgumentNames = argumentNames;
        }
        try {
          bindings = extractBindings(struct);
        } catch (UnreadableDebugInfoException unreadableDebugInfoException) {
          return false;
        }
        IScope binding = new BindingScope(struct.enclosingType, struct.context, bindings);

        // joinpoint, staticJoinpoint binding
        int extraArgument = extractExtraArgument(struct.method);

        Pointcut pc = null;
        if (preResolvedPointcut != null) {
          pc = preResolvedPointcut.getPointcut();
        } else {
          pc = parsePointcut(afterAdvice.getValue().stringifyValue(), struct, false);
          if (pc == null) {
            return false;// parse error
          }
          pc.resolve(binding);
        }
View Full Code Here

  private static boolean handleAfterReturningAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct,
      ResolvedPointcutDefinition preResolvedPointcut, BcelMethod owningMethod)
      throws ReturningFormalNotDeclaredInAdviceSignatureException {
    AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERRETURNING_ANNOTATION);
    if (after != null) {
      NameValuePair annValue = getAnnotationElement(after, VALUE);
      NameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
      NameValuePair annReturned = getAnnotationElement(after, RETURNING);

      // extract the pointcut and returned type/binding - do some checks
      String pointcut = null;
      String returned = null;
      if ((annValue != null && annPointcut != null) || (annValue == null && annPointcut == null)) {
        reportError("@AfterReturning: either 'value' or 'poincut' must be provided, not both", struct);
        return false;
      }
      if (annValue != null) {
        pointcut = annValue.getValue().stringifyValue();
      } else {
        pointcut = annPointcut.getValue().stringifyValue();
      }
      if (isNullOrEmpty(pointcut)) {
        reportError("@AfterReturning: either 'value' or 'poincut' must be provided, not both", struct);
        return false;
      }
      if (annReturned != null) {
        returned = annReturned.getValue().stringifyValue();
        if (isNullOrEmpty(returned)) {
          returned = null;
        } else {
          // check that thrownFormal exists as the last parameter in
          // the advice
View Full Code Here

  private static boolean handleAfterThrowingAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct,
      ResolvedPointcutDefinition preResolvedPointcut, BcelMethod owningMethod)
      throws ThrownFormalNotDeclaredInAdviceSignatureException {
    AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERTHROWING_ANNOTATION);
    if (after != null) {
      NameValuePair annValue = getAnnotationElement(after, VALUE);
      NameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
      NameValuePair annThrown = getAnnotationElement(after, THROWING);

      // extract the pointcut and throwned type/binding - do some checks
      String pointcut = null;
      String thrownFormal = null;
      if ((annValue != null && annPointcut != null) || (annValue == null && annPointcut == null)) {
        reportError("@AfterThrowing: either 'value' or 'poincut' must be provided, not both", struct);
        return false;
      }
      if (annValue != null) {
        pointcut = annValue.getValue().stringifyValue();
      } else {
        pointcut = annPointcut.getValue().stringifyValue();
      }
      if (isNullOrEmpty(pointcut)) {
        reportError("@AfterThrowing: either 'value' or 'poincut' must be provided, not both", struct);
        return false;
      }
      if (annThrown != null) {
        thrownFormal = annThrown.getValue().stringifyValue();
        if (isNullOrEmpty(thrownFormal)) {
          thrownFormal = null;
        } else {
          // check that thrownFormal exists as the last parameter in
          // the advice
View Full Code Here

   */
  private static boolean handleAroundAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct,
      ResolvedPointcutDefinition preResolvedPointcut) {
    AnnotationGen around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
    if (around != null) {
      NameValuePair aroundAdvice = getAnnotationElement(around, VALUE);
      if (aroundAdvice != null) {
        // this/target/args binding
        String argumentNames = getArgNamesValue(around);
        if (argumentNames != null) {
          struct.unparsedArgumentNames = argumentNames;
        }
        FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
        try {
          bindings = extractBindings(struct);
        } catch (UnreadableDebugInfoException unreadableDebugInfoException) {
          return false;
        }
        IScope binding = new BindingScope(struct.enclosingType, struct.context, bindings);

        // joinpoint, staticJoinpoint binding
        int extraArgument = extractExtraArgument(struct.method);

        Pointcut pc = null;
        if (preResolvedPointcut != null) {
          pc = preResolvedPointcut.getPointcut();
        } else {
          pc = parsePointcut(aroundAdvice.getValue().stringifyValue(), struct, false);
          if (pc == null) {
            return false;// parse error
          }
          pc.resolve(binding);
        }
View Full Code Here

  private static boolean handlePointcutAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeMethodStruct struct) {
    AnnotationGen pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
    if (pointcut == null) {
      return false;
    }
    NameValuePair pointcutExpr = getAnnotationElement(pointcut, VALUE);

    // semantic check: the method must return void, or be
    // "public static boolean" for if() support
    if (!(Type.VOID.equals(struct.method.getReturnType()) || (Type.BOOLEAN.equals(struct.method.getReturnType())
        && struct.method.isStatic() && struct.method.isPublic()))) {
      reportWarning("Found @Pointcut on a method not returning 'void' or not 'public static boolean'", struct);
      // no need to stop
    }

    // semantic check: the method must not throw anything
    if (struct.method.getExceptionTable() != null) {
      reportWarning("Found @Pointcut on a method throwing exception", struct);
      // no need to stop
    }

    String argumentNames = getArgNamesValue(pointcut);
    if (argumentNames != null) {
      struct.unparsedArgumentNames = argumentNames;
    }
    // this/target/args binding
    final IScope binding;
    try {
      if (struct.method.isAbstract()) {
        binding = null;
      } else {
        binding = new BindingScope(struct.enclosingType, struct.context, extractBindings(struct));
      }
    } catch (UnreadableDebugInfoException e) {
      return false;
    }

    UnresolvedType[] argumentTypes = new UnresolvedType[struct.method.getArgumentTypes().length];
    for (int i = 0; i < argumentTypes.length; i++) {
      argumentTypes[i] = UnresolvedType.forSignature(struct.method.getArgumentTypes()[i].getSignature());
    }

    Pointcut pc = null;
    if (struct.method.isAbstract()) {
      if ((pointcutExpr != null && isNullOrEmpty(pointcutExpr.getValue().stringifyValue())) || pointcutExpr == null) {
        // abstract pointcut
        // leave pc = null
      } else {
        reportError("Found defined @Pointcut on an abstract method", struct);
        return false;// stop
      }
    } else {
      if (pointcutExpr == null || isNullOrEmpty(pointcutExpr.getValue().stringifyValue())) {
        // the matches nothing pointcut (125475/125480) - perhaps not as
        // cleanly supported as it could be.
      } else {
        // if (pointcutExpr != null) {
        // use a LazyResolvedPointcutDefinition so that the pointcut is
        // resolved lazily
        // since for it to be resolved, we will need other pointcuts to
        // be registered as well
        pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct, true);
        if (pc == null) {
          return false;// parse error
        }
        pc.setLocation(struct.context, -1, -1);// FIXME AVASM !! bMethod
        // is null here..
View Full Code Here

  private static boolean handleDeclareErrorOrWarningAnnotation(AsmManager model, RuntimeAnnos runtimeAnnotations,
      AjAttributeFieldStruct struct) {
    AnnotationGen error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
    boolean hasError = false;
    if (error != null) {
      NameValuePair declareError = getAnnotationElement(error, VALUE);
      if (declareError != null) {
        if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
          reportError("@DeclareError used on a non String constant field", struct);
          return false;
        }
        Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct, false);
        if (pc == null) {
          hasError = false;// cannot parse pointcut
        } else {
          DeclareErrorOrWarning deow = new DeclareErrorOrWarning(true, pc, struct.field.getConstantValue().toString());
          setDeclareErrorOrWarningLocation(model, deow, struct);
          struct.ajAttributes.add(new AjAttribute.DeclareAttribute(deow));
          hasError = true;
        }
      }
    }
    AnnotationGen warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
    boolean hasWarning = false;
    if (warning != null) {
      NameValuePair declareWarning = getAnnotationElement(warning, VALUE);
      if (declareWarning != null) {
        if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
          reportError("@DeclareWarning used on a non String constant field", struct);
          return false;
        }
        Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct, false);
        if (pc == null) {
          hasWarning = false;// cannot parse pointcut
        } else {
          DeclareErrorOrWarning deow = new DeclareErrorOrWarning(false, pc, struct.field.getConstantValue().toString());
          setDeclareErrorOrWarningLocation(model, deow, struct);
View Full Code Here

          return false;
        }
        extendsAspect = struct.enclosingType.getSuperclass().isAspect();
      }

      NameValuePair aspectPerClause = getAnnotationElement(aspect, VALUE);
      final PerClause perClause;
      if (aspectPerClause == null) {
        // empty value means singleton unless inherited
        if (!extendsAspect) {
          perClause = new PerSingleton();
        } else {
          perClause = new PerFromSuper(struct.enclosingType.getSuperclass().getPerClause().getKind());
        }
      } else {
        String perX = aspectPerClause.getValue().stringifyValue();
        if (perX == null || perX.length() <= 0) {
          perClause = new PerSingleton();
        } else {
          perClause = parsePerClausePointcut(perX, struct);
        }
View Full Code Here

   * @return true if found
   */
  private static boolean handlePrecedenceAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeStruct struct) {
    AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPRECEDENCE_ANNOTATION);
    if (aspect != null) {
      NameValuePair precedence = getAnnotationElement(aspect, VALUE);
      if (precedence != null) {
        String precedencePattern = precedence.getValue().stringifyValue();
        PatternParser parser = new PatternParser(precedencePattern);
        DeclarePrecedence ajPrecedence = parser.parseDominates();
        struct.ajAttributes.add(new AjAttribute.DeclareAttribute(ajPrecedence));
        return true;
      }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.annotation.NameValuePair

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.