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

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


          true, cg.getConstantPool());
      cg.addAnnotation(ag);
    } else {
      // List elems = new ArrayList();
      List elems = new ArrayList();
      elems.add(new NameValuePair("value",
          new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), perclauseString), cg.getConstantPool()));
      AnnotationGen ag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Aspect"), elems, true, cg
          .getConstantPool());
      cg.addAnnotation(ag);
    }
    if (concreteAspect.precedence != null) {
      SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), concreteAspect.precedence);
      List elems = new ArrayList();
      elems.add(new NameValuePair("value", svg, cg.getConstantPool()));
      AnnotationGen agprec = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/DeclarePrecedence"), elems, true,
          cg.getConstantPool());
      cg.addAnnotation(agprec);
    }

    // default constructor
    LazyMethodGen init = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, "<init>", EMPTY_TYPES, EMPTY_STRINGS, cg);
    InstructionList cbody = init.getBody();
    cbody.append(InstructionConstants.ALOAD_0);

    cbody.append(cg.getFactory().createInvoke(parentName, "<init>", Type.VOID, EMPTY_TYPES, Constants.INVOKESPECIAL));
    cbody.append(InstructionConstants.RETURN);
    cg.addMethodGen(init);

    for (Iterator it = concreteAspect.pointcuts.iterator(); it.hasNext();) {
      Definition.Pointcut abstractPc = (Definition.Pointcut) it.next();
      // TODO AV - respect visibility instead of opening up as public?
      LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, abstractPc.name, EMPTY_TYPES, EMPTY_STRINGS, cg);
      SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), abstractPc.expression);
      List elems = new ArrayList();
      elems.add(new NameValuePair("value", svg, cg.getConstantPool()));
      AnnotationGen mag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Pointcut"), elems, true, cg
          .getConstantPool());
      AnnotationAJ max = new BcelAnnotation(mag, world);
      mg.addAnnotation(max);

      InstructionList body = mg.getBody();
      body.append(InstructionConstants.RETURN);
      cg.addMethodGen(mg);
    }

    if (concreteAspect.deows.size() > 0) {

      int counter = 1;
      for (Definition.DeclareErrorOrWarning deow : concreteAspect.deows) {

        // Building this:

        // @DeclareWarning("call(* javax.sql..*(..)) && !within(org.xyz.daos..*)")
        // static final String aMessage = "Only DAOs should be calling JDBC.";

        FieldGen field = new FieldGen(Modifier.FINAL, ObjectType.STRING, "rule" + (counter++), cg.getConstantPool());
        SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), deow.pointcut);
        List elems = new ArrayList();
        elems.add(new NameValuePair("value", svg, cg.getConstantPool()));
        AnnotationGen mag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Declare"
            + (deow.isError ? "Error" : "Warning")), elems, true, cg.getConstantPool());
        field.addAnnotation(mag);

        field.setValue(deow.message);
View Full Code Here


      AnnotationGen annotation = ((BcelAnnotation) annos[i]).getBcelAnnotation();
      if (annotation.getTypeSignature().equals(annotationOfInterestSignature)) {
        List<NameValuePair> vals = annotation.getValues();
        boolean doneAndDusted = false;
        for (Iterator<NameValuePair> iterator = vals.iterator(); iterator.hasNext();) {
          NameValuePair object = iterator.next();
          Object o = object.getValue();
          if (o instanceof EnumElementValue) {
            EnumElementValue v = (EnumElementValue) object.getValue();
            String s = v.getEnumTypeString();
            ResolvedType rt = toType.getWorld().resolve(UnresolvedType.forSignature(s));
            if (rt.equals(toType)) {
              il.append(fact.createGetStatic(rt.getName(), v.getEnumValueString(), Type.getType(rt.getSignature())));
              doneAndDusted = true;
            }
          } else if (o instanceof SimpleElementValue) {
            // FIXASC types other than String will go bang bang at runtime
            SimpleElementValue v = (SimpleElementValue) object.getValue();
            il.append(fact.createConstant(v.getValueString()));
            doneAndDusted = true;
            // String s = v.getEnumTypeString();
            // ResolvedType rt = toType.getWorld().resolve(UnresolvedType.forSignature(s));
            // if (rt.equals(toType)) {
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

    // 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

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.