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

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


    // ResolvedPointcutDefinition
    // preResolvedPointcut)
    // {
    AnnotationGen decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
    if (decp != null) {
      NameValuePair decpPatternNVP = getAnnotationElement(decp, VALUE);
      String decpPattern = decpPatternNVP.getValue().stringifyValue();
      if (decpPattern != null) {
        TypePattern typePattern = parseTypePattern(decpPattern, struct);
        ResolvedType fieldType = UnresolvedType.forSignature(struct.field.getSignature()).resolve(
            struct.enclosingType.getWorld());
        if (fieldType.isInterface()) {
          TypePattern parent = parseTypePattern(fieldType.getName(), struct);
          FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
          IScope binding = new BindingScope(struct.enclosingType, struct.context, bindings);
          // first add the declare implements like
          List<TypePattern> parents = new ArrayList<TypePattern>(1);
          parents.add(parent);
          DeclareParents dp = new DeclareParents(typePattern, parents, false);
          dp.resolve(binding); // resolves the parent and child parts
          // of the decp

          // resolve this so that we can use it for the
          // MethodDelegateMungers below.
          // eg. '@Coloured *' will change from a WildTypePattern to
          // an 'AnyWithAnnotationTypePattern' after this
          // resolution
          typePattern = typePattern.resolveBindings(binding, Bindings.NONE, false, false);
          // TODO kick ISourceLocation sl =
          // struct.bField.getSourceLocation(); ??
          // dp.setLocation(dp.getDeclaringType().getSourceContext(),
          // dp.getDeclaringType().getSourceLocation().getOffset(),
          // dp.getDeclaringType().getSourceLocation().getOffset());
          dp.setLocation(struct.context, -1, -1); // not ideal...
          struct.ajAttributes.add(new AjAttribute.DeclareAttribute(dp));

          // do we have a defaultImpl=xxx.class (ie implementation)
          String defaultImplClassName = null;
          NameValuePair defaultImplNVP = getAnnotationElement(decp, "defaultImpl");
          if (defaultImplNVP != null) {
            ClassElementValue defaultImpl = (ClassElementValue) defaultImplNVP.getValue();
            defaultImplClassName = UnresolvedType.forSignature(defaultImpl.getClassString()).getName();
            if (defaultImplClassName.equals("org.aspectj.lang.annotation.DeclareParents")) {
              defaultImplClassName = null;
            } else {
              // check public no arg ctor
View Full Code Here


      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

        for (int i = annotations.length - 1; i >= 0; i--) {
          AnnotationAJ ax = annotations[i];
          if (ax.getTypeName().equals(UnresolvedType.AT_RETENTION.getName())) {
            List<NameValuePair> values = ((BcelAnnotation) ax).getBcelAnnotation().getValues();
            for (Iterator<NameValuePair> it = values.iterator(); it.hasNext();) {
              NameValuePair element = it.next();
              EnumElementValue v = (EnumElementValue) element.getValue();
              retentionPolicy = v.getEnumValueString();
              return retentionPolicy;
            }
          }
        }
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.