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

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


          // We know the value is an array value
          ArrayElementValue array = (ArrayElementValue) (vals.get(0)).getValue();
          ElementValue[] values = array.getElementValuesArray();
          for (int j = 0; j < values.length; j++) {
            // We know values in the array are strings
            SimpleElementValue value = (SimpleElementValue) values[j];
            Lint.Kind lintKind = lint.getLintKind(value.getValueString());
            if (lintKind != null) {
              suppressedWarnings.add(lintKind);
            }
          }
        }
View Full Code Here


      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);
View Full Code Here

              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)) {
            // il.append(fact.createGetStatic(rt.getName(), v.getEnumValueString(), Type.getType(rt.getSignature())));
View Full Code Here

      cg.addAnnotation(ag);
    } else {
      // List elems = new ArrayList();
      List<NameValuePair> elems = new ArrayList<NameValuePair>();
      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<NameValuePair> elems = new ArrayList<NameValuePair>();
      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<Definition.Pointcut> 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<NameValuePair> elems = new ArrayList<NameValuePair>();
      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);
    }

    // Construct any defined declare error/warnings
    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<NameValuePair> elems = new ArrayList<NameValuePair>();
        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);
View Full Code Here

  /**
   * For the given PointcutAndAdvice build the correct advice annotation.
   */
  private AnnotationAJ buildAdviceAnnotation(LazyClassGen cg, PointcutAndAdvice paa) {
    SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), paa.pointcut);
    List<NameValuePair> elems = new ArrayList<NameValuePair>();
    elems.add(new NameValuePair("value", svg, cg.getConstantPool()));
    AnnotationGen mag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/" + paa.adviceKind.toString()), elems,
        true, cg.getConstantPool());
    AnnotationAJ aaj = new BcelAnnotation(mag, world);
View Full Code Here

            if (rt.equals(toType)) {
              il.append(fact.createGetStatic(rt.getName(), v.getEnumValueString(), Type.getType(rt.getSignature())));
              foundValueInAnnotationUsage = true;
            }
          } else if (o instanceof SimpleElementValue) {
            SimpleElementValue v = (SimpleElementValue) o;
            switch (v.getElementValueType()) {
            case ElementValue.PRIMITIVE_INT:
              il.append(fact.createConstant(v.getValueInt()));
              foundValueInAnnotationUsage = true;
              break;
            case ElementValue.STRING:
              il.append(fact.createConstant(v.getValueString()));
              foundValueInAnnotationUsage = true;
              break;
            default:
              throw new IllegalStateException("NYI: Unsupported annotation value binding for " + o);
            }
View Full Code Here

          // We know the value is an array value
          ArrayElementValue array = (ArrayElementValue) (vals.get(0)).getValue();
          ElementValue[] values = array.getElementValuesArray();
          for (int j = 0; j < values.length; j++) {
            // We know values in the array are strings
            SimpleElementValue value = (SimpleElementValue) values[j];
            Lint.Kind lintKind = lint.getLintKind(value.getValueString());
            if (lintKind != null) {
              suppressedWarnings.add(lintKind);
            }
          }
        }
View Full Code Here

 
  /**
     * Return immutable variant
     */
  public ElementValue getElementValue() {
    return new SimpleElementValue(type,idx,cpGen.getConstantPool());
  }
View Full Code Here

              // We know the value is an array value
              ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
              ElementValue[] values = array.getElementValuesArray();
              for (int j = 0; j < values.length; j++) {
                // We know values in the array are strings
          SimpleElementValue value = (SimpleElementValue)values[j];
          if (value.getValueString().equals(lintkey)) {
            suppressed = true;
          }
        }
            }
          }
View Full Code Here

              // We know the value is an array value
              ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
              ElementValue[] values = array.getElementValuesArray();
              for (int j = 0; j < values.length; j++) {
                // We know values in the array are strings
          SimpleElementValue value = (SimpleElementValue)values[j];
          Lint.Kind lintKind = lint.getLintKind(value.getValueString());
          if (lintKind != null) suppressedWarnings.add(lintKind);
        }
            }
          }
        }
View Full Code Here

TOP

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

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.