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

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


  }

  public boolean hasAnnotation(UnresolvedType t) {

    // annotations on the real thing
    AnnotationGen agens[] = myGen.getAnnotations();
    if (agens == null) {
      return false;
    }
    for (int i = 0; i < agens.length; i++) {
      AnnotationGen gen = agens[i];
      if (t.equals(UnresolvedType.forSignature(gen.getTypeSignature()))) {
        return true;
      }
    }

    // annotations added during this weave
View Full Code Here


    return false;
  }

  public void addAnnotation(AnnotationGen a) {
    if (!hasAnnotation(UnresolvedType.forSignature(a.getTypeSignature()))) {
      annotations.add(new AnnotationGen(a, getConstantPool(), true));
    }
  }
View Full Code Here

              }

              if (annotationsToAdd == null) {
                annotationsToAdd = new ArrayList<AnnotationGen>();
              }
              AnnotationGen a = ((BcelAnnotation) decaM.getAnnotation()).getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a, clazz.getConstantPool(), true);
              annotationsToAdd.add(ag);
              mg.addAnnotation(decaM.getAnnotation());

              AsmRelationshipProvider.addDeclareAnnotationMethodRelationship(decaM.getSourceLocation(),
                  clazz.getName(), mg.getMemberView(), world.getModelAsAsmManager());// getMethod());
              reportMethodCtorWeavingMessage(clazz, mg.getMemberView(), decaM, mg.getDeclarationLineNumber());
              isChanged = true;
              modificationOccured = true;
              // remove the declare @method since have matched
              // against it
              unusedDecams.remove(decaM);
            } else {
              if (!decaM.isStarredAnnotationPattern()) {
                worthRetrying.add(decaM); // an annotation is
                // specified that
                // might be put on
                // by a subsequent
                // decaf
              }
            }
          }

          // Multiple secondary passes
          while (!worthRetrying.isEmpty() && modificationOccured) {
            modificationOccured = false;
            // lets have another go
            List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>();
            for (DeclareAnnotation decaM : worthRetrying) {
              if (decaM.matches(mg.getMemberView(), world)) {
                if (doesAlreadyHaveAnnotation(mg.getMemberView(), decaM, reportedProblems)) {
                  // remove the declare @method since don't
                  // want an error when
                  // the annotation is already there
                  unusedDecams.remove(decaM);
                  continue; // skip this one...
                }

                if (annotationsToAdd == null) {
                  annotationsToAdd = new ArrayList<AnnotationGen>();
                }
                AnnotationGen a = ((BcelAnnotation) decaM.getAnnotation()).getBcelAnnotation();
                // create copy to get the annotation type into the right constant pool
                AnnotationGen ag = new AnnotationGen(a, clazz.getConstantPool(), true);
                annotationsToAdd.add(ag);
                mg.addAnnotation(decaM.getAnnotation());
                AsmRelationshipProvider.addDeclareAnnotationMethodRelationship(decaM.getSourceLocation(),
                    clazz.getName(), mg.getMemberView(), world.getModelAsAsmManager());// getMethod());
                isChanged = true;
View Full Code Here

              }

              if (annotationsToAdd == null) {
                annotationsToAdd = new ArrayList<AnnotationGen>();
              }
              AnnotationGen a = ((BcelAnnotation) decaM.getAnnotation()).getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a, clazz.getConstantPool(), true);
              annotationsToAdd.add(ag);
              mg.addAnnotation(decaM.getAnnotation());

              AsmRelationshipProvider.addDeclareAnnotationMethodRelationship(decaM.getSourceLocation(),
                  clazz.getName(), mg.getMemberView(), world.getModelAsAsmManager());// getMethod());
              reportMethodCtorWeavingMessage(clazz, mg.getMemberView(), decaM, mg.getDeclarationLineNumber());
              isChanged = true;
              modificationOccured = true;
              // remove the declare @method since have matched
              // against it
              unusedDecams.remove(decaM);
            } else {
              if (!decaM.isStarredAnnotationPattern()) {
                worthRetrying.add(decaM); // an annotation is
                // specified that
                // might be put on
                // by a subsequent
                // decaf
              }
            }
          }

          // Multiple secondary passes
          while (!worthRetrying.isEmpty() && modificationOccured) {
            modificationOccured = false;
            // lets have another go
            List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>();
            for (DeclareAnnotation decaM : worthRetrying) {
              if (decaM.matches(mg.getMemberView(), world)) {
                if (doesAlreadyHaveAnnotation(mg.getMemberView(), decaM, reportedProblems)) {
                  // remove the declare @method since don't
                  // want an error when
                  // the annotation is already there
                  unusedDecams.remove(decaM);
                  continue; // skip this one...
                }

                if (annotationsToAdd == null) {
                  annotationsToAdd = new ArrayList<AnnotationGen>();
                }
                AnnotationGen a = ((BcelAnnotation) decaM.getAnnotation()).getBcelAnnotation();
                // create copy to get the annotation type into the right constant pool
                AnnotationGen ag = new AnnotationGen(a, clazz.getConstantPool(), true);
                annotationsToAdd.add(ag);
                mg.addAnnotation(decaM.getAnnotation());
                AsmRelationshipProvider.addDeclareAnnotationMethodRelationship(decaM.getSourceLocation(),
                    clazz.getName(), mg.getMemberView(), world.getModelAsAsmManager());// getMethod());
                isChanged = true;
View Full Code Here

  }

  public boolean hasAnnotation(UnresolvedType t) {

    // annotations on the real thing
    AnnotationGen agens[] = myGen.getAnnotations();
    if (agens == null) {
      return false;
    }
    for (int i = 0; i < agens.length; i++) {
      AnnotationGen gen = agens[i];
      if (t.equals(UnresolvedType.forSignature(gen.getTypeSignature()))) {
        return true;
      }
    }

    // annotations added during this weave
View Full Code Here

    return false;
  }

  public void addAnnotation(AnnotationGen a) {
    if (!hasAnnotation(UnresolvedType.forSignature(a.getTypeSignature()))) {
      annotations.add(new AnnotationGen(a, getConstantPool(), true));
    }
  }
View Full Code Here

        + Constants.ACC_SUPER, EMPTY_STRINGS, world);
    if (parent != null && parent.isParameterizedType()) {
      cg.setSuperClass(parent);
    }
    if (perclauseString == null) {
      AnnotationGen ag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Aspect"),
          Collections.<NameValuePair> emptyList(), true, cg.getConstantPool());
      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);

        field.setValue(deow.message);
        cg.addField(field, null);
View Full Code Here

   */
  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);
    return aaj;
  }
View Full Code Here

          if (typename.charAt(0) == 'o') {
            if (typename.equals("org.aspectj.lang.annotation.Pointcut")
                || typename.equals("org.aspectj.lang.annotation.Before")
                || typename.equals("org.aspectj.lang.annotation.Around")
                || typename.startsWith("org.aspectj.lang.annotation.After")) {
              AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
              if (a != null) {
                List<NameValuePair> values = a.getValues();
                for (NameValuePair nvPair : values) {
                  if (nvPair.getNameString().equals("argNames")) {
                    String argNames = nvPair.getValue().stringifyValue();
                    StringTokenizer argNameTokenizer = new StringTokenizer(argNames, " ,");
                    List<String> argsList = new ArrayList<String>();
View Full Code Here

  public boolean hasAnnotation(UnresolvedType ofType) {
    // Due to re-entrancy we may be in the middle of unpacking the annotations already... in which case use this slow
    // alternative until the stack unwinds itself
    if (isUnpackingAnnotations()) {
      AnnotationGen annos[] = javaClass.getAnnotations();
      if (annos == null || annos.length == 0) {
        return false;
      } else {
        String lookingForSignature = ofType.getSignature();
        for (int a = 0; a < annos.length; a++) {
          AnnotationGen annotation = annos[a];
          if (lookingForSignature.equals(annotation.getTypeSignature())) {
            return true;
          }
        }
      }
      return false;
View Full Code Here

TOP

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

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.